public
Description: PyroCMS is a CMS built using the CodeIgniter PHP framework with modularity in mind. Lightweight, themeable and dynamic.
Homepage: http://pyrocms.com
Clone URL: git://github.com/philsturgeon/pyrocms.git
Click here to lend your support to: pyrocms and make a donation at www.pledgie.com !
pyrocms / application / libraries / Verifier.php
100644 385 lines (346 sloc) 7.852 kb
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
<?php
/**
* CodeIgniter Verifier Class
*
* This class enables you to verify system requirements for PHP, CodeIgniter,
* specific databases and other items.
*
* @author Jacob "Pygon" Sparks
* @version 0.3
*/
 
class Verifier
{
var $_loaded_extensions = array();
var $_dependants = array(
"captcha_pi" => array(
"checks" => array(
"extension"=>"gd"
)
),
 
"ftp" => array(
"checks" => array(
"function"=>"ftp_connect"
)
),
 
"image_lib" => array(
"checks" => array(
"imagelib"=>TRUE,
),
),
 
"xmlrpc" => array(
"checks" => array(
"function"=>"xml_parser_create"
),
),
 
"xmlrpcs" => array(
"checks" => array(
"function"=>"xml_parser_create"
),
),
 
"zip" => array(
"checks" => array(
"function"=>"gzencode"
),
),
 
"output" => array(
"checks" => array(
"function"=>"gzencode",
"ini"=>array(
"option"=>"zlib.output_compression",
"value"=> FALSE
)
)
)
);
 
/**
* Verifier Constructor
* The constructor runs the initialization function.
*
* @return void
*/
function Verifier()
{
$this->_initialize();
}
 
/**
* Create an array of loaded extensions and versions.
*
* @return void
* @access private
*/
function _initialize()
{
$tmp_ext = get_loaded_extensions();
 
// Fix case sensitivity for more accurate user checks and pre-fetch versions
foreach ($tmp_ext as $value)
{
$this->_loaded_extensions[strtolower($value)] = phpversion($value);
}
}
 
/**
* Check permissions to write to file/directory.
*
* @param string $file file name
* @return bool
* @access public
*/
function check_writable($file)
{
return is_really_writable($file);
}
 
/**
* Alias to function is_writable
*
* @param string $file file name
* @return bool
* @access public
*/
function check_writeable($file)
{
return $this->check_writable($file);
}
 
/**
* Get or compare PHP version.
* NOTE: Current version is left of operator.
*
* @param string $arg[0] optional minimum version
* @param string $arg[1] optional comparison operator
* @return mixed bool on compare,version
* @access public
*/
function check_php_version()
{
$args = func_get_args();
return $this->_check_version("php", $args);
}
 
/**
* Get or compare an extension version.
* NOTE: Current version is left of operator.
*
* @param string $extension extension name
* @param optional minimum version
* @param optional comparison operator
* @return mixed bool on compare, version
* @access public
*/
function check_extension_version($extension)
{
$extension = strtolower($extension);
if(array_key_exists($extension,$this->_loaded_extensions))
{
$args = array();
 
if(func_num_args() > 1)
{
$args = func_get_args();
array_shift($args);
}
 
return $this->_check_version($extension, $args);
}
return FALSE;
}
 
/**
* Private function that handles comparison of extention versions.
*
* @param string $item "php" or extension name
* @param string $arg[1] optional minimum version
* @param string $arg[2] optional comparison operator
* @return mixed bool on compare, version
* @access private
*/
function _check_version($item, $args)
{
$check_php = ($item == "php") ? TRUE : FALSE;
if(!empty($args))
{
$min_version = $args[0];
$operator = isset($args[1]) ? $args[1] : ">=";
 
return version_compare( (($check_php) ? PHP_VERSION : $this->_loaded_extensions[$item]), $min_version, $operator);
}
 
if($check_php)
{
return PHP_VERSION;
}
 
if( $this->_loaded_extensions[$item] === FALSE )
{
return "Unknown";
}
else
{
return $this->_loaded_extensions[$item];
}
}
 
/**
* Function to check whether an extension is loaded.
*
* @param string $item extension name
* @return bool
* @access public
*/
function check_has_extension($item)
{
return array_key_exists(strtolower($item),$this->_loaded_extensions);
}
 
/**
* Function to check an ini setting.
*
* @param string $item ini setting
* @param mixed $value optional value to compare
* @return mixed bool on compare, value
* @access public
*/
function check_has_ini($item,$value=null)
{
$ini_val = ini_get($item);
 
if($value !== null)
{
return ($ini_val == $value)? TRUE : FALSE;
}
 
return $ini_val;
}
 
/**
* Function to check if a function exists
*
* @param string $item function name
* @return bool
* @access public
*/
function check_has_function($item)
{
return function_exists($item);
}
 
/**
* Function to check if a constant is defined.
*
* @param string $item constant (case sensitive)
* @return bool
* @access public
*/
function check_has_constant($item)
{
return defined($item)? TRUE : FALSE; //Fix PHP <4.3.2 return 1 or 0 instead of TRUE/FALSE
}
 
/**
* Private function to check a dependancy.
*
* @param string $name CI class name (with CI_)
* @return bool
* @access private
*/
function _check_dependancy($name)
{
if(is_array($this->_dependants[$name]["checks"]))
{
$checks =& $this->_dependants[$name]["checks"];
}
else
{
return TRUE;
}
 
foreach($checks as $k=>$v)
{
switch($k)
{
 
case "function":
if($this->check_has_function($v) === FALSE)
{
return FALSE;
}
break;
 
case "extension":
if($this->check_has_extension($v) === FALSE)
{
return FALSE;
}
break;
 
case "ini":
if($this->check_has_ini($v["option"],$v["value"]) === FALSE)
{
return FALSE;
}
break;
case "constant":
if($this->check_has_constant($v) === FALSE)
{
return FALSE;
}
break;
case "imagelib":
if($this->check_has_imagelib() === FALSE)
{
return FALSE;
}
break;
}
}
unset($checks,$k,$v);
return TRUE;
 
}
 
/**
* Function to check that the extension selected for Image_lib is valid.
*
* @return bool
* @access public
*/
function check_has_imagelib()
{
$imagelib =& load_class('Image_lib');
$ext_image = $imagelib->image_library;
unset($imagelib);
if($ext_image == "gd2") $ext_image = "gd";
return $this->check_has_extension($ext_image);
}
 
/**
* Function to check a dependancy.
*
* @param string $name CI class name (with CI_)
* @return bool
* @access public
*/
function check_dependancy($name)
{
$name = strtolower($name);
if(!array_key_exists($name, $this->_dependants))
{
return TRUE; //No known dependancies
}
 
if($this->_check_dependancy($name) === FALSE)
{
return FALSE;
}
 
return TRUE;
}
 
/**
* Function to check all dependancies.
*
* @param string $name CI class name (with CI_)
* @return array (string)name => (bool)
* @access public
*/
function check_all_dependancies()
{
$output = array();
foreach(array_keys($this->_dependants) as $key)
{
$output[$key] = $this->_check_dependancy(strtolower($key));
}
unset($key);
return count($output)>=1 ? $output : FALSE;
}
 
/**
* Function to get a list of loaded extensions.
*
* @return array (string)name => (mixed)version
* @access public
*/
function get_extensions()
{
$out_exts = array();
foreach($this->_loaded_extensions as $k => $v)
{
$out_exts[$k] = ($v === FALSE) ? "Unknown" : $v;
}
unset($k,$v);
return $out_exts;
}
 
}
?>