Example #1
0
 /**
  * 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);
         }
     }
 }
Example #2
0
 /**
  * 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;
 }