Example #1
0
 /**
  * Load controller file
  *
  * @param   string $class Class name
  */
 private function controller($class)
 {
     if (!strstr(strtolower($class), 'controller')) {
         return;
     }
     $class = str_replace('\\', '/', $class);
     $file = explode('/', $class);
     $file = strtolower(array_pop($file));
     $path = JPATH_SITE . '/libraries/fabrik/fabrik/Controllers/' . \Joomla\String\StringHelper::ucfirst($file) . '.php';
     if (file_exists($path)) {
         require_once $path;
     }
 }
Example #2
0
 /**
  * Method to instantiate the form field object.
  *
  * @param   JForm  $form  The form to attach to the form field object.
  *
  * @since   11.1
  */
 public function __construct($form = null)
 {
     // If there is a form passed into the constructor set the form and form control properties.
     if ($form instanceof JForm) {
         $this->form = $form;
         $this->formControl = $form->getFormControl();
     }
     // Detect the field type if not set
     if (!isset($this->type)) {
         $parts = Normalise::fromCamelCase(get_called_class(), true);
         if ($parts[0] == 'J') {
             $this->type = StringHelper::ucfirst($parts[count($parts) - 1], '_');
         } else {
             $this->type = StringHelper::ucfirst($parts[0], '_') . StringHelper::ucfirst($parts[count($parts) - 1], '_');
         }
     }
 }
Example #3
0
 /**
  * Method to add alternative meta tags for associated menu items.
  *
  * @return  void
  *
  * @since   1.7
  */
 public function onAfterDispatch()
 {
     $doc = JFactory::getDocument();
     if ($this->app->isSite() && $this->params->get('alternate_meta', 1) && $doc->getType() == 'html') {
         $languages = $this->lang_codes;
         $homes = JLanguageMultilang::getSiteHomePages();
         $menu = $this->app->getMenu();
         $active = $menu->getActive();
         $levels = JFactory::getUser()->getAuthorisedViewLevels();
         $remove_default_prefix = $this->params->get('remove_default_prefix', 0);
         $server = JUri::getInstance()->toString(array('scheme', 'host', 'port'));
         $is_home = false;
         $currentInternalUrl = 'index.php?' . http_build_query($this->app->getRouter()->getVars());
         if ($active) {
             $active_link = JRoute::_($active->link . '&Itemid=' . $active->id);
             $current_link = JRoute::_($currentInternalUrl);
             // Load menu associations
             if ($active_link == $current_link) {
                 $associations = MenusHelper::getAssociations($active->id);
             }
             // Check if we are on the home page
             $is_home = $active->home && ($active_link == $current_link || $active_link == $current_link . 'index.php' || $active_link . '/' == $current_link);
         }
         // Load component associations.
         $option = $this->app->input->get('option');
         $cName = StringHelper::ucfirst(StringHelper::str_ireplace('com_', '', $option)) . 'HelperAssociation';
         JLoader::register($cName, JPath::clean(JPATH_COMPONENT_SITE . '/helpers/association.php'));
         if (class_exists($cName) && is_callable(array($cName, 'getAssociations'))) {
             $cassociations = call_user_func(array($cName, 'getAssociations'));
         }
         // For each language...
         foreach ($languages as $i => &$language) {
             switch (true) {
                 // Language without frontend UI || Language without specific home menu || Language without authorized access level
                 case !array_key_exists($i, JLanguageMultilang::getSiteLangs()):
                 case !isset($homes[$i]):
                 case isset($language->access) && $language->access && !in_array($language->access, $levels):
                     unset($languages[$i]);
                     break;
                     // Home page
                 // Home page
                 case $is_home:
                     $language->link = JRoute::_('index.php?lang=' . $language->sef . '&Itemid=' . $homes[$i]->id);
                     break;
                     // Current language link
                 // Current language link
                 case $i == $this->current_lang:
                     $language->link = JRoute::_($currentInternalUrl);
                     break;
                     // Component association
                 // Component association
                 case isset($cassociations[$i]):
                     $language->link = JRoute::_($cassociations[$i] . '&lang=' . $language->sef);
                     break;
                     // Menu items association
                     // Heads up! "$item = $menu" here below is an assignment, *NOT* comparison
                 // Menu items association
                 // Heads up! "$item = $menu" here below is an assignment, *NOT* comparison
                 case isset($associations[$i]) && ($item = $menu->getItem($associations[$i])):
                     $language->link = JRoute::_($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef);
                     break;
                     // Too bad...
                 // Too bad...
                 default:
                     unset($languages[$i]);
             }
         }
         // If there are at least 2 of them, add the rel="alternate" links to the <head>
         if (count($languages) > 1) {
             // Remove the sef from the default language if "Remove URL Language Code" is on
             if (isset($languages[$this->default_lang]) && $remove_default_prefix) {
                 $languages[$this->default_lang]->link = preg_replace('|/' . $languages[$this->default_lang]->sef . '/|', '/', $languages[$this->default_lang]->link, 1);
             }
             foreach ($languages as $i => &$language) {
                 $doc->addHeadLink($server . $language->link, 'alternate', 'rel', array('hreflang' => $i));
             }
             // Add x-default language tag
             if ($this->params->get('xdefault', 1)) {
                 $xdefault_language = $this->params->get('xdefault_language', $this->default_lang);
                 $xdefault_language = $xdefault_language == 'default' ? $this->default_lang : $xdefault_language;
                 if (isset($languages[$xdefault_language])) {
                     // Use a custom tag because addHeadLink is limited to one URI per tag
                     $doc->addCustomTag('<link href="' . $server . $languages[$xdefault_language]->link . '" rel="alternate" hreflang="x-default" />');
                 }
             }
         }
     }
 }
Example #4
0
 /**
  * Load a class for one of the form's entities of a particular type.
  * Currently, it makes sense to use this method for the "field" and "rule" entities
  * (but you can support more entities in your subclass).
  *
  * @param   string  $entity  One of the form entities (field or rule).
  * @param   string  $type    Type of an entity.
  *
  * @return  string|boolean  Class name on success or false otherwise.
  *
  * @since   11.1
  */
 protected static function loadClass($entity, $type)
 {
     $prefix = 'J';
     if (strpos($type, '.')) {
         list($prefix, $type) = explode('.', $type);
     }
     $class = StringHelper::ucfirst($prefix, '_') . 'Form' . StringHelper::ucfirst($entity, '_') . StringHelper::ucfirst($type, '_');
     if (class_exists($class)) {
         return $class;
     }
     // Get the field search path array.
     $paths = self::addPath($entity);
     // If the type is complex, add the base type to the paths.
     if ($pos = strpos($type, '_')) {
         // Add the complex type prefix to the paths.
         for ($i = 0, $n = count($paths); $i < $n; $i++) {
             // Derive the new path.
             $path = $paths[$i] . '/' . strtolower(substr($type, 0, $pos));
             // If the path does not exist, add it.
             if (!in_array($path, $paths)) {
                 $paths[] = $path;
             }
         }
         // Break off the end of the complex type.
         $type = substr($type, $pos + 1);
     }
     // Try to find the class file.
     $type = strtolower($type) . '.php';
     foreach ($paths as $path) {
         $file = JPath::find($path, $type);
         if (!$file) {
             continue;
         }
         JLoader::register($class, $file);
         if (class_exists($class)) {
             break;
         }
     }
     // Check for all if the class exists.
     return class_exists($class) ? $class : false;
 }