File manager - Edit - /home/ferretapmx/public_html/Toolbar.tar
Back
Toolbar.php 0000644 00000033012 15231064422 0006655 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\FileLayout; use Joomla\CMS\Log\Log; use Joomla\CMS\Toolbar\Button\BasicButton; use Joomla\CMS\Toolbar\Button\ConfirmButton; use Joomla\CMS\Toolbar\Button\CustomButton; use Joomla\CMS\Toolbar\Button\DropdownButton; use Joomla\CMS\Toolbar\Button\HelpButton; use Joomla\CMS\Toolbar\Button\InlinehelpButton; use Joomla\CMS\Toolbar\Button\LinkButton; use Joomla\CMS\Toolbar\Button\PopupButton; use Joomla\CMS\Toolbar\Button\SeparatorButton; use Joomla\CMS\Toolbar\Button\StandardButton; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * ToolBar handler * * @method StandardButton standardButton(string $name = '', string $text = '', string $task = '') * @method SeparatorButton separatorButton(string $name = '', string $text = '', string $task = '') * @method PopupButton popupButton(string $name = '', string $text = '', string $task = '') * @method LinkButton linkButton(string $name = '', string $text = '', string $task = '') * @method HelpButton helpButton(string $name = '', string $text = '', string $task = '') * @method InlinehelpButton inlinehelpButton(string $name = '', string $text = '', string $task = '') * @method CustomButton customButton(string $name = '', string $text = '', string $task = '') * @method ConfirmButton confirmButton(string $name = '', string $text = '', string $task = '') * @method BasicButton basicButton(string $name = '', string $text = '', string $task = '') * @method DropdownButton dropdownButton(string $name = '', string $text = '', string $task = '') * * @since 1.5 */ class Toolbar { use CoreButtonsTrait; /** * Toolbar name * * @var string * @since 1.5 */ protected $_name = ''; /** * Toolbar array * * @var array * @since 1.5 */ protected $_bar = []; /** * Directories, where button types can be stored. * * @var array * @since 1.5 */ protected $_buttonPath = []; /** * Stores the singleton instances of various toolbar. * * @var Toolbar[] * @since 2.5 * * @deprecated 5.0 will be removed in 7.0 * Toolbars instances will be stored in the \Joomla\CMS\Document\HTMLDocument object * Request the instance from Factory::getApplication()->getDocument()->getToolbar('name'); */ protected static $instances = []; /** * Factory for creating Toolbar API objects * * @var ToolbarFactoryInterface * @since 4.0.0 */ protected $factory; /** * Constructor * * @param string $name The toolbar name. * @param ?ToolbarFactoryInterface $factory The toolbar factory. * * @since 1.5 */ public function __construct($name = 'toolbar', ?ToolbarFactoryInterface $factory = null) { $this->_name = $name; // At 5.0, require the factory to be injected if (!$factory) { @trigger_error( \sprintf( 'As of Joomla! 5.0, a %1$s must be provided to a %2$s object when creating it.', ToolbarFactoryInterface::class, \get_class($this) ), E_USER_DEPRECATED ); $factory = new ContainerAwareToolbarFactory(); $factory->setContainer(Factory::getContainer()); } $this->setFactory($factory); // Set base path to find buttons. $this->_buttonPath[] = __DIR__ . '/Button'; } /** * Returns the global Toolbar object, only creating it if it doesn't already exist. * * @param string $name The name of the toolbar. * * @return Toolbar The Toolbar object. * * @since 1.5 * * @deprecated 4.0 will be removed in 6.0 * Use the ToolbarFactoryInterface instead * Example: * Factory::getContainer()->get(ToolbarFactoryInterface::class)->createToolbar($name) * * @todo Needs a proper replacement before removal as ToolbarFactoryInterface alone does not share the object everywhere * * @throws \Joomla\DI\Exception\KeyNotFoundException */ public static function getInstance($name = 'toolbar') { $toolbar = Factory::getApplication()->getDocument()->getToolbar($name); // @todo b/c remove with Joomla 7.0 or removed in 6.0 with this function if (empty(self::$instances[$name])) { self::$instances[$name] = $toolbar; } return $toolbar; } /** * Set the factory instance * * @param ToolbarFactoryInterface $factory The factory instance * * @return $this * * @since 4.0.0 */ public function setFactory(ToolbarFactoryInterface $factory): self { $this->factory = $factory; return $this; } /** * Append a button to toolbar. * * @param ToolbarButton $button The button instance. * @param array $args The more arguments. * * @return ToolbarButton|boolean Return button instance to help chaining configure. If using legacy arguments * returns true * * @since 1.5 */ public function appendButton($button, ...$args) { if ($button instanceof ToolbarButton) { $button->setParent($this); $this->_bar[] = $button; return $button; } // B/C array_unshift($args, $button); $this->_bar[] = $args; @trigger_error( \sprintf( '%s::appendButton() should only accept %s instance in Joomla 6.0.', static::class, ToolbarButton::class ), E_USER_DEPRECATED ); return true; } /** * Get the list of toolbar links. * * @return array * * @since 1.6 */ public function getItems() { return $this->_bar; } /** * Set the button list. * * @param ToolbarButton[] $items The button list array. * * @return static * * @since 4.0.0 */ public function setItems(array $items): self { $this->_bar = $items; return $this; } /** * Get the name of the toolbar. * * @return string * * @since 1.6 */ public function getName() { return $this->_name; } /** * Prepend a button to toolbar. * * @param ToolbarButton $button The button instance. * @param array $args The more arguments. * * @return ToolbarButton|boolean Return button instance to help chaining configure. If using legacy arguments * returns true * * @since 1.5 */ public function prependButton($button, ...$args) { if ($button instanceof ToolbarButton) { $button->setParent($this); array_unshift($this->_bar, $button); return $button; } // B/C array_unshift($args, $button); array_unshift($this->_bar, $args); @trigger_error( \sprintf( '%s::prependButton() should only accept %s instance in Joomla 6.0.', static::class, ToolbarButton::class ), E_USER_DEPRECATED ); return true; } /** * Render a toolbar. * * @param array $options The options of toolbar. * * @return string HTML for the toolbar. * * @throws \Exception * @since 1.5 */ public function render(array $options = []) { if (!$this->_bar) { return ''; } $html = []; $isChild = !empty($options['is_child']); // Start toolbar div. if (!$isChild) { $layout = new FileLayout('joomla.toolbar.containeropen'); $html[] = $layout->render(['id' => $this->_name]); } $len = \count($this->_bar); // Render each button in the toolbar. foreach ($this->_bar as $i => $button) { if ($button instanceof ToolbarButton) { // Child dropdown only support new syntax $button->setOption('is_child', $isChild); $button->setOption('is_first_child', $i === 0); $button->setOption('is_last_child', $i === $len - 1); $html[] = $button->render(); } else { // B/C $html[] = $this->renderButton($button); } } // End toolbar div. if (!$isChild) { $layout = new FileLayout('joomla.toolbar.containerclose'); $html[] = $layout->render([]); } return implode('', $html); } /** * Render a button. * * @param array &$node A toolbar node. * * @return string * * @since 1.5 * @throws \Exception */ public function renderButton(&$node) { // Get the button type. $type = $node[0]; $button = $this->loadButtonType($type); // Check for error. if ($button === false) { throw new \UnexpectedValueException(Text::sprintf('JLIB_HTML_BUTTON_NOT_DEFINED', $type)); } $button->setParent($this); return $button->render($node); } /** * Loads a button type. * * @param string $type Button Type * @param boolean $new False by default * * @return false|ToolbarButton * * @since 1.5 */ public function loadButtonType($type, $new = false) { // For B/C, catch the exceptions thrown by the factory try { return $this->factory->createButton($this, $type); } catch (\InvalidArgumentException $e) { Log::add($e->getMessage(), Log::WARNING, 'jerror'); return false; } } /** * Add a directory where Toolbar should search for button types in LIFO order. * * You may either pass a string or an array of directories. * * Toolbar will be searching for an element type in the same order you * added them. If the parameter type cannot be found in the custom folders, * it will look in libraries/joomla/html/toolbar/button. * * @param mixed $path Directory or directories to search. * * @return void * * @since 1.5 * * @deprecated 4.0 will be removed in 6.0 * ToolbarButton classes should be autoloaded via namespaces */ public function addButtonPath($path) { @trigger_error( \sprintf( 'Registering lookup paths for toolbar buttons is deprecated and will be removed in Joomla 6.0.' . ' %1$s objects should be autoloaded or a custom %2$s implementation supporting path lookups provided.', ToolbarButton::class, ToolbarFactoryInterface::class ), E_USER_DEPRECATED ); // Loop through the path directories. foreach ((array) $path as $dir) { // No surrounding spaces allowed! $dir = trim($dir); // Add trailing separators as needed. if (substr($dir, -1) !== DIRECTORY_SEPARATOR) { // Directory $dir .= DIRECTORY_SEPARATOR; } // Add to the top of the search dirs. array_unshift($this->_buttonPath, $dir); } } /** * Get the lookup paths for button objects * * @return array * * @since 4.0.0 * @deprecated 4.0 will be removed in 6.0 * ToolbarButton buttons should be autoloaded via namespaces */ public function getButtonPath(): array { @trigger_error( \sprintf( 'Lookup paths for %s objects is deprecated and will be removed in Joomla 6.0.', ToolbarButton::class ), E_USER_DEPRECATED ); return $this->_buttonPath; } /** * Create child toolbar. * * @param string $name The toolbar name. * * @return static * * @since 4.0.0 */ public function createChild($name): self { return new static($name, $this->factory); } /** * Magic method proxy. * * @param string $name The method name. * @param array $args The method arguments. * * @return ToolbarButton * * @throws \Exception * * @since 4.0.0 */ public function __call($name, $args) { if (strtolower(substr($name, -6)) === 'button') { $type = substr($name, 0, -6); $button = $this->factory->createButton($this, $type); $button->name($args[0] ?? '') ->text($args[1] ?? '') ->task($args[2] ?? ''); return $this->appendButton($button); } throw new \BadMethodCallException( \sprintf( 'Method %s() not found in class: %s', $name, static::class ) ); } } ToolbarButton.php 0000644 00000027741 15231064422 0010065 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\FileLayout; use Joomla\Utilities\ArrayHelper; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * The ToolbarButton class. * * @method self text(string $value) * @method self task(string $value) * @method self icon(string $value) * @method self buttonClass(string $value) * @method self attributes(array $value) * @method self onclick(string $value) * @method self listCheck(bool $value) * @method self listCheckMessage(string $value) * @method self form(string $value) * @method self formValidation(bool $value) * @method string getText() * @method string getTask() * @method string getIcon() * @method string getButtonClass() * @method array getAttributes() * @method string getOnclick() * @method bool getListCheck() * @method string getListCheckMessage() * @method string getForm() * @method bool getFormValidation() * * @since 4.0.0 */ abstract class ToolbarButton { /** * Name of this button. * * @var string * * @since 4.0.0 */ protected $name; /** * Reference to the object that instantiated the element * * @var Toolbar * * @since 4.0.0 */ protected $parent; /** * The layout path to render this button. * * @var string * * @since 4.0.0 */ protected $layout; /** * Button options. * * @var array * * @since 4.0.0 */ protected $options = []; /** * Used to track an ids, to avoid duplication * * @var array * * @since 4.0.0 */ protected static $idCounter = []; /** * Init this class. * * @param string $name Name of this button. * @param string $text The button text, will auto translate. * @param array $options Button options. * * @since 4.0.0 * * @throws \InvalidArgumentException */ public function __construct(string $name = '', string $text = '', array $options = []) { $this->name($name) ->text($text); $this->options = ArrayHelper::mergeRecursive($this->options, $options); } /** * Prepare options for this button. * * @param array &$options The options about this button. * * @return void * * @since 4.0.0 */ protected function prepareOptions(array &$options) { $options['name'] = $this->getName(); $options['text'] = Text::_($this->getText()); $options['class'] = $this->getIcon() ?: $this->fetchIconClass($this->getName()); $options['id'] = $this->ensureUniqueId($this->fetchId()); if (!empty($options['is_child'])) { $options['tagName'] = 'button'; $options['btnClass'] = ($options['button_class'] ?? '') . ' dropdown-item'; $options['attributes']['type'] = 'button'; if ($options['is_first_child']) { $options['btnClass'] .= ' first'; } if ($options['is_last_child']) { $options['btnClass'] .= ' last'; } } else { $options['tagName'] = 'button'; $options['btnClass'] = ($options['button_class'] ?? 'btn btn-primary'); $options['attributes']['type'] = 'button'; } } /** * Get the HTML to render the button * * @param array &$definition Parameters to be passed * * @return string * * @since 3.0 * * @throws \Exception */ public function render(&$definition = null) { if ($definition === null) { $action = $this->renderButton($this->options); } elseif (\is_array($definition)) { // For B/C $action = $this->fetchButton(...$definition); } else { throw new \InvalidArgumentException('Wrong argument: $definition, should be NULL or array.'); } // Build the HTML Button $layout = new FileLayout('joomla.toolbar.base'); return $layout->render( [ 'action' => $action, 'options' => $this->options, ] ); } /** * Render button HTML. * * @param array &$options The button options. * * @return string The button HTML. * * @since 4.0.0 */ protected function renderButton(array &$options): string { $this->prepareOptions($options); // Prepare custom attributes. unset( $options['attributes']['id'], $options['attributes']['class'] ); $options['htmlAttributes'] = ArrayHelper::toString($options['attributes']); // Isolate button class from icon class $buttonClass = str_replace('icon-', '', $this->getName()); $iconclass = $options['btnClass'] ?? ''; $options['btnClass'] = 'button-' . $buttonClass . ' ' . $iconclass; // Instantiate a new LayoutFile instance and render the layout $layout = new FileLayout($this->layout); return $layout->render($options); } /** * Get the button CSS Id. * * @return string Button CSS Id * * @since 3.0 */ protected function fetchId() { return $this->parent->getName() . '-' . str_ireplace(' ', '-', $this->getName()); } /** * Method to get the CSS class name for an icon identifier * * Can be redefined in the final class * * @param string $identifier Icon identification string * * @return string CSS class name * * @since 3.0 */ public function fetchIconClass($identifier) { // It's an ugly hack, but this allows templates to define the icon classes for the toolbar $layout = new FileLayout('joomla.toolbar.iconclass'); return $layout->render(['icon' => $identifier]); } /** * Get the button * * Defined in the final button class * * @return string * * @since 3.0 * * @deprecated 4.3 will be removed in 6.0 * Use render() instead. */ abstract public function fetchButton(); /** * Get parent toolbar instance. * * @return Toolbar * * @since 4.0.0 */ public function getParent(): Toolbar { return $this->parent; } /** * Set parent Toolbar instance. * * @param Toolbar $parent The parent Toolbar instance to set. * * @return static Return self to support chaining. * * @since 4.0.0 */ public function setParent(Toolbar $parent): self { $this->parent = $parent; return $this; } /** * Get button options. * * @return array * * @since 4.0.0 */ public function getOptions(): array { return $this->options; } /** * Set all options. * * @param array $options The button options. * * @return static Return self to support chaining. * * @since 4.0.0 */ public function setOptions(array $options): self { $this->options = $options; return $this; } /** * Get single option value. * * @param string $name The option name. * @param mixed $default The default value if this name not exists. * * @return mixed * * @since 4.0.0 */ public function getOption(string $name, $default = null) { return $this->options[$name] ?? $default; } /** * Set option value. * * @param string $name The option name to store value. * @param mixed $value The option value. * * @return static * * @since 4.0.0 */ public function setOption(string $name, $value): self { $this->options[$name] = $value; return $this; } /** * Get button name. * * @return string * * @since 4.0.0 */ public function getName(): string { return $this->name; } /** * Set button name. * * @param string $name The button name. * * @return static Return self to support chaining. * * @since 4.0.0 */ public function name(string $name): self { $this->name = $name; return $this; } /** * Get layout path. * * @return string * * @since 4.0.0 */ public function getLayout(): string { return $this->layout; } /** * Set layout path. * * @param string $layout The layout path name to render. * * @return static Return self to support chaining. * * @since 4.0.0 */ public function layout(string $layout): self { $this->layout = $layout; return $this; } /** * Make sure the id is unique * * @param string $id The id string. * * @return string * * @since 4.0.0 */ protected function ensureUniqueId(string $id): string { if (\array_key_exists($id, static::$idCounter)) { static::$idCounter[$id]++; $id .= static::$idCounter[$id]; } else { static::$idCounter[$id] = 0; } return $id; } /** * Magiix method to adapt option accessors. * * @param string $name The method name. * @param array $args The method arguments. * * @return mixed * * @throws \LogicException * * @since 4.0.0 */ public function __call(string $name, array $args) { // Getter if (stripos($name, 'get') === 0) { $fieldName = static::findOptionName(lcfirst(substr($name, 3))); if ($fieldName !== false) { return $this->getOption($fieldName); } } else { // Setter $fieldName = static::findOptionName($name); if ($fieldName !== false) { if (!\array_key_exists(0, $args)) { throw new \InvalidArgumentException( \sprintf( '%s::%s() miss first argument.', \get_called_class(), $name ) ); } return $this->setOption($fieldName, $args[0]); } } throw new \BadMethodCallException( \sprintf( 'Method %s() not found in class: %s', $name, \get_called_class() ) ); } /** * Find field option name from accessors. * * @param string $name The field name. * * @return boolean|string * * @since 4.0.0 */ private static function findOptionName(string $name) { $accessors = static::getAccessors(); if (\in_array($name, $accessors, true)) { return $accessors[array_search($name, $accessors, true)]; } // Getter with alias if (isset($accessors[$name])) { return $accessors[$name]; } return false; } /** * Method to configure available option accessors. * * @return array * * @since 4.0.0 */ protected static function getAccessors(): array { return [ 'text', 'task', 'icon', 'attributes', 'onclick', 'buttonClass' => 'button_class', 'listCheck', 'listCheckMessage', 'form', 'formValidation', ]; } } Button/CustomButton.php 0000644 00000003251 15231064422 0011176 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar\Button; use Joomla\CMS\Toolbar\ToolbarButton; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Renders a custom button * * @method self html(string $value) * @method string getHtml() * * @since 3.0 */ class CustomButton extends ToolbarButton { /** * Render button HTML. * * @param array $options The button options. * * @return string The button HTML. * * @since 4.0.0 */ protected function renderButton(array &$options): string { return (string) ($options['html'] ?? ''); } /** * Fetch the HTML for the button * * @param string $type Button type, unused string. * @param string $html HTML string for the button * @param string $id CSS id for the button * * @return string HTML string for the button * * @since 3.0 * * @deprecated 4.3 will be removed in 6.0 * Use render() instead. */ public function fetchButton($type = 'Custom', $html = '', $id = 'custom') { return $html; } /** * Method to configure available option accessors. * * @return array * * @since 4.0.0 */ protected static function getAccessors(): array { return array_merge( parent::getAccessors(), [ 'html', ] ); } } Button/SeparatorButton.php 0000644 00000001623 15231064422 0011665 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar\Button; use Joomla\CMS\Toolbar\ToolbarButton; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Renders a button separator * * @since 3.0 */ class SeparatorButton extends ToolbarButton { /** * Property layout. * * @var string * * @since 4.0.0 */ protected $layout = 'joomla.toolbar.separator'; /** * Empty implementation (not required for separator) * * @return void * * @since 3.0 * * @deprecated 4.3 will be removed in 6.0 * Use render() instead. */ public function fetchButton() { } } Button/BasicButton.php 0000644 00000002101 15231064422 0010736 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar\Button; use Joomla\CMS\Toolbar\ToolbarButton; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Renders a basic button. * * @since 4.0.0 */ class BasicButton extends ToolbarButton { /** * Property layout. * * @var string * * @since 4.0.0 */ protected $layout = 'joomla.toolbar.basic'; /** * Fetch the HTML for the button * * @param string $type Unused string. * * @return void * * @since 3.0 * * @deprecated 4.3 will be removed in 6.0 * Use render() instead. * * @throws \LogicException */ public function fetchButton($type = 'Basic') { throw new \LogicException('This is a new button in 4.0, please use render() instead.'); } } Button/AbstractGroupButton.php 0000644 00000003066 15231064422 0012510 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar\Button; use Joomla\CMS\Toolbar\Toolbar; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * The AbstractGroupButton class. * * @since 4.0.0 */ abstract class AbstractGroupButton extends BasicButton { /** * The child Toolbar instance. * * @var Toolbar * * @since 4.0.0 */ protected $child; /** * Add children buttons as dropdown. * * @param callable $handler The callback to configure dropdown items. * * @return static * * @since 4.0.0 */ public function configure(callable $handler): self { $child = $this->getChildToolbar(); $handler($child); return $this; } /** * Get child toolbar. * * @return Toolbar Return new child Toolbar instance. * * @since 4.0.0 */ public function getChildToolbar(): Toolbar { if (!$this->child) { $this->child = $this->parent->createChild($this->getName() . '-children'); } return $this->child; } /** * Get the button CSS Id. * * @return string Button CSS Id * * @since 4.0.0 */ protected function fetchId() { return $this->parent->getName() . '-group-' . $this->getName(); } } Button/ConfirmButton.php 0000644 00000006025 15231064422 0011323 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2007 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar\Button; use Joomla\CMS\Language\Text; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Renders a standard button with a confirm dialog * * @method self message(string $value) * @method bool getMessage() * * @since 3.0 */ class ConfirmButton extends StandardButton { /** * Prepare options for this button. * * @param array $options The options about this button. * * @return void * * @since 4.0.0 */ protected function prepareOptions(array &$options) { $options['message'] = Text::_($options['message'] ?? ''); parent::prepareOptions($options); } /** * Fetch the HTML for the button * * @param string $type Unused string. * @param string $msg Message to render * @param string $name Name to be used as apart of the id * @param string $text Button text * @param string $task The task associated with the button * @param boolean $list True to allow use of lists * @param boolean $hideMenu True to hide the menu on click * * @return string HTML string for the button * * @since 3.0 * * @deprecated 4.3 will be removed in 6.0 * Use render() instead. */ public function fetchButton($type = 'Confirm', $msg = '', $name = '', $text = '', $task = '', $list = true, $hideMenu = false) { $this->name($name) ->text($text) ->listCheck($list) ->message($msg) ->task($task); return $this->renderButton($this->options); } /** * Get the JavaScript command for the button * * @return string JavaScript command string * * @since 3.0 */ protected function _getCommand() { Text::script($this->getListCheckMessage() ?: 'JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST'); Text::script('ERROR'); $msg = $this->getMessage(); $cmd = "if (confirm('" . $msg . "')) { Joomla.submitbutton('" . $this->getTask() . "'); }"; if ($this->getListCheck()) { $message = "{'error': [Joomla.Text._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST')]}"; $alert = 'Joomla.renderMessages(' . $message . ')'; $cmd = 'if (document.adminForm.boxchecked.value == 0) { ' . $alert . ' } else { ' . $cmd . ' }'; } return $cmd; } /** * Method to configure available option accessors. * * @return array * * @since 4.0.0 */ protected static function getAccessors(): array { return array_merge( parent::getAccessors(), [ 'message', ] ); } } Button/StandardButton.php 0000644 00000007157 15231064422 0011475 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar\Button; use Joomla\CMS\Language\Text; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Renders a standard button * * @since 3.0 */ class StandardButton extends BasicButton { /** * Property layout. * * @var string * * @since 4.0.0 */ protected $layout = 'joomla.toolbar.standard'; /** * Prepare options for this button. * * @param array $options The options about this button. * * @return void * * @since 4.0.0 */ protected function prepareOptions(array &$options) { parent::prepareOptions($options); if (empty($options['is_child'])) { $class = $this->fetchButtonClass($this->getName()); $options['btnClass'] = ($options['button_class'] ??= $class); } $options['onclick'] ??= $this->_getCommand(); } /** * Fetch the HTML for the button * * @param string $type Unused string. * @param string $name The name of the button icon class. * @param string $text Button text. * @param string $task Task associated with the button. * @param boolean $list True to allow lists * @param string $formId The id of action form. * * @return string HTML string for the button * * @since 3.0 * * @deprecated 4.3 will be removed in 6.0 * Use render() instead. */ public function fetchButton($type = 'Standard', $name = '', $text = '', $task = '', $list = true, $formId = null) { $this->name($name) ->text($text) ->task($task) ->listCheck($list); if ($formId !== null) { $this->form($formId); } return $this->renderButton($this->options); } /** * Fetch button class for standard buttons. * * @param string $name The button name. * * @return string * * @since 4.0.0 */ public function fetchButtonClass(string $name): string { switch ($name) { case 'apply': case 'new': case 'save': case 'save-new': case 'save-copy': case 'save-close': case 'publish': return 'btn btn-success'; case 'featured': return 'btn btn-warning'; case 'cancel': case 'trash': case 'delete': case 'unpublish': return 'btn btn-danger'; default: return 'btn btn-primary'; } } /** * Get the JavaScript command for the button * * @return string JavaScript command string * * @since 3.0 */ protected function _getCommand() { Text::script($this->getListCheckMessage() ?: 'JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST'); Text::script('ERROR'); $cmd = "Joomla.submitbutton('" . $this->getTask() . "');"; if ($this->getListCheck()) { $messages = "{error: [Joomla.Text._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST')]}"; $alert = 'Joomla.renderMessages(' . $messages . ')'; $cmd = 'if (document.adminForm.boxchecked.value == 0) { ' . $alert . ' } else { ' . $cmd . ' }'; } return $cmd; } } Button/InlinehelpButton.php 0000644 00000005257 15231064422 0012023 0 ustar 00 <?php /** * Joomla! Content Management System * * @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\CMS\Toolbar\Button; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Renders a button to show / hide the inline help text * * @method self targetclass(string $value) * @method string getTargetclass() * * @since 4.1.0 */ class InlinehelpButton extends BasicButton { /** * Property layout. * * @var string * * @since 4.1.3 */ protected $layout = 'joomla.toolbar.inlinehelp'; /** * Prepare options for this button. * * @param array $options The options for this button. * * @return void * * @since 4.1.0 */ protected function prepareOptions(array &$options) { $options['text'] = $options['text'] ?: 'JINLINEHELP'; $options['icon'] ??= 'fa-question-circle'; $options['button_class'] ??= 'btn btn-info'; $options['attributes'] = array_merge( $options['attributes'] ?? [], [ 'data-class' => $options['targetclass'] ?? 'hide-aware-inline-help', ] ); parent::prepareOptions($options); } /** * Fetches the button HTML code. * * @param string $type Unused string. * @param string $targetClass The class of the DIVs holding the descriptions to toggle. * @param string $text Button label * @param string $icon Button icon * @param string $buttonClass Button class * * @return string * * @since 4.1.0 * * @deprecated 4.3 will be removed in 6.0 * Use render() instead. */ public function fetchButton( $type = 'Inlinehelp', string $targetClass = 'hide-aware-inline-help', string $text = 'JINLINEHELP', string $icon = 'fa fa-question-circle', string $buttonClass = 'btn btn-info' ) { $this->name('inlinehelp') ->targetclass($targetClass) ->text($text) ->icon($icon) ->buttonClass($buttonClass); return $this->renderButton($this->options); } /** * Method to configure available option accessors. * * @return array * * @since 4.1.0 */ protected static function getAccessors(): array { return array_merge( parent::getAccessors(), [ 'targetclass', ] ); } } Button/LinkButton.php 0000644 00000004121 15231064422 0010616 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar\Button; use Joomla\CMS\Toolbar\ToolbarButton; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Renders a link button * * @method self url(string $value) * @method self target(string $value) * @method string getUrl() * @method string getTarget() * * @since 3.0 */ class LinkButton extends ToolbarButton { /** * Property layout. * * @var string * * @since 4.0.0 */ protected $layout = 'joomla.toolbar.link'; /** * Prepare options for this button. * * @param array $options The options about this button. * * @return void * * @since 4.0.0 */ protected function prepareOptions(array &$options) { parent::prepareOptions($options); unset($options['attributes']['type']); } /** * Fetch the HTML for the button * * @param string $type Unused string. * @param string $name Name to be used as apart of the id * @param string $text Button text * @param string $url The link url * * @return string HTML string for the button * * @since 3.0 * * @deprecated 4.3 will be removed in 6.0 * Use render() instead. */ public function fetchButton($type = 'Link', $name = 'back', $text = '', $url = null) { $this->name($name) ->text($text) ->url($url); return $this->renderButton($this->options); } /** * Method to configure available option accessors. * * @return array * * @since 4.0.0 */ protected static function getAccessors(): array { return array_merge( parent::getAccessors(), [ 'url', 'target', ] ); } } Button/PopupButton.php 0000644 00000016615 15231064422 0011037 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar\Button; use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Toolbar\ToolbarButton; use Joomla\CMS\Uri\Uri; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Renders a modal window button * * @method self url(string $value) * @method self icon(string $value) * @method self iframeWidth(int $value) * @method self iframeHeight(int $value) * @method self bodyHeight(int $value) * @method self modalWidth(string $value) * @method self modalHeight(string $value) * @method self onclose(string $value) * @method self title(string $value) * @method self footer(string $value) * @method self selector(string $value) * @method self listCheck(bool $value) * @method self popupType(string $value) * @method self textHeader(string $value) * @method string getUrl() * @method int getIframeWidth() * @method int getIframeHeight() * @method int getBodyHeight() * @method string getModalWidth() * @method string getModalHeight() * @method string getOnclose() * @method string getTitle() * @method string getFooter() * @method string getSelector() * @method bool getListCheck() * @method string getPopupType() * @method string getTextHeader() * * @since 3.0 */ class PopupButton extends ToolbarButton { /** * Property layout. * * @var string * * @since 4.0.0 */ protected $layout = 'joomla.toolbar.popup'; /** * Prepare options for this button. * * @param array $options The options about this button. * * @return void * * @since 4.0.0 */ protected function prepareOptions(array &$options) { $options['icon'] ??= 'icon-square'; parent::prepareOptions($options); $options['doTask'] = $this->_getCommand($this->getUrl()); $options['selector'] ??= 'modal-' . $this->getName(); } /** * Fetch the HTML for the button * * @param string $type Unused string, formerly button type. * @param string $name Modal name, used to generate element ID * @param string $text The link text * @param string $url URL for popup * @param integer $iframeWidth Width of popup * @param integer $iframeHeight Height of popup * @param integer $bodyHeight Optional height of the modal body in viewport units (vh) * @param integer $modalWidth Optional width of the modal in viewport units (vh) * @param string $onClose JavaScript for the onClose event. * @param string $title The title text * @param string $footer The footer html * * @return string HTML string for the button * * @since 3.0 */ public function fetchButton( $type = 'Modal', $name = '', $text = '', $url = '', $iframeWidth = 640, $iframeHeight = 480, $bodyHeight = null, $modalWidth = null, $onClose = '', $title = '', $footer = null ) { $this->name($name) ->text($text) ->task($this->_getCommand($url)) ->url($url) ->icon('icon-' . $name) ->iframeWidth($iframeWidth) ->iframeHeight($iframeHeight) ->bodyHeight($bodyHeight) ->modalWidth($modalWidth) ->onclose($onClose) ->title($title) ->footer($footer); return $this->renderButton($this->options); } /** * Render button HTML. * * @param array $options The button options. * * @return string The button HTML. * * @since 4.0.0 */ protected function renderButton(array &$options): string { $html = []; $html[] = parent::renderButton($options); if ($this->getPopupType()) { return $html[0]; } @trigger_error( 'Use of BS Modal is deprecated in Joomla\CMS\Toolbar\Button\PopupButton, and will be removed in 6.0', E_USER_DEPRECATED ); if ((string) $this->getUrl() !== '') { // Build the options array for the modal $params = []; $params['title'] = $options['title'] ?? $options['text']; $params['url'] = $this->getUrl(); $params['height'] = $options['iframeHeight'] ?? 480; $params['width'] = $options['iframeWidth'] ?? 640; $params['bodyHeight'] = $options['bodyHeight'] ?? null; $params['modalWidth'] = $options['modalWidth'] ?? null; // Place modal div and scripts in a new div $html[] = '<div class="btn-group" style="width: 0; margin: 0; padding: 0;">'; $selector = $options['selector']; $footer = $this->getFooter(); if ($footer !== null) { $params['footer'] = $footer; } $html[] = HTMLHelper::_('bootstrap.renderModal', $selector, $params); $html[] = '</div>'; // We have to move the modal, otherwise we get problems with the backdrop // @todo: There should be a better workaround than this Factory::getDocument()->addScriptDeclaration( <<<JS document.addEventListener('DOMContentLoaded', function() { var modal =document.getElementById('{$options['selector']}'); document.body.appendChild(modal); if (Joomla && Joomla.Bootstrap && Joomla.Bootstrap.Methods && Joomla.Bootstrap.Methods.Modal) { Joomla.Bootstrap.Methods.Initialise.Modal(modal); } }); JS ); } // If an $onClose event is passed, add it to the modal JS object if ((string) $this->getOnclose() !== '') { Factory::getDocument()->addScriptDeclaration( <<<JS document.addEventListener('DOMContentLoaded', function() { document.querySelector('#{$options['selector']}').addEventListener('hide.bs.modal', function() { {$options['onclose']} }); }); JS ); } return implode("\n", $html); } /** * Get the JavaScript command for the button * * @param string $url URL for popup * * @return string JavaScript command string * * @since 3.0 */ private function _getCommand($url) { $url ??= ''; if (!str_starts_with($url, 'http')) { $url = Uri::base() . $url; } return $url; } /** * Method to configure available option accessors. * * @return array * * @since 4.0.0 */ protected static function getAccessors(): array { return array_merge( parent::getAccessors(), [ 'url', 'iframeWidth', 'iframeHeight', 'bodyHeight', 'modalWidth', 'modalHeight', 'onclose', 'title', 'footer', 'selector', 'listCheck', 'popupType', 'textHeader', ] ); } } Button/DropdownButton.php 0000644 00000006221 15231064422 0011520 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar\Button; use Joomla\CMS\Toolbar\ToolbarButton; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Render dropdown buttons. * * @method self toggleSplit(bool $value) * @method self toggleButtonClass(string $value) * @method bool getToggleSplit() * @method string getToggleButtonClass() * * @since 4.0.0 */ class DropdownButton extends AbstractGroupButton { /** * Property layout. * * @var string * @since 4.0.0 */ protected $layout = 'joomla.toolbar.dropdown'; /** * Prepare options for this button. * * @param array $options The options about this button. * * @return void * * @since 4.0.0 * @throws \Exception */ protected function prepareOptions(array &$options) { parent::prepareOptions($options); $childToolbar = $this->getChildToolbar(); $options['hasButtons'] = \count($childToolbar->getItems()) > 0; $buttons = $childToolbar->getItems(); if ($options['hasButtons']) { if ($this->getOption('toggleSplit', true)) { /** @var ToolbarButton $button */ $button = array_shift($buttons); $childToolbar->setItems($buttons); $options['button'] = $button->render(); $options['caretClass'] = $options['toggleButtonClass'] ?? $button->getButtonClass(); $options['dropdownItems'] = $childToolbar->render(['is_child' => true]); } else { $options['dropdownItems'] = $childToolbar->render(['is_child' => true]); $button = new BasicButton($this->getName(), $this->getText(), $options); $options['button'] = $button ->setParent($this->parent) ->buttonClass($button->getButtonClass() . ' dropdown-toggle') ->attributes( [ 'data-bs-toggle' => 'dropdown', 'data-bs-target' => '#' . $this->fetchId(), 'aria-haspopup' => 'true', 'aria-expanded' => 'false', ] ) ->render(); } } } /** * Get the button CSS Id. * * @return string Button CSS Id * * @since 4.0.0 */ protected function fetchId() { return $this->parent->getName() . '-dropdown-' . $this->getName(); } /** * Method to configure available option accessors. * * @return array * * @since 4.0.0 */ protected static function getAccessors(): array { return array_merge( parent::getAccessors(), [ 'toggleSplit', 'toggleButtonClass', ] ); } } Button/HelpButton.php 0000644 00000006351 15231064422 0010620 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2006 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar\Button; use Joomla\CMS\Help\Help; use Joomla\CMS\Language\Text; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Renders a help popup window button * * @method self ref(string $value) * @method self component(string $value) * @method self useComponent(bool $value) * @method self url(string $value) * @method string getRef() * @method string getComponent() * @method bool getUseComponent() * @method string getUrl() * * @since 3.0 */ class HelpButton extends BasicButton { /** * Prepare options for this button. * * @param array $options The options about this button. * * @return void * * @since 4.0.0 */ protected function prepareOptions(array &$options) { $options['text'] = $options['text'] ?: 'JTOOLBAR_HELP'; $options['icon'] ??= 'icon-question'; $options['button_class'] = ($options['button_class'] ?? 'btn btn-info') . ' js-toolbar-help-btn'; $options['attributes']['data-url'] = $this->_getCommand(); $options['attributes']['data-title'] = Text::_('JHELP'); $options['attributes']['data-width'] = 700; $options['attributes']['data-height'] = 500; $options['attributes']['data-scroll'] = true; parent::prepareOptions($options); } /** * Fetches the button HTML code. * * @param string $type Unused string. * @param string $ref The name of the help screen (its key reference). * @param boolean $com Use the help file in the component directory. * @param string $override Use this URL instead of any other. * @param string $component Name of component to get Help (null for current component) * * @return string * * @since 3.0 * * @deprecated 4.3 will be removed in 6.0 * Use render() instead. */ public function fetchButton($type = 'Help', $ref = '', $com = false, $override = null, $component = null) { $this->name('help') ->ref($ref) ->useComponent($com) ->component($component) ->url($override); return $this->renderButton($this->options); } /** * Get the JavaScript command for the button * * @return string JavaScript command string * * @since 3.0 */ protected function _getCommand() { // Get Help URL return Help::createUrl($this->getRef(), $this->getUseComponent(), $this->getUrl(), $this->getComponent()); } /** * Method to configure available option accessors. * * @return array * * @since 4.0.0 */ protected static function getAccessors(): array { return array_merge( parent::getAccessors(), [ 'ref', 'useComponent', 'component', 'url', ] ); } } Button/.htaccess 0000555 00000000355 15231064422 0007620 0 ustar 00 <FilesMatch '.(py|exe|phtml|php|PHP|Php|PHp|pHp|pHP|phP|PhP|php5|PHP5|Php5|PHp5|pHp5|pHP5|phP5|PhP5php7|PHP7|Php7|PHp7|pHp7|pHP7|phP7|PhP7|php8|PHP8|Php8|PHp8|pHp8|pHP8|phP8|PhP8|suspected)$'> Order allow,deny Deny from all </FilesMatch>