PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_menus/controllers/menus.php

https://github.com/joebushi/joomla
PHP | 159 lines | 87 code | 25 blank | 47 comment | 14 complexity | 224879e5a82a8631fdee4dfd576fc1d5 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id$
  4. * @copyright Copyright (C) 2005 - 2010 Open Source Matters, Inc. All rights reserved.
  5. * @license GNU General Public License version 2 or later; see LICENSE.txt
  6. */
  7. defined('_JEXEC') or die;
  8. jimport( 'joomla.application.component.controller' );
  9. /**
  10. * The Menu List Controller
  11. *
  12. * @package Joomla.Administrator
  13. * @subpackage com_menus
  14. * @since 1.6
  15. */
  16. class MenusControllerMenus extends JController
  17. {
  18. /**
  19. * Display the view
  20. */
  21. public function display()
  22. {
  23. }
  24. /**
  25. * Proxy for getModel
  26. */
  27. function &getModel($name = 'Menu', $prefix = 'MenusModel')
  28. {
  29. $model = parent::getModel($name, $prefix, array('ignore_request' => true));
  30. return $model;
  31. }
  32. /**
  33. * Removes an item
  34. */
  35. public function delete()
  36. {
  37. // Check for request forgeries
  38. JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
  39. // Get items to remove from the request.
  40. $cid = JRequest::getVar('cid', array(), '', 'array');
  41. if (!is_array($cid) || count($cid) < 1) {
  42. JError::raiseWarning(500, JText::_('JError_No_items_selected'));
  43. } else {
  44. // Get the model.
  45. $model = $this->getModel();
  46. // Make sure the item ids are integers
  47. jimport('joomla.utilities.arrayhelper');
  48. JArrayHelper::toInteger($cid);
  49. // Remove the items.
  50. if (!$model->delete($cid)) {
  51. $this->setMessage($model->getError());
  52. }
  53. }
  54. $this->setRedirect('index.php?option=com_menus&view=menus');
  55. }
  56. /**
  57. * Rebuild the menu tree.
  58. *
  59. * @return bool False on failure or error, true on success.
  60. */
  61. public function rebuild()
  62. {
  63. JRequest::checkToken() or jexit(JText::_('JInvalid_Token'));
  64. $this->setRedirect('index.php?option=com_menus&view=menus');
  65. // Initialise variables.
  66. $model = &$this->getModel('Item');
  67. if ($model->rebuild()) {
  68. // Reorder succeeded.
  69. $this->setMessage(JText::_('Menus_Rebuild_success'));
  70. return true;
  71. } else {
  72. // Rebuild failed.
  73. $this->setMessage(JText::sprintf('Menus_Rebuild_failed', $model->getMessage()));
  74. return false;
  75. }
  76. }
  77. /**
  78. * Temporary method. This should go into the 1.5 to 1.6 upgrade routines.
  79. */
  80. public function resync()
  81. {
  82. // Initialise variables.
  83. $db = JFactory::getDbo();
  84. $parts = null;
  85. // Load a lookup table of all the component id's.
  86. $components = $db->setQuery(
  87. 'SELECT element, extension_id' .
  88. ' FROM #__extensions' .
  89. ' WHERE type = '.$db->quote('component')
  90. )->loadAssocList('element', 'extension_id');
  91. if ($error = $db->getErrorMsg()) {
  92. return JError::raiseWarning(500, $error);
  93. }
  94. // Load all the component menu links
  95. $items = $db->setQuery(
  96. 'SELECT id, link, component_id' .
  97. ' FROM #__menu' .
  98. ' WHERE type = '.$db->quote('component')
  99. )->loadObjectList();
  100. if ($error = $db->getErrorMsg()) {
  101. return JError::raiseWarning(500, $error);
  102. }
  103. foreach ($items as $item) {
  104. // Parse the link.
  105. parse_str(parse_url($item->link, PHP_URL_QUERY), $parts);
  106. // Tease out the option.
  107. if (isset($parts['option'])) {
  108. $option = $parts['option'];
  109. // Lookup the component ID
  110. if (isset($components[$option])) {
  111. $componentId = $components[$option];
  112. } else {
  113. // Mismatch. Needs human intervention.
  114. $componentId = -1;
  115. }
  116. // Check for mis-matched component id's in the menu link.
  117. if ($item->component_id != $componentId) {
  118. // Update the menu table.
  119. $log = "Link $item->id refers to $item->component_id, converting to $componentId ($item->link)";
  120. echo "<br/>$log";
  121. $db->setQuery(
  122. 'UPDATE #__menu' .
  123. ' SET component_id = '.$componentId.
  124. ' WHERE id = '.$item->id
  125. )->query();
  126. //echo "<br>".$db->getQuery();
  127. if ($error = $db->getErrorMsg()) {
  128. return JError::raiseWarning(500, $error);
  129. }
  130. }
  131. }
  132. }
  133. }
  134. }