[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/classes/ -> class.moduleloader.inc.php (source)

   1  <?php
   2  # CMS - CMS Made Simple
   3  # (c)2004-6 by Ted Kulp (ted@cmsmadesimple.org)
   4  # This project's homepage is: http://cmsmadesimple.org
   5  #
   6  # This program is free software; you can redistribute it and/or modify
   7  # it under the terms of the GNU General Public License as published by
   8  # the Free Software Foundation; either version 2 of the License, or
   9  # (at your option) any later version.
  10  #
  11  # This program is distributed in the hope that it will be useful,
  12  # BUT withOUT ANY WARRANTY; without even the implied warranty of
  13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
  14  # GNU General Public License for more details.
  15  # You should have received a copy of the GNU General Public License
  16  # along with this program; if not, write to the Free Software
  17  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA    02111-1307    USA
  18  #
  19  #$Id$
  20  
  21  /**
  22   * Class to load modules
  23   *
  24   * @since        1.0
  25   * @package        CMS
  26   */
  27  
  28  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'class.module.inc.php');
  29  
  30  class ModuleLoader
  31  {
  32      /**
  33      * Loads modules from the filesystem.  If loadall is true, then it will load all
  34      * modules whether they're installed, or active.  If it is false, then it will
  35      * only load modules which are installed and active.
  36      */
  37  	function LoadModules($loadall = false, $noadmin = false)
  38      {
  39          global $gCms;
  40          $db =& $gCms->GetDb();
  41          $cmsmodules = &$gCms->modules;
  42  
  43          $dir = dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR."modules";
  44  
  45          if ($loadall == true)
  46          {
  47              $handle=opendir($dir);
  48              while ($file = readdir($handle))
  49              {
  50                  if (@is_file("$dir/$file/$file.module.php"))
  51                  {
  52                      include("$dir/$file/$file.module.php");
  53                  }
  54                  else
  55                  {
  56                      unset($cmsmodules[$file]);
  57                  }
  58              }
  59              closedir($handle);
  60              
  61              //Find modules and instantiate them
  62              $allmodules = $this->FindModules();
  63              foreach ($allmodules as $onemodule)
  64              {
  65                  if (class_exists($onemodule))
  66                  {
  67                      $newmodule =& new $onemodule;
  68                      $name = $newmodule->GetName();
  69                      $cmsmodules[$name]['object'] =& $newmodule;
  70                      $cmsmodules[$name]['installed'] = false;
  71                      $cmsmodules[$name]['active'] = false;
  72                  }
  73                  else
  74                  {
  75                      unset($cmsmodules[$name]);
  76                  }
  77              }
  78          }
  79  
  80          #Figger out what modules are active and/or installed
  81          #Load them if loadall is false
  82          if (isset($db))
  83          {
  84              $query = '';
  85              if ($noadmin)
  86              $query = "SELECT * FROM ".cms_db_prefix()."modules WHERE admin_only = 0 ORDER BY module_name";
  87              else
  88              $query = "SELECT * FROM ".cms_db_prefix()."modules ORDER BY module_name";
  89              $result = &$db->Execute($query);
  90              while ($result && !$result->EOF)
  91              {
  92                  if (isset($result->fields['module_name']))
  93                  {
  94                      $modulename = $result->fields['module_name'];
  95                      if (isset($modulename))
  96                      {
  97                          if ($loadall == true)
  98                          {
  99                              if (isset($cmsmodules[$modulename]))
 100                              {
 101                                  $cmsmodules[$modulename]['installed'] = true;
 102                                  $cmsmodules[$modulename]['active'] = ($result->fields['active'] == 1?true:false);
 103                              }
 104                          }
 105                          else
 106                          {
 107                              if ($result->fields['active'] == 1)
 108                              {
 109                                  if (@is_file("$dir/$modulename/$modulename.module.php"))
 110                                  {
 111                                      #var_dump('loading module:' . $modulename);
 112                                      include_once("$dir/$modulename/$modulename.module.php");
 113                                      if (class_exists($modulename))
 114                                      {
 115                                          $newmodule =& new $modulename;
 116                                          $name = $newmodule->GetName();
 117  
 118                                          global $CMS_VERSION;
 119                                          $dbversion = $result->fields['version'];
 120  
 121                                          #Check to see if there is an update and wether or not we should perform it
 122                                          if (version_compare($dbversion, $newmodule->GetVersion()) == -1 && $newmodule->AllowAutoUpgrade() == TRUE)
 123                                          {
 124                                              $newmodule->Upgrade($dbversion, $newmodule->GetVersion());
 125                                              $query = "UPDATE ".cms_db_prefix()."modules SET version = ? WHERE module_name = ?";
 126                                              $db->Execute($query, array($newmodule->GetVersion(), $name));
 127                                              Events::SendEvent('Core', 'ModuleUpgraded', array('name' => $name, 'oldversion' => $dbversion, 'newversion' => $newmodule->GetVersion()));
 128                                              $dbversion = $newmodule->GetVersion();
 129                                          }
 130  
 131                                          #Check to see if version in db matches file version
 132                                          if ($dbversion == $newmodule->GetVersion() && version_compare($newmodule->MinimumCMSVersion(), $CMS_VERSION) != 1)
 133                                          {
 134                                              $cmsmodules[$name]['object'] =& $newmodule;
 135                                              $cmsmodules[$name]['installed'] = true;
 136                                              $cmsmodules[$name]['active'] = ($result->fields['active'] == 1?true:false);
 137                                          }
 138                                          else
 139                                          {
 140                                              unset($cmsmodules[$name]);
 141                                          }
 142                                      }
 143                                      else //No point in doing anything with it
 144                                      {
 145                                          unset($cmsmodules[$name]);
 146                                      }
 147                                  }
 148                                  else
 149                                  {
 150                                      unset($cmsmodules[$modulename]);
 151                                  }
 152                              }
 153                          }
 154                      }
 155                      $result->MoveNext();
 156                  }
 157              }
 158              
 159              if ($result) $result->Close();
 160          }
 161      }
 162  
 163      /**
 164       * Finds all classes extending cmsmodule for loading
 165       */
 166  	function FindModules()
 167      {
 168          $result = array();
 169  
 170          foreach (get_declared_classes() as $oneclass)
 171          {
 172            $parent = get_parent_class($oneclass);
 173            while( $parent !== FALSE )
 174              {
 175                $str = strtolower($parent);
 176                if( $str == 'cmsmodule' ) 
 177              {
 178                $result[] = strtolower($oneclass);
 179                break;
 180              }
 181                $parent = get_parent_class($parent);
 182              }
 183          }
 184  
 185          sort($result);
 186  
 187          return $result;
 188      }
 189  }
 190  
 191  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7