PageRenderTime 56ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/administrator/components/com_joomfish/install/install.php

https://bitbucket.org/bekket/lviveurorent
PHP | 394 lines | 254 code | 49 blank | 91 comment | 42 complexity | 8178d0fd5d53f292bb814aa6f82288fd MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0
  1. <?php
  2. /**
  3. * @version $Id: install.php 33 2007-12-19 10:26:16Z andrew.eddie $
  4. * @package joomfish
  5. * @copyright 2003-2009 Think Network GmbH, Munich
  6. * @license GNU General Public License
  7. *
  8. * This is the special installer addon created by Andrew Eddie and the team of jXtended.
  9. * We thank for this cool idea of extending the installation process easily
  10. * copyright 2005-2008 New Life in IT Pty Ltd. All rights reserved.
  11. */
  12. // no direct access
  13. defined('_JEXEC') or die('Restricted access');
  14. //$nPaths = $this->_paths;
  15. $status = new JObject();
  16. $status->modules = array();
  17. $status->plugins = array();
  18. /***********************************************************************************************
  19. * ---------------------------------------------------------------------------------------------
  20. * MODULE INSTALLATION SECTION
  21. * ---------------------------------------------------------------------------------------------
  22. ***********************************************************************************************/
  23. $modules = &$this->manifest->getElementByPath('modules');
  24. if (is_a($modules, 'JSimpleXMLElement') && count($modules->children())) {
  25. foreach ($modules->children() as $module)
  26. {
  27. $mname = $module->attributes('module');
  28. $mclient = JApplicationHelper::getClientInfo($module->attributes('client'), true);
  29. // Set the installation path
  30. if (!empty ($mname)) {
  31. $this->parent->setPath('extension_root', $mclient->path.DS.'modules'.DS.$mname);
  32. } else {
  33. $this->parent->abort(JText::_('Module').' '.JText::_('Install').': '.JText::_('No module file specified'));
  34. return false;
  35. }
  36. /*
  37. * If the module directory already exists, then we will assume that the
  38. * module is already installed or another module is using that directory.
  39. */
  40. if (file_exists($this->parent->getPath('extension_root'))&&!$this->parent->getOverwrite()) {
  41. $this->parent->abort(JText::_('Module').' '.JText::_('Install').': '.JText::_('Another module is already using directory').': "'.$this->parent->getPath('extension_root').'"');
  42. return false;
  43. }
  44. // If the module directory does not exist, lets create it
  45. $created = false;
  46. if (!file_exists($this->parent->getPath('extension_root'))) {
  47. if (!$created = JFolder::create($this->parent->getPath('extension_root'))) {
  48. $this->parent->abort(JText::_('Module').' '.JText::_('Install').': '.JText::_('Failed to create directory').': "'.$this->parent->getPath('extension_root').'"');
  49. return false;
  50. }
  51. }
  52. /*
  53. * Since we created the module directory and will want to remove it if
  54. * we have to roll back the installation, lets add it to the
  55. * installation step stack
  56. */
  57. if ($created) {
  58. $this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_root')));
  59. }
  60. // Copy all necessary files
  61. $element = &$module->getElementByPath('files');
  62. if ($this->parent->parseFiles($element, -1) === false) {
  63. // Install failed, roll back changes
  64. $this->parent->abort();
  65. return false;
  66. }
  67. // Copy language files
  68. $element = &$module->getElementByPath('languages');
  69. if ($this->parent->parseLanguages($element, $mclient->id) === false) {
  70. // Install failed, roll back changes
  71. $this->parent->abort();
  72. return false;
  73. }
  74. // Copy media files
  75. $element = &$module->getElementByPath('media');
  76. if ($this->parent->parseMedia($element, $mclient->id) === false) {
  77. // Install failed, roll back changes
  78. $this->parent->abort();
  79. return false;
  80. }
  81. $mtitle = $module->attributes('title');
  82. $mposition = $module->attributes('position');
  83. $morder = $module->attributes('order');
  84. if ($mtitle && $mposition) {
  85. // if module already installed do not create a new instance
  86. $db =& JFactory::getDBO();
  87. $query = 'SELECT `id` FROM `#__modules` WHERE module = '.$db->Quote( $mname);
  88. $db->setQuery($query);
  89. if (!$db->Query()) {
  90. // Install failed, roll back changes
  91. $this->parent->abort(JText::_('Module').' '.JText::_('Install').': '.$db->stderr(true));
  92. return false;
  93. }
  94. $id = $db->loadResult();
  95. if (!$id){
  96. $row = & JTable::getInstance('module');
  97. $row->title = $mtitle;
  98. $row->ordering = $morder;
  99. $row->position = $mposition;
  100. $row->showtitle = 0;
  101. $row->iscore = 0;
  102. $row->access = ($mclient->id) == 1 ? 2 : 0;
  103. $row->client_id = $mclient->id;
  104. $row->module = $mname;
  105. $row->published = 1;
  106. $row->params = '';
  107. if (!$row->store()) {
  108. // Install failed, roll back changes
  109. $this->parent->abort(JText::_('Module').' '.JText::_('Install').': '.$db->stderr(true));
  110. return false;
  111. }
  112. // Make visible evertywhere if site module
  113. if ($mclient->id==0){
  114. $query = 'REPLACE INTO `#__modules_menu` (moduleid,menuid) values ('.$db->Quote( $row->id).',0)';
  115. $db->setQuery($query);
  116. if (!$db->query()) {
  117. // Install failed, roll back changes
  118. $this->parent->abort(JText::_('Module').' '.JText::_('Install').': '.$db->stderr(true));
  119. return false;
  120. }
  121. }
  122. }
  123. }
  124. $status->modules[] = array('name'=>$mname,'client'=>$mclient->name);
  125. }
  126. }
  127. /***********************************************************************************************
  128. * ---------------------------------------------------------------------------------------------
  129. * PLUGIN INSTALLATION SECTION
  130. * ---------------------------------------------------------------------------------------------
  131. ***********************************************************************************************/
  132. $plugins = &$this->manifest->getElementByPath('plugins');
  133. if (is_a($plugins, 'JSimpleXMLElement') && count($plugins->children())) {
  134. foreach ($plugins->children() as $plugin)
  135. {
  136. $pname = $plugin->attributes('plugin');
  137. $pgroup = $plugin->attributes('group');
  138. $porder = $plugin->attributes('order');
  139. // Set the installation path
  140. if (!empty($pname) && !empty($pgroup)) {
  141. $this->parent->setPath('extension_root', JPATH_ROOT.DS.'plugins'.DS.$pgroup);
  142. } else {
  143. $this->parent->abort(JText::_('Plugin').' '.JText::_('Install').': '.JText::_('No plugin file specified'));
  144. return false;
  145. }
  146. /**
  147. * ---------------------------------------------------------------------------------------------
  148. * Filesystem Processing Section
  149. * ---------------------------------------------------------------------------------------------
  150. */
  151. // If the plugin directory does not exist, lets create it
  152. $created = false;
  153. if (!file_exists($this->parent->getPath('extension_root'))) {
  154. if (!$created = JFolder::create($this->parent->getPath('extension_root'))) {
  155. $this->parent->abort(JText::_('Plugin').' '.JText::_('Install').': '.JText::_('Failed to create directory').': "'.$this->parent->getPath('extension_root').'"');
  156. return false;
  157. }
  158. }
  159. /*
  160. * If we created the plugin directory and will want to remove it if we
  161. * have to roll back the installation, lets add it to the installation
  162. * step stack
  163. */
  164. if ($created) {
  165. $this->parent->pushStep(array ('type' => 'folder', 'path' => $this->parent->getPath('extension_root')));
  166. }
  167. // Copy all necessary files
  168. $element = &$plugin->getElementByPath('files');
  169. if ($this->parent->parseFiles($element, -1) === false) {
  170. // Install failed, roll back changes
  171. $this->parent->abort();
  172. return false;
  173. }
  174. // Copy all necessary files
  175. $element = &$plugin->getElementByPath('languages');
  176. if ($this->parent->parseLanguages($element, 1) === false) {
  177. // Install failed, roll back changes
  178. $this->parent->abort();
  179. return false;
  180. }
  181. // Copy media files
  182. $element = &$plugin->getElementByPath('media');
  183. if ($this->parent->parseMedia($element, 1) === false) {
  184. // Install failed, roll back changes
  185. $this->parent->abort();
  186. return false;
  187. }
  188. /**
  189. * ---------------------------------------------------------------------------------------------
  190. * Database Processing Section
  191. * ---------------------------------------------------------------------------------------------
  192. */
  193. $db = &JFactory::getDBO();
  194. // Check to see if a plugin by the same name is already installed
  195. $query = 'SELECT `id`' .
  196. ' FROM `#__plugins`' .
  197. ' WHERE folder = '.$db->Quote($pgroup) .
  198. ' AND element = '.$db->Quote($pname);
  199. $db->setQuery($query);
  200. if (!$db->Query()) {
  201. // Install failed, roll back changes
  202. $this->parent->abort(JText::_('Plugin').' '.JText::_('Install').': '.$db->stderr(true));
  203. return false;
  204. }
  205. $id = $db->loadResult();
  206. // Was there a plugin already installed with the same name?
  207. if ($id) {
  208. if (!$this->parent->getOverwrite())
  209. {
  210. // Install failed, roll back changes
  211. $this->parent->abort(JText::_('Plugin').' '.JText::_('Install').': '.JText::_('Plugin').' "'.$pname.'" '.JText::_('already exists!'));
  212. return false;
  213. }
  214. } else {
  215. $row =& JTable::getInstance('plugin');
  216. $row->name = JText::_(ucfirst($pgroup)).' - '.JText::_(ucfirst($pname));
  217. $row->ordering = $porder;
  218. $row->folder = $pgroup;
  219. $row->iscore = 0;
  220. $row->access = 0;
  221. $row->client_id = 0;
  222. $row->element = $pname;
  223. $row->published = 1;
  224. $row->params = '';
  225. if (!$row->store()) {
  226. // Install failed, roll back changes
  227. $this->parent->abort(JText::_('Plugin').' '.JText::_('Install').': '.$db->stderr(true));
  228. return false;
  229. }
  230. }
  231. $status->plugins[] = array('name'=>$pname,'group'=>$pgroup);
  232. }
  233. }
  234. /***********************************************************************************************
  235. * ---------------------------------------------------------------------------------------------
  236. * SETUP DEFAULTS
  237. * ---------------------------------------------------------------------------------------------
  238. ***********************************************************************************************/
  239. // Check to see if a plugin by the same name is already installed
  240. $query = 'SELECT `id`' .
  241. ' FROM `#__components`' .
  242. ' WHERE parent = 0 and name=' .$db->Quote('Joom!Fish').
  243. ' AND parent = 0';
  244. $db->setQuery($query);
  245. $componentID = $db->loadResult();
  246. if(!is_null($componentID) && $componentID > 0) {
  247. $query = 'UPDATE #__components SET params = '
  248. . $db->Quote("noTranslation=2\n"
  249. . "defaultText=\n"
  250. . "overwriteGlobalConfig=1\n"
  251. . "storageOfOriginal=md5\n"
  252. . "frontEndPublish=1\n"
  253. . "frontEndPreview=1\n"
  254. . "showPanelNews=1\n"
  255. . "showPanelUnpublished=1\n"
  256. . "showPanelState=1\n"
  257. . "copyparams=1\n"
  258. . "transcaching=0\n"
  259. . "cachelife=180\n"
  260. . "qacaching=1\n"
  261. . "qalogging=0\n")
  262. . 'WHERE id = ' . $componentID;
  263. $db->setQuery($query);
  264. if (!$db->Query()) {
  265. // Install failed, roll back changes
  266. $this->parent->abort(JText::_('Plugin').' '.JText::_('Install').': '.$db->stderr(true));
  267. return false;
  268. }
  269. }
  270. // Insert the default lanauage if no language exist
  271. $query = 'SELECT count(*) FROM #__languages';
  272. $db->setQuery($query);
  273. $count = $db->loadResult();
  274. if($count==0) {
  275. $query = 'INSERT INTO #__languages VALUES (1, '
  276. .$db->quote('English (United Kingdom)')
  277. . ', 1, ' .$db->quote('en_GB.utf8, en_GB.UT'). ', ' . $db->quote('en-GB')
  278. . ', '. $db->quote('en') .', '. $db->quote('').', '. $db->quote('').', '. $db->quote(''). ', 1);';
  279. $db->execute($query);
  280. }
  281. /***********************************************************************************************
  282. * ---------------------------------------------------------------------------------------------
  283. * Execute specific system steps to ensure a consistent installtion
  284. * ---------------------------------------------------------------------------------------------
  285. ***********************************************************************************************/
  286. // check if prePost_translations.xml exist and if yes remove it
  287. if( JFile::exists(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'contentelements'.DS.'prepostTranslation.xml') ) {
  288. JFile::delete(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_joomfish'.DS.'contentelements'.DS.'prepostTranslation.xml');
  289. }
  290. /***********************************************************************************************
  291. * ---------------------------------------------------------------------------------------------
  292. * OUTPUT TO SCREEN
  293. * ---------------------------------------------------------------------------------------------
  294. ***********************************************************************************************/
  295. $rows = 0;
  296. ?>
  297. <img src="components/com_joomfish/assets/images/joomfish_slogan.png" width="138" height="50" alt="Joom!Fish Multilingual Content Manager" align="right" />
  298. <h2>Joom!Fish Installation</h2>
  299. <table class="adminlist">
  300. <thead>
  301. <tr>
  302. <th class="title" colspan="2"><?php echo JText::_('Extension'); ?></th>
  303. <th width="30%"><?php echo JText::_('Status'); ?></th>
  304. </tr>
  305. </thead>
  306. <tfoot>
  307. <tr>
  308. <td colspan="3"></td>
  309. </tr>
  310. </tfoot>
  311. <tbody>
  312. <tr class="row0">
  313. <td class="key" colspan="2"><?php echo 'Joom!Fish '.JText::_('Component'); ?></td>
  314. <td><strong><?php echo JText::_('Installed'); ?></strong></td>
  315. </tr>
  316. <?php if (count($status->modules)) : ?>
  317. <tr>
  318. <th><?php echo JText::_('Module'); ?></th>
  319. <th><?php echo JText::_('Client'); ?></th>
  320. <th></th>
  321. </tr>
  322. <?php foreach ($status->modules as $module) : ?>
  323. <tr class="row<?php echo (++ $rows % 2); ?>">
  324. <td class="key"><?php echo $module['name']; ?></td>
  325. <td class="key"><?php echo ucfirst($module['client']); ?></td>
  326. <td><strong><?php echo JText::_('Installed'); ?></strong></td>
  327. </tr>
  328. <?php endforeach;
  329. endif;
  330. if (count($status->plugins)) : ?>
  331. <tr>
  332. <th><?php echo JText::_('Plugin'); ?></th>
  333. <th><?php echo JText::_('Group'); ?></th>
  334. <th></th>
  335. </tr>
  336. <?php foreach ($status->plugins as $plugin) : ?>
  337. <tr class="row<?php echo (++ $rows % 2); ?>">
  338. <td class="key"><?php echo ucfirst($plugin['name']); ?></td>
  339. <td class="key"><?php echo ucfirst($plugin['group']); ?></td>
  340. <td><strong><?php echo JText::_('Installed'); ?></strong></td>
  341. </tr>
  342. <?php endforeach;
  343. endif; ?>
  344. </tbody>
  345. </table>