[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/administrator/components/com_installer/module/ -> module.class.php (source)

   1  <?php
   2  /**
   3  * @version $Id: module.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  */
  22  class mosInstallerModule extends mosInstaller {
  23      /**
  24      * Custom install method
  25      * @param boolean True if installing from directory
  26      */
  27  	function install( $p_fromdir = null ) {
  28          global $mosConfig_absolute_path, $database;
  29  
  30          if (!$this->preInstallCheck( $p_fromdir, 'module' )) {
  31              return false;
  32          }
  33  
  34          $xmlDoc     = $this->xmlDoc();
  35          $mosinstall =& $xmlDoc->documentElement;
  36  
  37          $client = '';
  38          if ($mosinstall->getAttribute( 'client' )) {
  39              $validClients = array( 'administrator' );
  40              if (!in_array( $mosinstall->getAttribute( 'client' ), $validClients )) {
  41                  $this->setError( 1, 'Unknown client type ['.$mosinstall->getAttribute( 'client' ).']' );
  42                  return false;
  43              }
  44              $client = 'admin';
  45          }
  46  
  47          // Set some vars
  48          $e = &$mosinstall->getElementsByPath( 'name', 1 );
  49          $this->elementName($e->getText());
  50          $this->elementDir( mosPathName( $mosConfig_absolute_path
  51              . ($client == 'admin' ? '/administrator' : '')
  52              . '/modules/' )
  53          );
  54          
  55          $e = &$mosinstall->getElementsByPath( 'position', 1 );
  56          if (!is_null($e)) {
  57              $position = $e->getText();
  58              
  59              if ($e->getAttribute( 'published' ) == '1') {
  60                  $published = 1;
  61              } else {
  62                  $published = 0;
  63              }
  64          } else {
  65              $position     = 'left';
  66              $published     = 0;
  67          }
  68          
  69          if ($this->parseFiles( 'files', 'module', 'No file is marked as module file' ) === false) {
  70              return false;
  71          }
  72          $this->parseFiles( 'images' );
  73  
  74          $client_id = intval( $client == 'admin' );
  75          // Insert in module in DB
  76          $query = "SELECT id FROM #__modules"
  77          . "\n WHERE module = " . $database->Quote( $this->elementSpecial() )
  78          . "\n AND client_id = " . (int) $client_id
  79          ;
  80          $database->setQuery( $query );
  81          if (!$database->query()) {
  82              $this->setError( 1, 'SQL error: ' . $database->stderr( true ) );
  83              return false;
  84          }
  85  
  86          $id = $database->loadResult();
  87  
  88          if (!$id) {
  89              $row = new mosModule( $database );
  90              $row->title         = $this->elementName();
  91              $row->ordering         = 99;
  92              $row->published        = $published;
  93              $row->position         = $position;
  94              $row->showtitle     = 1;
  95              $row->iscore         = 0;
  96              $row->access         = $client == 'admin' ? 99 : 0;
  97              $row->client_id     = $client_id;
  98              $row->module         = $this->elementSpecial();
  99  
 100              $row->store();
 101  
 102              $query = "INSERT INTO #__modules_menu"
 103              . "\n VALUES ( " . (int) $row->id . ", 0 )"
 104              ;
 105              $database->setQuery( $query );
 106              if(!$database->query()) {
 107                  $this->setError( 1, 'SQL error: ' . $database->stderr( true ) );
 108                  return false;
 109              }
 110          } else {
 111              $this->setError( 1, 'Module "' . $this->elementName() . '" already exists!' );
 112              return false;
 113          }
 114          if ($e = &$mosinstall->getElementsByPath( 'description', 1 )) {
 115              $this->setError( 0, $this->elementName() . '<p>' . $e->getText() . '</p>' );
 116          }
 117  
 118          return $this->copySetupFile('front');
 119      }
 120      /**
 121      * Custom install method
 122      * @param int The id of the module
 123      * @param string The URL option
 124      * @param int The client id
 125      */
 126  	function uninstall( $id, $option, $client=0 ) {
 127          global $database, $mosConfig_absolute_path;
 128  
 129          $id = intval( $id );
 130  
 131          $query = "SELECT module, iscore, client_id"
 132          . "\n FROM #__modules WHERE id = " . (int) $id
 133          ;
 134          $database->setQuery( $query );
 135          $row = null;
 136          $database->loadObject( $row );
 137  
 138          if ($row->iscore) {
 139              HTML_installer::showInstallMessage( $row->title .'is a core module, and can not be uninstalled.<br />You need to unpublish it if you don\'t want to use it', 'Uninstall -  error', $this->returnTo( $option, 'module', $row->client_id ? '' : 'admin' ) );
 140              exit();
 141          }
 142  
 143          $query = "SELECT id"
 144          . "\n FROM #__modules"
 145          . "\n WHERE module = " . $database->Quote( $row->module ) . " AND client_id = " . (int) $row->client_id
 146          ;
 147          $database->setQuery( $query );
 148          $modules = $database->loadResultArray();
 149  
 150          if (count( $modules )) {
 151              mosArrayToInts( $modules );
 152              $modID = 'moduleid=' . implode( ' OR moduleid=', $modules );
 153  
 154              $query = "DELETE FROM #__modules_menu"
 155              . "\n WHERE ( $modID )"
 156              ;
 157              $database->setQuery( $query );
 158              if (!$database->query()) {
 159                  $msg = $database->stderr;
 160                  die( $msg );
 161              }
 162  
 163              $query = "DELETE FROM #__modules"
 164              . "\n WHERE module = " . $database->Quote( $row->module ) . " AND client_id = " . (int) $row->client_id
 165              ;
 166              $database->setQuery( $query );
 167              if (!$database->query()) {
 168                  $msg = $database->stderr;
 169                  die( $msg );
 170              }
 171  
 172              if ( !$row->client_id ) {
 173                  $basepath = $mosConfig_absolute_path . '/modules/';
 174              } else {
 175                  $basepath = $mosConfig_absolute_path . '/administrator/modules/';
 176              }
 177  
 178                $xmlfile = $basepath . $row->module . '.xml';
 179  
 180                  // see if there is an xml install file, must be same name as element
 181              if (file_exists( $xmlfile )) {
 182                  $this->i_xmldoc = new DOMIT_Lite_Document();
 183                  $this->i_xmldoc->resolveErrors( true );
 184  
 185                  if ($this->i_xmldoc->loadXML( $xmlfile, false, true )) {
 186                      $mosinstall =& $this->i_xmldoc->documentElement;
 187                      // get the files element
 188                      $files_element =& $mosinstall->getElementsByPath( 'files', 1 );
 189                      if (!is_null( $files_element )) {
 190                          $files = $files_element->childNodes;
 191                          foreach ($files as $file) {
 192                              // delete the files
 193                              $filename = $file->getText();
 194                              if (file_exists( $basepath . $filename )) {
 195                                  $parts = pathinfo( $filename );
 196                                  $subpath = $parts['dirname'];
 197                                  if ($subpath != '' && $subpath != '.' && $subpath != '..') {
 198                                      echo '<br />Deleting: '. $basepath . $subpath;
 199                                      $result = deldir(mosPathName( $basepath . $subpath . '/' ));
 200                                  } else {
 201                                      echo '<br />Deleting: '. $basepath . $filename;
 202                                      $result = unlink( mosPathName ($basepath . $filename, false));
 203                                  }
 204                                  echo intval( $result );
 205                              }
 206                          }
 207  
 208                          // remove XML file from front
 209                          echo "Deleting XML File: $xmlfile";
 210                          @unlink(  mosPathName ($xmlfile, false ) );
 211                          return true;
 212                      }
 213                  }
 214              }
 215          }
 216  
 217      }
 218  }
 219  ?>


Généré le : Wed Nov 21 14:43:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics