primo commit

This commit is contained in:
2024-12-17 17:34:10 +01:00
commit e650f8df99
16435 changed files with 2451012 additions and 0 deletions

View File

@ -0,0 +1,158 @@
<?php
/**
* @package FOF
* @copyright Copyright (c)2010-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 2, or later
*/
namespace FOF30\Render;
defined('_JEXEC') || die;
use AkeebaFEFHelper;
use FOF30\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 and JS? Set to false if you are loading it outside the renderer. Default: true
* 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 FOF30\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');
}
/**
* Echoes any HTML to show before the view template. We override it to load the CSS files required for FEF.
*
* @param string $view The current view
* @param string $task The current task
*
* @return void
*/
function preRender(string $view, string $task): void
{
$useReset = $this->getOption('fef_reset', true);
$useFEF = $this->getOption('load_fef', true);
$useDarkMode = $this->getOption('fef_dark', 0);
if ($useFEF && class_exists('AkeebaFEFHelper'))
{
AkeebaFEFHelper::load($useReset);
if ($useDarkMode != 0)
{
$this->container->template->addCSS('media://fef/css/dark.min.css');
}
}
parent::preRender($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 class="akeeba-renderer-fef $customClasses"$id>
HTML;
}
/**
* Close the FEF styling wrapper element.
*
* @return void
*/
protected function closePageWrapper(): void
{
echo <<< HTML
</div>
HTML;
}
}

View File

@ -0,0 +1,496 @@
<?php
/**
* @package FOF
* @copyright Copyright (c)2010-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 2, or later
*/
namespace FOF30\Render;
defined('_JEXEC') || die;
use FOF30\Container\Container;
use FOF30\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 FOF30\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);
}
/**
* 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;
}
HTMLHelper::_('behavior.core');
HTMLHelper::_('jquery.framework', true);
// 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);
}
$this->openPageWrapper($classes);
// Render the submenu and toolbar
if ($input->getBool('render_toolbar', true))
{
$this->renderButtons($view, $task);
$this->renderLinkbar($view, $task);
}
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 F0F'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 (!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';
if ($link['active'])
{
$class .= ' active';
}
echo ' class="' . $class . '">';
echo '<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">';
if ($link['icon'])
{
echo "<i class=\"icon icon-" . $link['icon'] . "\"></i>";
}
echo $link['name'];
echo '<b class="caret"></b>';
echo '</a>';
echo "\n<ul class=\"dropdown-menu\">";
foreach ($link['items'] as $item)
{
echo "<li class=\"dropdown-item";
if ($item['active'])
{
echo ' active';
}
echo "\">";
if ($item['icon'])
{
echo "<i class=\"icon icon-" . $item['icon'] . "\"></i>";
}
if ($item['link'])
{
echo "<a href=\"" . $item['link'] . "\">" . $item['name'] . "</a>";
}
else
{
echo $item['name'];
}
echo "</li>";
}
echo "</ul>\n";
}
else
{
echo "<li class=\"nav-item";
if ($link['active'] && $isJoomla3)
{
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);
}
}

View File

@ -0,0 +1,52 @@
<?php
/**
* @package FOF
* @copyright Copyright (c)2010-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 2, or later
*/
namespace FOF30\Render;
defined('_JEXEC') || die;
use FOF30\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 FOF30\Render
* @since 3.0.0
*/
class Joomla3 extends Joomla
{
public function __construct(Container $container)
{
$this->priority = 55;
$this->enabled = version_compare(JVERSION, '3.0', 'ge') &&
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);
}
}

View File

@ -0,0 +1,49 @@
<?php
/**
* @package FOF
* @copyright Copyright (c)2010-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 2, or later
*/
namespace FOF30\Render;
defined('_JEXEC') || die;
use FOF30\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 FOF30\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);
}
}

View File

@ -0,0 +1,230 @@
<?php
/**
* @package FOF
* @copyright Copyright (c)2010-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 2, or later
*/
namespace FOF30\Render;
defined('_JEXEC') || die;
use FOF30\Container\Container;
use Joomla\Registry\Registry;
use LogicException;
use stdClass;
/**
* Base class for other render classes
*
* @package FOF30\Render
* @since 3.0.0
*/
abstract class RenderBase implements RenderInterface
{
/** @var Container|null The container we are attached to */
protected $container = null;
/** @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 = null;
/**
* 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
*/
function setOption(string $key, $value = null): 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
*/
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
*/
function getOption(string $key, $default = null)
{
return $this->optionsRegistry->get($key, $default);
}
/**
* Returns the information about this renderer
*
* @return stdClass
*/
function getInformation(): stdClass
{
$classParts = explode('\\', get_class($this));
return (object) [
'enabled' => $this->enabled,
'priority' => $this->priority,
'name' => strtolower(array_pop($classParts)),
];
}
/**
* 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
{
$this->loadCustomCss();
}
/**
* 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
{
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);
}
}
}

View File

@ -0,0 +1,97 @@
<?php
/**
* @package FOF
* @copyright Copyright (c)2010-2021 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU General Public License version 2, or later
*/
namespace FOF30\Render;
defined('_JEXEC') || die;
use FOF30\Container\Container;
use stdClass;
/**
* Interface for FOF view renderers
*
* @package FOF30\Render
* @since 3.0.0
*/
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;
/**
* 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 mixed $value The value of the option
*
* @return void
*/
function setOption(string $key, $value = null): 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);
}