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

Aaron Blankstein ablankstein at qs1489.pair.com
Sat Dec 29 19:11:42 EST 2007


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

Modified Files:
	config.class.php 
Log Message:
Updated config class to run more smoothly with PHP4.
Changed config class's plugin support.
Added barebones handling of static page's config options in the config class.



Index: config.class.php
===================================================================
RCS file: /cvsroot/geeklog/Geeklog-1.x/system/classes/config.class.php,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** config.class.php	29 Dec 2007 20:49:39 -0000	1.9
--- config.class.php	30 Dec 2007 00:11:40 -0000	1.10
***************
*** 33,37 ****
  
  class config {
-     var $ref;
      var $dbconfig_file;
      var $config_array;
--- 33,36 ----
***************
*** 52,70 ****
      {
          static $instance;
          return $instance;
      }
  
!     function create($ref = 'Core', $obj = null)
!     {
!         $instance =& config::get_instance();
!         if ($instance[$ref] === null) {
!             $instance[$ref] = ($obj === null ? new config($ref) : $obj);
!         }
!         return $instance[$ref];
!     }
! 
!     function config($ref)
      {
!         $this->ref = $ref;
      }
  
--- 51,62 ----
      {
          static $instance;
+         if(!$instance)
+             $instance = new config();
          return $instance;
      }
  
!     function config()
      {
!         $this->config_array = array();
      }
  
***************
*** 91,100 ****
      function load_baseconfig()
      {
!         if ($this->ref == 'Core') {
!             global $_DB, $_TABLES, $_CONF;
!             include($this->dbconfig_file);
!             $this->config_array =& $_CONF;
!             include_once($_CONF['path_system'] . 'lib-database.php' );
!         }
      }
  
--- 83,90 ----
      function load_baseconfig()
      {
!         global $_DB, $_TABLES, $_CONF;
!         include($this->dbconfig_file);
!         $this->config_array['Core'] =& $_CONF;
!         include_once($_CONF['path_system'] . 'lib-database.php' );
      }
  
***************
*** 110,125 ****
      {
          global $_TABLES;
!         $sql_query = "SELECT name, value FROM {$_TABLES['conf_values']} WHERE " .
!             "group_name = '{$this->ref}'";
          $result = DB_query($sql_query);
          while ($row = DB_fetchArray($result)) {
              if ($row[1] !== 'unset')
!                 $this->config_array[$row[0]] = unserialize($row[1]);
          }
!         if ($this->ref == 'Core')
!             $this->_post_configuration();
          return $this->config_array;
      }
  
      /**
       * This function sets a configuration variable to a value in the database
--- 100,126 ----
      {
          global $_TABLES;
!         $sql_query = "SELECT name, value, group_name FROM {$_TABLES['conf_values']}";
          $result = DB_query($sql_query);
          while ($row = DB_fetchArray($result)) {
              if ($row[1] !== 'unset')
!                 $this->config_array[$row[2]][$row[0]] = unserialize($row[1]);
          }
!         $this->_post_configuration();
!         
          return $this->config_array;
      }
  
+     function &get_config($group)
+     {
+         if(array_key_exists($group, $this->config_array))
+             return $this->config_array[$group];
+         return false;
+     }
+ 
+     function group_exists($group)
+     {
+         return array_key_exists($group, $this->config_array);
+     }
+ 
      /**
       * This function sets a configuration variable to a value in the database
***************
*** 130,141 ****
       * @param mixed value        The value to set the config parameter to
       */
!     function set($name, $value)
      {
          global $_TABLES, $_DB, $_DB_dbms;
          $escaped_val = addslashes(serialize($value));
          $escaped_name = addslashes($name);
          $sql_query = "UPDATE {$_TABLES['conf_values']} " .
              "SET value = '{$escaped_val}' WHERE " .
!             "name = '{$escaped_name}' AND group_name = '{$this->ref}'";
          if ($_DB_dbms == 'mssql') {
              $sql_query = str_replace("\\'","''",$sql_query);
--- 131,143 ----
       * @param mixed value        The value to set the config parameter to
       */
!     function set($name, $value, $group='Core')
      {
          global $_TABLES, $_DB, $_DB_dbms;
          $escaped_val = addslashes(serialize($value));
          $escaped_name = addslashes($name);
+         $escaped_grp = addslashes($group);
          $sql_query = "UPDATE {$_TABLES['conf_values']} " .
              "SET value = '{$escaped_val}' WHERE " .
!             "name = '{$escaped_name}' AND group_name = '{$escaped_grp}'";
          if ($_DB_dbms == 'mssql') {
              $sql_query = str_replace("\\'","''",$sql_query);
***************
*** 145,168 ****
              DB_query($sql_query);
          }
!         $this->config_array[$name] = $value;
!         if ($this->ref == 'Core')
!             $this->_post_configuration();
      }
  
!     function restore_param($name)
      {
          global $_TABLES;
          $escaped_name = addslashes($name);
          $sql = "UPDATE {$_TABLES['conf_values']} SET value = default_value " .
!             "WHERE name = '{$escaped_name}' AND group_name = '{$this->ref}'";
          DB_query($sql);
      }
  
!     function unset_param($name)
      {
          global $_TABLES;
          $escaped_name = addslashes($name);
          $sql = "UPDATE {$_TABLES['conf_values']} SET value = 'unset' " .
!             "WHERE name = '{$escaped_name}' AND group_name = '{$this->ref}'";
          DB_query($sql);
      }
--- 147,171 ----
              DB_query($sql_query);
          }
!         $this->config_array[$group][$name] = $value;
!         $this->_post_configuration();
      }
  
!     function restore_param($name, $group)
      {
          global $_TABLES;
          $escaped_name = addslashes($name);
+         $escaped_grp = addslashes($group);
          $sql = "UPDATE {$_TABLES['conf_values']} SET value = default_value " .
!             "WHERE name = '{$escaped_name}' AND group_name = '{$escaped_grp}'";
          DB_query($sql);
      }
  
!     function unset_param($name, $group)
      {
          global $_TABLES;
          $escaped_name = addslashes($name);
+         $escaped_grp = addslashes($group);
          $sql = "UPDATE {$_TABLES['conf_values']} SET value = 'unset' " .
!             "WHERE name = '{$escaped_name}' AND group_name = '{$escaped_grp}'";
          DB_query($sql);
      }
***************
*** 199,204 ****
       * @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;
--- 202,207 ----
       * @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, $group='Core')
      {
          global $_TABLES, $_DB, $_DB_dbms;
***************
*** 213,217 ****
                         $type,
                         $subgroup,
!                        $this->ref,
                         ($selection_array === null ?
                          -1 : $selection_array),
--- 216,220 ----
                         $type,
                         $subgroup,
!                        $group,
                         ($selection_array === null ?
                          -1 : $selection_array),
***************
*** 230,234 ****
          }
  
