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

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

https://bitbucket.org/eddieajau/the-art-of-joomla-archive
PHP | 334 lines | 211 code | 43 blank | 80 comment | 36 complexity | 19c26fd8c4a81251dc5ce27dcc0e58b5 MD5 | raw file
  1. <?php
  2. /**
  3. * @version $Id: install.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', JPATH_ADMINISTRATOR.'/components/com_aamenu');
  15. //$nPaths = $this->_paths;
  16. $status = new JObject();
  17. $status->modules = array();
  18. $status->plugins = array();
  19. /***********************************************************************************************
  20. * ---------------------------------------------------------------------------------------------
  21. * MODULE INSTALLATION 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. // Set the installation path
  31. if (!empty ($mname)) {
  32. $this->parent->setPath('extension_root', $mclient->path.DS.'modules'.DS.$mname);
  33. } else {
  34. $this->parent->abort(JText::_('J_Install_Module').' '.JText::_('J_INSTALL_INSTALL').': '.JText::_('J_INSTALL_MODULE_FILE_MISSING'));
  35. return false;
  36. }
  37. /*
  38. * If the module directory already exists, then we will assume that the
  39. * module is already installed or another module is using that directory.
  40. */
  41. if (file_exists($this->parent->getPath('extension_root'))&&!$this->parent->getOverwrite()) {
  42. $this->parent->abort(JText::_('J_Install_Module').' '.JText::_('J_INSTALL_INSTALL').': '.JText::sprintf('J_INSTALL_MODULE_PATH_CONFLICT', $this->parent->getPath('extension_root')));
  43. return false;
  44. }
  45. // If the module directory does not exist, lets create it
  46. $created = false;
  47. if (!file_exists($this->parent->getPath('extension_root'))) {
  48. if (!$created = JFolder::create($this->parent->getPath('extension_root'))) {
  49. $this->parent->abort(JText::_('J_Install_Module').' '.JText::_('J_INSTALL_INSTALL').': '.JText::sprintf('J_INSTALL_MODULE_PATH_CREATE_FAILURE', $this->parent->getPath('extension_root')));
  50. return false;
  51. }
  52. }
  53. /*
  54. * Since we created the module directory and will want to remove it if
  55. * we have to roll back the installation, lets add it to the
  56. * installation step stack
  57. */
  58. if ($created) {
  59. $this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_root')));
  60. }
  61. // Copy all necessary files
  62. $element = &$module->getElementByPath('files');
  63. if ($this->parent->parseFiles($element, -1) === false) {
  64. // Install failed, roll back changes
  65. $this->parent->abort();
  66. return false;
  67. }
  68. // Copy language files
  69. $element = &$module->getElementByPath('languages');
  70. if ($this->parent->parseLanguages($element, $mclient->id) === false) {
  71. // Install failed, roll back changes
  72. $this->parent->abort();
  73. return false;
  74. }
  75. // Copy media files
  76. $element = &$module->getElementByPath('media');
  77. if ($this->parent->parseMedia($element, $mclient->id) === false) {
  78. // Install failed, roll back changes
  79. $this->parent->abort();
  80. return false;
  81. }
  82. $mtitle = $module->attributes('title');
  83. $mposition = $module->attributes('position');
  84. if ($mtitle && $mposition) {
  85. $row = & JTable::getInstance('module');
  86. $row->title = $mtitle;
  87. $row->ordering = $row->getNextOrder("position='".$mposition."'");
  88. $row->position = $mposition;
  89. $row->showtitle = 0;
  90. $row->iscore = 0;
  91. $row->access = ($mclient->id) == 1 ? 2 : 0;
  92. $row->client_id = $mclient->id;
  93. $row->module = $mname;
  94. $row->published = 0;
  95. $row->params = '';
  96. if (!$row->store()) {
  97. // Install failed, roll back changes
  98. $this->parent->abort(JText::_('J_INSTALL_MODULE').' '.JText::_('J_INSTALL_INSTALL').': '.$db->stderr(true));
  99. return false;
  100. }
  101. }
  102. $status->modules[] = array('name'=>$mname,'client'=>$mclient->name);
  103. }
  104. }
  105. /***********************************************************************************************
  106. * ---------------------------------------------------------------------------------------------
  107. * PLUGIN INSTALLATION SECTION
  108. * ---------------------------------------------------------------------------------------------
  109. ***********************************************************************************************/
  110. $plugins = &$this->manifest->getElementByPath('plugins');
  111. if (is_a($plugins, 'JSimpleXMLElement') && count($plugins->children())) {
  112. foreach ($plugins->children() as $plugin)
  113. {
  114. $pname = $plugin->attributes('plugin');
  115. $pgroup = $plugin->attributes('group');
  116. // Set the installation path
  117. if (!empty($pname) && !empty($pgroup)) {
  118. $this->parent->setPath('extension_root', JPATH_ROOT.DS.'plugins'.DS.$pgroup);
  119. } else {
  120. $this->parent->abort(JText::_('J_INSTALL_PLUGIN').' '.JText::_('J_INSTALL_INSTALL').': '.JText::_('J_INSTALL_PLUGIN_FILE_MISSING'));
  121. return false;
  122. }
  123. /**
  124. * ---------------------------------------------------------------------------------------------
  125. * Filesystem Processing Section
  126. * ---------------------------------------------------------------------------------------------
  127. */
  128. // If the plugin directory does not exist, lets create it
  129. $created = false;
  130. if (!file_exists($this->parent->getPath('extension_root'))) {
  131. if (!$created = JFolder::create($this->parent->getPath('extension_root'))) {
  132. $this->parent->abort(JText::_('J_INSTALL_PLUGIN').' '.JText::_('J_INSTALL_INSTALL').': '.JText::sprintf('J_INSTALL_PLUGIN_PATH_CREATE_FAILURE', $this->parent->getPath('extension_root')));
  133. return false;
  134. }
  135. }
  136. /*
  137. * If we created the plugin directory and will want to remove it if we
  138. * have to roll back the installation, lets add it to the installation
  139. * step stack
  140. */
  141. if ($created) {
  142. $this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_root')));
  143. }
  144. // Copy all necessary files
  145. $element = &$plugin->getElementByPath('files');
  146. if ($this->parent->parseFiles($element, -1) === false) {
  147. // Install failed, roll back changes
  148. $this->parent->abort();
  149. return false;
  150. }
  151. // Copy all necessary files
  152. $element = &$plugin->getElementByPath('languages');
  153. if ($this->parent->parseLanguages($element, 1) === false) {
  154. // Install failed, roll back changes
  155. $this->parent->abort();
  156. return false;
  157. }
  158. // Copy media files
  159. $element = &$plugin->getElementByPath('media');
  160. if ($this->parent->parseMedia($element, 1) === false) {
  161. // Install failed, roll back changes
  162. $this->parent->abort();
  163. return false;
  164. }
  165. /**
  166. * ---------------------------------------------------------------------------------------------
  167. * Database Processing Section
  168. * ---------------------------------------------------------------------------------------------
  169. */
  170. $db = &JFactory::getDBO();
  171. // Check to see if a plugin by the same name is already installed
  172. $query = 'SELECT `id`' .
  173. ' FROM `#__plugins`' .
  174. ' WHERE folder = '.$db->Quote($pgroup) .
  175. ' AND element = '.$db->Quote($pname);
  176. $db->setQuery($query);
  177. if (!$db->Query()) {
  178. // Install failed, roll back changes
  179. $this->parent->abort(JText::_('J_INSTALL_PLUGIN').' '.JText::_('J_INSTALL_INSTALL').': '.$db->stderr(true));
  180. return false;
  181. }
  182. $id = $db->loadResult();
  183. // Was there a plugin already installed with the same name?
  184. if ($id) {
  185. if (!$this->parent->getOverwrite())
  186. {
  187. // Install failed, roll back changes
  188. $this->parent->abort(JText::_('J_INSTALL_PLUGIN').' '.JText::_('J_INSTALL_INSTALL').': '.JText::sprintf('J_INSTALL_PLUGIN_ALREADY_EXISTS', $pname));
  189. return false;
  190. }
  191. } else {
  192. $row =& JTable::getInstance('plugin');
  193. $row->name = JText::_(ucfirst($pgroup)).' - '.JText::_(ucfirst($pname));
  194. $row->ordering = 0;
  195. $row->folder = $pgroup;
  196. $row->iscore = 0;
  197. $row->access = 0;
  198. $row->client_id = 0;
  199. $row->element = $pname;
  200. $row->published = 1;
  201. $row->params = '';
  202. if (!$row->store()) {
  203. // Install failed, roll back changes
  204. $this->parent->abort(JText::_('J_INSTALL_PLUGIN').' '.JText::_('J_INSTALL_INSTALL').': '.$db->stderr(true));
  205. return false;
  206. }
  207. }
  208. $status->plugins[] = array('name'=>$pname,'group'=>$pgroup);
  209. }
  210. }
  211. /***********************************************************************************************
  212. * ---------------------------------------------------------------------------------------------
  213. * SETUP DEFAULTS
  214. * ---------------------------------------------------------------------------------------------
  215. ***********************************************************************************************/
  216. // Insert a new installation record in the version log if no rows are present.
  217. $db = &JFactory::getDBO();
  218. $db->setQuery('SELECT COUNT(`version`) FROM `#__taoj` WHERE `extension` = '.$db->quote('com_aamenu'));
  219. require_once(dirname(dirname(__FILE__)).'/version.php');
  220. $version = new AAMenuVersion();
  221. if ($db->loadResult() == 0)
  222. {
  223. // Vanilla new install
  224. $db->setQuery(
  225. 'INSERT IGNORE INTO `#__taoj` (`extension`,`version`,`log`)' .
  226. ' VALUES ('.$db->quote('com_aamenu').','.$db->Quote($version->version.'.'.$version->subversion.$version->status).', '.$db->Quote('J_Install_New_Install').')'
  227. );
  228. $db->query();
  229. }
  230. // Correct bug in components table for backend only extenions
  231. $db->setQuery(
  232. 'UPDATE `#__components` SET `link` = '.$db->quote('').' WHERE `option` = '.$db->quote('com_aamenu')
  233. );
  234. if (!$db->query()) {
  235. JError::raiseWarning(500, $db->getErrorMsg());
  236. }
  237. /***********************************************************************************************
  238. * ---------------------------------------------------------------------------------------------
  239. * OUTPUT TO SCREEN
  240. * ---------------------------------------------------------------------------------------------
  241. ***********************************************************************************************/
  242. $rows = 0;
  243. ?>
  244. <?php echo JText::sprintf('COM_AAMENU_INSTALLED', $version->version.'.'.$version->subversion.' '.$version->status);?>
  245. <table class="adminlist">
  246. <thead>
  247. <tr>
  248. <th class="title" colspan="2"><?php echo JText::_('J_INSTALL_EXTENSION'); ?></th>
  249. <th width="30%"><?php echo JText::_('J_INSTALL_STATUS'); ?></th>
  250. </tr>
  251. </thead>
  252. <tfoot>
  253. <tr>
  254. <td colspan="3"></td>
  255. </tr>
  256. </tfoot>
  257. <tbody>
  258. <tr class="row0">
  259. <td class="key" colspan="2"><?php echo JText::_('COM_AAMENU').' '.JText::_('J_INSTALL_COMPONENT'); ?></td>
  260. <td><strong><?php echo JText::_('J_INSTALL_INSTALLED'); ?></strong></td>
  261. </tr>
  262. <?php if (count($status->modules)) : ?>
  263. <tr>
  264. <th><?php echo JText::_('J_INSTALL_MODULE'); ?></th>
  265. <th><?php echo JText::_('J_INSTALL_CLIENT'); ?></th>
  266. <th></th>
  267. </tr>
  268. <?php foreach ($status->modules as $module) : ?>
  269. <tr class="row<?php echo (++ $rows % 2); ?>">
  270. <td class="key"><?php echo $module['name']; ?></td>
  271. <td class="key"><?php echo ucfirst($module['client']); ?></td>
  272. <td><strong><?php echo JText::_('J_INSTALL_INSTALLED'); ?></strong></td>
  273. </tr>
  274. <?php endforeach;
  275. endif;
  276. if (count($status->plugins)) : ?>
  277. <tr>
  278. <th><?php echo JText::_('J_INSTALL_PLUGIN'); ?></th>
  279. <th><?php echo JText::_('J_INSTALL_GROUP'); ?></th>
  280. <th></th>
  281. </tr>
  282. <?php foreach ($status->plugins as $plugin) : ?>
  283. <tr class="row<?php echo (++ $rows % 2); ?>">
  284. <td class="key"><?php echo ucfirst($plugin['name']); ?></td>
  285. <td class="key"><?php echo ucfirst($plugin['group']); ?></td>
  286. <td><strong><?php echo JText::_('J_INSTALL_INSTALLED'); ?></strong></td>
  287. </tr>
  288. <?php endforeach;
  289. endif; ?>
  290. </tbody>
  291. </table>