Esempio n. 1
0
 /**
  * Autoload Helpers
  *
  * @param   string  $class_name  The name of the class to load
  *
  * @return  void
  */
 public function autoload_fof_helper($class_name)
 {
     F0FPlatform::getInstance()->logDebug(__METHOD__ . "() autoloading {$class_name}");
     static $isCli = null, $isAdmin = null;
     if (is_null($isCli) && is_null($isAdmin)) {
         list($isCli, $isAdmin) = F0FDispatcher::isCliAdmin();
     }
     if (strpos($class_name, 'Helper') === false) {
         return;
     }
     // Change from camel cased into a lowercase array
     $class_modified = preg_replace('/(\\s)+/', '_', $class_name);
     $class_modified = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $class_modified));
     $parts = explode('_', $class_modified);
     // We need three parts in the name
     if (count($parts) != 3) {
         return;
     }
     // We need the second part to be "model"
     if ($parts[1] != 'helper') {
         return;
     }
     // Get the information about this class
     $component_raw = $parts[0];
     $component = 'com_' . $parts[0];
     $view = $parts[2];
     // Is this an F0F 2.1 or later component?
     if (!$this->isF0FComponent($component)) {
         return;
     }
     // Get the alternate view and class name (opposite singular/plural name)
     $alt_view = F0FInflector::isSingular($view) ? F0FInflector::pluralize($view) : F0FInflector::singularize($view);
     $alt_class = F0FInflector::camelize($component_raw . '_helper_' . $alt_view);
     // Get the proper and alternate paths and file names
     $componentPaths = F0FPlatform::getInstance()->getComponentBaseDirs($component);
     $file = "/helpers/{$view}.php";
     $altFile = "/helpers/{$alt_view}.php";
     $path = $componentPaths['main'];
     $altPath = $componentPaths['alt'];
     // Try to find the proper class in the proper path
     if (file_exists($path . $file)) {
         @(include_once $path . $file);
     }
     // Try to find the proper class in the alternate path
     if (!class_exists($class_name) && file_exists($altPath . $file)) {
         @(include_once $altPath . $file);
     }
     // Try to find the alternate class in the proper path
     if (!class_exists($alt_class) && file_exists($path . $altFile)) {
         @(include_once $path . $altFile);
     }
     // Try to find the alternate class in the alternate path
     if (!class_exists($alt_class) && file_exists($altPath . $altFile)) {
         @(include_once $altPath . $altFile);
     }
     // If the alternate class exists just map the class to the alternate
     if (!class_exists($class_name) && class_exists($alt_class)) {
         $this->class_alias($alt_class, $class_name);
     }
 }
Esempio n. 2
0
 /**
  * Executes a given controller task. The onBefore<task> and onAfter<task>
  * methods are called automatically if they exist.
  *
  * @param   string $task The task to execute, e.g. "browse"
  *
  * @throws  Exception   Exception thrown if the onBefore<task> returns false
  *
  * @return  null|bool  False on execution failure
  */
 public function execute($task)
 {
     $this->task = $task;
     $method_name = 'onBefore' . ucfirst($task);
     if (!method_exists($this, $method_name)) {
         $result = $this->onBeforeGenericTask($task);
     } elseif (method_exists($this, $method_name)) {
         $result = $this->{$method_name}();
     } else {
         $result = true;
     }
     if ($result) {
         $plugin_event = F0FInflector::camelize('on before ' . $this->bareComponent . ' controller ' . $this->view . ' ' . $task);
         $plugin_result = F0FPlatform::getInstance()->runPlugins($plugin_event, array(&$this, &$this->input));
         if (in_array(false, $plugin_result, true)) {
             $result = false;
         }
     }
     if (!$result) {
         throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
     }
     // Do not allow the display task to be directly called
     $task = strtolower($task);
     if (isset($this->taskMap[$task])) {
         $doTask = $this->taskMap[$task];
     } elseif (isset($this->taskMap['__default'])) {
         $doTask = $this->taskMap['__default'];
     } else {
         $doTask = null;
     }
     if ($doTask == 'display') {
         F0FPlatform::getInstance()->setHeader('Status', '400 Bad Request', true);
         throw new Exception('Bad Request', 400);
     }
     $this->doTask = $doTask;
     $ret = $this->{$doTask}();
     $method_name = 'onAfter' . ucfirst($task);
     if (method_exists($this, $method_name)) {
         $result = $this->{$method_name}();
     } else {
         $result = true;
     }
     if ($result) {
         $plugin_event = F0FInflector::camelize('on after ' . $this->bareComponent . ' controller ' . $this->view . ' ' . $task);
         $plugin_result = F0FPlatform::getInstance()->runPlugins($plugin_event, array(&$this, &$this->input, &$ret));
         if (in_array(false, $plugin_result, true)) {
             $result = false;
         }
     }
     if (!$result) {
         throw new Exception(JText::_('JLIB_APPLICATION_ERROR_ACCESS_FORBIDDEN'), 403);
     }
     return $ret;
 }
Esempio n. 3
0
 /**
  * Finds a suitable renderer
  *
  * @return  F0FRenderAbstract
  */
 protected function findRenderer()
 {
     $filesystem = F0FPlatform::getInstance()->getIntegrationObject('filesystem');
     // Try loading the stock renderers shipped with F0F
     if (empty(self::$renderers) || !class_exists('F0FRenderJoomla', false)) {
         $path = dirname(__FILE__) . '/../render/';
         $renderFiles = $filesystem->folderFiles($path, '.php');
         if (!empty($renderFiles)) {
             foreach ($renderFiles as $filename) {
                 if ($filename == 'abstract.php') {
                     continue;
                 }
                 @(include_once $path . '/' . $filename);
                 $camel = F0FInflector::camelize($filename);
                 $className = 'F0FRender' . ucfirst(F0FInflector::getPart($camel, 0));
                 $o = new $className();
                 self::registerRenderer($o);
             }
         }
     }
     // Try to detect the most suitable renderer
     $o = null;
     $priority = 0;
     if (!empty(self::$renderers)) {
         foreach (self::$renderers as $r) {
             $info = $r->getInformation();
             if (!$info->enabled) {
                 continue;
             }
             if ($info->priority > $priority) {
                 $priority = $info->priority;
                 $o = $r;
             }
         }
     }
     // Return the current renderer
     return $o;
 }