/** * Gets all labels for a defined type. * * @param string $type Name of the array group. * @param string $locale Locale code. * * @access public * @static * @uses Config() * @uses \Spyc * * @return array */ public static function getAll($type, $locale = '') { if (!$locale) { $locale = Core\Registry()->get('locale'); } return \Spyc::YAMLLoad(Core\Config()->paths('labels') . $locale . DIRECTORY_SEPARATOR . $type . '.yaml'); }
/** * Two way encryption: decrypt. * * @param string $data String to be encrypted. * @param string $password Value phrase. * @param string $type Cipher method name. * * @return string */ public static function decrypt($data, $password, $type) { if ($data) { return openssl_decrypt($data, $type, $password, 0, Core\Config()->DB['crypt_vector']); } return ''; }
/** * Creates a render instance. * * @param string $adapter Adapter class name. */ public function __construct($adapter) { $this->configuration = Core\Config()->paths('views'); $this->setAdapter($adapter); $this->filesExtension = $this->render->getTemplatesFileExtension(); $this->contentType = $this->render->getRenderedContentType(); $this->assets = new Assets(); }
/** * Down action. * * @param string $version Version string. * * @return void */ public static function down($version) { $migration = self::getMigration($version); $migrationName = self::getMigrationName($migration['name']); $name = 'DB\\Migrations\\' . $migrationName; require_once Core\Config()->paths('root') . implode(DIRECTORY_SEPARATOR, array('db', 'migrations', $migration['name'])) . '.php'; $migration = new $name($version); $migration->runDown(); }
/** * Filter owner resources. * * @param string $resourceModel Name of the resource model. * @param \Core\Base\Model|null $owner User Owner. * * @return \Core\Modules\DB\Query */ public static function filter($resourceModel, Base\Model $owner = null) { if (!$owner) { $owner = Core\Registry()->get('current_cms_user'); } $query = new DB\Query($resourceModel); $ownershipTable = 'cms_ownership'; $resourceTable = Core\Config()->DB['tables_prefix'] . $resourceModel::$tableName; $ownershipTablePrefixed = Core\Config()->DB['tables_prefix'] . 'cms_ownership'; $resourcePrimaryKey = $resourceModel::primaryKeyField(); return $query->select("{$resourceTable}.*")->from($resourceModel::$tableName)->join($ownershipTable, "{$resourceTable}.{$resourcePrimaryKey} = {$ownershipTablePrefixed}.resource_id")->where("{$ownershipTablePrefixed}.owner_id = ? AND {$ownershipTablePrefixed}.model = ?", array($owner->getPrimaryKeyValue(), $resourceModel)); }
/** * Initializer. Setup paths to temporary resources. * * @param mixed $params Params from the command line. * * @return void */ public static function init($params) { self::$CACHES = array('system' => 'temp/cache'); $modes = Core\Config()->modes(); foreach ($modes as $mode) { Core\Config()->setMode($mode); $assetsPath = Core\Config()->paths('assets'); $assets = Core\Utils::replaceFirstOccurrence(Core\Config()->paths('root'), '', $assetsPath['distribution']); if (file_exists($assetsPath['distribution'] . 'js')) { self::$CACHES['assets'][] = $assets . 'js'; } if (file_exists($assetsPath['distribution'] . 'css')) { self::$CACHES['assets'][] = $assets . 'css'; } } }
/** * Sends email via SMTP Mail Server. * * @param array $params Sending parameters. * @param boolean $auth Flag for usage of SMTP authentication or not. * * @uses Core\Config() * * @return boolean Result TRUE if the email was successfully sent, FALSE otherwise. */ private static function processSmtp(array $params, $auth = true) { /* Disable authentication if there is no valid SMTP user specified. */ if ($auth && !Core\Config()->MAILER['credentials']['smtp']['user']) { $auth = false; } $mail = new \PHPMailer(Core\Config()->MAILER['debug']); $mail->IsSMTP(); $mail->Host = Core\Config()->MAILER['credentials']['smtp']['host']; $mail->Port = Core\Config()->MAILER['credentials']['smtp']['port']; $mail->SMTPAuth = $auth; $mail->Username = Core\Config()->MAILER['credentials']['smtp']['user']; $mail->Password = Core\Config()->MAILER['credentials']['smtp']['password']; /* $mail->SMTPSecure = 'tls'; */ return self::processEmail($mail, $params); }
/** * Redis constructor. */ public function __construct() { $connParams = Core\Config()->CACHE['redis']; $this->redisClient = new Predis\Client($connParams); $this->redisClient->connect(); }
/** * Assigns filtering of the results. * * @param DB\Query $query Current query object instance of BaseModel or its children. * @param array $params Query params to format filtering criteria. * * @access private * @static * @uses Core\DB() * @uses Core\DbCache() * @uses Core\Helpers\SQL * * @return Core\Modules\DB\Query */ private static function assignFilter(DB\Query $query, array $params) { if (isset($params['filtering']) && !empty($params['filtering']) && is_array($params['filtering'])) { $model_fields = $query->getObject()->getSchema(); if ($query->getObject()->hasAndBelongsToMany) { $model_fields = array_merge($model_fields, $query->getObject()->hasAndBelongsToMany); } foreach ($params['filtering'] as $field => $value) { if ($value && isset($model_fields[$field])) { if (is_array($value)) { if (isset($value['start'], $value['end']) && !empty($value['start']) && !empty($value['end'])) { if (in_array($model_fields[$field]['type'], array('date', 'datetime'), true)) { $decorator = 'Core\\Modules\\DB\\Decorators\\Interfaces\\TimezoneAwareness'; if (is_subclass_of($query->getObject(), $decorator)) { $value['start'] = Core\Helpers\DateTime::formatGmt($value['start'] . date(' H:i:s'), 'Y-m-d'); $value['end'] = Core\Helpers\DateTime::formatGmt($value['end'] . date(' H:i:s'), 'Y-m-d'); } $query = $query->where("(DATE({$field}) BETWEEN " . Core\DB()->escapeString($value['start']) . ' AND ' . Core\DB()->escapeString($value['end']) . ')'); } else { $query = $query->where("{$field} BETWEEN " . Core\DB()->escapeString($value['start']) . ' AND ' . Core\DB()->escapeString($value['end'])); } } else { if (isset($query->getObject()->hasAndBelongsToMany[$field]) && $query->getObject()->hasAndBelongsToMany[$field]) { $related = $query->getObject()->hasAndBelongsToMany[$field]; $obj = $query->getObject(); $primaryKey = $obj->primaryKeyField(); $prefix = Core\Config()->DB['tables_prefix']; foreach ($value as $v) { $query = $query->join("{$related['table']} as {$related['table']}{$v}", "{$prefix}{$obj::$tableName}.{$primaryKey} = " . "{$related['table']}{$v}.{$related['key']}" . ' AND ' . "{$related['table']}{$v}.{$related['relative_key']} = {$v}"); } } } } elseif (strlen($value)) { if ($model_fields[$field]['type'] === 'string') { $value_to_match = trim(Core\DB()->escapeString($value), "'"); $query = $query->where("{$field} LIKE \"%{$value_to_match}%\""); } else { $query = $query->where($field . ' = ' . Core\DB()->escapeString($value)); } } } } } return $query; }
/** * Exports data from a database model. * * @param Request $request Current router request. * * @uses CMS\Helpers\Export * @uses CMS\Helpers\CMSUsers * * @return void */ public function export(Request $request) { $this->renderer->setLayout(null); $this->renderer->setView(null); if ($request->get('type')) { $fieldsToExport = array(); $attributes = array(); /* Determine which model data fields to export. */ $sections = $this->labels['attributes']; foreach ($sections as $section) { $attributes = array_merge($attributes, $section['fields']); } foreach ($attributes as $key => $attr) { $attr['export'] = isset($attr['export']) ? $attr['export'] : true; if ($attr['export']) { $fieldsToExport[$key] = $attr['title']; } } $query = Helpers\DataTables::toQuery($this->resource, array_keys($fieldsToExport), $request->get()); $exportFile = Core\Config()->paths('tmp') . md5($this->resourceModel) . '.export.tmp'; if (Helpers\Export::populateCsvfileCustomQuery(array('fields' => $fieldsToExport, 'query' => $query), $exportFile)) { if ('pdf' === $request->get('type')) { $cmsLabels = $this->labels; $title = $cmsLabels['export']['caption'] . ' ' . $cmsLabels['modules'][$this->getControllerName()]['title']; $assets = Core\Config()->paths('assets'); $logo = $assets['distribution'] . 'img' . DIRECTORY_SEPARATOR . 'logo.png'; $pdf = new Helpers\PDF($title, 'freeserif', $logo); $pdf->SetAuthor($cmsLabels['client']); $pdf->AddPage(); $pdf->embedContentTable(array_values($fieldsToExport), $pdf->loadData($exportFile)); $pdf->Output(); } else { Helpers\Export::getCsvBuffered($exportFile); } } } else { $request->redirectTo('index'); } }
/** * Initialize the template engine. * * @param array $config Template config variable. */ public function __construct(array $config) { $this->tpl = new \Smarty(); $this->tpl->setTemplateDir($config['templates'])->setCompileDir($config['compiled'])->setCacheDir($config['cache'])->setConfigDir($config['config'])->addPluginsDir(Core\Config()->paths('resources') . 'smarty_plugins'); $this->tpl->configLoad('globals.conf'); }
/** * Retrieve the relative request query string. * * @param string $path Request query string. * * @return string */ public static function normalizePath($path) { $path = explode('?', $path); if (!Core\Config()->ROUTER['rewrite'] && isset($path[1])) { $path = explode('&', $path[1]); } $path = $path[0]; $applicationPath = Core\Config()->urls('relative'); if ($applicationPath !== '/') { $path = '/' . str_replace($applicationPath, '', $path); } return ltrim($path, '/'); }
/** * Delete attachment. * * @param Base\Model $resource Currently processed resource. * * @static * @access public * * @return void */ public static function delete(Base\Model $resource) { self::$attachments = $resource::attachmentsFields(); foreach (self::$attachments as $name => $_attachment) { $attachment_file = Core\Config()->paths('root') . $resource->attachmentsStoragePath($name) . $resource->{$name}; if (file_exists($attachment_file)) { try { if (file_exists($attachment_file)) { Helpers\File::delete($attachment_file); } } catch (\Exception $e) { trigger_error($e->getMessage()); } /* Delete thumbnails */ if ($_attachment['type'] === array('photo') && isset($_attachment['thumbnails']) && is_array($_attachment['thumbnails'])) { self::deleteThumbnails($resource, $name, $resource->{$name}); } } } }
/** * Destroys session. * * @param mixed $key Session key, defaults to {$this->sessionKey}. * * @return boolean */ public function destroy($key = false) { $key = $key ? $key : $this->sessionKey; $query = "DELETE FROM {$this->storageTable} WHERE session_key = ?"; if ($this->db->query($query, array($key))) { Core\Router()->deleteCookie(Core\Config()->SESSION['name']); $this->vars = array(); $this->sessionKey = null; return true; } else { return false; } }
/** * Builds a sql query. * * @param DB\Query $query SQL Query. * * @throws \DomainException DB Adapter does not support the required JOIN type. * * @return string */ private function buildSql(DB\Query $query) { $sql = array(); if ($query->type === 'select') { $sql[] = 'SELECT'; $sql[] = $query->db_fields === 'all' ? '*' : (is_array($query->db_fields) ? implode(',', $query->db_fields) : $query->db_fields); $sql[] = 'FROM'; $sql[] = $query->table; if ($query->join) { foreach ($query->join as $join) { if (!in_array($join['type'], self::getSupportedJoinTypes(), true)) { throw new \DomainException('DB Adapter not supporting the required JOIN type:' . $join['type']); } $sql[] = $join['type']; $sql[] = 'JOIN'; $sql[] = Core\Config()->DB['tables_prefix'] . $join['table']; if ($join['condition']) { $sql[] = 'ON (' . $join['condition'] . ')'; } } } if ($query->where) { $sql[] = 'WHERE'; $sql[] = implode(' AND ', array_map(function ($item) { return '(' . $item . ')'; }, $query->where)); } if ($query->order) { $sql[] = 'ORDER BY'; $sql[] = implode(', ', array_map(function ($item) { return "{$item['field']} {$item['direction']}"; }, $query->order)); } if ($query->limit) { $sql[] = 'LIMIT'; $sql[] = $query->limit; if ($query->offset) { $sql[] = 'OFFSET'; $sql[] = $query->offset; } } } elseif ($query->type === 'insert') { $sql[] = 'INSERT IGNORE INTO'; $sql[] = $query->table; $sql[] = '(' . implode(',', $query->db_fields) . ')'; $sql[] = 'VALUES'; if (is_array(current($query->bind_params))) { $sql[] = implode(',', array_map(function ($item) { return '(' . implode(',', array_map(function () { return '?'; }, $item)) . ')'; }, $query->bind_params)); $query->bind_params = Core\Utils::arrayFlatten($query->bind_params); } else { $sql[] = '(' . implode(',', array_map(function () { return '?'; }, $query->bind_params)) . ')'; } } elseif ($query->type === 'update') { $sql[] = 'UPDATE'; $sql[] = $query->table; $sql[] = 'SET'; $sql[] = implode(',', array_map(function ($item) { return $item . ' = ?'; }, $query->db_fields)); $sql[] = 'WHERE'; $sql[] = implode(' AND ', array_map(function ($item) { return '(' . $item . ')'; }, $query->where)); } elseif ($query->type === 'remove') { $sql[] = 'DELETE FROM'; $sql[] = $query->table; $sql[] = 'WHERE'; $sql[] = implode(' AND ', array_map(function ($item) { return '(' . $item . ')'; }, $query->where)); } return implode(' ', $sql); }
/** * Parses a template. * * @param string $template Path to template. * @param array $params Template parameters. * * @return string * * @throws \Exception General Exception. * @throws \SmartyException Smarty Exception. */ private static function parseTemplate($template, array $params) { $tpl = new \Smarty(); $config = Core\Config()->paths('views'); $tpl->setCompileDir($config['compiled'])->setCacheDir($config['cache'])->setConfigDir($config['config'])->addPluginsDir(Core\Config()->paths('resources') . 'smarty_plugins'); foreach ($params as $key => $value) { $tpl->assign($key, $value); } $path = Core\Config()->paths('root') . 'core' . DIRECTORY_SEPARATOR . 'cli' . DIRECTORY_SEPARATOR; return $tpl->fetch($path . '_templates' . DIRECTORY_SEPARATOR . $template . '.php.tpl'); }
/** * Redirects the browser to a specified target. * * @param mixed $url Array/String representation of url. * @param integer $status Redirect status code according to HTTP specification (301, 302, 303, 307). * * @access public * @uses Core\Config() * @uses Core\Router() * @example * <code> * redirectTo(array('action' => 'show', 'id' => 5)) * redirectTo('http://www.athlonproduction.com') * redirectTo('back') - Only current controller action name. * </code> * * @return void */ public function redirectTo($url, $status = 302) { if (is_array($url)) { $url = Core\Config()->urls('relative') . Core\Router()->toUrl($url); } elseif ($url === 'back') { $url = $this->context['_SERVER']['HTTP_REFERER']; } elseif (strpos($url, '/') === false) { $url = Core\Config()->urls('relative') . Core\Router()->toUrl(array('controller' => $this->controller(), 'action' => $url)); } if (headers_sent() || $this->is('xhr')) { echo '<script type="text/javascript">' . "setTimeout(function() { location.href = '{$url}'; }, 0);" . '</script>'; exit; } switch ($status) { case 301: $status = '301 Moved Permanently'; break; case 303: $status = '303 See Other'; break; case 307: $status = '307 Temporary Redirect'; break; default: $status = '302 Found'; break; } header($this->type() . ' ' . $status); header('Location: ' . str_replace('&', '&', $url)); exit; }
/** * Get table meta information from cache or extract it, if missing. * * @param string $tableName Name of the table. * * @uses Core\Cache() * @uses extractSchemaMeta() * * @return array */ private function getSchemaMeta($tableName) { if (Core\Config()->CACHE['db_schema']) { $schemaMeta = Core\Cache()->fetch($tableName); if (is_null($schemaMeta)) { $schemaMeta = $this->extractSchemaMeta($tableName); Core\Cache()->store($tableName, $schemaMeta); } } else { $schemaMeta = $this->extractSchemaMeta($tableName); } return $schemaMeta; }
/** * Select the best route from all registered routes according url address. * * @param array $url URL elements array. * * @access public * * @return array */ public function extractRoute(array $url) { $route = null; $routes = $this->getAll(); $default_route = end($routes); foreach ($url as $position => $element) { foreach ($routes as $key => $route) { $route_elements = $this->toRoute($route['pattern']); $route_elements[$position] = isset($route_elements[$position]) ? $route_elements[$position] : null; if (($route_elements[$position] === '' || $route_elements[$position][0] !== Core\Config()->ROUTER['variables_prefix']) && $route_elements[$position] !== $element) { unset($routes[$key]); } } } if ($routes) { $route = reset($routes); $routed_url = $this->toRoute($route['pattern']); $test_route = $route['maps_to']; foreach ($route['maps_to'] as $role => $value) { if ('*' === $value) { $test_route[$role] = $url[array_search(Core\Config()->ROUTER['variables_prefix'] . $role, $routed_url)]; } } $_controller = $this->mode['namespace'] . '\\Controllers\\' . $test_route['controller']; if (!class_exists($_controller)) { $route = next($routes); $_controller = $this->mode['namespace'] . '\\Controllers\\' . $route['maps_to']['controller']; if (!method_exists($_controller, $test_route['controller'])) { $route = next($routes); } } } return $route ? $route : $default_route; }
/** * Reset access action. * * @param Request $request Current router request. * * @return void */ public function renew(Request $request) { $user = Models\CMSUser::find()->where('DATE_ADD(updated_on, INTERVAL 60 MINUTE) > UTC_TIMESTAMP() AND SHA1(CONCAT(password, ?, email)) = ?', array(Core\Config()->USER_AUTH['cookie_salt'], $request->get('id')))->first(); if ($user) { $new_password = Core\Utils::generatePassword(10); if ($user->save(array('password' => $new_password), true)) { $this->new_password = $new_password; } } else { $request->redirectTo(array('controller' => 'authentication')); } }
/** * Get object/objects from the Database. * * @param string $fields List of fields to return (optional). * * @access public * @final * @static * * @return DB\Query */ public static final function find($fields = 'all') { $query = new DB\Query(get_called_class()); if (static::$isI18n) { if (!static::$i18nLocale) { $_locale = Core\Registry()->get('locale'); static::$i18nLocale = isset(Core\Config()->I18N['locales'][$_locale]) ? $_locale : Core\Config()->I18N['default']; } if (!static::$i18nTableName) { static::$i18nTableName = static::$tableName . static::$i18nTableNameSuffix; } $prefix = Core\Config()->DB['tables_prefix']; return $query->select($fields)->from(static::$tableName)->join(static::$i18nTableName, $prefix . static::$tableName . '.' . static::$primaryKeyField . ' = ' . $prefix . static::$i18nTableName . '.' . static::$i18nForeignKeyField . ' AND ' . $prefix . static::$i18nTableName . '.' . static::$i18nLocaleField . ' = "' . static::$i18nLocale . '"'); } return $query->select($fields)->from(static::$tableName); }
/** * Builds the SQL part of the query. * * @param DB\Query $query Query object. * * @throws \DomainException DB Adapter does not support the required JOIN type. * * @return string */ private function buildSql(DB\Query $query) { $sql = array(); if ($query->type === 'select') { $sql[] = 'SELECT'; $sql[] = $query->db_fields === 'all' ? '*' : (is_array($query->db_fields) ? implode(',', $query->db_fields) : $query->db_fields); $sql[] = 'FROM'; $sql[] = $query->table; if ($query->join) { foreach ($query->join as $join) { if (!in_array($join['type'], self::getSupportedJoinTypes(), true)) { throw new \DomainException('DB Adapter does not support the JOIN type:' . $join['type']); } $sql[] = $join['type']; $sql[] = 'JOIN'; $sql[] = Core\Config()->DB['tables_prefix'] . $join['table']; if ($join['condition']) { $sql[] = 'ON (' . $join['condition'] . ')'; } } } if ($query->where) { $sql[] = 'WHERE'; $sql[] = implode(' AND ', array_map(function ($item) { return '(' . $item . ')'; }, $query->where)); } if ($query->order) { $sql[] = 'ORDER BY'; $sql[] = implode(', ', array_map(function ($item) { return "{$item['field']} {$item['direction']}"; }, $query->order)); } if ($query->limit) { $sql[] = 'LIMIT'; $sql[] = $query->limit; if ($query->offset) { $sql[] = 'OFFSET'; $sql[] = $query->offset; } } } elseif ($query->type === 'insert') { $sql[] = 'INSERT IGNORE INTO'; $sql[] = $query->table; $sql[] = '(' . implode(',', $query->db_fields) . ')'; $sql[] = 'VALUES'; if (isset($query->bind_params[0]) && is_array($query->bind_params[0])) { $sql[] = implode(',', array_map(function ($item) { return '(' . implode(',', array_map(function () { return '?'; }, $item)) . ')'; }, $query->bind_params)); $query->bind_params = Core\Utils::arrayFlatten($query->bind_params); } else { $sql[] = '(' . implode(',', array_map(function () { return '?'; }, $query->bind_params)) . ')'; } } elseif ($query->type === 'update') { $sql[] = 'UPDATE'; $sql[] = $query->table; $sql[] = 'SET'; $sql[] = implode(',', array_map(function ($item) { return $item . ' = ?'; }, $query->db_fields)); $sql[] = 'WHERE'; $sql[] = implode(' AND ', array_map(function ($item) { return '(' . $item . ')'; }, $query->where)); } elseif ($query->type === 'remove') { $sql[] = 'DELETE FROM'; $sql[] = $query->table; $sql[] = 'WHERE'; $sql[] = implode(' AND ', array_map(function ($item) { return '(' . $item . ')'; }, $query->where)); } elseif ($query->type === 'create_table') { $sql[] = 'CREATE TABLE IF NOT EXISTS'; $sql[] = $query->table; $fields = array(); foreach ($query->db_fields as $field => $attributes) { $is_primary_key = false; $attrs = $this->convertAttributes($attributes); if ($pos = array_search('pk', $attrs)) { unset($attrs[$pos]); $is_primary_key = true; } $fields[] = $field . ' ' . implode(' ', $attrs); if ($is_primary_key) { $fields[] = 'PRIMARY KEY(' . $field . ')'; } } $sql[] = '(' . implode(',', $fields) . ')'; $sql[] = 'ENGINE ' . $query->table_engine; } elseif ($query->type === 'drop_table') { $sql[] = 'DROP TABLE ' . $query->table; } elseif ($query->type === 'add_columns') { $sql[] = 'ALTER TABLE'; $sql[] = $query->table; $sql[] = 'ADD COLUMN'; $fields = array(); foreach ($query->db_fields as $field => $attributes) { $is_primary_key = false; $attrs = $this->convertAttributes($attributes); if ($pos = array_search('pk', $attrs)) { unset($attrs[$pos]); $is_primary_key = true; } $fields[] = $field . ' ' . implode(' ', $attrs); if ($is_primary_key) { $fields[] = 'PRIMARY KEY(' . $field . ')'; } } $sql[] = '(' . implode(',', $fields) . ')'; } elseif ($query->type === 'drop_columns') { $sql[] = 'ALTER TABLE'; $sql[] = $query->table; $cols = array(); foreach ($query->db_fields as $column) { $cols[] = 'DROP COLUMN ' . $column; } $sql[] = implode(',', $cols); } return implode(' ', $sql); }
/** * Assigns common template engine vars. * * @param Modules\Render\Render $renderer Render module object. * * @access private * * @return Modules\Render\Render */ private static function assignVariablesToRender(Modules\Render\Render &$renderer) { $renderer->set('_mode', Core\Config()->paths('mode')); $renderer->set('_registry', Core\Registry()); $renderer->set('_config', Core\Config()); $renderer->set('_session', Core\Session()); $renderer->set('_assets', $renderer->assets()); $renderer->set('_urls', Core\Config()->urls()); $renderer->set('_paths', Core\Config()->paths()); $renderer->set('_request', Core\Router()->request); $renderer->set('_get', Core\Router()->request->get()); $renderer->set('_post', Core\Router()->request->post()); $renderer->set('_environment', SILLA_ENVIRONMENT); return $renderer; }
/** * Database constructor. * * @access public */ public function __construct() { $this->tableName = Core\Config()->CACHE['database']['table_name']; $this->fields = Core\Config()->CACHE['database']['fields']; }
/** * Encrypt fields. * * @param Base\Model $resource Currently processed resource. * * @static * @access public * * @return void */ public static function encrypt(Base\Model $resource) { foreach (self::$encryptedFields as $field => $type) { $resource->{$field} = Crypt::encrypt($resource->{$field}, Core\Config()->DB['encryption_key'], $type); } }
/** * Destroys the session. * * @access public * * @return boolean */ public function destroy() { session_destroy(); $this->vars = array(); $this->sessionKey = null; unset($_COOKIE[Core\Config()->SESSION['name']]); self::$started = false; return true; }
/** * Formats a (relative) path to full path. * * @param string $path File path. * * @uses Core\Base\Configuration::paths To get root path of framework. * * @return string Full path. */ public static function getFullPath($path) { $path = trim(str_replace(Core\Config()->paths('root'), '', $path), '\\/'); $path = Core\Config()->paths('root') . $path; return $path; }
/** * Get either a Gravatar URL or complete image tag for a specified email address. * * @param string $email The email address. * @param integer $s Size in pixels, defaults to 80px [ 1 - 2048 ]. * @param string $d Default image-set to use [ 404 | mm | identicon | monsterid | wavatar ]. * @param string $r Maximum rating (inclusive) [ g | pg | r | x ]. * * @access public * @static * @uses Core\Config() * * @return string String containing either just a URL or a complete image tag. */ public static function getGravatar($email, $s = 70, $d = 'mm', $r = 'g') { $url = Core\Config()->urls('protocol') . '://gravatar.com/avatar/'; $url .= md5(strtolower(trim($email))); $url .= '?' . http_build_query(array('s' => $s, 'd' => $d, 'r' => $r), '', '&'); return $url; }
/** * Generates storage path. * * @access private * @static * * @return string */ private static function storagePath() { return Core\Config()->paths('tmp') . 'cache' . DIRECTORY_SEPARATOR; }