1: <?php
2: /**
3: * This file contains various helper functions to read specific values needed for setup checks.
4: *
5: * @package Setup
6: * @subpackage Helper_PHP
7: * @version SVN Revision $Rev:$
8: *
9: * @author Unknown
10: * @copyright four for business AG <www.4fb.de>
11: * @license http://www.contenido.org/license/LIZENZ.txt
12: * @link http://www.4fb.de
13: * @link http://www.contenido.org
14: */
15:
16: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
17:
18: define('CON_EXTENSION_AVAILABLE', 1);
19:
20: define('CON_EXTENSION_UNAVAILABLE', 2);
21:
22: define('CON_EXTENSION_CANTCHECK', 3);
23:
24: /**
25: * Retrieves the setting $setting from the PHP setup.
26: * Wrapper to avoid warnings if ini_get is in the
27: * disable_functions directive.
28: */
29: function getPHPIniSetting($setting) {
30: // Avoid errors if ini_get is in the disable_functions directive
31: $value = @ini_get($setting);
32:
33: return $value;
34: }
35:
36: /**
37: * Checks if PHP is able to use allow_url_fopen.
38: */
39: function canPHPurlfopen() {
40: return getPHPIniSetting('allow_url_fopen');
41: }
42:
43: /**
44: * Checks if the ini_get function is available and not disabled.
45: * Returns true if the
46: * function is available.
47: *
48: * Uses the PHP configuration value y2k_compilance which is available in all
49: * PHP4 versions.
50: */
51: function checkPHPiniget() {
52: $value = @ini_get('y2k_compliance');
53:
54: if ($value === NULL) {
55: return false;
56: } else {
57: return true;
58: }
59: }
60:
61: function getPHPDisplayErrorSetting() {
62: return getPHPIniSetting('display_errors');
63: }
64:
65: function getPHPFileUploadSetting() {
66: return getPHPIniSetting('file_uploads');
67: }
68:
69: function getPHPGPCOrder() {
70: return getPHPIniSetting('gpc_order');
71: }
72:
73: function getPHPMagicQuotesGPC() {
74: return getPHPIniSetting('magic_quotes_gpc');
75: }
76:
77: function getPHPMagicQuotesRuntime() {
78: return getPHPIniSetting('magic_quotes_runtime');
79: }
80:
81: // @todo Check if sybase still needed
82: function getPHPMagicQuotesSybase() {
83: return getPHPIniSetting('magic_quotes_sybase');
84: }
85:
86: function getPHPMaxExecutionTime() {
87: return getPHPIniSetting('max_execution_time');
88: }
89:
90: function getPHPOpenBasedirSetting() {
91: return getPHPIniSetting('open_basedir');
92: }
93:
94: function getPHPMaxPostSize() {
95: return getPHPIniSetting('post_max_size');
96: }
97:
98: function checkPHPSQLSafeMode() {
99: return getPHPIniSetting('sql.safe_mode');
100: }
101:
102: function checkPHPUploadMaxFilesize() {
103: return getPHPIniSetting('upload_max_filesize');
104: }
105:
106: function getAsBytes($val) {
107: if (strlen($val) == 0) {
108: return 0;
109: }
110: $val = trim($val);
111: $last = $val{strlen($val) - 1};
112: switch ($last) {
113: case 'k':
114: case 'K':
115: return (int) $val * 1024;
116: break;
117: case 'm':
118: case 'M':
119: return (int) $val * 1048576;
120: break;
121: default:
122: return $val;
123: }
124: }
125:
126: function isPHPExtensionLoaded($extension) {
127: $value = extension_loaded($extension);
128:
129: if ($value === NULL) {
130: return CON_EXTENSION_CANTCHECK;
131: }
132:
133: if ($value === true) {
134: return CON_EXTENSION_AVAILABLE;
135: }
136:
137: if ($value === false) {
138: return CON_EXTENSION_UNAVAILABLE;
139: }
140: }
141:
142: function isRegisterLongArraysActive() {
143: if (getPHPIniSetting('register_long_arrays') == false) {
144: return false;
145: }
146:
147: return true;
148: }
149:
150: function isPHPCompatible() {
151: if (version_compare(phpversion(), CON_SETUP_MIN_PHP_VERSION, '>=') == true) {
152: return true;
153: } else {
154: return false;
155: }
156: }
157:
158: ?>