PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 1ms app.codeStats 0ms

/install.weever.joomla.1.7.php

https://github.com/sphilp/com_weever
PHP | 384 lines | 236 code | 119 blank | 29 comment | 23 complexity | 533d7f4113350001719f3277a6453e04 MD5 | raw file
  1. <?php
  2. /*
  3. * Weever Apps Administrator Component for Joomla
  4. * (c) 2010-2011 Weever Apps Inc. <http://www.weeverapps.com/>
  5. *
  6. * Author: Robert Gerald Porter (rob@weeverapps.com)
  7. * Version: 1.2.3
  8. * License: GPL v3.0
  9. *
  10. * This extension is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This extension is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. defined('_JEXEC') or die;
  22. jimport("joomla.installer.installer");
  23. class com_WeeverInstallerScript
  24. {
  25. public function install($parent)
  26. {
  27. $manifest = $parent->get("manifest");
  28. $parent = $parent->getParent();
  29. $source = $parent->getPath("source");
  30. $lang = &JFactory::getLanguage();
  31. $lang->load("com_weever");
  32. $installer = new JInstaller();
  33. foreach($manifest->plugins->plugin as $plugin)
  34. {
  35. $attributes = $plugin->attributes();
  36. // 'folder' for install. No idea why this works.
  37. $plg = $source . DS . $attributes['folder'].DS.$attributes['plugin'];
  38. $result = $installer->install($plg);
  39. if($result)
  40. $message = "<span style='color:green'>".JText::_("WEEVER_SUCCESS")."</span>";
  41. else
  42. $message = "<span style='color:red'>".JText::_("WEEVER_FAILED")."</span>";
  43. ?>
  44. <p><?php echo JText::_("WEEVER_INSTALLING_PLUGIN"); ?><?php echo $attributes['folder']."/".$attributes['plugin'].": <b>".$message."</b>"; ?></p>
  45. <?php
  46. $this->enableExtension($attributes['plugin'], 'plugin');
  47. echo " <p><i>".JText::_("WEEVER_ENABLED_PLUGIN").$attributes['plugin']."</i></p>";
  48. }
  49. foreach($manifest->templates->template as $template)
  50. {
  51. $attributes = $template->attributes();
  52. $tmpl = $source . DS . 'templates'. DS . $attributes['template'];
  53. $result = $installer->install($tmpl);
  54. if($result)
  55. $message = "<span style='color:green'>".JText::_("WEEVER_SUCCESS")."</span>";
  56. else
  57. $message = "<span style='color:red'>".JText::_("WEEVER_FAILED")."</span>";
  58. ?>
  59. <p><?php echo JText::_("WEEVER_INSTALLING_TEMPLATE"); ?><?php echo $attributes['template'].": <b>".$message."</b>"; ?></p>
  60. <?php
  61. }
  62. if(!file_exists(JPATH_ROOT.DS."media".DS."com_weever".DS."phone_load_live.png"))
  63. copy(JPATH_ROOT.DS."media".DS."com_weever".DS."phone_load_.png", JPATH_ROOT.DS."media".DS."com_weever".DS."phone_load_live.png");
  64. if(!file_exists(JPATH_ROOT.DS."media".DS."com_weever".DS."icon_live.png"))
  65. copy(JPATH_ROOT.DS."media".DS."com_weever".DS."icon_.png", JPATH_ROOT.DS."media".DS."com_weever".DS."icon_live.png");
  66. if(!file_exists(JPATH_ROOT.DS."media".DS."com_weever".DS."tablet_load_live.png"))
  67. copy(JPATH_ROOT.DS."media".DS."com_weever".DS."tablet_load_.png", JPATH_ROOT.DS."media".DS."com_weever".DS."tablet_load_live.png");
  68. if(!file_exists(JPATH_ROOT.DS."media".DS."com_weever".DS."tablet_landscape_load_live.png"))
  69. copy(JPATH_ROOT.DS."media".DS."com_weever".DS."tablet_landscape_load_.png", JPATH_ROOT.DS."media".DS."com_weever".DS."tablet_landscape_load_live.png");
  70. if(!file_exists(JPATH_ROOT.DS."media".DS."com_weever".DS."titlebar_logo_live.png"))
  71. copy(JPATH_ROOT.DS."media".DS."com_weever".DS."titlebar_logo_.png", JPATH_ROOT.DS."media".DS."com_weever".DS."titlebar_logo_live.png");
  72. if(!function_exists("stream_context_create"))
  73. echo "<div style='color:#700; font-weight:bold'>".JText::_("WEEVER_ERROR_STREAM_CONTEXT_CREATE")."</div>";
  74. if(!function_exists("fopen"))
  75. echo "<div style='color:#700; font-weight:bold'>".JText::_("WEEVER_ERROR_STREAM_CONTEXT_CREATE")."</div>";
  76. if(!function_exists("stream_get_contents"))
  77. echo "<div style='color:#700; font-weight:bold'>".JText::_("WEEVER_ERROR_STREAM_CONTEXT_CREATE")."</div>";
  78. if(ini_get('allow_url_fopen') != 1)
  79. echo "<div style='color:#700; font-weight:bold'>".JText::_("WEEVER_ERROR_URL_FOPEN")."</div>";
  80. ?>
  81. <p><?php echo JText::_("WEEVER_INSTALL_WELCOME"); ?></p>
  82. <form action='index.php' enctype='multipart/form-data' method='post' name='adminForm' id='adminForm'>
  83. <div>
  84. <fieldset class='adminForm'>
  85. <legend><?php echo JText::_("WEEVER_INSTALL_SITE_KEY"); ?></legend>
  86. <p><i><?php echo JText::_("WEEVER_UPGRADE_NOTICE"); ?></i></p>
  87. <table class="admintable">
  88. <tr>
  89. <td><input type="text" name="site_key" maxlength="42" style="width:250px;" placeholder="Paste your Site Key here" value="" /><input type="submit" value="<?php echo JText::_("WEEVER_INSTALL_SUBMIT_KEY"); ?>" /> <?php echo JText::_("WEEVER_ALLOW_FEW_SECONDS"); ?></td>
  90. </tr>
  91. <tr>
  92. <td><input type="checkbox" name="staging" value="1" id="checkStaging" /> <label for="checkStaging"><?php echo JText::_("WEEVER_INSTALL_STAGING_MODE"); ?></label></td></tr>
  93. </table>
  94. </fieldset>
  95. </div>
  96. <input type="hidden" name="option" value="com_weever" />
  97. <input type="hidden" name="view" value="account" />
  98. <input type="hidden" name="task" value="save" />
  99. <input type="hidden" name="install" value="1" />
  100. <?php echo JHTML::_('form.token'); ?>
  101. </form>
  102. <?php
  103. }
  104. function enableExtension($ext, $type)
  105. {
  106. $db = JFactory::getDbo();
  107. $tableExtensions = $db->nameQuote("#__extensions");
  108. $columnElement = $db->nameQuote("element");
  109. $columnType = $db->nameQuote("type");
  110. $columnEnabled = $db->nameQuote("enabled");
  111. // Enable plugins
  112. $db->setQuery(
  113. "UPDATE
  114. ".$tableExtensions."
  115. SET
  116. ".$columnEnabled."='1'
  117. WHERE
  118. ".$columnElement."='".$ext."'
  119. AND
  120. ".$columnType."='".$type."'"
  121. );
  122. $db->query();
  123. }
  124. function getExtensionId($type, $name, $group='')
  125. {
  126. $db =& JFactory::getDBO();
  127. if($type=='plugin')
  128. $db->setQuery("SELECT extension_id FROM #__extensions WHERE `type`='".$type."' AND `folder`='".$group."' AND `element`='".$name."'");
  129. else
  130. $db->setQuery("SELECT extension_id FROM #__extensions WHERE `type`='".$type."' AND `element`='".$name."'");
  131. return $db->loadResult();
  132. }
  133. function uninstall($parent)
  134. {
  135. $manifest = $parent->get("manifest");
  136. $parent = $parent->getParent();
  137. $source = $parent->getPath("source");
  138. $lang = &JFactory::getLanguage();
  139. $lang->load("com_weever");
  140. $uninstaller = new JInstaller();
  141. foreach($manifest->plugins->plugin as $plugin)
  142. {
  143. $attributes = $plugin->attributes();
  144. // 'group' for uninstall.
  145. $id = $this->getExtensionId('plugin', $attributes['plugin'], $attributes['group']);
  146. $uninstaller->uninstall('plugin',$id,0);
  147. }
  148. foreach($manifest->templates->template as $template)
  149. {
  150. $attributes = $template->attributes();
  151. $id = $this->getExtensionId('template', $attributes['template']);
  152. $uninstaller->uninstall('template',$id);
  153. }
  154. }
  155. function update($parent)
  156. {
  157. $manifest = $parent->get("manifest");
  158. $parent = $parent->getParent();
  159. $source = $parent->getPath("source");
  160. $lang = &JFactory::getLanguage();
  161. $lang->load("com_weever");
  162. $uninstaller = new JInstaller();
  163. // remove legacy plugins
  164. // 0.9.2+
  165. $id = $this->getExtensionId('plugin', 'cartographer', 'system');
  166. if($id)
  167. $result = $uninstaller->uninstall('plugin',$id,0);
  168. if($result)
  169. $message = "<span style='color:green'>".JText::_("WEEVER_UNINSTALLED")."</span>";
  170. else
  171. $message = "<span style='color:grey'>".JText::_("WEEVER_NOT_PRESENT")."</span>";
  172. echo "<p>".JText::_("WEEVER_UNINSTALLING_PLUGIN")."system/cartographer: <b>".$message."</b></p>";
  173. $id = $this->getExtensionId('plugin', 'cartographerk2', 'system');
  174. if($id)
  175. $result = $uninstaller->uninstall('plugin',$id,0);
  176. if($result)
  177. $message = "<span style='color:green'>".JText::_("WEEVER_UNINSTALLED")."</span>";
  178. else
  179. $message = "<span style='color:grey'>".JText::_("WEEVER_NOT_PRESENT")."</span>";
  180. echo "<p>".JText::_("WEEVER_UNINSTALLING_PLUGIN")."system/cartographer_k2: <b>".$message."</b></p>";
  181. $id = $this->getExtensionId('template', 'weever_cartographerdetails');
  182. if($id)
  183. $result = $uninstaller->uninstall('template',$id,0);
  184. if($result)
  185. $message = "<span style='color:green'>".JText::_("WEEVER_UNINSTALLED")."</span>";
  186. else
  187. $message = "<span style='color:grey'>".JText::_("WEEVER_NOT_PRESENT")."</span>";
  188. echo "<p>".JText::_("WEEVER_UNINSTALLING_TEMPLATE")."templates/weever_cartographerdetails: <b>".$message."</b></p>";
  189. // end legacy removals
  190. $installer = new JInstaller();
  191. foreach($manifest->plugins->plugin as $plugin)
  192. {
  193. $attributes = $plugin->attributes();
  194. // 'folder' for install. No idea why this works.
  195. $plg = $source . DS . $attributes['folder'].DS.$attributes['plugin'];
  196. $result = $installer->install($plg);
  197. if($result)
  198. $message = "<span style='color:green'>".JText::_("WEEVER_SUCCESS")."</span>";
  199. else
  200. $message = "<span style='color:red'>".JText::_("WEEVER_FAILED")."</span>";
  201. ?>
  202. <p><?php echo JText::_("WEEVER_UPDATING_PLUGIN"); ?><?php echo $attributes['folder']."/".$attributes['plugin'].": <b>".$message."</b>"; ?></p>
  203. <?php
  204. $this->enableExtension($attributes['plugin'], 'plugin');
  205. echo " <p><i>".JText::_("WEEVER_ENABLED_PLUGIN").$attributes['plugin']."</i></p>";
  206. }
  207. foreach($manifest->templates->template as $template)
  208. {
  209. $attributes = $template->attributes();
  210. $tmpl = $source . DS . 'templates'. DS . $attributes['template'];
  211. $result = $installer->install($tmpl);
  212. if($result)
  213. $message = "<span style='color:green'>".JText::_("WEEVER_SUCCESS")."</span>";
  214. else
  215. $message = "<span style='color:red'>".JText::_("WEEVER_FAILED")."</span>";
  216. ?>
  217. <p><?php echo JText::_("WEEVER_UPDATING_TEMPLATE"); ?><?php echo $attributes['template'].": <b>".$message."</b>"; ?></p>
  218. <?php
  219. }
  220. $query = " SELECT `setting` FROM #__weever_config WHERE `option`='site_key' ";
  221. $db = &JFactory::getDBO();
  222. $db->setQuery($query);
  223. $key = @$db->loadObject();
  224. $query = " SELECT `setting` FROM #__weever_config WHERE `option`='loadspinner' ";
  225. $db = &JFactory::getDBO();
  226. $db->setQuery($query);
  227. $code = @$db->loadObject();
  228. if(!isset($code->setting))
  229. {
  230. $query = " INSERT IGNORE INTO `#__weever_config` VALUES(9, 'google_analytics', ''); ";
  231. $db = &JFactory::getDBO();
  232. $db->setQuery($query);
  233. @$db->loadObject();
  234. $query = " INSERT IGNORE INTO `#__weever_config` VALUES(10, 'domain', ''); ";
  235. $db = &JFactory::getDBO();
  236. $db->setQuery($query);
  237. @$db->loadObject();
  238. $query = " INSERT IGNORE INTO `#__weever_config` VALUES(11, 'loadspinner', ''); ";
  239. $db = &JFactory::getDBO();
  240. $db->setQuery($query);
  241. @$db->loadObject();
  242. }
  243. // check if there are server-side app updates to be made
  244. if($key->setting)
  245. {
  246. $response = file_get_contents('http://weeverapp.com/index.php?app=ajax&version=1.2.3&cms=joomla&m=upgrade&site_key='.$key->setting);
  247. ?>
  248. <form action='index.php' enctype='multipart/form-data' method='post' name='adminForm' id='adminForm'>
  249. <?php
  250. echo $response;
  251. echo JHTML::_('form.token');
  252. ?>
  253. </form>
  254. <?php
  255. }
  256. }
  257. function preflight($type, $parent)
  258. {
  259. //echo '<p>' . JText::_('COM_WEEVER_PREFLIGHT_' . $type . '_TEXT') . '</p>';
  260. }
  261. function postflight($type, $parent)
  262. {
  263. //echo '<p>' . JText::_('COM_WEEVER_POSTFLIGHT_' . $type . '_TEXT') . '</p>';
  264. }
  265. }