root/trunk/scripts/settings.class.php

Revision 1768, 23.9 KB (checked in by driehle, 3 months ago)

converted tabs to 4 spaces

  • Property svn:keywords set to HeadURL Rev Author Date
Line 
1<?php
2
3/**
4 * Jlog
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 *
20 * $HeadURL$
21 * $Rev$
22 * $Author$
23 * $Date$
24 */
25
26/**
27 * Settings class
28 *
29 * This class represents the current settings for Jlog and
30 * offers the possibility to modify these settings based on
31 * user's input. The configuration can be saved to disk,
32 * if wanted.
33 *
34 * @category  Jlog
35 * @package   Jlog_Settings
36 * @license   GNU General Public License
37 *
38 */
39class Settings {
40
41    /**
42    * Assoziative array holding configuration options
43    *
44    * @access private
45    * @var array
46    */
47    var $d = array();
48
49    /**
50    * Assoziative array holding translations according
51    * to the current language.
52    *
53    * @access private
54    * @var array
55    */
56    var $l = array();
57
58    /**
59    * Settings() - class constructor
60    *
61    * @access public
62    * @param array $l
63    * @return void
64    */
65    function Settings($l) {
66        // get the language array $l and put it into the class
67        $this->l = $l;
68    }
69
70    /**
71    * getValue() - reads configuration data
72    *
73    * This procedure returns the value for then configuration option
74    * specified by $key or an array of all options if $key is not
75    * specified or false
76    *
77    * @access public
78    * @param string|boolean $key
79    * @return mixed
80    */
81    function getValue($key = false) {
82        if($key === false) return $this->d;
83        else return $this->d[strtolower($key)];
84    }
85 
86    /**
87    * setValue() - sets configuration data
88    *
89    * @access public
90    * @param string|boolean $key
91    * @param mixed $value     
92    * @return mixed
93    */
94    function setValue($key, $value) {
95        $this->d[strtolower($key)] = $value;
96    }
97
98    /**
99    * importDataByConstants()
100    *
101    * imports data from global constats starting with JLOG_ prefix     
102    *
103    * @access public
104    * @return void
105    */
106    function importDataByConstants() {
107        # no return
108        // this is a blacklist of constats which are not to be written in settings.inc.php
109        $search = array(
110            'JLOG_ADMIN',
111            'JLOG_DB_CONTENT',
112            'JLOG_DB_COMMENTS',
113            'JLOG_DB_CATASSIGN',
114            'JLOG_DB_CATEGORIES',
115            'JLOG_DB_ATTRIBUTES',
116            'JLOG_UPDATE',
117            'JLOG_LOGIN',
118            'JLOG_SOFTWARE_VERSION',
119            'JLOG_SOFTWARE_URL',
120            'JLOG_SOFTWARE_PHPV',
121            'JLOG_SOFTWARE_MYSQLV',
122            'JLOG_ADMIN_PASSWORD_AGAIN'
123        );
124       
125        // get all needed constants and put it into the class
126        $constants = get_defined_constants();
127        foreach($constants as $key => $value) {
128            if(!in_array($key, $search) AND strpos($key, "JLOG_") !== false) {
129                $this->setValue($key, $value);
130            }
131        }
132    }
133
134    /**
135    * importDataByArray() - sets configuration data
136    *
137    * Sets configuration data according to $d. If working in
138    * non-exclusive mode (the default), $d is merged into the current
139    * configuration, otherwise the current configuration is discared
140    * and $d is set as the new configuration.
141    *
142    * @access public
143    * @param array $d
144    * @param boolean $exclusiv
145    * @return void
146    */
147    function importDataByArray($d = false, $exclusiv = false) {
148
149        // get the data from users $d array and put it into the class
150        if($d !== false) {
151            if($exclusiv) $this->d = $d;
152            else $this->d = array_merge($this->d, $d);
153        }
154       
155        if(JLOG_ADMIN === true) {
156            $this->d['jlog_db'] = JLOG_DB;
157            $this->d['jlog_db_url'] = JLOG_DB_URL;
158            $this->d['jlog_db_user'] = JLOG_DB_USER;
159            $this->d['jlog_db_pwd'] = JLOG_DB_PWD;
160            $this->d['jlog_db_prefix'] = JLOG_DB_PREFIX;
161            $this->d['jlog_start_year'] = JLOG_START_YEAR;
162            $this->d['jlog_path'] = JLOG_PATH;
163            $this->d['jlog_basepath'] = JLOG_BASEPATH;
164            if($this->d['jlog_admin_password'] == '') {
165                $this->jlog_admin_password = JLOG_ADMIN_PASSWORD;
166            }
167            else {
168                $this->d['jlog_admin_password'] = md5($this->d['jlog_admin_password']);
169                $this->d['jlog_admin_password_again'] = md5($this->d['jlog_admin_password_again']);
170            }
171            $this->d['jlog_installed_version'] = JLOG_INSTALLED_VERSION;
172            $this->d['jlog_installed_url'] = JLOG_INSTALLED_URL;
173            $this->d['jlog_installed_phpv'] = JLOG_INSTALLED_PHPV;
174            $this->d['jlog_installed_mysqlv'] = JLOG_INSTALLED_MYSQLV;
175        }
176        else {
177            $this->d['jlog_admin_password'] = md5($this->d['jlog_admin_password']);
178            $this->d['jlog_admin_password_again'] = md5($this->d['jlog_admin_password_again']);
179        }
180       
181        if((defined('JLOG_SETUP') AND JLOG_SETUP === true)) 
182        {
183            $this->d['jlog_installed_version'] = JLOG_SOFTWARE_VERSION;
184            $this->d['jlog_installed_url'] = JLOG_SOFTWARE_URL;
185            $this->d['jlog_installed_phpv'] = JLOG_SOFTWARE_PHPV;
186            $this->d['jlog_installed_mysqlv'] = JLOG_SOFTWARE_MYSQLV;
187        }
188    }
189
190    /**
191    * importSuggestedData() - preallocates configuration data
192    *
193    * Initialises the configuration with useful settings during
194    * the installation process.
195    *
196    * @access public
197    * @return void
198    */
199    function importSuggestedData() {
200        // suggest some data for setup
201        $this->setValue('jlog_path', $this->getSuggestPath());
202        $this->setValue('jlog_basepath', dirname(dirname( __FILE__ )).DIRECTORY_SEPARATOR);
203        $date = getdate();
204        $this->setValue('jlog_start_year', $date['year']);
205        $this->setValue('jlog_max_blog_orginal', 1);
206        $this->setValue('jlog_max_blog_big', 4);
207        $this->setValue('jlog_max_blog_small', 15);
208        $this->setValue('jlog_sub_current', 6);
209        $this->setValue('jlog_date', $this->l['date_format']);
210        $this->setValue('jlog_date_comment', $this->l['date_format_comment']);
211        $this->setValue('jlog_date_subcurrent', $this->l['date_format_subcurrent']);
212        $this->setValue('jlog_info_by_comment', true);
213        $this->setValue('jlog_db_url', 'localhost');
214        $this->setValue('jlog_db_prefix', 'jlog_');
215        $this->setValue('jlog_blogservices', 'http://rpc.pingomatic.com/');
216        $this->setValue('jlog_language', (defined('JLOG_LANGUAGE') ? JLOG_LANGUAGE : 'de'));
217    }
218
219
220    /**
221    * getSuggestPath() - generate a suggestion for JLOG_PATH
222    *
223    * @access private
224    * @return string
225    */
226    function getSuggestPath() {
227        $host  = empty($_SERVER['HTTP_HOST'])
228                  ? (empty($_SERVER['SERVER_NAME'])
229                      ? $_SERVER['SERVER_ADDR']
230                      : $_SERVER['SERVER_NAME'])
231                  : $_SERVER['HTTP_HOST'];
232        $proto = (empty($_SERVER['HTTPS']) OR $_SERVER['HTTPS'] == 'off')
233                  ? 'http'
234                  : 'https';
235        $port  = $_SERVER['SERVER_PORT'];
236   
237        $uri   = $proto . '://' . $host;
238        if ((('http' == $proto) and (80 != $port))
239        or (('https' == $proto) and (443 != $port))) 
240        {
241            $uri .= ':' . $port;
242        }
243        $uri  .= dirname($_SERVER['SCRIPT_NAME']);
244   
245        return $uri;
246    }
247
248    /**
249    * defaultValue() - gets a value of an array
250    *
251    * Look for index $key in the array $array and return
252    * the corresponding value if it exists or the default
253    * value $default if it doesn't.
254    *
255    * @access public
256    * @param array $array
257    * @param mixed $key
258    * @param mixed $default
259    * @return mixed
260    */
261    function defaultValue($array, $key, $default = '') {
262        if(isset($array[$key])) {
263          return $array[$key];
264        }
265        else {
266          return $default;
267        }
268    }
269
270    /**
271    * form_output() - generates HTML output for formular
272    *
273    * @access public
274    * @return string
275    */
276    function form_output() {
277        # returns the filled form
278   
279        $data = array_htmlspecialchars($this->d);
280   
281        if(isset($data['jlog_clean_url']) AND ($data['jlog_clean_url'] === 'true' OR $data['jlog_clean_url'] === '1'))
282        $d['clean_url_yes'] = " checked='checked'";
283        else $d['clean_url_no'] = " checked='checked'";
284   
285        if(isset($data['jlog_info_by_comment'])) $d['info_by_comment'] = " checked='checked'";
286        else $d['info_by_comment'] = "";
287   
288        if(isset($data['jlog_bs_weblogs_com']) AND ($data['jlog_bs_weblogs_com'] === 'true' OR $data['jlog_bs_weblogs_com'] === '1'))
289        $d['bs_weblogs_com'] = " checked='checked' ";
290   
291        if(defined("JLOG_ADMIN") AND JLOG_ADMIN === true) $admincenter_password = " ".$this->l['admin']['m_admin_password_admin'];
292        else $admincenter_password = '';
293   
294        // get available languages
295        $dir = opendir(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'lang');
296        $languages = array();
297        while(($file = readdir($dir)) !== false) {
298          if($file == '.' OR $file == '..') continue;
299          if(!preg_match('/lang\.([a-zA-z0-9]+)\.inc\.php/', $file, $matches)) continue;
300          $languages[] = $matches[1];
301        }
302   
303        // do the form
304        $form = "
305         <form action='".$_SERVER['SCRIPT_NAME']."' method='post'>
306          <fieldset><legend>".$this->l['admin']['m_metadata']."</legend>
307           <p><label for='language'>".$this->l['admin']['m_language']."</label><br />";
308       
309        if(defined("JLOG_ADMIN") AND JLOG_ADMIN === true) $form .= add_session_id_input_tag();
310       
311        $form .= "<select class='userdata' id='language' name='jlog_language'>";
312        foreach($languages as $lang) {
313          $form .= "<option";
314          if((isset($_POST['jlog_language']) AND $lang = $_POST['jlog_language']) OR $lang == JLOG_LANGUAGE)
315          $form .= " selected='selected'";
316          $form .= ">$lang</option>";
317        }
318   
319        $form .= "</select>
320           </p>
321           
322           <p><label for='website'>".$this->l['admin']['m_website']."</label><br />
323              <input class='userdata' id='website' name='jlog_website' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_website')."' /></p>
324           <p><label for='publisher'>".$this->l['admin']['m_publisher']."</label><br />
325              <input class='userdata' id='publisher' name='jlog_publisher' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_publisher')."' /></p>
326           <p><label for='admin_password'>".$this->l['admin']['m_admin_password'].$admincenter_password."</label><br />
327              <input class='userdata' id='admin_password' name='jlog_admin_password' type='password' size='20' maxlength='255' /></p>
328           <p><label for='admin_password_again'>".$this->l['admin']['m_admin_password_again'].$admincenter_password."</label><br />
329              <input class='userdata' id='admin_password_again' name='jlog_admin_password_again' type='password' size='20' maxlength='255' /></p>
330           <p><label for='email'>".$this->l['admin']['m_email']."</label><br />
331              <input class='userdata' id='email' name='jlog_email' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_email')."' /></p>
332           <p><label for='description'>".$this->l['admin']['m_description']."</label><br />
333              <textarea class='small' id='description' name='jlog_description' rows='2' cols='60'>".$this->defaultValue($data, 'jlog_description')."</textarea></p>
334          </fieldset>
335   
336          <fieldset><legend>".$this->l['admin']['m_behavior']."</legend>
337           <p><label>".$this->l['admin']['m_clean_url']."</label><br />
338              <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>
339              <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>
340           <p><label for='max_blog_orginal'>".$this->l['admin']['m_max_blog_orginal']."</label><br />
341              <input class='short' id='max_blog_orginal' name='jlog_max_blog_orginal' type='text' maxlength='3' size='3' value='".$this->defaultValue($data, 'jlog_max_blog_orginal')."' /></p>
342           <p><label for='max_blog_big'>".$this->l['admin']['m_max_blog_big']."</label><br />
343              <input class='short' id='max_blog_big' name='jlog_max_blog_big' type='text' size='3' maxlength='3' value='".$this->defaultValue($data, 'jlog_max_blog_big')."' /></p>
344           <p><label for='max_blog_small'>".$this->l['admin']['m_max_blog_small']."</label><br />
345              <input class='short' id='max_blog_small' name='jlog_max_blog_small' type='text' size='3' maxlength='3' value='".$this->defaultValue($data, 'jlog_max_blog_small')."' /></p>
346           <p><label for='sub_current'>".$this->l['admin']['m_sub_current']."</label><br />
347              <input class='short' id='sub_current' name='jlog_sub_current' type='text' size='3' maxlength='3' value='".$this->defaultValue($data, 'jlog_sub_current')."' /></p>
348           <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>
349           <p><label for='date'>".$this->l['admin']['m_date']."</label></p>
350           <p><input class='userdata' id='date' name='jlog_date' type='text' value='".$this->defaultValue($data, 'jlog_date')."' size='20' /> <label for='date' class='nobreak'>".$this->l['admin']['m_date_posting']."</label></p>
351           <p><input class='userdata' id='date_comment' name='jlog_date_comment' type='text' value='".$this->defaultValue($data, 'jlog_date_comment')."' size='20' /> <label for='date_comment' class='nobreak'>".$this->l['admin']['m_date_comment']."</label></p>
352           <p><input class='userdata' id='date_subcurrent' name='jlog_date_subcurrent' type='text' value='".$this->defaultValue($data, 'jlog_date_subcurrent')."' size='20' /> <label for='date_subcurrent' class='nobreak'>".$this->l['admin']['m_date_subcurrent']."</label></p>
353           <p><label for='blogservices'>".$this->l['admin']['m_bs']."</label></p>
354           <p><textarea class='small' id='blogservices' name='jlog_blogservices' rows='2' cols='60'>".$this->defaultValue($data, 'jlog_blogservices')."</textarea></p>
355          </fieldset>
356         ";
357   
358        if(defined('JLOG_SETUP') AND JLOG_SETUP === true) {
359          $form .=
360          "
361          <fieldset><legend>".$this->l['admin']['m_database']."</legend>
362           <p><label for='db'>".$this->l['admin']['m_db']."</label><br />
363              <input class='userdata' id='db' name='jlog_db' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db')."' /></p>
364           <p><label for='db_url'>".$this->l['admin']['m_db_url']."</label><br />
365              <input class='userdata' id='db_url' name='jlog_db_url' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_url')."' /></p>
366           <p><label for='db_user'>".$this->l['admin']['m_db_user']."</label><br />
367              <input class='userdata' id='db_user' name='jlog_db_user' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_user')."' /></p>
368           <p><label for='db_pwd'>".$this->l['admin']['m_db_pwd']."</label><br />
369              <input class='userdata' id='db_pwd' name='jlog_db_pwd' type='password' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_pwd')."' /></p>
370           <p><label for='db_prefix'>".$this->l['admin']['m_db_prefix']."</label><br />
371              <input class='userdata' id='db_prefix' name='jlog_db_prefix' type='text' size='20' maxlength='255' value='".$this->defaultValue($data, 'jlog_db_prefix')."' />
372              <input name='jlog_start_year' type='hidden' value='".$this->defaultValue($data, 'jlog_start_year', date("Y"))."' /></p>
373              <input name='jlog_path' type='hidden' value='".$this->defaultValue($data, 'jlog_path')."' />
374              <input name='jlog_basepath' type='hidden' value='".$this->defaultValue($data, 'jlog_basepath')."' />
375          </fieldset>
376         ";
377        }
378   
379        $form .= "
380          <p><input type='submit' class='button' value='".$this->l['admin']['submit']."' /></p>
381         </form>
382         ";
383   
384        return $form;
385    }
386
387    /**
388    * validate() - validates the current configuration
389    *
390    * If the current configuration is valid, an empty array is returned.
391    * Otherwise the returned array containes all errors, described in the
392    * current language.
393    *
394    * @access public
395    * @return array
396    */
397    function validate() {
398        # if everything validate then return true
399        # otherwise return the $errors array
400   
401        $errors = array();
402   
403        // paths
404        if(empty($this->d['jlog_path']) OR (check_url($this->d['jlog_path'], array ('http')) === false)) $errors[] = $this->l['admin']['e_path'];
405        if(empty($this->d['jlog_basepath']) OR !is_dir($this->d['jlog_basepath'])) $errors[] = $this->l['admin']['e_basepath'];
406        if($this->d['jlog_clean_url'] != 'true') $this->d['jlog_clean_url'] = 'false';
407        // metadata
408        if(empty($this->d['jlog_website'])) $errors[] = $this->l['admin']['e_website'];
409        if(empty($this->d['jlog_publisher'])) $errors[] = $this->l['admin']['e_publisher'];
410        if(defined('JLOG_SETUP') AND JLOG_SETUP) {
411          if($this->d['jlog_admin_password'] == md5(""))
412          $errors[] = $this->l['admin']['e_admin_password'];
413          elseif($this->d['jlog_admin_password'] !== $this->d['jlog_admin_password_again'])
414          $errors[] = $this->l['admin']['e_admin_password_again'];
415        }
416        elseif(!empty($this->d['jlog_admin_password']) AND $this->d['jlog_admin_password'] !== $this->d['jlog_admin_password_again']) {
417          $errors[] = $this->l['admin']['e_admin_password_again'];
418        }
419        // Fix of bug #148
420        if(isset($this->d['jlog_admin_password_again']))
421        unset($this->d['jlog_admin_password_again']);
422   
423        if(empty($this->d['jlog_email']) OR !strpos($this->d['jlog_email'], '@')) $errors[] = $this->l['admin']['e_email'];
424        if(empty($this->d['jlog_description'])) $errors[] = $this->l['admin']['e_description'];
425        // behavour
426        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'];
427        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'];
428        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'];
429        if(!is_numeric($this->d['jlog_sub_current']) OR intval($this->d['jlog_sub_current']) < 0) $errors[] = $this->l['admin']['e_sub_current'];
430        if(!is_numeric($this->d['jlog_start_year'])) $errors[] = $this->l['admin']['e_start_year'];
431        if($this->d['jlog_info_by_comment'] != 'true') $this->d['jlog_info_by_comment'] = 'false';
432        // database
433        if(empty($this->d['jlog_db'])) $errors[] = $this->l['admin']['e_db'];
434        if(empty($this->d['jlog_db_url'])) $errors[] = $this->l['admin']['e_db_url'];
435        // Fix of bug #196, prefix should only contain alphanumeric values, can be empty!
436        if(!preg_match('/^[a-zA-Z0-9_]*$/', $this->d['jlog_db_prefix'])) $errors[] = $this->l['admin']['e_db_prefix'];
437   
438        return $errors;
439    }
440
441    /**
442    * do_settings() - save configuration
443    *
444    * Saves the current configuration to the settings.inc.php file
445    * in the personal folder. Return an empty array if configuration
446    * was saved successfully, or an array containing descriptions of
447    * the errors that occured otherwise.
448    *
449    * @access public
450    * @return array
451    */
452    function do_settings() {
453        # if it's all done return true
454        # otherwise return the $errors array
455   
456        $errors = array();
457   
458        // if there is no new password set the old
459        if(JLOG_ADMIN AND empty($this->d['jlog_admin_password'])) $this->d['jlog_admin_password'] = JLOG_ADMIN_PASSWORD;
460   
461        // remove slashes at the end of JLOG_PATH if present
462        $this->d['jlog_path'] = rtrim($this->d['jlog_path'], '/');
463        // make shure JLOG_BASEPATH ends with a slash!!
464        $this->d['jlog_basepath'] = rtrim($this->d['jlog_basepath'], '/\\') . DIRECTORY_SEPARATOR;
465   
466        // no quotes for bolean and numbers
467        $no_quotes = array (
468            'jlog_clean_url' => 'bool',
469            'jlog_max_blog_orginal' => 'int',
470            'jlog_max_blog_big' => 'int',
471            'jlog_max_blog_small' => 'int',
472            'jlog_sub_current' => 'int',
473            'jlog_start_year' => 'int',
474            'jlog_info_by_comment' => 'bool'
475        );
476   
477        // serialize data to file format
478        $file_content = '<?php' . PHP_EOL . '// generated at ' . date('Y-m-d, h:i:s') . PHP_EOL;
479   
480        foreach($this->d as $key => $value) {
481            $output = '';
482            if(isset($no_quotes[$key])) {
483                // boolean values
484                if($no_quotes[$key] == 'bool') {
485                    if($value == 'true' OR $value === true) $output = 'true';
486                    else $output = 'false';
487                }
488                // numeric values
489                else {
490                    $output = (int) $value;
491                }
492            }
493            // string values
494            else {
495                $output = '\'' . $this->escapeForPhp($value) . '\'';
496            }
497            $key = '\'' . $this->escapeForPhp(strtoupper($key)) . '\'';
498            $file_content .= 'define(' . $key . ', ' . $output . ');' . PHP_EOL;
499        }
500   
501        $file_content .= '// eof';
502   
503        // write to settings.inc.php
504        if(!$handle = fopen(JLOG_BASEPATH."personal".DIRECTORY_SEPARATOR."settings.inc.php", "w")) $errors[] = $this->l['admin']['can_not_open']." /personal/settings.inc.php";
505        if(!fwrite($handle, $file_content)) $errors[] = $this->l['admin']['can_not_write']." /personal/settings.inc.php";
506        fclose($handle);
507   
508        return $errors;
509    }
510 
511    /**
512    * escapeForPhp()
513    *
514    * escapes $value so that it can be used between single quotes in a
515    * PHP script, single quotes are better than double qoutes, as therein no
516    * further substituions are performed   
517    *
518    * @access public
519    * @param string $value   
520    * @return string
521    */
522    function escapeForPhp($value) {
523        $value = str_replace('\\', '\\\\', $value);
524        $value = str_replace("'",  "\'", $value);
525        $value = str_replace("\0", '', $value