[ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 /* 3 +---------------------------------------------------------------+ 4 | e107 website system 5 | /e107_handlers/pref_class.php 6 | 7 | ©Steve Dunstan 2001-2002 8 | http://e107.org 9 | jalist@e107.org 10 | 11 | Released under the terms and conditions of the 12 | GNU General Public License (http://gnu.org). 13 +---------------------------------------------------------------+ 14 */ 15 16 if (!defined('e107_INIT')) { exit; } 17 18 // 19 // Simple functionality: 20 // Grab all prefs once, in one DB query. Reuse them throughout the session. 21 // 22 // get/set methods serve/consume strings (with slashes taken care of) 23 // getArray/setArray methods serve/consume entire arrays (since most prefs are such!) 24 // 25 // NOTE: Use of this class is VALUABLE (efficient) yet not NECESSARY (i.e. the system 26 // will not break if it is ignored)... AS LONG AS there is no path consisting of: 27 // - modify pref value(s) IGNORING this class 28 // - retrieve pref value(s) USING this class 29 // (while processing a single web page) 30 // Just to be safe I have changed a number of menu_pref edits to use setArray(). 31 // 32 33 class prefs { 34 var $prefVals; 35 var $prefArrays; 36 37 // List of rows that shouldn't be automatically extracted (delimeted by '|') 38 var $DefaultRows = "e107_name='e107' OR e107_name='menu_pref' OR e107_name='notify_prefs'"; 39 40 function ExtractPrefs($RowList = "", $use_default = FALSE) { 41 global $sql; 42 $Args = ''; 43 if($use_default) 44 { 45 $Args = $this->DefaultRows; 46 } 47 if(is_array($RowList)) 48 { 49 foreach($RowList as $v) 50 { 51 $Args .= ($Args ? " OR e107_name='{$v}'" : "e107_name='{$v}'"); 52 } 53 } 54 $sql->db_Select('core', '*', $Args, 'default'); 55 while ($row = $sql->db_Fetch()) 56 { 57 $this->prefVals['core'][$row['e107_name']] = $row['e107_value']; 58 } 59 } 60 61 /** 62 * Return current pref string $name from $table (only core for now) 63 * 64 * - @param string $name -- name of pref row 65 * - @param string $table -- "core" 66 * - @return string pref value, slashes already stripped 67 * - @access public 68 */ 69 function get($Name) { 70 if(isset($this->prefVals['core'][$Name])){ 71 if($this->prefVals['core'][$Name] != '### ROW CACHE FALSE ###'){ 72 return $this->prefVals['core'][$Name]; 73 } else { 74 return false; 75 } 76 } 77 78 $get_sql = new db; // required so sql loops don't break using $tp->toHTML(). 79 if($get_sql->db_Select('core', '*', "`e107_name` = '{$Name}'", 'default')) { 80 $row = $get_sql->db_Fetch(); 81 $this->prefVals['core'][$Name] = $row['e107_value']; 82 return $this->prefVals['core'][$Name]; 83 } else { 84 $this->prefVals['core'][$Name] = '### ROW CACHE FALSE ###'; 85 return false; 86 } 87 } 88 89 /** 90 * Return current array from pref string $name in $table (core only for now) 91 * 92 * - @param: string $name -- name of pref row 93 * - @param string $table -- "core" only now 94 * - @return array pref values 95 * - @access public 96 */ 97 // retrieve prefs as an array of values 98 function getArray($name) { 99 return unserialize($this->get($name)); 100 } 101 102 103 /** 104 * Update pref set and cache 105 * 106 * @param string val -- pre-serialized string 107 * @param string $name -- name of pref row 108 * @param string $table -- "core" or "user" 109 * @global $$name 110 * @access public 111 * 112 * set("val") == 'core', 'pref' 113 * set("val","rowname") == 'core', rowname 114 * set("val","","user") == 'user', 'user_pref' for current user 115 * set("val","","user",uid) == 'user', 'user_pref' for user uid 116 * set("val","fieldname","user") == 'user', fieldname 117 * 118 */ 119 function set($val, $name = "", $table = "core", $uid = USERID) { 120 global $sql; 121 if (!strlen($name)) { 122 switch ($table) { 123 case 'core': 124 $name = "pref"; 125 break; 126 case 'user': 127 $name = "user_pref"; 128 break; 129 } 130 } 131 $val = addslashes($val); 132 133 switch ($table ) { 134 case 'core': 135 if(!$sql->db_Update($table, "e107_value='$val' WHERE e107_name='$name'")) 136 { 137 $sql->db_Insert($table, "'{$name}', '{$val}'"); 138 } 139 $this->prefVals[$table][$name] = $val; 140 unset($this->prefArrays[$table][$name]); 141 break; 142 case 'user': 143 $sql->db_Update($table, "user_prefs='$val' WHERE user_id=$uid"); 144 break; 145 } 146 } 147 148 149 /** 150 * Update pref set and cache 151 * 152 * - @param string $name -- name of pref row 153 * - @param string $table -- "core" or "user" 154 * - @global $$name 155 * - @access public 156 * 157 * set() == core, pref 158 * set("rowname") == core, rowname 159 * set("","user") == user, user_pref for current user 160 * set("","user",uid) == user, user_pref for user uid 161 * set("fieldname","user") == user, fieldname 162 * 163 * all pref sets other than menu_pref get toDB() 164 */ 165 function setArray($name = "", $table = "core", $uid = USERID) { 166 global $tp; 167 168 if (!strlen($name)) { 169 switch ($table) { 170 case 'core': 171 $name = "pref"; 172 break; 173 case 'user': 174 $name = "user_pref"; 175 break; 176 } 177 } 178 179 global $$name; 180 if ($name != "menu_pref") { 181 foreach($$name as $key => $prefvalue) { 182 $$name[$key] = $tp->toDB($prefvalue); 183 } 184 } 185 186 $tmp = serialize($$name); 187 $this->set($tmp, $name, $table, $uid); 188 } 189 } 190 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |