Source for file menus.php

Documentation is available at menus.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 Menu List Controller
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_menus
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * Display the view
  22.      *
  23.      * @param   boolean            If true, the view output will be cached
  24.      * @param   array              An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  25.      *
  26.      * @return  JController        This object to support chaining.
  27.      * @since   1.6
  28.      */
  29.     public function display($cachable false$urlparams false)
  30.     {
  31.     }
  32.  
  33.     /**
  34.      * Method to get a model object, loading it if required.
  35.      *
  36.      * @param   string  $name    The model name. Optional.
  37.      * @param   string  $prefix  The class prefix. Optional.
  38.      * @param   array   $config  Configuration array for model. Optional.
  39.      *
  40.      * @return  object  The model.
  41.      *
  42.      * @since   1.6
  43.      */
  44.     public function getModel($name 'Menu'$prefix 'MenusModel'$config array('ignore_request' => true))
  45.     {
  46.         $model parent::getModel($name$prefix$config);
  47.         return $model;
  48.     }
  49.  
  50.     /**
  51.      * Removes an item
  52.      */
  53.     public function delete()
  54.     {
  55.         // Check for request forgeries
  56.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  57.  
  58.         // Get items to remove from the request.
  59.         $cid $this->input->get('cid'array()'array');
  60.  
  61.         if (!is_array($cid|| count($cid1)
  62.         {
  63.             JError::raiseWarning(500JText::_('COM_MENUS_NO_MENUS_SELECTED'));
  64.         }
  65.         else
  66.         {
  67.             // Get the model.
  68.             $model $this->getModel();
  69.  
  70.             // Make sure the item ids are integers
  71.             jimport('joomla.utilities.arrayhelper');
  72.             JArrayHelper::toInteger($cid);
  73.  
  74.             // Remove the items.
  75.             if (!$model->delete($cid))
  76.             {
  77.                 $this->setMessage($model->getError());
  78.             }
  79.             else
  80.             {
  81.                 $this->setMessage(JText::plural('COM_MENUS_N_MENUS_DELETED'count($cid)));
  82.             }
  83.         }
  84.  
  85.         $this->setRedirect('index.php?option=com_menus&view=menus');
  86.     }
  87.  
  88.     /**
  89.      * Rebuild the menu tree.
  90.      *
  91.      * @return  bool    False on failure or error, true on success.
  92.      */
  93.     public function rebuild()
  94.     {
  95.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  96.  
  97.         $this->setRedirect('index.php?option=com_menus&view=menus');
  98.  
  99.         $model $this->getModel('Item');
  100.  
  101.         if ($model->rebuild())
  102.         {
  103.             // Reorder succeeded.
  104.             $this->setMessage(JText::_('JTOOLBAR_REBUILD_SUCCESS'));
  105.             return true;
  106.         }
  107.         else
  108.         {
  109.             // Rebuild failed.
  110.             $this->setMessage(JText::sprintf('JTOOLBAR_REBUILD_FAILED'$model->getMessage()));
  111.             return false;
  112.         }
  113.     }
  114.  
  115.     /**
  116.      * Temporary method. This should go into the 1.5 to 1.6 upgrade routines.
  117.      */
  118.     public function resync()
  119.     {
  120.         $db JFactory::getDbo();
  121.         $query $db->getQuery(true);
  122.         $parts null;
  123.  
  124.         try
  125.         {
  126.             $query->select('element, extension_id')
  127.                 ->from('#__extensions')
  128.                 ->where('type = ' $db->quote('component'));
  129.             $db->setQuery($query);
  130.  
  131.             $components $db->loadAssocList('element''extension_id');
  132.         }
  133.         catch (RuntimeException $e)
  134.         {
  135.             return JError::raiseWarning(500$e->getMessage());
  136.         }
  137.  
  138.         // Load all the component menu links
  139.         $query->select($db->quoteName('id'))
  140.             ->select($db->quoteName('link'))
  141.             ->select($db->quoteName('component_id'))
  142.             ->from('#__menu')
  143.             ->where($db->quoteName('type'' = ' $db->quote('component.item'));
  144.             $db->setQuery($query);
  145.  
  146.         try
  147.         {
  148.             $items $db->loadObjectList();
  149.         }
  150.         catch (RuntimeException $e)
  151.         {
  152.             return JError::raiseWarning(500$e->getMessage());
  153.         }
  154.  
  155.         foreach ($items as $item)
  156.         {
  157.             // Parse the link.
  158.             parse_str(parse_url($item->linkPHP_URL_QUERY)$parts);
  159.  
  160.             // Tease out the option.
  161.             if (isset($parts['option']))
  162.             {
  163.                 $option $parts['option'];
  164.  
  165.                 // Lookup the component ID
  166.                 if (isset($components[$option]))
  167.                 {
  168.                     $componentId $components[$option];
  169.                 }
  170.                 else
  171.                 {
  172.                     // Mismatch. Needs human intervention.
  173.                     $componentId = -1;
  174.                 }
  175.  
  176.                 // Check for mis-matched component id's in the menu link.
  177.                 if ($item->component_id != $componentId)
  178.                 {
  179.                     // Update the menu table.
  180.                     $log "Link $item->id refers to $item->component_id, converting to $componentId ($item->link)";
  181.                     echo "<br/>$log";
  182.  
  183.                     $query->clear();
  184.                     $query->update('#__menu')
  185.                         ->set('component_id = ' $componentId)
  186.                         ->where('id = ' $item->id);
  187.  
  188.                     try
  189.                     {
  190.                         $db->setQuery($query)->execute();
  191.                     }
  192.                     catch (RuntimeException $e)
  193.                     {
  194.                         return JError::raiseWarning(500$e->getMessage());
  195.                     }
  196.                     //echo "<br>".$db->getQuery();
  197.                 }
  198.             }
  199.         }
  200.     }
  201. }

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