sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
protected function setLanguageProperties()
{
if (!$this->isInternalRoute()) {
$langcode = $this->route->getLangcode();
if (!empty($langcode)) {
$this->langcode = $langcode;
$this->translation->set($langcode, $this->current_route['simple_pattern']);
$this->current_language = $this->language->get($this->langcode);
}
}
} | Sets the current language data | entailment |
protected function setUserProperties()
{
if (!$this->isInstall()) {
$this->cart_uid = $this->cart->getUid();
$this->uid = $this->user->getId();
if (!empty($this->uid)) {
$this->current_user = $this->user->get($this->uid);
}
}
if (!empty($this->current_user['timezone'])) {
date_default_timezone_set($this->current_user['timezone']);
}
} | Sets user/access properties | entailment |
protected function setStoreProperties()
{
$this->current_store = $this->store->get();
if (isset($this->current_store['store_id'])) {
$this->store_id = $this->current_store['store_id'];
$this->is_maintenance = empty($this->current_store['status']) && !$this->access('maintenance');
}
} | Sets the current store data | entailment |
public function url($path = '', array $query = array(), $absolute = false, $exclude_lang = false)
{
return $this->url->get($path, $query, $absolute, $exclude_lang);
} | Returns a formatted URL
@param string $path
@param array $query
@param boolean $absolute
@param boolean $exclude_lang
@return string | entailment |
public function lurl($langcode, $path = '', array $query = array())
{
if ($langcode === $this->language->getDefault()) {
$langcode = '';
}
return $this->url->language($langcode, $path, $query);
} | Returns a formatted URL with a language code
@param string $langcode
@param string $path
@param array $query
@return string | entailment |
public function image($path, $imagestyle_id = null, $absolute = false)
{
return $this->image->getUrl($path, $imagestyle_id, $absolute);
} | Returns an image URL
@param string $path
@param integer|null $imagestyle_id
@param boolean $absolute
@return string | entailment |
public function download($file, $filename = '', $options = array())
{
$this->response->download($file, $filename, $options);
} | Download a file
@param string $file
@param string $filename
@param array $options | entailment |
public function jstext($strings, $print = true)
{
$code = '';
foreach ((array) $strings as $string) {
$key = gplcart_json_encode($string);
$text = $this->translation->text($string);
$translation = gplcart_json_encode(array($text));
$code .= "Gplcart.translations[$key]=$translation;\n";
}
if ($print && $code) {
echo "<script>$code</script>";
}
return $code;
} | Prints and/or returns JS array with translations
@param string|array $strings
@param bool $print
@return string | entailment |
public function error($key = null, $return_error = null, $return_no_error = '')
{
if (isset($key)) {
$result = gplcart_array_get($this->errors, $key);
} else {
$result = empty($this->errors) ? null : $this->errors;
}
if (isset($result)) {
return isset($return_error) ? $return_error : $result;
}
return $return_no_error;
} | Returns a value if an error occurred
@param string|array $key
@param mixed $return_error
@param mixed $return_no_error
@return mixed | entailment |
public function getStore($item = null)
{
if (isset($item)) {
return gplcart_array_get($this->current_store, $item);
}
return $this->current_store;
} | Returns a data of the current store
@param mixed $item
@return mixed | entailment |
public function getUser($item = null)
{
if (isset($item)) {
return gplcart_array_get($this->current_user, $item);
}
return $this->current_user;
} | Returns a data of the current user
@param mixed $item
@return mixed | entailment |
public function getJs($position)
{
$js = $this->asset->get('js', $position);
if (isset($js['js_settings']['asset'])) {
$json = gplcart_json_encode($js['js_settings']['asset']);
$js['js_settings']['asset'] = "Gplcart.settings=$json;";
}
return $js;
} | Returns an array of JS scripts
@param string $position
@return array | entailment |
public function date($timestamp = null, $full = true)
{
if (!isset($timestamp)) {
$timestamp = GC_TIME;
}
if ($full) {
$format = $this->config->get('date_full_format', 'd.m.Y H:i');
} else {
$format = $this->config->get('date_short_format', 'd.m.y');
}
return date($format, $timestamp);
} | Formats a local time/date
@param null|integer $timestamp
@param bool $full
@return string | entailment |
public function format($format, array $arguments = array(), $glue = '<br>')
{
if (is_array($format)) {
$format = implode($glue, gplcart_array_flatten($format));
}
return vsprintf($format, $arguments);
} | Return a formatted string
@param string|array $format
@param array $arguments
@param string $glue
@return string | entailment |
public function configTheme($key = null, $default = null)
{
if (!isset($key)) {
return $this->theme_settings;
}
$value = gplcart_array_get($this->theme_settings, $key);
return isset($value) ? $value : $default;
} | Returns a setting from the current theme settings
@param mixed $key
@param mixed $default
@return mixed | entailment |
public function filter($string, $filter = null)
{
if (!isset($filter)) {
$filter = $this->current_filter;
}
$delimiter = $this->config('teaser_delimiter', '<!--teaser-->');
$string = str_replace($delimiter, htmlspecialchars($delimiter), $string);
return $this->filter->run($string, $filter);
} | Clean up HTML string using defined HTML filters
@param string $string
@param mixed $filter
@return string | entailment |
protected function explodeText($text)
{
$delimiter = $this->config('teaser_delimiter', '<!--teaser-->');
$text = str_replace(htmlspecialchars($delimiter), $delimiter, $text);
$parts = array_filter(array_map('trim', explode($delimiter, $text, 2)));
return array_pad($parts, 2, '');
} | Explodes a text by teaser and full text
@param string $text
@return array | entailment |
public function attributes(array $attributes)
{
foreach ($attributes as $attribute => &$data) {
$data = implode(' ', (array) $data);
$data = $attribute . '="' . htmlspecialchars($data, ENT_QUOTES, 'UTF-8') . '"';
}
return empty($attributes) ? '' : ' ' . implode(' ', $attributes);
} | Formats tag attributes
@param array $attributes
@return string | entailment |
public function teaser($text, $enable_filter = true, $filter_id = null)
{
$summary = '';
if ($text !== '') {
$parts = $this->explodeText($text);
$summary = reset($parts);
}
if ($summary !== '' && $enable_filter) {
$summary = $this->filter($summary, $filter_id);
}
return $summary;
} | Returns a string from a text before the teaser delimiter
@param string $text
@param boolean $enable_filter
@param mixed $filter_id
@return string | entailment |
public function path($pattern = null)
{
if (isset($pattern)) {
return preg_match("~$pattern~i", $this->path) === 1;
}
return $this->path;
} | If $path is set - returns TRUE if the path pattern mathes the current URL path
If $path is not set or NULL - returns the current URL path
@param null|string $pattern
@return string|bool | entailment |
public function render($file, $data = array(), $merge = true, $default = '')
{
settype($data, 'array');
$templates = $this->getTemplateFiles($file);
if ($merge) {
$data = array_merge($data, $this->getDefaultData());
}
$rendered = null;
$this->hook->attach('template.render', $templates, $data, $rendered, $this);
if (isset($rendered)) {
return trim($rendered);
}
list($original, $overridden) = $templates;
if (is_file("$overridden.php")) {
$template = "$overridden.php";
} else if (is_file("$original.php")) {
$template = "$original.php";
} else {
return $default;
}
$rendered = $this->renderPhpTemplate($template, $data);
return trim($rendered);
} | Renders a template
@param string $file
@param array $data
@param boolean $merge
@param string $default
@return string | entailment |
protected function getTemplateFiles($file)
{
$module_id = $this->theme;
if (strpos($file, '|') !== false) {
list($module_id, $file) = explode('|', $file, 2);
} else if (gplcart_path_is_absolute($file)) {
$template = substr($file, 0, (strrpos($file, '.')));
return array($template, $template);
}
return array(
GC_DIR_MODULE . "/$module_id/templates/$file",
GC_DIR_MODULE . "/{$this->theme}/override/templates/$module_id/$file"
);
} | Returns an array of full template paths without file extension
@param string $file
@return array | entailment |
public function isPosted($key = null)
{
if (isset($key)) {
$value = $this->request->post($key, null);
return isset($value);
}
return $this->server->requestMethod() === 'POST';
} | Whether the key exists in POST query or current query is POST type
@param string|null $key
@return boolean | entailment |
public function getPosted($name, $default = null, $filter = true, $type = 'string')
{
return $this->request->post($name, $default, $filter, $type);
} | Returns a data from POST query
@param string $name
@param mixed $default
@param bool|string $filter
@param string $type
@return mixed | entailment |
public function isQuery($key = null)
{
$value = $this->request->get($key);
return !empty($value);
} | Whether a key is presented in the GET query
@param string|null $key
@return boolean | entailment |
public function getQuery($key = null, $default = null, $type = 'string')
{
return $this->request->get($key, $default, $type);
} | Returns a GET query
@param string|null $key
@param mixed $default
@param string|null $type
@return mixed | entailment |
protected function setThemeProperties()
{
$this->theme_frontend = $this->config('theme', 'frontend');
$this->theme_backend = $this->config('theme_backend', 'backend');
if ($this->is_backend) {
$this->theme = $this->theme_backend;
} elseif ($this->is_install) {
$this->theme = $this->theme_frontend;
} elseif (!empty($this->current_store)) {
$this->theme_frontend = $this->store->getConfig('theme');
$this->theme = $this->theme_frontend;
}
$this->hook->attach('theme', $this);
if (empty($this->theme)) {
$this->response->outputError404();
}
$this->current_theme = $this->module->getInfo($this->theme);
if (empty($this->current_theme)) {
$this->response->outputError404();
}
$this->theme_settings = (array) $this->getModuleSettings($this->theme, null, array());
$this->templates = $this->getDefaultTemplates();
if (!empty($this->current_theme['data']['templates'])) {
$this->templates = array_merge($this->templates, $this->current_theme['data']['templates']);
}
} | Sets theme properties | entailment |
public function getModuleSettings($module_id, $key = null, $default = null)
{
return $this->module->getSettings($module_id, $key, $default);
} | Returns all or a single module setting
@param string $module_id
@param null|string $key
@param mixed $default
@return mixed | entailment |
public function setData($key, $value)
{
gplcart_array_set($this->data, $key, $value);
return $this->data;
} | Sets a template variable
@param string|array $key
@param mixed $value
@return array | entailment |
public function setError($key, $value)
{
if (isset($key)) {
gplcart_array_set($this->errors, $key, $value);
} else {
$this->errors = (array) $value;
}
return $this->errors;
} | Sets an error
@param null|string|array $key
@param mixed $value
@return array | entailment |
public function setSubmitted($key = null, $value = null, $filter = true)
{
if (!isset($key)) {
if (isset($value)) {
return $this->submitted = (array) $value;
}
$this->submitted = (array) $this->request->post(null, array(), $filter, 'array');
return $this->submitted;
}
if (!isset($value) && empty($this->submitted)) {
$this->post_key = (string) $key;
$this->submitted = (array) $this->request->post($key, array(), $filter, 'array');
return $this->submitted;
}
gplcart_array_set($this->submitted, $key, $value);
return $this->submitted;
} | Sets an array of submitted data
@param string|array|null $key
@param mixed $value
@param boolean|string $filter
@return array | entailment |
public function filterSubmitted(array $allowed)
{
$this->submitted = array_intersect_key($this->submitted, array_flip($allowed));
return $this->submitted;
} | Limit an array of submitted data to the allowed keys
@param array $allowed
@return array | entailment |
public function setSubmittedBool($key)
{
$bool = (bool) $this->getSubmitted($key);
$this->setSubmitted($key, $bool);
return $bool;
} | Converts a submitted value to boolean
@param string|array $key
@return boolean | entailment |
public function setSubmittedArray($key)
{
$value = $this->getSubmitted($key);
if (isset($value) && is_string($value)) {
$array = gplcart_string_explode_multiline($value);
$this->setSubmitted($key, $array);
return $array;
}
return array();
} | Converts a submitted value to array using multiline delimiter
@param string|array $key
@return array | entailment |
public function getSubmitted($key = null, $default = null)
{
if (isset($key)) {
$result = gplcart_array_get($this->submitted, $key);
return isset($result) ? $result : $default;
}
return $this->submitted;
} | Returns a submitted value
@param string|array $key
@param mixed $default
@return mixed | entailment |
public function getData($key = null, $default = null)
{
if (!isset($key)) {
return $this->data;
}
$result = gplcart_array_get($this->data, $key);
return isset($result) ? $result : $default;
} | Returns a value from an array of template variables
@param string|array|null $key
@param mixed
@return mixed | entailment |
protected function controlCommonAccess()
{
if (!$this->isInstall()) {
if (!empty($this->uid)) {
$this->controlAccessCredentials();
}
$this->controlCsrf();
$this->controlAccessUpload();
$this->controlAccessRestrictedArea();
$this->controlAccessAdmin();
$this->controlAccessAccount();
}
} | Controls user access to the current page | entailment |
protected function controlAccessCredentials()
{
if (empty($this->current_user['hash']) || empty($this->current_user['status'])) {
$this->session->delete();
$this->url->redirect('login');
}
if (!gplcart_string_equals($this->current_user['hash'], $this->user->getSession('hash'))) {
$this->session->delete();
$this->url->redirect('login');
}
if ($this->current_user['role_id'] != $this->user->getRoleId()) {
$this->session->delete();
$this->url->redirect('login');
}
} | Controls the current user credentials, such as status, role, password hash... | entailment |
protected function controlAccessRestrictedArea()
{
if (($this->is_backend || $this->url->isAccount()) && empty($this->uid)) {
$this->url->redirect('login', array('target' => $this->path));
}
} | Controls access to restricted areas | entailment |
protected function controlCsrf()
{
if ($this->isPosted()
&& !$this->isInternalRoute()
&& (!isset($this->current_route['token']) || !empty($this->current_route['token']))) {
$token = $this->request->post('token', '', false, 'string');
if (!gplcart_string_equals($token, $this->token)) {
$this->response->outputError403();
}
}
} | Prevent Cross-Site Request Forgery (CSRF) | entailment |
protected function controlToken($key = null)
{
$control = isset($key) ? isset($this->query[$key]) : !empty($this->query);
if ($control && (empty($this->query['token']) || !gplcart_string_equals($this->token, $this->query['token']))) {
$this->response->outputError403();
}
} | Controls token in the URL query
@param null|string $key | entailment |
protected function controlAccessAdmin()
{
if ($this->is_backend && !$this->isSuperadmin()) {
if (empty($this->current_user['role_status']) || !$this->access('admin')) {
$this->redirect('/', $this->text('No access'), 'warning');
}
if (isset($this->current_route['access']) && !$this->access($this->current_route['access'])) {
$this->setHttpStatus(403);
}
}
} | Controls access to admin pages | entailment |
protected function controlAccessAccount()
{
$account_id = $this->url->getAccountId();
if ($account_id === false || $this->uid === $account_id) {
return null;
}
if ($this->isSuperadmin($account_id) && !$this->isSuperadmin()) {
$this->setHttpStatus(403);
return null;
}
if (!$this->access('user')) {
$this->setHttpStatus(403);
}
} | Controls access to account pages | entailment |
protected function controlMaintenanceMode()
{
$allowed_path = $this->is_install
|| $this->is_backend
|| in_array($this->path, array('login', 'logout', 'forgot'));
if ($this->is_maintenance && !$allowed_path) {
if (!$this->isFront()) {
$this->redirect('/');
}
$this->outputMaintenance();
}
} | Switches the site to maintenance mode | entailment |
public function redirect($url = '', $message = '', $severity = 'info', $exclude_lang = false)
{
$this->setMessage($message, $severity, true);
$parsed = parse_url($url);
$query = array();
if (isset($parsed['query'])) {
parse_str($parsed['query'], $query);
}
$full = strpos($url, $this->base) === 0;
$this->url->redirect($url, (array) $query, $full, $exclude_lang);
} | Redirects to a new location
@param string $url
@param string $message
@param string $severity
@param boolean $exclude_lang | entailment |
public function setTitle($title, $both = true)
{
$this->data['_head_title'] = strip_tags($title);
if ($both && !isset($this->data['_page_title'])) {
$this->setPageTitle($title);
}
} | Sets page <title> tag
@param string $title
@param boolean $both | entailment |
protected function setJsTranslation(array $scripts)
{
if (!empty($this->langcode) && !is_file($this->translation->getContextJsFile())) {
foreach ($scripts as $key => $script) {
if (strpos($key, 'system/modules/') === 0
&& strpos($key, '/vendor/') === false
&& !empty($script['file'])) {
$string = file_get_contents($script['file']);
$this->translation->createJsTranslation($string);
}
}
}
} | Extracts translatable strings from JS files and creates translation
@param array $scripts | entailment |
protected function prepareOutput(&$templates, array &$options)
{
if (!empty($this->http_status)) {
$title = (string) $this->response->getStatus($this->http_status);
$this->setTitle($title, false);
$templates = "common/status/{$this->http_status}";
$options['headers'] = $this->http_status;
}
} | Prepare output
@param mixed $templates
@param array $options | entailment |
protected function prepareDataOutput()
{
$this->data['_css'] = $this->getCss();
foreach (array('top', 'bottom') as $position) {
$this->data["_js_$position"] = $this->getJs($position);
$this->setJsTranslation($this->data["_js_$position"]);
}
$this->hook->attach('template.data', $this->data, $this);
gplcart_array_sort($this->data['_css']);
gplcart_array_sort($this->data['_js_top']);
gplcart_array_sort($this->data['_js_bottom']);
} | Prepare template data variables before output | entailment |
protected function renderOutput($templates)
{
$html = '';
if (!$this->isInternalRoute()) {
if (!is_array($templates)) {
$templates = array('region_content' => (string) $templates);
}
$templates = array_merge($this->templates, $templates);
$layout = $templates['layout'];
unset($templates['layout']);
$body = $data = $this->data;
foreach ($templates as $id => $template) {
if (strpos($id, 'region_') === 0) {
$body[$id] = $this->renderRegion($id, $template);
}
}
$data['_head'] = $data['_body'] = '';
if (!empty($templates['head'])) {
$data['_head'] = $this->render($templates['head'], $this->data);
}
if (!empty($templates['body'])) {
$data['_body'] = $this->render($templates['body'], $body);
}
$html = $this->render($layout, $data, false);
}
$this->hook->attach('template.output', $html, $this);
return $html;
} | Renders all templates before sending them to a browser
@param array|string $templates
@return string | entailment |
protected function renderRegion($region, $template)
{
if (!isset($this->data[$region])) {
return $this->render($template, $this->data);
}
$this->data[$region] = (array) $this->data[$region];
gplcart_array_sort($this->data[$region]);
$items = array();
foreach ($this->data[$region] as $item) {
$items[] = isset($item['rendered']) ? (string) $item['rendered'] : (string) $item;
}
$this->data[$region] = $this->render($template, array($region => $items));
return $this->data[$region];
} | Renders a region
@param string $region
@param string $template
@return string | entailment |
final public function output($templates = null, array $options = array())
{
if (empty($templates)) {
$templates = $this->templates;
}
$this->prepareDataOutput();
$this->prepareOutput($templates, $options);
$this->response->outputHtml($this->renderOutput($templates), $options);
} | Outputs rendered page
@param null|array|string $templates
@param array $options | entailment |
public function setRegion($region, $item)
{
if (is_array($item)) {
$template = array_shift($item);
$data = $item ? reset($item) : array();
$content = $this->render($template, $data);
} else {
$content = trim($item);
}
if ($content !== '' && isset($this->templates["region_$region"])) {
$weight = 1;
if (isset($this->data["region_$region"])) {
$weight = count($this->data["region_$region"]) + 1;
}
$this->data["region_$region"][] = array('rendered' => $content, 'weight' => $weight);
}
} | Adds an item to a region
@param string $region
@param string|array $item Expected array format:
first item - template, second - variables for $this->render() | entailment |
public function renderPhpTemplate($template, array $data)
{
extract($data, EXTR_SKIP);
unset($data); // Kill duplicates
ob_start();
include $template;
return ob_get_clean();
} | Renders PHP templates
@param string $template
@param array $data
@return string | entailment |
protected function setDefaultJs()
{
foreach ($this->getDefaultData() as $key => $value) {
$this->setJsSettings(ltrim($key, '_'), $value, 60);
}
$json = gplcart_json_encode($this->translation->loadJsTranslation());
$this->setJs("Gplcart.translations=$json;");
} | Adds default JS | entailment |
public function setJsSettings($key, $data, $weight = null)
{
$asset = array(
'type' => 'js',
'weight' => $weight,
'key' => 'js_settings',
'merge' => 'js_settings',
'asset' => array($key => $data)
);
$this->asset->set($asset);
} | Adds JSON string with JS settings
@param string $key
@param mixed $data
@param integer|null $weight | entailment |
protected function getDefaultData()
{
$data = array();
$data['_uid'] = $this->uid;
$data['_uri'] = $this->uri;
$data['_path'] = $this->path;
$data['_base'] = $this->base;
$data['_host'] = $this->host;
$data['_token'] = $this->token;
$data['_query'] = $this->query;
$data['_scheme'] = $this->scheme;
$data['_cart_uid'] = $this->cart_uid;
$data['_is_front'] = $this->isFront();
$data['_is_logged_in'] = !empty($this->uid);
$data['_is_admin'] = $this->access('admin');
$data['_is_superadmin'] = $this->isSuperadmin();
$data['_langcode'] = empty($this->langcode) ? 'en' : $this->langcode;
$data['_url'] = $this->scheme . $this->host . $this->base . $this->path;
return $data;
} | Returns global template variables
@return array | entailment |
protected function setDefaultData()
{
$this->data = array_merge($this->data, $this->getDefaultData());
$this->data['_version'] = gplcart_version();
$this->data['_user'] = $this->current_user;
$this->data['_store'] = $this->current_store;
$this->data['_language'] = $this->current_language;
$this->data['_maintenance'] = $this->is_maintenance;
$this->data['_messages'] = $this->session->getMessage();
$default_langcode = $this->language->getDefault();
foreach ($this->language->getList() as $code => $language) {
if (!empty($language['status']) || $code === $default_langcode) {
$this->data['_languages'][$code] = $language;
}
}
$this->data['_store_title'] = $this->store->getTranslation('title', $this->langcode);
if (!empty($this->current_store['data']['logo'])) {
$this->data['_store_logo'] = $this->image($this->current_store['data']['logo']);
}
if (!empty($this->current_store['data']['favicon'])) {
$this->data['_store_favicon'] = $this->image($this->current_store['data']['favicon']);
}
$this->setClasses();
$this->setDefaultJs();
} | Sets default template variables | entailment |
protected function setClasses()
{
$classes = array();
if (isset($this->current_route['pattern'])) {
$pattern = $this->current_route['pattern'] ? $this->current_route['pattern'] : 'front';
foreach (explode('/', $pattern) as $part) {
if (ctype_alpha($part)) {
$classes[] = "gc-$part";
}
}
}
if ($this->is_maintenance) {
$classes[] = "gc-maintenance";
}
$this->data['_classes'] = $classes;
} | Sets an array of body CSS classes | entailment |
public function setJs($script, array $options = array())
{
$options['type'] = 'js';
$options['asset'] = $script;
return $this->asset->set($options);
} | Adds a JS on the page
@param string $script
@param array $options
@return bool|array | entailment |
public function setCss($css, array $options = array())
{
$options['asset'] = $css;
$options['type'] = 'css';
return $this->asset->set($options);
} | Adds a CSS on the page
@param string $css
@param array $options
@return bool|array | entailment |
public function addAssetLibrary($library_id, array $options = array())
{
$added = array();
foreach ($this->library->getFiles($library_id) as $file) {
$extension = pathinfo($file, PATHINFO_EXTENSION);
if ($extension === 'js') {
$result = $this->setJs($file, $options);
} else if ($extension === 'css') {
$result = $this->setCss($file, $options);
}
if (!empty($result)) {
$added[] = $file;
}
}
return $added;
} | Adds single or multiple asset libraries
@param string|array $library_id
@param array $options
@return array | entailment |
public function setMeta($content)
{
$key = '_meta_tags';
if (!isset($this->data[$key])) {
$this->data[$key] = array();
}
$this->data[$key][] = $content;
} | Sets a meta tag on the page
@param array $content | entailment |
public function setBreadcrumb(array $breadcrumb)
{
$key = '_breadcrumbs';
if (!isset($this->data[$key])) {
$this->data[$key] = array();
}
$this->data[$key][] = $breadcrumb;
} | Sets a single page breadcrumb
@param array $breadcrumb | entailment |
protected function setMetaEntity(array $data)
{
if (!empty($data['meta_title'])) {
$this->setTitle($data['meta_title'], false);
}
if (!empty($data['meta_description'])) {
$this->setMeta(array('name' => 'description', 'content' => $data['meta_description']));
}
$this->setMeta(array('rel' => 'canonical', 'href' => $this->path));
} | Set meta tags on entity page
@param array $data | entailment |
public function setHtmlFilter($data)
{
$role_id = isset($data['role_id']) ? $data['role_id'] : 0;
$this->current_filter = $this->filter->getByRole($role_id);
} | Sets HTML filter globally
@param array $data | entailment |
public function hasErrors($message = true)
{
if (empty($this->errors)) {
return false;
}
if ($message) {
$this->setMessage($this->text('One or more errors occurred'), 'danger');
}
if (isset($this->post_key)) {
$this->setData($this->post_key, $this->submitted);
}
return true;
} | Returns true if an error occurred and pass back to template the submitted data
@param boolean $message
@return boolean | entailment |
public function validateComponent($handler_id, array $options = array())
{
$result = $this->validator->run($handler_id, $this->submitted, $options);
if ($result === true) {
return array();
}
return $this->errors = (array) $result;
} | Validates a submitted set of elements
@param string $handler_id
@param array $options
@return array | entailment |
protected function validateElement($field, $handler_id, $arguments = array())
{
if (is_array($field)) {
$label = reset($field);
$field = key($field);
}
$options = array(
'field' => $field,
'arguments' => (array) $arguments,
'label' => empty($label) ? $this->text('Field') : $label
);
$result = $this->validator->run($handler_id, $this->submitted, $options);
if ($result === true) {
return true;
}
settype($result, 'array');
$this->errors = gplcart_array_merge($this->errors, $result);
return false;
} | Validates a single element
@param string|array $field
@param string $handler_id
@param string|array $arguments
@return boolean | entailment |
public function setMessage($messages, $severity = 'info', $once = false)
{
if (!empty($messages)) {
foreach (gplcart_array_flatten((array) $messages) as $message) {
if ($once) {
$this->session->setMessage($message, $severity);
} else {
$this->data['_messages'][$severity][] = $message;
}
}
}
} | Sets a message or an array of messages
@param string|array $messages
@param string $severity
@param bool $once | entailment |
public function setFilter(array $allowed = array(), $query = null)
{
if (!isset($query)) {
$query = $this->getFilterQuery();
}
$this->setFilterData($allowed, $query);
$this->query_filter = array_filter($query, 'is_string');
} | Sets filter variables to the data array
@param array $allowed
@param array $query | entailment |
public function getFilterQuery(array $default = array(), $allowed = array())
{
$query = $this->query;
foreach ($query as $key => $value) {
if (!is_string($value)) {
continue;
}
if ($key === 'sort' && strpos($value, '-') !== false) {
list($sort, $order) = explode('-', $value, 2);
$query['sort'] = $sort;
$query['order'] = $order;
}
if ($value === 'any') {
unset($query[$key]);
}
}
$query += $default;
if (empty($allowed)) {
return $query;
}
return array_intersect_key($query, array_flip($allowed));
} | Returns an array of prepared GET values used for filtering and sorting
@param array $default
@param array $allowed
@return array | entailment |
public function setPager(array $options)
{
$pager = $this->getPager($options);
$this->data['_pager'] = $pager['rendered'];
return $pager['limit'];
} | Sets the pager
@param array $options
@return array | entailment |
public function getPager(array $options = array())
{
$options += array(
'query' => $this->getFilterQuery(),
'limit' => $this->config('list_limit', 20)
);
return array(
'rendered' => $this->getWidgetPager($options),
'limit' => $this->pager->getLimit()
);
} | Returns a rendered pager
@param array $options
@return array | entailment |
public function getWidgetPager(array $options)
{
$options += array(
'key' => 'p',
'page' => 1,
'template' => 'common/pager',
'query' => $this->getQuery(null, array(), 'array')
);
if (isset($options['query'][$options['key']])) {
$options['page'] = (int) $options['query'][$options['key']];
}
$options['query'][$options['key']] = '%num';
$data = array(
'options' => $options,
'pager' => $this->pager->build($options)->get()
);
return $this->render($options['template'], $data);
} | Returns the rendered pager
@param array $options
@return string | entailment |
public function routeHttp()
{
if ($this->config->isInitialized() || $this->url->isInstall()) {
$this->route->process();
} else {
$this->url->redirect('install');
}
} | Routes HTTP requests | entailment |
public function init(Request $request, $postType, $id, $method, $customId = '')
{
// Lets validate if the post type exists and if so, continue.
$postTypeModel = $this->getPostType($postType);
if(!$postTypeModel){
$errorMessages = 'You are not authorized to do this.';
return $this->abort($errorMessages);
}
$config = $this->getConfig($postTypeModel);
// Check if the post type has a identifier
if(empty($postTypeModel->identifier)){
$errorMessages = 'The post type does not have a identifier.';
if(array_has($postTypeModel->errorMessages, 'post_type_identifier_does_not_exist')){
$errorMessages = $postTypeModel->errorMessages['post_type_identifier_does_not_exist'];
}
return $this->abort($errorMessages, $config);
}
$post = $this->findPostInstance($postTypeModel, $request, $postType, $id, 'show_post');
if(!$post){
$errorMessages = 'Post does not exist.';
if(array_has($postTypeModel->errorMessages, 'post_does_not_exist')){
$errorMessages = $postTypeModel->errorMessages['post_does_not_exist'];
}
return $this->abort($errorMessages, $config);
}
if(method_exists($postTypeModel, 'show_custom_get_' . $method)){
$methodToEdit = 'show_custom_get_' . $method;
return $postTypeModel->$methodToEdit($request, $id, $customId, $post);
} else {
$errorMessages = 'The post type does not have the custom show get method ' . $method . '.';
if(array_has($postTypeModel->errorMessages, 'post_type_does_not_have_the_support_custom_show_getmethod')){
$errorMessages = $postTypeModel->errorMessages['post_type_does_not_have_the_support_custom_show_getmethod'];
}
return $this->abort($errorMessages);
}
} | Display a single post | entailment |
public function get($zone_id)
{
$result = null;
$this->hook->attach('zone.get.before', $zone_id, $result, $this);
if (isset($result)) {
return $result;
}
$result = $this->db->fetch('SELECT * FROM zone WHERE zone_id=?', array($zone_id));
$this->hook->attach('zone.get.after', $zone_id, $result, $this);
return $result;
} | Loads a zone from the database
@param int $zone_id
@return array | entailment |
public static function setLogin($user, $isAdmin = false, $expires = null)
{
if($expires === false)
$expires = time() + 31536000;
Cookie::set('user', $user, array('expires' => $expires));
Cookie::set('is_admin', $isAdmin, array('expires' => $expires));
} | 设置自动登录 | entailment |
public static function hasPurview($controller = null, $method = null)
{
if($controller && $method){
$ctr = ucfirst(Config::$application) . '\\' . Config::$controller['0'] . '\\' . ucfirst($controller);
}else{
$ctr = Request::$controller;
$explode = explode('\\', $ctr);
$controller = strtolower(end($explode));
$method = Request::$method;
}
if(!class_exists($ctr)){
return false;
}
$purview = self::getPurviewCache();
if(!$purview && Config::$authPurviewMethod){
$class = Config::$authPurviewMethod['0'];
$call = Config::$authPurviewMethod['1'];
$class::$call();
}
$white = property_exists($ctr, 'authWhite') && isset($ctr::$authWhite['purview']) ? $ctr::$authWhite['purview'] : array();
if(
!in_array(strtolower($method), $white) &&
!in_array(strtolower($controller . '@' . $method), $purview) &&
!in_array(strtolower($controller . '@*'), $purview)
){
return false;
}
return true;
} | 判断是否有权限 | entailment |
public function validator(Factory $factory)
{
if (!$this->shouldBeValidated()) {
return $factory->make([], []);
}
$rules = app()->call([$this, 'rules']);
return $factory->make(
$this->all(), $rules, $this->messages(), $this->attributes()
);
} | Injects validator with rules and data if validation is required
@param Factory $factory
@return Validator | entailment |
protected function execute(InputInterface $input, OutputInterface $output)
{
$targetArg = rtrim($input->getArgument('target'), '/');
if (!is_dir($targetArg)) {
throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
}
if (!function_exists('symlink') && $input->getOption('symlink')) {
throw new \InvalidArgumentException('The symlink() function is not available on your system. You need to install the assets without the --symlink option.');
}
$filesystem = $this->getServiceManager()->get('filesystem');
// Create the modules directory otherwise symlink will fail.
$filesystem->mkdir($targetArg . '/modules/', 0777);
$output->writeln(sprintf("Installing assets using the <comment>%s</comment> option", $input->getOption('symlink') ? 'symlink' : 'hard copy'));
foreach ($this->getServiceManager()->get('modulemanager')->getLoadedModules() as $module) {
if (!method_exists($module, 'getPath')) {
continue;
}
if (!is_dir($originDir = $module->getPath() . '/resources/public')) {
continue;
}
$modulesDir = $targetArg . '/modules/';
$targetDir = $modulesDir . str_replace('module', '', strtolower($module->getName()));
$output->writeln(sprintf('Installing assets for <comment>%s</comment> into <comment>%s</comment>', $module->getNamespace(), $targetDir));
$filesystem->remove($targetDir);
if ($input->getOption('symlink')) {
if ($input->getOption('relative')) {
$relativeOriginDir = $filesystem->makePathRelative($originDir, realpath($modulesDir));
} else {
$relativeOriginDir = $originDir;
}
$filesystem->symlink($relativeOriginDir, $targetDir);
} else {
$filesystem->mkdir($targetDir, 0777);
// We use a custom iterator to ignore VCS files
$filesystem->mirror($originDir, $targetDir, Finder::create()->in($originDir));
}
}
} | {@inheritdoc}
@throws \InvalidArgumentException When the target directory does not exist or symlink cannot be used | entailment |
public function category(array &$submitted, array $options = array())
{
$this->options = $options;
$this->submitted = &$submitted;
$this->validateCategory();
$this->validateWeight();
$this->validateBool('status');
$this->validateTitle();
$this->validateMetaTitle();
$this->validateMetaDescription();
$this->validateDescriptionCategory();
$this->validateGroupCategory();
$this->validateParentCategory();
$this->validateTranslation();
$this->validateImages();
$this->validateAlias();
$this->validateUploadImages('category');
$this->unsetSubmitted('update');
return $this->getResult();
} | Performs full category data validation
@param array $submitted
@param array $options
@return boolean|array | entailment |
protected function validateCategory()
{
$id = $this->getUpdatingId();
if ($id === false) {
return null;
}
$data = $this->category->get($id);
if (empty($data)) {
$this->setErrorUnavailable('update', $this->translation->text('Category'));
return false;
}
$this->setUpdating($data);
return true;
} | Validates a category to be updated
@return boolean|null | entailment |
protected function validateParentCategory()
{
$field = 'parent_id';
$value = $this->getSubmitted($field);
if (empty($value)) {
return null;
}
$label = $this->translation->text('Parent category');
if (!is_numeric($value)) {
$this->setErrorNumeric($field, $label);
return false;
}
$category = $this->getSubmitted('category');
if (isset($category['category_id']) && $category['category_id'] == $value) {
$this->setErrorInvalid($field, $label);
return false;
}
$parent_category = $this->category->get($value);
if (empty($parent_category['category_id'])) {
$this->setErrorUnavailable($field, $label);
return false;
}
return true;
} | Validates parent category group ID
@return boolean|null | entailment |
protected function validateDescriptionCategory()
{
$fields = array(
'description_1' => $this->translation->text('First description'),
'description_2' => $this->translation->text('Second description')
);
$errors = 0;
foreach ($fields as $field => $label) {
$value = $this->getSubmitted($field);
if (isset($value) && mb_strlen($value) > 65535) {
$errors++;
$this->setErrorLengthRange($field, $label, 0, 65535);
}
}
return empty($errors);
} | Validates first and second description
@return boolean | entailment |
public function userLogOut()
{
$result = $this->user_action->logout();
$this->redirect($result['redirect'], $result['message'], $result['severity']);
} | Logs out a user | entailment |
public function createService(ServiceLocatorInterface $serviceLocator)
{
$pluginManagerClass = static::PLUGIN_MANAGER_CLASS;
/* @var $plugins \Zend\ServiceManager\AbstractPluginManager */
$plugins = new $pluginManagerClass();
$plugins->setServiceLocator($serviceLocator);
return $plugins;
} | Create and return a plugin manager.
Classes that extend this should provide a valid class for
the PLUGIN_MANGER_CLASS constant.
@param ServiceLocatorInterface $serviceLocator
@return \Zend\ServiceManager\AbstractPluginManager | entailment |
public function listFile()
{
$this->downloadFile();
$this->actionListFile();
$this->setTitleListFile();
$this->setBreadcrumbListFile();
$this->setFilterListFile();
$this->setPagerListFile();
$this->setData('files', $this->getListFile());
$this->setData('entities', $this->file->getEntities());
$this->outputListFile();
} | Displays the file overview page | entailment |
protected function downloadFile()
{
$file_id = $this->getQuery('download');
if (!empty($file_id)) {
$file = $this->file->get($file_id);
$this->download(gplcart_file_absolute($file['path']));
}
} | Downloads a file | entailment |
protected function actionListFile()
{
list($selected, $action) = $this->getPostedAction();
$disk = $db = 0;
foreach ($selected as $file_id) {
if ($action === 'delete' && $this->access('file_delete')) {
$this->file->deleteAll($file_id, $db, $disk);
}
}
if (!empty($selected)) {
$severity = $disk && $disk == $db ? 'success' : 'warning';
$message = $this->text('Deleted from database: %db, disk: %disk', array('%db' => $db, '%disk' => $disk));
$this->setMessage($message, $severity);
}
} | Applies an action to the selected files | entailment |
protected function setPagerListFile()
{
$conditions = $this->query_filter;
$conditions['count'] = true;
$pager = array(
'query' => $this->query_filter,
'total' => (int) $this->file->getList($conditions)
);
return $this->data_limit = $this->setPager($pager);
} | Set pager
@return array | entailment |
protected function getListFile()
{
$conditions = $this->query_filter;
$conditions['limit'] = $this->data_limit;
$list = (array) $this->file->getList($conditions);
$this->prepareListFile($list);
return $list;
} | Returns an array of files
@return array | entailment |
protected function prepareListFile(array &$list)
{
foreach ($list as &$item) {
$path = strval(str_replace("\0", "", $item['path']));
$item['url'] = '';
if ($path && file_exists(GC_DIR_FILE . '/' . $path)) {
$item['url'] = $this->url->file($item['path']);
}
}
} | Prepare an array of files
@param array $list | entailment |
public function editFile($file_id = null)
{
$this->downloadFile();
$this->setFile($file_id);
$this->setTitleEditFile();
$this->setBreadcrumbEditFile();
$this->controlAccessEditFile();
$this->setData('file', $this->data_file);
$this->setData('can_delete', $this->canDeleteFile());
$this->setData('extensions', $this->file->supportedExtensions(true));
$this->setData('languages', $this->language->getList(array('enabled' => true)));
$this->submitEditFile();
$this->outputEditFile();
} | Displays the file edit page
@param null|integer $file_id | entailment |
protected function canDeleteFile()
{
return isset($this->data_file['file_id'])
&& $this->access('file_delete')
&& $this->file->canDelete($this->data_file['file_id']);
} | Whether the file can be deleted
@return bool | entailment |
protected function setFile($file_id)
{
$this->data_file = array();
if (is_numeric($file_id)) {
$conditions = array(
'language' => 'und',
'file_id' => $file_id
);
$this->data_file = $this->file->get($conditions);
if (empty($this->data_file)) {
$this->outputHttpStatus(404);
}
$this->prepareFile($this->data_file);
}
} | Sets a file data
@param integer $file_id | entailment |
protected function submitEditFile()
{
if ($this->isPosted('delete') && isset($this->data_file['file_id'])) {
$this->deleteFile();
} else if ($this->isPosted('save') && $this->validateEditFile()) {
if (isset($this->data_file['file_id'])) {
$this->updateFile();
} else {
$this->addFile();
}
}
} | Saves an array of submitted values | entailment |
protected function deleteFile()
{
$this->controlAccess('file_delete');
if ($this->file->deleteAll($this->data_file['file_id'])) {
$this->redirect('admin/content/file', $this->text('File has been deleted from database and disk'), 'success');
}
// Redirect in any case as file can be already deleted from the database
$this->redirect('admin/content/file', $this->text('An error occurred'), 'warning');
} | Deletes a file from the database an disk | entailment |
protected function validateEditFile()
{
$this->setSubmitted('file');
$this->setSubmitted('update', $this->data_file);
$this->validateComponent('file');
return !$this->hasErrors();
} | Validates a submitted data | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.