[geeklog-cvs] Geeklog-1.x/system/classes config.class.php,1.3,1.4

Oliver ospiess at qs1489.pair.com
Wed Oct 10 21:40:08 EDT 2007


Update of /usr/home/geeklog2/cvsroot/geeklog/Geeklog-1.x/system/classes
In directory qs1489.pair.com:/tmp/cvs-serv30622

Modified Files:
	config.class.php 
Log Message:
code cosmetics

Index: config.class.php
===================================================================
RCS file: /usr/home/geeklog2/cvsroot/geeklog/Geeklog-1.x/system/classes/config.class.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** config.class.php	23 Sep 2007 16:51:33 -0000	1.3
--- config.class.php	11 Oct 2007 01:40:06 -0000	1.4
***************
*** 36,51 ****
      var $dbconfig_file;
      var $config_array;
! 	
      /**
!      * This function will return an instance of the config class. If an 
!      * instance with the given group/reference name does not exist, then it 
!      * will create a new one. This function insures	that there is only one 
       * instance for a given group name.
!      *	
!      *	@param string group_name   This is simply the group name that this 
       *                             config object will control - for the main gl
       *                             settings this is 'Core'
!      *	
!      *	@return config 			   The newly created or referenced config object
       */
      function &get_instance()
--- 36,51 ----
      var $dbconfig_file;
      var $config_array;
! 
      /**
!      * This function will return an instance of the config class. If an
!      * instance with the given group/reference name does not exist, then it
!      * will create a new one. This function insures    that there is only one
       * instance for a given group name.
!      *
!      *    @param string group_name   This is simply the group name that this
       *                             config object will control - for the main gl
       *                             settings this is 'Core'
!      *
!      *    @return config                The newly created or referenced config object
       */
      function &get_instance()
***************
*** 54,58 ****
          return $instance;
      }
! 	
      function create($ref = 'Core', $obj = null)
      {
--- 54,58 ----
          return $instance;
      }
! 
      function create($ref = 'Core', $obj = null)
      {
***************
*** 68,92 ****
          $this->ref = $ref;
      }
!     
      /**
!      * This function sets the secure configuration file (database related 
       * settings) for the configuration class to read. This should only need to
!      * be called for the 'Core' group. It also must be called before 
       * load_baseconfig()
       *
!      * @param string sf		The filename and path of the secure db settings
       */
!     
      function set_configfile($sf)
      {
!         $this->dbconfig_file = $sf; 
      }
!     
      /**
!      * This function reads the secure configuration file and loads 
!      * lib-database.php. This needs to be called in the 'Core' group before 
       * &init_config() can be used. It only needs to be called once
       */
!     
      function load_baseconfig()
      {
--- 68,92 ----
          $this->ref = $ref;
      }
! 
      /**
!      * This function sets the secure configuration file (database related
       * settings) for the configuration class to read. This should only need to
!      * be called for the 'Core' group. It also must be called before
       * load_baseconfig()
       *
!      * @param string sf        The filename and path of the secure db settings
       */
! 
      function set_configfile($sf)
      {
!         $this->dbconfig_file = $sf;
      }
! 
      /**
!      * This function reads the secure configuration file and loads
!      * lib-database.php. This needs to be called in the 'Core' group before
       * &init_config() can be used. It only needs to be called once
       */
