PageRenderTime 41ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/aamenu/code/trunk/administrator/components/com_aamenu/install/uninstall.php

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 234 lines | 146 code | 31 blank | 57 comment | 27 complexity | c25ff58c1b9f6247a53adae9d1bc98de MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: uninstall.php 277 2010-09-13 04:21:14Z eddieajau $
  4. * @package Artof.AAMenu
  5. * @subpackage com_aamenu
  6. * @copyright Copyright (C) 2009 New Life in IT Pty Ltd. All rights reserved.
  7. * @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
  8. * @link http://www.theartofjoomla.com
  9. */
  10. // no direct access
  11. defined('_JEXEC') or die();
  12. // load the component language file
  13. $language = &JFactory::getLanguage();
  14. $language->load('com_aamenu');
  15. //$nPaths = $this->_paths;
  16. $status = new JObject();
  17. $status->modules = array();
  18. $status->plugins = array();
  19. /***********************************************************************************************
  20. * ---------------------------------------------------------------------------------------------
  21. * MODULE REMOVAL SECTION
  22. * ---------------------------------------------------------------------------------------------
  23. ***********************************************************************************************/
  24. $modules = &$this->manifest->getElementByPath('modules');
  25. if (is_a($modules, 'JSimpleXMLElement') && count($modules->children())) {
  26. foreach ($modules->children() as $module)
  27. {
  28. $mname = $module->attributes('module');
  29. $mclient = JApplicationHelper::getClientInfo($module->attributes('client'), true);
  30. $mposition = $module->attributes('position');
  31. // Set the installation path
  32. if (!empty ($mname)) {
  33. $this->parent->setPath('extension_root', $mclient->path.DS.'modules'.DS.$mname);
  34. } else {
  35. $this->parent->abort(JText::_('J_INSTALL_MODULE').' '.JText::_('J_INSTALL_UNINSTALL').': '.JText::_('J_INSTALL_MODULE_FILE_MISSING'));
  36. return false;
  37. }
  38. /**
  39. * ---------------------------------------------------------------------------------------------
  40. * Database Processing Section
  41. * ---------------------------------------------------------------------------------------------
  42. */
  43. $db = &JFactory::getDBO();
  44. // Lets delete all the module copies for the type we are uninstalling
  45. $query = 'SELECT `id`' .
  46. ' FROM `#__modules`' .
  47. ' WHERE module = '.$db->Quote($mname) .
  48. ' AND client_id = '.(int)$mclient->id;
  49. $db->setQuery($query);
  50. $modules = $db->loadResultArray();
  51. // Do we have any module copies?
  52. if (count($modules)) {
  53. JArrayHelper::toInteger($modules);
  54. $modID = implode(',', $modules);
  55. $query = 'DELETE' .
  56. ' FROM #__modules_menu' .
  57. ' WHERE moduleid IN ('.$modID.')';
  58. $db->setQuery($query);
  59. if (!$db->query()) {
  60. JError::raiseWarning(100, JText::_('J_INSTALL_MODULE').' '.JText::_('J_INSTALL_UNINSTALL').': '.$db->stderr(true));
  61. $retval = false;
  62. }
  63. }
  64. // Delete the modules in the #__modules table
  65. $query = 'DELETE FROM #__modules WHERE module = '.$db->Quote($mname);
  66. $db->setQuery($query);
  67. if (!$db->query()) {
  68. JError::raiseWarning(100, JText::_('J_INSTALL_MODULE').' '.JText::_('J_INSTALL_UNINSTALL').': '.$db->stderr(true));
  69. $retval = false;
  70. }
  71. /**
  72. * ---------------------------------------------------------------------------------------------
  73. * Filesystem Processing Section
  74. * ---------------------------------------------------------------------------------------------
  75. */
  76. // Remove all necessary files
  77. $element = &$module->getElementByPath('files');
  78. if (is_a($element, 'JSimpleXMLElement') && count($element->children())) {
  79. $this->parent->removeFiles($element, -1);
  80. }
  81. // Remove all necessary files
  82. $element = &$module->getElementByPath('media');
  83. if (is_a($element, 'JSimpleXMLElement') && count($element->children())) {
  84. $this->parent->removeFiles($element, -1);
  85. }
  86. $element = &$module->getElementByPath('languages');
  87. if (is_a($element, 'JSimpleXMLElement') && count($element->children())) {
  88. $this->parent->removeFiles($element, $mclient->id);
  89. }
  90. // Remove the installation folder
  91. if (!JFolder::delete($this->parent->getPath('extension_root'))) {
  92. }
  93. $status->modules[] = array('name'=>$mname,'client'=>$mclient->name);
  94. }
  95. }
  96. /***********************************************************************************************
  97. * ---------------------------------------------------------------------------------------------
  98. * PLUGIN REMOVAL SECTION
  99. * ---------------------------------------------------------------------------------------------
  100. ***********************************************************************************************/
  101. $plugins = &$this->manifest->getElementByPath('plugins');
  102. if (is_a($plugins, 'JSimpleXMLElement') && count($plugins->children())) {
  103. foreach ($plugins->children() as $plugin)
  104. {
  105. $pname = $plugin->attributes('plugin');
  106. $pgroup = $plugin->attributes('group');
  107. // Set the installation path
  108. if (!empty($pname) && !empty($pgroup)) {
  109. $this->parent->setPath('extension_root', JPATH_ROOT.DS.'plugins'.DS.$pgroup);
  110. } else {
  111. $this->parent->abort(JText::_('J_INSTALL_PLUGIN').' '.JText::_('J_INSTALL_UNINSTALL').': '.JText::_('J_INSTALL_PLUGIN_FILE_MISSING'));
  112. return false;
  113. }
  114. /**
  115. * ---------------------------------------------------------------------------------------------
  116. * Database Processing Section
  117. * ---------------------------------------------------------------------------------------------
  118. */
  119. $db = &JFactory::getDBO();
  120. // Delete the plugins in the #__plugins table
  121. $query = 'DELETE FROM #__plugins WHERE element = '.$db->Quote($pname).' AND folder = '.$db->Quote($pgroup);
  122. $db->setQuery($query);
  123. if (!$db->query()) {
  124. JError::raiseWarning(100, JText::_('J_INSTALL_PLUGIN').' '.JText::_('J_INSTALL_UNINSTALL').': '.$db->stderr(true));
  125. $retval = false;
  126. }
  127. /**
  128. * ---------------------------------------------------------------------------------------------
  129. * Filesystem Processing Section
  130. * ---------------------------------------------------------------------------------------------
  131. */
  132. // Remove all necessary files
  133. $element = &$plugin->getElementByPath('files');
  134. if (is_a($element, 'JSimpleXMLElement') && count($element->children())) {
  135. $this->parent->removeFiles($element, -1);
  136. }
  137. $element = &$plugin->getElementByPath('languages');
  138. if (is_a($element, 'JSimpleXMLElement') && count($element->children())) {
  139. $this->parent->removeFiles($element, 1);
  140. }
  141. // If the folder is empty, let's delete it
  142. $files = JFolder::files($this->parent->getPath('extension_root'));
  143. if (!count($files)) {
  144. JFolder::delete($this->parent->getPath('extension_root'));
  145. }
  146. $status->plugins[] = array('name'=>$pname,'group'=>$pgroup);
  147. }
  148. }
  149. /***********************************************************************************************
  150. * ---------------------------------------------------------------------------------------------
  151. * OUTPUT TO SCREEN
  152. * ---------------------------------------------------------------------------------------------
  153. ***********************************************************************************************/
  154. $rows = 0;
  155. ?>
  156. <h2><?php echo JText::_('COM_AAMENU_UnInstall_Heading');?></h2>
  157. <table class="adminlist">
  158. <thead>
  159. <tr>
  160. <th class="title" colspan="2"><?php echo JText::_('J_INSTALL_EXTENSION'); ?></th>
  161. <th width="30%"><?php echo JText::_('J_INSTALL_STATUS'); ?></th>
  162. </tr>
  163. </thead>
  164. <tfoot>
  165. <tr>
  166. <td colspan="3"></td>
  167. </tr>
  168. </tfoot>
  169. <tbody>
  170. <tr class="row0">
  171. <td class="key" colspan="2"><?php echo 'Advanced Administrator Menu '.JText::_('J_INSTALL_COMPONENT'); ?></td>
  172. <td><strong><?php echo JText::_('J_INSTALL_REMOVED'); ?></strong></td>
  173. </tr>
  174. <?php if (count($status->modules)) : ?>
  175. <tr>
  176. <th><?php echo JText::_('J_Install_Module'); ?></th>
  177. <th><?php echo JText::_('J_Install_Client'); ?></th>
  178. <th></th>
  179. </tr>
  180. <?php foreach ($status->modules as $module) : ?>
  181. <tr class="row<?php echo (++ $rows % 2); ?>">
  182. <td class="key"><?php echo $module['name']; ?></td>
  183. <td class="key"><?php echo ucfirst($module['client']); ?></td>
  184. <td><strong><?php echo JText::_('J_INSTALL_REMOVED'); ?></strong></td>
  185. </tr>
  186. <?php endforeach;
  187. endif;
  188. if (count($status->plugins)) : ?>
  189. <tr>
  190. <th><?php echo JText::_('J_INSTALL_PLUGIN'); ?></th>
  191. <th><?php echo JText::_('J_INSTALL_GROUP'); ?></th>
  192. <th></th>
  193. </tr>
  194. <?php foreach ($status->plugins as $plugin) : ?>
  195. <tr class="row<?php echo (++ $rows % 2); ?>">
  196. <td class="key"><?php echo ucfirst($plugin['name']); ?></td>
  197. <td class="key"><?php echo ucfirst($plugin['group']); ?></td>
  198. <td><strong><?php echo JText::_('J_INSTALL_REMOVED'); ?></strong></td>
  199. </tr>
  200. <?php endforeach;
  201. endif; ?>
  202. </tbody>
  203. </table>