示例#1
0
 protected function getOptions()
 {
     $styleId = (int) $this->form->getValue('id');
     if ($styleId) {
         $styleObject = JUDownloadFrontHelperTemplate::getTemplateStyleObject($styleId);
         $defaultStyleObject = JUDownloadFrontHelperTemplate::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());
     }
 }
示例#2
0
 public function saveDocumentPrepareTemplateParams(&$data, $pk, $isNew, $newMainCatId)
 {
     $removeTemplateParams = false;
     if (!$isNew) {
         $oldTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfDocument($pk);
         $styleId = $data['style_id'];
         if ($styleId == -2) {
             $newTemplateStyleObject = JUDownloadFrontHelperTemplate::getDefaultTemplateStyle();
         } elseif ($styleId == -1) {
             $newTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($newMainCatId);
         } else {
             $newTemplateStyleObject = JUDownloadFrontHelperTemplate::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();
     }
 }
示例#3
0
 public function prepareDataToImport($data, $isInsert, $config = array())
 {
     $db = JFactory::getDbo();
     $defaultData = array('cat_id' => $data['main_cat']);
     if ($isInsert) {
         $user = JFactory::getUser();
         $offset = $user->getParam('timezone', JFactory::getConfig()->get('offset'));
         if (!empty($config['publish_up'])) {
             $defaultData['publish_up'] = JFactory::getDate($config['publish_up'], $offset)->toSql();
         }
         if (!empty($config['force_publish'])) {
             $data[$this->field_name_id_array['published']] = $config['force_publish'];
         }
         if (!empty($config['publish_down']) && $config['publish_down'] != $db->getNullDate()) {
             $defaultData['publish_down'] = JFactory::getDate($config['publish_down'], $offset)->toSql();
         }
         if (!empty($config['created_by']) && $config['created_by'] > 0) {
             $defaultData['created_by'] = $config['created_by'];
         }
         if (!empty($config['default_icon'])) {
             $defaultData['icon'] = $config['default_icon'];
         }
         if (empty($defaultData['metadescription']) && !empty($config['meta_description'])) {
             $defaultData['metadescription'] = $config['meta_description'];
         }
         if (empty($defaultData['metakeyword']) && !empty($config['meta_keyword'])) {
             $defaultData['metakeyword'] = $config['meta_keyword'];
         }
         if (empty($data['secondary_cats']) && !empty($config['secondary_cats_assign'])) {
             $data['secondary_cats'] = $config['secondary_cats_assign'];
         }
         if (empty($defaultData['language'])) {
             $defaultData['language'] = '*';
         }
         if (empty($defaultData['access'])) {
             $defaultData['access'] = 1;
         }
         if (empty($defaultData['style_id'])) {
             $defaultData['style_id'] = -1;
         }
         if (empty($defaultData['layout'])) {
             $defaultData['layout'] = -1;
         }
         if (empty($defaultData['params'])) {
             $params = array('display_params' => array('show_comment' => -2, 'fields' => array('title' => array('detail_view' => -2), 'created' => array('detail_view' => -2), 'author' => array('detail_view' => -2), 'cat_id' => array('detail_view' => -2), 'rating' => array('detail_view' => -2))));
             $defaultData['params'] = json_encode($params);
         }
     }
     if (!empty($data['secondary_cats'])) {
         if (is_string($data['secondary_cats'])) {
             $data['secondary_cats'] = explode(',', $data['secondary_cats']);
         }
         $index = array_search($data['main_cat'], $data['secondary_cats']);
         if ($index) {
             unset($data['secondary_cats'][$index]);
         }
         $rootCat = JUDownloadFrontHelperCategory::getRootCategory();
         $params = JUDownloadHelper::getParams();
         $index = array_search($rootCat->id, $data['secondary_cats']);
         if ($index && !$params->get('allow_add_doc_to_root', 0)) {
             unset($data['secondary_cats'][$index]);
         }
         $data[$this->field_name_id_array['cat_id']]['secondary'] = implode(',', $data['secondary_cats']);
     }
     $aliasFieldId = $this->field_name_id_array['alias'];
     $titleFieldId = $this->field_name_id_array['title'];
     if (!$isInsert) {
         $oldMainCatId = JUDownloadFrontHelperCategory::getMainCategoryId($data['id']);
         if ($data['main_cat'] != $oldMainCatId) {
             if (empty($data[$titleFieldId])) {
                 $document = JUDownloadHelper::getDocumentById($data['id']);
                 $data[$titleFieldId] = $document->title;
             }
             if (empty($data[$aliasFieldId])) {
                 $document = JUDownloadHelper::getDocumentById($data['id']);
                 $data[$aliasFieldId] = $document->alias;
             }
         }
     }
     if (empty($data[$aliasFieldId])) {
         $data[$aliasFieldId] = strtolower(JApplication::stringURLSafe($data[$titleFieldId]));
     }
     $this->titleIncrement($data['main_cat'], $data['id'], $data[$aliasFieldId], $data[$titleFieldId]);
     $data['gallery'] = !empty($data['gallery']) ? explode('|', $data['gallery']) : array();
     $data['files'] = !empty($data['files']) ? explode('|', $data['files']) : array();
     $data['related_docs'] = !empty($data['related_docs']) ? explode(',', $data['related_docs']) : array();
     if (!empty($data['style_id']) && !$isInsert) {
         $oldTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfDocument($data['id']);
         $styleId = $data['style_id'];
         if ($styleId == -2) {
             $newTemplateStyleObject = JUDownloadFrontHelperTemplate::getDefaultTemplateStyle();
         } elseif ($styleId == -1) {
             $newTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($data['main_cat']);
         } else {
             $newTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleObject($styleId);
         }
         if ($oldTemplateStyleObject->template_id != $newTemplateStyleObject->template_id && !isset($data['template_params'])) {
             $data['template_params'] = '';
         }
     }
     if (!empty($data['template_params']) && is_array($data['template_params'])) {
         $registry = new JRegistry();
         $registry->loadArray($data['template_params']);
         $data['template_params'] = $registry->toString();
     }
     $data['plugin_params'] = !empty($data['plugin_params']) ? $data['plugin_params'] : array();
     if (!is_array($data['plugin_params'])) {
         $registry = new JRegistry();
         $registry->loadString($data['plugin_params']);
         $data['plugin_params'] = $registry->toArray();
     }
     $db_plugin_params = array();
     if (!$isInsert) {
         $db->setQuery("SELECT plugin_params FROM #__judownload_documents WHERE id = " . $data['id']);
         $rule_str = $db->loadResult();
         $rule_registry = new JRegistry();
         $rule_registry->loadString($rule_str);
         $db_plugin_params = $rule_registry->toArray();
     }
     if (!empty($db_plugin_params)) {
         $db->setQuery("SELECT element FROM #__extensions WHERE type='plugin' AND folder = 'judownload'");
         $rule_plugins = $db->loadColumn();
         foreach ($db_plugin_params as $name => $value) {
             if (!in_array($name, $rule_plugins)) {
                 unset($db_plugin_params[$name]);
             }
             if (array_key_exists($name, $data['plugin_params'])) {
                 unset($db_plugin_params[$name]);
             }
         }
     }
     $plugin_params = array_merge($db_plugin_params, $data['plugin_params']);
     $registry = new JRegistry();
     $registry->loadArray($plugin_params);
     $data['plugin_params'] = $registry->toString();
     $fieldsData = array();
     foreach ($data as $key => $value) {
         if (is_numeric($key)) {
             $fieldsData[$key] = $value;
         } elseif (is_string($key) && $key != 'files' && $key != 'gallery' && $key != 'main_cat' && $key != 'secondary_cats' && $key != 'related_docs') {
             $defaultData[$key] = $value;
         }
     }
     $postData = array('main_cat' => $data['main_cat'], 'data' => $defaultData, 'fieldsData' => $fieldsData, 'files' => $data['files'], 'gallery' => $data['gallery'], 'related_docs' => $data['related_docs']);
     return $postData;
 }
示例#4
0
 public function saveCategoryPrepareTemplateParams($pk, $table, &$data)
 {
     $app = JFactory::getApplication();
     if ($pk > 0) {
         $oldTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($table->id);
         if ($data['style_id'] == -2) {
             $newTemplateStyleObject = JUDownloadFrontHelperTemplate::getDefaultTemplateStyle();
         } elseif ($data['style_id'] == -1) {
             $newTemplateStyleObject = JUDownloadFrontHelperTemplate::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 = JUDownloadFrontHelperTemplate::getTemplateStyleObject($data['style_id']);
                             $app->enqueueMessage(JText::sprintf('COM_JUDOWNLOAD_INHERITED_TEMPLATE_STYLE_HAS_BEEN_CHANGED_TO_X', $newTemplateStyleObject->title ? $newTemplateStyleObject->title : JText::_("COM_JUDOWNLOAD_NONE")), 'Notice');
                         }
                     }
                 }
             }
         } else {
             $newTemplateStyleObject = JUDownloadFrontHelperTemplate::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'] = '';
         }
     }
 }
