protected function getOptions()
 {
     $styleId = (int) $this->form->getValue('id');
     if ($styleId) {
         $styleObject = JUDirectoryFrontHelperTemplate::getTemplateStyleObject($styleId);
         $defaultStyleObject = JUDirectoryFrontHelperTemplate::getDefaultTemplateStyle();
         if ($defaultStyleObject->template_id == $styleObject->template_id) {
             return array_merge(parent::getOptions(), JHtml::_('contentlanguage.existing'));
         } else {
             return parent::getOptions();
         }
     } else {
         return array_merge(parent::getOptions());
     }
 }
Example #2
0
 public function loadTemplate($tpl = null)
 {
     $this->_output = null;
     $app = JFactory::getApplication();
     $template = JFactory::getApplication()->getTemplate();
     if ($this->getName() == 'category' || $this->getName() == 'tree') {
         $layoutUrl = $app->input->getString('layout', '');
         if (isset($layoutUrl) && $layoutUrl != '') {
             $layout = $layoutUrl;
         } else {
             $layout = null;
         }
         $catId = $app->input->getInt('id', 1);
         $layout = JUDirectoryFrontHelperCategory::getCategoryViewLayout($layout, $catId);
         $this->setLayout($layout);
     } elseif ($this->getName() == 'listing') {
         $layoutUrl = $app->input->getString('layout', '');
         if (isset($layoutUrl) && $layoutUrl != '') {
             $layout = $layoutUrl;
         } else {
             $layout = null;
         }
         $listingId = $app->input->getInt('id', 0);
         if ($listingId > 0) {
             $layout = JUDirectoryFrontHelperListing::getListingViewLayout($layout, $listingId);
             $this->setLayout($layout);
         }
     }
     $layout = $this->getLayout();
     $layoutTemplate = $this->getLayoutTemplate();
     $file = isset($tpl) ? $layout . '_' . $tpl : $layout;
     $file = preg_replace('/[^A-Z0-9_\\.-]/i', '', $file);
     $tpl = isset($tpl) ? preg_replace('/[^A-Z0-9_\\.-]/i', '', $tpl) : $tpl;
     $lang = JFactory::getLanguage();
     $lang->load('tpl_' . $template, JPATH_BASE, null, false, false) || $lang->load('tpl_' . $template, JPATH_THEMES . "/{$template}", null, false, false);
     $component = JApplicationHelper::getComponentName();
     $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $component);
     $app = JFactory::getApplication();
     $id = $app->input->getInt('id', 0);
     $user = JFactory::getUser();
     if ($previewStyle = (int) $app->input->getInt('tplStyle', 0)) {
         if ($user->id == 0) {
             $uri = JUri::getInstance();
             $loginUrl = JRoute::_('index.php?option=com_users&view=login&return=' . base64_encode($uri), false);
             $app->enqueueMessage(JText::_("COM_JUDIRECTORY_YOU_MUST_LOGIN_AS_SUPER_ADMIN_TO_PREVIEW_TEMPLATE_STYLE"), 'Notice');
             $app->redirect($loginUrl);
             return false;
         } else {
             if (!$user->authorise('core.admin', 'com_judirectory')) {
                 $app->enqueueMessage(JText::_("COM_JUDIRECTORY_YOU_MUST_LOGIN_AS_SUPER_ADMIN_TO_PREVIEW_TEMPLATE_STYLE"), 'Notice');
             }
         }
     }
     if ($user->authorise('core.admin', 'com_judirectory') && ($previewStyle = (int) $app->input->getInt('tplStyle', 0))) {
         $currentTemplateStyleObject = JUDirectoryFrontHelperTemplate::getTemplateStyleObject($previewStyle);
     } else {
         $currentTemplateStyleObject = JUDirectoryFrontHelperTemplate::getCurrentTemplateStyle($this->getName(), $id);
     }
     $JUTemplate = trim($currentTemplateStyleObject->folder);
     $JUTemplate = strtolower($JUTemplate);
     $this->template_params = $currentTemplateStyleObject->params;
     if (!$JUTemplate) {
         $JUTemplate = 'default';
     }
     $this->template = $JUTemplate;
     $JUTemplatePath = JUDirectoryFrontHelperTemplate::getTemplatePathWithoutRoot($currentTemplateStyleObject->template_id);
     $topLevelTemplate = $JUTemplatePath[0]->folder ? $JUTemplatePath[0]->folder : 'default';
     $asset_file = JPATH_SITE . '/components/com_judirectory/templates/' . $topLevelTemplate . '/load_assets.php';
     if (JFile::exists($asset_file)) {
         include_once $asset_file;
     }
     $JUTemplatePathFull = array();
     $JUTemplatePathFull[] = $this->_basePath . '/templates/default/' . $this->getName();
     $JUTemplatePathFull[] = JPATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . 'default' . '/' . $this->getName();
     $JUTemplatePath = array_reverse($JUTemplatePath);
     foreach ($JUTemplatePath as $JUTemplatePathItem) {
         $JUTemplatePathFull[] = $this->_basePath . '/templates/' . $JUTemplatePathItem->folder . '/' . $this->getName();
         $JUTemplatePathFull[] = JPATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . $JUTemplatePathItem->folder . '/' . $this->getName();
     }
     foreach ($JUTemplatePathFull as $item) {
         $this->_addPath('template', $item);
     }
     if (isset($layoutTemplate) && $layoutTemplate != '_' && $layoutTemplate != $template) {
         $this->_path['template'] = str_replace($template, $layoutTemplate, $this->_path['template']);
     }
     $jversion_arr = explode(".", JVERSION);
     $priVersion = $jversion_arr[0];
     $subVersion = $jversion_arr[1];
     $fileToFind = $this->_createFileName('template', array('name' => $file . '.j' . $priVersion . $subVersion));
     $this->_template = JPath::find($this->_path['template'], $fileToFind);
     if ($this->_template == false) {
         $fileToFind = $this->_createFileName('template', array('name' => $file . '.j' . $priVersion . 'x'));
         $this->_template = JPath::find($this->_path['template'], $fileToFind);
     }
     if ($this->_template == false) {
         $fileToFind = $this->_createFileName('template', array('name' => $file));
         $this->_template = JPath::find($this->_path['template'], $fileToFind);
     }
     if ($this->_template == false) {
         $fallbackPaths = array();
         $fallbackPaths[] = $this->_basePath . '/templates/default/' . $this->getName();
         $fallbackPaths[] = JPATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . 'default' . '/' . $this->getName();
         foreach ($fallbackPaths as $fallbackPath) {
             $fallbackPath = trim($fallbackPath);
             if (substr($fallbackPath, -1) != DIRECTORY_SEPARATOR) {
                 $fallbackPath .= DIRECTORY_SEPARATOR;
             }
             array_unshift($fallbackPaths, $fallbackPath);
         }
         $fileToFind = $this->_createFileName('', array('name' => 'default.j' . $priVersion . $subVersion . (isset($tpl) ? '_' . $tpl : $tpl)));
         $this->_template = JPath::find($fallbackPaths, $fileToFind);
         if ($this->_template == false) {
             $fileToFind = $this->_createFileName('', array('name' => 'default.j' . $priVersion . 'x' . (isset($tpl) ? '_' . $tpl : $tpl)));
             $this->_template = JPath::find($fallbackPaths, $fileToFind);
         }
         if ($this->_template == false) {
             $fileToFind = $this->_createFileName('', array('name' => 'default' . (isset($tpl) ? '_' . $tpl : $tpl)));
             $this->_template = JPath::find($fallbackPaths, $fileToFind);
         }
     }
     if ($this->_template != false) {
         unset($tpl);
         unset($file);
         if (isset($this->this)) {
             unset($this->this);
         }
         ob_start();
         include $this->_template;
         $this->_output = ob_get_contents();
         ob_end_clean();
         return $this->_output;
     } else {
         return JError::raiseError(500, JText::sprintf('JLIB_APPLICATION_ERROR_LAYOUTFILE_NOT_FOUND', $file));
     }
 }
