- md5
- aa8aba12ddc55154fb80e838a71a9f86
- sha1
- b53887d4e0936ffbe885627cfc9849d8a8541e45
- sha256
- 1a57f1c6aa091a0a618bb17927eab2bc6a76a6ee0bdb3d19e3b41ac2fdc6883c
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
<?php
/**
* @package Joomla.Plugin
* @subpackage Editors.tinymce
*
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Plugin\Editors\TinyMCE\PluginTraits;
use Joomla\CMS\Uri\Uri;
use Joomla\Filesystem\File;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Handles the editor.css files.
*
* @since 4.1.0
*/
trait ResolveFiles
{
use ActiveSiteTemplate;
/**
* Compute the file paths to be included
*
* @param string $folder Folder name to search in (i.e. images, css, js).
* @param string $file Path to file.
*
* @return array files to be included.
*
* @since 4.1.0
*/
protected function includeRelativeFiles($folder, $file)
{
$fallback = Uri::root(true) . '/media/system/css/editor' . (JDEBUG ? '' : '.min') . '.css';
$template = $this->getActiveSiteTemplate();
if (!(array) $template) {
return $fallback;
}
// Extract extension and strip the file
$file = File::stripExt($file) . '.' . File::getExt($file);
$templaPath = $template->inheritable || (isset($template->parent) && $template->parent !== '')
? JPATH_ROOT . '/media/templates/site'
: JPATH_ROOT . '/templates';
if (isset($template->parent) && $template->parent !== '') {
$found = static::resolveFileUrl("$templaPath/$template->template/$folder/$file");
if (empty($found)) {
$found = static::resolveFileUrl("$templaPath/$template->parent/$folder/$file");
}
} else {
$found = static::resolveFileUrl("$templaPath/$template->template/$folder/$file");
}
if (empty($found)) {
return $fallback;
}
return $found;
}
/**
* Method that searches if file exists in given path and returns the relative path.
* If a minified version exists it will be preferred.
*
* @param string $path The actual path of the file
*
* @return string The relative path of the file
*
* @since 4.1.0
*/
protected static function resolveFileUrl($path = '')
{
$position = strrpos($path, '.min.');
// We are handling a name.min.ext file:
if ($position !== false) {
$minifiedPath = $path;
$nonMinifiedPath = substr_replace($path, '', $position, 4);
if (JDEBUG && is_file($nonMinifiedPath)) {
return Uri::root(true) . str_replace(JPATH_ROOT, '', $nonMinifiedPath);
}
if (is_file($minifiedPath)) {
return Uri::root(true) . str_replace(JPATH_ROOT, '', $minifiedPath);
}
if (is_file($nonMinifiedPath)) {
return Uri::root(true) . str_replace(JPATH_ROOT, '', $nonMinifiedPath);
}
return '';
}
$minifiedPath = pathinfo($path, PATHINFO_DIRNAME) . '/' . pathinfo($path, PATHINFO_FILENAME) . '.min.' . pathinfo($path, PATHINFO_EXTENSION);
if (JDEBUG && is_file($path)) {
return Uri::root(true) . str_replace(JPATH_ROOT, '', $path);
}
if (is_file($minifiedPath)) {
return Uri::root(true) . str_replace(JPATH_ROOT, '', $minifiedPath);
}
return '';
}
}
The same content is in 78 releases, Joomla 5.2.0-alpha3 to 6.1.0-rc1. See them all, or every version of this file.