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