Example #3
0
 public function saveCategoryPrepareTemplateParams($pk, $table, &$data)
 {
     $app = JFactory::getApplication();
     if ($pk > 0) {
         $oldTemplateStyleObject = JUDirectoryFrontHelperTemplate::getTemplateStyleOfCategory($table->id);
         if ($data['style_id'] == -2) {
             $newTemplateStyleObject = JUDirectoryFrontHelperTemplate::getDefaultTemplateStyle();
         } elseif ($data['style_id'] == -1) {
             $newTemplateStyleObject = JUDirectoryFrontHelperTemplate::getTemplateStyleOfCategory($data['parent_id']);
             if ($table->style_id == -1) {
                 if ($table->parent_id != $data['parent_id']) {
                     if ($oldTemplateStyleObject->template_id != $newTemplateStyleObject->template_id) {
                         if ($data['changeTemplateStyleAction'] == 1) {
                             $data['style_id'] = $oldTemplateStyleObject->id;
                             $newTemplateStyleObject = JUDirectoryFrontHelperTemplate::getTemplateStyleObject($data['style_id']);
                             $app->enqueueMessage(JText::sprintf('COM_JUDIRECTORY_INHERITED_TEMPLATE_STYLE_HAS_BEEN_CHANGED_TO_X', $newTemplateStyleObject->title ? $newTemplateStyleObject->title : JText::_("COM_JUDIRECTORY_NONE")), 'Notice');
                         }
                     }
                 }
             }
         } else {
             $newTemplateStyleObject = JUDirectoryFrontHelperTemplate::getTemplateStyleObject($data['style_id']);
         }
     }
     if (isset($data['template_params']) && is_array($data['template_params'])) {
         $registry = new JRegistry();
         $registry->loadArray($data['template_params']);
         $data['template_params'] = (string) $registry;
     }
     if ($pk > 0) {
         if ($oldTemplateStyleObject->template_id != $newTemplateStyleObject->template_id) {
             $data['template_params'] = '';
         }
     }
 }
Example #4
0
 public function saveListingPrepareTemplateParams(&$data, $pk, $isNew, $newMainCatId)
 {
     $removeTemplateParams = false;
     if (!$isNew) {
         $oldTemplateStyleObject = JUDirectoryFrontHelperTemplate::getTemplateStyleOfListing($pk);
         $styleId = $data['style_id'];
         if ($styleId == -2) {
             $newTemplateStyleObject = JUDirectoryFrontHelperTemplate::getDefaultTemplateStyle();
         } elseif ($styleId == -1) {
             $newTemplateStyleObject = JUDirectoryFrontHelperTemplate::getTemplateStyleOfCategory($newMainCatId);
         } else {
             $newTemplateStyleObject = JUDirectoryFrontHelperTemplate::getTemplateStyleObject($styleId);
         }
         if ($oldTemplateStyleObject->template_id != $newTemplateStyleObject->template_id) {
             $data['template_params'] = "";
             $removeTemplateParams = true;
         }
     }
     if (!$removeTemplateParams && isset($data['template_params']) && is_array($data['template_params'])) {
         $registry = new JRegistry();
         $registry->loadArray($data['template_params']);
         $data['template_params'] = $registry->toString();
     }
 }