Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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'),
Expand Down
74 changes: 53 additions & 21 deletions administrator/components/com_templates/src/Model/TemplateModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
{
Expand All @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand All @@ -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 = '<button type="button" data-target="#' . $template . '-Modal" class="thumbnail float-left" data-toggle="modal" title="'. Text::_('COM_TEMPLATES_CLICK_TO_ENLARGE') . '">' . $html . '</button>';
}
}

return $html;
}

Expand All @@ -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';
Expand All @@ -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 = '<button type="button" class="btn btn-secondary" data-dismiss="modal">'
. Text::_('JTOOLBAR_CLOSE') . '</button>';

$html .= HTMLHelper::_(
'bootstrap.renderModal',
$template . '-Modal',
array(
'title' => Text::sprintf('COM_TEMPLATES_SCREENSHOT', ucfirst($template)),
'height' => '500px',
'width' => '800px',
'footer' => $footer,
),
$body = '<div><img src="' . $preview . '" style="max-width:100%" alt="' . $template . '"></div>'
);
}

return $html;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\GenericDataException;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
use Joomla\CMS\Session\Session;
use Joomla\CMS\Toolbar\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;

/**
Expand Down Expand Up @@ -115,6 +117,7 @@ public function display($tpl = null)
protected function addToolbar()
{
$canDo = ContentHelper::getActions('com_templates');
$bar = Toolbar::getInstance('toolbar');

// Set the title.
if ((int) $this->get('State')->get('client_id') === 1)
Expand All @@ -128,13 +131,17 @@ protected function addToolbar()

if ($canDo->get('core.edit.state'))
{
ToolbarHelper::makeDefault('styles.setDefault', 'COM_TEMPLATES_TOOLBAR_SET_HOME');
$bar->appendButton('Custom', '<button class="button-copy btn btn-primary" disabled id="style-default" data-token="' . Session::getFormToken() . '" ><span class="icon-star" aria-hidden="true"></span> ' . Text::_('COM_TEMPLATES_TOOLBAR_SET_HOME') . '</button>', 'COM_TEMPLATES_TOOLBAR_SET_HOME', 'styleSetDefault');
ToolbarHelper::divider();
}

if ($canDo->get('core.create'))
{
ToolbarHelper::custom('styles.duplicate', 'copy', '', 'JTOOLBAR_DUPLICATE', true);
$bar->appendButton('Custom', '<button class="btn btn-warning" disabled id="create-child" data-token="' . Session::getFormToken() . '" ><span class="icon-copy" aria-hidden="true"></span> ' . Text::_('JTOOLBAR_CREATE_CHILD') . '</button>', 'JTOOLBAR_CREATE_CHILD', 'createChild');
ToolbarHelper::divider();
$bar->appendButton('Custom', '<button class="btn btn-warning" disabled id="override-child" data-token="' . Session::getFormToken() . '" ><span class="icon-edit" aria-hidden="true"></span> ' . Text::_('JTOOLBAR_OVERRIDE_CHILD') . '</button>', 'JTOOLBAR_OVERRIDE_CHILD', 'overrideChild');
ToolbarHelper::divider();
ToolbarHelper::custom('styles.duplicate', 'copy.png', 'copy_f2.png', 'JTOOLBAR_DUPLICATE', true);
ToolbarHelper::divider();
}

Expand Down
36 changes: 34 additions & 2 deletions administrator/components/com_templates/tmpl/styles/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,29 @@
$clientId = (int) $this->state->get('client_id', 0);
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));

/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa->addInlineStyle(
<<<CSS
.subhead joomla-toolbar-button {
-webkit-margin-start: 0;
margin-inline-start: 0;
}
.subhead .btn, .subhead .btn-group {
-webkit-margin-start: .75rem;
margin-inline-start: .75rem;
}

.subhead .btn > span {
-webkit-margin-end: .5rem;
margin-inline-end: .5rem;
}
CSS
);

$wa->registerAndUseScript('com_templates.styles_default_esm', 'com_templates/admin-styles-default.es6.js', ['version' => 'auto', 'relative' => true], ['type' => 'module', 'defer' => true]);
$wa->registerAndUseScript('com_templates.styles_default', 'com_templates/admin-styles-default.js', ['version' => 'auto', 'relative' => true], ['nomodule' => '', 'defer' => true]);
?>
<form action="<?php echo Route::_('index.php?option=com_templates&view=styles'); ?>" method="post" name="adminForm" id="adminForm">
<div class="row">
Expand All @@ -38,7 +61,7 @@
<thead>
<tr>
<td class="w-1 text-center">
<?php echo HTMLHelper::_('grid.checkall'); ?>
<!-- --><?php //echo HTMLHelper::_('grid.checkall'); ?>
</td>
<th scope="col">
<?php echo HTMLHelper::_('searchtools.sort', 'COM_TEMPLATES_HEADING_STYLE', 'a.title', $listDirn, $listOrder); ?>
Expand Down Expand Up @@ -67,10 +90,19 @@
$canCreate = $user->authorise('core.create', 'com_templates');
$canEdit = $user->authorise('core.edit', 'com_templates');
$canChange = $user->authorise('core.edit.state', 'com_templates');
$isParent = $item->inheritable ? 'true' : 'false';
$canEdit = $canChange ? 'true' : 'false';
$isHome = $item->home == '0' ? 'false' : 'true';
$isChild = !empty($item->parent) ? 'true' : 'false';
?>
<tr class="row<?php echo $i % 2; ?>">
<td class="w-1 text-center">
<?php echo HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->title); ?>
<?php echo '<label for="cb' . $i . '"><span class="sr-only">' . Text::_('JSELECT')
. ' ' . htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8') . '</span></label>'
. '<input type="radio" id="cb' . $i . '" name="cid[]" value="' . $item->id
. '" onclick="Joomla.isChecked(this.checked);" data-is-parent="' . $isParent
. '" data-can-edit="' . $canEdit . '" data-is-home="' . $isHome . '" data-is-child="' . $isChild . '">';
?>
</td>
<th scope="row">
<?php if ($canEdit) : ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@
defined('_JEXEC') or die;
ksort($this->files, SORT_STRING);
?>

<ul class="directory-tree treeselect">
<?php foreach($this->files as $key => $value) : ?>
<?php if (is_array($value)) : ?>
<li class="folder-select">
<a class="folder-url" data-id="<?php echo base64_encode($key); ?>" href="">
<span class="icon-folder icon-fw" aria-hidden="true"></span>
<?php $explodeArray = explode('/', $key); echo $this->escape(end($explodeArray)); ?>
</a>
<?php echo $this->folderTree($value); ?>
<details class="folder-url" data-id="<?php echo base64_encode($key); ?>">
<summary>
<span class="icon-folder icon-fw" aria-hidden="true"></span>
<?php $explodeArray = explode('/', $key); echo $this->escape(end($explodeArray)); ?>
</summary>
<?php echo $this->folderTree($value); ?>
</details>
</li>
<?php endif; ?>
<?php endforeach; ?>
Expand Down
Loading