/** * Loads and include jQuery js file from google's CDN * @param mixed $args must contain a 'tpl' key with the current template object */ public static function load($args) { if (!isset($args['tpl']) || $args['tpl'] == null) { throw new Core\Exception('Plugin Disqus needs a template object as argument in $args["tpl"]', E_USER_ERROR, self::CLASS_NAME); } if (!isset($args['id']) || $args['id'] == null) { throw new Core\Exception('Plugin Disqus needs a page identifier as argument in $args["id"]', E_USER_WARNING, self::CLASS_NAME); } $shortname = $args['shortname'] == null ? \Orion::config()->get('DISQUS_SHORTNAME') : $args['shortname']; $dev = $args['dev'] == true ? "var disqus_developer = 1;" : ""; if ($shortname == null) { throw new Core\Exception('Plugin Disqus needs a shortname string as argument in $args["shortname"] or in configuration under ["DISQUS_SHORTNAME"].', E_USER_ERROR, self::CLASS_NAME); } self::$TPL =& $args['tpl']; $script = '<script type="text/javascript"> //<![CDATA[ var disqus_shortname = "' . $shortname . '"; var disqus_identifier = "' . $args['id'] . '"; var disqus_url = "' . $args['permalink'] . '"; ' . $dev . ' //]]> </script> <script type="text/javascript" src="http://' . $shortname . '.disqus.com/embed.js" async></script>'; self::$TPL->addJs($script); self::$TPL->assign('disqus_message', '<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>'); }
/** * (Factory) Create and return a new Query instance based on Query\Base and specific to the DB type set in configuration. * @param String $class Name of the model class from whom the Factory call originates (Facultative). * @return \Orion\Core\Query\Base */ public static final function Factory($class = null) { if (!\Orion::config()->get('DB_TYPE')) { throw new Exception('No database type set in Orion configuration file.', E_ERROR, get_class()); } try { $queryClass = '\\Orion\\Core\\Query\\' . ucfirst(strtolower(\Orion::config()->get('DB_TYPE'))); return new $queryClass($class); } catch (Exception $e) { throw new Exception('Unable to load Query class for [' . \Orion::config()->get('DB_TYPE') . '] database type.', E_ERROR, get_class()); } }
/** * Manually close the connection to database * @return boolean success */ public static function disconnect() { if (!\Orion::config()->get('DB_TYPE')) { throw new Exception('No database type set in Orion configuration file.', E_ERROR, get_class()); } try { $dbClass = 'DB\\' . ucfirst(strtolower(\Orion::config()->get('DB_TYPE'))); return $dbClass::disconnect(); } catch (\Exception $e) { throw new Exception('Unable to load DB class for [' . \Orion::config()->get('DB_TYPE') . '] database type.', E_ERROR, get_class()); } }
/** * Loads a new SyntaxHighlighter plugin from Alex Gorbatchev's public CDN * No args required * @param mixed $args */ public static function load() { try { $theme = \Orion::config()->defined('SYNTAXHIGHLIGHTER_THEME') ? \Orion::config()->get('SYNTAXHIGHLIGHTER_THEME') : self::SH_THEME; Plugins\jQuery::loadPlugin(self::SH_DIR . 'scripts/shCore.js', true); Plugins\jQuery::loadPlugin(self::SH_DIR . 'scripts/shAutoloader.js', true); Plugins\jQuery::loadCSS($theme, true); Plugins\jQuery::script("\n function path()\n {\n var args = arguments,\n result = []\n ;\n \n for(var i = 0; i < args.length; i++)\n result.push(args[i].replace('@', '" . self::SH_DIR . "scripts/'));\n \n return result\n };\n \n SyntaxHighlighter.defaults['toolbar'] = false;\n\n SyntaxHighlighter.autoloader.apply(null, path(\n 'applescript @shBrushAppleScript.js',\n 'actionscript3 as3 @shBrushAS3.js',\n 'bash shell @shBrushBash.js',\n 'coldfusion cf @shBrushColdFusion.js',\n 'cpp c @shBrushCpp.js',\n 'c# c-sharp csharp @shBrushCSharp.js',\n 'css @shBrushCss.js',\n 'delphi pascal @shBrushDelphi.js',\n 'diff patch pas @shBrushDiff.js',\n 'erl erlang @shBrushErlang.js',\n 'groovy @shBrushGroovy.js',\n 'java @shBrushJava.js',\n 'jfx javafx @shBrushJavaFX.js',\n 'js jscript javascript @shBrushJScript.js',\n 'perl pl @shBrushPerl.js',\n 'php @shBrushPhp.js',\n 'text plain @shBrushPlain.js',\n 'py python @shBrushPython.js',\n 'ruby rails ror rb @shBrushRuby.js',\n 'sass scss @shBrushSass.js',\n 'scala @shBrushScala.js',\n 'sql @shBrushSql.js',\n 'vb vbnet @shBrushVb.js',\n 'xml xhtml xslt html @shBrushXml.js'\n ));\n SyntaxHighlighter.all();", true); } catch (Core\Exception $e) { throw $e; } }
/** * Check if user level is ($atleast) $slug * @param string $slug The level's slug * @param boolean $atleast Is exactly $slug (FALSE), or at least $slug (TRUE) */ public function is($slug, $atleast = false) { if (empty($this->level)) { throw new Core\Exception("Le niveau de l'utilisateur n'est pas défini."); } $roles = \Orion::config()->get('AUTH_ROLES'); if (!array_key_exists($slug, $roles)) { throw new Core\Exception("Le rôle demandé n'existe pas."); } $roleval = $roles[$slug]; if ($this->level == $roleval || $atleast && $this->level <= $roleval) { return true; } else { return false; } }
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'); }
/** * Main module function, executed right after module loading by Orion. * Handles route parsing and function callbacks. */ public function load() { if ($this->route == null) { if (!\Orion::config()->defined('ROUTING_AUTO') || \Orion::config()->get('ROUTING_AUTO') == false) { $this->sendError(self::E_ROUTE_NO); } $this->route = new Route(); $function = $this->route->decodeAuto(); } else { $function = $this->route->decode(); } if (Core\Tools::startWith($function->getName(), '__')) { $this->sendError(self::E_FUNCTION_NO); } if (Core\Tools::startWith($function->getName(), self::FUNCTION_PREFIX)) { $this->sendError(self::E_FUNCTION_NO); } if (!is_callable(array($this, self::FUNCTION_PREFIX . $function->getName()))) { $this->sendError(self::E_FUNCTION_NO); } Core\Tools::callClassMethod($this, self::FUNCTION_PREFIX . $function->getName(), $function->getArgs()); }
/** * Main module function, executed right after module loading by Orion. * Handles route parsing and function callbacks. */ public function load() { if ($this->route == null) { if (!\Orion::config()->defined('ROUTING_AUTO') || \Orion::config()->get('ROUTING_AUTO') == false) { throw new Exception('No route object found in controller and automatic routing is disabled.', E_USER_ERROR, get_class($this)); } $this->route = new Route(); $function = $this->route->decodeAuto(); } else { $function = $this->route->decode(); } if (Tools::startWith($function->getName(), '__')) { throw new Exception('Trying to access a resticted function, you are not allowed to use methods starting with "__".', E_USER_ERROR, get_class($this)); } if (Tools::startWith($function->getName(), self::FUNCTION_PREFIX)) { throw new Exception('Function name in rule must be declared without function prefix ' . self::FUNCTION_PREFIX . '.', E_USER_ERROR, get_class($this)); } if (!is_callable(array($this, self::FUNCTION_PREFIX . $function->getName()))) { Context::redirect(404); } Tools::callClassMethod($this, self::FUNCTION_PREFIX . $function->getName(), $function->getArgs()); }
/** * Return PDO instance or create intitial connection * @return PDO * @access public */ public static function getConnection() { if (!self::$instance) { try { $config = \Orion::config(); if (in_array($config->get('SQL_DRIVER'), self::$SQL_DRIVERS)) { $driver = $config->get('SQL_DRIVER'); } else { $driver = self::$DEFAULT_DRIVER; } if ($config->defined('SQL_PORT')) { $port = ';port=' . $config->get('SQL_PORT'); } else { $port = ''; } self::$instance = new \PDO($driver . ":host=" . $config->get('SQL_HOST') . $port . ";dbname=" . $config->get('SQL_DBNAME'), $config->get('SQL_USER'), $config->get('SQL_PASSWORD')); self::$instance->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } catch (\PDOException $e) { throw new Exception($e->getMessage(), $e->getCode(), get_class()); } } return self::$instance; }
/** * An elaborated split/double-salted hash method to hash passwords for example. * Uses sha1 as final hashing algorithm * @param string $data * @param string $extrasalt * @return hash */ public static function saltedHash($data, $extrasalt) { $password = str_split($data, strlen($data) / 2 + 1); $hash = hash('sha1', $extrasalt . $password[0] . \Orion::config()->get('SECURITY_KEY') . $password[1]); return $hash; }
/** * Decode current request URI into a usable OrionRouteMethod using an automated parser.<br /> * It's then possible to retreive the method to call and the arguments via the following getters:<br /> * OrionRouteMethod->getMethod();<br /> * OrionRouteMethod->getArgs();<br /> * OrionRouteMethod->getURI();<br /> * * @return OrionRouteMethod * @see OrionRouteMethod */ public function decodeAuto() { $uri = Context::$MODULE_URI; $matches = array(); if ($uri == '' || $uri == '/') { return new RouteMethod($this->defaultMethod, null, $uri); } if (preg_match('/^([a-zA-Z0-9_-]+)\\/(.*)$/i', $uri, $matches)) { array_shift($matches); $method = array_shift($matches); $args = array_shift($matches); if (\Orion::config()->defined('ROUTE_AUTO_ARGSEP')) { $cargs = explode(\Orion::config()->get('ROUTE_AUTO_ARGSEP'), $args); } else { $cargs = array($args); } return new RouteMethod($method, $cargs, $uri); } elseif (preg_match('/^([a-zA-Z0-9_-]+)$/i', $uri, $matches)) { array_shift($matches); $method = array_shift($matches); return new RouteMethod($method, null, $uri); } return new RouteMethod($this->errorMethod, array(self::E_NORULE), $uri); }
/** * * @param String $directory The relative path to the directory to empty. (relative to the upload directory) * @param boolean $empty Set this to TRUE to only empty the directory, FALSE|NULL to empty AND remove the directory * @return boolean */ public static function deleteDir($directory, $empty = false) { if (!\Orion::config()->defined('UPLOAD_DIR')) { throw new Exception('UPLOAD_DIR is not defined in Orion configuration.', E_ERROR, get_class()); } $base = $directory; $directory = \Orion::config()->get('UPLOAD_DIR') . $directory; if (substr($directory, -1) == DS) { $directory = substr($directory, 0, -1); } if (!file_exists($directory) || !is_dir($directory)) { return false; } elseif (!is_readable($directory)) { return false; } else { $directoryHandle = opendir($directory); while ($contents = readdir($directoryHandle)) { if ($contents != '.' && $contents != '..') { $path = $directory . "/" . $contents; if (is_dir($path)) { self::deleteDir($base . "/" . $contents); } else { unlink($path); } } } closedir($directoryHandle); if ($empty == false) { if (!rmdir($directory)) { return false; } } return true; } }
/** * <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 the full path to the provided template folder * @param string $template Template name * @return string */ public static function getTemplateAbsolutePath($template) { return \Orion::config()->get('TEMPLATE_ABS_PATH') . $template . DS; }
/** * 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; }