Source for file toolbar.php

Documentation is available at toolbar.php

  1. <?php
  2. /**
  3.  * @package     FrameworkOnFramework
  4.  * @subpackage  toolbar
  5.  * @copyright   Copyright (C) 2010 - 2012 Akeeba Ltd. All rights reserved.
  6.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  7.  */
  8. // Protect from unauthorized access
  9. defined('_JEXEC'or die;
  10.  
  11. /**
  12.  * The Toolbar class renders the back-end component title area and the back-
  13.  * and front-end toolbars.
  14.  *
  15.  * @package  FrameworkOnFramework
  16.  * @since    1.0
  17.  */
  18. class FOFToolbar
  19. {
  20.     /** @var array Configuration parameters */
  21.     protected $config = array();
  22.  
  23.     /** @var array Input (e.g. request) variables */
  24.     protected $input = array();
  25.  
  26.     /** @var array Permissions map, see the __construct method for more information */
  27.     public $perms = array();
  28.  
  29.     /** @var array The links to be rendered in the toolbar */
  30.     protected $linkbar = array();
  31.  
  32.     /** @var bool Should I render the submenu in the front-end? */
  33.     protected $renderFrontendSubmenu = false;
  34.  
  35.     /** @var bool Should I render buttons in the front-end? */
  36.     protected $renderFrontendButtons = false;
  37.  
  38.     /**
  39.      * Gets an instance of a component's toolbar
  40.      *
  41.      * @param   string  $option  The name of the component
  42.      * @param   array   $config  The configuration array for the component
  43.      *
  44.      * @return  FOFToolbar  The toolbar instance for the component
  45.      */
  46.     public static function &getAnInstance($option null$config array())
  47.     {
  48.         static $instances array();
  49.  
  50.         // Make sure $config is an array
  51.         if (is_object($config))
  52.         {
  53.             $config = (array) $config;
  54.         }
  55.         elseif (!is_array($config))
  56.         {
  57.             $config array();
  58.         }
  59.  
  60.         $hash $option;
  61.  
  62.         if (!array_key_exists($hash$instances))
  63.         {
  64.             if (array_key_exists('input'$config))
  65.             {
  66.                 if ($config['input'instanceof FOFInput)
  67.                 {
  68.                     $input $config['input'];
  69.                 }
  70.                 else
  71.                 {
  72.                     $input new FOFInput($config['input']);
  73.                 }
  74.             }
  75.             else
  76.             {
  77.                 $input new FOFInput;
  78.             }
  79.  
  80.             $config['option'!is_null($option$option $input->getCmd('option''com_foobar');
  81.             $input->set('option'$config['option']);
  82.             $config['input'$input;
  83.  
  84.             $className ucfirst(str_replace('com_'''$config['option'])) 'Toolbar';
  85.  
  86.             if (!class_exists($className))
  87.             {
  88.                 $componentPaths FOFPlatform::getInstance()->getComponentBaseDirs($config['option']);
  89.  
  90.                 $searchPaths array(
  91.                     $componentPaths['main'],
  92.                     $componentPaths['main''/toolbars',
  93.                     $componentPaths['alt'],
  94.                     $componentPaths['alt''/toolbars'
  95.                 );
  96.  
  97.                 if (array_key_exists('searchpath'$config))
  98.                 {
  99.                     array_unshift($searchPaths$config['searchpath']);
  100.                 }
  101.  
  102.                 JLoader::import('joomla.filesystem.path');
  103.                 $path JPath::find(
  104.                         $searchPaths'toolbar.php'
  105.                 );
  106.  
  107.                 if ($path)
  108.                 {
  109.                     require_once $path;
  110.                 }
  111.             }
  112.  
  113.             if (!class_exists($className))
  114.             {
  115.                 $className 'FOFToolbar';
  116.             }
  117.  
  118.             $instance new $className($config);
  119.  
  120.             $instances[$hash$instance;
  121.         }
  122.  
  123.         return $instances[$hash];
  124.     }
  125.  
  126.     /**
  127.      * Public cinstructor
  128.      *
  129.      * @param   array  $config  The configuration array of the component
  130.      */
  131.     public function __construct($config array())
  132.     {
  133.         // Make sure $config is an array
  134.         if (is_object($config))
  135.         {
  136.             $config = (array) $config;
  137.         }
  138.         elseif (!is_array($config))
  139.         {
  140.             $config array();
  141.         }
  142.  
  143.         // Cache the config
  144.         $this->config $config;
  145.  
  146.         // Get the input for this MVC triad
  147.         if (array_key_exists('input'$config))
  148.         {
  149.             $this->input $config['input'];
  150.         }
  151.         else
  152.         {
  153.             $this->input new FOFInput;
  154.         }
  155.  
  156.         // Get the default values for the component and view names
  157.         $this->component $this->input->getCmd('option''com_foobar');
  158.  
  159.         // Overrides from the config
  160.  
  161.         if (array_key_exists('option'$config))
  162.         {
  163.             $this->component $config['option'];
  164.         }
  165.  
  166.         $this->input->set('option'$this->component);
  167.  
  168.         // Get default permissions (can be overriden by the view)
  169.         $platform FOFPlatform::getInstance();
  170.         $perms = (object) array(
  171.                 'manage'     => $platform->authorise('core.manage'$this->input->getCmd('option''com_foobar')),
  172.                 'create'     => $platform->authorise('core.create'$this->input->getCmd('option''com_foobar')),
  173.                 'edit'         => $platform->authorise('core.edit'$this->input->getCmd('option''com_foobar')),
  174.                 'editstate'     => $platform->authorise('core.edit.state'$this->input->getCmd('option''com_foobar')),
  175.                 'delete'     => $platform->authorise('core.delete'$this->input->getCmd('option''com_foobar')),
  176.         );
  177.  
  178.         // Save front-end toolbar and submenu rendering flags if present in the config
  179.         if (array_key_exists('renderFrontendButtons'$config))
  180.         {
  181.             $this->renderFrontendButtons $config['renderFrontendButtons'];
  182.         }
  183.  
  184.         if (array_key_exists('renderFrontendSubmenu'$config))
  185.         {
  186.             $this->renderFrontendSubmenu $config['renderFrontendSubmenu'];
  187.         }
  188.  
  189.         // If not in the administrative area, load the JToolbarHelper
  190.         if (!FOFPlatform::getInstance()->isBackend())
  191.         {
  192.             // Pretty ugly require...
  193.             require_once JPATH_ROOT '/administrator/includes/toolbar.php';
  194.  
  195.             // Things to do if we have to render a front-end toolbar
  196.             if ($this->renderFrontendButtons)
  197.             {
  198.                 // Load back-end toolbar language files in front-end
  199.                 FOFPlatform::getInstance()->loadTranslations('');
  200.  
  201.                 // Load the core Javascript
  202.                 JHtml::_('behavior.framework'true);
  203.             }
  204.         }
  205.  
  206.         // Store permissions in the local toolbar object
  207.         $this->perms $perms;
  208.     }
  209.  
  210.     /**
  211.      * Renders the toolbar for the current view and task
  212.      *
  213.      * @param   string    $view   The view of the component
  214.      * @param   string    $task   The exact task of the view
  215.      * @param   FOFInput  $input  An optional input object used to determine the defaults
  216.      *
  217.      * @return  void 
  218.      */
  219.     public function renderToolbar($view null$task null$input null)
  220.     {
  221.         if (!empty($input))
  222.         {
  223.             $saveInput $this->input;
  224.             $this->input $input;
  225.         }
  226.  
  227.         // If tmpl=component the default behaviour is to not render the toolbar
  228.         if ($this->input->getCmd('tmpl'''== 'component')
  229.         {
  230.             $render_toolbar false;
  231.         }
  232.         else
  233.         {
  234.             $render_toolbar true;
  235.         }
  236.  
  237.         // If there is a render_toolbar=0 in the URL, do not render a toolbar
  238.  
  239.         $render_toolbar $this->input->getBool('render_toolbar'$render_toolbar);
  240.  
  241.         if (!$render_toolbar)
  242.         {
  243.             return;
  244.         }
  245.  
  246.         // Get the view and task
  247.  
  248.         if (empty($view))
  249.         {
  250.             $view $this->input->getCmd('view''cpanel');
  251.         }
  252.  
  253.         if (empty($task))
  254.         {
  255.             $task $this->input->getCmd('task''default');
  256.         }
  257.  
  258.         $this->view $view;
  259.         $this->task $task;
  260.         $view FOFInflector::pluralize($view);
  261.         $component $input->get('option''com_foobar''cmd');
  262.  
  263.         $configProvider new FOFConfigProvider;
  264.         $toolbar $configProvider->get(
  265.             $component '.views.' '.toolbar'
  266.         );
  267.  
  268.         // If we have a toolbar config specified
  269.         if (!empty($toolbar))
  270.         {
  271.             return $this->renderFromConfig($toolbar);
  272.         }
  273.  
  274.         // Check for an onViewTask method
  275.         $methodName 'on' ucfirst($viewucfirst($task);
  276.  
  277.         if (method_exists($this$methodName))
  278.         {
  279.             return $this->$methodName();
  280.         }
  281.  
  282.         // Check for an onView method
  283.         $methodName 'on' ucfirst($view);
  284.  
  285.         if (method_exists($this$methodName))
  286.         {
  287.             return $this->$methodName();
  288.         }
  289.  
  290.         // Check for an onTask method
  291.         $methodName 'on' ucfirst($task);
  292.  
  293.         if (method_exists($this$methodName))
  294.         {
  295.             return $this->$methodName();
  296.         }
  297.  
  298.         if (!empty($input))
  299.         {
  300.             $this->input $saveInput;
  301.         }
  302.     }
  303.  
  304.     /**
  305.      * Renders the toolbar for the component's Control Panel page
  306.      *
  307.      * @return  void 
  308.      */
  309.     public function onCpanelsBrowse()
  310.     {
  311.         if (FOFPlatform::getInstance()->isBackend(|| $this->renderFrontendSubmenu)
  312.         {
  313.             $this->renderSubmenu();
  314.         }
  315.  
  316.         if (!FOFPlatform::getInstance()->isBackend(&& !$this->renderFrontendButtons)
  317.         {
  318.             return;
  319.         }
  320.  
  321.         $option $this->input->getCmd('option''com_foobar');
  322.  
  323.         JToolBarHelper::title(JText::_(strtoupper($option))str_replace('com_'''$option));
  324.         JToolBarHelper::preferences($option550875);
  325.     }
  326.  
  327.     /**
  328.      * Renders the toolbar for the component's Browse pages (the plural views)
  329.      *
  330.      * @return  void 
  331.      */
  332.     public function onBrowse()
  333.     {
  334.         // On frontend, buttons must be added specifically
  335.  
  336.         if (FOFPlatform::getInstance()->isBackend(|| $this->renderFrontendSubmenu)
  337.         {
  338.             $this->renderSubmenu();
  339.         }
  340.  
  341.         if (!FOFPlatform::getInstance()->isBackend(&& !$this->renderFrontendButtons)
  342.         {
  343.             return;
  344.         }
  345.  
  346.         // Set toolbar title
  347.         $option $this->input->getCmd('option''com_foobar');
  348.         $subtitle_key strtoupper($option '_TITLE_' $this->input->getCmd('view''cpanel'));
  349.         JToolBarHelper::title(JText::_(strtoupper($option)) ' &ndash; <small>' JText::_($subtitle_key'</small>'str_replace('com_'''$option));
  350.  
  351.         // Add toolbar buttons
  352.  
  353.         if ($this->perms->create)
  354.         {
  355.             if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'))
  356.             {
  357.                 JToolBarHelper::addNew();
  358.             }
  359.             else
  360.             {
  361.                 JToolBarHelper::addNewX();
  362.             }
  363.         }
  364.  
  365.         if ($this->perms->edit)
  366.         {
  367.             if (FOFPlatform::getInstance()->checkVersion(JVERSION'3.0''ge'))
  368.             {
  369.                 JToolBarHelper::editList();
  370.             }
  371.             else
  372.             {
  373.                 JToolBarHelper::editListX();
  374.             }
  375.         }
  376.  
  377.         if ($this->perms->create || $this->perms->edit)
  378.         {
  379.             JToolBarHelper::divider();
  380.         }
  381.  
  382.         if ($this->perms->editstate)
  383.         {
  384.             JToolBarHelper::publishList();
  385.             JToolBarHelper::unpublishList();
  386.             JToolBarHelper::divider();
  387.         }
  388.  
  389.         if ($this->perms->delete)
  390.         {
  391.             $msg JText::_($this->input->getCmd('option''com_foobar''_CONFIRM_DELETE');
  392.             JToolBarHelper::deleteList($msg);
  393.         }
  394.     }
  395.  
  396.     /**
  397.      * Renders the toolbar for the component's Read pages
  398.      *
  399.      * @return  void 
  400.      */
  401.     public function onRead()
  402.     {
  403.         // On frontend, buttons must be added specifically
  404.  
  405.         if (FOFPlatform::getInstance()->isBackend(|| $this->renderFrontendSubmenu)
  406.         {
  407.             $this->renderSubmenu();
  408.         }
  409.  
  410.         if (!FOFPlatform::getInstance()->isBackend(&& !$this->renderFrontendButtons)
  411.         {
  412.             return;
  413.         }
  414.  
  415.         $option $this->input->getCmd('option''com_foobar');
  416.         $componentName str_replace('com_'''$option);
  417.  
  418.         // Set toolbar title
  419.         $subtitle_key strtoupper($option '_TITLE_' $this->input->getCmd('view''cpanel''_READ');
  420.         JToolBarHelper::title(JText::_(strtoupper($option)) ' &ndash; <small>' JText::_($subtitle_key'</small>'$componentName);
  421.  
  422.         // Set toolbar icons
  423.         JToolBarHelper::back();
  424.     }
  425.  
  426.     /**
  427.      * Renders the toolbar for the component's Add pages
  428.      *
  429.      * @return  void 
  430.      */
  431.     public function onAdd()
  432.     {
  433.         // On frontend, buttons must be added specifically
  434.         if (!FOFPlatform::getInstance()->isBackend(&& !$this->renderFrontendButtons)
  435.         {
  436.             return;
  437.         }
  438.  
  439.         $option $this->input->getCmd('option''com_foobar');
  440.         $componentName str_replace('com_'''$option);
  441.  
  442.         // Set toolbar title
  443.         $subtitle_key strtoupper($option '_TITLE_' FOFInflector::pluralize($this->input->getCmd('view''cpanel'))) '_EDIT';
  444.         JToolBarHelper::title(JText::_(strtoupper($option)) ' &ndash; <small>' JText::_($subtitle_key'</small>'$componentName);
  445.  
  446.         // Set toolbar icons
  447.         JToolBarHelper::apply();
  448.         JToolBarHelper::save();
  449.         JToolBarHelper::custom('savenew''save-new.png''save-new_f2.png''JTOOLBAR_SAVE_AND_NEW'false);
  450.         JToolBarHelper::cancel();
  451.     }
  452.  
  453.     /**
  454.      * Renders the toolbar for the component's Edit pages
  455.      *
  456.      * @return  void 
  457.      */
  458.     public function onEdit()
  459.     {
  460.         // On frontend, buttons must be added specifically
  461.         if (!FOFPlatform::getInstance()->isBackend(&& !$this->renderFrontendButtons)
  462.         {
  463.             return;
  464.         }
  465.  
  466.         $this->onAdd();
  467.     }
  468.  
  469.     /**
  470.      * Removes all links from the link bar
  471.      *
  472.      * @return  void 
  473.      */
  474.     public function clearLinks()
  475.     {
  476.         $this->linkbar array();
  477.     }
  478.  
  479.     /**
  480.      * Get the link bar's link definitions
  481.      *
  482.      * @return  array 
  483.      */
  484.     public function &getLinks()
  485.     {
  486.         return $this->linkbar;
  487.     }
  488.  
  489.     /**
  490.      * Append a link to the link bar
  491.      *
  492.      * @param   string       $name    The text of the link
  493.      * @param   string|null $link    The link to render; set to null to render a separator
  494.      * @param   boolean      $active  True if it's an active link
  495.      * @param   string|null $icon    Icon class (used by some renderers, like the Bootstrap renderer)
  496.      * @param   string|null $parent  The parent element (referenced by name)) Thsi will create a dropdown list
  497.      *
  498.      * @return  void 
  499.      */
  500.     public function appendLink($name$link null$active false$icon null$parent '')
  501.     {
  502.         $linkDefinition array(
  503.             'name'     => $name,
  504.             'link'     => $link,
  505.             'active' => $active,
  506.             'icon'     => $icon
  507.         );
  508.  
  509.         if (empty($parent))
  510.         {
  511.             $this->linkbar[$name$linkDefinition;
  512.         }
  513.         else
  514.         {
  515.             if (!array_key_exists($parent$this->linkbar))
  516.             {
  517.                 $parentElement $linkDefinition;
  518.                 $parentElement['link'null;
  519.                 $this->linkbar[$parent$parentElement;
  520.                 $parentElement['items'array();
  521.             }
  522.             else
  523.             {
  524.                 $parentElement $this->linkbar[$parent];
  525.  
  526.                 if (!array_key_exists('dropdown'$parentElement&& !empty($parentElement['link']))
  527.                 {
  528.                     $newSubElement $parentElement;
  529.                     $parentElement['items'array($newSubElement);
  530.                 }
  531.             }
  532.  
  533.             $parentElement['items'][$linkDefinition;
  534.             $parentElement['dropdown'true;
  535.  
  536.             $this->linkbar[$parent$parentElement;
  537.         }
  538.     }
  539.  
  540.     /**
  541.      * Prefixes (some people erroneously call this "prepend" â€“ there is no such word) a link to the link bar
  542.      *
  543.      * @param   string       $name    The text of the link
  544.      * @param   string|null $link    The link to render; set to null to render a separator
  545.      * @param   boolean      $active  True if it's an active link
  546.      * @param   string|null $icon    Icon class (used by some renderers, like the Bootstrap renderer)
  547.      *
  548.      * @return  void 
  549.      */
  550.     public function prefixLink($name$link null$active false$icon null)
  551.     {
  552.         $linkDefinition array(
  553.             'name'     => $name,
  554.             'link'     => $link,
  555.             'active' => $active,
  556.             'icon'     => $icon
  557.         );
  558.         array_unshift($this->linkbar$linkDefinition);
  559.     }
  560.  
  561.     /**
  562.      * Renders the submenu (toolbar links) for all detected views of this component
  563.      *
  564.      * @return  void 
  565.      */
  566.     public function renderSubmenu()
  567.     {
  568.         $views $this->getMyViews();
  569.  
  570.         if (empty($views))
  571.         {
  572.             return;
  573.         }
  574.  
  575.         $activeView $this->input->getCmd('view''cpanel');
  576.  
  577.         foreach ($views as $view)
  578.         {
  579.             // Get the view name
  580.             $key strtoupper($this->component'_TITLE_' strtoupper($view);
  581.  
  582.             if (strtoupper(JText::_($key)) == $key)
  583.             {
  584.                 $altview FOFInflector::isPlural($viewFOFInflector::singularize($viewFOFInflector::pluralize($view);
  585.                 $key2 strtoupper($this->component'_TITLE_' strtoupper($altview);
  586.  
  587.                 if (strtoupper(JText::_($key2)) == $key2)
  588.                 {
  589.                     $name ucfirst($view);
  590.                 }
  591.                 else
  592.                 {
  593.                     $name JText::_($key2);
  594.                 }
  595.             }
  596.             else
  597.             {
  598.                 $name JText::_($key);
  599.             }
  600.  
  601.             $link 'index.php?option=' $this->component '&view=' $view;
  602.  
  603.             $active $view == $activeView;
  604.  
  605.             $this->appendLink($name$link$active);
  606.         }
  607.     }
  608.  
  609.     /**
  610.      * Automatically detects all views of the component
  611.      *
  612.      * @return  array  A list of all views, in the order to be displayed in the toolbar submenu
  613.      */
  614.     protected function getMyViews()
  615.     {
  616.         $views array();
  617.         $t_views array();
  618.         $using_meta false;
  619.  
  620.         $componentPaths FOFPlatform::getInstance()->getComponentBaseDirs($this->component);
  621.         $searchPath $componentPaths['main''/views';
  622.  
  623.         JLoader::import('joomla.filesystem.folder');
  624.         JLoader::import('joomla.utilities.arrayhelper');
  625.  
  626.         $allFolders JFolder::folders($searchPath);
  627.  
  628.         if (!empty($allFolders))
  629.         {
  630.             foreach ($allFolders as $folder)
  631.             {
  632.                 $view $folder;
  633.  
  634.                 // View already added
  635.                 if (in_array(FOFInflector::pluralize($view)$t_views))
  636.                 {
  637.                     continue;
  638.                 }
  639.  
  640.                 // Do we have a 'skip.xml' file in there?
  641.                 $files JFolder::files($searchPath '/' $view'^skip\.xml$');
  642.  
  643.                 if (!empty($files))
  644.                 {
  645.                     continue;
  646.                 }
  647.  
  648.                 // Do we have extra information about this view? (ie. ordering)
  649.                 $meta JFolder::files($searchPath '/' $view'^metadata\.xml$');
  650.  
  651.                 // Not found, do we have it inside the plural one?
  652.                 if (!$meta)
  653.                 {
  654.                     $plural FOFInflector::pluralize($view);
  655.  
  656.                     if (in_array($plural$allFolders))
  657.                     {
  658.                         $view $plural;
  659.                         $meta JFolder::files($searchPath '/' $view'^metadata\.xml$');
  660.                     }
  661.                 }
  662.  
  663.                 if (!empty($meta))
  664.                 {
  665.                     $using_meta true;
  666.                     $xml simplexml_load_file($searchPath '/' $view '/' $meta[0]);
  667.                     $order = (int) $xml->foflib->ordering;
  668.                 }
  669.                 else
  670.                 {
  671.                     // Next place. It's ok since the index are 0-based and count is 1-based
  672.  
  673.                     if (!isset($to_order))
  674.                     {
  675.                         $to_order array();
  676.                     }
  677.  
  678.                     $order count($to_order);
  679.                 }
  680.  
  681.                 $view FOFInflector::pluralize($view);
  682.  
  683.                 $t_view new stdClass;
  684.                 $t_view->ordering = $order;
  685.                 $t_view->view $view;
  686.  
  687.                 $to_order[$t_view;
  688.                 $t_views[$view;
  689.             }
  690.         }
  691.  
  692.         JArrayHelper::sortObjects($to_order'ordering');
  693.         $views JArrayHelper::getColumn($to_order'view');
  694.  
  695.         // If not using the metadata file, let's put the cpanel view on top
  696.         if (!$using_meta)
  697.         {
  698.             $cpanel array_search('cpanels'$views);
  699.  
  700.             if ($cpanel !== false)
  701.             {
  702.                 unset($views[$cpanel]);
  703.                 array_unshift($views'cpanels');
  704.             }
  705.         }
  706.  
  707.         return $views;
  708.     }
  709.  
  710.     /**
  711.      * Return the front-end toolbar rendering flag
  712.      *
  713.      * @return  boolean 
  714.      */
  715.     public function getRenderFrontendButtons()
  716.     {
  717.         return $this->renderFrontendButtons;
  718.     }
  719.  
  720.     /**
  721.      * Return the front-end submenu rendering flag
  722.      *
  723.      * @return  boolean 
  724.      */
  725.     public function getRenderFrontendSubmenu()
  726.     {
  727.         return $this->renderFrontendSubmenu;
  728.     }
  729.  
  730.     /**
  731.      * Render the toolbar from the configuration.
  732.      *
  733.      * @param   array  $toolbar  The toolbar definition
  734.      *
  735.      * @return  void 
  736.      */
  737.     private function renderFromConfig(array $toolbar)
  738.     {
  739.         if (FOFPlatform::getInstance()->isBackend(|| $this->renderFrontendSubmenu)
  740.         {
  741.             $this->renderSubmenu();
  742.         }
  743.  
  744.         if (!FOFPlatform::getInstance()->isBackend(&& !$this->renderFrontendButtons)
  745.         {
  746.             return;
  747.         }
  748.  
  749.         // Render each element
  750.         foreach ($toolbar as $elementType => $elementAttributes)
  751.         {
  752.             $value = isset($elementAttributes['value']$elementAttributes['value'null;
  753.             $this->renderToolbarElement($elementType$value$elementAttributes);
  754.         }
  755.  
  756.         return;
  757.     }
  758.  
  759.     /**
  760.      * Render a toolbar element.
  761.      *
  762.      * @param   string  $type        The element type.
  763.      * @param   mixed   $value       The element value.
  764.      * @param   array   $attributes  The element attributes.
  765.      *
  766.      * @return  void 
  767.      *
  768.      * @throws  InvalidArgumentException
  769.      */
  770.     private function renderToolbarElement($type$value nullarray $attributes array())
  771.     {
  772.         switch ($type)
  773.         {
  774.             case 'title':
  775.                 $icon = isset($attributes['icon']$attributes['icon''generic.png';
  776.  
  777.                 JToolbarHelper::title($value$icon);
  778.                 break;
  779.  
  780.             case 'divider':
  781.                 JToolbarHelper::divider();
  782.                 break;
  783.  
  784.             case 'custom':
  785.                 $task = isset($attributes['task']$attributes['task''';
  786.                 $icon = isset($attributes['icon']$attributes['icon''';
  787.                 $iconOver = isset($attributes['icon_over']$attributes['icon_over''';
  788.                 $alt = isset($attributes['alt']$attributes['alt''';
  789.                 $listSelect = isset($attributes['list_select']?
  790.                     FOFStringUtils::toBool($attributes['list_select']true;
  791.  
  792.                 JToolbarHelper::custom($task$icon$iconOver$alt$listSelect);
  793.                 break;
  794.  
  795.             case 'preview':
  796.                 $url = isset($attributes['url']$attributes['url''';
  797.                 $update_editors = isset($attributes['update_editors']?
  798.                     FOFStringUtils::toBool($attributes['update_editors']false;
  799.  
  800.                 JToolbarHelper::preview($url$update_editors);
  801.                 break;
  802.  
  803.             case 'help':
  804.                 if (!isset($attributes['help']))
  805.                 {
  806.                     throw new InvalidArgumentException(
  807.                         'The help attribute is missing in the help button type.'
  808.                     );
  809.                 }
  810.  
  811.                 $ref $attributes['help'];
  812.                 $com = isset($attributes['com']FOFStringUtils::toBool($attributes['com']false;
  813.                 $override = isset($attributes['override']$attributes['override'null;
  814.                 $component = isset($attributes['component']$attributes['component'null;
  815.  
  816.                 JToolbarHelper::help($ref$com$override$component);
  817.                 break;
  818.  
  819.             case 'back':
  820.                 $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_BACK';
  821.                 $href = isset($attributes['href']$attributes['href''javascript:history.back();';
  822.  
  823.                 JToolbarHelper::back($alt$href);
  824.                 break;
  825.  
  826.             case 'media_manager':
  827.                 $directory = isset($attributes['directory']$attributes['directory''';
  828.                 $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_UPLOAD';
  829.  
  830.                 JToolbarHelper::media_manager($directory$alt);
  831.                 break;
  832.  
  833.             case 'assign':
  834.                 $task = isset($attributes['task']$attributes['task''assign';
  835.                 $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_ASSIGN';
  836.  
  837.                 JToolbarHelper::assign($task$alt);
  838.                 break;
  839.  
  840.             case 'new':
  841.                 if ($this->perms->create)
  842.                 {
  843.                     $task = isset($attributes['task']$attributes['task''add';
  844.                     $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_NEW';
  845.                     $check = isset($attributes['check']?
  846.                         FOFStringUtils::toBool($attributes['check']false;
  847.  
  848.                     JToolbarHelper::addNew($task$alt$check);
  849.                 }
  850.  
  851.                 break;
  852.  
  853.             case 'publish':
  854.                 if ($this->perms->editstate)
  855.                 {
  856.                     $task = isset($attributes['task']$attributes['task''publish';
  857.                     $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_PUBLISH';
  858.                     $check = isset($attributes['check']?
  859.                         FOFStringUtils::toBool($attributes['check']false;
  860.  
  861.                     JToolbarHelper::publish($task$alt$check);
  862.                 }
  863.  
  864.                 break;
  865.  
  866.             case 'publishList':
  867.                 if ($this->perms->editstate)
  868.                 {
  869.                     $task = isset($attributes['task']$attributes['task''publish';
  870.                     $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_PUBLISH';
  871.  
  872.                     JToolbarHelper::publishList($task$alt);
  873.                 }
  874.  
  875.                 break;
  876.  
  877.             case 'unpublish':
  878.                 if ($this->perms->editstate)
  879.                 {
  880.                     $task = isset($attributes['task']$attributes['task''unpublish';
  881.                     $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_UNPUBLISH';
  882.                     $check = isset($attributes['check']?
  883.                         FOFStringUtils::toBool($attributes['check']false;
  884.  
  885.                     JToolbarHelper::unpublish($task$alt$check);
  886.                 }
  887.  
  888.                 break;
  889.  
  890.             case 'unpublishList':
  891.                 if ($this->perms->editstate)
  892.                 {
  893.                     $task = isset($attributes['task']$attributes['task''unpublish';
  894.                     $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_UNPUBLISH';
  895.  
  896.                     JToolbarHelper::unpublishList($task$alt);
  897.                 }
  898.  
  899.                 break;
  900.  
  901.             case 'archiveList':
  902.                 if ($this->perms->editstate)
  903.                 {
  904.                     $task = isset($attributes['task']$attributes['task''archive';
  905.                     $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_ARCHIVE';
  906.  
  907.                     JToolbarHelper::archiveList($task$alt);
  908.                 }
  909.  
  910.                 break;
  911.  
  912.             case 'unarchiveList':
  913.                 if ($this->perms->editstate)
  914.                 {
  915.                     $task = isset($attributes['task']$attributes['task''unarchive';
  916.                     $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_UNARCHIVE';
  917.  
  918.                     JToolbarHelper::unarchiveList($task$alt);
  919.                 }
  920.  
  921.                 break;
  922.  
  923.             case 'editList':
  924.                 if ($this->perms->edit)
  925.                 {
  926.                     $task = isset($attributes['task']$attributes['task''edit';
  927.                     $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_EDIT';
  928.  
  929.                     JToolbarHelper::editList($task$alt);
  930.                 }
  931.  
  932.                 break;
  933.  
  934.             case 'editHtml':
  935.                 $task = isset($attributes['task']$attributes['task''edit_source';
  936.                 $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_EDIT_HTML';
  937.  
  938.                 JToolbarHelper::editHtml($task$alt);
  939.                 break;
  940.  
  941.             case 'editCss':
  942.                 $task = isset($attributes['task']$attributes['task''edit_css';
  943.                 $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_EDIT_CSS';
  944.  
  945.                 JToolbarHelper::editCss($task$alt);
  946.                 break;
  947.  
  948.             case 'deleteList':
  949.                 if ($this->perms->delete)
  950.                 {
  951.                     $msg = isset($attributes['msg']$attributes['msg''';
  952.                     $task = isset($attributes['task']$attributes['task''remove';
  953.                     $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_DELETE';
  954.  
  955.                     JToolbarHelper::deleteList($msg$task$alt);
  956.                 }
  957.  
  958.                 break;
  959.  
  960.             case 'trash':
  961.                 if ($this->perms->editstate)
  962.                 {
  963.                     $task = isset($attributes['task']$attributes['task''remove';
  964.                     $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_TRASH';
  965.                     $check = isset($attributes['check']?
  966.                         FOFStringUtils::toBool($attributes['check']true;
  967.  
  968.                     JToolbarHelper::trash($task$alt$check);
  969.                 }
  970.  
  971.                 break;
  972.  
  973.             case 'apply':
  974.                 $task = isset($attributes['task']$attributes['task''apply';
  975.                 $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_APPLY';
  976.  
  977.                 JToolbarHelper::apply($task$alt);
  978.                 break;
  979.  
  980.             case 'save':
  981.                 $task = isset($attributes['task']$attributes['task''save';
  982.                 $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_SAVE';
  983.  
  984.                 JToolbarHelper::save($task$alt);
  985.                 break;
  986.  
  987.             case 'save2new':
  988.                 $task = isset($attributes['task']$attributes['task''save2new';
  989.                 $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_SAVE_AND_NEW';
  990.  
  991.                 JToolbarHelper::save2new($task$alt);
  992.                 break;
  993.  
  994.             case 'save2copy':
  995.                 $task = isset($attributes['task']$attributes['task''save2copy';
  996.                 $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_SAVE_AS_COPY';
  997.                 JToolbarHelper::save2copy($task$alt);
  998.                 break;
  999.  
  1000.             case 'checkin':
  1001.                 $task = isset($attributes['task']$attributes['task''checkin';
  1002.                 $alt = isset($attributes['alt']$attributes['alt':'JTOOLBAR_CHECKIN';
  1003.                 $check = isset($attributes['check']?
  1004.                     FOFStringUtils::toBool($attributes['check']true;
  1005.  
  1006.                 JToolbarHelper::checkin($task$alt$check);
  1007.                 break;
  1008.  
  1009.             case 'cancel':
  1010.                 $task = isset($attributes['task']$attributes['task''cancel';
  1011.                 $alt = isset($attributes['alt']$attributes['alt''JTOOLBAR_CANCEL';
  1012.  
  1013.                 JToolbarHelper::cancel($task$alt);
  1014.                 break;
  1015.  
  1016.             case 'preferences':
  1017.                 if (!isset($attributes['component']))
  1018.                 {
  1019.                     throw new InvalidArgumentException(
  1020.                         'The component attribute is missing in the preferences button type.'
  1021.                     );
  1022.                 }
  1023.  
  1024.                 $component $attributes['component'];
  1025.                 $height = isset($attributes['height']$attributes['height''550';
  1026.                 $width = isset($attributes['width']$attributes['width''875';
  1027.                 $alt = isset($attributes['alt']$attributes['alt''JToolbar_Options';
  1028.                 $path = isset($attributes['path']$attributes['path''';
  1029.  
  1030.                 JToolbarHelper::preferences($component$height$width$alt$path);
  1031.                 break;
  1032.  
  1033.             default:
  1034.                 throw new InvalidArgumentException(sprintf('Unknown button type %s'$type));
  1035.         }
  1036.     }
  1037. }

Documentation generated on Tue, 19 Nov 2013 15:15:52 +0100 by phpDocumentor 1.4.3