Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
init.inc
1 <?php
32 if (!defined('PHP_VERSION_ID')) {
33  $version = explode('.', PHP_VERSION);
34  define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2]));
35 }
36 
37 
38 // set the level of PHP reported errors and some other
39 // PHP thingies we want done OUR way
40 if (PHP_VERSION_ID < 50300) {
41  // pear http/client module contains deprecated syntax which will cause trouble
42  // E_DEPRECATED is introduced in PHP 5.3 and included in E_ALL, so has to remove E_DEPRECATED for php 5.3 and above
43  error_reporting(E_ALL);
44 }
45 else {
46  error_reporting(E_ALL ^ E_DEPRECATED);
47 }
48 
49 # Before 5.3.0 we have to set magic quotes runtime off
50 if (PHP_VERSION_ID < 50300) {
51  set_magic_quotes_runtime(0);
52 }
53 
54 // we need this so that our error handler won't kill itself attempting to try and remove
55 // all existing buffers - especially important when Zend Performance Suite is installed because
56 // it adds another OB level
57 define('SQ_INIT_OB_LEVEL', ob_get_level());
58 
59 // are we running from the command line ?
60 define('SQ_PHP_CLI', (php_sapi_name() == 'cli'));
61 
62 
63 // Let's get our bearings as to where everything is from here.
64 // These paths may be relative or absolute
65 if (!defined('SQ_SYSTEM_ROOT')) {
66  define('SQ_SYSTEM_ROOT', dirname(dirname(dirname(realpath(__FILE__)))));
67 }
68 define('SQ_INCLUDE_PATH', SQ_SYSTEM_ROOT.'/core/include');
69 define('SQ_CORE_PACKAGE_PATH', SQ_SYSTEM_ROOT.'/core/assets');
70 define('SQ_ATTRIBUTES_PATH', SQ_SYSTEM_ROOT.'/core/attributes');
71 define('SQ_LIB_PATH', SQ_SYSTEM_ROOT.'/core/lib');
72 define('SQ_DATA_PATH', SQ_SYSTEM_ROOT.'/data');
73 define('SQ_CACHE_PATH', SQ_SYSTEM_ROOT.'/cache');
74 define('SQ_PACKAGES_PATH', SQ_SYSTEM_ROOT.'/packages');
75 define('SQ_WEB_PATH', SQ_SYSTEM_ROOT.'/core/web');
76 define('SQ_FUDGE_PATH', SQ_SYSTEM_ROOT.'/fudge');
77 define('SQ_TEMP_PATH', SQ_SYSTEM_ROOT.'/data/temp');
78 define('SQ_LOG_PATH', SQ_SYSTEM_ROOT.'/data/private/logs');
79 
80 
81 // include the system version setttings
82 require_once SQ_INCLUDE_PATH.'/version.inc';
83 
84 // include the main system config file
85 require_once SQ_DATA_PATH.'/private/conf/main.inc';
86 if (!SQ_PHP_CLI) {
87  ini_set('memory_limit', SQ_CONF_WEB_MEMORY_LIMIT.'M');
88 }
89 
90 // This sets the default timezone so date functions don't throw E_STRICT.
91 if (defined('SQ_CONF_TIMEZONE')) {
92  date_default_timezone_set(SQ_CONF_TIMEZONE);
93 }
94 
95 // include installation key if it exists
96 if (file_exists(SQ_DATA_PATH.'/private/conf/licence.inc')) {
97  require_once SQ_DATA_PATH.'/private/conf/licence.inc';
98 }
99 
100 // To be able to use symlinks without MySource Matrix tripping over the index.php, strip
101 // it out of the PHP_SELF variable (pretend we're someone we're not). When
102 // the symlinked directory gets redirected by the .htaccess file, it has
103 // the index.php appended to the url, which causes all sorts of problems for
104 // the system as it expects php_self to be just a name, as it is normally
105 // aliased to the index.php directly. This will
106 // quite probably need to be changed to a function like get_real_self()
107 
108 // if there's a index.php/ that's not at the end (ie it has a trailing slash) in the
109 // php_self variable, remove it as it breaks everything (symlinks only).
110 if (strrpos($_SERVER['PHP_SELF'], 'index.php/')) {
111  $_SERVER['PHP_SELF'] = str_replace('index.php/','', $_SERVER['PHP_SELF']);
112 }
113 
114 // sanitize PHP_SELF against XSS attack <script> should never gets to PHP_SELF
115 $_SERVER['PHP_SELF'] = htmlspecialchars($_SERVER['PHP_SELF']);
116 
117 // Load general everyday handy functions for developers
118 require_once SQ_FUDGE_PATH.'/dev/dev.inc';
119 require_once SQ_FUDGE_PATH.'/general/general.inc';
120 
121 // nice little boolean to use for testing whether we happen to be in the backend or not
122 $in_backend = (trim(SQ_CONF_BACKEND_SUFFIX) != '') && (basename($_SERVER['PHP_SELF']) == SQ_CONF_BACKEND_SUFFIX);
123 define('SQ_IN_BACKEND', $in_backend);
124 
125 // nice little boolean to use for testing whether we happen to be in limbo (frontend editing) or not
126 $in_limbo = (trim(SQ_CONF_LIMBO_SUFFIX) != '') && (basename($_SERVER['PHP_SELF']) == SQ_CONF_LIMBO_SUFFIX);
127 define('SQ_IN_LIMBO', $in_limbo);
128 
129 // nice little boolean to use for testing whether we happen to be in login interface or not
130 $in_login = (trim(SQ_CONF_LOGIN_SUFFIX) != '') && (basename($_SERVER['PHP_SELF']) == SQ_CONF_LOGIN_SUFFIX);
131 define('SQ_IN_LOGIN', $in_login);
132 
133 // we are in performance results view
134 $in_performance = defined('SQ_CONF_PERFORMANCE_SUFFIX') && (trim(SQ_CONF_PERFORMANCE_SUFFIX) != '') && (basename($_SERVER['PHP_SELF']) == SQ_CONF_PERFORMANCE_SUFFIX);
135 define('SQ_IN_PERFORMANCE', $in_performance);
136 
137 // we are timing performance data
138 $in_performance_timing = defined('SQ_CONF_PERFORMANCE_TIMING_SUFFIX') && (trim(SQ_CONF_PERFORMANCE_TIMING_SUFFIX) != '') && (basename($_SERVER['PHP_SELF']) == SQ_CONF_PERFORMANCE_TIMING_SUFFIX);
139 if($in_performance_timing)
140  define('SQ_IN_PERFORMANCE_TIMING', $in_performance_timing);
141 
142 // we are showing performance result
143 $in_performance_result = defined('SQ_CONF_PERFORMANCE_RESULT_SUFFIX') && (trim(SQ_CONF_PERFORMANCE_RESULT_SUFFIX) != '') && (basename($_SERVER['PHP_SELF']) == SQ_CONF_PERFORMANCE_RESULT_SUFFIX);
144 define('SQ_IN_PERFORMANCE_RESULT', $in_performance_result);
145 
146 // boolean to use for testing whether we're running cron scripts
147 if (!defined('SQ_IN_CRON')) {
148  define('SQ_IN_CRON', FALSE);
149 }
150 
151 // make sure there is a trailing slash if we are in the backend
152 if (SQ_IN_BACKEND && substr($_SERVER['PHP_SELF'], -1) != '/') {
153  header('Location: '.$_SERVER['PHP_SELF'].'/'.(($_SERVER['QUERY_STRING']) ? '?'.$_SERVER['QUERY_STRING'] : ''));
154  exit();
155 }
156 
157 
158 // the current output type for the system, can be changed during run-time (eg to XML)
159 // main use is so that the error_reporter doesn't error in HTML to something expecting XML
160 if (!isset($GLOBALS['SQ_OUTPUT_TYPE'])) {
161  $GLOBALS['SQ_OUTPUT_TYPE'] = (SQ_PHP_CLI) ? 'text' : 'html';
162 }
163 
164 
165 // we are not purging the trash
166 $GLOBALS['SQ_PURGING_TRASH'] = FALSE;
167 
168 // we are not reverting to a system version
169 $GLOBALS['SQ_REVERT_TO_SYSTEM_VERSION'] = FALSE;
170 
171 
172 /*
173 * LINK TYPES - way in which assets can be associated with each other
174 */
175 define('SQ_LINK_TYPE_1', 1); // link is displayed on frontend and backend navigation
176 define('SQ_LINK_TYPE_2', 2); // same power/rank as a TYPE_1 link but is only displayed on backend navigation
177 define('SQ_LINK_TYPE_3', 4); // same power/rank as a TYPE_1 link, but is not displayed on any navigation
178 define('SQ_LINK_NOTICE', 8); // for information purposes only, (eg register HREF's from one asset to another)
179 
180 define('SQ_SC_LINK_ALL', 15); // short hand what all the main link types add up to
181 define('SQ_SC_LINK_FRONTEND_NAV', 1); // short hand for TYPE_1
182 define('SQ_SC_LINK_BACKEND_NAV', 3); // short hand for TYPE_1 | TYPE_2
183 define('SQ_SC_LINK_SIGNIFICANT', 7); // short hand for TYPE_1 | TYPE_2 | TYPE_3
184 define('SQ_SC_LINK_WEB_PATHS', 7); // short hand for links affected by web path changes
185 
186 
187 /*
188 * PERMISSION TYPES - different access levels to control access to an asset
189 */
190 define('SQ_PERMISSION_WORKFLOW', 0); // workflow
191 define('SQ_PERMISSION_READ', 1); // read access
192 define('SQ_PERMISSION_WRITE', 2); // write access
193 define('SQ_PERMISSION_ADMIN', 3); // admin access
194 
195 
196 /*
197 * STATUS TYPES - statii an asset can currently have
198 * It is very important that the statii stay in the order they are defined
199 * as they are compared to eachother when changing the status of an asset
200 */
201 define('SQ_STATUS_ARCHIVED', 1); // asset is archived
202 define('SQ_STATUS_UNDER_CONSTRUCTION', 2); // asset is under construction
203 define('SQ_STATUS_PENDING_APPROVAL', 4); // asset is currently in workflow
204 define('SQ_STATUS_APPROVED', 8); // asset is approved waiting to go live from under construction
205 define('SQ_STATUS_LIVE', 16); // asset is live
206 define('SQ_STATUS_LIVE_APPROVAL', 32); // asset is up for review
207 define('SQ_STATUS_EDITING', 64); // asset is currently safe editing
208 define('SQ_STATUS_EDITING_APPROVAL', 128); // asset is currently in workflow from safe edit
209 define('SQ_STATUS_EDITING_APPROVED', 256); // asset is approved waiting to go live from safe edit
210 
211 define('SQ_SC_STATUS_NOT_LIVE', 15); // short cut for ARCHIVED | UNDER_CONSTRUCTION | PENDING_APPROVAL | APPROVED
212 define('SQ_SC_STATUS_LIVE_EDIT', 48); // short cut for LIVE | LIVE_APPROVAL
213 define('SQ_SC_STATUS_CAN_APPROVE', 66); // short cut for UNDER_CONSTRUCTION | EDITING
214 define('SQ_SC_STATUS_PENDING', 164); // short cut for PENDING_APPROVAL | EDITING_APPROVAL | LIVE_APPROVAL
215 define('SQ_SC_STATUS_ALL_APPROVED', 264); // short cut for APPROVED | EDITING_APPROVED
216 define('SQ_SC_STATUS_SAFE_EDITING', 448); // short cut for EDITING | EDITING_APPROVAL | SQ_STATUS_EDITING_APPROVED
217 define('SQ_SC_STATUS_ALL', 511); // short cut for SQ_STATUS_*
218 
219 
220 /*
221 * RUN LEVEL SETTINGS - security systems that can be enabled and disabled
222 */
223 define('SQ_SECURITY_PERMISSIONS', 1); // enable permissions checking
224 define('SQ_SECURITY_LOCKING', 2); // enable locking
225 define('SQ_SECURITY_DATA_VALIDATION', 4); // enable data value validation
226 define('SQ_SECURITY_PASSWORD_VALIDATION', 8); // enable password rule checking
227 define('SQ_SECURITY_LINK_INTEGRITY', 16); // enable link validation
228 define('SQ_SECURITY_INTEGRITY', 32); // enable additional actions to ensure system/asset integrity
229 define('SQ_SECURITY_STATUS_INTEGRITY', 64); // enable status change checking
230 define('SQ_SECURITY_TRIGGERS', 128); // enable triggering/event system
231 
232 define('SQ_RUN_LEVEL_OPEN', 0); // no security
233 define('SQ_RUN_LEVEL_FORCED', 236); // DATA_VALIDATION, PASSWORD_VALIDATION, INTEGRITY, STATUS_INTEGRITY and TRIGGERS
234 define('SQ_RUN_LEVEL_SECURE', 255); // full security
235 
236 
237 // this is where parameter map and trigger actions will store session variables
238 define('SQ_SESSION_SANDBOX_INDEX', '__SQ_SESSION_SANDBOX');
239 
240 
241 // load assertion functions, for integrated testing
242 require_once SQ_INCLUDE_PATH.'/assertions.inc';
243 
244 
245 // load general functions, including the error handler
246 require_once SQ_INCLUDE_PATH.'/general.inc';
247 ini_set('display_errors', 1); // we'll manage whether to display the errors or not in the error_handler
248 set_error_handler('sq_error_handler');
249 set_exception_handler('sq_exception_handler');
250 
251 // turn off error reporting on the front end (errors are still caught and displayed/hidden by the error handler)
252 if (!(SQ_IN_BACKEND | SQ_IN_LIMBO | SQ_IN_CRON) & hide_frontend_errors()) {
253  ini_set('display_errors', 0);
254 }
255 
256 // Logging to syslog? If so, turn it on now (it won't connect to syslog until the first actual error)
257 if ((boolean)SQ_CONF_ERRORS_LOG_TO_SYSLOG === TRUE) {
258  $ident = SQ_CONF_SYSTEM_NAME;
259  if (empty($ident) === TRUE) {
260  $ident = SQ_SYSTEM_LONG_NAME;
261  }
262  $consts = get_defined_constants();
263  $facility = $consts['LOG_'.strtoupper(SQ_CONF_ERRORS_SYSLOG_FACILITY)];
264  openlog($ident, LOG_ODELAY, $facility);
265 }
266 
267 // if there is magic quotes, strip them out
268 if (get_magic_quotes_gpc()) {
269  stripslashes_array($_GET, TRUE);
270  stripslashes_array($_POST, TRUE);
271  stripslashes_array($_COOKIE, TRUE);
272  stripslashes_array($_REQUEST, TRUE);
273  if (isset($_SERVER['QUERY_STRING'])) {
274  $_SERVER['QUERY_STRING'] = stripslashes($_SERVER['QUERY_STRING']);
275  }
276 }
277 
278 // create and init the system object
279 require_once SQ_INCLUDE_PATH.'/mysource.inc';
280 $GLOBALS['SQ_SYSTEM'] = new MySource();
281 $GLOBALS['SQ_SYSTEM']->setRunLevel(SQ_RUN_LEVEL_SECURE);
282 $GLOBALS['SQ_SYSTEM']->init();
283 ?>