sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
protected function updateFile() { $this->controlAccess('file_edit'); if ($this->file->update($this->data_file['file_id'], $this->getSubmitted())) { $this->redirect('admin/content/file', $this->text('File has been updated'), 'success'); } $this->redirect('', $this->text('File has not been updated'), 'warning'); }
Updates a file
entailment
protected function addFile() { $this->controlAccess('file_add'); if ($this->file->add($this->getSubmitted())) { $this->redirect('admin/content/file', $this->text('File has been added'), 'success'); } $this->redirect('', $this->text('File has not been added'), 'warning'); }
Adds a new file
entailment
protected function setTitleEditFile() { if (isset($this->data_file['file_id'])) { $title = $this->text('Edit %name', array('%name' => $this->data_file['title'])); } else { $title = $this->text('Add file'); } $this->setTitle($title); }
Sets titles on the edit file page
entailment
protected function setBreadcrumbEditFile() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('admin'), 'text' => $this->text('Dashboard') ); $breadcrumbs[] = array( 'url' => $this->url('admin/content/file'), 'text' => $this->text('Files') ); $this->setBreadcrumbs($breadcrumbs); }
Sets breadcrumbs on the edit file page
entailment
public function init() { $this->setLangcode(); $this->path = $this->url->path(); $this->db = $this->config->getDb(); }
Initialize route
entailment
public function getList() { $routes = &gplcart_static('route.list'); if (isset($routes)) { return $routes; } $routes = (array) gplcart_config_get(GC_FILE_CONFIG_ROUTE); $this->hook->attach('route.list', $routes, $this); return $routes; }
Returns an array of all available routes @return array
entailment
public function process() { try { $this->processAlias(); $this->processRoute(); $this->output404(); } catch (Exception $ex) { trigger_error($ex->getMessage()); $this->response->outputError500(); } }
Processes the route
entailment
protected function setLangcode() { $languages = $this->config->get('languages', array()); if (!empty($languages)) { $segments = $this->url->getSegments(true); $default = $this->config->get('language', 'en'); $found = !empty($languages[$segments[0]]['status']) || $segments[0] === 'en'; $this->langcode = $found ? $segments[0] : $default; $is_default = ($this->langcode === $default); $suffix = $is_default ? '' : $this->langcode; $this->request->setLangcode($suffix); if ($found && $is_default && $this->config->get('redirect_default_langcode', 1)) { unset($segments[0]); $path = $this->request->base(true) . implode('/', $segments); $this->url->redirect($path, $this->request->get(), true); } } }
Sets language
entailment
public function processAlias($path = null) { if (!isset($path)) { $path = $this->path; } if ($this->db->isInitialized() && $this->config->get('alias', true)) { foreach (array_keys($this->findAlias($path)) as $pattern) { $this->callAliasController($pattern, $path, null); } } }
Finds an alias for a path @param string|null $path
entailment
protected function findAlias($path) { $routes = $this->getList(); $alias = $this->db->fetch('SELECT entity, entity_id FROM alias WHERE alias=?', array($path)); foreach ($routes as $pattern => $route) { if (isset($route['status']) && empty($route['status'])) { unset($routes[$pattern]); continue; } if (empty($route['handlers']['alias'])) { unset($routes[$pattern]); continue; } $this->callAliasController($pattern, $path, $alias); } return $routes; }
Try to find and call an alias handler using the URL path @param string $path @return array An array of active routes which don't support aliases
entailment
public function processRoute() { foreach ($this->getList() as $pattern => $route) { if (isset($route['status']) && empty($route['status'])) { continue; } $arguments = array(); if (gplcart_path_match($this->path, $pattern, $arguments)) { $this->callController($pattern, $arguments); } } }
Find an appropriate controller for the URL
entailment
public function aliasCallback($pattern, $path, $alias) { if (!empty($alias['entity']) && !empty($alias['entity_id'])) { if (strpos($pattern, "{$alias['entity']}/") === 0) { $this->callController($pattern, array($alias['entity_id'])); } } if (!isset($alias)) { $arguments = array(); if (gplcart_path_match($path, $pattern, $arguments)) { $conditions = array(strtok($pattern, '/'), reset($arguments)); $sql = 'SELECT alias FROM alias WHERE entity=? AND entity_id=?'; $alias_path = $this->db->fetchColumn($sql, $conditions); } if (!empty($alias_path)) { $this->url->redirect($alias_path); } } }
Route alias callback @param string $pattern @param string $path @param array $alias
entailment
public function callController($route, array $arguments = array()) { $route = $this->set($route, $arguments); $callback = Handler::get($route, null, 'controller'); if (!$callback[0] instanceof Controller) { throw new LogicException('Controller must be instance of \gplcart\core\Controller'); } call_user_func_array($callback, $route['arguments']); // We should never get here as the page callback must abort the script execution throw new LogicException('An error occurred while processing the route'); }
Call a controller for the route @param string|array $route @param array $arguments @throws LogicException
entailment
public function callAliasController($pattern, $path, $alias) { $route = $this->set($pattern, array($pattern, $path, $alias)); Handler::call($route, null, 'alias', $route['arguments']); }
Calls an alias controller for the route @param string $pattern @param string $path @param array|null $alias
entailment
public function set($route, array $arguments = array()) { if (!is_array($route)) { $pattern = $route; $list = $this->getList(); if (empty($list[$pattern])) { throw new OutOfBoundsException("Unknown route pattern $pattern"); } $route = $list[$pattern]; $route += array('arguments' => array(), 'pattern' => $pattern); $route['simple_pattern'] = preg_replace('@\(.*?\)@', '*', $pattern); if (!empty($arguments)) { $route['arguments'] = array_merge($arguments, $route['arguments']); } } return $this->route = $route; }
Sets a route @param array|string $route @param array $arguments @return array @throws OutOfBoundsException
entailment
public function used(array $condition, array $data) { if (!isset($data['rule']['used'])) { return false; } return $this->compare($data['rule']['used'], $condition['value'], $condition['operator']); }
Returns true if the "number of usage" condition is met @param array $condition @param array $data @return boolean
entailment
public function configureServiceManager(ServiceManager $serviceManager) { parent::configureServiceManager($serviceManager); /* * Parameters: * * 'session.class' => 'Symfony\Component\HttpFoundation\Session\Session', * 'session.storage.class' => 'Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage', * 'session.flashbag.class' => 'Symfony\Component\HttpFoundation\Session\Flash\FlashBag', * 'session.attribute_bag.class' => 'Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag', * 'session.storage.native.class' => 'Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage', * 'session.handler.native_file.class' => 'Symfony\Component\HttpFoundation\Session\Storage\Handler\NativeFileSessionHandler', */ $config = $serviceManager->get('Config'); $options = array_merge(array( 'auto_start' => false, 'storage_id' => 'session.storage.native', 'handler_id' => 'session.handler.native_file', 'name' => null, 'cookie_lifetime' => null, 'cookie_path' => null, 'cookie_domain' => null, 'cookie_secure' => null, 'cookie_httponly' => null, 'gc_divisor' => null, 'gc_probability' => null, 'gc_maxlifetime' => null, 'save_path' => null, ), isset($config['session']) ? $config['session'] : array()); $storageOptions = $options; foreach (array('auto_start', 'storage_id', 'handler_id') as $k) { unset($storageOptions[$k]); } // session handler $serviceManager->setFactory('session.handler', function ($serviceManager) use ($options) { $handlerID = $options['handler_id']; return $handlerID === null ? null : $serviceManager->get($handlerID); }); // session storage native $serviceManager->setFactory('session.storage.native', function ($serviceManager) use ($storageOptions) { // We need to strip out keys with a null value so symfony doesn't try and set things with a blank value $storageOptions = array_filter($storageOptions); return new NativeSessionStorage($storageOptions, $serviceManager->get('session.handler')); }); // session flash bag $serviceManager->setFactory('session.flash_bag', function ($serviceManager) { return new FlashBag(); }); // session attribute bag $serviceManager->setFactory('session.attribute_bag', function ($serviceManager) { return new AttributeBag(); }); $that = $this; // session handler native file $serviceManager->setFactory('session.handler.native_file', function ($serviceManager) use ($that, $storageOptions) { // We want absolute paths if we can if (null !== $storageOptions['save_path'] && !$that->isAbsolutePath($storageOptions['save_path'])) { $storageOptions['save_path'] = realpath($storageOptions['save_path']); // Basically if the realpath() failed then we revert back to null so default paths kick in if ($storageOptions['save_path'] === false) { $storageOptions['save_path'] = null; } } return new NativeFileSessionHandler($storageOptions['save_path']); }); // session $serviceManager->setFactory('session', function ($serviceManager) { $session = new Session( $serviceManager->get('session.storage.native'), $serviceManager->get('session.attribute_bag'), $serviceManager->get('session.flash_bag') ); //$session->start(); return $session; }); }
{@inheritdoc}
entailment
public function shippingMethod(array $values) { $existing = array_filter($values, function ($method_id) { return (bool) $this->shipping->get($method_id); }); if (count($values) != count($existing)) { return $this->translation->text('@name is unavailable', array( '@name' => $this->translation->text('Shipping'))); } return true; }
Validates the shipping method condition @param array $values @return boolean|string
entailment
public function paymentMethod(array $values) { $existing = array_filter($values, function ($method_id) { return (bool) $this->payment->get($method_id); }); if (count($values) != count($existing)) { return $this->translation->text('@name is unavailable', array( '@name' => $this->translation->text('Payment'))); } return true; }
Validates the payment method condition @param array $values @return boolean|string
entailment
public function editProductBundle($product_id) { $this->setProductProductBundle($product_id); $this->setTitleEditProductBundle(); $this->setBreadcrumbEditProductBundle(); $this->setData('product', $this->data_product); $this->submitEditProductBundle(); $this->setDataItemsProductBundle(); $this->outputEditProductBundle(); }
Displays the edit product bundle page @param integer $product_id
entailment
protected function setProductProductBundle($product_id) { $this->data_product = $this->product->get($product_id); if (empty($this->data_product)) { $this->outputHttpStatus(404); } $this->prepareProductBundle($this->data_product); }
Sets the product data @param integer $product_id
entailment
protected function validateEditProductBundle() { $this->setSubmitted('product'); $this->setSubmitted('product_id', $this->data_product['product_id']); $this->validateComponent('product_bundle'); return !$this->hasErrors(); }
Validates a product bundle data @return bool
entailment
protected function saveProductBundle() { $this->controlAccess('product_bundle_edit'); $product_id = $this->getSubmitted('product_id'); $products = $this->getSubmitted('products', array()); if ($this->product_bundle->set($product_id, $products)) { $this->redirect('admin/content/product', $this->text('Product bundle has been updated'), 'success'); } $this->redirect('', $this->text('Product bundle has not been updated'), 'warning'); }
Saves a product bundle
entailment
protected function setBreadcrumbEditProductBundle() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('admin'), 'text' => $this->text('Dashboard') ); $breadcrumbs[] = array( 'text' => $this->text('Products'), 'url' => $this->url('admin/content/product') ); $this->setBreadcrumbs($breadcrumbs); }
Sets breadcrumbs on the edit product bundle page
entailment
public function build(array $items) { $this->graph = array(); // Reset all previous data foreach ($items as $id => $item) { $this->graph[$id]['edges'] = array(); if (empty($item['dependencies'])) { continue; } foreach ($item['dependencies'] as $did => $ddata) { $this->graph[$id]['edges'][$did] = $ddata; } } $this->search(); foreach ($this->graph as $id => $data) { $items[$id]['required_by'] = isset($data['reverse_paths']) ? $data['reverse_paths'] : array(); $items[$id]['requires'] = isset($data['paths']) ? $data['paths'] : array(); $items[$id]['sort'] = $data['weight']; } return $items; }
Determines which components require and are required by each component @param array $items @return array
entailment
public function sort(array $ids, array $list) { $data = array(); foreach ($ids as $key) { if (!isset($list[$key])) { return array(); } $data[$key] = $list[$key]['sort']; foreach (array_keys($list[$key]['requires']) as $dependency) { if (!isset($data[$dependency])) { $data[$dependency] = 0; } } } arsort($data); return array_keys($data); }
Sort a list of IDs according to their dependencies Dependent items always go last @param array $ids @param array $list @return array
entailment
protected function search() { $this->state = array( 'last_visit_order' => array(), 'components' => array(), ); foreach ($this->graph as $start => $data) { $this->searchComponent($start); } $component_weights = array(); foreach ($this->state['last_visit_order'] as $vertex) { $component = $this->graph[$vertex]['component']; if (!isset($component_weights[$component])) { $component_weights[$component] = 0; } $this->graph[$vertex]['weight'] = $component_weights[$component]--; } }
Performs a depth-first search and sort on a directed acyclic graph
entailment
protected function searchComponent($start) { if (!isset($this->component)) { $this->component = $start; } if (isset($this->graph[$start]['paths'])) { return null; } $this->graph[$start]['paths'] = array(); $this->graph[$start]['component'] = $this->component; $this->state['components'][$this->component][] = $start; if (isset($this->graph[$start]['edges'])) { foreach ($this->graph[$start]['edges'] as $end => $v) { $this->graph[$start]['paths'][$end] = $v; if (isset($this->graph[$end]['component']) && $this->component != $this->graph[$end]['component']) { $new_component = $this->graph[$end]['component']; foreach ($this->state['components'][$this->component] as $vertex) { $this->graph[$vertex]['component'] = $new_component; $this->state['components'][$new_component][] = $vertex; } unset($this->state['components'][$this->component]); $this->component = $new_component; } if (isset($this->graph[$end])) { $this->searchComponent($end); $this->graph[$start]['paths'] += $this->graph[$end]['paths']; } } } foreach ($this->graph[$start]['paths'] as $end => $v) { if (isset($this->graph[$end])) { $this->graph[$end]['reverse_paths'][$start] = $v; } } $this->state['last_visit_order'][] = $start; return null; }
Performs a depth-first search on a graph @param string $start @return null
entailment
public function addBookmark() { $this->setBookmark(); $this->controlAccess('bookmark_add'); $options = array( 'user_id' => $this->uid, 'title' => $this->data_title ); $this->bookmark->set($this->data_path, $options); $this->redirect($this->data_path); }
Page callback to add a bookmark
entailment
public function deleteBookmark() { $this->setBookmark(); $this->controlAccess('bookmark_delete'); $this->bookmark->delete(array('path' => $this->data_path)); $this->redirect($this->data_target); }
Page callback to delete a bookmark
entailment
protected function setBookmark() { $this->data_path = $this->getQuery('path'); $this->data_title = $this->getQuery('title'); $this->data_target = $this->getQuery('target', $this->data_path); if (empty($this->data_path)) { $this->outputHttpStatus(403); } }
Sets bookmark data
entailment
public function listBookmark() { $this->setTitleListBookmark(); $this->setBreadcrumbListBookmark(); $this->setFilterListBookmark(); $this->setPagerlListBookmark(); $this->setData('bookmarks', $this->getListBookmark()); $this->outputListBookmark(); }
Displays the bookmark overview page
entailment
protected function setPagerlListBookmark() { $options = $this->query_filter; $options['count'] = true; $total = (int) $this->bookmark->getList($options); $pager = array( 'total' => $total, 'query' => $this->query_filter ); return $this->data_limit = $this->setPager($pager); }
Sets pager @return array
entailment
protected function getListBookmark() { $conditions = $this->query_filter; $conditions['user_id'] = $this->uid; $conditions['limit'] = $this->data_limit; return (array) $this->bookmark->getList($conditions); }
Returns an array of bookmarks @return array
entailment
public function listReportPayment() { $this->setTitleListReportPayment(); $this->setBreadcrumbListReportPayment(); $this->setFilterListReportPayment(); $this->setPagerListReportPayment(); $this->setData('methods', (array) $this->getListReportPayment()); $this->outputListReportPayment(); }
Displays the payment methods overview page
entailment
protected function setPagerListReportPayment() { $pager = array( 'query' => $this->query_filter, 'total' => (int) $this->getListReportPayment(true) ); return $this->data_limit = $this->setPager($pager); }
Sets pager @return array
entailment
protected function getListReportPayment($count = false) { $list = $this->payment->getList(); $allowed = $this->getAllowedFiltersReportPayment(); $this->filterList($list, $allowed, $this->query_filter); $this->sortList($list, $allowed, $this->query_filter, array('id' => 'asc')); if ($count) { return count($list); } $this->limitList($list, $this->data_limit); return $list; }
Returns an array of payment methods @param bool $count @return array|int
entailment
protected function updateNumPages() { $this->pages = ($this->limit == 0) ? 0 : (int) ceil($this->total / $this->limit); return $this; }
Updates the current number of pages @return $this
entailment
public function getPages() { $pages = array(); if ($this->pages <= 1) { return array(); } if ($this->pages <= $this->limit_pages) { for ($i = 1; $i <= $this->pages; $i++) { $pages[] = $this->createPage($i, $i == $this->current); } return $pages; } $num_adjacents = (int) floor(($this->limit_pages - 3) / 2); if ($this->current + $num_adjacents > $this->pages) { $sliding_start = $this->pages - $this->limit_pages + 2; } else { $sliding_start = $this->current - $num_adjacents; } if ($sliding_start < 2) { $sliding_start = 2; } $sliding_end = $sliding_start + $this->limit_pages - 3; if ($sliding_end >= $this->pages) { $sliding_end = $this->pages - 1; } $pages[] = $this->createPage(1, $this->current == 1); if ($sliding_start > 2) { $pages[] = $this->createPageEllipsis(); } for ($i = $sliding_start; $i <= $sliding_end; $i++) { $pages[] = $this->createPage($i, $i == $this->current); } if ($sliding_end < $this->pages - 1) { $pages[] = $this->createPageEllipsis(); } $pages[] = $this->createPage($this->pages, $this->current == $this->pages); return $pages; }
Get an array of paginated page data @return array
entailment
public function getCurrentPageLastItem() { $first = $this->getCurrentPageFirstItem(); if (empty($first)) { return 0; } $last = $first + $this->limit - 1; if ($last > $this->total) { return $this->total; } return $last; }
Returns the last item for the current page @return integer
entailment
public function getCurrentPageFirstItem() { $first = ($this->current - 1) * $this->limit; if ($first > $this->total) { return 0; } return $first; }
Returns the first item for the current page @return integer
entailment
public function build(array $data = array()) { $data += array( 'page' => 1, 'limit' => 0, 'total' => 0, 'mini' => false, 'max_pages' => 10, 'query' => array() ); $this->setPage($data['page']) ->setPerPage($data['limit']) ->setTotal($data['total']) ->setMaxPages($data['max_pages']) ->setUrlPattern('?' . urldecode(http_build_query($data['query']))); return $this; }
Set up pager from an array of parameters @param array $data @return $this
entailment
public function load($file, $type = null) { $path = $this->locator->locate($file); $this->setCurrentDir(dirname($path)); $config = require $path; // not an array if (!is_array($config)) { throw new \InvalidArgumentException(sprintf('The file "%s" must contain a PHP array.', $path)); } return $config; }
Loads a PHP file. @param mixed $file The resource @param string $type The resource type @throws \InvalidArgumentException @return array Array with configuration
entailment
public function editSettings() { $this->setTitleEditSettings(); $this->setBreadcrumbEditSettings(); $this->setData('settings', $this->getSettings()); $this->setData('timezones', gplcart_timezones()); $this->submitEditSettings(); $this->outputEditSettings(); }
Displays the edit settings page
entailment
protected function validateEditSettings() { $this->setSubmitted('settings'); if (!$this->getSubmitted('cron_key')) { $this->setSubmitted('cron_key', gplcart_string_random()); } return !$this->hasErrors(); }
Validates submitted settings @return bool
entailment
protected function updateSettings() { $this->controlAccess('settings_edit'); foreach ($this->getSubmitted() as $key => $value) { $this->config->set($key, $value); } $this->redirect('', $this->text('Settings have been updated'), 'success'); }
Updates settings
entailment
public function get($code) { $result = null; $this->hook->attach('language.get.before', $code, $result, $this); if (isset($result)) { return (array) $result; } $list = $this->getList(); $result = isset($list[$code]) ? $list[$code] : array(); $this->hook->attach('language.get.after', $code, $result, $this); return (array) $result; }
Returns a language @param string $code @return array
entailment
public function getList(array $options = array()) { $options += array( 'enabled' => false, 'in_database' => false ); $languages = &gplcart_static(gplcart_array_hash(array('language.list' => $options))); if (isset($languages)) { return $languages; } $this->hook->attach('language.list.before', $options, $languages, $this); if (isset($languages)) { return (array) $languages; } $iso = $this->getIso(); $default_code = $this->getDefault(); $default_data = $this->getDefaultData(); $saved = $this->config->get('languages', array()); $languages = array_replace_recursive($iso, $saved); $this->hook->attach('language.list.after', $options, $languages, $this); foreach ($languages as $code => &$language) { $language['code'] = $code; $language += $default_data; $language['default'] = ($code == $default_code); $language['in_database'] = isset($saved[$code]); if (empty($language['native_name'])) { $language['native_name'] = $language['name']; } if ($options['enabled'] && empty($language['status'])) { unset($languages[$code]); continue; } if ($options['in_database'] && empty($language['in_database'])) { unset($languages[$code]); } } gplcart_array_sort($languages); return $languages; }
Returns an array of languages @param array $options @return array
entailment
public function add(array $data) { $result = null; $this->hook->attach('language.add.before', $data, $result, $this); if (isset($result)) { return (bool) $result; } if (!empty($data['default'])) { $this->setDefault($data['code']); } $default = $this->getDefaultData(); $data += $default; if (empty($data['name'])) { $data['name'] = $data['code']; } if (empty($data['native_name'])) { $data['native_name'] = $data['name']; } $languages = $this->config->select('languages', array()); $languages[$data['code']] = array_intersect_key($data, $default); $result = $this->config->set('languages', $languages); $this->hook->attach('language.add.after', $data, $result, $this); return (bool) $result; }
Adds a language @param array $data @return boolean
entailment
public function translit($string, $language) { $result = null; $this->hook->attach('language.translit.before', $string, $language, $result, $this); if (isset($result)) { return $result; } $result = $string; if (function_exists('transliterator_transliterate')) { $result = transliterator_transliterate('Any-Latin; Latin-ASCII; [\u0100-\u7fff] remove', $string); } else if (function_exists('iconv')) { $result = iconv('UTF-8', 'ASCII//IGNORE//TRANSLIT', $string); } if (trim($result) === '') { $result = $string; } $this->hook->attach('language.translit.after', $string, $language, $result, $this); return $result; }
Transliterate a string @param string $string @param string $language @return string
entailment
public function getIso($code = null) { $data = (array) gplcart_config_get(GC_FILE_CONFIG_LANGUAGE); if (isset($code)) { return isset($data[$code]) ? (array) $data[$code] : array(); } return $data; }
Returns an array of common languages with their English and native names @param null|string $code @return array
entailment
public static function parseName($name, $type = 0) { if ($type) { return ucfirst(preg_replace_callback('/_([a-zA-Z])/', function ($match) { return strtoupper($match[1]); }, $name)); } else { return strtolower(trim(preg_replace('/[A-Z]/', '_\\0', $name), '_')); } }
驼峰与下划线的相互转化
entailment
public static function attributes(array $attributes = NULL) { if (!$attributes) return; asort($attributes); $h = ''; foreach ($attributes as $k => $v) { $h .= " $k=\"" . self::h($v) . '"'; } return $h; }
Compiles an array of HTML attributes into an attribute string and HTML escape it to prevent malformed (but not malicious) data. @param array $attributes the tag's attribute list @return string
entailment
public static function tag($tag, $text = '', array $attributes = NULL) { $autoClose = array('input', 'br', 'hr', 'img', 'col', 'area', 'base', 'link', 'meta', 'frame', 'param'); return "<$tag" . self::attributes($attributes) . (in_array($tag, $autoClose) ? ' />' : ">$text</$tag>"); }
Create an HTML tag @param string $tag the tag name @param string $text the text to insert between the tags @param array $attributes of additional tag settings @return string
entailment
public static function select($name, array $options, $selected = NULL, array $attributes = NULL) { $h = ''; foreach ($options as $k => $v) { $a = array('value' => $k); // Is this element one of the selected options? if ($selected AND in_array($k, (array)$selected)) { $a['selected'] = 'selected'; } $h .= self::tag('option', $v, $a); } if (!$attributes) { $attributes = array(); } return self::tag('select', $h, $attributes + array('name' => $name)); }
Auto creates a form select dropdown from the options given . @param string $name the select element name @param array $options the select options @param mixed $selected the selected options(s) @param array $attributes of additional tag settings @return string
entailment
public function editUserRegister() { $this->controlAccessUserRegister(); $this->setTitleEditUserRegister(); $this->setBreadcrumbEditUserRegister(); $this->submitUserRegister(); $this->setData('password_limit', $this->user->getPasswordLength()); $this->outputEditUserRegister(); }
Displays the user registration page
entailment
protected function userRegister() { $result = $this->user_action->register($this->getSubmitted()); $this->redirect($result['redirect'], $result['message'], $result['severity']); }
Registers a user
entailment
protected function validateUserRegister() { $this->setSubmitted('user', null, false); $this->filterSubmitted(array('email', 'password', 'name')); $this->setSubmitted('store_id', $this->store_id); $this->validateComponent('user'); return !$this->hasErrors(); }
Validates an array of submitted data during registration @return bool
entailment
public function cart(array &$submitted, array $options = array()) { $this->options = $options; $this->submitted = &$submitted; $this->validateCart(); $this->validateStoreId(); $this->validateProductCart(); $this->validateSkuCart(); $this->validateUserCartId(); $this->validateOrderCart(); $this->validateQuantityCart(); $this->validateOptionsCart(); $this->validateLimitCart(); $this->validateData(); $this->unsetSubmitted('update'); return $this->getResult(); }
Performs full cart data validation @param array $submitted @param array $options @return boolean|array
entailment
protected function validateCart() { $id = $this->getUpdatingId(); if ($id === false) { return null; } $data = $this->cart->get($id); if (empty($data)) { $this->setErrorUnavailable('update', $this->translation->text('Cart')); return false; } $this->setUpdating($data); return true; }
Validates a cart item to be updated @return boolean
entailment
protected function validateSkuCart() { if ($this->isError('store_id')) { return null; } $field = 'sku'; $value = $this->getSubmitted($field); if (!isset($value)) { return null; } $label = $this->translation->text('SKU'); if (empty($value)) { $this->setErrorRequired($field, $label); return false; } $store_id = $this->getSubmitted('store_id'); $product = $this->product->getBySku($value, $store_id); if (empty($product['product_id'])) { $this->setErrorUnavailable($field, $label); return false; } $this->setSubmitted('product', $product); return true; }
Validates a cart item SKU @return boolean|null
entailment
protected function validateOrderCart() { $field = 'order_id'; $value = $this->getSubmitted($field); if (empty($value)) { return null; } $label = $this->translation->text('Order'); if (!is_numeric($value)) { $this->setErrorNumeric($field, $label); return false; } $order = $this->order->get($value); if (empty($order['order_id'])) { $this->setErrorUnavailable($field, $label); return false; } return true; }
Validates an order ID @return boolean|null
entailment
protected function validateQuantityCart() { $field = 'quantity'; if ($this->isExcluded($field)) { return null; } $value = $this->getSubmitted($field); if (!isset($value)) { if ($this->isUpdating()) { return null; } $value = 1; } $label = $this->translation->text('Quantity'); if (!is_numeric($value)) { $this->setErrorNumeric($field, $label); return false; } if (strlen($value) > 2) { $this->setErrorLengthRange($field, $label, 1, 2); return false; } return true; }
Validates cart item quantity @return boolean|null
entailment
protected function validateLimitCart() { if ($this->isError()) { return null; } $admin = $this->getSubmitted('admin'); $product = $this->getSubmitted('product'); if (!empty($admin) || empty($product)) { return null; } $sku = $this->getSubmitted('sku'); $user_id = $this->getSubmitted('user_id'); $store_id = $this->getSubmitted('store_id'); $quantity = $this->getSubmitted('quantity'); $increment = $this->getSubmitted('increment', true); $stock = $this->getSubmitted('stock', $product['stock']); $expected_quantity_sku = $quantity; $existing_quantity = $this->cart->getQuantity(array('user_id' => $user_id, 'store_id' => $store_id)); if (!empty($increment) && isset($existing_quantity['sku'][$sku])) { $expected_quantity_sku += $existing_quantity['sku'][$sku]; } if ($product['subtract'] && $expected_quantity_sku > $stock) { $error = $this->translation->text('Too low stock level'); $this->setError('quantity', $error); return false; } $limit_sku = $this->cart->getLimits('sku'); $limit_item = $this->cart->getLimits('item'); if (!empty($limit_item) && !isset($existing_quantity['sku'][$sku]) && count($existing_quantity['sku']) >= $limit_item) { $error = $this->translation->text('Please no more than @num items', array('@num' => $limit_item)); $this->setError('quantity', $error); return false; } if (!empty($limit_sku) && $expected_quantity_sku > $limit_sku) { $error = $this->translation->text('Please no more than @num items per SKU', array('@num' => $limit_sku)); $this->setError('quantity', $error); return false; } return true; }
Validates cart limits @return boolean|null
entailment
protected function validateOptionsCart() { $product = $this->getSubmitted('product'); if (empty($product) || $this->isError()) { return null; } $options = array_filter((array) $this->getSubmitted('options')); if (empty($options)) { $this->setSubmitted('options', array()); $this->setSubmitted('sku', $product['sku']); $this->setSubmitted('stock', $product['stock']); return true; } $combination_id = $this->sku->getCombinationId($options, $product['product_id']); if (empty($product['combination'][$combination_id]['status'])) { $error = $this->translation->text('Invalid combination'); $this->setError('options', $error); return false; } $this->setSubmitted('options', $options); $this->setSubmitted('combination_id', $combination_id); $this->setSubmitted('sku', $product['combination'][$combination_id]['sku']); $this->setSubmitted('stock', $product['combination'][$combination_id]['stock']); return true; }
Validates products cart options @return boolean|null
entailment
public function address(array &$submitted, array $options = array()) { $this->options = $options; $this->submitted = &$submitted; $this->validateAddress(); $this->validateCountryAddress(); $this->validateStateAddress(); $this->validateCityAddress(); $this->validateTypeAddress(); $this->validateFieldsAddress(); $this->validateUserIdAddress(); $this->validateData(); $this->unsetSubmitted('update'); return $this->getResult(); }
Performs full address data validation @param array $submitted @param array $options @return array|boolean
entailment
protected function validateAddress() { $id = $this->getUpdatingId(); if ($id === false) { return null; } $data = $this->address->get($id); if (empty($data)) { $this->setErrorUnavailable('update', $this->translation->text('Address')); return false; } $this->setUpdating($data); return true; }
Validates an address to be updated @return boolean
entailment
protected function validateUserIdAddress() { $field = 'user_id'; if ($this->isExcluded($field)) { return null; } $value = $this->getSubmitted($field); if ($this->isUpdating() && !isset($value)) { $this->unsetSubmitted($field); return null; } $label = $this->translation->text('User'); if (empty($value) || mb_strlen($value) > 255) { $this->setErrorLengthRange($field, $label); return false; } if (!is_numeric($value)) { return true; // Anonymous user } $user = $this->user->get($value); if (empty($user)) { $this->setErrorUnavailable($field, $label); return false; } return true; }
Validates a user Id @return boolean
entailment
protected function validateCountryAddress() { $field = 'country'; $value = $this->getSubmitted($field); if (!isset($value)) { $this->unsetSubmitted($field); return null; } $country = $this->country->get($value); $label = $this->translation->text('Country'); if (empty($country)) { $this->setErrorUnavailable($field, $label); return false; } return true; }
Validates a country code @return boolean|null
entailment
protected function validateStateAddress() { $field = 'state_id'; $value = $this->getSubmitted($field); if (!isset($value)) { $this->unsetSubmitted($field); return null; } $label = $this->translation->text('Country state'); $format = $this->getCountryFormatAddress(); if (empty($value) && !empty($format['state_id']['required'])) { $this->setErrorRequired($field, $label); return false; } if (!is_numeric($value)) { $this->setErrorNumeric($field, $label); return false; } if (empty($value)) { return true; } $state = $this->state->get($value); if (empty($state)) { $this->setErrorUnavailable($field, $label); return false; } return true; }
Validates a country state @return boolean|null
entailment
protected function validateCityAddress() { $field = 'city_id'; if ($this->isExcluded($field) || $this->isError('country')) { return null; } $value = $this->getSubmitted($field); if ($this->isUpdating() && !isset($value)) { $this->unsetSubmitted($field); return null; } $label = $this->translation->text('City'); $format = $this->getCountryFormatAddress(); if (empty($value) && !empty($format['city_id']['required'])) { $this->setErrorRequired($field, $label); return false; } // City ID can be either numeric ID or non-numeric human name if (is_numeric($value)) { if ($this->city->get($value)) { return true; } $this->setErrorUnavailable($field, $label); return false; } if (empty($value)) { return true; } if (mb_strlen($value) > 255) { $this->setErrorLengthRange($field, $label); return false; } // Try to convert human name to a numeric ID $country = $this->getSubmitted('country'); $state_id = $this->getSubmitted('state_id'); if (empty($country) || empty($state_id)) { return true; } $conditions = array( 'name' => $value, 'country' => $country, 'state_id' => $state_id ); foreach ((array) $this->city->getList($conditions) as $city) { if (strcasecmp($city['name'], $value) === 0) { $this->setSubmitted($field, $city['city_id']); break; } } return true; }
Validates a city @return boolean|null
entailment
protected function validateTypeAddress() { $field = 'type'; $value = $this->getSubmitted($field); if (!isset($value)) { $this->unsetSubmitted($field); return null; } if (!in_array($value, $this->address->getTypes())) { $this->setErrorUnavailable($field, $this->translation->text('Type')); return false; } return true; }
Validates an address type @return boolean|null
entailment
protected function validateFieldsAddress() { $this->validateFieldAddress('address_1'); $this->validateFieldAddress('address_2'); $this->validateFieldAddress('phone'); $this->validateFieldAddress('middle_name'); $this->validateFieldAddress('last_name'); $this->validateFieldAddress('first_name'); $this->validateFieldAddress('postcode'); $this->validateFieldAddress('company'); $this->validateFieldAddress('fax'); }
Validates address fields
entailment
protected function validateFieldAddress($field) { if ($this->isExcluded($field) || $this->isError('country')) { return null; } $value = $this->getSubmitted($field); if ($this->isUpdating() && !isset($value)) { $this->unsetSubmitted($field); return null; } $format = $this->getCountryFormatAddress(); if (empty($format[$field]['required'])) { return null; } if (!isset($value) || $value === '' || mb_strlen($value) > 255) { $this->setErrorLengthRange($field, $format[$field]['name'], 1, 255); return false; } return true; }
Validates an address field associated with the country format @param string $field @return bool|null
entailment
protected function getCountryFormatAddress() { $updating = $this->getUpdating(); if (isset($updating['country_format'])) { return $updating['country_format']; } $field = 'country'; $code = $this->getSubmitted($field); if (!isset($code)) { return $this->country->getDefaultFormat(); } $country = $this->country->get($code); if (empty($country['format'])) { $this->setErrorUnavailable($field, $this->translation->text('Country')); return array(); } return $country['format']; }
Returns the current country format @return array
entailment
public function indexPage($page_id) { $this->setPage($page_id); $this->setTitleIndexPage(); $this->setBreadcrumbIndexPage(); $this->setHtmlFilterIndexPage(); $this->setMetaIndexPage(); $this->setData('page', $this->data_page); $this->setDataImagesIndexPage(); $this->outputIndexPage(); }
Displays a page @param integer $page_id
entailment
protected function setPage($page_id) { $this->data_page = $this->page->get($page_id); if (empty($this->data_page)) { $this->outputHttpStatus(404); } $this->controlAccessPage(); $this->preparePage($this->data_page); }
Sets a page data @param integer $page_id
entailment
protected function controlAccessPage() { if (empty($this->data_page['status']) && !$this->access('page')) { $this->outputHttpStatus(403); } if ($this->data_page['store_id'] != $this->store_id) { $this->outputHttpStatus(404); } }
Controls access to the page
entailment
protected function setDataImagesIndexPage() { $options = array( 'imagestyle' => $this->configTheme('image_style_page', 5) ); $this->setItemThumb($this->data_page, $this->image, $options); $this->setData('images', $this->render('page/images', array('page' => $this->data_page))); }
Sets the rendered images on the page
entailment
public function matchRequest(Request $request) { try { $parameters = parent::matchRequest($request); $this->matchedRouteRequest = $request; return $parameters; } catch (\Exception $e) { throw $e; } }
@param Request $request @throws \Exception
entailment
public function login(array $data, $check_password = true) { $result = array(); $this->hook->attach('user.login.before', $data, $check_password, $result, $this); if (!empty($result)) { return (array) $result; } if (empty($data['email'])) { return $this->getResultErrorLogin(); } $user = $this->user->getByEmail($data['email']); if (empty($user['status'])) { return $this->getResultErrorLogin(); } if ($check_password && (!isset($data['password']) || !$this->user->passwordMatches($data['password'], $user))) { return $this->getResultErrorLogin(); } $this->session->regenerate(true); $this->session->set('user', $user); $result = $this->getResultLogin($user); $this->hook->attach('user.login.after', $data, $check_password, $result, $this); return (array) $result; }
Logs in a user @param array $data @param bool $check_password @return array
entailment
public function register(array $data) { $result = array(); $this->hook->attach('user.register.before', $data, $result, $this); if (!empty($result)) { return (array) $result; } $data['status'] = $this->config->get('user_registration_status', true); $data['user_id'] = $this->user->add($data); if (empty($data['user_id'])) { return $this->getResultError(); } $this->emailRegistration($data); $this->session->regenerate(true); $login = $this->config->get('user_registration_login', true); $result = ($login && $data['status']) ? $this->login($data) : $this->getResultRegistered($data); $this->hook->attach('user.register.after', $data, $result, $this); return (array) $result; }
Registers a user @param array $data @return array
entailment
public function logout() { $result = array(); $user = $this->user->get($this->user->getId()); $this->hook->attach('user.logout.before', $user, $result, $this); if (!empty($result)) { return (array) $result; } $this->session->delete(); $result = $this->getResultLogOut($user); $this->hook->attach('user.logout.after', $user, $result, $this); return (array) $result; }
Logs out the current user @return array
entailment
public function resetPassword(array $data) { $result = array(); $this->hook->attach('user.reset.password.before', $data, $result, $this); if (!empty($result)) { return (array) $result; } if (empty($data['user']['user_id'])) { return $this->getResultError(); } if (isset($data['password'])) { $result = $this->resetPasswordFinish($data); } else { $result = $this->resetPasswordStart($data); } $this->session->regenerate(true); $this->hook->attach('user.reset.password.after', $data, $result, $this); return (array) $result; }
Performs reset password operation @param array $data @return array
entailment
protected function resetPasswordStart(array $data) { $data['user']['data']['reset_password'] = array( 'token' => gplcart_string_random(), 'expires' => GC_TIME + $this->user->getResetPasswordLifespan(), ); $this->user->update($data['user']['user_id'], array('data' => $data['user']['data'])); $this->mail->set('user_reset_password', array($data['user'])); return $this->getResultResetPasswordStart(); }
Start the password reset operation @param array $data @return array
entailment
protected function resetPasswordFinish(array $data) { $data['user']['password'] = $data['password']; unset($data['user']['data']['reset_password']); $this->user->update($data['user']['user_id'], $data['user']); $this->mail->set('user_changed_password', array($data['user'])); return $this->getResultResetPasswordFinish(); }
Finish the password reset operation @param array $data @return array
entailment
public function emailRegistration(array $data) { if ($this->config->get('user_registration_email_customer', true)) { $this->mail->set('user_registered_customer', array($data)); } if ($this->config->get('user_registration_email_admin', true)) { $this->mail->set('user_registered_admin', array($data)); } }
Sends e-mails on registration event @param array $data
entailment
protected function getLoginRedirect(array $user) { $redirect = "account/{$user['user_id']}"; if (!empty($user['role_redirect'])) { $redirect = $user['role_redirect']; } if ($this->user->isSuperadmin($user['user_id'])) { $redirect = 'admin'; } return $redirect; }
Returns a redirect path for the user @param array $user @return string
entailment
public static function string2dateTime($string, \DateTimeZone $zone = null) { if (!$zone) { $zone = new \DateTimeZone('UTC'); } $dt = new \DateTime('now', $zone); $dt->setTimestamp(self::string2timestamp($string)); return $dt; }
@param string $string @param \DateTimeZone $zone @return \DateTime
entailment
public static function string2timestamp($string) { $matches = array(); if (!preg_match( '/^(\\d\\d\\d\\d)-(\\d\\d)-(\\d\\d)T(\\d\\d):(\\d\\d):(\\d\\d)(?:\\.\\d+)?Z$/D', $string, $matches ) ) { throw new \InvalidArgumentException('Invalid timestamp: '.$string); } $year = intval($matches[1]); $month = intval($matches[2]); $day = intval($matches[3]); $hour = intval($matches[4]); $minute = intval($matches[5]); $second = intval($matches[6]); // Use gmmktime because the timestamp will always be given in UTC? $ts = gmmktime($hour, $minute, $second, $month, $day, $year); return $ts; }
@param $string @return int
entailment
public function init($file = GC_FILE_CONFIG_COMPILED) { $this->initialized = false; $this->setErrorHandlers(); if (is_file($file)) { $this->setConfig($file); $this->setErrorLevel(); $this->setKey(); $this->setLogger(); date_default_timezone_set($this->get('timezone', 'Europe/London')); $this->initialized = true; } return $this->initialized; }
Initialize the system configuration @param string $file @return bool
entailment
protected function setErrorLevel() { switch ($this->get('error_level', 2)) { case 0: error_reporting(0); break; case 1: error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); break; case 2: error_reporting(E_ALL); break; } }
Set PHP error reporting level
entailment
protected function setErrorHandlers() { register_shutdown_function(array($this->logger, 'shutdownHandler')); set_exception_handler(array($this->logger, 'exceptionHandler')); set_error_handler(array($this->logger, 'errorHandler'), error_reporting()); }
Sets PHP error handlers
entailment
protected function setLogger() { $this->logger->setDb($this->db) ->printError($this->get('error_print', false)) ->logBacktrace($this->get('error_log_backtrace', true)) ->printBacktrace($this->get('error_print_backtrace', false)) ->errorToException($this->get('error_to_exception', false)); }
Sets logger
entailment
public function setConfig($config) { if (is_array($config)) { $this->config = $config; } else { $this->config = (array) gplcart_config_get((string) $config); $this->setDb($this->config['database']); $this->config = array_merge($this->config, $this->select()); } }
Set array of configuration options @param array|string $config Either a file path or an array of configuration options
entailment
public function setKey($key = null) { if (empty($key)) { $key = $this->get('private_key'); if (empty($key)) { $key = gplcart_string_random(); $this->set('private_key', $key); } } else { $this->set('private_key', $key); } return $this->key = $key; }
Sets the private key @param null|string $key @return string
entailment
public function get($key = null, $default = null) { if (!isset($key)) { return $this->config; } if (array_key_exists($key, $this->config)) { return $this->config[$key]; } return $default; }
Returns a value from an array of configuration options @param string $key @param mixed $default @return mixed
entailment
public function set($key, $value) { if (!$this->db->isInitialized() || empty($key) || !isset($value)) { return false; } $this->reset($key); $serialized = 0; if (is_array($value)) { $value = serialize($value); $serialized = 1; } $values = array( 'id' => $key, 'value' => $value, 'created' => GC_TIME, 'serialized' => $serialized ); $this->db->insert('settings', $values); return true; }
Saves a configuration value in the database @param string $key @param mixed $value @return boolean
entailment
public function select($name = null, $default = null) { if (!$this->db->isInitialized()) { return isset($name) ? $default : array(); } $conditions = array(); $sql = 'SELECT * FROM settings'; if (isset($name)) { $conditions[] = $name; $sql .= ' WHERE id=? LIMIT 0,1'; } $settings = array(); foreach ($this->db->fetchAll($sql, $conditions) as $result) { if (!empty($result['serialized'])) { $result['value'] = unserialize($result['value']); } $settings[$result['id']] = $result['value']; } return isset($name) ? reset($settings) : $settings; }
Select all or a single setting from the database @param null|string $name @param mixed $default @return mixed
entailment
public function get($key) { $parts = explode('.', $key); $offset = $this->config; foreach($parts as $part) { if(!isset($offset[$part])) return null; $offset = $offset[$part]; } return $offset; }
Get configuration by key @param $key @return mixed
entailment