[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/kernel/ -> config.php (source)

   1  <?php
   2  // $Id: config.php 694 2006-09-04 11:33:22Z skalpa $

   3  //  ------------------------------------------------------------------------ //

   4  //                XOOPS - PHP Content Management System                      //

   5  //                    Copyright (c) 2000 XOOPS.org                           //

   6  //                       <http://www.xoops.org/>                             //

   7  //  ------------------------------------------------------------------------ //

   8  //  This program 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  //  You may not change or alter any portion of this comment or credits       //

  14  //  of supporting developers from this source code or any supporting         //

  15  //  source code which is considered copyrighted (c) material of the          //

  16  //  original comment or credit authors.                                      //

  17  //                                                                           //

  18  //  This program is distributed in the hope that it will be useful,          //

  19  //  but WITHOUT ANY WARRANTY; without even the implied warranty of           //

  20  //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //

  21  //  GNU General Public License for more details.                             //

  22  //                                                                           //

  23  //  You should have received a copy of the GNU General Public License        //

  24  //  along with this program; if not, write to the Free Software              //

  25  //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //

  26  //  ------------------------------------------------------------------------ //

  27  // Author: Kazumi Ono (AKA onokazu)                                          //

  28  // URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //

  29  // Project: The XOOPS Project                                                //

  30  // ------------------------------------------------------------------------- //

  31  
  32  if (!defined('XOOPS_ROOT_PATH')) {
  33      exit();
  34  }
  35  
  36  require_once XOOPS_ROOT_PATH.'/kernel/configoption.php';
  37  require_once XOOPS_ROOT_PATH.'/kernel/configitem.php';
  38  
  39  /**

  40   * @package     kernel

  41   * 

  42   * @author        Kazumi Ono    <onokazu@xoops.org>

  43   * @copyright    copyright (c) 2000-2003 XOOPS.org

  44   */
  45  
  46  
  47  /**

  48  * XOOPS configuration handling class.

  49  * This class acts as an interface for handling general configurations of XOOPS

  50  * and its modules.

  51  *

  52  *

  53  * @author  Kazumi Ono <webmaster@myweb.ne.jp>

  54  * @todo    Tests that need to be made:

  55  *          - error handling

  56  * @access  public

  57  */
  58  
  59  class XoopsConfigHandler
  60  {
  61  
  62      /**

  63       * holds reference to config item handler(DAO) class

  64       * 

  65       * @var     object

  66       * @access    private

  67       */
  68      var $_cHandler;
  69  
  70      /**

  71       * holds reference to config option handler(DAO) class

  72       * 

  73       * @var        object

  74       * @access    private

  75       */
  76      var $_oHandler;
  77  
  78      /**

  79       * holds an array of cached references to config value arrays,

  80       *  indexed on module id and category id

  81       *

  82       * @var     array

  83       * @access  private

  84       */
  85      var $_cachedConfigs = array();
  86  
  87      /**

  88       * Constructor

  89       * 

  90       * @param    object  &$db    reference to database object

  91       */
  92      function XoopsConfigHandler(&$db)
  93      {
  94          $this->_cHandler = new XoopsConfigItemHandler($db);
  95          $this->_oHandler = new XoopsConfigOptionHandler($db);
  96      }
  97  
  98      /**

  99       * Create a config

 100       * 

 101       * @see     XoopsConfigItem

 102       * @return    object  reference to the new {@link XoopsConfigItem}

 103       */
 104      function &createConfig()
 105      {
 106          $instance =& $this->_cHandler->create();
 107          return $instance;
 108      }
 109  
 110      /**

 111       * Get a config

 112       * 

 113       * @param    int     $id             ID of the config

 114       * @param    bool    $withoptions    load the config's options now?

 115       * @return    object  reference to the {@link XoopsConfig} 

 116       */
 117      function &getConfig($id, $withoptions = false)
 118      {
 119          $config =& $this->_cHandler->get($id);
 120          if ($withoptions == true) {
 121              $config->setConfOptions($this->getConfigOptions(new Criteria('conf_id', $id)));
 122          }
 123          return $config;
 124      }
 125  
 126      /**

 127       * insert a new config in the database

 128       * 

 129       * @param    object  &$config    reference to the {@link XoopsConfigItem} 

 130       */
 131      function insertConfig(&$config)
 132      {
 133          if (!$this->_cHandler->insert($config)) {
 134              return false;
 135          }
 136          $options =& $config->getConfOptions();
 137          $count = count($options);
 138          $conf_id = $config->getVar('conf_id');
 139          for ($i = 0; $i < $count; $i++) {
 140              $options[$i]->setVar('conf_id', $conf_id);
 141              if (!$this->_oHandler->insert($options[$i])) {
 142                  foreach($options[$i]->getErrors() as $msg){
 143                      $config->setErrors($msg);
 144                  }
 145              }
 146          }
 147          if (!empty($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')])) {
 148              unset ($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')]);
 149          }
 150          return true;
 151      }
 152  
 153      /**

 154       * Delete a config from the database

 155       * 

 156       * @param    object  &$config    reference to a {@link XoopsConfigItem} 

 157       */
 158      function deleteConfig(&$config)
 159      {
 160          if (!$this->_cHandler->delete($config)) {
 161              return false;
 162          }
 163          $options =& $config->getConfOptions();
 164          $count = count($options);
 165          if ($count == 0) {
 166              $options = $this->getConfigOptions(new Criteria('conf_id', $config->getVar('conf_id')));
 167              $count = count($options);
 168          }
 169          if (is_array($options) && $count > 0) {
 170              for ($i = 0; $i < $count; $i++) {
 171                  $this->_oHandler->delete($options[$i]);
 172              }
 173          }
 174          if (!empty($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')])) {
 175              unset ($this->_cachedConfigs[$config->getVar('conf_modid')][$config->getVar('conf_catid')]);
 176          }
 177          return true;
 178      }
 179  
 180      /**

 181       * get one or more Configs

 182       * 

 183       * @param    object  $criteria       {@link CriteriaElement} 

 184       * @param    bool    $id_as_key      Use the configs' ID as keys?

 185       * @param    bool    $with_options   get the options now?

 186       * 

 187       * @return    array   Array of {@link XoopsConfigItem} objects

 188       */
 189      function getConfigs($criteria = null, $id_as_key = false, $with_options = false)
 190      {
 191          return $this->_cHandler->getObjects($criteria, $id_as_key);
 192      }
 193  
 194      /**

 195       * Count some configs

 196       * 

 197       * @param    object  $criteria   {@link CriteriaElement} 

 198       */
 199      function getConfigCount($criteria = null)
 200      {
 201          return $this->_cHandler->getCount($criteria);
 202      }
 203  
 204      /**

 205       * Get configs from a certain category

 206       * 

 207       * @param    int $category   ID of a category

 208       * @param    int $module     ID of a module

 209       * 

 210       * @return    array   array of {@link XoopsConfig}s 

 211       */
 212      function &getConfigsByCat($category, $module = 0)
 213      {
 214          static $_cachedConfigs;
 215          if (!empty($_cachedConfigs[$module][$category])) {
 216              return $_cachedConfigs[$module][$category];
 217          } else {
 218              $ret = array();
 219              $criteria = new CriteriaCompo(new Criteria('conf_modid', intval($module)));
 220              if (!empty($category)) {
 221                  $criteria->add(new Criteria('conf_catid', intval($category)));
 222              }
 223              $configs = $this->getConfigs($criteria, true);
 224              if (is_array($configs)) {
 225                  foreach (array_keys($configs) as $i) {
 226                      $ret[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput();
 227                  }
 228              }
 229              $_cachedConfigs[$module][$category] = $ret;
 230              return $_cachedConfigs[$module][$category];
 231          }
 232      }
 233  
 234      /**

 235       * Make a new {@link XoopsConfigOption} 

 236       * 

 237       * @return    object  {@link XoopsConfigOption} 

 238       */
 239      function &createConfigOption() {
 240          $inst =& $this->_oHandler->create();
 241          return $inst;
 242      }
 243  
 244      /**

 245       * Get a {@link XoopsConfigOption} 

 246       * 

 247       * @param    int $id ID of the config option

 248       * 

 249       * @return    object  {@link XoopsConfigOption} 

 250       */
 251      function &getConfigOption($id) {
 252          $inst =& $this->_oHandler->get($id);
 253          return $inst;
 254      }
 255  
 256      /**

 257       * Get one or more {@link XoopsConfigOption}s

 258       * 

 259       * @param    object  $criteria   {@link CriteriaElement} 

 260       * @param    bool    $id_as_key  Use IDs as keys in the array?

 261       * 

 262       * @return    array   Array of {@link XoopsConfigOption}s

 263       */
 264      function getConfigOptions($criteria = null, $id_as_key = false)
 265      {
 266          return $this->_oHandler->getObjects($criteria, $id_as_key);
 267      }
 268  
 269      /**

 270       * Count some {@link XoopsConfigOption}s

 271       * 

 272       * @param    object  $criteria   {@link CriteriaElement} 

 273       * 

 274       * @return    int     Count of {@link XoopsConfigOption}s matching $criteria

 275       */
 276      function getConfigOptionsCount($criteria = null)
 277      {
 278          return $this->_oHandler->getCount($criteria);
 279      }
 280  
 281      /**

 282       * Get a list of configs

 283       * 

 284       * @param    int $conf_modid ID of the modules

 285       * @param    int $conf_catid ID of the category

 286       * 

 287       * @return    array   Associative array of name=>value pairs.

 288       */
 289      function getConfigList($conf_modid, $conf_catid = 0)
 290      {
 291          if (!empty($this->_cachedConfigs[$conf_modid][$conf_catid])) {
 292              return $this->_cachedConfigs[$conf_modid][$conf_catid];
 293          } else {
 294              $criteria = new CriteriaCompo(new Criteria('conf_modid', $conf_modid));
 295              if (empty($conf_catid)) {
 296                  $criteria->add(new Criteria('conf_catid', $conf_catid));
 297              }
 298              $configs =& $this->_cHandler->getObjects($criteria);
 299              $confcount = count($configs);
 300              $ret = array();
 301              for ($i = 0; $i < $confcount; $i++) {
 302                  $ret[$configs[$i]->getVar('conf_name')] = $configs[$i]->getConfValueForOutput();
 303              }
 304              $this->_cachedConfigs[$conf_modid][$conf_catid] =& $ret;
 305              return $ret;
 306          }
 307      }
 308  }
 309  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics