File manager - Edit - /home/opticamezl/www/newok/Toolbar.tar
Back
ToolbarHelper.php 0000644 00000056060 15172656140 0010035 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2005 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\Table\Table; use Joomla\CMS\Uri\Uri; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Utility class for the button bar. * * @since 1.5 */ abstract class ToolbarHelper { /** * Title cell. * For the title and toolbar to be rendered correctly, * this title function must be called before the starttable function and the toolbars icons * this is due to the nature of how the css has been used to position the title in respect to the toolbar. * * @param string $title The title. * @param string $icon The space-separated names of the image. * * @return void * * @since 1.5 */ public static function title($title, $icon = 'generic.png') { $layout = new FileLayout('joomla.toolbar.title'); $html = $layout->render(['title' => $title, 'icon' => $icon]); $app = Factory::getApplication(); $app->JComponentTitle = $html; $title = strip_tags($title) . ' - ' . $app->get('sitename'); if ($app->isClient('administrator')) { $title .= ' - ' . Text::_('JADMINISTRATION'); } Factory::getDocument()->setTitle($title); } /** * Writes a spacer cell. * * @param string $width The width for the cell * * @return void * * @since 1.5 */ public static function spacer($width = '') { $bar = Toolbar::getInstance('toolbar'); // Add a spacer. $bar->appendButton('Separator', 'spacer', $width); } /** * Writes a divider between menu buttons * * @return void * * @since 1.5 */ public static function divider() { $bar = Toolbar::getInstance('toolbar'); // Add a divider. $bar->appendButton('Separator', 'divider'); } /** * Writes a custom option and task button for the button bar. * * @param string $task The task to perform (picked up by the switch($task) blocks). * @param string $icon The image to display. * @param string $iconOver @deprecated 4.3 will be removed in 6.0 * @param string $alt The alt text for the icon image. * @param bool $listSelect True if required to check that a standard list item is checked. * @param string $formId The id of action form. * * @return void * * @since 1.5 */ public static function custom($task = '', $icon = '', $iconOver = '', $alt = '', $listSelect = true, $formId = null) { $bar = Toolbar::getInstance('toolbar'); // Strip extension. $icon = preg_replace('#\.[^.]*$#', '', $icon); // Add a standard button. $bar->appendButton('Standard', $icon, $alt, $task, $listSelect, $formId); } /** * Writes a preview button for a given option (opens a popup window). * * @param string $url The name of the popup file (excluding the file extension) * @param bool $updateEditors Unused * @param string $icon The image to display. * @param integer $bodyHeight The body height of the preview popup * @param integer $modalWidth The modal width of the preview popup * * @return void * * @since 1.5 */ public static function preview($url = '', $updateEditors = false, $icon = 'preview', $bodyHeight = null, $modalWidth = null) { $bar = Toolbar::getInstance('toolbar'); // Add a preview button. $bar->appendButton('Popup', $icon, 'Preview', $url . '&task=preview', 640, 480, $bodyHeight, $modalWidth); } /** * Writes a jooa11y accessibility checker button for a given option (opens a popup window). * * @param string $url The url to open * @param bool $updateEditors Unused * @param string $icon The image to display. * @param integer $bodyHeight The body height of the preview popup * @param integer $modalWidth The modal width of the preview popup * * @return void * * @since 4.1.0 */ public static function jooa11y($url = '', $updateEditors = false, $icon = 'icon-universal-access', $bodyHeight = null, $modalWidth = null) { $bar = Toolbar::getInstance('toolbar'); // Add a button. $bar->appendButton('Popup', $icon, 'Preview', $url . '&task=preview', 640, 480, $bodyHeight, $modalWidth); } /** * Writes a help button for a given option (opens a popup window). * * @param string $ref The name of the popup file (excluding the file extension for an xml file). * @param bool $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 void * * @since 1.5 */ public static function help($ref, $com = false, $override = null, $component = null) { // Don't show a help button if neither $ref nor $override is given if (!$ref && !$override) { return; } $bar = Toolbar::getInstance('toolbar'); // Add a help button. $bar->appendButton('Help', $ref, $com, $override, $component); } /** * Writes a help button for showing/hiding the inline help of a form * * @param string $class The class used by the inline help items. * * @return void * * @since 4.1.0 */ public static function inlinehelp(string $class = "hide-aware-inline-help") { $bar = Toolbar::getInstance('toolbar'); $bar->inlinehelp($class); } /** * Writes a cancel button that will go back to the previous page without doing * any other operation. * * @param string $alt Alternative text. * @param string $href URL of the href attribute. * * @return void * * @since 1.5 */ public static function back($alt = 'JTOOLBAR_BACK', $href = 'javascript:history.back();') { $bar = Toolbar::getInstance('toolbar'); // Add a back button. $arrow = Factory::getLanguage()->isRtl() ? 'arrow-right' : 'arrow-left'; $bar->appendButton('Link', $arrow, $alt, $href); } /** * Creates a button to redirect to a link * * @param string $url The link url * @param string $text Button text * @param string $name Name to be used as apart of the id * * @return void * * @since 3.5 */ public static function link($url, $text, $name = 'link') { $bar = Toolbar::getInstance('toolbar'); $bar->appendButton('Link', $name, $text, $url); } /** * Writes a media_manager button. * * @param string $directory The subdirectory to upload the media to. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function media_manager($directory = '', $alt = 'JTOOLBAR_UPLOAD') { $bar = Toolbar::getInstance('toolbar'); // Add an upload button. $bar->appendButton('Popup', 'upload', $alt, 'index.php?option=com_media&tmpl=component&task=popupUpload&folder=' . $directory, 800, 520); } /** * Writes a common 'default' button for a record. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function makeDefault($task = 'default', $alt = 'JTOOLBAR_DEFAULT') { $bar = Toolbar::getInstance('toolbar'); // Add a default button. $bar->appendButton('Standard', 'default', $alt, $task, true); } /** * Writes a common 'assign' button for a record. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function assign($task = 'assign', $alt = 'JTOOLBAR_ASSIGN') { $bar = Toolbar::getInstance('toolbar'); // Add an assign button. $bar->appendButton('Standard', 'assign', $alt, $task, true); } /** * Writes the common 'new' icon for the button bar. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * @param boolean $check True if required to check that a standard list item is checked. * * @return void * * @since 1.5 */ public static function addNew($task = 'add', $alt = 'JTOOLBAR_NEW', $check = false) { $bar = Toolbar::getInstance('toolbar'); // Add a new button. $bar->appendButton('Standard', 'new', $alt, $task, $check); } /** * Writes a common 'publish' button. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * @param boolean $check True if required to check that a standard list item is checked. * * @return void * * @since 1.5 */ public static function publish($task = 'publish', $alt = 'JTOOLBAR_PUBLISH', $check = false) { $bar = Toolbar::getInstance('toolbar'); // Add a publish button. $bar->appendButton('Standard', 'publish', $alt, $task, $check); } /** * Writes a common 'publish' button for a list of records. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function publishList($task = 'publish', $alt = 'JTOOLBAR_PUBLISH') { $bar = Toolbar::getInstance('toolbar'); // Add a publish button (list). $bar->appendButton('Standard', 'publish', $alt, $task, true); } /** * Writes a common 'unpublish' button. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * @param boolean $check True if required to check that a standard list item is checked. * * @return void * * @since 1.5 */ public static function unpublish($task = 'unpublish', $alt = 'JTOOLBAR_UNPUBLISH', $check = false) { $bar = Toolbar::getInstance('toolbar'); // Add an unpublish button $bar->appendButton('Standard', 'unpublish', $alt, $task, $check); } /** * Writes a common 'unpublish' button for a list of records. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function unpublishList($task = 'unpublish', $alt = 'JTOOLBAR_UNPUBLISH') { $bar = Toolbar::getInstance('toolbar'); // Add an unpublish button (list). $bar->appendButton('Standard', 'unpublish', $alt, $task, true); } /** * Writes a common 'archive' button for a list of records. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function archiveList($task = 'archive', $alt = 'JTOOLBAR_ARCHIVE') { $bar = Toolbar::getInstance('toolbar'); // Add an archive button. $bar->appendButton('Standard', 'archive', $alt, $task, true); } /** * Writes an unarchive button for a list of records. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function unarchiveList($task = 'unarchive', $alt = 'JTOOLBAR_UNARCHIVE') { $bar = Toolbar::getInstance('toolbar'); // Add an unarchive button (list). $bar->appendButton('Standard', 'unarchive', $alt, $task, true); } /** * Writes a common 'edit' button for a list of records. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function editList($task = 'edit', $alt = 'JTOOLBAR_EDIT') { $bar = Toolbar::getInstance('toolbar'); // Add an edit button. $bar->appendButton('Standard', 'edit', $alt, $task, true); } /** * Writes a common 'edit' button for a template html. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function editHtml($task = 'edit_source', $alt = 'JTOOLBAR_EDIT_HTML') { $bar = Toolbar::getInstance('toolbar'); // Add an edit html button. $bar->appendButton('Standard', 'edithtml', $alt, $task, true); } /** * Writes a common 'edit' button for a template css. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function editCss($task = 'edit_css', $alt = 'JTOOLBAR_EDIT_CSS') { $bar = Toolbar::getInstance('toolbar'); // Add an edit css button (hide). $bar->appendButton('Standard', 'editcss', $alt, $task, true); } /** * Writes a common 'delete' button for a list of records. * * @param string $msg Postscript for the 'are you sure' message. * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function deleteList($msg = '', $task = 'remove', $alt = 'JTOOLBAR_DELETE') { $bar = Toolbar::getInstance('toolbar'); // Add a delete button. if ($msg) { $bar->appendButton('Confirm', $msg, 'delete', $alt, $task, true); } else { $bar->appendButton('Standard', 'delete', $alt, $task, true); } } /** * Writes a common 'trash' button for a list of records. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * @param bool $check True to allow lists. * * @return void * * @since 1.5 */ public static function trash($task = 'remove', $alt = 'JTOOLBAR_TRASH', $check = true) { $bar = Toolbar::getInstance('toolbar'); // Add a trash button. $bar->appendButton('Standard', 'trash', $alt, $task, $check, false); } /** * Writes a save button for a given option. * Apply operation leads to a save action only (does not leave edit mode). * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function apply($task = 'apply', $alt = 'JTOOLBAR_APPLY') { $bar = Toolbar::getInstance('toolbar'); // Add an apply button $bar->apply($task, $alt); } /** * Writes a save button for a given option. * Save operation leads to a save and then close action. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function save($task = 'save', $alt = 'JTOOLBAR_SAVE') { $bar = Toolbar::getInstance('toolbar'); // Add a save button. $bar->save($task, $alt); } /** * Writes a save and create new button for a given option. * Save and create operation leads to a save and then add action. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.6 */ public static function save2new($task = 'save2new', $alt = 'JTOOLBAR_SAVE_AND_NEW') { $bar = Toolbar::getInstance('toolbar'); // Add a save and create new button. $bar->save2new($task, $alt); } /** * Writes a save as copy button for a given option. * Save as copy operation leads to a save after clearing the key, * then returns user to edit mode with new key. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.6 */ public static function save2copy($task = 'save2copy', $alt = 'JTOOLBAR_SAVE_AS_COPY') { $bar = Toolbar::getInstance('toolbar'); // Add a save and create new button. $bar->save2copy($task, $alt); } /** * Writes a checkin button for a given option. * * @param string $task An override for the task. * @param string $alt An override for the alt text. * @param boolean $check True if required to check that a standard list item is checked. * * @return void * * @since 1.7 */ public static function checkin($task = 'checkin', $alt = 'JTOOLBAR_CHECKIN', $check = true) { $bar = Toolbar::getInstance('toolbar'); // Add a save and create new button. $bar->appendButton('Standard', 'checkin', $alt, $task, $check); } /** * Writes a cancel button and invokes a cancel operation (eg a checkin). * * @param string $task An override for the task. * @param string $alt An override for the alt text. * * @return void * * @since 1.5 */ public static function cancel($task = 'cancel', $alt = 'JTOOLBAR_CANCEL') { $bar = Toolbar::getInstance('toolbar'); // Add a cancel button. $bar->appendButton('Standard', 'cancel', $alt, $task, false); } /** * Writes a configuration button and invokes a cancel operation (eg a checkin). * * @param string $component The name of the component, eg, com_content. * @param integer $height The height of the popup. [UNUSED] * @param integer $width The width of the popup. [UNUSED] * @param string $alt The name of the button. * @param string $path An alternative path for the configuration xml relative to JPATH_SITE. * * @return void * * @since 1.5 */ public static function preferences($component, $height = 550, $width = 875, $alt = 'JTOOLBAR_OPTIONS', $path = '') { $component = urlencode($component); $path = urlencode($path); $bar = Toolbar::getInstance('toolbar'); $uri = (string) Uri::getInstance(); $return = urlencode(base64_encode($uri)); // Add a button linking to config for component. $bar->appendButton( 'Link', 'options', $alt, 'index.php?option=com_config&view=component&component=' . $component . '&path=' . $path . '&return=' . $return ); } /** * Writes a version history * * @param string $typeAlias The component and type, for example 'com_content.article' * @param integer $itemId The id of the item, for example the article id. * @param integer $height The height of the popup. * @param integer $width The width of the popup. * @param string $alt The name of the button. * * @return void * * @since 3.2 */ public static function versions($typeAlias, $itemId, $height = 800, $width = 500, $alt = 'JTOOLBAR_VERSIONS') { $lang = Factory::getLanguage(); $lang->load('com_contenthistory', JPATH_ADMINISTRATOR, $lang->getTag(), true); /** @var \Joomla\CMS\Table\ContentType $contentTypeTable */ $contentTypeTable = Table::getInstance('Contenttype'); $typeId = $contentTypeTable->getTypeId($typeAlias); // Options array for Layout $options = []; $options['title'] = Text::_($alt); $options['height'] = $height; $options['width'] = $width; $options['itemId'] = $typeAlias . '.' . $itemId; $bar = Toolbar::getInstance('toolbar'); $layout = new FileLayout('joomla.toolbar.versions'); $bar->appendButton('Custom', $layout->render($options), 'versions'); } /** * Writes a save button for a given option, with an additional dropdown * * @param array $buttons An array of buttons * @param string $class The button class * * @return void * * @since 4.0.0 */ public static function saveGroup($buttons = [], $class = 'btn-success') { $validOptions = [ 'apply' => 'JTOOLBAR_APPLY', 'save' => 'JTOOLBAR_SAVE', 'save2new' => 'JTOOLBAR_SAVE_AND_NEW', 'save2copy' => 'JTOOLBAR_SAVE_AS_COPY', ]; $bar = Toolbar::getInstance('toolbar'); $saveGroup = $bar->dropdownButton('save-group'); $saveGroup->configure( function (Toolbar $childBar) use ($buttons, $validOptions) { foreach ($buttons as $button) { if (!\array_key_exists($button[0], $validOptions)) { continue; } $altText = $button[2] ?? $validOptions[$button[0]]; $childBar->{$button[0]}($button[1]) ->text($altText); } } ); } /** * Displays a modal button * * @param string $targetModalId ID of the target modal box * @param string $icon Icon class to show on modal button * @param string $alt Title for the modal button * @param string $class The button class * * @return void * * @since 3.2 */ public static function modal($targetModalId, $icon, $alt, $class = 'btn-primary') { $title = Text::_($alt); $dhtml = '<joomla-toolbar-button><button data-bs-toggle="modal" data-bs-target="#' . $targetModalId . '" class="btn ' . $class . '"> <span class="' . $icon . ' icon-fw" title="' . $title . '"></span> ' . $title . '</button></joomla-toolbar-button>'; $bar = Toolbar::getInstance('toolbar'); $bar->appendButton('Custom', $dhtml, $alt); } } ToolbarButton.php 0000644 00000027747 15172656140 0010103 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('JPATH_PLATFORM') 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', ]; } } Toolbar.php 0000644 00000032171 15172656140 0006672 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('JPATH_PLATFORM') 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 */ 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') { if (empty(self::$instances[$name])) { self::$instances[$name] = Factory::getContainer()->get(ToolbarFactoryInterface::class)->createToolbar($name); } return self::$instances[$name]; } /** * 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 5.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 5.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 = []) { $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 5.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 5.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 ) ); } } Button/PopupButton.php 0000644 00000015561 15172656140 0011046 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('JPATH_PLATFORM') 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(int $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 string getUrl() * @method int getIframeWidth() * @method int getIframeHeight() * @method int getBodyHeight() * @method int getModalWidth() * @method string getOnclose() * @method string getTitle() * @method string getFooter() * @method string getSelector() * @method bool getListCheck() * * @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'] = $options['icon'] ?? 'icon-square'; parent::prepareOptions($options); $options['doTask'] = $this->_getCommand($this->getUrl()); $options['selector'] = $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 ((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 = $url ?? ''; if (strpos($url, 'http') !== 0) { $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', 'onclose', 'title', 'footer', 'selector', 'listCheck', ] ); } } Button/BasicButton.php 0000644 00000002111 15172656140 0010747 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('JPATH_PLATFORM') 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/InlinehelpButton.php 0000644 00000005343 15172656140 0012027 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('JPATH_PLATFORM') 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'] = $options['icon'] ?? 'fa-question-circle'; $options['button_class'] = $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/SeparatorButton.php 0000644 00000001633 15172656140 0011676 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('JPATH_PLATFORM') 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/DropdownButton.php 0000644 00000006705 15172656140 0011537 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('JPATH_PLATFORM') 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(); } } } /** * 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 parent::renderButton($options); } /** * 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 00000006430 15172656140 0010626 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('JPATH_PLATFORM') 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'] = $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/StandardButton.php 0000644 00000007246 15172656140 0011504 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('JPATH_PLATFORM') 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'] = ($options['button_class'] ?? $class); } $options['onclick'] = $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/CustomButton.php 0000644 00000003261 15172656140 0011207 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('JPATH_PLATFORM') 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/LinkButton.php 0000644 00000004131 15172656140 0010627 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('JPATH_PLATFORM') 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/ConfirmButton.php 0000644 00000006035 15172656140 0011334 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('JPATH_PLATFORM') 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/AbstractGroupButton.php 0000644 00000003066 15172656140 0012520 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(); } } ToolbarFactoryInterface.php 0000644 00000002057 15172656140 0012043 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ namespace Joomla\CMS\Toolbar; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Interface for creating toolbar objects * * @since 4.0.0 */ interface ToolbarFactoryInterface { /** * Creates a new toolbar button. * * @param Toolbar $toolbar The Toolbar instance to attach to the button * @param string $type Button Type * * @return ToolbarButton * * @since 4.0.0 * @throws \InvalidArgumentException */ public function createButton(Toolbar $toolbar, string $type): ToolbarButton; /** * Creates a new Toolbar object. * * @param string $name The toolbar name. * * @return Toolbar * * @since 4.0.0 */ public function createToolbar(string $name = 'toolbar'): Toolbar; } ContainerAwareToolbarFactory.php 0000644 00000006506 15172656140 0013050 0 ustar 00 <?php /** * Joomla! Content Management System * * @copyright (C) 2017 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\Filesystem\Path; use Joomla\CMS\Filter\InputFilter; use Joomla\CMS\Language\Text; use Joomla\CMS\Log\Log; use Joomla\DI\ContainerAwareInterface; use Joomla\DI\ContainerAwareTrait; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Default factory for creating toolbar objects * * @since 4.0.0 */ class ContainerAwareToolbarFactory implements ToolbarFactoryInterface, ContainerAwareInterface { use ContainerAwareTrait; /** * Creates a new toolbar button. * * @param Toolbar $toolbar The Toolbar instance to attach to the button * @param string $type Button Type * * @return ToolbarButton * * @since 3.8.0 * @throws \InvalidArgumentException */ public function createButton(Toolbar $toolbar, string $type): ToolbarButton { $normalisedType = ucfirst($type); $buttonClass = $this->loadButtonClass($normalisedType); if (!$buttonClass) { $dirs = $toolbar->getButtonPath(); $file = InputFilter::getInstance()->clean(str_replace('_', DIRECTORY_SEPARATOR, strtolower($type)) . '.php', 'path'); if ($buttonFile = Path::find($dirs, $file)) { include_once $buttonFile; } else { Log::add(Text::sprintf('JLIB_HTML_BUTTON_NO_LOAD', $buttonClass, $buttonFile), Log::WARNING, 'jerror'); throw new \InvalidArgumentException(Text::sprintf('JLIB_HTML_BUTTON_NO_LOAD', $buttonClass, $buttonFile)); } } if (!class_exists($buttonClass)) { throw new \InvalidArgumentException(sprintf('Class `%1$s` does not exist, could not create a toolbar button.', $buttonClass)); } // Check for a possible service from the container otherwise manually instantiate the class if ($this->getContainer()->has($buttonClass)) { return $this->getContainer()->get($buttonClass); } /** @var ToolbarButton $button */ $button = new $buttonClass($normalisedType); return $button->setParent($toolbar); } /** * Creates a new Toolbar object. * * @param string $name The toolbar name. * * @return Toolbar * * @since 4.0.0 */ public function createToolbar(string $name = 'toolbar'): Toolbar { return new Toolbar($name, $this); } /** * Load the button class including the deprecated ones. * * @param string $type Button Type (normalized) * * @return string|null * * @since 4.0.0 */ private function loadButtonClass(string $type) { $buttonClasses = [ 'Joomla\\CMS\\Toolbar\\Button\\' . $type . 'Button', /** * @deprecated 4.3 will be removed in 6.0 */ 'JToolbarButton' . $type, ]; foreach ($buttonClasses as $buttonClass) { if (!class_exists($buttonClass)) { continue; } return $buttonClass; } return null; } } CoreButtonsTrait.php 0000644 00000040302 15172656140 0010536 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; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\FileLayout; use Joomla\CMS\Toolbar\Button\ConfirmButton; use Joomla\CMS\Toolbar\Button\CustomButton; 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; use Joomla\CMS\Uri\Uri; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects /** * Enhance Toolbar class to add more pre-defined methods. * * @since 4.0.0 */ trait CoreButtonsTrait { /** * Writes a divider between dropdown menu items. * * @param string $text The text of button. * * @return SeparatorButton * * @since 4.0.0 */ public function divider(string $text = ''): SeparatorButton { return $this->separatorButton('divider', $text); } /** * Writes a preview button for a given option (opens a popup window). * * @param string $url The name of the popup file (excluding the file extension) * @param string $text The text of button. * @param bool $newWindow Whether to open the preview in _blank or just a modal * * @return PopupButton|LinkButton * * @since 4.0.0 */ public function preview(string $url, string $text = 'JGLOBAL_PREVIEW', $newWindow = false) { if ($newWindow === true) { $button = $this->linkButton('link', $text) ->url($url) ->attributes(['target' => '_blank']) ->icon('icon-eye'); } else { $button = $this->popupButton('preview', $text) ->url($url) ->iframeWidth(640) ->iframeHeight(480) ->icon('icon-eye'); } return $button; } /** * Writes a jooa11y accessibility checker button for a given option (opens a popup window). * * @param string $url The url to open * @param string $text The text of button. * @param bool $newWindow Whether to open the preview in _blank or just a modal * * @return PopupButton|LinkButton * * @since 4.1.0 */ public function jooa11y(string $url, string $text = 'JGLOBAL_JOOA11Y', $newWindow = false) { if ($newWindow === true) { $button = $this->linkButton('jooa11y-link', $text) ->url($url) ->attributes(['target' => '_blank']) ->icon('icon-universal-access'); } else { $button = $this->popupButton('jooa11y-preview', $text) ->url($url) ->iframeWidth(640) ->iframeHeight(480) ->icon('icon-universal-access'); } return $button; } /** * Writes a help button for a given option (opens a popup window). * * @param string $ref The name of the popup file (excluding the file extension for an xml file). * @param bool $useComponent Use the help file in the component directory. * @param string $url Use this URL instead of any other. * @param string $component Name of component to get Help (null for current component) * * @return HelpButton * * @since 4.0.0 */ public function help($ref, $useComponent = false, $url = null, $component = null): HelpButton { return $this->helpButton('help', 'JTOOLBAR_HELP') ->ref($ref) ->useComponent($useComponent) ->url($url) ->component($component); } /** * Writes a help button for a given option (opens a popup window). * * @param string $class The class used by the inline help items. * * @return InlinehelpButton * * @since 4.3.0 */ public function inlinehelp(string $class = 'hide-aware-inline-help'): InlinehelpButton { return $this->inlinehelpButton('inlinehelp') ->targetclass($class) ->icon('fa fa-question-circle'); } /** * Writes a cancel button that will go back to the previous page without doing * any other operation. * * @param string $text The text of button. * * @return LinkButton * * @since 4.0.0 */ public function back(string $text = 'JTOOLBAR_BACK'): LinkButton { return $this->link('back', $text) ->url('javascript:history.back();'); } /** * Creates a button to redirect to a link. * * @param string $text Button text. * @param string $url The link url. * * @return LinkButton * * @since 4.0.0 */ public function link(string $text, string $url): LinkButton { return $this->linkButton('link', $text) ->url($url); } /** * Writes a media_manager button. * * @param string $directory The subdirectory to upload the media to. * @param string $text An override for the alt text. * * @return PopupButton * * @since 4.0.0 */ public function mediaManager(string $directory, string $text = 'JTOOLBAR_UPLOAD'): PopupButton { return $this->popupButton('upload', $text) ->iframeWidth(800) ->iframeHeight(520) ->url('index.php?option=com_media&tmpl=component&task=popupUpload&folder=' . $directory); } /** * Writes a common 'default' button for a record. * * @param string $task An override for the task. * @param string $text An override for the alt text. * * @return StandardButton * * @since 4.0.0 */ public function makeDefault(string $task, string $text = 'JTOOLBAR_DEFAULT'): StandardButton { return $this->standardButton('default', $text, $task); } /** * Writes a common 'assign' button for a record. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function assign(string $task, string $text = 'JTOOLBAR_ASSIGN'): StandardButton { return $this->standardButton('assign', $text, $task); } /** * Writes the common 'new' icon for the button bar. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function addNew(string $task, string $text = 'JTOOLBAR_NEW'): StandardButton { return $this->standardButton('new', $text, $task); } /** * Writes a common 'publish' button. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function publish(string $task, string $text = 'JTOOLBAR_PUBLISH'): StandardButton { return $this->standardButton('publish', $text, $task); } /** * Writes a common 'unpublish' button. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function unpublish(string $task, string $text = 'JTOOLBAR_UNPUBLISH'): StandardButton { return $this->standardButton('unpublish', $text, $task); } /** * Writes a common 'archive' button. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function archive(string $task, string $text = 'JTOOLBAR_ARCHIVE'): StandardButton { return $this->standardButton('archive', $text, $task); } /** * Writes a common 'unarchive' button. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function unarchive(string $task, string $text = 'JTOOLBAR_UNARCHIVE'): StandardButton { return $this->standardButton('unarchive', $text, $task); } /** * Writes a common 'edit' button. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function edit(string $task, string $text = 'JTOOLBAR_EDIT'): StandardButton { return $this->standardButton('edit', $text, $task); } /** * Writes a common 'editHtml' button. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function editHtml(string $task, string $text = 'JTOOLBAR_EDIT_HTML'): StandardButton { return $this->standardButton('edithtml', $text, $task); } /** * Writes a common 'editCss' button. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function editCss(string $task, string $text = 'JTOOLBAR_EDIT_CSS'): StandardButton { return $this->standardButton('editcss', $text, $task); } /** * Writes a common 'delete' button. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return ConfirmButton * * @since 4.0.0 */ public function delete(string $task, string $text = 'JTOOLBAR_DELETE'): ConfirmButton { return $this->confirmButton('delete', $text, $task); } /** * Writes a common 'trash' button. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function trash(string $task, string $text = 'JTOOLBAR_TRASH'): StandardButton { return $this->standardButton('trash', $text, $task); } /** * Writes a save button for a given option. * Apply operation leads to a save action only (does not leave edit mode). * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function apply(string $task, string $text = 'JTOOLBAR_APPLY'): StandardButton { return $this->standardButton('apply', $text, $task) ->formValidation(true); } /** * Writes a save button for a given option. * Save operation leads to a save and then close action. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function save(string $task, string $text = 'JTOOLBAR_SAVE'): StandardButton { return $this->standardButton('save', $text, $task) ->formValidation(true); } /** * Writes a save and create new button for a given option. * Save and create operation leads to a save and then add action. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function save2new(string $task, string $text = 'JTOOLBAR_SAVE_AND_NEW'): StandardButton { return $this->standardButton('save-new', $text, $task) ->formValidation(true); } /** * Writes a save as copy button for a given option. * Save as copy operation leads to a save after clearing the key, * then returns user to edit mode with new key. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function save2copy(string $task, string $text = 'JTOOLBAR_SAVE_AS_COPY'): StandardButton { return $this->standardButton('save-copy', $text, $task) ->formValidation(true); } /** * Writes a checkin button for a given option. * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function checkin(string $task, string $text = 'JTOOLBAR_CHECKIN'): StandardButton { return $this->standardButton('checkin', $text, $task) ->listCheck(true); } /** * Writes a cancel button and invokes a cancel operation (eg a checkin). * * @param string $task The task name of this button. * @param string $text The text of this button. * * @return StandardButton * * @since 4.0.0 */ public function cancel(string $task, string $text = 'JTOOLBAR_CLOSE'): StandardButton { return $this->standardButton('cancel', $text, $task); } /** * Writes a configuration button and invokes a cancel operation (eg a checkin). * * @param string $component The name of the component, eg, com_content. * @param string $text The text of this button. * @param string $path An alternative path for the configuration xml relative to JPATH_SITE. * * @return LinkButton * * @since 4.0.0 */ public function preferences(string $component, string $text = 'JTOOLBAR_OPTIONS', string $path = ''): LinkButton { $component = urlencode($component); $path = urlencode($path); $uri = (string) Uri::getInstance(); $return = urlencode(base64_encode($uri)); return $this->linkButton('options', $text) ->url('index.php?option=com_config&view=component&component=' . $component . '&path=' . $path . '&return=' . $return); } /** * Writes a version history * * @param string $typeAlias The component and type, for example 'com_content.article' * @param integer $itemId The id of the item, for example the article id. * @param integer $height The height of the popup. * @param integer $width The width of the popup. * @param string $text The name of the button. * * @return CustomButton * * @since 4.0.0 */ public function versions( string $typeAlias, int $itemId, int $height = 800, int $width = 500, string $text = 'JTOOLBAR_VERSIONS' ): CustomButton { $lang = Factory::getLanguage(); $lang->load('com_contenthistory', JPATH_ADMINISTRATOR, $lang->getTag(), true); // Options array for Layout $options = []; $options['title'] = Text::_($text); $options['height'] = $height; $options['width'] = $width; $options['itemId'] = $typeAlias . '.' . $itemId; $layout = new FileLayout('joomla.toolbar.versions'); return $this->customHtml($layout->render($options), 'version'); } /** * Writes a custom HTML to toolbar. * * @param string $html The HTML string to write. * @param string $name The button name. * * @return CustomButton * * @since 4.0.0 */ public function customHtml(string $html, string $name = 'custom'): CustomButton { return $this->customButton($name) ->html($html); } }
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings