Ejemplo n.º 1
0
 public function getAjaxTemplate()
 {
     $files = JRequest::getVar('names', '');
     if (empty($files)) {
         return false;
     }
     // Ensure the integrity of each items submitted to be an array.
     if (!is_array($files)) {
         $files = array($files);
     }
     $result = array();
     foreach ($files as $file) {
         $template = Komento::getTheme();
         $out = $template->fetch($file . '.ejs');
         $obj = new stdClass();
         $obj->name = $file;
         $obj->content = $out;
         $result[] = $obj;
     }
     Komento::getClass('json', 'KomentoJson');
     header('Content-type: text/x-json; UTF-8');
     $json = new KomentoJson();
     echo $json->encode($result);
     exit;
 }
Ejemplo n.º 2
0
 public function getResource()
 {
     $resources = JRequest::getVar('resource');
     $component = JRequest::getCmd('kmtcomponent');
     Komento::setCurrentComponent($component);
     if (!is_array($resources)) {
         header('Content-type: text/x-json; UTF-8');
         echo '[]';
         exit;
     }
     foreach ($resources as &$resource) {
         $resource = (object) $resource;
         switch ($resource->type) {
             case 'language':
                 $resource->content = JText::_(strtoupper($resource->name));
                 break;
             case 'view':
                 $template = Komento::getTheme();
                 $out = $template->fetch($resource->name . '.ejs');
                 if ($out !== false) {
                     $resource->content = $out;
                 }
                 break;
         }
     }
     Komento::getClass('json', 'KomentoJson');
     header('Content-type: text/x-json; UTF-8');
     $json = new KomentoJson();
     echo $json->encode($resources);
     exit;
 }
Ejemplo n.º 3
0
 public function getLanguage()
 {
     $languages = JRequest::getVar('languages');
     $result = array();
     // If this is not an array, make it as an array.
     if (!is_array($languages)) {
         $languages = array($languages);
     }
     foreach ($languages as $key) {
         $result[$key] = JText::_(strtoupper($key));
     }
     Komento::getClass('json', 'Services_JSON');
     header('Content-type: text/x-json; UTF-8');
     $json = new KomentoJson();
     echo $json->encode($result);
     exit;
 }
Ejemplo n.º 4
0
 /**
  * Processes all AJAX calls here
  */
 public function process()
 {
     $namespace = JRequest::getCmd('namespace', '');
     $isAjaxCall = JRequest::getCmd('format') == 'ajax' && !empty($namespace);
     if (!$isAjaxCall) {
         return false;
     }
     //@task: Process namespace
     $namespace = explode('.', $namespace);
     if (!JRequest::checkToken() && !JRequest::checkToken('get')) {
         echo 'Invalid token';
         exit;
     }
     // @rule: All calls should be made a minimum out of 3 parts of dots (.)
     if (count($namespace) < 4) {
         $this->fail(JText::_('Invalid calls'));
         return $this->send();
     }
     /**
      * Namespaces are broken into the following
      *
      * site.views.viewname.methodname - Front end ajax calls
      * admin.views.viewname.methodname - Back end ajax calls
      * plugin.views.pluginname.methodname - Plugin ajax calls (for extended plugin)
      */
     list($location, $type, $view, $method) = $namespace;
     if ($type != 'views') {
         $this->fail(JText::_('Currently only serving views'));
         return $this->send();
     }
     $location = strtolower($location);
     $view = strtolower($view);
     $path = JPATH_ROOT;
     $class = '';
     switch ($location) {
         case 'admin':
             $path .= DIRECTORY_SEPARATOR . 'administrator' . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_komento' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $view . DIRECTORY_SEPARATOR . 'view.ajax.php';
             $class = 'KomentoView' . preg_replace('/[^A-Z0-9_]/i', '', $view);
             break;
         case 'site':
             $path .= DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_komento' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . $view . DIRECTORY_SEPARATOR . 'view.ajax.php';
             $class = 'KomentoView' . preg_replace('/[^A-Z0-9_]/i', '', $view);
             break;
         case 'plugin':
             $path .= DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . 'komento';
             if (Komento::joomlaVersion() >= '1.6') {
                 $path .= DIRECTORY_SEPARATOR . $view;
             }
             $path .= DIRECTORY_SEPARATOR . $view . '.ajax.php';
             $class = 'KomentoPlugin' . preg_replace('/[^A-Z0-9_]/i', '', $view);
             break;
     }
     if (!class_exists($class)) {
         jimport('joomla.filesystem.file');
         if (!JFile::exists($path)) {
             $this->fail(JText::_('View file does not exist.'));
             return $this->send();
         }
         require_once $path;
     }
     $object = new $class();
     $args = JRequest::getVar('args', '');
     if (!method_exists($object, $method)) {
         $this->fail(JText::sprintf('The method %1s does not exists.', $method));
         return $this->send();
     }
     if (!empty($args)) {
         require_once KOMENTO_CLASSES . DIRECTORY_SEPARATOR . 'json.php';
         $json = new KomentoJson();
         $args = $json->decode($args);
         if (!is_array($args)) {
             $args = array($args);
         }
         call_user_func_array(array($object, $method), $args);
     } else {
         $object->{$method}();
     }
     $this->send();
 }