/** * Loads a jQuery sub plugin CSS file * @param string $file * @param boolean $external Is the file external ? if false, automatically adds jQuery plugin path */ public static function loadCSS($file, $external = false) { if (self::$TPL == null) { throw new Core\Exception('Template object must be defined in load function before calling loadCSS()', E_USER_WARNING, self::CLASS_NAME); } if (!$external) { $file = Core\Context::getPluginURL('jquery') . $file; } self::$TPL->includeCSS($file); }
public function _login() { try { Core\Auth::login(); if (isset($_SESSION['orion_auth_target']) && $_SESSION['orion_auth_target'] != Core\Context::genModuleURL($this->name)) { $target = $_SESSION['orion_auth_target']; unset($_SESSION['orion_auth_target']); Core\Context::redirect($target); } else { Core\Context::redirect(Core\Context::genURL(\Orion::config()->get('DEFAULT_LOGGED_PAGE'))); } } catch (Core\Exception $e) { $this->assign('info', $e->getMessage()); $this->assign('type', 'error'); } $this->renderView('views/login'); }
/** * Loads the RESTful plugin * @param mixed $args must contain a 'tpl' key with the current template object * and can contain : * a 'vars' key with an associative array to pass variables to JS, * an 'include' key with an array of local js files to load */ public static function load($args) { if (!isset($args['tpl']) || $args['tpl'] == null) { throw new Core\Exception('Plugin RESTful needs a template object as argument in $args["tpl"]', E_USER_ERROR, self::CLASS_NAME); } self::$TPL =& $args['tpl']; $vars = ''; if (is_array($args['vars']) && !empty($args['vars'])) { foreach ($args['vars'] as $key => $val) { $vars .= ',' . $key . ':' . (is_string($val) ? '"' . $val . '"' : json_encode($val)); } } $script = '<script type="text/javascript"> //<![CDATA[ var RESTdata={module:"' . Core\Context::$MODULE_NAME . '",path:{root:"' . Core\Context::getBaseURL() . '",module:"' . Core\Context::getModuleAbsolutePath() . '",page:"' . Core\Context::getModuleURL() . '"},vars:{_restv:"RESTfulPlugin.v1"' . $vars . '}}; //]]> </script>'; self::$TPL->addJs(trim($script)); if (is_array($args['include']) && !empty($args['include'])) { foreach ($args['include'] as $js) { self::$TPL->includeJS($js); } } }
/** * Sends a standard {"error":X} JSON Object * @param int $e Error code */ public function sendError($e, $code = 401) { Core\Context::setHeaderCode($code); $this->send(array('error' => $e)); exit; }
/** * Set a new template theme. * @param string $name */ public function setTemplate($name) { if ($name == $this->template) { return false; } if (!file_exists(Core\Context::getTemplateFilePath($name))) { throw new Core\Exception('Template not found in [' . Core\Context::getTemplateFilePath($name) . ']', E_USER_WARNING, $this->name); } $this->template = $name; if ($this->tpl != null) { $this->tpl->addTemplateDir(Core\Context::getTemplatePath($this->template)); } }
/** * <p><b>Must be called AFTER Core\Auth::login()</b></p> * Allows access only to logged users that have a level equal to or less than provided role. If permission is nsot granted, it will automatically redirect the user to the login module. * <p><b>Note that while it's doing all login/auth/redirection work automatically, you still have to create the corresponding user table in your database in addition to provide the login module into orion's module directory.</b></p> * @see Core\Auth * MainConfig * LoginModule * @param string $slug the role identifier (ie: 'administrator', 'member', etc.). See your configuration file for a liste of roles and their permission level. * @return bool TRUE if user has the permission, FALSE otherwise (even if redirected) */ public static function allow($slug, $noredirect = false) { if (!self::logged()) { self::login(); } $roles = \Orion::config()->get('AUTH_ROLES'); if (!array_key_exists($slug, $roles)) { throw new Exception('Unable to restrict access, role [' . $slug . '] does not exist.', E_USER_ERROR, __CLASS__); } if (self::$user == null || empty(self::$user->level) || self::$user->level <= 0) { throw new Exception('Missing user information. See Core\\Auth for more info.', E_USER_ERROR, __CLASS__); } if (self::$user->level > $roles[$slug]) { Context::setHeaderCode(403); if (!$noredirect) { Context::redirect(Context::genModuleURL('users', 'error-' . self::E_LEVEL_RESTRICT, 'default')); } return false; } else { return true; } }
/** * Get important context data as an array (useful for template hydratation) */ public function getDataArray() { $array = array(); try { $array['module'] = array(); $array['module']['name'] = \Orion::module()->getName(); $array['module']['path'] = \Orion\Core\Context::getModulePath(); $array['module']['url'] = \Orion\Core\Context::getModuleURL(\Orion::module()->getName()); $array['module']['uri'] = \Orion\Core\Context::getModuleURI(); $array['module']['fulluri'] = \Orion\Core\Context::getFullURI(); $array['template'] = array(); $array['template']['name'] = \Orion::module()->getTemplate(); $array['template']['path'] = \Orion\Core\Context::getTemplatePath(\Orion::module()->getTemplate()); $array['template']['abspath'] = \Orion\Core\Context::getTemplateAbsolutePath(\Orion::module()->getTemplate()); if (\Orion::config()->defined(strtoupper(\Orion::getMode()) . '_MENU')) { $array['menu'] = \Orion::config()->get(strtoupper(\Orion::getMode()) . '_MENU'); } $array['title'] = \Orion::config()->get('SITE_NAME'); $array['description'] = \Orion::config()->get('SITE_DESC'); $array['author'] = \Orion::config()->get('SITE_AUTHOR'); $array['baseurl'] = \Orion::config()->get('BASE_URL'); $array['mode'] = \Orion::getMode(); $array['logged'] = \Orion\Core\Auth::logged() ? 'yes' : 'no'; if (\Orion\Core\Auth::user() != null) { $array['user'] = array(); $array['user']['login'] = \Orion\Core\Auth::user()->login; $array['user']['hasadmin'] = \Orion\Core\Auth::user()->is('moderator', true); } } catch (Exception $e) { $array['error'] = 'Unable to retreive all data.'; } return $array; }