! 
      function load_baseconfig()
      {
***************
*** 100,109 ****
  
      /**
!      * This function initializes the configuration array (i.e. $_CONF) and 
       * will return a reference to the newly created array. The class keeps
       * track of this reference, and the set function will mutate it.
!      * 
!      * @return array(string => mixed)	  This is a reference to the
!      * 			       		  config array
       */
      function &initConfig()
--- 100,109 ----
  
      /**
!      * This function initializes the configuration array (i.e. $_CONF) and
       * will return a reference to the newly created array. The class keeps
       * track of this reference, and the set function will mutate it.
!      *
!      * @return array(string => mixed)      This is a reference to the
!      *                              config array
       */
      function &initConfig()
***************
*** 123,132 ****
  
      /**
!      * This function sets a configuration variable to a value in the database 
!      * and in the current array. If the variable does not already exist, 
       * nothing will happen.
!      * 
!      * @param string name		Name of the config parameter to set
!      * @param mixed value		The value to set the config parameter to
       */
      function set($name, $value)
--- 123,132 ----
  
      /**
!      * This function sets a configuration variable to a value in the database
!      * and in the current array. If the variable does not already exist,
       * nothing will happen.
!      *
!      * @param string name        Name of the config parameter to set
!      * @param mixed value        The value to set the config parameter to
       */
      function set($name, $value)
***************
*** 172,182 ****
       *
       * @param string $param_name        name of the parameter to add
!      * @param mixed  $default_value     the default value of the parameter 
       *                                  (also will be the initial value)
!      * @param string $display_name      name that will be displayed on the 
       *                                  user interface
       * @param string $type              the type of the configuration variable
!      *    
!      *    If the configuration variable is an array, prefix this string with 
       *    '@' if the administrator should NOT be able to add or remove keys
       *    '*' if the administrator should be able to add named keys
--- 172,182 ----
       *
       * @param string $param_name        name of the parameter to add
!      * @param mixed  $default_value     the default value of the parameter
       *                                  (also will be the initial value)
!      * @param string $display_name      name that will be displayed on the
       *                                  user interface
       * @param string $type              the type of the configuration variable
!      *
!      *    If the configuration variable is an array, prefix this string with
       *    '@' if the administrator should NOT be able to add or remove keys
       *    '*' if the administrator should be able to add named keys
***************
*** 189,204 ****
       *    'hidden'  no display            string  value stored
       *
!      * @param string $subgroup          subgroup of the variable 
       *                                  (the second row of tabs on the user interface)
       * @param string $fieldset          the fieldset to display the variable under
       * @param array  $selection_array   possible selections for the 'select' type
!      *                                  this MUST be passed if you use the 'select' 
       *                                  type
       * @param int    $sort              sort rank on the user interface (ascending)
!      * 
       * @param boolean $set              whether or not this parameter is set
       */
!     function add($param_name, $default_value, $type, $subgroup, $fieldset, 
! 		 $selection_array=null, $sort=0, $set=true)
      {
          global $_TABLES, $_DB, $_DB_dbms;
--- 189,204 ----
       *    'hidden'  no display            string  value stored
       *
!      * @param string $subgroup          subgroup of the variable
       *                                  (the second row of tabs on the user interface)
       * @param string $fieldset          the fieldset to display the variable under
       * @param array  $selection_array   possible selections for the 'select' type
!      *                                  this MUST be passed if you use the 'select'
       *                                  type
       * @param int    $sort              sort rank on the user interface (ascending)
!      *
       * @param boolean $set              whether or not this parameter is set
       */
!     function add($param_name, $default_value, $type, $subgroup, $fieldset,
!          $selection_array=null, $sort=0, $set=true)
      {
          global $_TABLES, $_DB, $_DB_dbms;
***************
*** 206,220 ****
              'subgroup, group_name, selectionArray, sort_order,'.
              ' fieldset, default_value) ' .
!             'VALUES ("%2$s","%3$s","%4$s",%5$s,"%6$s",%7$s,'. 
              '%8$s,%9$s, "%10$s")';
!         $Qargs = array($_TABLES['conf_values'], 
                         $param_name,
!                        $set ? serialize($default_value) : 'unset', 
!                        $type, 
                         $subgroup,
!                        $this->ref, 
!                        ($selection_array === null ? 
                          -1 : $selection_array),
!                        $sort, 
                         $fieldset,
                         serialize($default_value));
--- 206,220 ----
              'subgroup, group_name, selectionArray, sort_order,'.
              ' fieldset, default_value) ' .
!             'VALUES ("%2$s","%3$s","%4$s",%5$s,"%6$s",%7$s,'.
              '%8$s,%9$s, "%10$s")';
!         $Qargs = array($_TABLES['conf_values'],
                         $param_name,
!                        $set ? serialize($default_value) : 'unset',
!                        $type,
                         $subgroup,
!                        $this->ref,
!                        ($selection_array === null ?
                          -1 : $selection_array),
!                        $sort,
                         $fieldset,
                         serialize($default_value));
***************
*** 245,260 ****
      }
  
! 	/**
       * Gets extended (GUI related) information from the database
! 	 * @param string subgroup			filters by subgroup
! 	 * @return array(string => string => array(string => mixed))
! 	 *    Array keys are fieldset => parameter named => information array
! 	 */
      function _get_extended($subgroup)
      {
          global $_TABLES, $LANG_coreconfignames, $LANG_coreconfigselects;
!         $q_string = "SELECT name, type, selectionArray, " 
!             . "fieldset, value FROM {$_TABLES['conf_values']}" . 
!             " WHERE group_name='{$this->ref}' and subgroup='{$subgroup}' " . 
              " ORDER BY sort_order ASC";
          $Qresult = DB_query($q_string);
--- 245,260 ----
      }
  
!     /**
       * Gets extended (GUI related) information from the database
!      * @param string subgroup            filters by subgroup
!      * @return array(string => string => array(string => mixed))
!      *    Array keys are fieldset => parameter named => information array
!      */
      function _get_extended($subgroup)
      {
          global $_TABLES, $LANG_coreconfignames, $LANG_coreconfigselects;
!         $q_string = "SELECT name, type, selectionArray, "
!             . "fieldset, value FROM {$_TABLES['conf_values']}" .
!             " WHERE group_name='{$this->ref}' and subgroup='{$subgroup}' " .
              " ORDER BY sort_order ASC";
          $Qresult = DB_query($q_string);
***************
*** 262,277 ****
          while ($row = DB_fetchArray($Qresult)) {
              $cur = $row;
!             $res[$cur[3]][$cur[0]] = 
!                 array('display_name' => 
                        (array_key_exists($cur[0], $LANG_coreconfignames) ?
                         $LANG_coreconfignames[$cur[0]]
                         : $cur[0]),
!                       'type' => 
                        (($cur[4] == 'unset') ?
                         'unset' : $cur[1]),
!                       'selectionArray' => 
                        (($cur[2] != -1) ?
                         $LANG_coreconfigselects[$cur[2]] : null),
!                       'value' => 
                        (($cur[4] == 'unset') ?
                         'unset' : unserialize($cur[4])));
--- 262,277 ----
          while ($row = DB_fetchArray($Qresult)) {
              $cur = $row;
!             $res[$cur[3]][$cur[0]] =
!                 array('display_name' =>
                        (array_key_exists($cur[0], $LANG_coreconfignames) ?
                         $LANG_coreconfignames[$cur[0]]
                         : $cur[0]),
!                       'type' =>
                        (($cur[4] == 'unset') ?
                         'unset' : $cur[1]),
!                       'selectionArray' =>
                        (($cur[2] != -1) ?
                         $LANG_coreconfigselects[$cur[2]] : null),
!                       'value' =>
                        (($cur[4] == 'unset') ?
                         'unset' : unserialize($cur[4])));
***************
*** 283,289 ****
      function _post_configuration()
      {
!         $this->config_array['path_layout'] = $this->config_array['path_themes'] 
              . $this->config_array['theme'] . '/';
!         $this->config_array['layout_url'] = $this->config_array['site_url'] 
              . '/layout/' . $this->config_array['theme'];
      }
--- 283,289 ----
      function _post_configuration()
      {
!         $this->config_array['path_layout'] = $this->config_array['path_themes']
              . $this->config_array['theme'] . '/';
!         $this->config_array['layout_url'] = $this->config_array['site_url']
              . '/layout/' . $this->config_array['theme'];
      }
***************
*** 298,302 ****
          global $_TABLES;
          $q_string = "SELECT subgroup FROM {$_TABLES['conf_values']} WHERE " .
!             "group_name='{$this->ref}' " . 
              "GROUP BY subgroup";
          $res = DB_query($q_string);
--- 298,302 ----
          global $_TABLES;
          $q_string = "SELECT subgroup FROM {$_TABLES['conf_values']} WHERE " .
!             "group_name='{$this->ref}' " .
              "GROUP BY subgroup";
          $res = DB_query($q_string);
***************
*** 307,322 ****
      }
  
! 	/**
       * This function is responsible for creating the configuration GUI
! 	 *
! 	 * @param string sg		This is the subgroup name to load the gui for. 
! 	 *						If nothing is passed, it will display the first 
! 	 * 						(alpha) subgroup
! 	 *
! 	 * @param array(string=>boolean) change_result
! 	 *						This is an array of what changes were made to the
! 	 *						configuration - if it is passed, it will display
! 	 *						the "Changes" message box.						
! 	 */
      function get_ui($sg=0, $change_result=null)
      {
--- 307,322 ----
      }
  
!     /**
       * This function is responsible for creating the configuration GUI
!      *
!      * @param string sg        This is the subgroup name to load the gui for.
!      *                        If nothing is passed, it will display the first
!      *                         (alpha) subgroup
!      *
!      * @param array(string=>boolean) change_result
!      *                        This is an array of what changes were made to the
!      *                        configuration - if it is passed, it will display
!      *                        the "Changes" message box.
!      */
      function get_ui($sg=0, $change_result=null)
      {
***************
*** 341,345 ****
              $t->set_var('select_id', ($sg === $sgroup ? 'id="current"' : ''));
              $t->set_var('subgroup_name', $sgroup);
!             $t->set_var("subgroup_display_name", 
                          $LANG_coreconfigsubgroups[$sgroup]);
              $t->parse("navbar", "subgroup-selector", true);
--- 341,345 ----
              $t->set_var('select_id', ($sg === $sgroup ? 'id="current"' : ''));
              $t->set_var('subgroup_name', $sgroup);
!             $t->set_var("subgroup_display_name",
                          $LANG_coreconfigsubgroups[$sgroup]);
              $t->parse("navbar", "subgroup-selector", true);
***************
*** 352,365 ****
              $fs_contents = '';
              foreach ($params as $name=>$e) {
!                 $fs_contents .= 
                      config::_UI_get_conf_element($name,
!                                                $e['display_name'], 
                                                 $e['type'],
!                                                $e['value'], 
                                                 $e['selectionArray']);
              }
              config::_UI_get_fs($fs_contents, $fset, $t);
          }
!           
          // Output the result.
          $display  = COM_siteHeader('menu');
--- 352,365 ----
              $fs_contents = '';
              foreach ($params as $name=>$e) {
!                 $fs_contents .=
                      config::_UI_get_conf_element($name,
!                                                $e['display_name'],
                                                 $e['type'],
!                                                $e['value'],
                                                 $e['selectionArray']);
              }
              config::_UI_get_fs($fs_contents, $fset, $t);
          }
! 
          // Output the result.
          $display  = COM_siteHeader('menu');
***************
*** 367,371 ****
          $display .= config::_UI_get_change_block($change_result);
          $display .= $t->finish($t->parse("OUTPUT", "main"));
!         $display .= COM_endBlock(); 
          $display .= COM_siteFooter(false);
          return $display;
--- 367,371 ----
          $display .= config::_UI_get_change_block($change_result);
          $display .= $t->finish($t->parse("OUTPUT", "main"));
!         $display .= COM_endBlock();
          $display .= COM_siteFooter(false);
          return $display;
***************
*** 408,412 ****
          return $display;
      }
!   
      function _UI_get_conf_element($name, $display_name, $type, $val,
                                            $selectionArray = null , $deletable=0)
--- 408,412 ----
          return $display;
      }
! 
      function _UI_get_conf_element($name, $display_name, $type, $val,
                                            $selectionArray = null , $deletable=0)
***************
*** 416,420 ****
  
          $blocks = array('delete-button', 'text-element', 'placeholder-element',
!                         'select-element', 'list-element', 'unset-param', 
                          'keyed-add-button', 'unkeyed-add-button');
          foreach ($blocks as $block)
--- 416,420 ----
  
          $blocks = array('delete-button', 'text-element', 'placeholder-element',
!                         'select-element', 'list-element', 'unset-param',
                          'keyed-add-button', 'unkeyed-add-button');
          foreach ($blocks as $block)
***************
*** 427,431 ****
              $t->set_var('delete', $t->parse('output', 'delete-button'));
          elseif ($this->ref == 'Core' ) {
!             $t->set_var('unset_link', 
                          "<a href='#' onClick='unset(\"{$name}\");'>(X)</a>");
              if (($a = strrchr($name, '[')) !== FALSE) {
--- 427,431 ----
              $t->set_var('delete', $t->parse('output', 'delete-button'));
          elseif ($this->ref == 'Core' ) {
!             $t->set_var('unset_link',
                          "<a href='#' onClick='unset(\"{$name}\");'>(X)</a>");
              if (($a = strrchr($name, '[')) !== FALSE) {
***************
*** 440,444 ****
                      $baseUrl = 'http://www.geeklog.net';
                  }
!                 $t->set_var('doc_link', 
                              '(<a href="' . $baseUrl . '/docs/config.html#desc_'
                              . $o . '" target="help">?</a>)');
--- 440,444 ----
                      $baseUrl = 'http://www.geeklog.net';
                  }
!                 $t->set_var('doc_link',
                              '(<a href="' . $baseUrl . '/docs/config.html#desc_'
                              . $o . '" target="help">?</a>)');
***************
*** 479,508 ****
              $button = $t->parse('output', (strpos($type, "*") === 0 ?
                                             'keyed-add-button' :
!                                            'unkeyed-add-button')); 
              $t->set_var('my_add_element_button', $button);
              $result = "";
              foreach ($val as $valkey => $valval) {
!                 $result .= config::_UI_get_conf_element($name . '[' . $valkey . ']', $valkey, 
                                                        substr($type, 1), $valval, $selectionArray, true);
              }
              $t->set_var('my_elements', $result);
!             return $t->parse('output', 'list-element'); 
          }
      }
  
! 	/**
       * This function takes $_POST input and evaluates it
! 	 *
! 	 * param array(string=>mixed) $change_array		this is the $_POST array
! 	 * return array(string=>boolean)				this is the change_array
! 	 */
      function updateConfig($change_array)
      {
!         if (!SEC_inGroup('Root'))
              return null;
          $success_array = array();
          foreach ($this->config_array as $param_name => $param_value) {
              if (array_key_exists($param_name, $change_array)) {
!                 $change_array[$param_name] = 
                      $this->_validate_input($change_array[$param_name]);
                  if ($change_array[$param_name] != $param_value) {
--- 479,509 ----
              $button = $t->parse('output', (strpos($type, "*") === 0 ?
                                             'keyed-add-button' :
!                                            'unkeyed-add-button'));
              $t->set_var('my_add_element_button', $button);
              $result = "";
              foreach ($val as $valkey => $valval) {
!                 $result .= config::_UI_get_conf_element($name . '[' . $valkey . ']', $valkey,
                                                        substr($type, 1), $valval, $selectionArray, true);
              }
              $t->set_var('my_elements', $result);
!             return $t->parse('output', 'list-element');
          }
      }
  
!     /**
       * This function takes $_POST input and evaluates it
!      *
!      * param array(string=>mixed)       $change_array this is the $_POST array
!      * return array(string=>boolean)    this is the change_array
!      */
      function updateConfig($change_array)
      {
!         if (!SEC_inGroup('Root')) {
              return null;
+         }
          $success_array = array();
          foreach ($this->config_array as $param_name => $param_value) {
              if (array_key_exists($param_name, $change_array)) {
!                 $change_array[$param_name] =
                      $this->_validate_input($change_array[$param_name]);
                  if ($change_array[$param_name] != $param_value) {
***************
*** 519,531 ****
          if (is_array($input_val)) {
              $r = array();
!             foreach ($input_val as $key => $val)
!                 if ($key !== 'placeholder')
                      $r[$key] = $this->_validate_input($val);
          } else {
              $r = COM_stripSlashes( $input_val );
!             if ($r == 'b:0' OR $r == 'b:1')
                  $r = ($r == 'b:1');
!             if (is_numeric($r))
                  $r = $r + 0;
          }
          return $r;
--- 520,536 ----
          if (is_array($input_val)) {
              $r = array();
!             foreach ($input_val as $key => $val) {
!                 if ($key !== 'placeholder') {
                      $r[$key] = $this->_validate_input($val);
+                 }
+             }
          } else {
              $r = COM_stripSlashes( $input_val );
!             if ($r == 'b:0' OR $r == 'b:1') {
                  $r = ($r == 'b:1');
!             }
!             if (is_numeric($r)) {
                  $r = $r + 0;
+             }
          }
          return $r;




More information about the geeklog-cvs mailing list