diff --git a/administrator/components/com_templates/src/Controller/StylesController.php b/administrator/components/com_templates/src/Controller/StylesController.php index 54c116802d122..a381f6d949b6b 100644 --- a/administrator/components/com_templates/src/Controller/StylesController.php +++ b/administrator/components/com_templates/src/Controller/StylesController.php @@ -23,6 +23,39 @@ */ class StylesController extends AdminController { + /** + * Method to create a child template. + * + * @return void + */ + public function createChild() + { + // Check for request forgeries + $this->checkToken(); + + $pks = $this->input->post->get('cid', array(), 'array'); + + try + { + if (empty($pks)) + { + throw new \Exception(Text::_('COM_TEMPLATES_NO_TEMPLATE_SELECTED')); + } + + $pks = ArrayHelper::toInteger($pks); + + $model = $this->getModel($name = 'Template', $prefix = 'Administrator', $config = array()); +// $model->duplicate($pks); + $this->setMessage(Text::_('COM_TEMPLATES_SUCCESS_DUPLICATED')); + } + catch (\Exception $e) + { + $this->app->enqueueMessage($e->getMessage(), 'error'); + } + + $this->setRedirect('index.php?option=com_templates&view=styles'); + } + /** * Method to clone and existing template style. * diff --git a/administrator/components/com_templates/src/Model/StylesModel.php b/administrator/components/com_templates/src/Model/StylesModel.php index b900bcd636219..1424f83d1dc02 100644 --- a/administrator/components/com_templates/src/Model/StylesModel.php +++ b/administrator/components/com_templates/src/Model/StylesModel.php @@ -132,6 +132,8 @@ protected function getListQuery() $db->quoteName('a.title'), $db->quoteName('a.home'), $db->quoteName('a.client_id'), + $db->quoteName('a.inheritable'), + $db->quoteName('a.parent'), $db->quoteName('l.title', 'language_title'), $db->quoteName('l.image'), $db->quoteName('l.sef', 'language_sef'), @@ -157,6 +159,8 @@ protected function getListQuery() $db->quoteName('a.title'), $db->quoteName('a.home'), $db->quoteName('a.client_id'), + $db->quoteName('a.inheritable'), + $db->quoteName('a.parent'), $db->quoteName('l.title'), $db->quoteName('l.image'), $db->quoteName('l.sef'), diff --git a/administrator/components/com_templates/src/Model/TemplateModel.php b/administrator/components/com_templates/src/Model/TemplateModel.php index af7ad955f1538..8f636eb929d28 100644 --- a/administrator/components/com_templates/src/Model/TemplateModel.php +++ b/administrator/components/com_templates/src/Model/TemplateModel.php @@ -50,6 +50,22 @@ class TemplateModel extends FormModel */ protected $element = null; + /** + * The path to the template + * + * @var \stdClass + * @since 3.2 + */ + protected $elementMedia = null; + + /** + * Mode indicator + * + * @var boolean + * @since __DEPLOY_VERSION__ + */ + protected $supportsChildren = false; + /** * Internal method to get file properties. * @@ -382,24 +398,34 @@ public function getFiles() if ($template = $this->getTemplate()) { - $app = Factory::getApplication(); - $client = ApplicationHelper::getClientInfo($template->client_id); - $path = Path::clean($client->path . '/templates/' . $template->element . '/'); - $lang = Factory::getLanguage(); + $app = Factory::getApplication(); + $client = ApplicationHelper::getClientInfo($template->client_id); + $clientPath = ($client->id == 0) ? '' : 'administrator/'; + $this->element = Path::clean($client->path . '/templates/' . $template->element . '/'); + $this->elementMedia = Path::clean(JPATH_ROOT . '/media/templates/' . $clientPath . $template->element . '/');; + $lang = Factory::getLanguage(); // Load the core and/or local language file(s). $lang->load('tpl_' . $template->element, $client->path) || $lang->load('tpl_' . $template->element, $client->path . '/templates/' . $template->element); - $this->element = $path; - if (!is_writable($path)) + if (!is_writable($this->element)) { $app->enqueueMessage(Text::_('COM_TEMPLATES_DIRECTORY_NOT_WRITABLE'), 'error'); } - if (is_dir($path)) + if (is_dir($this->element)) { - $result = $this->getDirectoryTree($path); + $result = $this->getDirectoryTree($this->element); + + // New mode + if (is_dir($this->elementMedia)) + { + $resultTmp = $this->getDirectoryTree($this->elementMedia); + + $result = array_merge( + (array) $result, (array) $resultTmp); + } } else { @@ -437,6 +463,7 @@ public function getDirectoryTree($dir) if (is_dir($dir . $value)) { $relativePath = str_replace($this->element, '', $dir . $value); + $relativePath = str_replace($this->elementMedia, '', $relativePath); $result['/' . $relativePath] = $this->getDirectoryTree($dir . $value . '/'); } else @@ -927,20 +954,12 @@ public function &getSource() if ($this->template) { - $input = Factory::getApplication()->input; - $fileName = base64_decode($input->get('file')); - $client = ApplicationHelper::getClientInfo($this->template->client_id); + $input = Factory::getApplication()->input; + $fileName = base64_decode($input->get('file')); + $client = ApplicationHelper::getClientInfo($this->template->client_id); + $clientPath = ($client->id == 0) ? '' : 'administrator/'; - try - { - $filePath = Path::check($client->path . '/templates/' . $this->template->element . '/' . $fileName); - } - catch (\Exception $e) - { - $app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_FOUND'), 'error'); - - return; - } + $filePath = Path::check($client->path . '/templates/' . $this->template->element . $fileName); if (file_exists($filePath)) { @@ -955,6 +974,19 @@ public function &getSource() $item->core = file_get_contents($coreFile); } } + elseif (file_exists($filePathNew = Path::check($fileName))) + { + $item->extension_id = $this->getState('extension.id'); + $item->filename = Path::clean($fileName); + $item->source = file_get_contents($filePathNew); + $item->filePath = Path::clean($filePathNew); + + if ($coreFile = $this->getCoreFile($fileName, $this->template->client_id)) + { + $item->coreFile = $coreFile; + $item->core = file_get_contents($coreFile); + } + } else { $app->enqueueMessage(Text::_('COM_TEMPLATES_ERROR_SOURCE_FILE_NOT_FOUND'), 'error'); diff --git a/administrator/components/com_templates/src/Model/TemplatesModel.php b/administrator/components/com_templates/src/Model/TemplatesModel.php index 0bb8f057d086f..e1a0b32811f44 100644 --- a/administrator/components/com_templates/src/Model/TemplatesModel.php +++ b/administrator/components/com_templates/src/Model/TemplatesModel.php @@ -142,6 +142,10 @@ protected function getListQuery() ->where($db->quoteName('a.client_id') . ' = :clientid') ->where($db->quoteName('a.enabled') . ' = 1') ->where($db->quoteName('a.type') . ' = ' . $db->quote('template')) + + // Exclude children templates + ->join('INNER', '#__template_styles AS b', $db->quoteName('a.element') . ' = b.template AND ' . $db->quoteName('b.parent') . ' = ""') + ->bind(':clientid', $clientId, ParameterType::INTEGER); // Filter by search in title. diff --git a/administrator/components/com_templates/src/Service/HTML/Templates.php b/administrator/components/com_templates/src/Service/HTML/Templates.php index 8745d3eda5f94..627b1955bedd8 100644 --- a/administrator/components/com_templates/src/Service/HTML/Templates.php +++ b/administrator/components/com_templates/src/Service/HTML/Templates.php @@ -39,11 +39,11 @@ public function thumb($template, $clientId = 0) $basePath = $client->path . '/templates/' . $template; $thumb = $basePath . '/template_thumbnail.png'; $preview = $basePath . '/template_preview.png'; + $clientPath = ($clientId == 0) ? '' : 'administrator/'; $html = ''; if (file_exists($thumb)) { - $clientPath = ($clientId == 0) ? '' : 'administrator/'; $thumb = $clientPath . 'templates/' . $template . '/template_thumbnail.png'; $html = HTMLHelper::_('image', $thumb, Text::_('COM_TEMPLATES_PREVIEW')); @@ -53,6 +53,19 @@ public function thumb($template, $clientId = 0) } } + // Alter the paths for the new mode + $basePath = JPATH_ROOT . '/media/templates/' . $clientPath . $template; + $thumb = $basePath . '/template_thumbnail.png'; + + if (file_exists($thumb)) { + $html = HTMLHelper::_('image', 'media/templates/' . $clientPath . $template . '/template_thumbnail.png', Text::_('COM_TEMPLATES_PREVIEW'), [], false); + + if (file_exists($basePath . '/template_preview.png')) + { + $html = ''; + } + } + return $html; } @@ -70,6 +83,7 @@ public function thumbModal($template, $clientId = 0) { $client = ApplicationHelper::getClientInfo($clientId); $basePath = $client->path . '/templates/' . $template; + $clientPath = ($clientId == 0) ? '' : 'administrator/'; $baseUrl = ($clientId == 0) ? Uri::root(true) : Uri::root(true) . '/administrator'; $thumb = $basePath . '/template_thumbnail.png'; $preview = $basePath . '/template_preview.png'; @@ -94,6 +108,31 @@ public function thumbModal($template, $clientId = 0) ); } + // Alter the paths for the new mode + $basePath = JPATH_ROOT . '/media/templates/' . $clientPath . $template; + $baseUrl = Uri::root(true); + $thumb = $basePath . '/template_thumbnail.png'; + $preview = $basePath . '/template_preview.png'; + + if (file_exists($thumb) && file_exists($preview)) + { + $preview = '/media/templates/' . $clientPath . $template . '/template_preview.png'; + $footer = ''; + + $html .= HTMLHelper::_( + 'bootstrap.renderModal', + $template . '-Modal', + array( + 'title' => Text::sprintf('COM_TEMPLATES_SCREENSHOT', ucfirst($template)), + 'height' => '500px', + 'width' => '800px', + 'footer' => $footer, + ), + $body = '