Dotclear


Ignore:
Timestamp:
11/17/13 20:25:53 (12 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
2.6
Children:
2567:6c11245cbf04, 2568:61c67a7d17fa
Message:

Add some people in CREDITS, remove trailing spaces and tabs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inc/core/class.dc.namespace.php

    r1179 r2566  
    2222     protected $table;        ///< <b>string</b> Settings table name 
    2323     protected $blog_id;      ///< <b>string</b> Blog ID 
    24       
     24 
    2525     protected $global_settings = array();   ///< <b>array</b> Global settings array 
    2626     protected $local_settings = array();    ///< <b>array</b> Local settings array 
    2727     protected $settings = array();          ///< <b>array</b> Associative settings array 
    2828     protected $ns;           ///< <b>string</b> Current namespace 
    29       
     29 
    3030     /** 
    3131     Object constructor. Retrieves blog settings and puts them in $settings 
    3232     array. Local (blog) settings have a highest priority than global settings. 
    33       
     33 
    3434     @param    name      <b>string</b>       ID for this namespace 
    3535     */ 
     
    4141               throw new Exception(sprintf(__('Invalid setting dcNamespace: %s'),$name)); 
    4242          } 
    43            
     43 
    4444          $this->con =& $core->con; 
    4545          $this->table = $core->prefix.'setting'; 
    4646          $this->blog_id =& $blog_id; 
    47            
     47 
    4848          $this->getSettings($rs); 
    4949     } 
    50       
     50 
    5151     private function getSettings($rs=null) 
    52      {     
     52     { 
    5353          if ($rs == null) { 
    5454               $strReq = 'SELECT blog_id, setting_id, setting_value, '. 
     
    5959                         "AND setting_ns = '".$this->con->escape($this->ns)."' ". 
    6060                         'ORDER BY setting_id DESC '; 
    61            
     61 
    6262               try { 
    6363                    $rs = $this->con->select($strReq); 
     
    7474               $value = $rs->f('setting_value'); 
    7575               $type = $rs->f('setting_type'); 
    76                 
     76 
    7777               if ($type == 'float' || $type == 'double') { 
    7878                    $type = 'float'; 
     
    8080                    $type = 'string'; 
    8181               } 
    82                 
     82 
    8383               settype($value,$type); 
    84                 
     84 
    8585               $array = $rs->blog_id ? 'local' : 'global'; 
    86                 
     86 
    8787               $this->{$array.'_settings'}[$id] = array( 
    8888                    'ns' => $this->ns, 
     
    9393               ); 
    9494          } 
    95            
     95 
    9696          $this->settings = $this->global_settings; 
    97            
     97 
    9898          foreach ($this->local_settings as $id => $v) { 
    9999               $this->settings[$id] = $v; 
    100100          } 
    101            
     101 
    102102          return true; 
    103103     } 
    104       
     104 
    105105     private function settingExists($id,$global=false) 
    106106     { 
     
    108108          return isset($this->{$array.'_settings'}[$id]); 
    109109     } 
    110       
     110 
    111111     /** 
    112112     Returns setting value if exists. 
    113       
     113 
    114114     @param    n         <b>string</b>       Setting name 
    115115     @return   <b>mixed</b> 
     
    120120               return $this->settings[$n]['value']; 
    121121          } 
    122            
     122 
    123123          return null; 
    124124     } 
    125       
     125 
    126126     /** 
    127127     Magic __get method. 
     
    132132          return $this->get($n); 
    133133     } 
    134       
     134 
    135135     /** 
    136136     Sets a setting in $settings property. This sets the setting for script 
    137137     execution time only and if setting exists. 
    138       
     138 
    139139     @param    n         <b>string</b>       Setting name 
    140140     @param    v         <b>mixed</b>        Setting value 
     
    146146          } 
    147147     } 
    148       
     148 
    149149     /** 
    150150     Magic __set method. 
     
    155155          $this->set($n,$v); 
    156156     } 
    157       
     157 
    158158     /** 
    159159     Creates or updates a setting. 
    160       
     160 
    161161     $type could be 'string', 'integer', 'float', 'boolean' or null. If $type is 
    162162     null and setting exists, it will keep current setting type. 
    163       
     163 
    164164     $value_change allow you to not change setting. Useful if you need to change 
    165165     a setting label or type and don't want to change its value. 
    166       
     166 
    167167     @param    id             <b>string</b>       Setting ID 
    168168     @param    value          <b>mixed</b>        Setting value 
     
    177177               throw new Exception(sprintf(__('%s is not a valid setting id'),$id)); 
    178178          } 
    179            
     179 
    180180          # We don't want to change setting value 
    181181          if (!$value_change) 
     
    187187               } 
    188188          } 
    189            
     189 
    190190          # Setting type 
    191191          if ($type == 'double') 
     
    207207               $type = 'string'; 
    208208          } 
    209            
     209 
    210210          # We don't change label 
    211211          if ($label == null) 
     
    217217               } 
    218218          } 
    219            
     219 
    220220          settype($value,$type); 
    221            
     221 
    222222          $cur = $this->con->openCursor($this->table); 
    223223          $cur->setting_value = ($type == 'boolean') ? (string) (integer) $value : (string) $value; 
    224224          $cur->setting_type = $type; 
    225225          $cur->setting_label = $label; 
    226            
     226 
    227227          #If we are local, compare to global value 
    228228          if (!$global && $this->settingExists($id,true)) 
     
    231231               $same_setting = $g['ns'] == $this->ns && $g['value'] == $value 
    232232               && $g['type'] == $type && $g['label'] == $label; 
    233                 
     233 
    234234               # Drop setting if same value as global 
    235235               if ($same_setting && $this->settingExists($id,false)) { 
     
    239239               } 
    240240          } 
    241            
     241 
    242242          if ($this->settingExists($id,$global) && $this->ns == $this->settings[$id]['ns']) 
    243243          { 
     
    247247                    $where = "WHERE blog_id = '".$this->con->escape($this->blog_id)."' "; 
    248248               } 
    249                 
     249 
    250250               $cur->update($where."AND setting_id = '".$this->con->escape($id)."' AND setting_ns = '".$this->con->escape($this->ns)."' "); 
    251251          } 
     
    255255               $cur->blog_id = $global ? null : $this->blog_id; 
    256256               $cur->setting_ns = $this->ns; 
    257                 
     257 
    258258               $cur->insert(); 
    259259          } 
     
    272272               throw new Exception(__('No namespace specified')); 
    273273          } 
    274            
     274 
    275275          if (!array_key_exists($oldId,$this->settings) || array_key_exists($newId,$this->settings)) { 
    276276               return false; 
     
    291291 
    292292     /** 
    293      Removes an existing setting in a Namespace  
    294       
     293     Removes an existing setting in a Namespace 
     294 
    295295     @param    id        <b>string</b>       Setting ID 
    296296     */ 
     
    300300               throw new Exception(__('No namespace specified')); 
    301301          } 
    302            
     302 
    303303          $strReq = 'DELETE FROM '.$this->table.' '; 
    304            
     304 
    305305          if ($this->blog_id === null) { 
    306306               $strReq .= 'WHERE blog_id IS NULL '; 
     
    308308               $strReq .= "WHERE blog_id = '".$this->con->escape($this->blog_id)."' "; 
    309309          } 
    310            
     310 
    311311          $strReq .= "AND setting_id = '".$this->con->escape($id)."' "; 
    312312          $strReq .= "AND setting_ns = '".$this->con->escape($this->ns)."' "; 
    313            
     313 
    314314          $this->con->execute($strReq); 
    315315     } 
    316       
    317      /** 
    318      Removes all existing settings in a Namespace  
    319       
     316 
     317     /** 
     318     Removes all existing settings in a Namespace 
     319 
    320320     @param    force_global   <b>boolean</b> Force global pref drop 
    321321     */ 
     
    325325               throw new Exception(__('No namespace specified')); 
    326326          } 
    327            
     327 
    328328          $strReq = 'DELETE FROM '.$this->table.' '; 
    329            
     329 
    330330          if (($force_global) || ($this->blog_id === null)) { 
    331331               $strReq .= 'WHERE blog_id IS NULL '; 
     
    335335               $global = false; 
    336336          } 
    337            
     337 
    338338          $strReq .= "AND setting_ns = '".$this->con->escape($this->ns)."' "; 
    339            
     339 
    340340          $this->con->execute($strReq); 
    341            
     341 
    342342          $array = $global ? 'global' : 'local'; 
    343343          unset($this->{$array.'_settings'}); 
    344344          $this->{$array.'_settings'} = array(); 
    345            
     345 
    346346          $array = $global ? 'local' : 'global'; 
    347347          $this->settings = $this->{$array.'_settings'}; 
    348348     } 
    349       
     349 
    350350     /** 
    351351     Returns $settings property content. 
    352       
     352 
    353353     @return   <b>array</b> 
    354354     */ 
     
    357357          return $this->settings; 
    358358     } 
    359       
     359 
    360360     /** 
    361361     Returns $global_settings property content. 
    362       
     362 
    363363     @return   <b>array</b> 
    364364     */ 
     
    369369 
    370370} 
    371 ?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map