Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.1 com_templates, child templates 2/2 #35879

Closed
Closed
Changes from 34 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
ed0a641
New mode for cassiopeia and atum
dgrammatiko Oct 22, 2021
ed0fa0a
DB Changes
dgrammatiko Oct 22, 2021
d29cd20
Fix wrong import paths
dgrammatiko Oct 22, 2021
108250f
SQL for updates
dgrammatiko Oct 22, 2021
843a3b4
Deleted files and folder for changing core templates to inheritable
richard67 Oct 22, 2021
60476dd
Better version comments
richard67 Oct 22, 2021
4b3c5f0
Merge pull request #4 from richard67/4.1-dev-dgrammatiko-child-templa…
dgrammatiko Oct 22, 2021
cac4933
Move custom files in core templates to media folder on update
richard67 Oct 22, 2021
6de4fc4
Better English in the comment
richard67 Oct 22, 2021
06edcdc
Merge pull request #5 from richard67/4.1-dev-dgrammatiko-child-templa…
dgrammatiko Oct 22, 2021
dca3ac9
Fix some paths
dgrammatiko Oct 22, 2021
00e431b
System templates
dgrammatiko Oct 22, 2021
8680438
Deleted files and folders for system templates
richard67 Oct 23, 2021
09b4d89
Move template preview files, too
richard67 Oct 23, 2021
9faa291
Create parent folders if necessary at target path
richard67 Oct 23, 2021
1562dff
Don't delete template previews
richard67 Oct 23, 2021
aa87408
Merge pull request #6 from richard67/4.1-dev-dgrammatiko-child-templa…
dgrammatiko Oct 23, 2021
d8a1d8b
Revert special handling for core template preview images
richard67 Oct 23, 2021
d59f121
Merge pull request #7 from richard67/4.1-dev-dgrammatiko-child-templa…
dgrammatiko Oct 23, 2021
40f24d9
move images to the correct folder
dgrammatiko Oct 23, 2021
d08883b
Fix the thumb/preview paths
dgrammatiko Oct 23, 2021
8502440
xmldata not always in the template object
dgrammatiko Oct 23, 2021
cef1870
CS
dgrammatiko Oct 23, 2021
4ded3d7
Child Creation logic
dgrammatiko Oct 23, 2021
2725303
Create a media folder
dgrammatiko Oct 23, 2021
0d3af89
more
dgrammatiko Oct 28, 2021
e7e0304
tree-view
dgrammatiko Nov 1, 2021
5a8cb83
more
dgrammatiko Nov 1, 2021
9169c32
Fix the adapter, fallback image
dgrammatiko Nov 2, 2021
e9ebc5d
Lang, child tmpls name convention: parent_child
dgrammatiko Nov 2, 2021
bbbf42b
Fix the img paths
dgrammatiko Nov 2, 2021
132b236
Fix roboto path
dgrammatiko Nov 2, 2021
5c68f5c
CS
dgrammatiko Nov 2, 2021
bc2914a
CS
dgrammatiko Nov 2, 2021
10ce4d4
Update administrator/components/com_templates/src/Model/TemplateModel…
dgrammatiko Nov 2, 2021
083fee5
Update administrator/components/com_templates/src/Model/TemplateModel…
dgrammatiko Nov 2, 2021
b3c3a56
Update administrator/components/com_templates/src/Model/TemplateModel…
dgrammatiko Nov 2, 2021
3c2b599
Update administrator/components/com_templates/tmpl/template/default_m…
dgrammatiko Nov 2, 2021
d6d1650
Update administrator/components/com_templates/tmpl/template/default_m…
dgrammatiko Nov 2, 2021
d330cf8
Update administrator/components/com_templates/src/Service/HTML/Templa…
dgrammatiko Nov 2, 2021
1e33423
Update administrator/components/com_templates/src/Service/HTML/Templa…
dgrammatiko Nov 2, 2021
ba76d9c
CS
dgrammatiko Nov 2, 2021
0f61e00
beatify the tree (still not a11y compliant)
dgrammatiko Nov 2, 2021
36a2d55
meh
dgrammatiko Nov 2, 2021
071e0a2
prevent default
dgrammatiko Nov 2, 2021
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
311 changes: 311 additions & 0 deletions administrator/components/com_admin/script.php

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--
-- Convert core templates to new mode
--
UPDATE `#__template_styles` SET `inheritable` = 1 WHERE `template` = 'atum' AND `client_id` = 1 OR `template` = 'cassiopeia' AND `client_id` = 0;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--
-- Convert core templates to new mode
--
UPDATE "#__template_styles" SET "inheritable" = 1 WHERE "template" = 'atum' AND "client_id" = 1 OR "template" = 'cassiopeia' AND "client_id" = 0;
Original file line number Diff line number Diff line change
@@ -980,4 +980,106 @@ public function ajax()

