sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
protected function getRecentProduct()
{
$items = $this->product_view->set($this->data_product['product_id'], $this->cart_uid);
$product_ids = array();
foreach ((array) $items as $id => $item) {
if ($item['product_id'] != $this->data_product['product_id']) {
$product_ids[$id] = $item['product_id'];
}
}
if (empty($product_ids)) {
return array();
}
$products = $this->getProducts(array('product_id' => $product_ids));
// Retain original order
uksort($products, function ($key1, $key2) use ($product_ids) {
return (array_search($key1, $product_ids) < array_search($key2, $product_ids));
});
return $products;
} | Returns an array of recent products
@return array | entailment |
protected function setBackendInstances()
{
$this->job = $this->getInstance('gplcart\\core\\models\\Job');
$this->help = $this->getInstance('gplcart\\core\\models\\Help');
$this->bookmark = $this->getInstance('gplcart\\core\\models\\Bookmark');
} | Sets default class instances | entailment |
protected function setBackendData()
{
$this->data['_job'] = $this->getWidgetJob($this->job);
$this->data['_stores'] = (array) $this->store->getList();
$this->data['_menu'] = $this->getWidgetAdminMenu($this->route);
$this->data['_help'] = $this->help->getByPattern($this->current_route['simple_pattern'], $this->langcode);
$bookmarks = $this->bookmark->getList(array('user_id' => $this->uid));
$this->data['_is_bookmarked'] = isset($bookmarks[$this->path]);
$this->data['_bookmarks'] = array_splice($bookmarks, 0, $this->config('bookmark_limit', 5));
} | Sets default variables for backend templates | entailment |
protected function setCron()
{
$interval = (int) $this->config('cron_interval', 24 * 60 * 60);
if (!empty($interval) && (GC_TIME - $this->config('cron_last_run', 0)) > $interval) {
$url = $this->url('cron', array('key' => $this->config('cron_key', '')));
$this->setJs("\$(function(){\$.get('$url', function(data){});});", array('position' => 'bottom'));
}
} | Set up self-executing CRON | entailment |
protected function getPostedAction($message = true)
{
$action = $this->getPosted('action', array(), true, 'array');
if (!empty($action)) {
if (empty($action['name'])) {
$error = $this->text('An error occurred');
} else if (empty($action['items'])) {
$error = $this->text('Please select at least one item');
} else {
$parts = explode('|', $action['name'], 2);
return array($action['items'], $parts[0], isset($parts[1]) ? $parts[1] : null);
}
if (isset($error) && $message) {
$this->setMessage($error, 'warning');
}
}
return array(array(), null, null);
} | Returns an array of submitted bulk action
@param bool $message
@return array | entailment |
protected function validateCastValue($val)
{
try {
$val = (string) $val;
} catch (\Exception $e) {
$val = json_encode($val);
}
switch ($this->format()) {
case 'email':
if (strpos($val, '@') === false) {
throw $this->getValidationException('value is not a valid email', $val);
}
break;
case 'uri':
if (filter_var($val, FILTER_VALIDATE_URL) === false) {
throw $this->getValidationException(null, $val);
}
break;
case 'binary':
$decoded = base64_decode($val, true);
if ($decoded === false) {
throw $this->getValidationException(null, $val);
}
break;
}
return $val;
} | @param mixed $val
@return string
@throws \frictionlessdata\tableschema\Exceptions\FieldValidationException; | entailment |
public function createService(ServiceLocatorInterface $serviceLocator)
{
$em = new EventManager();
$em->setSharedManager($serviceLocator->get('SharedEventManager'));
return $em;
} | Create an EventManager instance.
Creates a new EventManager instance, seeding it with a shared instance
of SharedEventManager.
@param ServiceLocatorInterface $serviceLocator
@return EventManager | entailment |
public function field(array &$submitted, array $options = array())
{
$this->options = $options;
$this->submitted = &$submitted;
$this->validateField();
$this->validateTitle();
$this->validateWeight();
$this->validateTranslation();
$this->validateTypeField();
$this->validateWidgetField();
$this->unsetSubmitted('update');
return $this->getResult();
} | Performs full field data validation
@param array $submitted
@param array $options
@return boolean|array | entailment |
protected function validateField()
{
$id = $this->getUpdatingId();
if ($id === false) {
return null;
}
$data = $this->field->get($id);
if (empty($data)) {
$this->setErrorUnavailable('update', $this->translation->text('Field'));
return false;
}
$this->setUpdating($data);
return true;
} | Validates a field to be updated
@return boolean|null | entailment |
protected function validateWidgetField()
{
$field = 'widget';
if ($this->isExcluded($field)) {
return null;
}
$value = $this->getSubmitted($field);
if ($this->isUpdating() && !isset($value)) {
$this->unsetSubmitted($field);
return null;
}
$label = $this->translation->text('Widget');
if (empty($value)) {
$this->setErrorRequired($field, $label);
return false;
}
$types = $this->field->getWidgetTypes();
if (empty($types[$value])) {
$this->setErrorUnavailable($field, $label);
return false;
}
return true;
} | Validates a field widget type
@return boolean|null | entailment |
public function upload($post, $handler, $path = null)
{
$result = $this->transferred = null;
$this->hook->attach('file.upload.before', $post, $handler, $path, $result, $this);
if (isset($result)) {
return $result;
}
if (!empty($post['error']) || empty($post['tmp_name']) || !is_uploaded_file($post['tmp_name'])) {
return $this->translation->text('Unable to upload the file');
}
$this->setHandler($handler);
$this->setDestination($path);
$result = $this->validate($post['tmp_name'], $post['name']);
if ($result !== true) {
unlink($post['tmp_name']);
return $result;
}
try {
$result = $this->finalize($post['tmp_name'], $post['name'], true);
} catch (Exception $ex) {
$result = $ex->getMessage();
}
$this->hook->attach('file.upload.after', $post, $handler, $path, $result, $this);
return $result;
} | Uploads a file
@param array $post
@param null|string|false $handler
@param string|null $path
@return mixed | entailment |
public function uploadMultiple($files, $handler, $path = null)
{
$return = array(
'errors' => array(),
'transferred' => array()
);
if (!gplcart_file_multi_upload($files)) {
return $return;
}
foreach ($files as $key => $file) {
$result = $this->upload($file, $handler, $path);
if ($result === true) {
$return['transferred'][$key] = $this->getTransferred(true);
} else {
$return['errors'][$key] = (string) $result;
}
}
return $return;
} | Multiple file upload
@param array $files
@param null|string|false $handler
@param string|null $path
@return array | entailment |
public function download($url, $handler, $path = null)
{
$result = $this->transferred = null;
$this->hook->attach('file.download.before', $url, $handler, $path, $result, $this);
if (isset($result)) {
return $result;
}
$this->setHandler($handler);
$this->setDestination($path);
try {
$temp = $this->downloadTempFile($url);
} catch (Exception $ex) {
return $ex->getMessage();
}
try {
$this->validateHandler($temp);
} catch (Exception $ex) {
unlink($temp);
return $ex->getMessage();
}
try {
$result = $this->finalize($temp, $this->destination, false);
} catch (Exception $ex) {
$result = $ex->getMessage();
}
$this->hook->attach('file.download.after', $url, $handler, $temp, $result, $this);
return $result;
} | Downloads a file from a remote URL
@param string $url
@param null|false|string $handler
@param string|null $path
@return mixed | entailment |
protected function downloadTempFile($url)
{
$temp = $this->file->getTempFile();
$fh = fopen($temp, "w");
if (!is_resource($fh)) {
throw new UnexpectedValueException($this->translation->text('File handle is not a valid resource'));
}
$response = $this->http->request($url);
fwrite($fh, $response['data']);
fclose($fh);
return $temp;
} | Writes a temporary file from a remote file
@param string $url
@return string
@throws UnexpectedValueException | entailment |
protected function finalize($temp, $to, $upload)
{
if (!isset($this->destination)) {
$this->transferred = $temp;
return true;
}
$directory = gplcart_file_absolute(gplcart_file_relative($this->destination));
$pathinfo = $upload ? pathinfo($to) : pathinfo($directory);
if ($upload) {
$filename = $this->prepareFileName($pathinfo['filename'], $pathinfo['extension']);
} else {
$filename = $pathinfo['basename'];
$directory = $pathinfo['dirname'];
}
if (!file_exists($directory) && !mkdir($directory, 0775, true)) {
unlink($temp);
throw new UnexpectedValueException($this->translation->text('Unable to create @name', array(
'@name' => $directory)));
}
$destination = "$directory/$filename";
if ($upload) {
$destination = gplcart_file_unique($destination);
}
$copied = copy($temp, $destination);
unlink($temp);
if (!$copied) {
throw new UnexpectedValueException($this->translation->text('Unable to move @source to @destination', array(
'@source' => $temp,
'@destination' => $destination)));
}
chmod($destination, 0644);
$this->transferred = $destination;
return true;
} | Finalize file transfer
@param string $temp
@param string $to
@param bool $upload
@return boolean
@throws UnexpectedValueException | entailment |
protected function prepareFileName($filename, $extension)
{
if ($this->config->get('file_upload_translit', 1)) {
$filename = $this->language->translit($filename, null);
}
$suffix = gplcart_string_random(6);
$clean = gplcart_file_sanitize($filename);
return "$clean-$suffix.$extension";
} | Sanitize and transliterate a filename
@param string $filename
@param string $extension
@return string | entailment |
public function validate($path, $filename = null)
{
$pathinfo = isset($filename) ? pathinfo($filename) : pathinfo($path);
if (empty($pathinfo['filename'])) {
return $this->translation->text('Unknown filename');
}
if (empty($pathinfo['extension'])) {
return $this->translation->text('Unknown file extension');
}
if ($this->handler === false) {
return true;
}
if (!isset($this->handler)) {
try {
$this->setHandlerByExtension($pathinfo['extension']);
} catch (Exception $ex) {
return $ex->getMessage();
}
}
if (!isset($this->destination) && isset($this->handler['path'])) {
$this->destination = $this->handler['path'];
}
try {
return $this->validateHandler($path, $pathinfo['extension']);
} catch (Exception $ex) {
return $ex->getMessage();
}
} | Validate a file
@param string $path
@param null|string $filename
@return boolean|string | entailment |
protected function validateHandler($file, $extension = null)
{
if (empty($this->handler['validator'])) {
throw new UnexpectedValueException($this->translation->text('Unknown handler'));
}
if (!empty($this->handler['extensions']) && isset($extension) && !in_array($extension, $this->handler['extensions'])) {
throw new RuntimeException($this->translation->text('Unsupported file extension'));
}
if (isset($this->handler['filesize']) && filesize($file) > $this->handler['filesize']) {
throw new RuntimeException($this->translation->text('File size exceeds %num bytes', array(
'%num' => $this->handler['filesize'])));
}
$result = $this->validator->run($this->handler['validator'], $file, $this->handler);
if ($result !== true) {
throw new UnexpectedValueException($result);
}
return true;
} | Validates a file using a validator
@param string $file
@param string|null $extension
@return bool
@throws UnexpectedValueException
@throws RuntimeException | entailment |
public function setHandler($id)
{
if (is_string($id)) {
$this->handler = $this->file->getHandler($id);
} else {
$this->handler = $id;
}
return $this;
} | Sets the current transfer handler
@param mixed $id
- string: load by validator ID
- false: disable validator at all,
- null: detect validator by file extension
@return $this | entailment |
protected function setHandlerByExtension($extension)
{
if (!in_array($extension, $this->file->supportedExtensions())) {
throw new RuntimeException($this->translation->text('Unsupported file extension'));
}
return $this->handler = $this->file->getHandler(".$extension");
} | Find and set handler by a file extension
@param string $extension
@return array
@throws RuntimeException | entailment |
public function listReportLibrary()
{
$this->setTitleListReportLibrary();
$this->setBreadcrumbListReportLibrary();
$this->setFilterListReportLibrary();
$this->setPagerListReportLibrary();
$this->setData('types', $this->getTypesLibrary());
$this->setData('libraries', (array) $this->getListReportLibrary());
$this->outputListReportLibrary();
} | Displays the library overview page | entailment |
protected function setPagerListReportLibrary()
{
$pager = array(
'query' => $this->query_filter,
'total' => (int) $this->getListReportLibrary(true)
);
return $this->data_limit = $this->setPager($pager);
} | Sets pager
@return array | entailment |
protected function getListReportLibrary($count = false)
{
$list = $this->library->getList();
$this->prepareListLibrary($list);
$allowed = $this->getAllowedFiltersReportLibrary();
$this->filterList($list, $allowed, $this->query_filter);
$this->sortList($list, $allowed, $this->query_filter, array('name' => 'desc'));
if ($count) {
return count($list);
}
$this->limitList($list, $this->data_limit);
return $list;
} | Returns an array of libraries
@param bool $count
@return array|int | entailment |
protected function prepareListLibrary(array &$list)
{
foreach ($list as &$item) {
$item['status'] = empty($item['errors']);
$item['has_dependencies'] = !empty($item['requires']) || !empty($item['required_by']);
}
} | Prepare an array of libraries
@param array $list | entailment |
protected function getTypesLibrary()
{
$types = array();
foreach (array_keys($this->library->getTypes()) as $id) {
$types[$id] = $this->text(ucfirst($id));
}
return $types;
} | Returns an array of library type names
@return array | entailment |
public function validateDependencies(array &$items, $enabled = false)
{
foreach ($items as &$item) {
$this->validateDependency($item, $items, $enabled);
}
return $items;
} | Validates dependency for an array of items
@param array $items
@param bool $enabled
@return array | entailment |
protected function validateDependency(&$item, $items, $enabled = false)
{
if (empty($item['dependencies'])) {
return null;
}
foreach ($item['dependencies'] as $id => $version) {
if (!isset($items[$id])) {
$item['errors'][] = array('Unknown dependency @id', array('@id' => $id));
continue;
}
if ($enabled && empty($items[$id]['status'])) {
$item['errors'][] = array('Requires @id to be enabled', array('@id' => $items[$id]['name']));
continue;
}
$components = $this->getVersionComponents($version);
if (empty($components)) {
$item['errors'][] = array('Unknown version of @name', array('@name' => $id));
continue;
}
list($operator, $number) = $components;
if ($operator === '=' && strpos($number, 'x') !== false) {
$allowed = version_compare($items[$id]['version'], $number);
} else {
$allowed = version_compare($items[$id]['version'], $number, $operator);
}
if (!$allowed) {
$item['errors'][] = array('Requires incompatible version of @name', array('@name' => $id));
}
}
return null;
} | Validates dependency for a single item
@param array $item
@param array $items
@param bool $enabled
@return null | entailment |
public function getVersionComponents($data)
{
$string = str_replace(' ', '', $data);
$matches = array();
preg_match_all('/(^(==|=|!=|<>|>|<|>=|<=)?(?=\d))(.*)/', $string, $matches);
if (empty($matches[3][0])) {
return array();
}
$operator = empty($matches[2][0]) ? '=' : $matches[2][0];
return array($operator, $matches[3][0]);
} | Extracts an array of components from strings like ">= 1.0.0"
@param string $data
@return array | entailment |
public function getDynamicProperty($name, $default = null)
{
return isset($this->dynamicProperties[$name]) ? $this->dynamicProperties[$name] : $default;
} | Read dynamic property
@param $name
@param null $default
@return mixed|null | entailment |
protected function reset()
{
$this->open = null;
$this->close = null;
$this->model = null;
$this->style = $this->config->get('style');
$this->elements = [];
} | Reset all of the properties | entailment |
public function up()
{
Schema::create('cms_config', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('option_name')->nullable();
$table->longText('option_value')->nullable();
$table->string('group')->nullable()->default('default');
$table->longText('custom')->nullable();
$table->string('type')->nullable();
$table->timestamps();
$table->index(['option_name', 'id']);
});
} | Run the migrations.
@return void | entailment |
public function set($type = null, $key = null, $value = null)
{
if (isset($type)) {
$this->request[$type]["$key"] = $value;
} else {
$this->request = array(
'get' => $_GET,
'post' => $_POST,
'files' => $_FILES,
'cookie' => $_COOKIE
);
}
return $this;
} | Sets a request parameter
@param null|string $type
@param null|string $key
@param mixed $value
@return $this | entailment |
public function base($exclude_langcode = false)
{
$base = GC_BASE;
if ($base !== '/') {
$base .= '/';
}
if (!empty($this->langcode)) {
$suffix = "{$this->langcode}/";
$base .= $suffix;
}
if ($exclude_langcode && !empty($suffix)) {
$base = substr($base, 0, -strlen($suffix));
}
return $base;
} | Returns the current base path
@param boolean $exclude_langcode
@return string | entailment |
public function post($name = null, $default = null, $filter = true, $type = null)
{
$post = $this->request['post'];
if ($filter !== 'raw') {
gplcart_array_trim($post, (bool) $filter);
}
if (isset($name)) {
$result = gplcart_array_get($post, $name);
$return = isset($result) ? $result : $default;
} else {
$return = $post;
}
gplcart_settype($return, $type, $default);
return $return;
} | Returns a data from POST request
@param string|array $name
@param mixed $default
@param bool|string $filter
@param null|string $type
@return mixed | entailment |
public function get($name = null, $default = null, $type = null)
{
$get = $this->request['get'];
gplcart_array_trim($get, true);
if (isset($name)) {
$result = gplcart_array_get($get, $name);
$return = isset($result) ? $result : $default;
} else {
$return = $get;
}
gplcart_settype($return, $type, $default);
return $return;
} | Returns a data from GET request
@param string $name
@param mixed $default
@param null|string $type
@return mixed | entailment |
public function file($name = null, $default = null)
{
$files = $this->request['files'];
if (isset($name)) {
return !empty($files[$name]['name']) ? $files[$name] : $default;
}
return $files;
} | Returns a data from FILES request
@param string $name
@param mixed $default
@return mixed | entailment |
public function cookie($name = null, $default = null, $type = null)
{
$cookie = $this->request['cookie'];
gplcart_array_trim($cookie, true);
if (isset($name)) {
$return = isset($cookie[$name]) ? $cookie[$name] : $default;
} else {
$return = $cookie;
}
gplcart_settype($return, $type, $default);
return $return;
} | Returns a data from COOKIE
@param string $name
@param mixed $default
@param null|string $type
@return mixed | entailment |
public function deleteCookie($name = null)
{
if (isset($name)) {
if (isset($this->request['cookie'][$name])) {
unset($this->request['cookie'][$name]);
return setcookie($name, '', GC_TIME - 3600, '/');
}
return false;
}
foreach (array_keys($this->request['cookie']) as $key) {
$this->deleteCookie($key);
}
return true;
} | Deletes a cookie
@param string $name
@return boolean | entailment |
public static function bankAppId($bankApp)
{
if ($bankApp == 'swedbank_företag')
throw new UserException('Bank type "swedbank_företag" is no longer valid. Please "swedbank_foretag" instead.', 1);
elseif (!isset(self::$appData[$bankApp]))
throw new UserException('Bank type does not exists, use one of the following: '.implode(', ', array_keys(self::$appData)), 2);
return self::$appData[$bankApp];
} | Bank type settings
@param string $bankApp Bank type
@return array | entailment |
public function update($field_id, array $data)
{
$result = null;
$this->hook->attach('field.update.before', $field_id, $data, $result, $this);
if (isset($result)) {
return (bool) $result;
}
unset($data['type']);
$updated = $this->db->update('field', $data, array('field_id' => $field_id));
$data['field_id'] = $field_id;
$updated += (int) $this->setTranslations($data, $this->translation_entity, 'field');
$result = $updated > 0;
$this->hook->attach('field.update.after', $field_id, $data, $result, $this);
return (bool) $result;
} | Updates a field
@param integer $field_id
@param array $data
@return boolean | entailment |
public function getWidgetTypes()
{
$types = &gplcart_static('field.widget.types');
if (isset($types)) {
return $types;
}
$types = array(
'button' => $this->translation->text('Button'),
'radio' => $this->translation->text('Radio buttons'),
'select' => $this->translation->text('Dropdown list')
);
$this->hook->attach('field.widget.types', $types, $this);
return $types;
} | Returns an array of widget types
@return array | entailment |
protected function deleteLinkedFieldValues($field_id)
{
$sql = 'DELETE fvt
FROM field_value_translation AS fvt
WHERE fvt.field_value_id IN (SELECT DISTINCT(fv.field_value_id)
FROM field_value AS fv
INNER JOIN field_value AS fv2
ON (fv.field_value_id = fv2.field_value_id)
WHERE fv.field_id = ?)';
return (bool) $this->db->run($sql, array($field_id))->rowCount();
} | Delete all field values and their translations related to the field
@param int $field_id
@return bool | entailment |
protected function deleteLinked($field_id)
{
$this->db->delete('field_value', array('field_id' => $field_id));
$this->db->delete('field_translation', array('field_id' => $field_id));
$this->db->delete('product_class_field', array('field_id' => $field_id));
} | Delete all database tables related to the field
@param int $field_id | entailment |
public function getSettings($module_id, $key = null, $default = null)
{
$module = $this->get($module_id);
if (empty($module['settings'])) {
return $default;
}
if (!isset($key)) {
return (array) $module['settings'];
}
$value = gplcart_array_get($module['settings'], $key);
return isset($value) ? $value : $default;
} | Returns module setting(s)
@param string $module_id
@param string $key
@param mixed $default
@return mixed | entailment |
public function setSettings($module_id, array $settings)
{
$result = false;
if ($this->isInstalled($module_id)) {
$this->update($module_id, array('settings' => $settings));
$result = true;
} else if ($this->isActiveTheme($module_id)) {
$data = array('status' => true, 'settings' => $settings, 'module_id' => $module_id);
$this->add($data);
$result = true;
}
return $result;
} | Adds/updates settings for a given module
@param string $module_id
@param array $settings
@return boolean | entailment |
public function update($module_id, array $data)
{
$data['modified'] = GC_TIME;
$this->db->update('module', $data, array('module_id' => $module_id));
} | Updates a module
@param string $module_id
@param array $data | entailment |
public function add(array $data)
{
$weight = (int) $this->db->fetchColumn('SELECT COUNT(*) FROM module', array());
$data += array('weight' => $weight + 1);
$data['created'] = $data['modified'] = GC_TIME;
$this->db->insert('module', $data);
} | Adds (installs) a module to the database
@param array $data | entailment |
public function getActiveThemes()
{
$themes = &gplcart_static('module.active.themes');
if (isset($themes)) {
return $themes;
}
$themes = array($this->config->get('theme_backend', 'backend'));
if (!$this->db->isInitialized()) {
return $themes;
}
$stores = $this->db->fetchAll('SELECT * FROM store', array());
foreach ($stores as $store) {
$data = unserialize($store['data']);
foreach ($data as $key => $value) {
if (strpos($key, 'theme') === 0) {
$themes[] = $value;
}
}
}
return $themes;
} | Returns an array of active theme modules
@return array | entailment |
public function getList()
{
$modules = &gplcart_static('module.list');
if (isset($modules)) {
return $modules;
}
$installed = $this->getInstalled();
$modules = array();
foreach ($this->scan() as $module_id => $info) {
$modules[$module_id] = $this->prepareInfo($module_id, $info, $installed);
}
gplcart_array_sort($modules);
return $modules;
} | Returns an array of all available modules
@return array | entailment |
public function scan($directory = GC_DIR_MODULE)
{
$modules = array();
foreach (scandir($directory) as $module_id) {
if (!$this->isValidId($module_id)) {
continue;
}
$info = $this->getInfo($module_id);
if (!isset($info['core'])) {
continue;
}
$modules[$module_id] = $info;
}
return $modules;
} | Returns an array of scanned module IDs
@param string $directory
@return array | entailment |
protected function prepareInfo($module_id, array $info, array $installed)
{
$info['directory'] = $this->getDirectory($module_id);
$info += array(
'type' => 'module',
'name' => $module_id,
'version' => null
);
// Do not override status set in module.json for locked modules
if (isset($info['status']) && !empty($info['lock'])) {
unset($installed[$module_id]['status']);
}
if ($info['version'] === 'core') {
$info['version'] = GC_VERSION;
}
if (!empty($info['dependencies'])) {
foreach ((array) $info['dependencies'] as $dependency_module_id => $dependency_version) {
if ($dependency_version === 'core') {
$info['dependencies'][$dependency_module_id] = GC_VERSION;
}
}
}
// Do not override weight set in module.json for locked modules
if (isset($info['weight']) && !empty($info['lock'])) {
unset($installed[$module_id]['weight']);
}
if (isset($installed[$module_id])) {
$info['installed'] = true;
if (empty($installed[$module_id]['settings'])) {
unset($installed[$module_id]['settings']);
}
$info = array_replace($info, $installed[$module_id]);
}
if (!empty($info['status'])) {
try {
$instance = $this->getInstance($module_id);
$info['hooks'] = $this->getHooks($instance);
$info['class'] = get_class($instance);
} catch (Exception $exc) {
return $info;
}
}
return $info;
} | Prepare module info
@param string $module_id
@param array $info
@param array $installed
@return array | entailment |
public function get($module_id)
{
$modules = $this->getList();
return empty($modules[$module_id]) ? array() : $modules[$module_id];
} | Returns an array of module data
@param string $module_id
@return array | entailment |
public function getInfo($module_id)
{
static $information = array();
if (isset($information[$module_id])) {
return $information[$module_id];
}
$file = $this->getModuleInfoFile($module_id);
$decoded = null;
if (is_file($file)) {
$decoded = json_decode(file_get_contents($file), true);
}
if (is_array($decoded)) {
$decoded['id'] = $decoded['module_id'] = $module_id;
$information[$module_id] = $decoded;
} else {
$information[$module_id] = array();
}
return $information[$module_id];
} | Returns an array of module data from module.json file
@param string $module_id
@todo - remove 'id' key everywhere
@return array | entailment |
public function getInstalled()
{
if (!$this->db->isInitialized()) {
return array();
}
$modules = &gplcart_static('module.installed.list');
if (isset($modules)) {
return $modules;
}
$options = array(
'index' => 'module_id',
'unserialize' => 'settings'
);
return $modules = $this->db->fetchAll('SELECT * FROM module', array(), $options);
} | Returns an array of all installed modules
@return array | entailment |
public function getHooks($class)
{
$hooks = array();
foreach (get_class_methods($class) as $method) {
if (strpos($method, 'hook') === 0) {
$hooks[] = $method;
}
}
return $hooks;
} | Returns an array of class methods which are hooks
@param object|string $class
@return array | entailment |
public function getByType($type, $enabled = false)
{
$modules = $enabled ? $this->getEnabled() : $this->getList();
foreach ($modules as $id => $info) {
if ($type !== $info['type']) {
unset($modules[$id]);
}
}
return $modules;
} | Returns an array of modules by the type
@param string $type
@param boolean $enabled
@return array | entailment |
public function get($product_class_field_id)
{
$result = null;
$this->hook->attach('product.class.field.get.before', $product_class_field_id, $result, $this);
if (isset($result)) {
return $result;
}
$sql = 'SELECT * FROM product_class_field WHERE product_class_field_id=?';
$result = $this->db->fetch($sql, array($product_class_field_id));
$this->hook->attach('product.class.field.get.after', $result, $this);
return $result;
} | Loads a product class field from the database
@param integer $product_class_field_id
@return array | entailment |
public function delete($condition)
{
$result = null;
$this->hook->attach('product.class.field.delete.before', $condition, $result, $this);
if (isset($result)) {
return (bool) $result;
}
if (!is_array($condition)) {
$condition = array('product_class_field_id' => $condition);
}
$result = (bool) $this->db->delete('product_class_field', $condition);
$this->hook->attach('product.class.field.delete.after', $condition, $result, $this);
return (bool) $result;
} | Deletes a product class field
@param int|array $condition
@return boolean | entailment |
public static function inferDescriptor($descriptor)
{
if (isset($descriptor->type) && $descriptor->type == static::type()) {
return new static($descriptor);
} else {
return false;
}
} | try to create a field object based on the descriptor
by default uses the type attribute
return the created field object or false if the descriptor does not match this field.
@param object $descriptor
@return bool|BaseField | entailment |
public static function infer($val, $descriptor = null, $lenient = false)
{
$field = new static($descriptor);
try {
$field->castValue($val);
} catch (FieldValidationException $e) {
return false;
}
$field->inferProperties($val, $lenient);
return $field;
} | try to create a new field object based on the given value.
@param mixed $val
@param null|object $descriptor
@param bool @lenient
@return bool|BaseField | entailment |
final public function castValue($val)
{
if ($this->isEmptyValue($val)) {
if ($this->required()) {
throw $this->getValidationException('field is required', $val);
}
return null;
} else {
$val = $this->validateCastValue($val);
if (!$this->constraintsDisabled) {
$validationErrors = $this->checkConstraints($val);
if (count($validationErrors) > 0) {
throw new FieldValidationException($validationErrors);
}
}
return $val;
}
} | @param mixed $val
@return mixed
@throws \frictionlessdata\tableschema\Exceptions\FieldValidationException; | entailment |
public function listSearch()
{
$this->setTermSearch();
$this->setTitleListSearch();
$this->setBreadcrumbListSearch();
$this->setFilterQueryListSearch();
$this->setPagerListSearch();
$this->setResultsSearch();
$this->setDataNavbarListSearch();
$this->setDataProductsListSearch();
$this->outputListSearch();
} | Displays the search page | entailment |
protected function setDataNavbarListSearch()
{
$options = array(
'total' => $this->data_limit,
'view' => $this->query_filter['view'],
'quantity' => count($this->data_results),
'sort' => "{$this->query_filter['sort']}-{$this->query_filter['order']}"
);
$this->setData('navbar', $this->render('category/navbar', $options));
} | Sets the navbar on the search page | entailment |
protected function setFilterQueryListSearch()
{
$default = array(
'view' => $this->configTheme('catalog_view', 'grid'),
'sort' => $this->configTheme('catalog_sort', 'price'),
'order' => $this->configTheme('catalog_order', 'asc')
);
$this->setFilter(array(), $this->getFilterQuery($default));
} | Sets filter on the search page | entailment |
protected function setPagerListSearch()
{
$options = array(
'status' => 1,
'count' => true,
'store_id' => $this->store_id,
'language' => $this->langcode
);
$pager = array(
'query' => $this->query_filter,
'limit' => $this->configTheme('catalog_limit', 20),
'total' => (int) $this->search->search('product', $this->data_term, $options)
);
return $this->data_limit = $this->setPager($pager);
} | Sets pager
@return array | entailment |
protected function setTitleListSearch()
{
$title = $this->text('Search');
if ($this->data_term !== '') {
$title = $this->text('Search for «@term»', array('@term' => $this->data_term));
}
$this->setTitle($title);
} | Sets titles on the search page | entailment |
protected function setResultsSearch()
{
$options = array(
'status' => 1,
'entity' => 'product',
'limit' => $this->data_limit,
'language' => $this->langcode,
'store_id' => $this->store_id
);
$options += $this->query_filter;
$this->data_results = $this->search->search('product', $this->data_term, $options);
if (!empty($this->data_results)) {
settype($this->data_results, 'array');
$options['placeholder'] = true;
$this->prepareEntityItems($this->data_results, $options);
}
} | Sets an array of search results | entailment |
public function editLanguage($code = null)
{
$this->setLanguage($code);
$this->setTitleEditLanguage();
$this->setBreadcrumbEditLanguage();
$this->setData('edit', isset($code));
$this->setData('language', $this->data_language);
$this->setData('can_delete', $this->canDeleteLanguage());
$this->setData('default_language', $this->language->getDefault());
$this->submitEditLanguage();
$this->outputEditLanguage();
} | Displays the language edit form
@param string|null $code | entailment |
protected function canDeleteLanguage()
{
return isset($this->data_language['code'])
&& $this->access('language_delete')
&& $this->language->canDelete($this->data_language['code']);
} | Whether the language can be deleted
@return bool | entailment |
protected function setLanguage($code)
{
$this->data_language = array();
if (!empty($code)) {
$this->data_language = $this->language->get($code);
if (empty($this->data_language)) {
$this->outputHttpStatus(404);
}
}
} | Set a language data
@param string $code | entailment |
protected function submitEditLanguage()
{
if ($this->isPosted('delete')) {
$this->deleteLanguage();
} else if ($this->isPosted('save') && $this->validateLanguage()) {
if (isset($this->data_language['code'])) {
$this->updateLanguage();
} else {
$this->addLanguage();
}
}
} | Handles a submitted language data | entailment |
protected function deleteLanguage()
{
$this->controlAccess('language_delete');
if ($this->language->delete($this->data_language['code'])) {
$this->redirect('admin/settings/language', $this->text('Language has been deleted'), 'success');
}
$this->redirect('', $this->text('Language has not been deleted'), 'warning');
} | Deletes a language | entailment |
protected function validateLanguage()
{
$this->setSubmitted('language');
$this->setSubmittedBool('status');
$this->setSubmittedBool('default');
$this->setSubmitted('update', $this->data_language);
$this->validateComponent('language');
return !$this->hasErrors();
} | Validates a language
@return boolean | entailment |
protected function updateLanguage()
{
$this->controlAccess('language_edit');
if ($this->language->update($this->data_language['code'], $this->getSubmitted())) {
$this->redirect('admin/settings/language', $this->text('Language has been updated'), 'success', true);
}
$this->redirect('', $this->text('Language has not been updated'), 'warning', true);
} | Updates a language | entailment |
protected function addLanguage()
{
$this->controlAccess('language_add');
if ($this->language->add($this->getSubmitted())) {
$this->redirect('admin/settings/language', $this->text('Language has been added'), 'success');
}
$this->redirect('', $this->text('Language has not been added'), 'warning');
} | Adds a new language | entailment |
protected function setTitleEditLanguage()
{
if (isset($this->data_language['code'])) {
$title = $this->text('Edit %name', array('%name' => $this->data_language['native_name']));
} else {
$title = $this->text('Add language');
}
$this->setTitle($title);
} | Sets titles on the edit language page | entailment |
protected function setBreadcrumbEditLanguage()
{
$breadcrumbs = array();
$breadcrumbs[] = array(
'url' => $this->url('admin'),
'text' => $this->text('Dashboard')
);
$breadcrumbs[] = array(
'url' => $this->url('admin/settings/language'),
'text' => $this->text('Languages')
);
$this->setBreadcrumbs($breadcrumbs);
} | Sets breadcrumbs on the edit language page | entailment |
public function listLanguage()
{
$this->refreshLanguage();
$this->setTitleListLanguage();
$this->setBreadcrumbListLanguage();
$this->setFilterListLanguage();
$this->setPagerListLanguage();
$this->setData('languages', (array) $this->getListLanguage());
$this->outputListLanguage();
} | Displays the language overview page | entailment |
protected function setPagerListLanguage()
{
$pager = array(
'query' => $this->query_filter,
'total' => (int) $this->getListLanguage(true)
);
return $this->data_limit = $this->setPager($pager);
} | Sets pager
@return array | entailment |
protected function getListLanguage($count = false)
{
$list = $this->language->getList();
$allowed = $this->getAllowedFiltersLanguage();
$this->filterList($list, $allowed, $this->query_filter);
$this->sortList($list, $allowed, $this->query_filter, array('code' => 'asc'));
if ($count) {
return count($list);
}
$this->limitList($list, $this->data_limit);
$this->prepareListLanguage($list);
return $list;
} | Returns an array of prepared languages
@param bool $count
@return array|int | entailment |
protected function prepareListLanguage(array &$list)
{
foreach ($list as $id => &$item) {
$item['file_exists'] = is_file($this->translation->getFile($id));
}
} | Prepare an array of languages
@param array $list | entailment |
protected function refreshLanguage()
{
$this->controlToken('refresh');
$code = $this->getQuery('refresh');
if (!empty($code) && $this->access('language_edit') && $this->translation->refresh($code)) {
$this->redirect('', $this->text('Language has been refreshed'), 'success');
}
} | Removes a cached translation | entailment |
public function sendHeaders()
{
if (!headers_sent()) {
foreach ($this->headers as $header) {
header($header, true);
}
}
$this->headers = array();
return $this;
} | Sends HTTP headers
@return $this | entailment |
public function addHeader($name, $value = null)
{
if (is_numeric($name)) {
$status = $this->getStatus($name);
if (!empty($status)) {
$this->headers[] = "{$_SERVER['SERVER_PROTOCOL']} $name $status";
}
} elseif (isset($value)) {
$this->headers[] = "$name: $value";
}
return $this;
} | Adds a header
@param string|int $name
@param string $value
@return $this | entailment |
protected function addOptionalHeaders($options)
{
if (!empty($options['headers'])) {
foreach ((array) $options['headers'] as $header) {
list($name, $value) = array_pad((array) $header, 2, null);
$this->addHeader($name, $value);
}
}
return $this;
} | Adds headers from options
@param array $options
@return $this | entailment |
public function getStatus($status = null)
{
$statuses = array(
100 => 'Continue',
101 => 'Switching Protocols',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Time-out',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Large',
415 => 'Unsupported Media Type',
416 => 'Requested range not satisfiable',
417 => 'Expectation Failed',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Time-out',
505 => 'HTTP Version not supported'
);
if (!isset($status)) {
return $statuses;
}
return isset($statuses[$status]) ? $statuses[$status] : '';
} | Returns a single status message or an array of HTTP statuses keyed by code
@param null|int $status
@return array|string | entailment |
public function outputHtml($html, $options = array())
{
$this->addHeader('Content-Type', 'text/html; charset=utf-8')
->addOptionalHeaders($options)
->sendHeaders();
echo $html;
exit;
} | Output HTML page
@param string $html
@param array $options | entailment |
public function outputJson($data, $options = array())
{
$this->addHeader('Content-Type', 'application/json')
->addOptionalHeaders($options)
->sendHeaders();
echo gplcart_json_encode($data);
exit;
} | Output JSON string
@param mixed $data
@param array $options | entailment |
public function download($file, $filename = '', $options = array())
{
$readfile = empty($options['text']);
if ($readfile && !is_file($file)) {
return null;
}
if ($readfile && empty($filename)) {
$filename = basename($file);
}
$size = $readfile ? filesize($file) : strlen($file);
$this->addHeader('Expires', 0)
->addHeader('Pragma', 'public')
->addHeader('Content-Length', $size)
->addHeader('Cache-Control', 'must-revalidate')
->addHeader('Content-Description', 'File Transfer')
->addHeader('Content-Type', 'application/octet-stream')
->addHeader('Content-Disposition', 'attachment; filename=' . $filename)
->addOptionalHeaders($options)
->sendHeaders();
if ($readfile) {
readfile($file);
} else {
echo $file;
}
exit;
} | Download a file
@param string $file Absolute path to the file
@param string $filename An alternative filename
@param array $options
@return null | entailment |
public function outputStatus($code, $message = null)
{
$this->addHeader($code)->sendHeaders();
if (isset($message)) {
echo $message;
}
exit;
} | Output an HTTP status and abort script execution
@param int $code
@param null|string $message | entailment |
public function outputError403($show_message = true)
{
$message = $show_message ? $this->getError403() : null;
$this->outputStatus(403, $message);
} | Output 403 error page
@param bool $show_message | entailment |
public function outputError404($show_message = true)
{
$message = $show_message ? $this->getError404() : null;
$this->outputStatus(404, $message);
} | Output 404 error page
@param bool $show_message | entailment |
public function outputError500($show_message = true, $error = '')
{
$message = $show_message ? $this->getError500($error) : null;
$this->outputStatus(500, $message);
} | Output 500 error page
@param bool $show_message
@param string $error | entailment |
public static function url()
{
$regex = ucfirst(\Tiny\Config::$application) . '\\\\' . 'Controller\\\\'; // 需要考虑到route的目录,所以需要用正则
$ctrl = preg_replace('/^(' . $regex . ')/', '', self::$controller);
$ctrl = implode('/', array_map('lcfirst', explode('\\', $ctrl))); // 首字母小写处理
return \Tiny\Url::get($ctrl . '/' . self::$method);
} | 当前请求的url | entailment |
public function listImageStyle()
{
$this->clearCacheImageStyle();
$this->setTitleListImageStyle();
$this->setBreadcrumbListImageStyle();
$this->setFilterListImageStyle();
$this->setPagerListImageStyle();
$this->setData('image_styles', (array) $this->getListImageStyle());
$this->outputListImageStyle();
} | Displays the image style overview page | entailment |
protected function setPagerListImageStyle()
{
$pager = array(
'query' => $this->query_filter,
'total' => (int) $this->getListImageStyle(true)
);
return $this->data_limit = $this->setPager($pager);
} | Sets pager
@return array | entailment |
protected function getListImageStyle($count = false)
{
$list = $this->image_style->getList();
$allowed = $this->getAllowedFiltersImageStyle();
$this->filterList($list, $allowed, $this->query_filter);
$this->sortList($list, $allowed, $this->query_filter, array('name' => 'desc'));
if ($count) {
return count($list);
}
$this->limitList($list, $this->data_limit);
$this->prepareListImageStyle($list);
return $list;
} | Returns an array of image styles
@param bool $count
@return array|int | entailment |
protected function prepareListImageStyle(array &$list)
{
foreach ($list as $id => &$item) {
$item['directory_exists'] = is_dir($this->image_style->getDirectory($id));
}
} | Prepare an array of image styles
@param array $list | entailment |
protected function clearCacheImageStyle()
{
$this->controlToken('clear');
$style_id = $this->getQuery('clear');
if (!empty($style_id)) {
if ($this->image_style->clearCache($style_id)) {
$this->redirect('', $this->text('Cache has been deleted'), 'success');
}
$this->redirect('', $this->text('Cache has not been deleted'), 'warning');
}
} | Clear cached images | entailment |
public function editImageStyle($style_id = null)
{
$this->setImageStyle($style_id);
$this->setTitleEditImageStyle();
$this->setBreadcrumbEditImageStyle();
$this->setData('imagestyle', $this->data_imagestyle);
$this->setData('actions', $this->getActionsImageStyle());
$this->setData('can_delete', $this->canDeleteImageStyle());
$this->submitEditImageStyle();
$this->setDataEditImageStyle();
$this->outputEditImageStyle();
} | Displays the imagestyle edit form
@param integer|null $style_id | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.