flatpress /branches/session-fix/flatpress/fp-includes/core/core.system.php

Language PHP Lines 187
MD5 Hash eac36abb0abb26ff02f724ffd9eb9a6b Estimated Cost $2,282 (why?)
Repository https://bitbucket.org/alexandrul/flatpress View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php 

	/**
	 * system.php
	 * string-to-php and general system functions 
	 */
	
	
	

	/**
	 * function system_save
	 * 
	 * This function saves a list of variables provided after $file
	 * encapsulated in an array where KEY is the var name
	 * in a php file.
	 *
	 * Example usage:
	 * <code>
	 * <?php
	 * // Let's suppose you want to save an array called $my_arr
	 *  // in file $my_file
	 * $my_file = 'path/to/file'
	 * $my_arr = array ('val1', 'val2', 'val3');
	 * $save_arr = array('$my_arr' => $my_arr); //same as: $save_arr['$my_arr'] = $my_arr);
	 * system_save($my_file, $my_arr);
	 * // now the file $my_file will contain the following lines:
	 *  // global $my_arr;
	 * // $my_arr = array (
	 * //           '$my_arr' => val1', 
	 * //           '$my_arr' => 'val2', 
	 * //           '$my_arr' => 'val3'
	 * //           );
	 * ?>
	 * </code>
	 *
	 * @param string $file file path where $array contents will be saved
	 * @array $var_list list of vars to be saved
	 * @return bool
	 *
	 * @see config_save, config_load
	 *
	 */
	function system_save($file, $array ) {
		
		//if ( ( $numargs = func_num_args() ) > 1) {
		
			$string = "<?php\n\n";
		
			//$arg_list = func_get_args();
			foreach ($array as $key => $arg) {
				//$vname = utils_vname ($arg);
				//var_export($arg);
				$s = /*"  global {$key};\n*/  "\${$key} = " .
						var_export($arg, true) . ";\n";
				$string .= $s;
			}
		
			$string .= "\n?>";
			
			return io_write_file($file, $string);
		
		//} else die('Wrong number of parameters!');
			
	}

	function system_hashsalt_save($force=false) {
		global $fp_config;
		if ($force || !file_exists(HASHSALT_FILE))
			return system_save(HASHSALT_FILE, array('fp_hashsalt'=>$fp_config['general']['blogid'] . ABS_PATH . BLOG_BASEURL .mt_rand()));	
		return true;
	}


	
	define('SYSTEM_VER', '0.803');
	function system_ver() {
		return 'fp-' . SYSTEM_VER;
	}
	
	function system_generate_id($string) {
		return 'fp-'.dechex(crc32($string) ^ mt_rand());
	}
	
	function system_guessblogroot() {
		return substr($_SERVER['REQUEST_URI'],	0,strrpos($_SERVER['REQUEST_URI'],'/')+1);
	}
	
	function system_guessbaseurl() {
		return 'http://'.$_SERVER['HTTP_HOST']. BLOG_ROOT;
	}
	
	function system_getindex() {
		if (MOD_BLOG != INDEX)
			return MOD_BLOG;
		else
			return 'index.php'; 
	}
	
	function system_unregister_globals() {
		$v = @ini_get('register_globals');
		
		// on error we unregister anyway
		if ($v || is_null($v)) {
			foreach ($_REQUEST as $var => $val) {
				unset($GLOBALS[$var]);
			}
		}
		
	}
	
	function system_sanitizequery() {
		$err = false;
		foreach ($_GET as $k => $v) {
			if (preg_match('![<>]|://!', $v)) {
				$err = true;
				break;
			}
		}
		if ($err) {
			// @todo add log handler
			utils_redirect();
		}
	}

	
	function system_init() {
		
		system_sanitizequery();
		system_unregister_globals();
		
		$GLOBALS['fpdb'] =& new FPDB;
							
		$GLOBALS['fp_widgets'] =& new widget_indexer;
		
		$GLOBALS['smarty'] =& $GLOBALS['_FP_SMARTY'];
		$smarty =& $GLOBALS['smarty'];
			
		
		$GLOBALS['fp_config'] =& config_load();
		
		$GLOBALS['theme'] =& theme_loadsettings();
		
		$GLOBALS['lang'] =& lang_load();
		
		
		cookie_setup();
		sess_setup();
		user_loggedin();
		
		plugin_loadall();
		
		// init smarty	
		$smarty->compile_dir = CACHE_DIR;
		$smarty->cache_dir = SMARTY_DIR . 'cache/';
		$smarty->caching = 0;
	
		do_action('init');	

	}

	function system_seterr($module, $val) {
		if ($module)
			$elem = 'success_'.$module;
		else
			$elem = 'success';
		sess_add($elem, $val);
	}

	function system_geterr($module='') {
		if ($module)
			$elem = 'success_'.$module;
		else
			$elem = 'success';
		return sess_remove($elem);
	}
	
	/* delayed print */
	function system_dpr($action, $content) {
		$p = print_r($content,1);
		$f = create_function('', "echo '<pre style=\'position:absolute\'>$p</pre>';");
		add_action($action, $f);
	}
	

?>
Back to Top