示例#5
0
 public function setDefault($cid)
 {
     $app = JFactory::getApplication();
     $jInput = $app->input;
     $keepStyleDefault = $jInput->post->getInt('changeTemplateStyleAction', 1);
     $db = JFactory::getDbo();
     $styleObject = JUDownloadFrontHelperTemplate::getTemplateStyleObject($cid);
     $defaultTemplateStyleObject = JUDownloadFrontHelperTemplate::getDefaultTemplateStyle();
     if ($styleObject->template_id != $defaultTemplateStyleObject->template_id) {
         if ($keepStyleDefault == 1) {
             JUDownloadFrontHelperTemplate::updateStyleIdForCatDocUsingDefaultStyle($defaultTemplateStyleObject->id);
         } else {
             JUDownloadFrontHelperTemplate::removeTemplateParamsOfCatDocUsingDefaultStyle();
         }
     }
     $query = $db->getQuery(true);
     $query->update('#__judownload_template_styles');
     $query->set('home = 0');
     $query->where('home = 1');
     $db->setQuery($query);
     $db->execute();
     $query = $db->getQuery(true);
     $query->update('#__judownload_template_styles');
     $query->set('home = 1');
     $query->where('id = ' . (int) $cid);
     $db->setQuery($query);
     $db->execute();
 }
