| [ Index ] |
PHP Cross Reference of Joomla 2.5.4 DE |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved. 4 * @license GNU General Public License version 2 or later; see LICENSE.txt 5 */ 6 7 defined('_JEXEC') or die; 8 9 jimport( 'joomla.application.component.controller' ); 10 11 /** 12 * The Menu List Controller 13 * 14 * @package Joomla.Administrator 15 * @subpackage com_menus 16 * @since 1.6 17 */ 18 class MenusControllerMenus extends JController 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 = JRequest::getVar('cid', array(), '', 'array'); 60 61 if (!is_array($cid) || count($cid) < 1) { 62 JError::raiseWarning(500, JText::_('COM_MENUS_NO_MENUS_SELECTED')); 63 } else { 64 // Get the model. 65 $model = $this->getModel(); 66 67 // Make sure the item ids are integers 68 jimport('joomla.utilities.arrayhelper'); 69 JArrayHelper::toInteger($cid); 70 71 // Remove the items. 72 if (!$model->delete($cid)) { 73 $this->setMessage($model->getError()); 74 } else { 75 $this->setMessage(JText::plural('COM_MENUS_N_MENUS_DELETED', count($cid))); 76 } 77 } 78 79 $this->setRedirect('index.php?option=com_menus&view=menus'); 80 } 81 82 /** 83 * Rebuild the menu tree. 84 * 85 * @return bool False on failure or error, true on success. 86 */ 87 public function rebuild() 88 { 89 JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); 90 91 $this->setRedirect('index.php?option=com_menus&view=menus'); 92 93 // Initialise variables. 94 $model = $this->getModel('Item'); 95 96 if ($model->rebuild()) { 97 // Reorder succeeded. 98 $this->setMessage(JText::_('JTOOLBAR_REBUILD_SUCCESS')); 99 return true; 100 } else { 101 // Rebuild failed. 102 $this->setMessage(JText::sprintf('JTOOLBAR_REBUILD_FAILED', $model->getMessage())); 103 return false; 104 } 105 } 106 107 /** 108 * Temporary method. This should go into the 1.5 to 1.6 upgrade routines. 109 */ 110 public function resync() 111 { 112 // Initialise variables. 113 $db = JFactory::getDbo(); 114 $parts = null; 115 116 // Load a lookup table of all the component id's. 117 $components = $db->setQuery( 118 'SELECT element, extension_id' . 119 ' FROM #__extensions' . 120 ' WHERE type = '.$db->quote('component') 121 )->loadAssocList('element', 'extension_id'); 122 123 if ($error = $db->getErrorMsg()) { 124 return JError::raiseWarning(500, $error); 125 } 126 127 // Load all the component menu links 128 $items = $db->setQuery( 129 'SELECT id, link, component_id' . 130 ' FROM #__menu' . 131 ' WHERE type = '.$db->quote('component') 132 )->loadObjectList(); 133 134 if ($error = $db->getErrorMsg()) { 135 return JError::raiseWarning(500, $error); 136 } 137 138 foreach ($items as $item) { 139 // Parse the link. 140 parse_str(parse_url($item->link, PHP_URL_QUERY), $parts); 141 142 // Tease out the option. 143 if (isset($parts['option'])) { 144 $option = $parts['option']; 145 146 // Lookup the component ID 147 if (isset($components[$option])) { 148 $componentId = $components[$option]; 149 } else { 150 // Mismatch. Needs human intervention. 151 $componentId = -1; 152 } 153 154 // Check for mis-matched component id's in the menu link. 155 if ($item->component_id != $componentId) { 156 // Update the menu table. 157 $log = "Link $item->id refers to $item->component_id, converting to $componentId ($item->link)"; 158 echo "<br/>$log"; 159 160 $db->setQuery( 161 'UPDATE #__menu' . 162 ' SET component_id = '.$componentId. 163 ' WHERE id = '.$item->id 164 )->query(); 165 //echo "<br>".$db->getQuery(); 166 167 if ($error = $db->getErrorMsg()) { 168 return JError::raiseWarning(500, $error); 169 } 170 } 171 } 172 } 173 } 174 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Apr 3 11:40:28 2012 | Cross-referenced by PHPXref 0.7.1 |