!         $this->config_array[$param_name] = $default_value;
      }
  
--- 233,237 ----
          }
  
!         $this->config_array[$group][$param_name] = $default_value;
      }
  
***************
*** 237,246 ****
       * @param string  $param_name   This is the name of the parameter to delete
       */
!     function del($param_name)
      {
          DB_delete($GLOBALS['_TABLES']['conf_values'],
                    array("name","group_name"),
!                   array(addslashes($param_name), addslashes($this->ref)));
!         unset($this->config_array[$param_name]);
      }
  
--- 240,249 ----
       * @param string  $param_name   This is the name of the parameter to delete
       */
!     function del($param_name, $group)
      {
          DB_delete($GLOBALS['_TABLES']['conf_values'],
                    array("name","group_name"),
!                   array(addslashes($param_name), addslashes($group)));
!         unset($this->config_array[$group][$param_name]);
      }
  
***************
*** 251,269 ****
       *    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);
          $res = array();
          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' =>
--- 254,276 ----
       *    Array keys are fieldset => parameter named => information array
       */
!     function _get_extended($subgroup, $group)
      {
!         global $_TABLES, $LANG_confignames, $LANG_configselects;
          $q_string = "SELECT name, type, selectionArray, "
              . "fieldset, value FROM {$_TABLES['conf_values']}" .
!             " WHERE group_name='{$group}' and subgroup='{$subgroup}' " .
              " ORDER BY sort_order ASC";
          $Qresult = DB_query($q_string);
          $res = array();
+         if(!array_key_exists($group, $LANG_configselects))
+             $LANG_configselects[$group] = array();
+         if(!array_key_exists($group, $LANG_confignames))
+             $LANG_confignames[$group] = array();
          while ($row = DB_fetchArray($Qresult)) {
              $cur = $row;
              $res[$cur[3]][$cur[0]] =
                  array('display_name' =>
!                       (array_key_exists($cur[0], $LANG_confignames[$group]) ?
!                        $LANG_confignames[$group][$cur[0]]
                         : $cur[0]),
                        'type' =>
***************
*** 272,276 ****
                        'selectionArray' =>
                        (($cur[2] != -1) ?
!                        $LANG_coreconfigselects[$cur[2]] : null),
                        'value' =>
                        (($cur[4] == 'unset') ?
--- 279,283 ----
                        'selectionArray' =>
                        (($cur[2] != -1) ?
!                        $LANG_configselects[$group][$cur[2]] : null),
                        'value' =>
                        (($cur[4] == 'unset') ?
***************
*** 283,302 ****
      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'];
      }
  
      function _get_groups()
      {
!         return array_keys(config::get_instance());
      }
  
!     function get_sgroups()
      {
          global $_TABLES;
          $q_string = "SELECT subgroup FROM {$_TABLES['conf_values']} WHERE " .
!             "group_name='{$this->ref}' " .
              "GROUP BY subgroup";
          $res = DB_query($q_string);
--- 290,309 ----
      function _post_configuration()
      {
!         $this->config_array['Core']['path_layout'] = $this->config_array['Core']['path_themes']
!             . $this->config_array['Core']['theme'] . '/';
!         $this->config_array['Core']['layout_url'] = $this->config_array['Core']['site_url']
!             . '/layout/' . $this->config_array['Core']['theme'];
      }
  
      function _get_groups()
      {
!         return array_keys($this->config_array);
      }
  
!     function get_sgroups($group)
      {
          global $_TABLES;
          $q_string = "SELECT subgroup FROM {$_TABLES['conf_values']} WHERE " .
!             "group_name='{$group}' " .
              "GROUP BY subgroup";
          $res = DB_query($q_string);
***************
*** 319,325 ****
       *                        the "Changes" message box.
       */
!     function get_ui($sg='0', $change_result=null)
      {
!         global $_CONF,$LANG_coreconfigsubgroups;
  
          if (!SEC_inGroup('Root'))
--- 326,334 ----
       *                        the "Changes" message box.
       */
!     function get_ui($grp, $sg='0', $change_result=null)
      {
!         global $_CONF,$LANG_configsubgroups;
!         if(!array_key_exists($grp, $LANG_configsubgroups))
!             $LANG_configsubgroups[$grp] = array();
  
          if (!SEC_inGroup('Root'))
***************
*** 332,345 ****
          $t->set_var( 'xhtml', XHTML );
          $t->set_var('site_url',$_CONF['site_url']);
-         $t->set_var('open_group', $this->ref);
  
!         $groups = config::_get_groups();
  
          if (count($groups) > 0) {
              foreach ($groups as $group) {
!                 $t->set_var("select_id", ($group === $this->ref ? 'id="current"' : ''));
                  $t->set_var("group_select_value", $group);
                  $t->set_var("group_display", ucwords($group));
!                 $subgroups = $this->get_sgroups();
                  $t->set_block('menugroup','subgroup-selector','subgroups');
                  foreach ($subgroups as $sgroup) {
--- 341,355 ----
          $t->set_var( 'xhtml', XHTML );
          $t->set_var('site_url',$_CONF['site_url']);
  
!         $t->set_var('open_group', $grp);
! 
!         $groups = $this->_get_groups();
  
          if (count($groups) > 0) {
              foreach ($groups as $group) {
!                 $t->set_var("select_id", ($group === $grp ? 'id="current"' : ''));
                  $t->set_var("group_select_value", $group);
                  $t->set_var("group_display", ucwords($group));
!                 $subgroups = $this->get_sgroups($group);
                  $t->set_block('menugroup','subgroup-selector','subgroups');
                  foreach ($subgroups as $sgroup) {
***************
*** 347,351 ****
                      $t->set_var('subgroup_name', $sgroup);
                      $t->set_var("subgroup_display_name",
!                                 $LANG_coreconfigsubgroups[$sgroup]);
                      $t->parse('subgroups', "subgroup-selector", true);
                  }
--- 357,361 ----
                      $t->set_var('subgroup_name', $sgroup);
                      $t->set_var("subgroup_display_name",
!                                 $LANG_configsubgroups[$group][$sgroup]);
                      $t->parse('subgroups', "subgroup-selector", true);
                  }
***************
*** 356,369 ****
              $t->set_var('hide_groupselection','none');
          }
- 
          $t->set_var('open_sg', $sg);
          $t->set_block('main','fieldset','sg_contents');
          $t->set_block('fieldset', 'notes', 'fs_notes');
!         $ext_info = $this->_get_extended($sg);
          foreach ($ext_info as $fset=>$params) {
              $fs_contents = '';
              foreach ($params as $name=>$e) {
                  $fs_contents .=
!                     config::_UI_get_conf_element($name,
                                                 $e['display_name'],
                                                 $e['type'],
--- 366,378 ----
              $t->set_var('hide_groupselection','none');
          }
          $t->set_var('open_sg', $sg);
          $t->set_block('main','fieldset','sg_contents');
          $t->set_block('fieldset', 'notes', 'fs_notes');
!         $ext_info = $this->_get_extended($sg, $grp);
          foreach ($ext_info as $fset=>$params) {
              $fs_contents = '';
              foreach ($params as $name=>$e) {
                  $fs_contents .=
!                     $this->_UI_get_conf_element($name,
                                                 $e['display_name'],
                                                 $e['type'],
***************
*** 371,375 ****
                                                 $e['selectionArray']);
              }
!             config::_UI_get_fs($fs_contents, $fset, $t);
          }
  
--- 380,384 ----
                                                 $e['selectionArray']);
              }
!             $this->_UI_get_fs($grp, $fs_contents, $fset, $t);
          }
  
***************
*** 378,382 ****
          $display  = COM_siteHeader('none','Configuration Manager',$cssfile);
          if ($change_result != null AND $change_result !== array() ) {
!             $t->set_var('change_block',config::_UI_get_change_block($change_result));
          } else {
              $t->set_var('show_changeblock','none');
--- 387,391 ----
          $display  = COM_siteHeader('none','Configuration Manager',$cssfile);
          if ($change_result != null AND $change_result !== array() ) {
!             $t->set_var('change_block',$this->_UI_get_change_block($change_result));
          } else {
              $t->set_var('show_changeblock','none');
***************
*** 398,406 ****
      }
  
!     function _UI_get_fs($contents, $fs_id, &$t)
      {
          global $LANG_fs;
          $t->set_var('fs_contents', $contents);
!         $t->set_var('fs_display', $LANG_fs[$fs_id]);
          $t->set_var('fs_notes', '');
          $t->parse('sg_contents', 'fieldset', true);
--- 407,417 ----
      }
  
!     function _UI_get_fs($group, $contents, $fs_id, &$t)
      {
          global $LANG_fs;
+         if(!array_key_exists($group, $LANG_fs))
+             $LANG_fs[$group] = array();
          $t->set_var('fs_contents', $contents);
!         $t->set_var('fs_display', $LANG_fs[$group][$fs_id]);
          $t->set_var('fs_notes', '');
          $t->parse('sg_contents', 'fieldset', true);
***************
*** 510,528 ****
       * return array(string=>boolean)    this is the change_array
       */
!     function updateConfig($change_array)
      {
          if (!SEC_inGroup('Root')) {
              return null;
          }
-         if ($this->config_array == null) {
-             $this->initConfig();
-         }
          $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) {
!                     $this->set($param_name, $change_array[$param_name]);
                      $success_array[$param_name] = true;
                  }
--- 521,536 ----
       * return array(string=>boolean)    this is the change_array
       */
!     function updateConfig($change_array, $group)
      {
          if (!SEC_inGroup('Root')) {
              return null;
          }
          $success_array = array();
!         foreach ($this->config_array[$group] 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) {
!                     $this->set($param_name, $change_array[$param_name], $group);
                      $success_array[$param_name] = true;
                  }




More information about the geeklog-cvs mailing list