[ Index ]
 

Code source de Plume CMS 1.2.2

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/manager/inc/ -> class.config.php (source)

   1  <?php
   2  /* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
   3  /*
   4  # ***** BEGIN LICENSE BLOCK *****
   5  # This file is part of Plume CMS, a website management application.
   6  # Copyright (C) 2001-2005 Loic d'Anterroches and contributors.
   7  #
   8  # Plume CMS is free software; you can redistribute it and/or modify
   9  # it under the terms of the GNU General Public License as published by
  10  # the Free Software Foundation; either version 2 of the License, or
  11  # (at your option) any later version.
  12  #
  13  # Plume CMS is distributed in the hope that it will be useful,
  14  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16  # GNU General Public License for more details.
  17  #
  18  # You should have received a copy of the GNU General Public License
  19  # along with this program; if not, write to the Free Software
  20  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  21  #
  22  # ***** END LICENSE BLOCK ***** */
  23  
  24  
  25  /**
  26   * Wrapper for the configuration variables. 
  27   * The website variables are in the same "space" as the general variables.
  28   * The plugin variables have their own "space".
  29   * The functions are all static for ease of use.
  30   */
  31  class config
  32  {
  33  
  34      /**
  35       * Get a configuration variable.
  36       *
  37       * @param string Variable to get
  38       * @param string Plugin to get the variable from ('plume')
  39       * @return mixed Return an empty string if variable not set.
  40       */
  41      function f($var, $plugin='plume')
  42      {
  43          if ($plugin != 'plume') {
  44              // Get the variable from a plugin
  45              if (isset($GLOBALS['_PX_config_plugins'][$plugin][$var]))
  46                  return $GLOBALS['_PX_config_plugins'][$plugin][$var];
  47              // It may not have been set, so look now at the other
  48              // configuration variables.
  49          }
  50          if (isset($GLOBALS['_PX_config_runtime'][$var]))
  51              return $GLOBALS['_PX_config_runtime'][$var];
  52          if (isset($GLOBALS['_PX_website_config'][$var]))
  53              return $GLOBALS['_PX_website_config'][$var];
  54          if (isset($GLOBALS['_PX_config'][$var]))
  55              return $GLOBALS['_PX_config'][$var];
  56          return '';
  57      }
  58  
  59      /**
  60       * Get a configuration variable as boolean.
  61       *
  62       * @param string Variable to get
  63       * @param string Plugin to get the variable from ('plume')
  64       * @return bool False if not set
  65       */
  66      function fbool($var, $plugin='plume')
  67      {
  68          return (config::f($var, $plugin)) ? true : false;
  69      }
  70  
  71      /**
  72       * Get a configuration variable as integer.
  73       *
  74       * @param string Variable to get
  75       * @param string Plugin to get the variable from ('plume')
  76       * @return int 0 if not set
  77       */
  78      function fint($var, $plugin='plume')
  79      {
  80          return (int) config::f($var, $plugin);
  81      }
  82  
  83      /**
  84       * Get cache dir.
  85       *
  86       * @return string Cache dir of the current website.
  87       */
  88      function getCacheDir()
  89      {
  90          return dirname(__FILE__).'/../cache/'.config::f('website_id').'/';
  91      }
  92  
  93      /**
  94       * Get mass update file.
  95       *
  96       * @return string Path to the mass update file of the current website.
  97       */
  98      function getMassUpdateFile()
  99      {
 100          return config::getCacheDir().'MASS_UPDATE';
 101      }
 102  
 103      /**
 104       * Load a website configuration file.
 105       * It overwrite the configuration of the website previously loaded. 
 106       * It reset the configuration to an empty array in case of error.
 107       *
 108       * @param string Website id
 109       * @retrun bool Success or not
 110       */
 111      function loadWebsite($websiteid)
 112      {
 113          global $_PX_website_config;
 114          $success = true;
 115          if (preg_match('/[^0-9a-z\-]/i', $websiteid)) $success = false;
 116  
 117          $config = dirname(__FILE__).'/../conf/configweb_'.$websiteid.'.php';
 118          if ($success && file_exists($config)) {
 119              include $config;
 120              return true;
 121          } else {
 122              $_PX_website_config = array();
 123              return false;
 124          }
 125      }
 126  
 127      /**
 128       * Load a plugin configuration file.
 129       * It reset the configuration of the plugin to an empty array
 130       * in case of error.
 131       *
 132       * @param string Plugin id
 133       * @return bool Success or not
 134       */
 135      function loadPlugin($pluginid)
 136      {
 137          global $_PX_config_plugins;
 138          $success = true;
 139          if (preg_match('/[^0-9a-z\-]/i', $pluginid)) $success = false;
 140  
 141          $config = dirname(__FILE__).'/../conf/configplugin_'.$pluginid.'.php';
 142          if ($success && file_exists($config)) {
 143              include $config;
 144              return true;
 145          } else {
 146              $_PX_config_plugins[$pluginid] = array();
 147              return false;
 148          }
 149      }
 150  
 151      /**
 152       * Set runtime configuration variable.
 153       * The runtime configuration variables are used mainly in the
 154       * public part, this is a good way to store the parameters for
 155       * them to be accessible by all the objects.
 156       *
 157       * @param string Variable name
 158       * @param mixed Value
 159       * @return bool true
 160       */
 161      function setVar($var, $value)
 162      {
 163          if (empty($GLOBALS['_PX_config_runtime'])) {
 164              $GLOBALS['_PX_config_runtime'] = array();
 165          }
 166          $GLOBALS['_PX_config_runtime'][$var] = $value;
 167          return true;
 168      }
 169  
 170      /**
 171       * Alias of setVar()
 172       *
 173       * @param string Variable name
 174       * @param mixed Value
 175       * @return bool true
 176       */
 177      function setField($var, $value)
 178      {
 179          return config::setVar($var, $value);
 180      }
 181  
 182      /**
 183       * Set the context. 
 184       * The context is a particular configuration variable to know
 185       * if the current call is from within the manager or the public
 186       * website.
 187       * 4 contexts exist:
 188       * - manager: When in the manager
 189       * - website: When in the public website
 190       * - external: When in the public website but with need of full urls
 191       * - install: When in the installer
 192       *
 193       * @param string Context ('manager')
 194       * @return bool true
 195       */
 196      function setContext($c='manager')
 197      {
 198          $GLOBALS['_PX_config']['context'] = $c;
 199          return true;
 200      }
 201  
 202  }
 203  ?>


Généré le : Mon Nov 26 11:57:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics