primo commit
This commit is contained in:
159
libraries/fof40/Render/FEF.php
Normal file
159
libraries/fof40/Render/FEF.php
Normal file
@ -0,0 +1,159 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FOF
|
||||
* @copyright Copyright (c)2010-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 3, or later
|
||||
*/
|
||||
|
||||
namespace FOF40\Render;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use FOF40\Container\Container;
|
||||
|
||||
/**
|
||||
* Renderer class for use with Akeeba FEF
|
||||
*
|
||||
* Renderer options
|
||||
*
|
||||
* wrapper_id The ID of the wrapper DIV. Default: akeeba-rendered-fef
|
||||
* linkbar_style Style for linkbars: joomla3|classic. Default: joomla3
|
||||
* load_fef Load FEF CSS? Set to false if you are loading it outside the renderer. Default: true
|
||||
* load_fef_js Load FEF JS? Set to false if you are loading it outside the rendered. Default: true
|
||||
* load_fef_js_minimal Load the minimal FEF JS (without features depending on FEF CSS)? Default: inverse of load_fef
|
||||
* fef_reset Should I reset the CSS styling for basic HTML elements inside the FEF container? Default: true
|
||||
* fef_dark Should I load the FEF Dark Mode CSS and supporting JS? Default: 0 (no). Options: 1 (yes and
|
||||
* activate immediately), -1 (include dark.css but not enable by default, also enables auto mode
|
||||
* for Safari)
|
||||
* custom_css Comma-separated list of custom CSS files to load _after_ the main FEF CSS file, e.g.
|
||||
* media://com_foo/css/bar.min.css,media://com_foo/css/baz.min.css
|
||||
* remove_wrapper_classes Comma-separated list of classes to REMOVE from the container
|
||||
* add_wrapper_classes Comma-separated list of classes to ADD to the container
|
||||
*
|
||||
* Note: when Dark Mode is enabled the class akeeba-renderer-fef--dark is applied to the container DIV. You can use
|
||||
* remove_wrapper_classes to remove it e.g. when you want it to be enabled only through a JavaScript-powered toggle.
|
||||
*
|
||||
* @package FOF40\Render
|
||||
*/
|
||||
class FEF extends Joomla
|
||||
{
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
|
||||
$helperFile = JPATH_SITE . '/media/fef/fef.php';
|
||||
|
||||
if (!class_exists('AkeebaFEFHelper') && is_file($helperFile))
|
||||
{
|
||||
include_once $helperFile;
|
||||
}
|
||||
|
||||
$this->priority = 20;
|
||||
$this->enabled = class_exists('AkeebaFEFHelper');
|
||||
}
|
||||
|
||||
public function initialise(string $view, string $task): void
|
||||
{
|
||||
$useReset = $this->getOption('fef_reset', 1);
|
||||
$useFefCss = $this->getOption('load_fef', 1);
|
||||
$useFefJs = $this->getOption('load_fef_js', 1);
|
||||
$minimalJs = $this->getOption('load_fef_js_minimal', $useFefCss ? 0 : 1);
|
||||
$useDarkMode = $this->getOption('fef_dark', 0);
|
||||
|
||||
if (class_exists('AkeebaFEFHelper'))
|
||||
{
|
||||
if ($useFefCss)
|
||||
{
|
||||
\AkeebaFEFHelper::loadCSSFramework((bool) $useReset, (bool) $useDarkMode != 0);
|
||||
}
|
||||
|
||||
if ($useFefJs)
|
||||
{
|
||||
\AkeebaFEFHelper::loadJSFramework((bool) $minimalJs);
|
||||
}
|
||||
}
|
||||
|
||||
// Unlike the Joomla renderer we do NOT load jQuery unless explicitly enabled
|
||||
$loadJQuery = $this->getOption('load_jquery', false);
|
||||
$this->setOption('load_jquery', $loadJQuery ? 1 : 0);
|
||||
|
||||
parent::initialise($view, $task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the FEF styling wrapper element. Our component's output will be inside this wrapper.
|
||||
*
|
||||
* @param array $classes An array of additional CSS classes to add to the outer page wrapper element.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function openPageWrapper(array $classes): void
|
||||
{
|
||||
$useDarkMode = $this->getOption('fef_dark', false);
|
||||
|
||||
if (($useDarkMode == 1) && !in_array('akeeba-renderer-fef--dark', $classes))
|
||||
{
|
||||
$classes[] = 'akeeba-renderer-fef--dark';
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove wrapper classes. By default these are classes for the Joomla 3 sidebar which is not used in FEF
|
||||
* components anymore.
|
||||
*/
|
||||
$removeClasses = $this->getOption('remove_wrapper_classes', [
|
||||
'j-toggle-main',
|
||||
'j-toggle-transition',
|
||||
'row-fluid',
|
||||
]);
|
||||
|
||||
if (!is_array($removeClasses))
|
||||
{
|
||||
$removeClasses = explode(',', $removeClasses);
|
||||
}
|
||||
|
||||
$removeClasses = array_map('trim', $removeClasses);
|
||||
|
||||
foreach ($removeClasses as $class)
|
||||
{
|
||||
$x = array_search($class, $classes);
|
||||
|
||||
if ($x !== false)
|
||||
{
|
||||
unset($classes[$x]);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the following classes to the wrapper div
|
||||
$addClasses = $this->getOption('add_wrapper_classes', '');
|
||||
|
||||
if (!is_array($addClasses))
|
||||
{
|
||||
$addClasses = explode(',', $addClasses);
|
||||
}
|
||||
|
||||
$addClasses = array_map('trim', $addClasses);
|
||||
$customClasses = implode(' ', array_unique(array_merge($classes, $addClasses)));
|
||||
|
||||
$id = $this->getOption('wrapper_id', 'akeeba-renderer-fef');
|
||||
$id = empty($id) ? "" : sprintf(' id="%s"', $id);
|
||||
|
||||
echo <<< HTML
|
||||
<div id="akeeba-renderer-fef" class="akeeba-renderer-fef $customClasses"$id>
|
||||
|
||||
HTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the FEF styling wrapper element.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function closePageWrapper(): void
|
||||
{
|
||||
echo <<< HTML
|
||||
</div>
|
||||
|
||||
HTML;
|
||||
|
||||
}
|
||||
}
|
||||
599
libraries/fof40/Render/Joomla.php
Normal file
599
libraries/fof40/Render/Joomla.php
Normal file
@ -0,0 +1,599 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FOF
|
||||
* @copyright Copyright (c)2010-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 3, or later
|
||||
*/
|
||||
|
||||
namespace FOF40\Render;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use FOF40\Container\Container;
|
||||
use FOF40\Toolbar\Toolbar;
|
||||
use JHtmlSidebar;
|
||||
use Joomla\CMS\Factory as JoomlaFactory;
|
||||
use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Toolbar\Toolbar as JoomlaToolbar;
|
||||
|
||||
/**
|
||||
* Renderer class for use with Joomla! 3.x and 4.x
|
||||
*
|
||||
* Renderer options
|
||||
*
|
||||
* wrapper_id The ID of the wrapper DIV. Default: akeeba-renderjoomla
|
||||
* linkbar_style Style for linkbars: joomla3|classic. Default: joomla3
|
||||
* remove_wrapper_classes Comma-separated list of classes to REMOVE from the container
|
||||
* add_wrapper_classes Comma-separated list of classes to ADD to the container
|
||||
*
|
||||
* @package FOF40\Render
|
||||
* @since 3.6.0
|
||||
*/
|
||||
class Joomla extends RenderBase implements RenderInterface
|
||||
{
|
||||
/** @inheritDoc */
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->priority = 30;
|
||||
$this->enabled = true;
|
||||
|
||||
parent::__construct($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs initialisation.
|
||||
*
|
||||
* This is where we load any CSS and JavaScript frameworks. For this renderer we load the core Joomla JavaScript
|
||||
* and the jQuery framework.
|
||||
*
|
||||
* The following renderer options are recognised:
|
||||
* * load_core. Should I load the Joomla core JavaScript if it's not already loaded?
|
||||
* * load_jquery. Should I load jQuery if it's not already loaded?
|
||||
*
|
||||
* @param string $view The current view
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function initialise(string $view, string $task): void
|
||||
{
|
||||
$input = $this->container->input;
|
||||
$platform = $this->container->platform;
|
||||
|
||||
$format = $input->getCmd('format', 'html');
|
||||
|
||||
if (empty($format))
|
||||
{
|
||||
$format = 'html';
|
||||
}
|
||||
|
||||
if ($format != 'html')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($platform->isCli())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->getOption('load_core', true))
|
||||
{
|
||||
HTMLHelper::_('behavior.core');
|
||||
}
|
||||
|
||||
if ($this->getOption('load_jquery', true))
|
||||
{
|
||||
HTMLHelper::_('jquery.framework', true);
|
||||
}
|
||||
|
||||
parent::initialise($view, $task); // TODO: Change the autogenerated stub
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Echoes any HTML to show before the view template
|
||||
*
|
||||
* @param string $view The current view
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function preRender(string $view, string $task): void
|
||||
{
|
||||
$input = $this->container->input;
|
||||
$platform = $this->container->platform;
|
||||
|
||||
$format = $input->getCmd('format', 'html');
|
||||
|
||||
if (empty($format))
|
||||
{
|
||||
$format = 'html';
|
||||
}
|
||||
|
||||
if ($format != 'html')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ($platform->isCli())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Wrap output in various classes
|
||||
$versionParts = explode('.', JVERSION);
|
||||
$minorVersion = $versionParts[0] . $versionParts[1];
|
||||
$majorVersion = $versionParts[0];
|
||||
|
||||
$classes = [];
|
||||
|
||||
if ($platform->isBackend())
|
||||
{
|
||||
$area = $platform->isBackend() ? 'admin' : 'site';
|
||||
$option = $input->getCmd('option', '');
|
||||
$viewForCssClass = $input->getCmd('view', '');
|
||||
$layout = $input->getCmd('layout', '');
|
||||
$taskForCssClass = $input->getCmd('task', '');
|
||||
|
||||
$classes = [
|
||||
'joomla-version-' . $majorVersion,
|
||||
'joomla-version-' . $minorVersion,
|
||||
$area,
|
||||
$option,
|
||||
'view-' . $view,
|
||||
'view-' . $viewForCssClass,
|
||||
'layout-' . $layout,
|
||||
'task-' . $task,
|
||||
'task-' . $taskForCssClass,
|
||||
// We have a floating sidebar, they said. It looks great, they said. They must've been blind, I say!
|
||||
'j-toggle-main',
|
||||
'j-toggle-transition',
|
||||
'row-fluid',
|
||||
];
|
||||
|
||||
$classes = array_unique($classes);
|
||||
}
|
||||
|
||||
// Render the submenu and toolbar
|
||||
if ($input->getBool('render_toolbar', true))
|
||||
{
|
||||
$this->renderButtons($view, $task);
|
||||
$this->renderLinkbar($view, $task);
|
||||
}
|
||||
|
||||
$this->openPageWrapper($classes);
|
||||
|
||||
parent::preRender($view, $task);
|
||||
}
|
||||
|
||||
/**
|
||||
* Echoes any HTML to show after the view template
|
||||
*
|
||||
* @param string $view The current view
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function postRender(string $view, string $task): void
|
||||
{
|
||||
$input = $this->container->input;
|
||||
$platform = $this->container->platform;
|
||||
|
||||
$format = $input->getCmd('format', 'html');
|
||||
|
||||
if (empty($format))
|
||||
{
|
||||
$format = 'html';
|
||||
}
|
||||
|
||||
if ($format != 'html')
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Closing tag only if we're not in CLI
|
||||
if ($platform->isCli())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Closes akeeba-renderjoomla div
|
||||
$this->closePageWrapper();
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the submenu (link bar)
|
||||
*
|
||||
* @param string $view The active view name
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function renderLinkbar(string $view, string $task): void
|
||||
{
|
||||
$style = $this->getOption('linkbar_style', 'joomla');
|
||||
|
||||
switch ($style)
|
||||
{
|
||||
case 'joomla':
|
||||
$this->renderLinkbar_joomla($view, $task);
|
||||
break;
|
||||
|
||||
case 'classic':
|
||||
default:
|
||||
$this->renderLinkbar_classic($view, $task);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the submenu (link bar) in FOF's classic style, using a Bootstrapped
|
||||
* tab bar.
|
||||
*
|
||||
* @param string $view The active view name
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function renderLinkbar_classic(string $view, string $task): void
|
||||
{
|
||||
$platform = $this->container->platform;
|
||||
|
||||
if ($platform->isCli())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$isJoomla4 = version_compare(JVERSION, '3.99999.99999', 'gt');
|
||||
$isJoomla3 = !$isJoomla4 && version_compare(JVERSION, '3.0.0', 'ge');
|
||||
|
||||
// Do not render a submenu unless we are in the the admin area
|
||||
$toolbar = $this->container->toolbar;
|
||||
$renderFrontendSubmenu = $toolbar->getRenderFrontendSubmenu();
|
||||
|
||||
if (!$platform->isBackend() && !$renderFrontendSubmenu)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$links = $toolbar->getLinks();
|
||||
|
||||
if ($isJoomla4)
|
||||
{
|
||||
try
|
||||
{
|
||||
HTMLHelper::_('bootstrap.tab');
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
// Since RC1 this is no longer available.
|
||||
}
|
||||
HTMLHelper::_('bootstrap.dropdown');
|
||||
}
|
||||
|
||||
if (!empty($links))
|
||||
{
|
||||
echo "<ul class=\"nav nav-tabs\">\n";
|
||||
|
||||
foreach ($links as $link)
|
||||
{
|
||||
$dropdown = false;
|
||||
|
||||
if (array_key_exists('dropdown', $link))
|
||||
{
|
||||
$dropdown = $link['dropdown'];
|
||||
}
|
||||
|
||||
if ($dropdown)
|
||||
{
|
||||
echo "<li";
|
||||
$class = 'nav-item dropdown';
|
||||
|
||||
$subMenuActive = array_reduce($link['items'], function ($carry, $item) {
|
||||
return $carry || $item['active'] ?? false;
|
||||
}, false);
|
||||
|
||||
if ($subMenuActive || $link['active'])
|
||||
{
|
||||
$class .= ' active';
|
||||
}
|
||||
|
||||
echo ' class="' . $class . '">';
|
||||
|
||||
if ($isJoomla3)
|
||||
{
|
||||
echo '<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">';
|
||||
}
|
||||
else
|
||||
{
|
||||
$tabActiveClass = ($subMenuActive || $link['active']) ? 'active' : '';
|
||||
echo '<a class="nav-link dropdown-toggle '.$tabActiveClass.'" data-bs-toggle="dropdown" href="#">';
|
||||
}
|
||||
|
||||
if ($link['icon'])
|
||||
{
|
||||
echo "<span class=\"icon icon-" . $link['icon'] . "\"></span>";
|
||||
}
|
||||
|
||||
echo $link['name'];
|
||||
echo '<b class="caret"></b>';
|
||||
echo '</a>';
|
||||
|
||||
echo "\n<ul class=\"dropdown-menu\">";
|
||||
|
||||
foreach ($link['items'] as $item)
|
||||
{
|
||||
if ($isJoomla3)
|
||||
{
|
||||
echo "<li class=\"dropdown-item";
|
||||
|
||||
if ($item['active'])
|
||||
{
|
||||
echo ' active';
|
||||
}
|
||||
|
||||
echo "\">";
|
||||
|
||||
if ($item['icon'])
|
||||
{
|
||||
echo "<span class=\"icon icon-" . $item['icon'] . "\"></span>";
|
||||
}
|
||||
|
||||
if ($item['link'])
|
||||
{
|
||||
echo "<a href=\"" . $item['link'] . "\">" . $item['name'] . "</a>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $item['name'];
|
||||
}
|
||||
|
||||
echo "</li>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<li>";
|
||||
$tag = $item['link'] ? 'a' : 'span';
|
||||
$activeItem = ($item['active'] ?? false) ? 'active' : '';
|
||||
|
||||
echo "<$tag class=\"dropdown-item $activeItem\"";
|
||||
|
||||
if ($item['link'])
|
||||
{
|
||||
echo "href=\"{$item['link']}\"";
|
||||
}
|
||||
|
||||
echo ">";
|
||||
|
||||
if ($item['icon'])
|
||||
{
|
||||
echo "<span class=\"icon icon-" . $item['icon'] . "\"></span>";
|
||||
}
|
||||
|
||||
echo $item['name'];
|
||||
|
||||
echo "</$tag>";
|
||||
|
||||
echo "</li>";
|
||||
}
|
||||
}
|
||||
|
||||
echo "</ul>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo "<li class=\"nav-item";
|
||||
|
||||
if ($link['active'])
|
||||
{
|
||||
echo ' active"';
|
||||
}
|
||||
|
||||
echo "\">";
|
||||
|
||||
if ($link['icon'])
|
||||
{
|
||||
echo "<span class=\"icon icon-" . $link['icon'] . "\"></span>";
|
||||
}
|
||||
|
||||
if ($isJoomla3)
|
||||
{
|
||||
if ($link['link'])
|
||||
{
|
||||
echo "<a href=\"" . $link['link'] . "\">" . $link['name'] . "</a>";
|
||||
}
|
||||
else
|
||||
{
|
||||
echo $link['name'];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$class = $link['active'] ? 'active' : '';
|
||||
|
||||
$href = $link['link'] ?: '#';
|
||||
|
||||
echo "<a href=\"$href\" class=\"nav-link $class\">{$link['name']}</a>";
|
||||
}
|
||||
}
|
||||
|
||||
echo "</li>\n";
|
||||
}
|
||||
|
||||
echo "</ul>\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the submenu (link bar) using Joomla!'s style. On Joomla! 2.5 this
|
||||
* is a list of bar separated links, on Joomla! 3 it's a sidebar at the
|
||||
* left-hand side of the page.
|
||||
*
|
||||
* @param string $view The active view name
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function renderLinkbar_joomla(string $view, string $task): void
|
||||
{
|
||||
$platform = $this->container->platform;
|
||||
|
||||
// On command line don't do anything
|
||||
if ($platform->isCli())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not render a submenu unless we are in the the admin area
|
||||
$toolbar = $this->container->toolbar;
|
||||
$renderFrontendSubmenu = $toolbar->getRenderFrontendSubmenu();
|
||||
|
||||
if (!$platform->isBackend() && !$renderFrontendSubmenu)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->renderLinkbarItems($toolbar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the linkbar
|
||||
*
|
||||
* @param Toolbar $toolbar An FOF toolbar object
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function renderLinkbarItems(Toolbar $toolbar): void
|
||||
{
|
||||
$links = $toolbar->getLinks();
|
||||
|
||||
if (!empty($links))
|
||||
{
|
||||
foreach ($links as $link)
|
||||
{
|
||||
JHtmlSidebar::addEntry($link['name'], $link['link'], $link['active']);
|
||||
|
||||
$dropdown = false;
|
||||
|
||||
if (array_key_exists('dropdown', $link))
|
||||
{
|
||||
$dropdown = $link['dropdown'];
|
||||
}
|
||||
|
||||
if ($dropdown)
|
||||
{
|
||||
foreach ($link['items'] as $item)
|
||||
{
|
||||
JHtmlSidebar::addEntry('– ' . $item['name'], $item['link'], $item['active']);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the toolbar buttons
|
||||
*
|
||||
* @param string $view The active view name
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function renderButtons(string $view, string $task): void
|
||||
{
|
||||
$platform = $this->container->platform;
|
||||
|
||||
if ($platform->isCli())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Do not render buttons unless we are in the the frontend area and we are asked to do so
|
||||
$toolbar = $this->container->toolbar;
|
||||
$renderFrontendButtons = $toolbar->getRenderFrontendButtons();
|
||||
|
||||
// Load main backend language, in order to display toolbar strings
|
||||
// (JTOOLBAR_BACK, JTOOLBAR_PUBLISH etc etc)
|
||||
$platform->loadTranslations('joomla');
|
||||
|
||||
if ($platform->isBackend() || !$renderFrontendButtons)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$bar = JoomlaToolbar::getInstance('toolbar');
|
||||
$items = $bar->getItems();
|
||||
|
||||
$substitutions = [
|
||||
'icon-32-new' => 'icon-plus',
|
||||
'icon-32-publish' => 'icon-eye-open',
|
||||
'icon-32-unpublish' => 'icon-eye-close',
|
||||
'icon-32-delete' => 'icon-trash',
|
||||
'icon-32-edit' => 'icon-edit',
|
||||
'icon-32-copy' => 'icon-th-large',
|
||||
'icon-32-cancel' => 'icon-remove',
|
||||
'icon-32-back' => 'icon-circle-arrow-left',
|
||||
'icon-32-apply' => 'icon-ok',
|
||||
'icon-32-save' => 'icon-hdd',
|
||||
'icon-32-save-new' => 'icon-repeat',
|
||||
];
|
||||
|
||||
if (isset(JoomlaFactory::getApplication()->JComponentTitle))
|
||||
{
|
||||
$title = JoomlaFactory::getApplication()->JComponentTitle;
|
||||
}
|
||||
else
|
||||
{
|
||||
$title = '';
|
||||
}
|
||||
|
||||
$html = [];
|
||||
$actions = [];
|
||||
|
||||
// We have to use the same id we're using inside other renderers
|
||||
$html[] = '<div class="well" id="FOFHeaderContainer">';
|
||||
$html[] = '<div class="titleContainer">' . $title . '</div>';
|
||||
$html[] = '<div class="buttonsContainer">';
|
||||
|
||||
foreach ($items as $node)
|
||||
{
|
||||
$type = $node[0];
|
||||
$button = $bar->loadButtonType($type);
|
||||
|
||||
if ($button !== false)
|
||||
{
|
||||
$action = call_user_func_array([&$button, 'fetchButton'], $node);
|
||||
$action = str_replace('class="toolbar"', 'class="toolbar btn"', $action);
|
||||
$action = str_replace('<span ', '<i ', $action);
|
||||
$action = str_replace('</span>', '</i>', $action);
|
||||
$action = str_replace(array_keys($substitutions), array_values($substitutions), $action);
|
||||
$actions[] = $action;
|
||||
}
|
||||
}
|
||||
|
||||
$html = array_merge($html, $actions);
|
||||
$html[] = '</div>';
|
||||
$html[] = '</div>';
|
||||
|
||||
echo implode("\n", $html);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the wrapper DIV element. Our component's output will be inside this wrapper.
|
||||
*
|
||||
* @param array $classes An array of additional CSS classes to add to the outer page wrapper element.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function openPageWrapper(array $classes): void
|
||||
{
|
||||
$this->setOption('wrapper_id', $this->getOption('wrapper_id', 'akeeba-renderjoomla'));
|
||||
|
||||
$classes[] = 'akeeba-renderer-joomla';
|
||||
|
||||
parent::openPageWrapper($classes);
|
||||
}
|
||||
|
||||
}
|
||||
50
libraries/fof40/Render/Joomla3.php
Normal file
50
libraries/fof40/Render/Joomla3.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FOF
|
||||
* @copyright Copyright (c)2010-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 3, or later
|
||||
*/
|
||||
|
||||
namespace FOF40\Render;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use FOF40\Container\Container;
|
||||
|
||||
/**
|
||||
* Renderer class for use with Joomla! 3.x
|
||||
*
|
||||
* Renderer options
|
||||
*
|
||||
* wrapper_id The ID of the wrapper DIV. Default: akeeba-renderjoomla
|
||||
* linkbar_style Style for linkbars: joomla3|classic. Default: joomla3
|
||||
* remove_wrapper_classes Comma-separated list of classes to REMOVE from the container
|
||||
* add_wrapper_classes Comma-separated list of classes to ADD to the container
|
||||
*
|
||||
* @package FOF40\Render
|
||||
*/
|
||||
class Joomla3 extends Joomla
|
||||
{
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->priority = 55;
|
||||
$this->enabled = version_compare(JVERSION, '3.9.999', 'le');
|
||||
|
||||
parent::__construct($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the FEF styling wrapper element. Our component's output will be inside this wrapper.
|
||||
*
|
||||
* @param array $classes An array of additional CSS classes to add to the outer page wrapper element.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function openPageWrapper(array $classes): void
|
||||
{
|
||||
$classes[] = 'akeeba-renderer-joomla3';
|
||||
|
||||
parent::openPageWrapper($classes);
|
||||
}
|
||||
|
||||
}
|
||||
50
libraries/fof40/Render/Joomla4.php
Normal file
50
libraries/fof40/Render/Joomla4.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FOF
|
||||
* @copyright Copyright (c)2010-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 3, or later
|
||||
*/
|
||||
|
||||
namespace FOF40\Render;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use FOF40\Container\Container;
|
||||
|
||||
/**
|
||||
* Renderer class for use with Joomla! 4.x
|
||||
*
|
||||
* Renderer options
|
||||
*
|
||||
* wrapper_id The ID of the wrapper DIV. Default: akeeba-renderjoomla
|
||||
* linkbar_style Style for linkbars: joomla3|classic. Default: joomla3
|
||||
* remove_wrapper_classes Comma-separated list of classes to REMOVE from the container
|
||||
* add_wrapper_classes Comma-separated list of classes to ADD to the container
|
||||
*
|
||||
* @package FOF40\Render
|
||||
*/
|
||||
class Joomla4 extends Joomla
|
||||
{
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->priority = 40;
|
||||
$this->enabled = version_compare(JVERSION, '3.9.999', 'gt');
|
||||
|
||||
parent::__construct($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the FEF styling wrapper element. Our component's output will be inside this wrapper.
|
||||
*
|
||||
* @param array $classes An array of additional CSS classes to add to the outer page wrapper element.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function openPageWrapper(array $classes): void
|
||||
{
|
||||
$classes[] = 'akeeba-renderer-joomla4';
|
||||
|
||||
parent::openPageWrapper($classes);
|
||||
}
|
||||
|
||||
}
|
||||
250
libraries/fof40/Render/RenderBase.php
Normal file
250
libraries/fof40/Render/RenderBase.php
Normal file
@ -0,0 +1,250 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FOF
|
||||
* @copyright Copyright (c)2010-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 3, or later
|
||||
*/
|
||||
|
||||
namespace FOF40\Render;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use FOF40\Container\Container;
|
||||
use Joomla\Registry\Registry;
|
||||
use LogicException;
|
||||
use stdClass;
|
||||
|
||||
/**
|
||||
* Base class for other render classes
|
||||
*
|
||||
* @package FOF40\Render
|
||||
* @since 3.0.0
|
||||
*/
|
||||
abstract class RenderBase implements RenderInterface
|
||||
{
|
||||
/** @var Container|null The container we are attached to */
|
||||
protected $container;
|
||||
|
||||
/** @var bool Is this renderer available under this execution environment? */
|
||||
protected $enabled = false;
|
||||
|
||||
/** @var int The priority of this renderer in case we have multiple available ones */
|
||||
protected $priority = 0;
|
||||
|
||||
/** @var Registry A registry object holding renderer options */
|
||||
protected $optionsRegistry;
|
||||
|
||||
/**
|
||||
* Public constructor. Determines the priority of this class and if it should be enabled
|
||||
*/
|
||||
public function __construct(Container $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
|
||||
$this->optionsRegistry = new Registry();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a renderer option (depends on the renderer)
|
||||
*
|
||||
* @param string $key The name of the option to set
|
||||
* @param mixed $value The value of the option
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setOption(string $key, string $value): void
|
||||
{
|
||||
$this->optionsRegistry->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set multiple renderer options at once (depends on the renderer)
|
||||
*
|
||||
* @param array $options The options to set as key => value pairs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setOptions(array $options): void
|
||||
{
|
||||
foreach ($options as $key => $value)
|
||||
{
|
||||
$this->setOption($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a renderer option
|
||||
*
|
||||
* @param string $key The name of the parameter
|
||||
* @param mixed $default The default value to return if the parameter is not set
|
||||
*
|
||||
* @return mixed The parameter value
|
||||
*/
|
||||
public function getOption(string $key, $default = null)
|
||||
{
|
||||
return $this->optionsRegistry->get($key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the information about this renderer
|
||||
*
|
||||
* @return stdClass
|
||||
*/
|
||||
public function getInformation(): stdClass
|
||||
{
|
||||
$classParts = explode('\\', get_class($this));
|
||||
|
||||
return (object) [
|
||||
'enabled' => $this->enabled,
|
||||
'priority' => $this->priority,
|
||||
'name' => strtolower(array_pop($classParts)),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs initialisation.
|
||||
*
|
||||
* This is where you load your CSS and JavaScript frameworks. Only load the common code that the view's static
|
||||
* assets will definitely depend on.
|
||||
*
|
||||
* This runs at the top of the View's display() method, before ony onBefore* handlers. Any files inserted to the
|
||||
* Joomla document / WebAssetManager by this method CAN plausibly be removed by code in the view or any view event
|
||||
* handlers in plugins.
|
||||
*
|
||||
* @param string $view The current view
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function initialise(string $view, string $task): void
|
||||
{
|
||||
$this->loadCustomCss();
|
||||
}
|
||||
|
||||
/**
|
||||
* Echoes any HTML to show before the view template
|
||||
*
|
||||
* @param string $view The current view
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function preRender(string $view, string $task): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Echoes any HTML to show after the view template
|
||||
*
|
||||
* @param string $view The current view
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function postRender(string $view, string $task): void
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the submenu (link bar) for a category view when it is used in a
|
||||
* extension
|
||||
*
|
||||
* Note: this function has to be called from the addSubmenu function in
|
||||
* the ExtensionNameHelper class located in
|
||||
* administrator/components/com_ExtensionName/helpers/Extensionname.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function renderCategoryLinkbar(): void
|
||||
{
|
||||
throw new LogicException(sprintf('Renderer class %s must implement the %s method', get_class($this), __METHOD__));
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a wrapper DIV. Our component's output will be inside this wrapper.
|
||||
*
|
||||
* @param array $classes An array of additional CSS classes to add to the outer page wrapper element.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function openPageWrapper(array $classes): void
|
||||
{
|
||||
$removeClasses = $this->getOption('remove_wrapper_classes', []);
|
||||
|
||||
if (!is_array($removeClasses))
|
||||
{
|
||||
$removeClasses = explode(',', $removeClasses);
|
||||
}
|
||||
|
||||
$removeClasses = array_map('trim', $removeClasses);
|
||||
|
||||
foreach ($removeClasses as $class)
|
||||
{
|
||||
$x = array_search($class, $classes);
|
||||
|
||||
if ($x !== false)
|
||||
{
|
||||
unset($classes[$x]);
|
||||
}
|
||||
}
|
||||
|
||||
// Add the following classes to the wrapper div
|
||||
$addClasses = $this->getOption('add_wrapper_classes', '');
|
||||
|
||||
if (!is_array($addClasses))
|
||||
{
|
||||
$addClasses = explode(',', $addClasses);
|
||||
}
|
||||
|
||||
$addClasses = array_map('trim', $addClasses);
|
||||
$customClasses = implode(' ', array_unique(array_merge($classes, $addClasses)));
|
||||
|
||||
$id = $this->getOption('wrapper_id', null);
|
||||
$id = empty($id) ? "" : sprintf(' id="%s"', $id);
|
||||
|
||||
echo <<< HTML
|
||||
<div class="$customClasses"$id>
|
||||
|
||||
HTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs HTML which closes the page wrappers opened with openPageWrapper.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function closePageWrapper(): void
|
||||
{
|
||||
echo "</div>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the custom CSS files defined in the custom_css renderer option.
|
||||
*/
|
||||
protected function loadCustomCss()
|
||||
{
|
||||
$custom_css_raw = $this->getOption('custom_css', '');
|
||||
$custom_css_raw = trim($custom_css_raw);
|
||||
|
||||
if (empty($custom_css_raw))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$files = explode(',', $custom_css_raw);
|
||||
$mediaVersion = $this->container->mediaVersion;
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$file = trim($file);
|
||||
|
||||
if (empty($file))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->container->template->addCSS($file, $mediaVersion);
|
||||
}
|
||||
}
|
||||
}
|
||||
109
libraries/fof40/Render/RenderInterface.php
Normal file
109
libraries/fof40/Render/RenderInterface.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* @package FOF
|
||||
* @copyright Copyright (c)2010-2022 Nicholas K. Dionysopoulos / Akeeba Ltd
|
||||
* @license GNU General Public License version 3, or later
|
||||
*/
|
||||
|
||||
namespace FOF40\Render;
|
||||
|
||||
defined('_JEXEC') || die;
|
||||
|
||||
use FOF40\Container\Container;
|
||||
use stdClass;
|
||||
|
||||
interface RenderInterface
|
||||
{
|
||||
/**
|
||||
* Public constructor
|
||||
*
|
||||
* @param Container $container The container we are attached to
|
||||
*/
|
||||
function __construct(Container $container);
|
||||
|
||||
/**
|
||||
* Returns the information about this renderer
|
||||
*
|
||||
* @return object
|
||||
*/
|
||||
function getInformation(): stdClass;
|
||||
|
||||
/**
|
||||
* Performs initialisation.
|
||||
*
|
||||
* This is where you load your CSS and JavaScript frameworks. Only load the common code that the view's static
|
||||
* assets will definitely depend on.
|
||||
*
|
||||
* This runs at the top of the View's display() method, before ony onBefore* handlers. Any files inserted to the
|
||||
* Joomla document / WebAssetManager by this method CAN plausibly be removed by code in the view or any view event
|
||||
* handlers in plugins.
|
||||
*
|
||||
* @param string $view The current view
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
* @since 4.0.0
|
||||
*/
|
||||
function initialise(string $view, string $task): void;
|
||||
|
||||
/**
|
||||
* Echoes any HTML to show before the view template
|
||||
*
|
||||
* @param string $view The current view
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function preRender(string $view, string $task): void;
|
||||
|
||||
/**
|
||||
* Echoes any HTML to show after the view template
|
||||
*
|
||||
* @param string $view The current view
|
||||
* @param string $task The current task
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function postRender(string $view, string $task): void;
|
||||
|
||||
/**
|
||||
* Renders the submenu (link bar) for a category view when it is used in a
|
||||
* extension
|
||||
*
|
||||
* Note: this function has to be called from the addSubmenu function in
|
||||
* the ExtensionNameHelper class located in
|
||||
* administrator/components/com_ExtensionName/helpers/Extensionname.php
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function renderCategoryLinkbar(): void;
|
||||
|
||||
/**
|
||||
* Set a renderer option (depends on the renderer)
|
||||
*
|
||||
* @param string $key The name of the option to set
|
||||
* @param string $value The value of the option
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setOption(string $key, string $value): void;
|
||||
|
||||
/**
|
||||
* Set multiple renderer options at once (depends on the renderer)
|
||||
*
|
||||
* @param array $options The options to set as key => value pairs
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function setOptions(array $options): void;
|
||||
|
||||
/**
|
||||
* Get the value of a renderer option
|
||||
*
|
||||
* @param string $key The name of the parameter
|
||||
* @param mixed $default The default value to return if the parameter is not set
|
||||
*
|
||||
* @return mixed The parameter value
|
||||
*/
|
||||
function getOption(string $key, $default = null);
|
||||
}
|
||||
Reference in New Issue
Block a user