[ Index ] |
|
Code source de Joomla 1.0.13 |
1 <?php 2 /** 3 * @version $Id: mambot.class.php 4996 2006-09-10 16:33:55Z friesengeist $ 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 15 // no direct access 16 defined( '_VALID_MOS' ) or die( 'Restricted access' ); 17 18 /** 19 * Module installer 20 * @package Joomla 21 * @subpackage Installer 22 */ 23 class mosInstallerMambot extends mosInstaller { 24 /** 25 * Custom install method 26 * @param boolean True if installing from directory 27 */ 28 function install( $p_fromdir = null ) { 29 global $mosConfig_absolute_path, $database; 30 31 if (!$this->preInstallCheck( $p_fromdir, 'mambot' )) { 32 return false; 33 } 34 35 $xmlDoc = $this->xmlDoc(); 36 $mosinstall =& $xmlDoc->documentElement; 37 38 // Set some vars 39 $e = &$mosinstall->getElementsByPath( 'name', 1 ); 40 $this->elementName( $e->getText() ); 41 42 $folder = $mosinstall->getAttribute( 'group' ); 43 $this->elementDir( mosPathName( $mosConfig_absolute_path . '/mambots/' . $folder ) ); 44 45 if(!file_exists($this->elementDir()) && !mosMakePath($this->elementDir())) { 46 $this->setError( 1, 'Failed to create directory "' . $this->elementDir() . '"' ); 47 return false; 48 } 49 50 if ($this->parseFiles( 'files', 'mambot', 'No file is marked as mambot file' ) === false) { 51 return false; 52 } 53 54 // Insert mambot in DB 55 $query = "SELECT id" 56 . "\n FROM #__mambots" 57 . "\n WHERE element = " . $database->Quote( $this->elementName() ) 58 ; 59 $database->setQuery( $query ); 60 if (!$database->query()) { 61 $this->setError( 1, 'SQL error: ' . $database->stderr( true ) ); 62 return false; 63 } 64 65 $id = $database->loadResult(); 66 67 if (!$id) { 68 $row = new mosMambot( $database ); 69 $row->name = $this->elementName(); 70 $row->ordering = 0; 71 $row->folder = $folder; 72 $row->iscore = 0; 73 $row->access = 0; 74 $row->client_id = 0; 75 $row->element = $this->elementSpecial(); 76 77 if ($folder == 'editors') { 78 $row->published = 1; 79 } 80 81 if (!$row->store()) { 82 $this->setError( 1, 'SQL error: ' . $row->getError() ); 83 return false; 84 } 85 } else { 86 $this->setError( 1, 'Mambot "' . $this->elementName() . '" already exists!' ); 87 return false; 88 } 89 if ($e = &$mosinstall->getElementsByPath( 'description', 1 )) { 90 $this->setError( 0, $this->elementName() . '<p>' . $e->getText() . '</p>' ); 91 } 92 93 return $this->copySetupFile('front'); 94 } 95 /** 96 * Custom install method 97 * @param int The id of the module 98 * @param string The URL option 99 * @param int The client id 100 */ 101 function uninstall( $id, $option, $client=0 ) { 102 global $database, $mosConfig_absolute_path; 103 104 $id = intval( $id ); 105 $query = "SELECT name, folder, element, iscore" 106 . "\n FROM #__mambots" 107 . "\n WHERE id = " . (int) $id 108 ; 109 $database->setQuery( $query ); 110 111 $row = null; 112 $database->loadObject( $row ); 113 if ($database->getErrorNum()) { 114 HTML_installer::showInstallMessage( $database->stderr(), 'Uninstall - error', 115 $this->returnTo( $option, 'mambot', $client ) ); 116 exit(); 117 } 118 if ($row == null) { 119 HTML_installer::showInstallMessage( 'Invalid object id', 'Uninstall - error', 120 $this->returnTo( $option, 'mambot', $client ) ); 121 exit(); 122 } 123 124 if (trim( $row->folder ) == '') { 125 HTML_installer::showInstallMessage( 'Folder field empty, cannot remove files', 'Uninstall - error', 126 $this->returnTo( $option, 'mambot', $client ) ); 127 exit(); 128 } 129 130 $basepath = $mosConfig_absolute_path . '/mambots/' . $row->folder . '/'; 131 $xmlfile = $basepath . $row->element . '.xml'; 132 133 // see if there is an xml install file, must be same name as element 134 if (file_exists( $xmlfile )) { 135 $this->i_xmldoc = new DOMIT_Lite_Document(); 136 $this->i_xmldoc->resolveErrors( true ); 137 138 if ($this->i_xmldoc->loadXML( $xmlfile, false, true )) { 139 $mosinstall =& $this->i_xmldoc->documentElement; 140 // get the files element 141 $files_element =& $mosinstall->getElementsByPath( 'files', 1 ); 142 if (!is_null( $files_element )) { 143 $files = $files_element->childNodes; 144 foreach ($files as $file) { 145 // delete the files 146 $filename = $file->getText(); 147 if (file_exists( $basepath . $filename )) { 148 $parts = pathinfo( $filename ); 149 $subpath = $parts['dirname']; 150 if ($subpath != '' && $subpath != '.' && $subpath != '..') { 151 echo '<br />Deleting: '. $basepath . $subpath; 152 $result = deldir(mosPathName( $basepath . $subpath . '/' )); 153 } else { 154 echo '<br />Deleting: '. $basepath . $filename; 155 $result = unlink( mosPathName ($basepath . $filename, false)); 156 } 157 echo intval( $result ); 158 } 159 } 160 161 // remove XML file from front 162 echo "Deleting XML File: $xmlfile"; 163 @unlink( mosPathName ($xmlfile, false ) ); 164 165 // define folders that should not be removed 166 $sysFolders = array( 167 'content', 168 'search' 169 ); 170 if (!in_array( $row->folder, $sysFolders )) { 171 // delete the non-system folders if empty 172 if (count( mosReadDirectory( $basepath ) ) < 1) { 173 deldir( $basepath ); 174 } 175 } 176 } 177 } 178 } 179 180 if ($row->iscore) { 181 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', 182 'Uninstall - error', $this->returnTo( $option, 'mambot', $client ) ); 183 exit(); 184 } 185 186 $query = "DELETE FROM #__mambots" 187 . "\n WHERE id = " . (int) $id 188 ; 189 $database->setQuery( $query ); 190 if (!$database->query()) { 191 $msg = $database->stderr; 192 die( $msg ); 193 } 194 return true; 195 } 196 } 197 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 14:43:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |