Changeset 2566:9bf417837888 for inc/core/class.dc.namespace.php
- Timestamp:
- 11/17/13 20:25:53 (12 years ago)
- Branch:
- 2.6
- Children:
- 2567:6c11245cbf04, 2568:61c67a7d17fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
inc/core/class.dc.namespace.php
r1179 r2566 22 22 protected $table; ///< <b>string</b> Settings table name 23 23 protected $blog_id; ///< <b>string</b> Blog ID 24 24 25 25 protected $global_settings = array(); ///< <b>array</b> Global settings array 26 26 protected $local_settings = array(); ///< <b>array</b> Local settings array 27 27 protected $settings = array(); ///< <b>array</b> Associative settings array 28 28 protected $ns; ///< <b>string</b> Current namespace 29 29 30 30 /** 31 31 Object constructor. Retrieves blog settings and puts them in $settings 32 32 array. Local (blog) settings have a highest priority than global settings. 33 33 34 34 @param name <b>string</b> ID for this namespace 35 35 */ … … 41 41 throw new Exception(sprintf(__('Invalid setting dcNamespace: %s'),$name)); 42 42 } 43 43 44 44 $this->con =& $core->con; 45 45 $this->table = $core->prefix.'setting'; 46 46 $this->blog_id =& $blog_id; 47 47 48 48 $this->getSettings($rs); 49 49 } 50 50 51 51 private function getSettings($rs=null) 52 { 52 { 53 53 if ($rs == null) { 54 54 $strReq = 'SELECT blog_id, setting_id, setting_value, '. … … 59 59 "AND setting_ns = '".$this->con->escape($this->ns)."' ". 60 60 'ORDER BY setting_id DESC '; 61 61 62 62 try { 63 63 $rs = $this->con->select($strReq); … … 74 74 $value = $rs->f('setting_value'); 75 75 $type = $rs->f('setting_type'); 76 76 77 77 if ($type == 'float' || $type == 'double') { 78 78 $type = 'float'; … … 80 80 $type = 'string'; 81 81 } 82 82 83 83 settype($value,$type); 84 84 85 85 $array = $rs->blog_id ? 'local' : 'global'; 86 86 87 87 $this->{$array.'_settings'}[$id] = array( 88 88 'ns' => $this->ns, … … 93 93 ); 94 94 } 95 95 96 96 $this->settings = $this->global_settings; 97 97 98 98 foreach ($this->local_settings as $id => $v) { 99 99 $this->settings[$id] = $v; 100 100 } 101 101 102 102 return true; 103 103 } 104 104 105 105 private function settingExists($id,$global=false) 106 106 { … … 108 108 return isset($this->{$array.'_settings'}[$id]); 109 109 } 110 110 111 111 /** 112 112 Returns setting value if exists. 113 113 114 114 @param n <b>string</b> Setting name 115 115 @return <b>mixed</b> … … 120 120 return $this->settings[$n]['value']; 121 121 } 122 122 123 123 return null; 124 124 } 125 125 126 126 /** 127 127 Magic __get method. … … 132 132 return $this->get($n); 133 133 } 134 134 135 135 /** 136 136 Sets a setting in $settings property. This sets the setting for script 137 137 execution time only and if setting exists. 138 138 139 139 @param n <b>string</b> Setting name 140 140 @param v <b>mixed</b> Setting value … … 146 146 } 147 147 } 148 148 149 149 /** 150 150 Magic __set method. … … 155 155 $this->set($n,$v); 156 156 } 157 157 158 158 /** 159 159 Creates or updates a setting. 160 160 161 161 $type could be 'string', 'integer', 'float', 'boolean' or null. If $type is 162 162 null and setting exists, it will keep current setting type. 163 163 164 164 $value_change allow you to not change setting. Useful if you need to change 165 165 a setting label or type and don't want to change its value. 166 166 167 167 @param id <b>string</b> Setting ID 168 168 @param value <b>mixed</b> Setting value … … 177 177 throw new Exception(sprintf(__('%s is not a valid setting id'),$id)); 178 178 } 179 179 180 180 # We don't want to change setting value 181 181 if (!$value_change) … … 187 187 } 188 188 } 189 189 190 190 # Setting type 191 191 if ($type == 'double') … … 207 207 $type = 'string'; 208 208 } 209 209 210 210 # We don't change label 211 211 if ($label == null) … … 217 217 } 218 218 } 219 219 220 220 settype($value,$type); 221 221 222 222 $cur = $this->con->openCursor($this->table); 223 223 $cur->setting_value = ($type == 'boolean') ? (string) (integer) $value : (string) $value; 224 224 $cur->setting_type = $type; 225 225 $cur->setting_label = $label; 226 226 227 227 #If we are local, compare to global value 228 228 if (!$global && $this->settingExists($id,true)) … … 231 231 $same_setting = $g['ns'] == $this->ns && $g['value'] == $value 232 232 && $g['type'] == $type && $g['label'] == $label; 233 233 234 234 # Drop setting if same value as global 235 235 if ($same_setting && $this->settingExists($id,false)) { … … 239 239 } 240 240 } 241 241 242 242 if ($this->settingExists($id,$global) && $this->ns == $this->settings[$id]['ns']) 243 243 { … … 247 247 $where = "WHERE blog_id = '".$this->con->escape($this->blog_id)."' "; 248 248 } 249 249 250 250 $cur->update($where."AND setting_id = '".$this->con->escape($id)."' AND setting_ns = '".$this->con->escape($this->ns)."' "); 251 251 } … … 255 255 $cur->blog_id = $global ? null : $this->blog_id; 256 256 $cur->setting_ns = $this->ns; 257 257 258 258 $cur->insert(); 259 259 } … … 272 272 throw new Exception(__('No namespace specified')); 273 273 } 274 274 275 275 if (!array_key_exists($oldId,$this->settings) || array_key_exists($newId,$this->settings)) { 276 276 return false; … … 291 291 292 292 /** 293 Removes an existing setting in a Namespace 294 293 Removes an existing setting in a Namespace 294 295 295 @param id <b>string</b> Setting ID 296 296 */ … … 300 300 throw new Exception(__('No namespace specified')); 301 301 } 302 302 303 303 $strReq = 'DELETE FROM '.$this->table.' '; 304 304 305 305 if ($this->blog_id === null) { 306 306 $strReq .= 'WHERE blog_id IS NULL '; … … 308 308 $strReq .= "WHERE blog_id = '".$this->con->escape($this->blog_id)."' "; 309 309 } 310 310 311 311 $strReq .= "AND setting_id = '".$this->con->escape($id)."' "; 312 312 $strReq .= "AND setting_ns = '".$this->con->escape($this->ns)."' "; 313 313 314 314 $this->con->execute($strReq); 315 315 } 316 317 /** 318 Removes all existing settings in a Namespace 319 316 317 /** 318 Removes all existing settings in a Namespace 319 320 320 @param force_global <b>boolean</b> Force global pref drop 321 321 */ … … 325 325 throw new Exception(__('No namespace specified')); 326 326 } 327 327 328 328 $strReq = 'DELETE FROM '.$this->table.' '; 329 329 330 330 if (($force_global) || ($this->blog_id === null)) { 331 331 $strReq .= 'WHERE blog_id IS NULL '; … … 335 335 $global = false; 336 336 } 337 337 338 338 $strReq .= "AND setting_ns = '".$this->con->escape($this->ns)."' "; 339 339 340 340 $this->con->execute($strReq); 341 341 342 342 $array = $global ? 'global' : 'local'; 343 343 unset($this->{$array.'_settings'}); 344 344 $this->{$array.'_settings'} = array(); 345 345 346 346 $array = $global ? 'local' : 'global'; 347 347 $this->settings = $this->{$array.'_settings'}; 348 348 } 349 349 350 350 /** 351 351 Returns $settings property content. 352 352 353 353 @return <b>array</b> 354 354 */ … … 357 357 return $this->settings; 358 358 } 359 359 360 360 /** 361 361 Returns $global_settings property content. 362 362 363 363 @return <b>array</b> 364 364 */ … … 369 369 370 370 } 371 ?>
Note: See TracChangeset
for help on using the changeset viewer.