Source for file view.html.php

Documentation is available at view.html.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_menus
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC'or die;
  11.  
  12. /**
  13.  * The HTML Menus Menu Items View.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_menus
  17.  * @since       1.6
  18.  */
  19. class MenusViewItems extends JViewLegacy
  20. {
  21.     protected $f_levels;
  22.  
  23.     protected $items;
  24.  
  25.     protected $pagination;
  26.  
  27.     protected $state;
  28.  
  29.     /**
  30.      * Display the view
  31.      *
  32.      * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  33.      *
  34.      * @return  void 
  35.      */
  36.     public function display($tpl null)
  37.     {
  38.         $lang         JFactory::getLanguage();
  39.         $this->items        = $this->get('Items');
  40.         $this->pagination    = $this->get('Pagination');
  41.         $this->state        = $this->get('State');
  42.         $this->filterForm    $this->get('FilterForm');
  43.         $this->activeFilters $this->get('ActiveFilters');
  44.  
  45.         MenusHelper::addSubmenu('items');
  46.  
  47.         // Check for errors.
  48.         if (count($errors $this->get('Errors')))
  49.         {
  50.             JError::raiseError(500implode("\n"$errors));
  51.  
  52.             return false;
  53.         }
  54.  
  55.         $this->ordering array();
  56.  
  57.         // Preprocess the list of items to find ordering divisions.
  58.         foreach ($this->items as $item)
  59.         {
  60.             $this->ordering[$item->parent_id][$item->id;
  61.  
  62.             // Item type text
  63.             switch ($item->type)
  64.             {
  65.                 case 'url':
  66.                     $value JText::_('COM_MENUS_TYPE_EXTERNAL_URL');
  67.                     break;
  68.  
  69.                 case 'alias':
  70.                     $value JText::_('COM_MENUS_TYPE_ALIAS');
  71.                     break;
  72.  
  73.                 case 'separator':
  74.                     $value JText::_('COM_MENUS_TYPE_SEPARATOR');
  75.                     break;
  76.  
  77.                 case 'heading':
  78.                     $value JText::_('COM_MENUS_TYPE_HEADING');
  79.                     break;
  80.  
  81.                 case 'component':
  82.                 default:
  83.                     // Load language
  84.                         $lang->load($item->componentname '.sys'JPATH_ADMINISTRATORnullfalsetrue)
  85.                     ||    $lang->load($item->componentname '.sys'JPATH_ADMINISTRATOR '/components/' $item->componentnamenullfalsetrue);
  86.  
  87.                     if (!empty($item->componentname))
  88.                     {
  89.                         $value    JText::_($item->componentname);
  90.                         $vars    null;
  91.  
  92.                         parse_str($item->link$vars);
  93.  
  94.                         if (isset($vars['view']))
  95.                         {
  96.                             // Attempt to load the view xml file.
  97.                             $file JPATH_SITE '/components/' $item->componentname '/views/' $vars['view''/metadata.xml';
  98.  
  99.                             if (!is_file($file))
  100.                             {
  101.                                 $file JPATH_SITE '/components/' $item->componentname '/view/' $vars['view''/metadata.xml';
  102.                             }
  103.  
  104.                             if (is_file($file&& $xml simplexml_load_file($file))
  105.                             {
  106.                                 // Look for the first view node off of the root node.
  107.                                 if ($view $xml->xpath('view[1]'))
  108.                                 {
  109.                                     if (!empty($view[0]['title']))
  110.                                     {
  111.                                         $vars['layout'= isset($vars['layout']$vars['layout''default';
  112.  
  113.                                         // Attempt to load the layout xml file.
  114.                                         // If Alternative Menu Item, get template folder for layout file
  115.                                         if (strpos($vars['layout']':'0)
  116.                                         {
  117.                                             // Use template folder for layout file
  118.                                             $temp explode(':'$vars['layout']);
  119.                                             $file JPATH_SITE '/templates/' $temp[0'/html/' $item->componentname '/' $vars['view''/' $temp[1'.xml';
  120.  
  121.                                             // Load template language file
  122.                                             $lang->load('tpl_' $temp[0'.sys'JPATH_SITEnullfalsetrue)
  123.                                             ||    $lang->load('tpl_' $temp[0'.sys'JPATH_SITE '/templates/' $temp[0]nullfalsetrue);
  124.                                         }
  125.                                         else
  126.                                         {
  127.                                             // Get XML file from component folder for standard layouts
  128.                                             $file JPATH_SITE '/components/' $item->componentname '/views/' $vars['view''/tmpl/' $vars['layout''.xml';
  129.  
  130.                                             if (!file_exists($file))
  131.                                             {
  132.                                                 $file JPATH_SITE '/components/' $item->componentname '/view/' $vars['view''/tmpl/' $vars['layout''.xml';
  133.                                             }
  134.  
  135.                                         }
  136.  
  137.                                         if (is_file($file&& $xml simplexml_load_file($file))
  138.                                         {
  139.                                             // Look for the first view node off of the root node.
  140.                                             if ($layout $xml->xpath('layout[1]'))
  141.                                             {
  142.                                                 if (!empty($layout[0]['title']))
  143.                                                 {
  144.                                                     $value .= ' » ' JText::_(trim((string) $layout[0]['title']));
  145.                                                 }
  146.                                             }
  147.  
  148.                                             if (!empty($layout[0]->message[0]))
  149.                                             {
  150.                                                 $item->item_type_desc JText::_(trim((string) $layout[0]->message[0]));
  151.                                             }
  152.                                         }
  153.                                     }
  154.                                 }
  155.  
  156.                                 unset($xml);
  157.                             }
  158.                             else
  159.                             {
  160.                                 // Special case for absent views
  161.                                 $value .= ' » ' $vars['view'];
  162.                             }
  163.                         }
  164.                     }
  165.                     else
  166.                     {
  167.                         if (preg_match("/^index.php\?option=([a-zA-Z\-0-9_]*)/"$item->link$result))
  168.                         {
  169.                             $value JText::sprintf('COM_MENUS_TYPE_UNEXISTING'$result[1]);
  170.                         }
  171.                         else
  172.                         {
  173.                             $value JText::_('COM_MENUS_TYPE_UNKNOWN');
  174.                         }
  175.                     }
  176.                     break;
  177.             }
  178.  
  179.             $item->item_type $value;
  180.         }
  181.  
  182.         // Levels filter.
  183.         $options    array();
  184.         $options[]    JHtml::_('select.option''1'JText::_('J1'));
  185.         $options[]    JHtml::_('select.option''2'JText::_('J2'));
  186.         $options[]    JHtml::_('select.option''3'JText::_('J3'));
  187.         $options[]    JHtml::_('select.option''4'JText::_('J4'));
  188.         $options[]    JHtml::_('select.option''5'JText::_('J5'));
  189.         $options[]    JHtml::_('select.option''6'JText::_('J6'));
  190.         $options[]    JHtml::_('select.option''7'JText::_('J7'));
  191.         $options[]    JHtml::_('select.option''8'JText::_('J8'));
  192.         $options[]    JHtml::_('select.option''9'JText::_('J9'));
  193.         $options[]    JHtml::_('select.option''10'JText::_('J10'));
  194.  
  195.         $this->f_levels = $options;
  196.  
  197.         $this->addToolbar();
  198.         $this->sidebar JHtmlSidebar::render();
  199.  
  200.         // Allow a system plugin to insert dynamic menu types to the list shown in menus:
  201.         JEventDispatcher::getInstance()->trigger('onBeforeRenderMenuItems'array($this));
  202.  
  203.         parent::display($tpl);
  204.     }
  205.  
  206.     /**
  207.      * Add the page title and toolbar.
  208.      *
  209.      * @return  void 
  210.      *
  211.      * @since   1.6
  212.      */
  213.     protected function addToolbar()
  214.     {
  215.         require_once JPATH_COMPONENT '/helpers/menus.php';
  216.  
  217.         $canDo    MenusHelper::getActions($this->state->get('filter.parent_id'));
  218.         $user  JFactory::getUser();
  219.  
  220.         // Get the toolbar object instance
  221.         $bar JToolBar::getInstance('toolbar');
  222.  
  223.         JToolbarHelper::title(JText::_('COM_MENUS_VIEW_ITEMS_TITLE')'list menumgr');
  224.  
  225.         if ($canDo->get('core.create'))
  226.         {
  227.             JToolbarHelper::addNew('item.add');
  228.         }
  229.  
  230.         if ($canDo->get('core.edit'))
  231.         {
  232.             JToolbarHelper::editList('item.edit');
  233.         }
  234.  
  235.         if ($canDo->get('core.edit.state'))
  236.         {
  237.             JToolbarHelper::publish('items.publish''JTOOLBAR_PUBLISH'true);
  238.             JToolbarHelper::unpublish('items.unpublish''JTOOLBAR_UNPUBLISH'true);
  239.         }
  240.  
  241.         if (JFactory::getUser()->authorise('core.admin'))
  242.         {
  243.             JToolbarHelper::checkin('items.checkin''JTOOLBAR_CHECKIN'true);
  244.         }
  245.  
  246.         if ($this->state->get('filter.published'== -&& $canDo->get('core.delete'))
  247.         {
  248.             JToolbarHelper::deleteList('''items.delete''JTOOLBAR_EMPTY_TRASH');
  249.         }
  250.         elseif ($canDo->get('core.edit.state'))
  251.         {
  252.             JToolbarHelper::trash('items.trash');
  253.         }
  254.  
  255.         if ($canDo->get('core.edit.state'))
  256.         {
  257.             JToolbarHelper::makeDefault('items.setDefault''COM_MENUS_TOOLBAR_SET_HOME');
  258.         }
  259.  
  260.         if (JFactory::getUser()->authorise('core.admin'))
  261.         {
  262.             JToolbarHelper::custom('items.rebuild''refresh.png''refresh_f2.png''JToolbar_Rebuild'false);
  263.         }
  264.  
  265.         // Add a batch button
  266.         if ($user->authorise('core.create''com_menus'&& $user->authorise('core.edit''com_menus'&& $user->authorise('core.edit.state''com_menus'))
  267.         {
  268.             JHtml::_('bootstrap.modal''collapseModal');
  269.             $title JText::_('JTOOLBAR_BATCH');
  270.  
  271.             // Instantiate a new JLayoutFile instance and render the batch button
  272.             $layout new JLayoutFile('joomla.toolbar.batch');
  273.  
  274.             $dhtml $layout->render(array('title' => $title));
  275.             $bar->appendButton('Custom'$dhtml'batch');
  276.         }
  277.  
  278.         JToolbarHelper::help('JHELP_MENUS_MENU_ITEM_MANAGER');
  279.     }
  280.  
  281.     /**
  282.      * Returns an array of fields the table can be sorted by
  283.      *
  284.      * @return  array  Array containing the field name to sort by as the key and display text as value
  285.      *
  286.      * @since   3.0
  287.      */
  288.     protected function getSortFields()
  289.     {
  290.         return array(
  291.             'a.lft' => JText::_('JGRID_HEADING_ORDERING'),
  292.             'a.published' => JText::_('JSTATUS'),
  293.             'a.title' => JText::_('JGLOBAL_TITLE'),
  294.             'a.home' => JText::_('COM_MENUS_HEADING_HOME'),
  295.             'a.access' => JText::_('JGRID_HEADING_ACCESS'),
  296.             'association' => JText::_('COM_MENUS_HEADING_ASSOCIATION'),
  297.             'language' => JText::_('JGRID_HEADING_LANGUAGE'),
  298.             'a.id' => JText::_('JGRID_HEADING_ID')
  299.         );
  300.     }
  301. }

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