[ Index ] |
|
Code source de XOOPS 2.0.17.1 |
1 <?php 2 // $Id: configitem.php 506 2006-05-26 23:10:37Z 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 /** 37 * @package kernel 38 * 39 * @author Kazumi Ono <onokazu@xoops.org> 40 * @copyright copyright (c) 2000-2003 XOOPS.org 41 */ 42 43 /**#@+ 44 * Config type 45 */ 46 define('XOOPS_CONF', 1); 47 define('XOOPS_CONF_USER', 2); 48 define('XOOPS_CONF_METAFOOTER', 3); 49 define('XOOPS_CONF_CENSOR', 4); 50 define('XOOPS_CONF_SEARCH', 5); 51 define('XOOPS_CONF_MAILER', 6); 52 define('XOOPS_CONF_AUTH', 7); 53 /**#@-*/ 54 55 /** 56 * 57 * 58 * @author Kazumi Ono <onokazu@xoops.org> 59 * @copyright copyright (c) 2000-2003 XOOPS.org 60 */ 61 class XoopsConfigItem extends XoopsObject 62 { 63 64 /** 65 * Config options 66 * 67 * @var array 68 * @access private 69 */ 70 var $_confOptions = array(); 71 72 /** 73 * Constructor 74 */ 75 function XoopsConfigItem() 76 { 77 $this->initVar('conf_id', XOBJ_DTYPE_INT, null, false); 78 $this->initVar('conf_modid', XOBJ_DTYPE_INT, null, false); 79 $this->initVar('conf_catid', XOBJ_DTYPE_INT, null, false); 80 $this->initVar('conf_name', XOBJ_DTYPE_OTHER); 81 $this->initVar('conf_title', XOBJ_DTYPE_TXTBOX); 82 $this->initVar('conf_value', XOBJ_DTYPE_TXTAREA); 83 $this->initVar('conf_desc', XOBJ_DTYPE_OTHER); 84 $this->initVar('conf_formtype', XOBJ_DTYPE_OTHER); 85 $this->initVar('conf_valuetype', XOBJ_DTYPE_OTHER); 86 $this->initVar('conf_order', XOBJ_DTYPE_INT); 87 } 88 89 /** 90 * Get a config value in a format ready for output 91 * 92 * @return string 93 */ 94 function getConfValueForOutput() 95 { 96 switch ($this->getVar('conf_valuetype')) { 97 case 'int': 98 return intval($this->getVar('conf_value', 'N')); 99 break; 100 case 'array': 101 return unserialize($this->getVar('conf_value', 'N')); 102 case 'float': 103 $value = $this->getVar('conf_value', 'N'); 104 return (float)$value; 105 break; 106 case 'textarea': 107 return $this->getVar('conf_value'); 108 default: 109 return $this->getVar('conf_value', 'N'); 110 break; 111 } 112 } 113 114 /** 115 * Set a config value 116 * 117 * @param mixed &$value Value 118 * @param bool $force_slash 119 */ 120 function setConfValueForInput(&$value, $force_slash = false) 121 { 122 switch($this->getVar('conf_valuetype')) { 123 case 'array': 124 if (!is_array($value)) { 125 $value = explode('|', trim($value)); 126 } 127 $this->setVar('conf_value', serialize($value), $force_slash); 128 break; 129 case 'text': 130 $this->setVar('conf_value', trim($value), $force_slash); 131 break; 132 default: 133 $this->setVar('conf_value', $value, $force_slash); 134 break; 135 } 136 } 137 138 /** 139 * Assign one or more {@link XoopsConfigItemOption}s 140 * 141 * @param mixed $option either a {@link XoopsConfigItemOption} object or an array of them 142 */ 143 function setConfOptions($option) 144 { 145 if (is_array($option)) { 146 $count = count($option); 147 for ($i = 0; $i < $count; $i++) { 148 $this->setConfOptions($option[$i]); 149 } 150 } else { 151 if(is_object($option)) { 152 $this->_confOptions[] =& $option; 153 } 154 } 155 } 156 157 /** 158 * Get the {@link XoopsConfigItemOption}s of this Config 159 * 160 * @return array array of {@link XoopsConfigItemOption} 161 */ 162 function &getConfOptions() 163 { 164 return $this->_confOptions; 165 } 166 } 167 168 169 /** 170 * XOOPS configuration handler class. 171 * 172 * This class is responsible for providing data access mechanisms to the data source 173 * of XOOPS configuration class objects. 174 * 175 * @author Kazumi Ono <onokazu@xoops.org> 176 * @copyright copyright (c) 2000-2003 XOOPS.org 177 */ 178 class XoopsConfigItemHandler extends XoopsObjectHandler 179 { 180 181 /** 182 * Create a new {@link XoopsConfigItem} 183 * 184 * @see XoopsConfigItem 185 * @param bool $isNew Flag the config as "new"? 186 * @return object reference to the new config 187 */ 188 function &create($isNew = true) 189 { 190 $config = new XoopsConfigItem(); 191 if ($isNew) { 192 $config->setNew(); 193 } 194 return $config; 195 } 196 197 /** 198 * Load a config from the database 199 * 200 * @param int $id ID of the config 201 * @return object reference to the config, FALSE on fail 202 */ 203 function &get($id) 204 { 205 $config = false; 206 $id = intval($id); 207 if ($id > 0) { 208 $sql = 'SELECT * FROM '.$this->db->prefix('config').' WHERE conf_id='.$id; 209 if (!$result = $this->db->query($sql)) { 210 return $config; 211 } 212 $numrows = $this->db->getRowsNum($result); 213 if ($numrows == 1) { 214 $myrow = $this->db->fetchArray($result); 215 $config = new XoopsConfigItem(); 216 $config->assignVars($myrow); 217 } 218 } 219 return $config; 220 } 221 222 /** 223 * Write a config to the database 224 * 225 * @param object &$config {@link XoopsConfigItem} object 226 * @return mixed FALSE on fail. 227 */ 228 function insert(&$config) 229 { 230 if (strtolower(get_class($config)) != 'xoopsconfigitem') { 231 return false; 232 } 233 if (!$config->isDirty()) { 234 return true; 235 } 236 if (!$config->cleanVars()) { 237 return false; 238 } 239 foreach ($config->cleanVars as $k => $v) { 240 ${$k} = $v; 241 } 242 if ($config->isNew()) { 243 $conf_id = $this->db->genId('config_conf_id_seq'); 244 $sql = sprintf("INSERT INTO %s (conf_id, conf_modid, conf_catid, conf_name, conf_title, conf_value, conf_desc, conf_formtype, conf_valuetype, conf_order) VALUES (%u, %u, %u, %s, %s, %s, %s, %s, %s, %u)", $this->db->prefix('config'), $conf_id, $conf_modid, $conf_catid, $this->db->quoteString($conf_name), $this->db->quoteString($conf_title), $this->db->quoteString($conf_value), $this->db->quoteString($conf_desc), $this->db->quoteString($conf_formtype), $this->db->quoteString($conf_valuetype), $conf_order); 245 } else { 246 $sql = sprintf("UPDATE %s SET conf_modid = %u, conf_catid = %u, conf_name = %s, conf_title = %s, conf_value = %s, conf_desc = %s, conf_formtype = %s, conf_valuetype = %s, conf_order = %u WHERE conf_id = %u", $this->db->prefix('config'), $conf_modid, $conf_catid, $this->db->quoteString($conf_name), $this->db->quoteString($conf_title), $this->db->quoteString($conf_value), $this->db->quoteString($conf_desc), $this->db->quoteString($conf_formtype), $this->db->quoteString($conf_valuetype), $conf_order, $conf_id); 247 } 248 if (!$result = $this->db->query($sql)) { 249 return false; 250 } 251 if (empty($conf_id)) { 252 $conf_id = $this->db->getInsertId(); 253 } 254 $config->assignVar('conf_id', $conf_id); 255 return true; 256 } 257 258 /** 259 * Delete a config from the database 260 * 261 * @param object &$config Config to delete 262 * @return bool Successful? 263 */ 264 function delete(&$config) 265 { 266 if (strtolower(get_class($config)) != 'xoopsconfigitem') { 267 return false; 268 } 269 $sql = sprintf("DELETE FROM %s WHERE conf_id = %u", $this->db->prefix('config'), $config->getVar('conf_id')); 270 if (!$result = $this->db->query($sql)) { 271 return false; 272 } 273 return true; 274 } 275 276 /** 277 * Get configs from the database 278 * 279 * @param object $criteria {@link CriteriaElement} 280 * @param bool $id_as_key return the config's id as key? 281 * @return array Array of {@link XoopsConfigItem} objects 282 */ 283 function getObjects($criteria = null, $id_as_key = false) 284 { 285 $ret = array(); 286 $limit = $start = 0; 287 $sql = 'SELECT * FROM '.$this->db->prefix('config'); 288 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 289 $sql .= ' '.$criteria->renderWhere(); 290 $sql .= ' ORDER BY conf_order ASC'; 291 $limit = $criteria->getLimit(); 292 $start = $criteria->getStart(); 293 } 294 $result = $this->db->query($sql, $limit, $start); 295 if (!$result) { 296 return false; 297 } 298 while ($myrow = $this->db->fetchArray($result)) { 299 $config = new XoopsConfigItem(); 300 $config->assignVars($myrow); 301 if (!$id_as_key) { 302 $ret[] =& $config; 303 } else { 304 $ret[$myrow['conf_id']] =& $config; 305 } 306 unset($config); 307 } 308 return $ret; 309 } 310 311 /** 312 * Count configs 313 * 314 * @param object $criteria {@link CriteriaElement} 315 * @return int Count of configs matching $criteria 316 */ 317 function getCount($criteria = null) 318 { 319 $ret = array(); 320 $limit = $start = 0; 321 $sql = 'SELECT * FROM '.$this->db->prefix('config'); 322 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 323 $sql .= ' '.$criteria->renderWhere(); 324 } 325 $result =& $this->db->query($sql); 326 if (!$result) { 327 return false; 328 } 329 list($count) = $this->db->fetchRow($result); 330 return $count; 331 } 332 } 333 334 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Nov 25 11:44:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |