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

/administrator/components/com_jce/installer/plugins/plugins.class.php

https://bitbucket.org/dgough/annamaria-daneswood-25102012
PHP | 207 lines | 142 code | 29 blank | 36 comment | 29 complexity | 4f7891f7cf1dcddec9db2a75b7f97162 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: mambot.class.php 393 2005-10-08 13:37:52Z akede $
  4. * @package Joomla
  5. * @subpackage Installer
  6. * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14. // no direct access
  15. defined( '_VALID_MOS' ) or die( 'Restricted access' );
  16. /**
  17. * Module installer
  18. * @package Joomla
  19. * @subpackage Installer
  20. */
  21. class JCEPluginInstaller extends mosInstaller {
  22. /**
  23. * Custom install method
  24. * @param boolean True if installing from directory
  25. */
  26. function install( $p_fromdir = null ) {
  27. global $mosConfig_absolute_path, $database;
  28. if (!$this->preInstallCheck( $p_fromdir, 'jceplugin' )) {
  29. return false;
  30. }
  31. $xmlDoc = $this->xmlDoc();
  32. $mosinstall =& $xmlDoc->documentElement;
  33. // Set some vars
  34. $e = &$mosinstall->getElementsByPath( 'name', 1 );
  35. $this->elementName( $e->getText() );
  36. $folder = $mosinstall->getAttribute( 'plugin' );
  37. $this->elementDir( mosPathName( $mosConfig_absolute_path . '/mambots/editors/jce/jscripts/tiny_mce/plugins/' . $folder ) );
  38. if(!file_exists($this->elementDir()) && !mosMakePath($this->elementDir())) {
  39. $this->setError( 1, 'Failed to create directory "' . $this->elementDir() . '"' );
  40. return false;
  41. }
  42. if ($this->parseFiles( 'files', 'plugin', 'No file is marked as plugin file' ) === false) {
  43. return false;
  44. }
  45. // Insert mambot in DB
  46. $query = "SELECT id"
  47. . "\n FROM #__jce_plugins"
  48. . "\n WHERE plugin = '" . $this->elementName() . "'"
  49. ;
  50. $database->setQuery( $query );
  51. if (!$database->query()) {
  52. $this->setError( 1, 'SQL error: ' . $database->stderr( true ) );
  53. return false;
  54. }
  55. $id = $database->loadResult();
  56. if (!$id) {
  57. $row = new jcePlugins( $database );
  58. $row->name = $this->elementName();
  59. $row->plugin = $folder;
  60. $element = &$mosinstall->getElementsByPath( 'icon', 1 );
  61. $row->icon = $element ? $element->getText() : '';
  62. $element = &$mosinstall->getElementsByPath( 'layout_icon', 1 );
  63. $row->layout_icon = $element ? $element->getText() : '';
  64. $row->type = 'plugin';
  65. $row->access = 18;
  66. $row->row = 4;
  67. $row->ordering = 1;
  68. $row->published = 1;
  69. $row->editable = 1;
  70. $element = &$mosinstall->getElementsByPath( 'elements', 1 );
  71. $row->elements = $element ? $element->getText() : '';
  72. $row->iscore = 0;
  73. if (!$row->store()) {
  74. $this->setError( 1, 'SQL error: ' . $row->getError() );
  75. return false;
  76. }
  77. } else {
  78. $this->setError( 1, 'Plugin "' . $this->elementName() . '" already exists!' );
  79. return false;
  80. }
  81. if ($e = &$mosinstall->getElementsByPath( 'description', 1 )) {
  82. $this->setError( 0, $this->elementName() . '<p>' . $e->getText() . '</p>' );
  83. }
  84. return $this->copySetupFile('front');
  85. }
  86. /**
  87. * Custom install method
  88. * @param int The id of the module
  89. * @param string The URL option
  90. * @param int The client id
  91. */
  92. function uninstall( $id, $option, $client=0 ) {
  93. global $database, $mosConfig_absolute_path;
  94. $id = intval( $id );
  95. $query = "SELECT name, plugin, iscore"
  96. . "\n FROM #__jce_plugins"
  97. . "\n WHERE id = $id"
  98. ;
  99. $database->setQuery( $query );
  100. $row = null;
  101. $database->loadObject( $row );
  102. if ($database->getErrorNum()) {
  103. HTML_installer::showInstallMessage( $database->stderr(), 'Uninstall - error',
  104. $this->returnTo( $option, 'install&element=plugins', $client ) );
  105. exit();
  106. }
  107. if ($row == null) {
  108. HTML_installer::showInstallMessage( 'Invalid object id', 'Uninstall - error',
  109. $this->returnTo( $option, 'install&element=plugins', $client ) );
  110. exit();
  111. }
  112. if (trim( $row->plugin ) == '') {
  113. HTML_installer::showInstallMessage( 'Folder field empty, cannot remove files', 'Uninstall - error',
  114. $this->returnTo( $option, 'install&element=plugins', $client ) );
  115. exit();
  116. }
  117. $basepath = $mosConfig_absolute_path . '/mambots/editors/jce/jscripts/tiny_mce/plugins/' . $row->plugin . '/';
  118. $xmlfile = $basepath . $row->plugin . '.xml';
  119. // see if there is an xml install file, must be same name as element
  120. if (file_exists( $xmlfile )) {
  121. $this->i_xmldoc = new DOMIT_Lite_Document();
  122. $this->i_xmldoc->resolveErrors( true );
  123. if ($this->i_xmldoc->loadXML( $xmlfile, false, true )) {
  124. $mosinstall =& $this->i_xmldoc->documentElement;
  125. // get the files element
  126. $files_element =& $mosinstall->getElementsByPath( 'files', 1 );
  127. if (!is_null( $files_element )) {
  128. $files = $files_element->childNodes;
  129. foreach ($files as $file) {
  130. // delete the files
  131. $filename = $file->getText();
  132. if (file_exists( $basepath . $filename )) {
  133. $parts = pathinfo( $filename );
  134. $subpath = $parts['dirname'];
  135. if ($subpath != '' && $subpath != '.' && $subpath != '..') {
  136. echo '<br />Deleting: '. $basepath . $subpath;
  137. $result = deldir(mosPathName( $basepath . $subpath . '/' ));
  138. } else {
  139. echo '<br />Deleting: '. $basepath . $filename;
  140. $result = unlink( mosPathName ($basepath . $filename, false));
  141. }
  142. echo intval( $result );
  143. }
  144. }
  145. // remove XML file from front
  146. echo "Deleting XML File: $xmlfile";
  147. @unlink( mosPathName ($xmlfile, false ) );
  148. // define folders that should not be removed
  149. $sysFolders = array(
  150. 'content',
  151. 'search'
  152. );
  153. if (!in_array( $row->folder, $sysFolders )) {
  154. // delete the non-system folders if empty
  155. if (count( mosReadDirectory( $basepath ) ) < 1) {
  156. deldir( $basepath );
  157. }
  158. }
  159. }
  160. }
  161. }
  162. if ($row->iscore) {
  163. HTML_installer::showInstallMessage( $row->name .' is a core element, and cannot be uninstalled.<br />You need to unpublish it if you don\'t want to use it',
  164. 'Uninstall - error', $this->returnTo( $option, 'install&element=plugins', $client ) );
  165. exit();
  166. }
  167. $query = "DELETE FROM #__jce_plugins"
  168. . "\n WHERE id = $id"
  169. ;
  170. $database->setQuery( $query );
  171. if (!$database->query()) {
  172. $msg = $database->stderr;
  173. die( $msg );
  174. }
  175. return true;
  176. }
  177. }
  178. ?>