b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _abstractsettings.class.php

Documentation is available at _abstractsettings.class.php

  1. <?php
  2. /**
  3.  * This file implements the AbstractSettings class designed to handle any kind of settings.
  4.  *
  5.  * This file is part of the evoCore framework - {@link http://evocore.net/}
  6.  * See also {@link http://sourceforge.net/projects/evocms/}.
  7.  *
  8.  * @copyright (c)2003-2010 by Francois PLANQUE - {@link http://fplanque.net/}
  9.  *  Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
  10.  *
  11.  *  {@internal License choice
  12.  *  - If you have received this file as part of a package, please find the license.txt file in
  13.  *    the same folder or the closest folder above for complete license terms.
  14.  *  - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  15.  *    then you must choose one of the following licenses before using the file:
  16.  *    - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  17.  *    - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  18.  *  }}}
  19.  *
  20.  *  {@internal Open Source relicensing agreement:
  21.  *  Daniel HAHLER grants Francois PLANQUE the right to license
  22.  *  Daniel HAHLER's contributions to this file and the b2evolution project
  23.  *  under any OSI approved OSS license (http://www.opensource.org/licenses/).
  24.  *  }}}
  25.  *
  26.  * @package evocore
  27.  *
  28.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  29.  * @author blueyed: Daniel HAHLER
  30.  * @author fplanque: Francois PLANQUE
  31.  *
  32.  * @version $Id: _abstractsettings.class.php,v 1.9 2010/02/08 17:53:55 efy-yury Exp $
  33.  */
  34. if!defined('EVO_MAIN_INIT') ) die'Please, do not access this page directly.' );
  35.  
  36.  
  37. // DEBUG: (Turn switch on or off to log debug info for specified category)
  38. $GLOBALS['debug_settings'false;
  39.  
  40.  
  41. /**
  42.  * Class to handle settings in an abstract manner (to get used with either 1, 2 or 3 DB column keys).
  43.  *
  44.  * Arrays and Objects automatically get serialized and unserialized
  45.  * (in {@link AbstractSettings::get()} and {@link AbstractSettings::dbupdate()}).
  46.  *
  47.  * Note: I've evaluated splitting this into single classes for performance reasons, but only
  48.  *       get() is relevant performance-wise and we could now only get rid of the switch() therein,
  49.  *       which is not sufficient to split it into *_base + _X classes. (blueyed, 2006-08)
  50.  *
  51.  * @package evocore
  52.  * @abstract
  53.  * @see UserSettings, GeneralSettings, PluginSettings, CollectionSettings
  54.  */
  55. {
  56.     /**
  57.      * The DB table which stores the settings.
  58.      *
  59.      * @var string 
  60.      * @access protected
  61.      */
  62.     var $db_table_name;
  63.  
  64.     /**
  65.      * Array with DB column key names.
  66.      *
  67.      * @var array 
  68.      * @access protected
  69.      */
  70.     var $col_key_names = array();
  71.  
  72.     /**
  73.      * DB column name for the value.
  74.      *
  75.      * @var string 
  76.      * @access protected
  77.      */
  78.     var $col_value_name;
  79.  
  80.  
  81.     /**
  82.      * The number of column keys to cache by. This are the first x keys of
  83.      * {@link $col_key_names}. 0 means 'load all'.
  84.      *
  85.      * @var integer 
  86.      */
  87.     var $cache_by_col_keys;
  88.  
  89.  
  90.     /**
  91.      * The internal cache.
  92.      *
  93.      * false, if settings  could not be loaded or NULL if not initialized.
  94.      *
  95.       * @access protected
  96.      * @var array 
  97.      */
  98.     var $cache = NULL;
  99.  
  100.  
  101.     /**
  102.      * Do we have loaded everything?
  103.      *
  104.      * @var boolean 
  105.      */
  106.     var $all_loaded = false;
  107.  
  108.  
  109.     /**
  110.      * Default settings.
  111.      *
  112.      * Maps last colkeyname to some default setting that will be used by
  113.      * {@link get()} if no value was defined (and it is set as a default).
  114.      *
  115.      * @var array 
  116.      */
  117.     var $_defaults = array();
  118.  
  119.  
  120.     /**
  121.      * Constructor.
  122.      * @param string The name of the DB table with the settings stored.
  123.      * @param array List of names for the DB columns keys that reference a value.
  124.      * @param string The name of the DB column that holds the value.
  125.      * @param integer The number of column keys to cache by. This are the first x keys of {@link $col_key_names}. 0 means 'load all'.
  126.      */
  127.     function AbstractSettings$db_table_name$col_key_names$col_value_name$cache_by_col_keys )
  128.     {
  129.         $this->db_table_name = $db_table_name;
  130.         $this->col_key_names = $col_key_names;
  131.         $this->col_value_name = $col_value_name;
  132.         $this->cache_by_col_keys = $cache_by_col_keys;
  133.  
  134.  
  135.         /**
  136.          * internal counter for the number of column keys
  137.          * @var integer
  138.          */
  139.         $this->count_col_key_names count$this->col_key_names );
  140.  
  141.         if$this->count_col_key_names || $this->count_col_key_names )
  142.         {
  143.             debug_die'Settings keycount not supported for class '.get_class() );
  144.         }
  145.     }
  146.  
  147.  
  148.     /**
  149.      * Load all settings, disregarding the derived classes setting of
  150.      * {@link $cache_by_col_keys} - useful if you know that you want to get
  151.      * all user settings for example.
  152.      */
  153.     function load_all()
  154.     {
  155.         return $this->_load();
  156.     }
  157.  
  158.  
  159.     /**
  160.      * Loads the settings. Not meant to be called directly, but gets called
  161.      * when needed.
  162.      *
  163.      * @access protected
  164.      * @param string First column key
  165.      * @param string Second column key
  166.      * @param string Third column key
  167.      * @return boolean always true
  168.      */
  169.     function _load$arg1 NULL$arg2 NULL$arg3 NULL )
  170.     {
  171.         if$this->all_loaded )
  172.         // already all loaded
  173.             return true;
  174.         }
  175.         global $DB;
  176.  
  177.         /**
  178.          * The where clause - gets filled when {@link $cache_by_col_keys} is used.
  179.          */
  180.         $whereList array();
  181.  
  182.         if$this->cache_by_col_keys && isset($arg1) )
  183.         // The number of column keys to cache by is > 0
  184.             $testCache $this->cache;
  185.             $args array$arg1$arg2$arg3 );
  186.  
  187.             for$i 0$i $this->cache_by_col_keys$i++ )
  188.             {
  189.                 $whereList[$this->col_key_names[$i]." = '".$args[$i]."'";
  190.  
  191.                 ifis_array$testCache )
  192.                         || is_null($args[$i])
  193.                         || isset$testCache[$args[$i]] )
  194.                         || ($testCache $testCache[$args[$i]]) )
  195.                 {
  196.                     break;
  197.                 }
  198.             }
  199.  
  200.             if$i == $this->cache_by_col_keys )
  201.             // already loaded!
  202.                 return true;
  203.             }
  204.         }
  205.         else
  206.         // We cache everything at once!
  207.             $this->all_loaded = true;
  208.         }
  209.  
  210.  
  211.         $result $DB->get_results'
  212.             SELECT '.implode', '$this->col_key_names ).', '.$this->col_value_name.'
  213.             FROM '.$this->db_table_name.(
  214.                 isset$whereList[0)
  215.                 ? ' WHERE '.implode' AND '$whereList )
  216.                 : '' ) );
  217.  
  218.         switch$this->count_col_key_names )
  219.         {
  220.             case 1:
  221.                 if$result )
  222.                 // Remember that we've tried it
  223.                     $this->cache$arg1 NULL;
  224.                 }
  225.                 else foreach$result as $loop_row )
  226.                 {
  227.                     $this->cache[$loop_row->{$this->col_key_names[0]}]->value $loop_row->{$this->col_value_name};
  228.                     $this->cache[$loop_row->{$this->col_key_names[0]}]->dbUptodate true;
  229.                     $this->cache[$loop_row->{$this->col_key_names[0]}]->dbRemove false;
  230.                 }
  231.                 break;
  232.  
  233.             case 2:
  234.                 if$result )
  235.                 // Remember that we've tried it
  236.                     $this->cache$arg1 ]$arg2 NULL;
  237.                 }
  238.                 else foreach$result as $loop_row )
  239.                 {
  240.                     $this->cache[$loop_row->{$this->col_key_names[0]}][$loop_row->{$this->col_key_names[1]}]->value $loop_row->{$this->col_value_name};
  241.                     $this->cache[$loop_row->{$this->col_key_names[0]}][$loop_row->{$this->col_key_names[1]}]->dbUptodate true;
  242.                     $this->cache[$loop_row->{$this->col_key_names[0]}][$loop_row->{$this->col_key_names[1]}]->dbRemove false;
  243.                 }
  244.                 break;
  245.  
  246.             case 3:
  247.                 if$result )
  248.                 // Remember that we've tried it
  249.                     $this->cache$arg1 ]$arg2 ]$arg3 NULL;
  250.                 }
  251.                 else foreach$result as $loop_row )
  252.                 {
  253.                     $this->cache[$loop_row->{$this->col_key_names[0]}][$loop_row->{$this->col_key_names[1]}][$loop_row->{$this->col_key_names[2]}]->value $loop_row->{$this->col_value_name};
  254.                     $this->cache[$loop_row->{$this->col_key_names[0]}][$loop_row->{$this->col_key_names[1]}][$loop_row->{$this->col_key_names[2]}]->dbUptodate true;
  255.                     $this->cache[$loop_row->{$this->col_key_names[0]}][$loop_row->{$this->col_key_names[1]}][$loop_row->{$this->col_key_names[2]}]->dbRemove false;
  256.                 }
  257.                 break;
  258.         }
  259.  
  260.         return true;
  261.     }
  262.  
  263.  
  264.     /**
  265.      * Get a setting from the DB settings table.
  266.      *
  267.      * @uses get_default()
  268.      * @param string First column key
  269.      * @param string Second column key
  270.      * @param string Third column key
  271.      * @return string|false|NULLvalue as string on success; NULL if not found; false in case of error
  272.      */
  273.     function get$col_key1$col_key2 NULL$col_key3 NULL )
  274.     {
  275.         global $debug;
  276.  
  277.         if$debug )
  278.         {
  279.             global $Debuglog$Timer;
  280.             $this_class get_class($this);
  281.             $Timer->resume('abstractsettings_'.$this_class.'_get'false );
  282.         }
  283.  
  284.         switch$this->count_col_key_names )
  285.         {
  286.             case 1:
  287.                 $this->_load$col_key1 );
  288.                 if!empty($this->cache$col_key1 ]->unserialized) )
  289.                 {    // The value has been unserialized before:
  290.                     $r $this->cache$col_key1 ]->value;
  291.                 }
  292.                 elseifisset($this->cache$col_key1 ]->value) )
  293.                 {    // First attempt to access the value, we need to unserialize it:
  294.                     // Try to unserialize setting (once) - this is as fast as checking an array of values that should get unserialized
  295.                     if( ($r @unserialize($this->cache$col_key1 ]->value)) !== false )
  296.                     {
  297.                         $this->cache$col_key1 ]->value $r;
  298.                     }
  299.                     else
  300.                     {
  301.                         $r $this->cache$col_key1 ]->value;
  302.                     }
  303.                     $this->cache$col_key1 ]->unserialized true;
  304.                 }
  305.                 else
  306.                 {    // The value is not in the cache, we use the default:
  307.                     $r $this->get_default$col_key1 );
  308.                     $this->cache$col_key1 ]->value $r// remember in cache
  309.                     $this->cache$col_key1 ]->dbUptodate true;
  310.                     $this->cache$col_key1 ]->unserialized true;
  311.                     $from_default true// for debug
  312.                 }
  313.                 break;
  314.  
  315.             case 2:
  316.                 $this->_load$col_key1$col_key2 );
  317.  
  318.                 ifisset($this->cache$col_key1 ]$col_key2 ]->unserialized) )
  319.                 {
  320.                     $r $this->cache$col_key1 ]$col_key2 ]->value;
  321.                 }
  322.                 elseifisset($this->cache$col_key1 ]$col_key2 ]->value) )
  323.                 {
  324.                     // Try to unserialize setting (once) - this is as fast as checking an array of values that should get unserialized
  325.                     if( ($r @unserialize($this->cache$col_key1 ]$col_key2 ]->value)) !== false )
  326.                     {
  327.                         $this->cache$col_key1 ]$col_key2 ]->value $r;
  328.                     }
  329.                     else
  330.                     {
  331.                         $r $this->cache$col_key1 ]$col_key2 ]->value;
  332.                     }
  333.                     $this->cache$col_key1 ]$col_key2 ]->unserialized true;
  334.                 }
  335.                 else
  336.                 {
  337.                     $r $this->get_default$col_key2 );
  338.                     $this->cache$col_key1 ]$col_key2 ]->value $r// remember in cache
  339.                     $this->cache$col_key1 ]$col_key2 ]->dbUptodate true;
  340.                     $this->cache$col_key1 ]$col_key2 ]->unserialized true;
  341.                     $from_default true// for debug
  342.                 }
  343.                 break;
  344.  
  345.             case 3:
  346.                 $this->_load$col_key1$col_key2$col_key3 );
  347.  
  348.                 ifisset($this->cache$col_key1 ]$col_key2 ]$col_key3 ]->unserialized) )
  349.                 {
  350.                     $r $this->cache$col_key1 ]$col_key2 ]$col_key3 ]->value;
  351.                 }
  352.                 elseifisset($this->cache$col_key1 ]$col_key2 ]$col_key3 ]->value) )
  353.                 {
  354.                     // Try to unserialize setting (once) - this is as fast as checking an array of values that should get unserialized
  355.                     if( ($r @unserialize($this->cache$col_key1 ]$col_key2 ]$col_key3 ]->value)) !== false )
  356.                     {
  357.                         $this->cache$col_key1 ]$col_key2 ]$col_key3 ]->value $r;
  358.                     }
  359.                     else
  360.                     {
  361.                         $r $this->cache$col_key1 ]$col_key2 ]$col_key3 ]->value;
  362.                     }
  363.                     $this->cache$col_key1 ]$col_key2 ]$col_key3 ]->unserialized true;
  364.                 }
  365.                 else
  366.                 {
  367.                     $r $this->get_default$col_key3 );
  368.                     $this->cache$col_key1 ]$col_key2 ]$col_key3 ]->value $r// remember in cache
  369.                     $this->cache$col_key1 ]$col_key2 ]$col_key3 ]->dbUptodate true;
  370.                     $this->cache$col_key1 ]$col_key2 ]$col_key3 ]->unserialized true;
  371.                     $from_default true// for debug
  372.                 }
  373.                 break;
  374.         }
  375.  
  376.         if$debug )
  377.         {
  378.             $Debuglog->add$this_class.'::get( '.$col_key1.'/'.$col_key2.'/'.$col_key3.' ): '
  379.                 .isset($from_default'[DEFAULT]: ' '' )
  380.                 .var_export$rtrue )'settings' );
  381.             $Timer->pause('abstractsettings_'.$this_class.'_get'false );
  382.         }
  383.  
  384.         return $r;
  385.     }
  386.  
  387.  
  388.     /**
  389.      * Get the default for the last key of {@link $col_key_names}
  390.      *
  391.      * @param string The last column key
  392.      * @return NULL|mixedNULL if no default is set, otherwise the value (should be string).
  393.      */
  394.     function get_default$last_key )
  395.     {
  396.         ifisset($this->_defaults$last_key ]) )
  397.         {
  398.             return $this->_defaults$last_key ];
  399.         }
  400.  
  401.         return NULL;
  402.     }
  403.  
  404.  
  405.     /**
  406.      * Only set the first variable (passed by reference) if we could retrieve a
  407.      * setting.
  408.      *
  409.      * @param mixed variable to set maybe (by reference)
  410.      * @param string the values for the column keys (depends on $this->col_key_names
  411.      *                and must match its count and order)
  412.      * @return boolean true on success (variable was set), false if not
  413.      */
  414.     function get_cond$toset )
  415.     {
  416.         $args func_get_args();
  417.         array_shift$args );
  418.  
  419.         $result call_user_func_arrayarray$this'get' )$args );
  420.  
  421.         if$result !== NULL && $result !== false )
  422.         // No error and value retrieved
  423.             $toset $result;
  424.             return true;
  425.         }
  426.         else
  427.         {
  428.             return false;
  429.         }
  430.     }
  431.  
  432.  
  433.     /**
  434.      * Temporarily sets a setting ({@link dbupdate()} writes it to DB).
  435.      *
  436.      * @param string $args,... the values for the {@link $col_key_names column keys}
  437.      *                          and {@link $col_value_name column value}. Must match order and count!
  438.      * @return boolean true, if the value has been set, false if it has not changed.
  439.      */
  440.     function set()
  441.     {
  442.         global $Debuglog;
  443.  
  444.         $args func_get_args();
  445.         $value array_pop($args);
  446.  
  447.         call_user_func_arrayarray(&$this'_load')$args );
  448.  
  449.         $debugMsg get_class($this).'::set( '.implode(', '$args ).' ): ';
  450.  
  451.         switch$this->count_col_key_names )
  452.         {
  453.             case 1:
  454.                 $atCache $this->cache$args[0] ];
  455.                 break;
  456.  
  457.             case 2:
  458.                 $atCache $this->cache$args[0] ]$args[1] ];
  459.                 break;
  460.  
  461.             case 3:
  462.                 $atCache $this->cache$args[0] ]$args[1] ]$args[2] ];
  463.                 break;
  464.  
  465.             default:
  466.                 return false;
  467.         }
  468.  
  469.         $atCache->dbRemove false;
  470.  
  471.         ifisset($atCache->value) )
  472.         {
  473.             if$atCache->value == $value )
  474.             // already set
  475.                 $Debuglog->add$debugMsg.' Already set to the same value.''settings' );
  476.                 return false;
  477.             }
  478.         }
  479.  
  480.         $atCache->value $value;
  481.         $atCache->dbUptodate false;
  482.         $atCache->unserialized false// We haven't tried to unserialize the value yet
  483.  
  484.         $Debuglog->add$debugMsg.' SET!''settings' );
  485.  
  486.         return true;
  487.     }
  488.  
  489.  
  490.     /**
  491.      * Set an array of values.
  492.      *
  493.      * @param array Array of parameters for {@link set()}
  494.      */
  495.     function set_array$array )
  496.     {
  497.         foreach$array as $lSet )
  498.         {
  499.             call_user_func_arrayarray$this'set' )$lSet );
  500.         }
  501.     }
  502.  
  503.  
  504.     /**
  505.      * Remove a setting.
  506.      *
  507.      * @param array List of {@link $col_key_names}
  508.      * @return boolean 
  509.      */
  510.     function delete$args )
  511.     {
  512.         $args func_get_args();
  513.  
  514.         switch$this->count_col_key_names )
  515.         {
  516.             case 1:
  517.                 $atCache $this->cache$args[0] ];
  518.                 break;
  519.  
  520.             case 2:
  521.                 $atCache $this->cache$args[0] ]$args[1] ];
  522.                 break;
  523.  
  524.             case 3:
  525.                 $atCache $this->cache$args[0] ]$args[1] ]$args[2] ];
  526.                 break;
  527.  
  528.             default:
  529.                 return false;
  530.         }
  531.  
  532.         $atCache->dbRemove true;
  533.         unset($atCache->unserialized);
  534.         unset($atCache->value);
  535.  
  536.         return true;
  537.     }
  538.  
  539.  
  540.     /**
  541.      * Delete an array of values.
  542.      *
  543.      * @param array Array of parameters for {@link delete()}
  544.      */
  545.     function delete_array$array )
  546.     {
  547.         foreach$array as $lDel )
  548.         {
  549.             call_user_func_arrayarray$this'delete' )array($lDel) );
  550.         }
  551.     }
  552.  
  553.  
  554.     /**
  555.      * Delete values for {@link $_defaults default settings} in DB.
  556.      *
  557.      * This will use the default settings on the next {@link get()}
  558.      * again.
  559.      *
  560.      * @return boolean true, if settings have been updated; false otherwise
  561.      */
  562.     function restore_defaults()
  563.     {
  564.         $this->delete_arrayarray_keys$this->_defaults ) );
  565.  
  566.         return $this->dbupdate();
  567.     }
  568.  
  569.  
  570.     /**
  571.      * Commit changed settings to DB.
  572.      *
  573.      * @return boolean true, if settings have been updated; false otherwise
  574.      */
  575.     function dbupdate()
  576.     {
  577.         ifempty($this->cache) )
  578.         {
  579.             return false;
  580.         }
  581.  
  582.         global $DB;
  583.  
  584.         $query_insert array();
  585.         $query_where_delete array();
  586.  
  587.         switch$this->count_col_key_names )
  588.         {
  589.             case 1:
  590.                 foreach$this->cache as $key => $value )
  591.                 {
  592.                     if$value === NULL )
  593.                     // Remembered as not existing
  594.                         continue;
  595.                     }
  596.                     ifempty($value->dbRemove) )
  597.                     {
  598.                         $query_where_delete["{$this->col_key_names[0]} = '$key'";
  599.                         unset$this->cache[$key);
  600.                     }
  601.                     elseifisset($value->dbUptodate&& !$value->dbUptodate )
  602.                     {
  603.                         $value $value->value;
  604.                         ifis_array$value || is_object$value ) )
  605.                         {
  606.                             $value serialize($value);
  607.                         }
  608.                         $query_insert["('$key', '".$DB->escape$value )."')";
  609.                         $this->cache[$key]->dbUptodate true;
  610.                     }
  611.                 }
  612.                 break;
  613.  
  614.             case 2:
  615.                 foreach$this->cache as $key => $value )
  616.                 {
  617.                     foreach$value as $key2 => $value2 )
  618.                     {
  619.                         if$value2 === NULL )
  620.                         // Remembered as not existing
  621.                             continue;
  622.                         }
  623.                         ifempty($value2->dbRemove) )
  624.                         {
  625.                             $query_where_delete["{$this->col_key_names[0]} = '$key' AND {$this->col_key_names[1]} = '$key2'";
  626.                             unset$this->cache[$key][$key2);
  627.                         }
  628.                         elseifisset($value2->dbUptodate&& !$value2->dbUptodate )
  629.                         {
  630.                             $value2 $value2->value;
  631.                             ifis_array$value2 || is_object$value2 ) )
  632.                             {
  633.                                 $value2 serialize($value2);
  634.                             }
  635.                             $query_insert["('$key', '$key2', '".$DB->escape$value2 )."')";
  636.                             $this->cache[$key][$key2]->dbUptodate true;
  637.                         }
  638.                     }
  639.                 }
  640.                 break;
  641.  
  642.             case 3:
  643.                 foreach$this->cache as $key => $value )
  644.                 {
  645.                     foreach$value as $key2 => $value2 )
  646.                     {
  647.                         foreach$value2 as $key3 => $value3 )
  648.                         {
  649.                             if$value3 === NULL )
  650.                             // Remembered as not existing
  651.                                 continue;
  652.                             }
  653.                             ifempty($value3->dbRemove) )
  654.                             {
  655.                                 $query_where_delete["{$this->col_key_names[0]} = '$key' AND {$this->col_key_names[1]} = '$key2' AND {$this->col_key_names[2]} = '$key3'";
  656.                                 unset$this->cache[$key][$key2][$key3);
  657.                             }
  658.                             elseifisset($value3->dbUptodate&& !$value3->dbUptodate )
  659.                             {
  660.                                 $value3 $value3->value;
  661.                                 ifis_array($value3|| is_object($value3) )
  662.                                 {
  663.                                     $value3 serialize($value3);
  664.                                 }
  665.                                 $query_insert["('$key', '$key2', '$key3', '".$DB->escape$value3 )."')";
  666.                                 $this->cache[$key][$key2][$key3]->dbUptodate true;
  667.                             }
  668.                         }
  669.                     }
  670.                 }
  671.                 break;
  672.  
  673.             default:
  674.                 return false;
  675.         }
  676.  
  677.  
  678.         $r false;
  679.  
  680.         ifempty($query_where_delete) )
  681.         {
  682.             $query 'DELETE FROM '.$this->db_table_name." WHERE\n(".implode")\nOR ("$query_where_delete ).')';
  683.             $r = (boolean)$DB->query$query );
  684.         }
  685.  
  686.  
  687.         ifempty($query_insert) )
  688.         {
  689.             $query 'REPLACE INTO '.$this->db_table_name.' ('.implode', '$this->col_key_names ).', '.$this->col_value_name
  690.                                 .') VALUES '.implode(', '$query_insert);
  691.             $r $DB->query$query || $r;
  692.         }
  693.  
  694.         return $r;
  695.     }
  696.  
  697.  
  698.     /**
  699.      * Reset cache (includes settings to be written to DB).
  700.      *
  701.      * This is useful, to rollback settings that have been made, e.g. when a Plugin
  702.      * decides that his settings should not get updated.
  703.      */
  704.     function reset()
  705.     {
  706.         $this->cache NULL;
  707.         $this->all_loaded false;
  708.     }
  709.  
  710.  
  711.     /**
  712.      * Get a param from Request and save it to Settings, or default to previously saved user setting.
  713.      *
  714.      * If the setting was not set before (and there's no default given that gets returned), $default gets used.
  715.      *
  716.      * @param string Request param name
  717.      * @param string setting name. Make sure this is unique!
  718.      * @param string Force value type to one of:
  719.      *  - integer
  720.      *  - float
  721.      *  - string (strips (HTML-)Tags, trims whitespace)
  722.      *  - array
  723.      *  - object
  724.      *  - null
  725.      *  - html (does nothing)
  726.      *  - '' (does nothing)
  727.      *  - '/^...$/' check regexp pattern match (string)
  728.      *  - boolean (will force type to boolean, but you can't use 'true' as a default since it has special meaning. There is no real reason to pass booleans on a URL though. Passing 0 and 1 as integers seems to be best practice).
  729.      *  Value type will be forced only if resulting value (probably from default then) is !== NULL
  730.      * @param mixed Default value or TRUE
  731.      * @param boolean Do we need to memorize this to regenerate the URL for this page?
  732.      * @param boolean Override if variable already set
  733.      * @return NULL|mixedNULL, if neither a param was given nor knows about it.
  734.      */
  735.     function param_Request$param_name$set_name$type ''$default ''$memorize false$override false // we do not force setting it..
  736.     {
  737.         $value param$param_name$typeNULL$memorize$overridefalse )// we pass NULL here, to see if it got set at all
  738.  
  739.         if$value !== false )
  740.         // we got a value
  741.             $this->set$set_name$value );
  742.             $this->dbupdate();
  743.         }
  744.         else
  745.         // get the value from user settings
  746.             $value $this->get($set_name);
  747.  
  748.             ifis_null($value) )
  749.             // it's not saved yet and there's not default defined ($_defaults)
  750.                 $value $default;
  751.             }
  752.         }
  753.  
  754.         set_param$param_name$value );
  755.         return get_param($param_name);
  756.     }
  757. }
  758.  
  759.  
  760. /*
  761.  * $Log: _abstractsettings.class.php,v $
  762.  * Revision 1.9  2010/02/08 17:53:55  efy-yury
  763.  * copyright 2009 -> 2010
  764.  *
  765.  * Revision 1.8  2010/01/22 08:39:02  sam2kb
  766.  * Fixied warning: call_user_func_array() expects parameter 2 to be array
  767.  *
  768.  * Revision 1.7  2009/11/30 00:22:05  fplanque
  769.  * clean up debug info
  770.  * show more timers in view of block caching
  771.  *
  772.  * Revision 1.6  2009/10/08 20:05:52  efy-maxim
  773.  * Modular/Pluggable Permissions
  774.  *
  775.  * Revision 1.5  2009/03/08 23:57:45  fplanque
  776.  * 2009
  777.  *
  778.  * Revision 1.4  2008/01/21 09:35:34  fplanque
  779.  * (c) 2008
  780.  *
  781.  * Revision 1.3  2007/11/28 16:57:50  fplanque
  782.  * bugfix when trying to access a serialized value rigth after setting it
  783.  *
  784.  * Revision 1.2  2007/11/28 16:38:20  fplanque
  785.  * minor
  786.  *
  787.  * Revision 1.1  2007/06/25 11:01:20  fplanque
  788.  * MODULES (refactored MVC)
  789.  *
  790.  * Revision 1.21  2007/04/26 00:10:59  fplanque
  791.  * (c) 2007
  792.  *
  793.  * Revision 1.20  2007/02/06 00:41:52  waltercruz
  794.  * Changing double quotes to single quotes
  795.  *
  796.  * Revision 1.19  2006/12/07 23:13:11  fplanque
  797.  * @var needs to have only one argument: the variable type
  798.  * Otherwise, I can't code!
  799.  *
  800.  * Revision 1.18  2006/11/24 18:27:25  blueyed
  801.  * Fixed link to b2evo CVS browsing interface in file docblocks
  802.  *
  803.  * Revision 1.17  2006/11/15 21:04:46  blueyed
  804.  * - Fixed removing setting after delete() and get() (from defaults) (When getting value from default do not reset $dbRemove property)
  805.  * - Opt: default settings are already unserialized
  806.  *
  807.  * Revision 1.16  2006/11/15 20:18:50  blueyed
  808.  * Fixed AbstractSettings::delete(): unset properties in cache
  809.  *
  810.  * Revision 1.15  2006/11/04 01:35:02  blueyed
  811.  * Fixed unserializing of array()
  812.  */
  813. ?>

Documentation generated on Sat, 06 Mar 2010 03:59:37 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).