$app->close();
}

/**
* Method for copying the template.
*
* @return boolean true on success, false otherwise
*
* @since __DEPLOY_VERSION__
*/
public function child()
{
// Check for request forgeries
$this->checkToken();

$app = $this->app;
$this->input->set('installtype', 'folder');
$newNameRaw = $this->input->get('new_name', null, 'string');
// Only accept letters, numbers and underscore for template name
$newName = preg_replace('/[^a-zA-Z0-9_]/', '', $newNameRaw);
$templateID = (int) $this->input->getInt('id', 0);
$file = (string) $this->input->get('file', '', 'cmd');

// Access check.
if (!$this->allowEdit()) {
$app->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'), 'error');

return false;
}

$this->setRedirect('index.php?option=com_templates&view=template&id=' . $templateID . '&file=' . $file);

/* @var \Joomla\Component\Templates\Administrator\Model\TemplateModel $model */
$model = $this->getModel('Template', 'Administrator');
$model->setState('new_name', $newName);
$model->setState('tmp_prefix', uniqid('template_child_'));
$model->setState('to_path', $app->get('tmp_path') . '/' . $model->getState('tmp_prefix'));

// Process only if we have a new name entered
if (strlen($newName) > 0) {
if (!$this->app->getIdentity()->authorise('core.create', 'com_templates')) {
// User is not authorised to delete
$this->setMessage(Text::_('COM_TEMPLATES_ERROR_CREATE_NOT_PERMITTED'), 'error');

return false;
}

// Check that new name is valid
if (($newNameRaw !== null) && ($newName !== $newNameRaw)) {
$this->setMessage(Text::_('COM_TEMPLATES_ERROR_INVALID_TEMPLATE_NAME'), 'error');

return false;
}

// Check that new name doesn't already exist
if (!$model->checkNewName()) {
$this->setMessage(Text::_('COM_TEMPLATES_ERROR_DUPLICATE_TEMPLATE_NAME'), 'error');

return false;
}

// Check that from name does exist and get the folder name
$fromName = $model->getFromName();

if (!$fromName) {
$this->setMessage(Text::_('COM_TEMPLATES_ERROR_INVALID_FROM_NAME'), 'error');

return false;
}

// Call model's child method
if (!$model->child()) {
$this->setMessage(Text::_('COM_TEMPLATES_ERROR_COULD_NOT_COPY'), 'error');

return false;
}

// Call installation model
$this->input->set('install_directory', $app->get('tmp_path') . '/' . $model->getState('tmp_prefix'));

/** @var \Joomla\Component\Installer\Administrator\Model\InstallModel $installModel */
$installModel = $this->app->bootComponent('com_installer')
->getMVCFactory()->createModel('Install', 'Administrator');
$this->app->getLanguage()->load('com_installer');

if (!$installModel->install()) {
$this->setMessage(Text::_('COM_TEMPLATES_ERROR_COULD_NOT_INSTALL'), 'error');

return false;
}

// @todo get the correct ID of the child template
$url = 'index.php?option=com_templates&view=template&id=' . $templateID;

$this->setMessage(Text::sprintf('COM_TEMPLATES_CHILD_SUCCESS', $newName, Route::_($url)));
$model->cleanup();

return true;
}

$this->setMessage(Text::sprintf('COM_TEMPLATES_ERROR_INVALID_TEMPLATE_NAME'), 'error');

return false;
}
}
Original file line number Diff line number Diff line change
@@ -419,6 +419,8 @@ protected function preprocessForm(Form $form, $data, $group = 'content')

// Load the core and/or local language file(s).
$lang->load('tpl_' . $template, $client->path)
|| $lang->load('tpl_' . $data->parent, $client->path)
|| $lang->load('tpl_' . $data->parent, $client->path . '/templates/' . $data->parent)
|| $lang->load('tpl_' . $template, $client->path . '/templates/' . $template);

if (file_exists($formFile))
Loading