/** * 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'); }
/** * Returns an instance of the Cache object. * * @param string $adapter Adapter name. * * @access public * @static * @final * @uses Core\Registry() * * @return Cache */ public static final function getInstance($adapter) { if (null === self::$instance) { $adapter = 'Core\\Modules\\Cache\\Adapters\\' . $adapter; self::$instance = new Cache($adapter); Core\Registry()->set('cache', self::$instance); } return self::$instance; }
/** * Login verification gate. * * @param Request $request Current Router request. * * @return void */ protected function checkLogged(Request $request) { if (1 === Core\Session()->get('cms_user_logged')) { $this->user = unserialize(rawurldecode(Core\Session()->get('cms_user_info'))); Core\Registry()->set('current_cms_user', $this->user); Core\Helpers\DateTime::setEnvironmentTimezone($this->user->timezone); } else { $request->redirectTo(array('controller' => 'authentication', 'action' => 'login', 'redirect' => $request->meta('REQUEST_URI'))); } }
/** * Verifies whether a user can access a specific resource scope. * * @param array $scope Example array('controller' => '' , 'action' =>''). * @param \CMS\Models\CMSUser|null $user User instance to verify. * * @access public * @static * * @return boolean */ public static function userCan(array $scope, CMS\Models\CMSUser $user = null) { if (!$user) { $user = Core\Registry()->get('current_cms_user'); } $_cache_key = md5(serialize($user) . serialize($scope)); static $user_access_scope_cache; if (!isset($user_access_scope_cache[$_cache_key])) { $user_access_scope = $user->role()->permissions; $user_access_scope_cache[$_cache_key] = array_key_exists($scope['controller'], $user_access_scope) && in_array($scope['action'], $user_access_scope[$scope['controller']], true); } return $user_access_scope_cache[$_cache_key]; }
/** * 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); }
/** * 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; }
/** * Remove Ownership Data for an Owner. * * @param \Core\Base\Model|null $owner Owner instance * * @return void */ public static function resetOwner(Base\Model $owner = null) { if (!$owner) { $owner = Core\Registry()->get('current_cms_user'); } $query = new Core\Modules\DB\Query(); Core\DB()->run($query->remove()->from('cms_ownership')->where('owner_id = ? AND model = ?', array($owner->getPrimaryKeyValue(), get_class($resource)))); }