示例#6
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 = JUDownloadFrontHelperCategory::getCategoryViewLayout($layout, $catId);
			$this->setLayout($layout);
		}
		elseif ($this->getName() == 'document')
		{
			
			$layoutUrl = $app->input->getString('layout', '');
			if (isset($layoutUrl) && $layoutUrl != '')
			{
				$layout = $layoutUrl;
			}
			else
			{
				$layout = null;
			}
			$docId = $app->input->getInt('id', 0);

			if ($docId > 0)
			{
				$layout = JUDownloadFrontHelperDocument::getDocumentViewLayout($layout, $docId);

				$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_JUDOWNLOAD_YOU_MUST_LOGIN_AS_SUPER_ADMIN_TO_PREVIEW_TEMPLATE_STYLE"), 'Notice');
				$app->redirect($loginUrl);

				return false;
			}
			else
			{
				if (!$user->authorise('core.admin', 'com_judownload'))
				{
					$app->enqueueMessage(JText::_("COM_JUDOWNLOAD_YOU_MUST_LOGIN_AS_SUPER_ADMIN_TO_PREVIEW_TEMPLATE_STYLE"), 'Notice');
				}
			}
		}

		
		if ($user->authorise('core.admin', 'com_judownload') && $previewStyle = (int) $app->input->getInt('tplStyle', 0))
		{
			$currentTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleObject($previewStyle);
		}
		else
		{
			$currentTemplateStyleObject = JUDownloadFrontHelperTemplate::getCurrentTemplateStyle($this->getName(), $id);
		}

		$JUTemplate            = trim($currentTemplateStyleObject->folder);
		$JUTemplate            = strtolower($JUTemplate);
		$this->template_params = $currentTemplateStyleObject->params;

		if (!$JUTemplate)
		{
			$JUTemplate = 'default';
		}

		$this->template = $JUTemplate;

		
		$JUTemplatePath = JUDownloadFrontHelperTemplate::getTemplatePathWithoutRoot($currentTemplateStyleObject->template_id);

		$topLevelTemplate = $JUTemplatePath[0]->folder ? $JUTemplatePath[0]->folder : 'default';

		
		$asset_file = JPATH_SITE . '/components/com_judownload/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));
		}
	}