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

/install.script.php

https://github.com/vuvvn/ecwid-joomla-plugin
PHP | 195 lines | 150 code | 23 blank | 22 comment | 11 complexity | 7ac6a8ef4e17c6d5953c73bad37bef96 MD5 | raw file
  1. <?php
  2. /**
  3. * @package gantry
  4. * @subpackage core
  5. * @version 1.3 March 1, 2011
  6. * @author RocketTheme http://www.rockettheme.com
  7. * @copyright Copyright (C) 2007 - 2011 RocketTheme, LLC
  8. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
  9. *
  10. * Gantry uses the Joomla Framework (http://www.joomla.org), a GNU/GPLv2 content management system
  11. *
  12. */
  13. class PlgSystemInstallerInstallerScript
  14. {
  15. protected $packages = array();
  16. protected $sourcedir;
  17. protected $installerdir;
  18. protected $manifest;
  19. protected function setup($parent){
  20. $this->sourcedir = $parent->getParent()->getPath('source');
  21. $this->manifest = $parent->getParent()->getManifest();
  22. $this->installerdir = $this->sourcedir . DS . 'installer';
  23. }
  24. public function install($parent)
  25. {
  26. jimport('joomla.filesystem.file');
  27. jimport('joomla.filesystem.folder');
  28. $retval = true;
  29. $buffer = '';
  30. $install_html_file = dirname(__FILE__).'/install.html';
  31. $install_css_file = dirname(__FILE__).'/install.css';
  32. $tmp_path = JPATH_ROOT . '/tmp';
  33. // Drop out Style
  34. if (file_exists($install_css_file)){
  35. $buffer .= JFile::read($install_html_file);
  36. }
  37. if (JFolder::exists($tmp_path)){
  38. // Copy install.css to tmp dir for inclusion
  39. JFile::copy($install_css_file, $tmp_path.'/install.css');
  40. }
  41. // Opening HTML
  42. ob_start();
  43. ?>
  44. <div id="rokinstall-logo">
  45. <ul id="rokinstall-status">
  46. <?php
  47. $buffer .= ob_get_clean();
  48. // Cycle through cogs and install each
  49. if (count($this->manifest->cogs->children()))
  50. {
  51. require_once($this->installerdir . DS . 'RokInstaller.php');
  52. foreach ($this->manifest->cogs->children() as $cog)
  53. {
  54. $folder = $this->sourcedir . DS . trim($cog);
  55. jimport('joomla.installer.helper');
  56. if (is_dir($folder))
  57. {
  58. // if its actually a directory then fill it up
  59. $package = Array();
  60. $package['dir'] = $folder;
  61. $package['type'] = JInstallerHelper::detectType($folder);
  62. $package['installer'] = new RokInstaller();
  63. $package['name'] = (string)$cog->name;
  64. $package['state'] = 'Success';
  65. $package['description'] = (string)$cog->description;
  66. $package['msg'] = '';
  67. $package['type'] = ucfirst((string)$cog['type']);
  68. $package['installer']->setCogInfo($cog);
  69. // add installer to static for possible rollback
  70. $this->packages[] = $package;
  71. if (!$package['installer']->install($package['dir']))
  72. {
  73. while ($error = JError::getError(true)){
  74. $package['msg'] .= $error;
  75. }
  76. $buffer .= $this->printerror($package,$package['msg']);
  77. //$this->abort();
  78. break;
  79. }
  80. if ($package['installer']->getInstallType() == 'install'){
  81. $buffer .= $this->printInstall($package);
  82. }
  83. else {
  84. $buffer .= $this->printUpdate($package);
  85. }
  86. }
  87. else {
  88. $package = Array();
  89. $package['dir'] = $folder;
  90. $package['name'] = (string)$cog->name;
  91. $package['state'] = 'Failed';
  92. $package['description'] = (string)$cog->description;
  93. $package['msg'] = '';
  94. $package['type'] = ucfirst((string)$cog['type']);
  95. $buffer .= $this->printerror($package, JText::_('JLIB_INSTALLER_ABORT_NOINSTALLPATH'));
  96. //$this->abort();
  97. break;
  98. }
  99. }
  100. }
  101. else
  102. {
  103. $parent->getParent()->abort(JText::sprintf('JLIB_INSTALLER_ABORT_PACK_INSTALL_NO_FILES', JText::_('JLIB_INSTALLER_' . strtoupper($this->route))));
  104. }
  105. // Closing HTML
  106. ob_start();
  107. ?>
  108. </ul>
  109. </div>
  110. <?php
  111. $buffer .= ob_get_clean();
  112. // Return stuff
  113. echo $buffer;
  114. return $retval;
  115. }
  116. public function uninstall($parent)
  117. {
  118. }
  119. public function update($parent)
  120. {
  121. return $this->install($parent);
  122. }
  123. public function preflight($type, $parent)
  124. {
  125. $this->setup($parent);
  126. //Load Event Handler
  127. $event_handler_file = $this->installerdir.'/RokInstallerEvents.php';
  128. require_once($event_handler_file);
  129. $dispatcher =& JDispatcher::getInstance();
  130. new RokInstallerEvents($dispatcher);
  131. }
  132. public function postflight($type, $parent)
  133. {
  134. $parent->getParent()->abort();
  135. }
  136. public function abort($msg=null, $type=null){
  137. if ($msg) {
  138. JError::raiseWarning(100, $msg);
  139. }
  140. foreach($this->packages as $package){
  141. $package['installer']->abort(null,$type);
  142. }
  143. }
  144. public function printerror($package, $msg){
  145. ob_start();
  146. ?>
  147. <li class="rokinstall-failure"><span class="rokinstall-row"><span class="rokinstall-icon"></span><?php echo $package['name'];?> installation failed</span>
  148. <span class="rokinstall-errormsg">
  149. <?php echo $msg; ?>
  150. </span>
  151. </li>
  152. <?php
  153. $out = ob_get_clean();
  154. return $out;
  155. }
  156. public function printInstall($package){
  157. ob_start();
  158. ?>
  159. <li class="rokinstall-success"><span class="rokinstall-row"><span class="rokinstall-icon"></span><?php echo $package['name'];?> installation was successful</span></li>
  160. <?php
  161. $out = ob_get_clean();
  162. return $out;
  163. }
  164. public function printUpdate($package){
  165. ob_start();
  166. ?>
  167. <li class="rokinstall-update"><span class="rokinstall-row"><span class="rokinstall-icon"></span><?php echo $package['name'];?> update was successful</span></li>
  168. <?php
  169. $out = ob_get_clean();
  170. return $out;
  171. }
  172. }