[ PHPXref.com ] [ Generated: Sun Jul 20 18:22:37 2008 ] [ Jlog 1.0.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/scripts/ -> settings.class.php (source)

   1  <?php
   2  /* settings Class for the Jlog setup.php and change settings in /admin/settings.php

   3     It needs the $l(anguage) array 

   4  */
   5  
   6  class Settings {
   7  
   8      function Settings($l) {
   9       # no return

  10      
  11       // get the language array $l and put it into the class

  12       $this->l = $l;
  13      }
  14  
  15      function put_data($what = false) {
  16      if($what === false) return $this->d;
  17      else return $this->d[$what];
  18      }
  19  
  20      function get_data() {
  21       # no return

  22       $search = array(   'JLOG_ADMIN',
  23                          'JLOG_DB_CONTENT',
  24                          'JLOG_DB_COMMENTS',
  25                          'JLOG_DB_CATASSIGN',
  26                          'JLOG_DB_CATEGORIES',
  27                          'JLOG_DB_ATTRIBUTES',
  28                          'JLOG_UPDATE',
  29                          'JLOG_VERSION',
  30                          'JLOG_LOGIN'
  31                       );
  32      
  33       // get all needed constants and put it into the class

  34       $constants = get_defined_constants();
  35       foreach($constants as $key => $value) {
  36        if(!in_array($key, $search) AND strpos($key, "JLOG_") !== false) {
  37         $key = strtolower($key);
  38         $this->d[$key] = stripslashes($value);
  39        }
  40       }
  41      }
  42      
  43      function get_userdata($d) {
  44      # no return

  45      
  46       // get the data from users $d array and put it into the class

  47       $this->d = $d;
  48     
  49        if(JLOG_ADMIN === true) {
  50          $this->d['jlog_db'] = JLOG_DB;
  51          $this->d['jlog_db_url'] = JLOG_DB_URL;
  52          $this->d['jlog_db_user'] = JLOG_DB_USER;
  53          $this->d['jlog_db_pwd'] = JLOG_DB_PWD;
  54          $this->d['jlog_db_prefix'] = JLOG_DB_PREFIX;
  55          $this->d['jlog_start_year'] = JLOG_START_YEAR;
  56          $this->d['jlog_path'] = JLOG_PATH;
  57          $this->d['jlog_basepath'] = JLOG_BASEPATH;
  58          if($this->d['jlog_admin_password'] == '') $this->jlog_admin_password = JLOG_ADMIN_PASSWORD;
  59          else $this->d['jlog_admin_password'] = md5( $this->d['jlog_admin_password'] );
  60        }
  61        else $this->d['jlog_admin_password'] = md5( $this->d['jlog_admin_password'] );
  62      }
  63      
  64      function get_sugestiondata() {
  65       # no return

  66      
  67       // suggest some data for setup

  68       $this->d['jlog_path'] = dirname("http://".$_SERVER["HTTP_HOST"].$_SERVER["PHP_SELF"]);
  69       $this->d['jlog_basepath'] = dirname(dirname( __FILE__ )).DIRECTORY_SEPARATOR;
  70       $date = getdate();
  71       $this->d['jlog_start_year'] = $date['year'];
  72       $this->d['jlog_max_blog_orginal'] = 1;
  73       $this->d['jlog_max_blog_big'] = 4;
  74       $this->d['jlog_max_blog_small'] = 15;
  75       $this->d['jlog_sub_current'] = 6;
  76       $this->d['jlog_date'] = $this->l['date_format'];
  77       $this->d['jlog_date_comment'] = $this->l['date_format_comment'];
  78       $this->d['jlog_date_subcurrent'] = $this->l['date_format_subcurrent'];
  79       $this->d['jlog_info_by_comment'] = '1';
  80       $this->d['jlog_db_url'] = "localhost";
  81       $this->d['jlog_db_prefix'] = "jlog_";
  82       $this->d['jlog_blogservices'] = "http://rpc.pingomatic.com/";
  83      }
  84  
  85      function form_output() {
  86      # returns the filled form

  87  
  88       $data = array_htmlspecialchars($this->d);
  89  
  90  
  91       if($data['jlog_clean_url'] === 'true') $d['clean_url_yes'] = " checked='checked'";
  92       elseif($data['jlog_clean_url'] === 'false') $d['clean_url_no'] = " checked='checked'";
  93       elseif($data['jlog_clean_url'] === '1') $d['clean_url_yes'] = " checked='checked'";
  94       else $d['clean_url_no'] = " checked='checked'";
  95  
  96       if($data['jlog_info_by_comment']) $d['info_by_comment'] = " checked='checked'";
  97       else $d['info_by_comment'] = "";
  98  
  99       if($data['jlog_bs_weblogs_com'] === 'true') $d['bs_weblogs_com'] = " checked='checked' ";
 100       elseif($data['jlog_bs_weblogs_com'] === '1') $d['bs_weblogs_com'] = " checked='checked' ";
 101  
 102       if(JLOG_ADMIN === true) $admincenter_password = " ".$this->l['admin']['m_admin_password_admin'];
 103       else $admincenter_password = '';
 104  
 105      // do the form

 106       $form = "
 107       <form action='".$_SERVER['PHP_SELF']."' method='post'>
 108        <fieldset><legend>".$this->l['admin']['m_metadata']."</legend>
 109         <p><label for='website'>".$this->l['admin']['m_website']."</label><br />
 110            <input class='userdata' id='website' name='jlog_website' type='text' size='20' maxlength='255' value='".$data['jlog_website']."' /></p>
 111         <p><label for='publisher'>".$this->l['admin']['m_publisher']."</label><br />
 112            <input class='userdata' id='publisher' name='jlog_publisher' type='text' size='20' maxlength='255' value='".$data['jlog_publisher']."' /></p>
 113         <p><label for='admin_password'>".$this->l['admin']['m_admin_password'].$admincenter_password."</label><br />
 114            <input class='userdata' id='admin_password' name='jlog_admin_password' type='password' size='20' maxlength='255' /></p>
 115         <p><label for='email'>".$this->l['admin']['m_email']."</label><br />
 116            <input class='userdata' id='email' name='jlog_email' type='text' size='20' maxlength='255' value='".$data['jlog_email']."' /></p>
 117         <p><label for='description'>".$this->l['admin']['m_description']."</label><br />
 118            <textarea class='small' id='description' name='jlog_description' rows='2' cols='60'>".$data['jlog_description']."</textarea></p>
 119        </fieldset>
 120  
 121        <fieldset><legend>".$this->l['admin']['m_behavior']."</legend>
 122         <p><label>".$this->l['admin']['m_clean_url']."</label><br />
 123            <input id='clean_url_yes' name='jlog_clean_url' type='radio' value='true'".$d['clean_url_yes']." /><label class='nobreak' for='clean_url_yes'>".$this->l['admin']['yes']."</label>
 124            <input id='clean_url_no' name='jlog_clean_url' type='radio' value='false'".$d['clean_url_no']." /><label class='nobreak' for='clean_url_no'>".$this->l['admin']['no']."</label></p>
 125         <p><label for='max_blog_orginal'>".$this->l['admin']['m_max_blog_orginal']."</label><br />
 126            <input class='short' id='max_blog_orginal' name='jlog_max_blog_orginal' type='text' maxlength='3' size='3' value='".$data['jlog_max_blog_orginal']."' /></p>
 127         <p><label for='max_blog_big'>".$this->l['admin']['m_max_blog_big']."</label><br />
 128            <input class='short' id='max_blog_big' name='jlog_max_blog_big' type='text' size='3' maxlength='3' value='".$data['jlog_max_blog_big']."' /></p>
 129         <p><label for='max_blog_small'>".$this->l['admin']['m_max_blog_small']."</label><br />
 130            <input class='short' id='max_blog_small' name='jlog_max_blog_small' type='text' size='3' maxlength='3' value='".$data['jlog_max_blog_small']."' /></p>
 131         <p><label for='sub_current'>".$this->l['admin']['m_sub_current']."</label><br />
 132            <input class='short' id='sub_current' name='jlog_sub_current' type='text' size='3' maxlength='3' value='".$data['jlog_sub_current']."' /></p>
 133         <p><input id='info_by_comment' name='jlog_info_by_comment' type='checkbox' value='true'".$d['info_by_comment']."/> <label for='info_by_comment' class='nobreak'>".$this->l['admin']['m_info_by_comment']."</label></p>
 134         <p><label for='date'>".$this->l['admin']['m_date']."</label></p>
 135         <p><input class='userdata' id='date' name='jlog_date' type='text' value='".$data['jlog_date']."' size='20' /> <label for='date' class='nobreak'>".$this->l['admin']['m_date_posting']."</label></p>
 136         <p><input class='userdata' id='date_comment' name='jlog_date_comment' type='text' value='".$data['jlog_date_comment']."' size='20' /> <label for='date_comment' class='nobreak'>".$this->l['admin']['m_date_comment']."</label></p>
 137         <p><input class='userdata' id='date_subcurrent' name='jlog_date_subcurrent' type='text' value='".$data['jlog_date_subcurrent']."' size='20' /> <label for='date_subcurrent' class='nobreak'>".$this->l['admin']['m_date_subcurrent']."</label></p>
 138         <p><label for='blogservices'>".$this->l['admin']['m_bs']."</label></p>
 139         <p><textarea class='small' id='blogservices' name='jlog_blogservices' rows='2' cols='60'>".$data['jlog_blogservices']."</textarea></p>
 140        </fieldset>
 141       ";
 142  
 143       if(JLOG_SETUP === true) {
 144       $form .=
 145       "
 146        <fieldset><legend>".$this->l['admin']['m_database']."</legend>
 147         <p><label for='db'>".$this->l['admin']['m_db']."</label><br />
 148            <input class='userdata' id='db' name='jlog_db' type='text' size='20' maxlength='255' value='".$data['jlog_db']."' /></p>
 149         <p><label for='db_url'>".$this->l['admin']['m_db_url']."</label><br />
 150            <input class='userdata' id='db_url' name='jlog_db_url' type='text' size='20' maxlength='255' value='".$data['jlog_db_url']."' /></p>
 151         <p><label for='db_user'>".$this->l['admin']['m_db_user']."</label><br />
 152            <input class='userdata' id='db_user' name='jlog_db_user' type='text' size='20' maxlength='255' value='".$data['jlog_db_user']."' /></p>
 153         <p><label for='db_pwd'>".$this->l['admin']['m_db_pwd']."</label><br />
 154            <input class='userdata' id='db_pwd' name='jlog_db_pwd' type='password' size='20' maxlength='255' value='".$data['jlog_db_pwd']."' /></p>
 155         <p><label for='db_prefix'>".$this->l['admin']['m_db_prefix']."</label><br />
 156            <input class='userdata' id='db_prefix' name='jlog_db_prefix' type='text' size='20' maxlength='255' value='".$data['jlog_db_prefix']."' />
 157            <input name='jlog_start_year' type='hidden' value='".$data['jlog_start_year']."' /></p>
 158            <input name='jlog_path' type='hidden' value='".$data['jlog_path']."' />
 159            <input name='jlog_basepath' type='hidden' value='".$data['jlog_basepath']."' />
 160        </fieldset>
 161       ";
 162       }
 163      
 164       $form .= "
 165        <p><input type='submit' class='button' value='".$this->l['admin']['submit']."' /></p>
 166       </form>
 167       ";
 168  
 169       return $form;
 170      }
 171      
 172      function validate() {
 173       # if everything validate then return true

 174       # otherwise return the $errors array

 175  
 176       $errors = array();
 177  
 178         // paths

 179         if(empty($this->d['jlog_path']) OR (check_url($this->d['jlog_path'], array ('http')) === false)) $errors[] = $this->l['admin']['e_path'];
 180         if(empty($this->d['jlog_basepath']) OR !is_dir($this->d['jlog_basepath'])) $errors[] = $this->l['admin']['e_basepath'];
 181         if($this->d['jlog_clean_url'] != 'true') $this->d['jlog_clean_url'] = 'false';
 182         // metadata

 183         if(empty($this->d['jlog_website'])) $errors[] = $this->l['admin']['e_website'];
 184         if(empty($this->d['jlog_publisher'])) $errors[] = $this->l['admin']['e_publisher'];
 185         if(!JLOG_ADMIN AND empty($this->d['jlog_admin_password'])) $errors[] = $this->l['admin']['e_admin_password'];
 186         if(empty($this->d['jlog_email']) OR !strpos($this->d['jlog_email'], '@')) $errors[] = $this->l['admin']['e_email'];
 187         if(empty($this->d['jlog_description'])) $errors[] = $this->l['admin']['e_description'];
 188         // behavour

 189         if(!is_numeric($this->d['jlog_max_blog_orginal']) OR intval($this->d['jlog_max_blog_orginal']) < 0) $errors[] = $this->l['admin']['e_max_blog_orginal'];
 190         if(!is_numeric($this->d['jlog_max_blog_big']) OR intval($this->d['jlog_max_blog_big']) < 0) $errors[] = $this->l['admin']['e_max_blog_big'];
 191         if(!is_numeric($this->d['jlog_max_blog_small']) OR intval($this->d['jlog_max_blog_small']) < 0) $errors[] = $this->l['admin']['e_max_blog_small'];
 192         if(!is_numeric($this->d['jlog_sub_current']) OR intval($this->d['jlog_sub_current']) < 0) $errors[] = $this->l['admin']['e_sub_current'];
 193         if(!is_numeric($this->d['jlog_start_year'])) $errors[] = $this->l['admin']['e_start_year'];
 194         if($this->d['jlog_info_by_comment'] != 'true') $this->d['jlog_info_by_comment'] = 'false';
 195         // database

 196         if(empty($this->d['jlog_db'])) $errors[] = $this->l['admin']['e_db'];
 197         if(empty($this->d['jlog_db_url'])) $errors[] = $this->l['admin']['e_db_url'];
 198  
 199        return $errors;
 200      }
 201      
 202      function do_settings() {
 203      # if it's all done return true 

 204      # otherwise return the $errors array

 205  
 206       $errors = array();
 207  
 208       // if there is no new password set the old

 209       if(JLOG_ADMIN AND empty($this->d['jlog_admin_password'])) $this->d['jlog_admin_password'] = $this->jlog_admin_password;
 210      
 211       // erase last slashes

 212      if(strrpos($this->d['jlog_path'], "/") == strlen($this->d['jlog_path'])-1) $this->d['jlog_path'] = substr($this->d['jlog_path'], 0, strrpos($this->d['jlog_path'], "/"));
 213      if(strrpos($this->d['jlog_basepath'], DIRECTORY_SEPARATOR) != strlen($this->d['jlog_basepath'])-1) $this->d['jlog_basepath'] = $this->d['jlog_basepath'].DIRECTORY_SEPARATOR;
 214  
 215       // no quotes for bolean and numbers

 216       $no_quotes = array ( "jlog_clean_url",
 217                            "jlog_max_blog_orginal",
 218                            "jlog_max_blog_big",
 219                            "jlog_max_blog_small",
 220                            "jlog_sub_current",
 221                            "jlog_start_year",
 222                            "jlog_info_by_comment" );
 223  
 224       // serialize data to file format

 225       $file_content = "<?php\n";
 226      
 227       foreach($this->d as $key => $value) {
 228       unset($q, $s, $s2);
 229              if(!in_array($key, $no_quotes)) $q = "'";
 230          $key = strtoupper($key);
 231  
 232          // bolean

 233          if($key == 'JLOG_CLEAN_URL' OR $key == 'JLOG_INFO_BY_COMMENT') {
 234              if($value == 'true') $value = "true";
 235              else $value = "false";
 236          }
 237          $file_content .= " define('".$key."', ".$q.addslashes($value).$q.");\n";
 238      }
 239   
 240      $file_content .= " require_once(JLOG_BASEPATH.\"scripts\".DIRECTORY_SEPARATOR.\"prepend.inc.php\");\n?>";
 241  
 242      // write to settings.inc.php

 243       if(!$handle = fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."settings.inc.php", "w")) $errors[] = $this->l['admin']['can_not_open']." /personal/settings.inc.php";
 244       if(!fwrite($handle, $file_content)) $errors[] = $this->l['admin']['can_not_write']." /personal/settings.inc.php";
 245       fclose($handle);
 246     
 247       return $errors;
 248      }
 249  }
 250  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]