[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/plugins/editors/tinymce/src/PluginTraits/ -> ResolveFiles.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Plugin
   5   * @subpackage  Editors.tinymce
   6   *
   7   * @copyright   (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Plugin\Editors\TinyMCE\PluginTraits;
  12  
  13  use Joomla\CMS\Filesystem\File;
  14  use Joomla\CMS\Uri\Uri;
  15  
  16  // phpcs:disable PSR1.Files.SideEffects
  17  \defined('_JEXEC') or die;
  18  // phpcs:enable PSR1.Files.SideEffects
  19  
  20  /**
  21   * Handles the editor.css files.
  22   *
  23   * @since  4.1.0
  24   */
  25  trait ResolveFiles
  26  {
  27      use ActiveSiteTemplate;
  28  
  29      /**
  30       * Compute the file paths to be included
  31       *
  32       * @param   string   $folder  Folder name to search in (i.e. images, css, js).
  33       * @param   string   $file    Path to file.
  34       *
  35       * @return  array    files to be included.
  36       *
  37       * @since   4.1.0
  38       */
  39      protected function includeRelativeFiles($folder, $file)
  40      {
  41          $fallback = Uri::root(true) . '/media/system/css/editor' . (JDEBUG ? '' : '.min') . '.css';
  42          $template = $this->getActiveSiteTemplate();
  43  
  44          if (!(array) $template) {
  45              return $fallback;
  46          }
  47  
  48          // Extract extension and strip the file
  49          $file       = File::stripExt($file) . '.' . File::getExt($file);
  50          $templaPath = $template->inheritable || (isset($template->parent) && $template->parent !== '')
  51              ? JPATH_ROOT . '/media/templates/site'
  52              : JPATH_ROOT . '/templates';
  53  
  54          if (isset($template->parent) && $template->parent !== '') {
  55              $found = static::resolveFileUrl("$templaPath/$template->template/$folder/$file");
  56  
  57              if (empty($found)) {
  58                  $found = static::resolveFileUrl("$templaPath/$template->parent/$folder/$file");
  59              }
  60          } else {
  61              $found = static::resolveFileUrl("$templaPath/$template->template/$folder/$file");
  62          }
  63  
  64          if (empty($found)) {
  65              return $fallback;
  66          }
  67  
  68          return $found;
  69      }
  70  
  71      /**
  72       * Method that searches if file exists in given path and returns the relative path.
  73       * If a minified version exists it will be preferred.
  74       *
  75       * @param   string   $path          The actual path of the file
  76       *
  77       * @return  string  The relative path of the file
  78       *
  79       * @since   4.1.0
  80       */
  81      protected static function resolveFileUrl($path = '')
  82      {
  83          $position = strrpos($path, '.min.');
  84  
  85          // We are handling a name.min.ext file:
  86          if ($position !== false) {
  87              $minifiedPath    = $path;
  88              $nonMinifiedPath = substr_replace($path, '', $position, 4);
  89  
  90              if (JDEBUG && is_file($nonMinifiedPath)) {
  91                  return Uri::root(true) . str_replace(JPATH_ROOT, '', $nonMinifiedPath);
  92              }
  93  
  94              if (is_file($minifiedPath)) {
  95                  return Uri::root(true) . str_replace(JPATH_ROOT, '', $minifiedPath);
  96              }
  97  
  98              return '';
  99          }
 100  
 101          $minifiedPath = pathinfo($path, PATHINFO_DIRNAME) . '/' . pathinfo($path, PATHINFO_FILENAME) . '.min.' . pathinfo($path, PATHINFO_EXTENSION);
 102  
 103          if (JDEBUG && is_file($path)) {
 104              return Uri::root(true) . str_replace(JPATH_ROOT, '', $path);
 105          }
 106  
 107          if (is_file($minifiedPath)) {
 108              return Uri::root(true) . str_replace(JPATH_ROOT, '', $minifiedPath);
 109          }
 110  
 111          return '';
 112      }
 113  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer