Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Fix HTMLHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
Septdir committed Dec 9, 2022
1 parent c8a9c1e commit c8d1922
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 116 deletions.
147 changes: 32 additions & 115 deletions classes/HTMLHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,131 +32,48 @@ abstract class HTMLHelper extends HTMLHelperCore
*
* @since 1.6.0
*/
protected static function includeRelativeFiles($folder, $file, $relative, $detect_browser, $detect_debug)
protected static function includeRelativeFiles($folder, $file, $relative, $detectBrowser, $detectDebug)
{
// Get defaults include paths
$default = parent::includeRelativeFiles($folder, $file, $relative, $detect_browser, $detect_debug);

// If don't child return default
if (!defined('YOOTHEME_CHILD')) return $default;

// If http is present return default path
if (strpos($file, 'http') === 0 || strpos($file, '//') === 0) return $default;

// If don't relative return default path
if (!$relative) return $default;

// Prepare array of files
$includes = array();

// Extract extension and strip the file
$strip = File::stripExt($file);
$ext = File::getExt($file);

// Detect browser and compute potential files
if ($detect_browser)
if (!defined('YOOTHEME_CHILD'))
{
$navigator = Browser::getInstance();
$browser = $navigator->getBrowser();
$major = $navigator->getMajor();
$minor = $navigator->getMinor();

// Try to include files named filename.ext, filename_browser.ext, filename_browser_major.ext, filename_browser_major_minor.ext
// where major and minor are the browser version names
$potential = array(
$strip,
$strip . '_' . $browser,
$strip . '_' . $browser . '_' . $major,
$strip . '_' . $browser . '_' . $major . '_' . $minor,
);
}
else
{
$potential = array($strip);
return parent::includeRelativeFiles($folder, $file, $relative, $detectBrowser, $detectDebug);
}

// Get the template
$template = 'yootheme_' . YOOTHEME_CHILD;

// For each potential files
foreach ($potential as $strip)
{
$files = array();

// Detect debug mode
if ($detect_debug && Factory::getConfig()->get('debug'))
{
/*
* Detect if we received a file in the format name.min.ext
* If so, strip the .min part out, otherwise append -uncompressed
*/
if (strlen($strip) > 4 && preg_match('#\.min$#', $strip))
{
$files[] = preg_replace('#\.min$#', '.', $strip) . $ext;
}
else
{
$files[] = $strip . '-uncompressed.' . $ext;
}
}
$app = Factory::getApplication();
$template = $app->getTemplate(true);
$source = clone $template;

$files[] = $strip . '.' . $ext;
$template->template = 'yootheme_' . YOOTHEME_CHILD;
$template->parent = 'yootheme';
$app->set('template', $template);

/*
* Loop on 1 or 2 files and break on first found.
* Add the content of the MD5SUM file located in the same folder to URL to ensure cache browser refresh
* This MD5SUM file must represent the signature of the folder content
*/
foreach ($files as $file)
{
// If the file is in the template folder
$path = JPATH_THEMES . "/$template/$folder/$file";
if (file_exists($path))
{
$includes[] = Uri::base(true) . "/templates/$template/$folder/$file" . static::getMd5Version($path);
$result = parent::includeRelativeFiles($folder, $file, $relative, $detectBrowser, $detectDebug);

break;
}
else
{
// If the file contains any /: it can be in a media extension subfolder
if (strpos($file, '/'))
{
// Divide the file extracting the extension as the first part before /
list($extension, $file) = explode('/', $file, 2);
$app->set('template', $source);

// If the file yet contains any /: it can be a plugin
if (strpos($file, '/'))
{
// Divide the file extracting the element as the first part before /
list($element, $file) = explode('/', $file, 2);

// Try to deal with system files in the template folder
$path = JPATH_THEMES . "/$template/$folder/system/$element/$file";
if (file_exists($path))
{
$includes[] = Uri::root(true) . "/templates/$template/$folder/system/$element/$file" . static::getMd5Version($path);

break;
}
}
else
{
// Try to deal with system files in the template folder
$path = JPATH_THEMES . "/$template/$folder/system/$file";

if (file_exists($path))
{
$includes[] = Uri::root(true) . "/templates/$template/$folder/system/$file" . static::getMd5Version($path);
return $result;
}

break;
}
}
}
}
}
/**
* 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
* @param string $ext The extension of the file
* @param boolean $debugMode Signifies if debug is enabled
*
* @return string The relative path of the file
*
* @since __DEPLOY_VERSION__
*/
protected static function addFileToBuffer($path = '', $ext = '', $debugMode = false)
{
$result = parent::addFileToBuffer($path, $ext, $debugMode);
if (empty($result) && strpos($path, 'media/templates/site/yootheme') !== false)
{
$path = str_replace('media/templates/site/', 'templates/', $path);
$result = parent::addFileToBuffer($path, $ext, $debugMode);
}

return (!empty($includes)) ? $includes : $default;
return $result;
}
}
2 changes: 1 addition & 1 deletion script.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PlgSystemJYProExtraInstallerScript
*
* @since 1.0.0
*/
protected $minimumJoomla = '3.9.0';
protected $minimumJoomla = '4.2';

/**
* YOOtheme external files.
Expand Down

0 comments on commit c8d1922

Please sign in to comment.