[ Index ]
 

Code source de Joomla 1.0.13

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

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

   1  <?php
   2  /**
   3  * @version $Id: component.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  * Component installer
  20  * @package Joomla
  21  * @subpackage Installer
  22  */
  23  class mosInstallerComponent extends mosInstaller {
  24      var $i_componentadmindir     = '';
  25      var $i_hasinstallfile         = false;
  26      var $i_installfile             = '';
  27  
  28  	function componentAdminDir($p_dirname = null) {
  29          if(!is_null($p_dirname)) {
  30              $this->i_componentadmindir = mosPathName($p_dirname);
  31          }
  32          return $this->i_componentadmindir;
  33      }
  34  
  35      /**
  36      * Custom install method
  37      * @param boolean True if installing from directory
  38      */
  39  	function install($p_fromdir = null) {
  40          global $mosConfig_absolute_path,$database;
  41  
  42          if (!$this->preInstallCheck( $p_fromdir, 'component' )) {
  43              return false;
  44          }
  45  
  46          // aje moved down to here. ??  seemed to be some referencing problems
  47          $xmlDoc     = $this->xmlDoc();
  48          $mosinstall = &$xmlDoc->documentElement;
  49  
  50          // Set some vars
  51          $e = &$mosinstall->getElementsByPath('name', 1);
  52          $this->elementName($e->getText());
  53          $this->elementDir( mosPathName( $mosConfig_absolute_path . "/components/"
  54              . strtolower("com_" . str_replace(" ","",$this->elementName())) . "/" )
  55          );
  56          $this->componentAdminDir( mosPathName( $mosConfig_absolute_path . "/administrator/components/"
  57              . strtolower( "com_" . str_replace( " ","",$this->elementName() ) ) )
  58          );
  59  
  60          if (file_exists($this->elementDir())) {
  61              $this->setError( 1, 'Another component is already using directory: "' . $this->elementDir() . '"' );
  62              return false;
  63          }
  64  
  65          if(!file_exists($this->elementDir()) && !mosMakePath($this->elementDir())) {
  66              $this->setError( 1, 'Failed to create directory "' . $this->elementDir() . '"' );
  67              return false;
  68          }
  69  
  70          if(!file_exists($this->componentAdminDir()) && !mosMakePath($this->componentAdminDir())) {
  71              $this->setError( 1, 'Failed to create directory "' . $this->componentAdminDir() . '"' );
  72              return false;
  73          }
  74  
  75          // Find files to copy
  76          if ($this->parseFiles( 'files' ) === false) {
  77              return false;
  78          }
  79          $this->parseFiles( 'images' );
  80          $this->parseFiles( 'administration/files','','',1 );
  81          $this->parseFiles( 'administration/images','','',1 );
  82  
  83          // Are there any SQL queries??
  84          $query_element = &$mosinstall->getElementsByPath('install/queries', 1);
  85          if (!is_null($query_element)) {
  86              $queries = $query_element->childNodes;
  87              foreach($queries as $query)
  88              {
  89                  $database->setQuery( $query->getText());
  90                  if (!$database->query())
  91                  {
  92                      $this->setError( 1, "SQL Error " . $database->stderr( true ) );
  93                      return false;
  94                  }
  95              }
  96          }
  97  
  98          // Is there an installfile
  99          $installfile_elemet = &$mosinstall->getElementsByPath('installfile', 1);
 100  
 101          if (!is_null($installfile_elemet)) {
 102              // check if parse files has already copied the install.component.php file (error in 3rd party xml's!)
 103              if (!file_exists($this->componentAdminDir().$installfile_elemet->getText())) {
 104                  if(!$this->copyFiles($this->installDir(), $this->componentAdminDir(), array($installfile_elemet->getText())))              {
 105                      $this->setError( 1, 'Could not copy PHP install file.' );
 106                      return false;
 107                  }
 108              }
 109              $this->hasInstallfile(true);
 110              $this->installFile($installfile_elemet->getText());
 111          }
 112          // Is there an uninstallfile
 113          $uninstallfile_elemet = &$mosinstall->getElementsByPath('uninstallfile',1);
 114          if(!is_null($uninstallfile_elemet)) {
 115              if (!file_exists($this->componentAdminDir().$uninstallfile_elemet->getText())) {
 116                  if(!$this->copyFiles($this->installDir(), $this->componentAdminDir(), array($uninstallfile_elemet->getText()))) {
 117                      $this->setError( 1, 'Could not copy PHP uninstall file' );
 118                      return false;
 119                  }
 120              }
 121          }
 122  
 123          // Is the menues ?
 124          $adminmenu_element = &$mosinstall->getElementsByPath('administration/menu',1);
 125          if(!is_null($adminmenu_element))
 126          {
 127              $adminsubmenu_element    = &$mosinstall->getElementsByPath('administration/submenu',1);
 128              $com_name                = strtolower("com_" . str_replace(" ","",$this->elementName()));
 129              $com_admin_menuname        = $adminmenu_element->getText();
 130  
 131              if(!is_null($adminsubmenu_element))
 132              {
 133                  $com_admin_menu_id    = $this->createParentMenu($com_admin_menuname,$com_name);
 134                  if($com_admin_menu_id === false)
 135                  {
 136                      return false;
 137                  }
 138                  $com_admin_submenus = $adminsubmenu_element->childNodes;
 139  
 140                  $submenuordering = 0;
 141                  foreach($com_admin_submenus as $admin_submenu)
 142                  {
 143                      $com = new mosComponent( $database );
 144                      $com->name        = $admin_submenu->getText();
 145                      $com->link        = '';
 146                      $com->menuid    = 0;
 147                      $com->parent    = $com_admin_menu_id;
 148                      $com->iscore    = 0;
 149  
 150                      if ( $admin_submenu->getAttribute("act"))
 151                      {
 152                          $com->admin_menu_link = "option=$com_name&act=" . $admin_submenu->getAttribute("act");
 153                      }
 154                      else if ($admin_submenu->getAttribute("task"))
 155                      {
 156                          $com->admin_menu_link = "option=$com_name&task=" . $admin_submenu->getAttribute("task");
 157                      }
 158                      else if ($admin_submenu->getAttribute("link"))
 159                      {
 160                          $com->admin_menu_link = $admin_submenu->getAttribute("link");
 161                      }
 162                      else
 163                      {
 164                          $com->admin_menu_link = "option=$com_name";
 165                      }
 166                      $com->admin_menu_alt = $admin_submenu->getText();
 167                      $com->option = $com_name;
 168                      $com->ordering = $submenuordering++;
 169                      $com->admin_menu_img = "js/ThemeOffice/component.png";
 170  
 171                      if (!$com->store())
 172                      {
 173                          $this->setError( 1, $database->stderr( true ) );
 174                          return false;
 175                      }
 176                  }
 177              }
 178              else
 179              {
 180                  $this->createParentMenu($com_admin_menuname,$com_name);
 181              }
 182          }
 183  
 184          $desc= '';
 185          if ($e = &$mosinstall->getElementsByPath( 'description', 1 )) {
 186              $desc = $this->elementName() . '<p>' . $e->getText() . '</p>';
 187          }
 188          $this->setError( 0, $desc );
 189  
 190          if ($this->hasInstallfile()) {
 191              if (is_file($this->componentAdminDir() . '/' . $this->installFile())) {
 192                  require_once($this->componentAdminDir() . "/" . $this->installFile());
 193                  $ret = com_install();
 194                  if ($ret != '') {
 195                      $this->setError( 0, $desc . $ret );
 196                  }
 197              }
 198          }
 199          return $this->copySetupFile();
 200      }
 201  
 202  	function createParentMenu($_menuname,$_comname, $_image = "js/ThemeOffice/component.png") {
 203          global $database;
 204          $db_name            = $_menuname;
 205          $db_link            = "option=$_comname";
 206          $db_menuid            = 0;
 207          $db_parent            = 0;
 208          $db_admin_menu_link    = "option=$_comname";
 209          $db_admin_menu_alt    = $_menuname;
 210          $db_option            = $_comname;
 211          $db_ordering        = 0;
 212          $db_admin_menu_img    = $_image;
 213          $db_iscore            = 0;
 214          $db_params            = '';
 215  
 216          $query = "INSERT INTO #__components"
 217          . "\n VALUES( '', " . $database->Quote( $db_name ) . ", " . $database->Quote( $db_link ) . ", " . (int) $db_menuid . ", " . (int) $db_parent . ", " . $database->Quote( $db_admin_menu_link ) . ", " . $database->Quote( $db_admin_menu_alt ) . ", " . $database->Quote( $db_option ) . ", " . (int) $db_ordering . ", " . $database->Quote( $db_admin_menu_img ) . ", " . (int) $db_iscore . ", '' )";
 218          $database->setQuery( $query );
 219          if(!$database->query())
 220          {
 221              $this->setError( 1, $database->stderr( true ) );
 222              return false;
 223          }
 224          $menuid = $database->insertid();
 225          return $menuid;
 226      }
 227      /**
 228      * Custom install method
 229      * @param int The id of the module
 230      * @param string The URL option
 231      * @param int The client id
 232      */
 233  	function uninstall( $cid, $option, $client=0 ) {
 234          global $database,$mosConfig_absolute_path;
 235  
 236          $uninstallret = '';
 237  
 238          $sql = "SELECT *"
 239          . "\n FROM #__components"
 240          . "\n WHERE id = " . (int) $cid
 241          ;
 242          $database->setQuery($sql);
 243  
 244          $row = null;
 245          if (!$database->loadObject( $row )) {
 246              HTML_installer::showInstallMessage($database->stderr(true),'Uninstall -  error',
 247                  $this->returnTo( $option, 'component', $client ) );
 248              exit();
 249          }
 250  
 251          if ($row->iscore) {
 252              HTML_installer::showInstallMessage("Component $row->name is a core component, and can not be uninstalled.<br />You need to unpublish it if you don't want to use it", 'Uninstall -  error',
 253                  $this->returnTo( $option, 'component', $client ) );
 254              exit();
 255          }
 256  
 257          // Delete entries in the DB
 258          $sql = "DELETE FROM #__components"
 259          . "\n WHERE parent = " . (int) $row->id
 260          ;
 261          $database->setQuery($sql);
 262          if (!$database->query()) {
 263              HTML_installer::showInstallMessage($database->stderr(true),'Uninstall -  error',
 264                  $this->returnTo( $option, 'component', $client ) );
 265              exit();
 266          }
 267  
 268          $sql = "DELETE FROM #__components"
 269          . "\n WHERE id = " . (int) $row->id
 270          ;
 271          $database->setQuery($sql);
 272          if (!$database->query()) {
 273              HTML_installer::showInstallMessage($database->stderr(true),'Uninstall -  error',
 274                  $this->returnTo( $option, 'component', $client ) );
 275              exit();
 276          }
 277  
 278          // Try to find the uninstall file
 279          $filesindir = mosReadDirectory( $mosConfig_absolute_path.'/administrator/components/'.$row->option, 'uninstall' );
 280          if (count( $filesindir ) > 0) {
 281              $uninstall_file = $filesindir[0];
 282              if(file_exists($mosConfig_absolute_path.'/administrator/components/'.$row->option .'/'.$uninstall_file))
 283              {
 284                  require_once($mosConfig_absolute_path.'/administrator/components/'.$row->option .'/'.$uninstall_file );
 285                  $uninstallret = com_uninstall();
 286              }
 287          }
 288  
 289          // Try to find the XML file
 290          $filesindir = mosReadDirectory( mosPathName( $mosConfig_absolute_path.'/administrator/components/'.$row->option ), '.xml$');
 291          if (count($filesindir) > 0) {
 292              $ismosinstall = false;
 293              $found = 0;
 294              foreach ($filesindir as $file) {
 295                  $xmlDoc = new DOMIT_Lite_Document();
 296                  $xmlDoc->resolveErrors( true );
 297                  if (!$xmlDoc->loadXML( $mosConfig_absolute_path."/administrator/components/".$row->option . "/" . $file, false, true )) {
 298                      return false;
 299                  }
 300                  $root = &$xmlDoc->documentElement;
 301  
 302                  if ($root->getTagName() != 'mosinstall') {
 303                      continue;
 304                  }
 305                  $found = 1;
 306  
 307                  $query_element = &$root->getElementsbyPath( 'uninstall/queries', 1 );
 308                  if(!is_null($query_element))
 309                  {
 310                      $queries = $query_element->childNodes;
 311                      foreach($queries as $query)
 312                      {
 313                          $database->setQuery( $query->getText());
 314                          if (!$database->query())
 315                          {
 316                              HTML_installer::showInstallMessage($database->stderr(true),'Uninstall -  error',
 317                                  $this->returnTo( $option, 'component', $client ) );
 318                              exit();
 319                          }
 320                      }
 321                  }
 322              }
 323              if(!$found) {
 324                  HTML_installer::showInstallMessage('XML File invalid','Uninstall -  error',
 325                      $this->returnTo( $option, 'component', $client ) );
 326                  exit();
 327              }
 328          } else {
 329              /*
 330              HTML_installer::showInstallMessage( 'Could not find XML Setup file in '.$mosConfig_absolute_path.'/administrator/components/'.$row->option,
 331                  'Uninstall -  error', $option, 'component' );
 332              exit();
 333              */
 334          }
 335  
 336          // Delete directories
 337  
 338          if (trim( $row->option )) {
 339              $result = 0;
 340              $path = mosPathName( $mosConfig_absolute_path.'/administrator/components/' . $row->option );
 341              if (is_dir( $path )) {
 342                  $result |= deldir( $path );
 343              }
 344              $path = mosPathName( $mosConfig_absolute_path.'/components/'.$row->option );
 345              if (is_dir( $path )) {
 346                  $result |= deldir( $path );
 347              }
 348              return $result;
 349          } else {
 350              HTML_installer::showInstallMessage( 'Option field empty, cannot remove files', 'Uninstall -  error', $option,'component');
 351              exit();
 352          }
 353  
 354          return $uninstallret;
 355      }
 356  }
 357  ?>


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