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

Child Templates html directory #38986

Merged
merged 3 commits into from
Dec 29, 2022
Merged

Child Templates html directory #38986

merged 3 commits into from
Dec 29, 2022

Conversation

brianteeman
Copy link
Contributor

@brianteeman brianteeman commented Oct 17, 2022

Summary of Changes

when creating a child template it is incorrectly creating the html directory as a subdirectory of media - it should be /templates/childname/html - you can verify that by creating a template override and observing where the files are created.

the templateDetails.xml is also incorrect for the same reason

Testing Instructions

Create a child template.

Actual result BEFORE applying this Pull Request

You will see the child template has no template subdirectories and has a media/html subdirectoy
Check the templateDetails.xml and you will see

		<filename>templateDetails.xml</filename>
		<folder>html</folder>
	</files>
	<media destination="templates/site/cassiopeia" folder="media">
		<folder>js</folder>
		<folder>css</folder>
		<folder>scss</folder>
		<folder>images</folder>
	</media>

image

Expected result AFTER applying this Pull Request

You will see the child template has a template/html subdirectory and no media/html subdirectoy
Check the templateDetails.xml and you will see


  <files>
    <filename>templateDetails.xml</filename>
    <folder>html</folder>
  </files>
  <media folder="media" destination="templates/site/cassiopeia_after_pr">
    <folder>css</folder>
    <folder>js</folder>
    <folder>images</folder>
    <folder>scss</folder>
  </media>

![image](https://user-images.githubusercontent.com/1296369/196300773-4496ca7f-f5bc-4520-ab88-310941a2b310.png)

Link to documentations

Please select:

  • Documentation link for docs.joomla.org:

  • No documentation changes for docs.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

when creating a child template it is incorrectly creating the html directory as a subdirectory of media - it should be /templates/childname/html
@dgrammatiko
Copy link
Contributor

it should be /templates/childname/html

Nope, you're wrong. As the contents of this folder SHOUD be publicly accessible the HTML folder was moved to the media folder, so once someone is hardening their security/access to their site the contents could be fetched from tinyMCE.

@wilsonge
Copy link
Contributor

Nope, you're wrong. As the contents of this folder SHOUD be publicly accessible the HTML folder was moved to the media folder, so once someone is hardening their security/access to their site the contents could be fetched from tinyMCE.

The HTML folder is where the content overrides belong - they are still present in the standard installs as they are PHP Files https://github.com/joomla/joomla-cms/tree/4.2-dev/templates/cassiopeia/html

TinyMCE HTML as html files might need to be some sort of special case admittedly - but either way the majority of the files do belong in the templates dir and they indeed do not belong in the media subtree in the xml file.

@dgrammatiko
Copy link
Contributor

dgrammatiko commented Oct 18, 2022

The HTML folder is where the content overrides belong

True and that exposes the real problem: the implementation of this feature is subpar. Let me explain:

Eg:

tinymce.xml
<?xml version="1.0" encoding="utf-8"?>
<extension type="plugin" group="editors" method="upgrade">
	<name>plg_editors_tinymce</name>
	<version>5.10.3</version>
	<creationDate>2005-08</creationDate>
	<author>Tiny Technologies, Inc</author>
	<authorEmail>N/A</authorEmail>
	<authorUrl>https://www.tiny.cloud</authorUrl>
	<copyright>Tiny Technologies, Inc</copyright>
	<license>LGPL</license>
	<description>PLG_TINY_XML_DESCRIPTION</description>
	<namespace path="src">Joomla\Plugin\Editors\TinyMCE</namespace>
	<files>
		<folder plugin="tinymce">forms</folder>
		<folder>src</folder>
		<folder>services</folder>
	</files>
	<media destination="editors" folder="media">
		<folder>tinymce</folder>
	</media>
	<languages>
		<language tag="en-GB">language/en-GB/plg_editors_tinymce.ini</language>
		<language tag="en-GB">language/en-GB/plg_editors_tinymce.sys.ini</language>
	</languages>
	<config>
		<fields name="params">
			<fieldset name="basic" addfieldprefix="Joomla\Plugin\Editors\TinyMCE\Field">
				<field
					name="configuration"
					type="tinymcebuilder"
					label="PLG_TINY_BUILDER"
					hiddenLabel="true"
				/>
			</fieldset>

			<fieldset name="advanced" label="PLG_TINY_FIELD_LABEL_ADVANCEDPARAMS">
				<field
					name="sets_amount"
					type="number"
					label="PLG_TINY_FIELD_NUMBER_OF_SETS_LABEL"
					filter="int"
					validate="number"
					min="3"
					default="3"
				/>

				<field
					name="html_height"
					type="text"
					label="PLG_TINY_FIELD_HTMLHEIGHT_LABEL"
					default="550px"
				/>

				<field
					name="html_width"
					type="text"
					label="PLG_TINY_FIELD_HTMLWIDTH_LABEL"
					default=""
				/>
			</fieldset>
		</fields>
	</config>
</extension>
tinymce.php
<?php

/**
 * @package     Joomla.Plugin
 * @subpackage  Editors.tinymce
 *
 * @copyright   (C) 2006 Open Source Matters, Inc. <https://www.joomla.org>
 * @license     GNU General Public License version 2 or later; see LICENSE.txt

 * @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
 */

use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Session\Session;
use Joomla\Plugin\Editors\TinyMCE\PluginTraits\DisplayTrait;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * TinyMCE Editor Plugin
 *
 * @since  1.5
 */
class PlgEditorTinymce extends CMSPlugin
{
    use DisplayTrait;

    /**
     * Base path for editor files
     *
     * @since  3.5
     *
     * @deprecated 5.0
     */
    protected $_basePath = 'media/vendor/tinymce';

    /**
     * Load the language file on instantiation.
     *
     * @var    boolean
     * @since  3.1
     */
    protected $autoloadLanguage = true;

    /**
     * Loads the application object
     *
     * @var    \Joomla\CMS\Application\CMSApplication
     * @since  3.2
     */
    protected $app = null;

    /**
     * Initialises the Editor.
     *
     * @return  void
     *
     * @since   1.5
     */
    public function onInit()
    {
    }
}

class PlgEditorsTinymce extends PlgEditorTinymce
{
    /**
     * Helper function to get the active Site template style.
     *
     * @return  object
     *
     * @since   4.3.0
     */
    public function onAjaxTinymce()
    {
        // @todo collect the templates properly
        // Template
        // $templates = [];

        // if (!empty($allButtons['template'])) {
        //     // Do we have a custom content_template_path
        //     $template_path = $levelParams->get('content_template_path');
        //     $template_path = $template_path ? '/templates/' . $template_path : '/media/vendor/tinymce/templates';

        //     $filepaths = Folder::exists(JPATH_ROOT . $template_path)
        //         ? Folder::files(JPATH_ROOT . $template_path, '\.(html|txt)$', false, true)
        //         : [];

        //     foreach ($filepaths as $filepath) {
        //         $fileinfo      = pathinfo($filepath);
        //         $filename      = $fileinfo['filename'];
        //         $full_filename = $fileinfo['basename'];

        //         if ($filename === 'index') {
        //             continue;
        //         }

        //         $title       = $filename;
        //         $title_upper = strtoupper($filename);
        //         $description = ' ';

        //         if ($language->hasKey('PLG_TINY_TEMPLATE_' . $title_upper . '_TITLE')) {
        //             $title = Text::_('PLG_TINY_TEMPLATE_' . $title_upper . '_TITLE');
        //         }

        //         if ($language->hasKey('PLG_TINY_TEMPLATE_' . $title_upper . '_DESC')) {
        //             $description = Text::_('PLG_TINY_TEMPLATE_' . $title_upper . '_DESC');
        //         }

        //         $templates[] = [
        //             'title'       => $title,
        //             'description' => $description,
        //             'url'         => Uri::root(true) . $template_path . '/' . $full_filename,
        //         ];
        //     }
        // }

        header('Content-type:application/json;charset=utf-8');

        @ob_end_clean();

        if (!Session::checkToken('request') || !(Factory::getUser())->authorise('core.edit', 'com_plugins')) {
            throw new \Exception('Not Allowed');
        }

        echo (json_encode([
            [
                'title'       => 'Success',
                'description' => 'A success alert',
                'content'     => '<div class="alert alert-success">My content</div>'
            ]
        ]));

        flush();

        Factory::getApplication()->close();
    }
}

And 'templates' => Uri::base(false) . 'index.php?option=com_ajax&type=plugin&plugin=tinymce&group=editors&format=json&' . Session::getFormToken() . '=1', //$templates, @

@wilsonge what is extremely awkward is that the editors plugin due to this line

$name = 'PlgEditor' . $this->_name;
(should be $name = 'PlgEditors' . $this->_name; Editors not Editor) don't follow the API convention and thus the com_ajax events are not fired. Joomla disagrees with it's own API...

@brianteeman
Copy link
Contributor Author

@dgrammatiko create a template override in a child template and see where the file is created

@dgrammatiko
Copy link
Contributor

dgrammatiko commented Oct 18, 2022

@brianteeman my bad I thought you were fixing #38911 and my comments are totally valid for that issue. If Layout overrides end up in the media folder then it's an obvious bug (will try to test later today)

I can't replicate the issue:

Screen.Recording.2022-10-18.at.11.31.10.mov

Screenshot 2022-10-18 at 11 31 55

@brianteeman
Copy link
Contributor Author

I can't replicate the issue:

Your video shows the problem that this PR resolves

@toivo
Copy link
Contributor

toivo commented Oct 24, 2022

I have tested this item ✅ successfully on 5614ebf

Tested successfully in Joomla 4.2.4-dev of 24 October in Wampserver using PHP 8.1.10


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38986.

@ReLater
Copy link
Contributor

ReLater commented Dec 24, 2022

I have tested this item ✅ successfully on c9ce99f


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38986.

1 similar comment
@viocassel
Copy link
Contributor

I have tested this item ✅ successfully on c9ce99f


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38986.

@Quy
Copy link
Contributor

Quy commented Dec 29, 2022

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/38986.

@joomla-cms-bot joomla-cms-bot added the RTC This Pull Request is Ready To Commit label Dec 29, 2022
@wilsonge wilsonge merged commit d2dddb2 into joomla:4.2-dev Dec 29, 2022
@joomla-cms-bot joomla-cms-bot removed the RTC This Pull Request is Ready To Commit label Dec 29, 2022
@wilsonge
Copy link
Contributor

Thanks!

@wilsonge wilsonge added this to the Joomla! 4.2.7 milestone Dec 29, 2022
@brianteeman
Copy link
Contributor Author

Thanks @wilsonge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants