| Current Path : /proc/1908984/root/proc/2603263/cwd/ |
| Current File : //proc/1908984/root/proc/2603263/cwd/Toolbar.tar |
Exception/MissingAttribute.php 0000644 00000001053 15234512466 0012517 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Toolbar\Exception;
use Exception;
defined('_JEXEC') or die;
class MissingAttribute extends \InvalidArgumentException
{
public function __construct($missingArgument, $buttonType, $code = 500, Exception $previous = null)
{
$message = \JText::sprintf('LIB_FOF_TOOLBAR_ERR_MISSINGARGUMENT', $missingArgument, $buttonType);
parent::__construct($message, $code, $previous);
}
}
Exception/UnknownButtonType.php 0000644 00000001012 15234512466 0012712 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Toolbar\Exception;
use Exception;
defined('_JEXEC') or die;
class UnknownButtonType extends \InvalidArgumentException
{
public function __construct($buttonType, $code = 500, Exception $previous = null)
{
$message = \JText::sprintf('LIB_FOF_TOOLBAR_ERR_UNKNOWNBUTTONTYPE', $buttonType);
parent::__construct($message, $code, $previous);
}
}
Toolbar.php 0000644 00000076307 15234512466 0006704 0 ustar 00 <?php
/**
* @package FOF
* @copyright Copyright (c)2010-2019 Nicholas K. Dionysopoulos / Akeeba Ltd
* @license GNU GPL version 2 or later
*/
namespace FOF30\Toolbar;
use FOF30\Container\Container;
use FOF30\Controller\Controller;
use FOF30\Toolbar\Exception\MissingAttribute;
use FOF30\Toolbar\Exception\UnknownButtonType;
use FOF30\Utils\StringHelper;
use FOF30\View\DataView\DataViewInterface;
use FOF30\View\View;
use Joomla\Utilities\ArrayHelper;
use JText;
use JToolBarHelper;
defined('_JEXEC') or die;
/**
* The Toolbar class renders the back-end component title area and the back-
* and front-end toolbars.
*
* @since 1.0
*/
class Toolbar
{
/** @var Container Component container */
protected $container = null;
/** @var array Permissions map, see the __construct method for more information */
public $perms = array();
/** @var array The links to be rendered in the toolbar */
protected $linkbar = array();
/** @var bool Should I render the submenu in the front-end? */
protected $renderFrontendSubmenu = false;
/** @var bool Should I render buttons in the front-end? */
protected $renderFrontendButtons = false;
/** @var bool Should I use the configuration file (fof.xml) of the component? */
protected $useConfigurationFile = false;
/** @var null|bool Are we rendering a data-aware view? */
protected $isDataView = null;
/**
* Public constructor.
*
* The $config array can contain the following optional values:
*
* renderFrontendButtons bool Should I render buttons in the front-end of the component?
* renderFrontendSubmenu bool Should I render the submenu in the front-end of the component?
* useConfigurationFile bool Should we use the configuration file (fof.xml) of the component?
*
* @param Container $c The container for the component
* @param array $config The configuration overrides, see above
*/
public function __construct(Container $c, array $config = array())
{
// Store the container reference in this object
$this->container = $c;
// Get a reference to some useful objects
$input = $this->container->input;
$platform = $this->container->platform;
// Get default permissions (can be overriden by the view)
$perms = (object)array(
'manage' => $this->container->platform->authorise('core.manage', $input->getCmd('option', 'com_foobar')),
'create' => $this->container->platform->authorise('core.create', $input->getCmd('option', 'com_foobar')),
'edit' => $this->container->platform->authorise('core.edit', $input->getCmd('option', 'com_foobar')),
'editstate' => $this->container->platform->authorise('core.edit.state', $input->getCmd('option', 'com_foobar')),
'delete' => $this->container->platform->authorise('core.delete', $input->getCmd('option', 'com_foobar')),
);
// Save front-end toolbar and submenu rendering flags if present in the config
if (array_key_exists('renderFrontendButtons', $config))
{
$this->renderFrontendButtons = $config['renderFrontendButtons'];
}
if (array_key_exists('renderFrontendSubmenu', $config))
{
$this->renderFrontendSubmenu = $config['renderFrontendSubmenu'];
}
// If not in the administrative area, load the JToolbarHelper
if (!$platform->isBackend())
{
// Needed for tests, so we can inject our "special" helper class
if (!class_exists('\\JToolbarHelper'))
{
$platformDirs = $platform->getPlatformBaseDirs();
$path = $platformDirs['root'] . '/administrator/includes/toolbar.php';
require_once $path;
}
// Things to do if we have to render a front-end toolbar
if ($this->renderFrontendButtons)
{
// Load back-end toolbar language files in front-end
$platform->loadTranslations('');
// Needed for tests (we can fake we're not in the backend, but we are still in CLI!)
if (!$platform->isCli())
{
// Load the core Javascript
\JHtml::_('behavior.core');
\JHtml::_('jquery.framework', true);
}
}
}
// Store permissions in the local toolbar object
$this->perms = $perms;
}
/**
* Renders the toolbar for the current view and task
*
* @param string $view The view of the component
* @param string $task The exact task of the view
*
* @return void
*/
public function renderToolbar($view = null, $task = null)
{
$input = $this->container->input;
// If tmpl=component the default behaviour is to not render the toolbar
if ($input->getCmd('tmpl', '') == 'component')
{
$render_toolbar = false;
}
else
{
$render_toolbar = true;
}
// If there is a render_toolbar=0 in the URL, do not render a toolbar
$render_toolbar = $input->getBool('render_toolbar', $render_toolbar);
if (!$render_toolbar)
{
return;
}
// Get the view and task
$controller = $this->container->dispatcher->getController();
$autoDetectedView = 'cpanel';
$autoDetectedTask = 'main';
if (is_object($controller) && ($controller instanceof Controller))
{
$autoDetectedView = $controller->getName();
$autoDetectedTask = $controller->getTask();
}
if (empty($view))
{
$view = $input->getCmd('view', $autoDetectedView);
}
if (empty($task))
{
$task = $input->getCmd('task', $autoDetectedTask);
}
// If there is a fof.xml toolbar configuration use it and return
$view = $this->container->inflector->pluralize($view);
$toolbarConfig = $this->container->appConfig->get('views.' . ucfirst($view) . '.toolbar.' . $task);
$oldValues = array(
'renderFrontendButtons' => $this->renderFrontendButtons,
'renderFrontendSubmenu' => $this->renderFrontendSubmenu,
'useConfigurationFile' => $this->useConfigurationFile,
);
$newValues = array(
'renderFrontendButtons' => $this->container->appConfig->get(
'views.' . ucfirst($view) . '.config.renderFrontendButtons',
$oldValues['renderFrontendButtons']
),
'renderFrontendSubmenu' => $this->container->appConfig->get(
'views.' . ucfirst($view) . '.config.renderFrontendSubmenu',
$oldValues['renderFrontendSubmenu']
),
'useConfigurationFile' => $this->container->appConfig->get(
'views.' . ucfirst($view) . '.config.useConfigurationFile',
$oldValues['useConfigurationFile']
),
);
foreach ($newValues as $k => $v)
{
$this->$k = $v;
}
if (!empty($toolbarConfig) && $this->useConfigurationFile)
{
$this->renderFromConfig($toolbarConfig);
return;
}
// Check for an onViewTask method
$methodName = 'on' . ucfirst($view) . ucfirst($task);
if (method_exists($this, $methodName))
{
$this->$methodName();
return;
}
// Check for an onView method
$methodName = 'on' . ucfirst($view);
if (method_exists($this, $methodName))
{
$this->$methodName();
return;
}
// Check for an onTask method
$methodName = 'on' . ucfirst($task);
if (method_exists($this, $methodName))
{
$this->$methodName();
return;
}
}
/**
* Renders the toolbar for the component's Control Panel page
*
* @return void
*/
public function onCpanelsBrowse()
{
if ($this->container->platform->isBackend() || $this->renderFrontendSubmenu)
{
$this->renderSubmenu();
}
if (!$this->container->platform->isBackend() && !$this->renderFrontendButtons)
{
return;
}
$option = $this->container->componentName;
JToolBarHelper::title(JText::_(strtoupper($option)), str_replace('com_', '', $option));
if (!$this->isDataView())
{
return;
}
JToolBarHelper::preferences($option);
}
/**
* Renders the toolbar for the component's Browse pages (the plural views)
*
* @return void
*/
public function onBrowse()
{
// On frontend, buttons must be added specifically
if ($this->container->platform->isBackend() || $this->renderFrontendSubmenu)
{
$this->renderSubmenu();
}
if (!$this->container->platform->isBackend() && !$this->renderFrontendButtons)
{
return;
}
// Setup
$option = $this->container->componentName;
$view = $this->container->input->getCmd('view', 'cpanel');
// Set toolbar title
$subtitle_key = strtoupper($option . '_TITLE_' . $view);
JToolBarHelper::title(JText::_(strtoupper($option)) . ': ' . JText::_($subtitle_key), str_replace('com_', '', $option));
if (!$this->isDataView())
{
return;
}
// Add toolbar buttons
if ($this->perms->create)
{
JToolBarHelper::addNew();
}
if ($this->perms->edit)
{
JToolBarHelper::editList();
}
if ($this->perms->create || $this->perms->edit)
{
JToolBarHelper::divider();
}
// Published buttons are only added if there is a enabled field in the table
try
{
$model = $this->container->factory->model($view);
if ($model->hasField('enabled') && $this->perms->editstate)
{
JToolBarHelper::publishList();
JToolBarHelper::unpublishList();
JToolBarHelper::divider();
}
}
catch (\Exception $e)
{
// Yeah. Let's not add the buttons if we can't load the model...
}
if ($this->perms->delete)
{
$msg = JText::_($option . '_CONFIRM_DELETE');
JToolBarHelper::deleteList(strtoupper($msg));
}
// A Check-In button is only added if there is a locked_on field in the table
try
{
$model = $this->container->factory->model($view);
if ($model->hasField('locked_on') && $this->perms->edit)
{
JToolBarHelper::checkin();
}
}
catch (\Exception $e)
{
// Yeah. Let's not add the button if we can't load the model...
}
}
/**
* Renders the toolbar for the component's Read pages
*
* @return void
*/
public function onRead()
{
// On frontend, buttons must be added specifically
if ($this->container->platform->isBackend() || $this->renderFrontendSubmenu)
{
$this->renderSubmenu();
}
if (!$this->container->platform->isBackend() && !$this->renderFrontendButtons)
{
return;
}
$option = $this->container->componentName;
$componentName = str_replace('com_', '', $option);
$view = $this->container->input->getCmd('view', 'cpanel');
// Set toolbar title
$subtitle_key = strtoupper($option . '_TITLE_' . $view . '_READ');
JToolBarHelper::title(JText::_(strtoupper($option)) . ': ' . JText::_($subtitle_key), $componentName);
if (!$this->isDataView())
{
return;
}
// Set toolbar icons
JToolBarHelper::back();
}
/**
* Renders the toolbar for the component's Add pages
*
* @return void
*/
public function onAdd()
{
// On frontend, buttons must be added specifically
if (!$this->container->platform->isBackend() && !$this->renderFrontendButtons)
{
return;
}
$option = $this->container->componentName;
$componentName = str_replace('com_', '', $option);
$view = $this->container->input->getCmd('view', 'cpanel');
// Set toolbar title
$subtitle_key = strtoupper($option . '_TITLE_' . $this->container->inflector->pluralize($view)) . '_EDIT';
JToolBarHelper::title(JText::_(strtoupper($option)) . ': ' . JText::_($subtitle_key), $componentName);
if (!$this->isDataView())
{
return;
}
// Set toolbar icons
if ($this->perms->edit || $this->perms->editown)
{
// Show the apply button only if I can edit the record, otherwise I'll return to the edit form and get a
// 403 error since I can't do that
JToolBarHelper::apply();
}
JToolBarHelper::save();
if ($this->perms->create)
{
JToolBarHelper::custom('savenew', 'save-new.png', 'save-new_f2.png', 'JTOOLBAR_SAVE_AND_NEW', false);
}
JToolBarHelper::cancel();
}
/**
* Renders the toolbar for the component's Edit pages
*
* @return void
*/
public function onEdit()
{
// On frontend, buttons must be added specifically
if (!$this->container->platform->isBackend() && !$this->renderFrontendButtons)
{
return;
}
$this->onAdd();
}
/**
* Removes all links from the link bar
*
* @return void
*/
public function clearLinks()
{
$this->linkbar = array();
}
/**
* Get the link bar's link definitions
*
* @return array
*/
public function &getLinks()
{
return $this->linkbar;
}
/**
* Append a link to the link bar
*
* @param string $name The text of the link
* @param string|null $link The link to render; set to null to render a separator
* @param boolean $active True if it's an active link
* @param string|null $icon Icon class (used by some renderers, like the Bootstrap renderer)
* @param string|null $parent The parent element (referenced by name)) Thsi will create a dropdown list
*
* @return void
*/
public function appendLink($name, $link = null, $active = false, $icon = null, $parent = '')
{
$linkDefinition = array(
'name' => $name,
'link' => $link,
'active' => $active,
'icon' => $icon
);
if (empty($parent))
{
if (array_key_exists($name, $this->linkbar))
{
$this->linkbar[$name] = array_merge($this->linkbar[$name], $linkDefinition);
// If there already are some children, I have to put this view link in the "items" array in the first place
if (array_key_exists('items', $this->linkbar[$name]))
{
array_unshift($this->linkbar[$name]['items'], $linkDefinition);
}
}
else
{
$this->linkbar[$name] = $linkDefinition;
}
}
else
{
if (!array_key_exists($parent, $this->linkbar))
{
$parentElement = $linkDefinition;
$parentElement['name'] = $parent;
$parentElement['link'] = null;
$this->linkbar[$parent] = $parentElement;
$parentElement['items'] = array();
}
else
{
$parentElement = $this->linkbar[$parent];
if (!array_key_exists('dropdown', $parentElement) && !empty($parentElement['link']))
{
$newSubElement = $parentElement;
$parentElement['items'] = array($newSubElement);
}
}
$parentElement['items'][] = $linkDefinition;
$parentElement['dropdown'] = true;
if ($active)
{
$parentElement['active'] = true;
}
$this->linkbar[$parent] = $parentElement;
}
}
/**
* Prefixes (some people erroneously call this "prepend" – there is no such word) a link to the link bar
*
* @param string $name The text of the link
* @param string|null $link The link to render; set to null to render a separator
* @param boolean $active True if it's an active link
* @param string|null $icon Icon class (used by some renderers, like the Bootstrap renderer)
*
* @return void
*/
public function prefixLink($name, $link = null, $active = false, $icon = null)
{
$linkDefinition = array(
'name' => $name,
'link' => $link,
'active' => $active,
'icon' => $icon
);
array_unshift($this->linkbar, $linkDefinition);
}
/**
* Renders the submenu (toolbar links) for all detected views of this component
*
* @return void
*/
public function renderSubmenu()
{
$views = $this->getMyViews();
if (empty($views))
{
return;
}
$activeView = $this->container->input->getCmd('view', 'cpanel');
foreach ($views as $view)
{
// Get the view name
$key = strtoupper($this->container->componentName) . '_TITLE_' . strtoupper($view);
//Do we have a translation for this key?
if (strtoupper(JText::_($key)) == $key)
{
$altview = $this->container->inflector->isPlural($view) ? $this->container->inflector->singularize($view) : $this->container->inflector->pluralize($view);
$key2 = strtoupper($this->container->componentName) . '_TITLE_' . strtoupper($altview);
// Maybe we have for the alternative view?
if (strtoupper(JText::_($key2)) == $key2)
{
// Nope, let's use the raw name
$name = ucfirst($view);
}
else
{
$name = JText::_($key2);
}
}
else
{
$name = JText::_($key);
}
$link = 'index.php?option=' . $this->container->componentName . '&view=' . $view;
$active = $view == $activeView;
$this->appendLink($name, $link, $active);
}
}
/**
* Automatically detects all views of the component
*
* @return array A list of all views, in the order to be displayed in the toolbar submenu
*/
protected function getMyViews()
{
$t_views = array();
$using_meta = false;
$componentPaths = $this->container->platform->getComponentBaseDirs($this->container->componentName);
$searchPath = $componentPaths['main'] . '/View';
$filesystem = $this->container->filesystem;
$allFolders = $filesystem->folderFolders($searchPath);
if (!empty($allFolders))
{
foreach ($allFolders as $folder)
{
$view = $folder;
// View already added
if (in_array($this->container->inflector->pluralize($view), $t_views))
{
continue;
}
// Do we have a 'skip.xml' file in there?
$files = $filesystem->folderFiles($searchPath . '/' . $view, '^skip\.xml$');
if (!empty($files))
{
continue;
}
// Do we have extra information about this view? (ie. ordering)
$meta = $filesystem->folderFiles($searchPath . '/' . $view, '^metadata\.xml$');
// Not found, do we have it inside the plural one?
if (!$meta)
{
$plural = $this->container->inflector->pluralize($view);
if (in_array($plural, $allFolders))
{
$view = $plural;
$meta = $filesystem->folderFiles($searchPath . '/' . $view, '^metadata\.xml$');
}
}
if (!empty($meta))
{
$using_meta = true;
$xml = simplexml_load_file($searchPath . '/' . $view . '/' . $meta[0]);
$order = (int)$xml->foflib->ordering;
}
else
{
// Next place. It's ok since the index are 0-based and count is 1-based
if (!isset($to_order))
{
$to_order = array();
}
$order = count($to_order);
}
$view = $this->container->inflector->pluralize($view);
$t_view = new \stdClass;
$t_view->ordering = $order;
$t_view->view = $view;
$to_order[] = $t_view;
$t_views[] = $view;
}
}
$views = array();
if (!empty($to_order))
{
if (class_exists('JArrayHelper'))
{
\JArrayHelper::sortObjects($to_order, 'ordering');
$views = \JArrayHelper::getColumn($to_order, 'view');
}
else
{
ArrayHelper::sortObjects($to_order, 'ordering');
$views = ArrayHelper::getColumn($to_order, 'view');
}
}
// If not using the metadata file, let's put the cpanel view on top
if (!$using_meta)
{
$cpanel = array_search('cpanels', $views);
if ($cpanel !== false)
{
unset($views[$cpanel]);
array_unshift($views, 'cpanels');
}
}
return $views;
}
/**
* Return the front-end toolbar rendering flag
*
* @return boolean
*/
public function getRenderFrontendButtons()
{
return $this->renderFrontendButtons;
}
/**
* @param boolean $renderFrontendButtons
*/
public function setRenderFrontendButtons($renderFrontendButtons)
{
$this->renderFrontendButtons = $renderFrontendButtons;
}
/**
* Return the front-end submenu rendering flag
*
* @return boolean
*/
public function getRenderFrontendSubmenu()
{
return $this->renderFrontendSubmenu;
}
/**
* @param boolean $renderFrontendSubmenu
*/
public function setRenderFrontendSubmenu($renderFrontendSubmenu)
{
$this->renderFrontendSubmenu = $renderFrontendSubmenu;
}
/**
* Is the view we are rendering the toolbar for a data-aware view?
*
* @return bool
*/
public function isDataView()
{
if (is_null($this->isDataView))
{
$this->isDataView = false;
$controller = $this->container->dispatcher->getController();
$view = null;
if (is_object($controller) && ($controller instanceof Controller))
{
$view = $controller->getView();
}
if (is_object($view) && ($view instanceof View))
{
$this->isDataView = $view instanceof DataViewInterface;
}
}
return $this->isDataView;
}
/**
* Render the toolbar from the configuration.
*
* @param array $toolbar The toolbar definition
*
* @return void
*/
private function renderFromConfig(array $toolbar)
{
$isBackend = $this->container->platform->isBackend();
if ($isBackend || $this->renderFrontendSubmenu)
{
$this->renderSubmenu();
}
if (!$isBackend && !$this->renderFrontendButtons)
{
return;
}
if (!$this->isDataView())
{
return;
}
// Render each element
foreach ($toolbar as $elementType => $elementAttributes)
{
$value = isset($elementAttributes['value']) ? $elementAttributes['value'] : null;
$this->renderToolbarElement($elementType, $value, $elementAttributes);
}
return;
}
/**
* Simplified default rendering without any attributes.
*
* @access protected
* @param array $tasks Array of tasks.
*
* @return void
*/
protected function renderToolbarElements($tasks)
{
foreach($tasks as $task)
$this->renderToolbarElement($task);
}
/**
* Render a toolbar element.
*
* @param string $type The element type.
* @param mixed $value The element value.
* @param array $attributes The element attributes.
*
* @return void
*
* @codeCoverageIgnore
* @throws \InvalidArgumentException
*/
private function renderToolbarElement($type, $value = null, array $attributes = array())
{
switch ($type)
{
case 'title':
$icon = isset($attributes['icon']) ? $attributes['icon'] : 'generic.png';
if (isset($attributes['translate']))
{
$value = JText::_($value);
}
JToolbarHelper::title($value, $icon);
break;
case 'divider':
JToolbarHelper::divider();
break;
case 'custom':
$task = isset($attributes['task']) ? $attributes['task'] : '';
$icon = isset($attributes['icon']) ? $attributes['icon'] : '';
$iconOver = isset($attributes['icon_over']) ? $attributes['icon_over'] : '';
$alt = isset($attributes['alt']) ? $attributes['alt'] : '';
$listSelect = isset($attributes['list_select']) ?
StringHelper::toBool($attributes['list_select']) : true;
JToolbarHelper::custom($task, $icon, $iconOver, $alt, $listSelect);
break;
case 'preview':
$url = isset($attributes['url']) ? $attributes['url'] : '';
$update_editors = isset($attributes['update_editors']) ?
StringHelper::toBool($attributes['update_editors']) : false;
JToolbarHelper::preview($url, $update_editors);
break;
case 'help':
if (!isset($attributes['help']))
{
throw new MissingAttribute('help', 'help');
}
$ref = $attributes['help'];
$com = isset($attributes['com']) ? StringHelper::toBool($attributes['com']) : false;
$override = isset($attributes['override']) ? $attributes['override'] : null;
$component = isset($attributes['component']) ? $attributes['component'] : null;
JToolbarHelper::help($ref, $com, $override, $component);
break;
case 'back':
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_BACK';
$href = isset($attributes['href']) ? $attributes['href'] : 'javascript:history.back();';
JToolbarHelper::back($alt, $href);
break;
case 'media_manager':
$directory = isset($attributes['directory']) ? $attributes['directory'] : '';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UPLOAD';
JToolbarHelper::media_manager($directory, $alt);
break;
case 'assign':
$task = isset($attributes['task']) ? $attributes['task'] : 'assign';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_ASSIGN';
JToolbarHelper::assign($task, $alt);
break;
case 'addNew':
case 'new':
$area = isset($attributes['acl']) ? $attributes['acl'] : 'create';
if ($this->checkACL($area))
{
$task = isset($attributes['task']) ? $attributes['task'] : 'add';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_NEW';
$check = isset($attributes['check']) ?
StringHelper::toBool($attributes['check']) : false;
JToolbarHelper::addNew($task, $alt, $check);
}
break;
case 'copy':
$area = isset($attributes['acl']) ? $attributes['acl'] : 'create';
if ($this->checkACL($area))
{
$task = isset($attributes['task']) ? $attributes['task'] : 'copy';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JLIB_HTML_BATCH_COPY';
$icon = isset($attributes['icon']) ? $attributes['icon'] : 'copy.png';
$iconOver = isset($attributes['iconOver']) ? $attributes['iconOver'] : 'copy_f2.png';
JToolBarHelper::custom($task, $icon, $iconOver, $alt, false);
}
break;
case 'publish':
$area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate';
if ($this->checkACL($area))
{
$task = isset($attributes['task']) ? $attributes['task'] : 'publish';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_PUBLISH';
$check = isset($attributes['check']) ?
StringHelper::toBool($attributes['check']) : false;
JToolbarHelper::publish($task, $alt, $check);
}
break;
case 'publishList':
$area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate';
if ($this->checkACL($area))
{
$task = isset($attributes['task']) ? $attributes['task'] : 'publish';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_PUBLISH';
JToolbarHelper::publishList($task, $alt);
}
break;
case 'unpublish':
$area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate';
if ($this->checkACL($area))
{
$task = isset($attributes['task']) ? $attributes['task'] : 'unpublish';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UNPUBLISH';
$check = isset($attributes['check']) ?
StringHelper::toBool($attributes['check']) : false;
JToolbarHelper::unpublish($task, $alt, $check);
}
break;
case 'unpublishList':
$area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate';
if ($this->checkACL($area))
{
$task = isset($attributes['task']) ? $attributes['task'] : 'unpublish';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UNPUBLISH';
JToolbarHelper::unpublishList($task, $alt);
}
break;
case 'archiveList':
$area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate';
if ($this->checkACL($area))
{
$task = isset($attributes['task']) ? $attributes['task'] : 'archive';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_ARCHIVE';
JToolbarHelper::archiveList($task, $alt);
}
break;
case 'unarchiveList':
$area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate';
if ($this->checkACL($area))
{
$task = isset($attributes['task']) ? $attributes['task'] : 'unarchive';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UNARCHIVE';
JToolbarHelper::unarchiveList($task, $alt);
}
break;
case 'edit':
case 'editList':
$area = isset($attributes['acl']) ? $attributes['acl'] : 'edit';
if ($this->checkACL($area))
{
$task = isset($attributes['task']) ? $attributes['task'] : 'edit';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_EDIT';
JToolbarHelper::editList($task, $alt);
}
break;
case 'editHtml':
$task = isset($attributes['task']) ? $attributes['task'] : 'edit_source';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_EDIT_HTML';
JToolbarHelper::editHtml($task, $alt);
break;
case 'editCss':
$task = isset($attributes['task']) ? $attributes['task'] : 'edit_css';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_EDIT_CSS';
JToolbarHelper::editCss($task, $alt);
break;
case 'deleteList':
case 'delete':
$area = isset($attributes['acl']) ? $attributes['acl'] : 'delete';
if ($this->checkACL($area))
{
$msg = isset($attributes['msg']) ? $attributes['msg'] : '';
$task = isset($attributes['task']) ? $attributes['task'] : 'remove';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_DELETE';
JToolbarHelper::deleteList($msg, $task, $alt);
}
break;
case 'trash':
$area = isset($attributes['acl']) ? $attributes['acl'] : 'editstate';
if ($this->checkACL($area))
{
$task = isset($attributes['task']) ? $attributes['task'] : 'trash';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_TRASH';
$check = isset($attributes['check']) ?
StringHelper::toBool($attributes['check']) : true;
JToolbarHelper::trash($task, $alt, $check);
}
break;
case 'apply':
$task = isset($attributes['task']) ? $attributes['task'] : 'apply';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_APPLY';
JToolbarHelper::apply($task, $alt);
break;
case 'save':
$task = isset($attributes['task']) ? $attributes['task'] : 'save';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE';
JToolbarHelper::save($task, $alt);
break;
case 'savenew':
$task = isset($attributes['task']) ? $attributes['task'] : 'savenew';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE_AND_NEW';
$icon = isset($attributes['icon']) ? $attributes['icon'] : 'save-new.png';
$iconOver = isset($attributes['iconOver']) ? $attributes['iconOver'] : 'save-new_f2.png';
JToolBarHelper::custom($task, $icon, $iconOver, $alt, false);
break;
case 'save2new':
$task = isset($attributes['task']) ? $attributes['task'] : 'save2new';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE_AND_NEW';
JToolbarHelper::save2new($task, $alt);
break;
case 'save2copy':
$task = isset($attributes['task']) ? $attributes['task'] : 'save2copy';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE_AS_COPY';
JToolbarHelper::save2copy($task, $alt);
break;
case 'checkin':
$task = isset($attributes['task']) ? $attributes['task'] : 'checkin';
$alt = isset($attributes['alt']) ? $attributes['alt'] :'JTOOLBAR_CHECKIN';
$check = isset($attributes['check']) ?
StringHelper::toBool($attributes['check']) : true;
JToolbarHelper::checkin($task, $alt, $check);
break;
case 'cancel':
$task = isset($attributes['task']) ? $attributes['task'] : 'cancel';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_CANCEL';
JToolbarHelper::cancel($task, $alt);
break;
case 'preferences':
if (!isset($attributes['component']))
{
throw new MissingAttribute('component', 'preferences');
}
$component = $attributes['component'];
$height = isset($attributes['height']) ? $attributes['height'] : '550';
$width = isset($attributes['width']) ? $attributes['width'] : '875';
$alt = isset($attributes['alt']) ? $attributes['alt'] : 'JToolbar_Options';
$path = isset($attributes['path']) ? $attributes['path'] : '';
JToolbarHelper::preferences($component, $height, $width, $alt, $path);
break;
default:
throw new UnknownButtonType($type);
}
}
/**
* Checks if the current user has enough privileges for the requested ACL privilege of a custom toolbar button.
*
* @param string $area The ACL privilege as set up in the $this->perms object
*
* @return boolean True if the user has the ACL privilege specified
*/
protected function checkACL($area)
{
if (is_bool($area))
{
return $area;
}
if (in_array(strtolower($area), array('false','0','no','403')))
{
return false;
}
if (in_array(strtolower($area), array('true','1','yes')))
{
return true;
}
if (in_array(strtolower($area), array('guest')))
{
return $this->container->platform->getUser()->guest;
}
if (in_array(strtolower($area), array('user')))
{
return !$this->container->platform->getUser()->guest;
}
if (empty($area))
{
return true;
}
if (isset($this->perms->$area))
{
return $this->perms->$area;
}
return false;
}
}
Button/ConfirmButton.php 0000644 00000006131 15234553720 0011330 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;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\Toolbar\ToolbarButton;
/**
* Renders a standard button with a confirm dialog
*
* @since 3.0
*/
class ConfirmButton extends ToolbarButton
{
/**
* Button type
*
* @var string
*/
protected $_name = 'Confirm';
/**
* 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
*/
public function fetchButton($type = 'Confirm', $msg = '', $name = '', $text = '', $task = '', $list = true, $hideMenu = false)
{
// Store all data to the options array for use with JLayout
$options = array();
$options['text'] = \JText::_($text);
$options['msg'] = \JText::_($msg, true);
$options['class'] = $this->fetchIconClass($name);
$options['doTask'] = $this->_getCommand($options['msg'], $name, $task, $list);
// Instantiate a new JLayoutFile instance and render the layout
$layout = new FileLayout('joomla.toolbar.confirm');
return $layout->render($options);
}
/**
* Get the button CSS Id
*
* @param string $type Button type
* @param string $msg Message to display
* @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 Button CSS Id
*
* @since 3.0
*/
public function fetchId($type = 'Confirm', $msg = '', $name = '', $text = '', $task = '', $list = true, $hideMenu = false)
{
return $this->_parent->getName() . '-' . $name;
}
/**
* Get the JavaScript command for the button
*
* @param object $msg The message to display.
* @param string $name Not used.
* @param string $task The task used by the application
* @param boolean $list True is requires a list confirmation.
*
* @return string JavaScript command string
*
* @since 3.0
*/
protected function _getCommand($msg, $name, $task, $list)
{
\JText::script('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST');
$cmd = "if (confirm('" . $msg . "')) { Joomla.submitbutton('" . $task . "'); }";
if ($list)
{
$alert = "alert(Joomla.JText._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST'));";
$cmd = "if (document.adminForm.boxchecked.value == 0) { " . $alert . " } else { " . $cmd . " }";
}
return $cmd;
}
}
Button/CustomButton.php 0000644 00000002326 15234553720 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;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Toolbar\ToolbarButton;
/**
* Renders a custom button
*
* @since 3.0
*/
class CustomButton extends ToolbarButton
{
/**
* Button type
*
* @var string
*/
protected $_name = 'Custom';
/**
* 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
*/
public function fetchButton($type = 'Custom', $html = '', $id = 'custom')
{
return $html;
}
/**
* Get the button CSS Id
*
* @param string $type Not used.
* @param string $html Not used.
* @param string $id The id prefix for the button.
*
* @return string Button CSS Id
*
* @since 3.0
*/
public function fetchId($type = 'Custom', $html = '', $id = 'custom')
{
return $this->_parent->getName() . '-' . $id;
}
}
Button/HelpButton.php 0000644 00000004743 15234553720 0010632 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;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Help\Help;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\Toolbar\ToolbarButton;
/**
* Renders a help popup window button
*
* @since 3.0
*/
class HelpButton extends ToolbarButton
{
/**
* @var string Button type
*/
protected $_name = 'Help';
/**
* 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
*/
public function fetchButton($type = 'Help', $ref = '', $com = false, $override = null, $component = null)
{
// Store all data to the options array for use with JLayout
$options = array();
$options['text'] = \JText::_('JTOOLBAR_HELP');
$options['doTask'] = $this->_getCommand($ref, $com, $override, $component);
// Instantiate a new JLayoutFile instance and render the layout
$layout = new FileLayout('joomla.toolbar.help');
return $layout->render($options);
}
/**
* Get the button id
*
* Redefined from JButton class
*
* @return string Button CSS Id
*
* @since 3.0
*/
public function fetchId()
{
return $this->_parent->getName() . '-help';
}
/**
* Get the JavaScript command for the button
*
* @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 JavaScript command string
*
* @since 3.0
*/
protected function _getCommand($ref, $com, $override, $component)
{
// Get Help URL
$url = Help::createUrl($ref, $com, $override, $component);
$url = json_encode(htmlspecialchars($url, ENT_QUOTES), JSON_HEX_APOS);
$url = substr($url, 1, -1);
$cmd = "Joomla.popupWindow('$url', '" . \JText::_('JHELP', true) . "', 700, 500, 1)";
return $cmd;
}
}
Button/LinkButton.php 0000644 00000003465 15234553720 0010637 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;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\Toolbar\ToolbarButton;
/**
* Renders a link button
*
* @since 3.0
*/
class LinkButton extends ToolbarButton
{
/**
* Button type
* @var string
*/
protected $_name = 'Link';
/**
* 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
*/
public function fetchButton($type = 'Link', $name = 'back', $text = '', $url = null)
{
// Store all data to the options array for use with JLayout
$options = array();
$options['text'] = \JText::_($text);
$options['class'] = $this->fetchIconClass($name);
$options['doTask'] = $this->_getCommand($url);
// Instantiate a new JLayoutFile instance and render the layout
$layout = new FileLayout('joomla.toolbar.link');
return $layout->render($options);
}
/**
* Get the button CSS Id
*
* @param string $type The button type.
* @param string $name The name of the button.
*
* @return string Button CSS Id
*
* @since 3.0
*/
public function fetchId($type = 'Link', $name = '')
{
return $this->_parent->getName() . '-' . $name;
}
/**
* Get the JavaScript command for the button
*
* @param object $url Button definition
*
* @return string JavaScript command string
*
* @since 3.0
*/
protected function _getCommand($url)
{
return $url;
}
}
Button/PopupButton.php 0000644 00000006527 15234553720 0011047 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;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\Toolbar\ToolbarButton;
/**
* Renders a modal window button
*
* @since 3.0
*/
class PopupButton extends ToolbarButton
{
/**
* Button type
*
* @var string
*/
protected $_name = 'Popup';
/**
* 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 $width Width of popup
* @param integer $height Height of popup
* @param integer $top Top attribute. [@deprecated Unused, will be removed in 4.0]
* @param integer $left Left attribute. [@deprecated Unused, will be removed in 4.0]
* @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 = '', $width = 640, $height = 480, $top = 0, $left = 0,
$onClose = '', $title = '', $footer = null)
{
// If no $title is set, use the $text element
if ($title === '')
{
$title = $text;
}
// Store all data to the options array for use with JLayout
$options = array();
$options['name'] = $name;
$options['text'] = \JText::_($text);
$options['title'] = \JText::_($title);
$options['class'] = $this->fetchIconClass($name);
$options['doTask'] = $this->_getCommand($url);
// Instantiate a new JLayoutFile instance and render the layout
$layout = new FileLayout('joomla.toolbar.popup');
$html = array();
$html[] = $layout->render($options);
// Place modal div and scripts in a new div
$html[] = '<div class="btn-group" style="width: 0; margin: 0">';
// Build the options array for the modal
$params = array();
$params['title'] = $options['title'];
$params['url'] = $options['doTask'];
$params['height'] = $height;
$params['width'] = $width;
if (isset($footer))
{
$params['footer'] = $footer;
}
$html[] = \JHtml::_('bootstrap.renderModal', 'modal-' . $name, $params);
// If an $onClose event is passed, add it to the modal JS object
if ($onClose !== '')
{
$html[] = '<script>'
. 'jQuery(\'#modal-' . $name . '\').on(\'hide\', function () {' . $onClose . ';});'
. '</script>';
}
$html[] = '</div>';
return implode("\n", $html);
}
/**
* Get the button id
*
* @param string $type Button type
* @param string $name Button name
*
* @return string Button CSS Id
*
* @since 3.0
*/
public function fetchId($type, $name)
{
return $this->_parent->getName() . '-popup-' . $name;
}
/**
* 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)
{
if (strpos($url, 'http') !== 0)
{
$url = \JUri::base() . $url;
}
return $url;
}
}
Button/SeparatorButton.php 0000644 00000002615 15234553720 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;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\Toolbar\ToolbarButton;
/**
* Renders a button separator
*
* @since 3.0
*/
class SeparatorButton extends ToolbarButton
{
/**
* Button type
*
* @var string
*/
protected $_name = 'Separator';
/**
* Get the HTML for a separator in the toolbar
*
* @param array &$definition Class name and custom width
*
* @return string The HTML for the separator
*
* @see ToolbarButton::render()
* @since 3.0
*/
public function render(&$definition)
{
// Store all data to the options array for use with JLayout
$options = array();
// Separator class name
$options['class'] = empty($definition[1]) ? '' : $definition[1];
// Custom width
$options['style'] = empty($definition[2]) ? '' : ' style="width:' . (int) $definition[2] . 'px;"';
// Instantiate a new JLayoutFile instance and render the layout
$layout = new FileLayout('joomla.toolbar.separator');
return $layout->render($options);
}
/**
* Empty implementation (not required for separator)
*
* @return void
*
* @since 3.0
*/
public function fetchButton()
{
}
}
Button/SliderButton.php 0000644 00000004701 15234553720 0011156 0 ustar 00 <?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2012 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;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\Toolbar\ToolbarButton;
/**
* Renders a button to render an HTML element in a slider container
*
* @since 3.0
*/
class SliderButton extends ToolbarButton
{
/**
* Button type
*
* @var string
*/
protected $_name = 'Slider';
/**
* Fetch the HTML for the button
*
* @param string $type Unused string, formerly button type.
* @param string $name Button name
* @param string $text The link text
* @param string $url URL for popup
* @param integer $width Width of popup
* @param integer $height Height of popup
* @param string $onClose JavaScript for the onClose event.
*
* @return string HTML string for the button
*
* @since 3.0
*/
public function fetchButton($type = 'Slider', $name = '', $text = '', $url = '', $width = 640, $height = 480, $onClose = '')
{
\JHtml::_('script', 'jui/cms.js', array('version' => 'auto', 'relative' => true));
// Store all data to the options array for use with JLayout
$options = array();
$options['text'] = \JText::_($text);
$options['name'] = $name;
$options['class'] = $this->fetchIconClass($name);
$options['onClose'] = '';
$doTask = $this->_getCommand($url);
$options['doTask'] = 'Joomla.setcollapse(\'' . $doTask . '\', \'' . $name . '\', \'' . $height . '\');';
if ($onClose)
{
$options['onClose'] = ' rel="{onClose: function() {' . $onClose . '}}"';
}
// Instantiate a new JLayoutFile instance and render the layout
$layout = new FileLayout('joomla.toolbar.slider');
return $layout->render($options);
}
/**
* Get the button id
*
* @param string $type Button type
* @param string $name Button name
*
* @return string Button CSS Id
*
* @since 3.0
*/
public function fetchId($type, $name)
{
return $this->_parent->getName() . '-slider-' . $name;
}
/**
* 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)
{
if (strpos($url, 'http') !== 0)
{
$url = \JUri::base() . $url;
}
return $url;
}
}
Button/StandardButton.php 0000644 00000005663 15234553720 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;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\Toolbar\ToolbarButton;
/**
* Renders a standard button
*
* @since 3.0
*/
class StandardButton extends ToolbarButton
{
/**
* Button type
*
* @var string
*/
protected $_name = 'Standard';
/**
* 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
*
* @return string HTML string for the button
*
* @since 3.0
*/
public function fetchButton($type = 'Standard', $name = '', $text = '', $task = '', $list = true)
{
// Store all data to the options array for use with JLayout
$options = array();
$options['text'] = \JText::_($text);
$options['class'] = $this->fetchIconClass($name);
$options['doTask'] = $this->_getCommand($options['text'], $task, $list);
$options['btnClass'] = 'btn btn-small button-' . $name;
if ($name === 'apply' || $name === 'new')
{
$options['btnClass'] .= ' btn-success';
$options['class'] .= ' icon-white';
}
// Instantiate a new JLayoutFile instance and render the layout
$layout = new FileLayout('joomla.toolbar.standard');
return $layout->render($options);
}
/**
* Get the button CSS Id
*
* @param string $type Unused string.
* @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 Button CSS Id
*
* @since 3.0
*/
public function fetchId($type = 'Standard', $name = '', $text = '', $task = '', $list = true, $hideMenu = false)
{
return $this->_parent->getName() . '-' . $name;
}
/**
* Get the JavaScript command for the button
*
* @param string $name The task name as seen by the user
* @param string $task The task used by the application
* @param boolean $list True is requires a list confirmation.
*
* @return string JavaScript command string
*
* @since 3.0
*/
protected function _getCommand($name, $task, $list)
{
\JText::script('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST');
$cmd = "Joomla.submitbutton('" . $task . "');";
if ($list)
{
$alert = "alert(Joomla.JText._('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST'));";
$cmd = "if (document.adminForm.boxchecked.value == 0) { " . $alert . " } else { " . $cmd . " }";
}
return $cmd;
}
}
ToolbarButton.php 0000644 00000004430 15234553720 0010062 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;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Layout\FileLayout;
/**
* Button base class
*
* The JButton is the base class for all JButton types
*
* @since 3.0
*/
abstract class ToolbarButton
{
/**
* element name
*
* This has to be set in the final renderer classes.
*
* @var string
*/
protected $_name = null;
/**
* reference to the object that instantiated the element
*
* @var \JButton
*/
protected $_parent = null;
/**
* Constructor
*
* @param object $parent The parent
*/
public function __construct($parent = null)
{
$this->_parent = $parent;
}
/**
* Get the element name
*
* @return string type of the parameter
*
* @since 3.0
*/
public function getName()
{
return $this->_name;
}
/**
* Get the HTML to render the button
*
* @param array &$definition Parameters to be passed
*
* @return string
*
* @since 3.0
*/
public function render(&$definition)
{
/*
* Initialise some variables
*/
$id = call_user_func_array(array(&$this, 'fetchId'), $definition);
$action = call_user_func_array(array(&$this, 'fetchButton'), $definition);
// Build id attribute
if ($id)
{
$id = ' id="' . $id . '"';
}
// Build the HTML Button
$options = array();
$options['id'] = $id;
$options['action'] = $action;
$layout = new FileLayout('joomla.toolbar.base');
return $layout->render($options);
}
/**
* 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(array('icon' => $identifier));
}
/**
* Get the button
*
* Defined in the final button class
*
* @return string
*
* @since 3.0
*/
abstract public function fetchButton();
}
ToolbarHelper.php 0000644 00000043473 15234553720 0010040 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;
defined('_JEXEC') or die;
use Joomla\CMS\Layout\FileLayout;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Uri\Uri;
/**
* 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(array('title' => $title, 'icon' => $icon));
$app = Factory::getApplication();
$app->JComponentTitle = $html;
Factory::getDocument()->setTitle(strip_tags($title) . ' - ' . $app->get('sitename') . ' - ' . Text::_('JADMINISTRATION'));
}
/**
* 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 The image to display when moused over.
* @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.
*
* @return void
*
* @since 1.5
*/
public static function custom($task = '', $icon = '', $iconOver = '', $alt = '', $listSelect = true)
{
$bar = Toolbar::getInstance('toolbar');
// Strip extension.
$icon = preg_replace('#\.[^.]*$#', '', $icon);
// Add a standard button.
$bar->appendButton('Standard', $icon, $alt, $task, $listSelect);
}
/**
* 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
*
* @return void
*
* @since 1.5
*/
public static function preview($url = '', $updateEditors = false)
{
$bar = Toolbar::getInstance('toolbar');
// Add a preview button.
$bar->appendButton('Popup', 'preview', 'Preview', $url . '&task=preview');
}
/**
* Writes a preview 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)
{
$bar = Toolbar::getInstance('toolbar');
// Add a help button.
$bar->appendButton('Help', $ref, $com, $override, $component);
}
/**
* 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.
$bar->appendButton('Link', 'back', $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->appendButton('Standard', 'apply', $alt, $task, false);
}
/**
* 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->appendButton('Standard', 'save', $alt, $task, false);
}
/**
* 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->appendButton('Standard', 'save-new', $alt, $task, false);
}
/**
* 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->appendButton('Standard', 'save-copy', $alt, $task, false);
}
/**
* 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 configuation 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);
$contentTypeTable = Table::getInstance('Contenttype');
$typeId = $contentTypeTable->getTypeId($typeAlias);
// Options array for JLayout
$options = array();
$options['title'] = Text::_($alt);
$options['height'] = $height;
$options['width'] = $width;
$options['itemId'] = $itemId;
$options['typeId'] = $typeId;
$options['typeAlias'] = $typeAlias;
$bar = Toolbar::getInstance('toolbar');
$layout = new FileLayout('joomla.toolbar.versions');
$bar->appendButton('Custom', $layout->render($options), 'versions');
}
/**
* 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
*
* @return void
*
* @since 3.2
*/
public static function modal($targetModalId, $icon, $alt)
{
$title = Text::_($alt);
$dhtml = '<button data-toggle="modal" data-target="#' . $targetModalId . '" class="btn btn-small">
<span class="' . $icon . '" title="' . $title . '"></span> ' . $title . '</button>';
$bar = Toolbar::getInstance('toolbar');
$bar->appendButton('Custom', $dhtml, $alt);
}
}