1: <?php
2: /**
3: * Basic CakePHP functionality.
4: *
5: * Handles loading of core files needed on every request
6: *
7: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
8: * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
9: *
10: * Licensed under The MIT License
11: * For full copyright and license information, please see the LICENSE.txt
12: * Redistributions of files must retain the above copyright notice.
13: *
14: * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
15: * @link http://cakephp.org CakePHP(tm) Project
16: * @package Cake
17: * @since CakePHP(tm) v 0.2.9
18: * @license http://www.opensource.org/licenses/mit-license.php MIT License
19: */
20:
21: define('TIME_START', microtime(true));
22:
23: if (!defined('E_DEPRECATED')) {
24: define('E_DEPRECATED', 8192);
25: }
26:
27: if (!defined('E_USER_DEPRECATED')) {
28: define('E_USER_DEPRECATED', E_USER_NOTICE);
29: }
30: error_reporting(E_ALL & ~E_DEPRECATED);
31:
32: if (!defined('CAKE_CORE_INCLUDE_PATH')) {
33: define('CAKE_CORE_INCLUDE_PATH', dirname(dirname(__FILE__)));
34: }
35:
36: if (!defined('CORE_PATH')) {
37: define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
38: }
39:
40: if (!defined('WEBROOT_DIR')) {
41: define('WEBROOT_DIR', 'webroot');
42: }
43:
44: /**
45: * Path to the cake directory.
46: */
47: define('CAKE', CORE_PATH . 'Cake' . DS);
48:
49: /**
50: * Path to the application's directory.
51: */
52: if (!defined('APP')) {
53: define('APP', ROOT . DS . APP_DIR . DS);
54: }
55:
56: /**
57: * Path to the application's libs directory.
58: */
59: define('APPLIBS', APP . 'Lib' . DS);
60:
61: /**
62: * Path to the public CSS directory.
63: */
64: if (!defined('CSS')) {
65: define('CSS', WWW_ROOT . 'css' . DS);
66: }
67:
68: /**
69: * Path to the public JavaScript directory.
70: */
71: if (!defined('JS')) {
72: define('JS', WWW_ROOT . 'js' . DS);
73: }
74:
75: /**
76: * Path to the public images directory.
77: */
78: if (!defined('IMAGES')) {
79: define('IMAGES', WWW_ROOT . 'img' . DS);
80: }
81:
82: /**
83: * Path to the tests directory.
84: */
85: if (!defined('TESTS')) {
86: define('TESTS', APP . 'Test' . DS);
87: }
88:
89: /**
90: * Path to the temporary files directory.
91: */
92: if (!defined('TMP')) {
93: define('TMP', APP . 'tmp' . DS);
94: }
95:
96: /**
97: * Path to the logs directory.
98: */
99: if (!defined('LOGS')) {
100: define('LOGS', TMP . 'logs' . DS);
101: }
102:
103: /**
104: * Path to the cache files directory. It can be shared between hosts in a multi-server setup.
105: */
106: if (!defined('CACHE')) {
107: define('CACHE', TMP . 'cache' . DS);
108: }
109:
110: /**
111: * Path to the vendors directory.
112: */
113: if (!defined('VENDORS')) {
114: define('VENDORS', ROOT . DS . 'vendors' . DS);
115: }
116:
117: /**
118: * Web path to the public images directory.
119: */
120: if (!defined('IMAGES_URL')) {
121: define('IMAGES_URL', 'img/');
122: }
123:
124: /**
125: * Web path to the CSS files directory.
126: */
127: if (!defined('CSS_URL')) {
128: define('CSS_URL', 'css/');
129: }
130:
131: /**
132: * Web path to the js files directory.
133: */
134: if (!defined('JS_URL')) {
135: define('JS_URL', 'js/');
136: }
137:
138: require CAKE . 'basics.php';
139: require CAKE . 'Core' . DS . 'App.php';
140: require CAKE . 'Error' . DS . 'exceptions.php';
141:
142: spl_autoload_register(array('App', 'load'));
143:
144: App::uses('ErrorHandler', 'Error');
145: App::uses('Configure', 'Core');
146: App::uses('CakePlugin', 'Core');
147: App::uses('Cache', 'Cache');
148: App::uses('CakeObject', 'Core');
149: App::uses('Object', 'Core');
150: App::uses('Multibyte', 'I18n');
151:
152: App::$bootstrapping = true;
153:
154: /**
155: * Full URL prefix
156: */
157: if (!defined('FULL_BASE_URL')) {
158: $s = null;
159: if (env('HTTPS')) {
160: $s = 's';
161: }
162:
163: $httpHost = env('HTTP_HOST');
164:
165: if (isset($httpHost)) {
166: define('FULL_BASE_URL', 'http' . $s . '://' . $httpHost);
167: Configure::write('App.fullBaseUrl', FULL_BASE_URL);
168: }
169: unset($httpHost, $s);
170: }
171:
172: Configure::write('App.imageBaseUrl', IMAGES_URL);
173: Configure::write('App.cssBaseUrl', CSS_URL);
174: Configure::write('App.jsBaseUrl', JS_URL);
175:
176:
177: if (!function_exists('mb_stripos')) {
178:
179: /**
180: * Find position of first occurrence of a case-insensitive string.
181: *
182: * @param string $haystack The string from which to get the position of the first occurrence of $needle.
183: * @param string $needle The string to find in $haystack.
184: * @param int $offset The position in $haystack to start searching.
185: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
186: * @return int|bool The numeric position of the first occurrence of $needle in the $haystack string, or false
187: * if $needle is not found.
188: */
189: function mb_stripos($haystack, $needle, $offset = 0, $encoding = null) {
190: return Multibyte::stripos($haystack, $needle, $offset);
191: }
192:
193: }
194:
195: if (!function_exists('mb_stristr')) {
196:
197: /**
198: * Finds first occurrence of a string within another, case insensitive.
199: *
200: * @param string $haystack The string from which to get the first occurrence of $needle.
201: * @param string $needle The string to find in $haystack.
202: * @param bool $part Determines which portion of $haystack this function returns.
203: * If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
204: * If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
205: * Default value is false.
206: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
207: * @return string|bool The portion of $haystack, or false if $needle is not found.
208: */
209: function mb_stristr($haystack, $needle, $part = false, $encoding = null) {
210: return Multibyte::stristr($haystack, $needle, $part);
211: }
212:
213: }
214:
215: if (!function_exists('mb_strlen')) {
216:
217: /**
218: * Get string length.
219: *
220: * @param string $string The string being checked for length.
221: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
222: * @return int The number of characters in string $string having character encoding encoding.
223: * A multi-byte character is counted as 1.
224: */
225: function mb_strlen($string, $encoding = null) {
226: return Multibyte::strlen($string);
227: }
228:
229: }
230:
231: if (!function_exists('mb_strpos')) {
232:
233: /**
234: * Find position of first occurrence of a string.
235: *
236: * @param string $haystack The string being checked.
237: * @param string $needle The position counted from the beginning of haystack.
238: * @param int $offset The search offset. If it is not specified, 0 is used.
239: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
240: * @return int|bool The numeric position of the first occurrence of $needle in the $haystack string.
241: * If $needle is not found, it returns false.
242: */
243: function mb_strpos($haystack, $needle, $offset = 0, $encoding = null) {
244: return Multibyte::strpos($haystack, $needle, $offset);
245: }
246:
247: }
248:
249: if (!function_exists('mb_strrchr')) {
250:
251: /**
252: * Finds the last occurrence of a character in a string within another.
253: *
254: * @param string $haystack The string from which to get the last occurrence of $needle.
255: * @param string $needle The string to find in $haystack.
256: * @param bool $part Determines which portion of $haystack this function returns.
257: * If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
258: * If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
259: * Default value is false.
260: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
261: * @return string|bool The portion of $haystack. or false if $needle is not found.
262: */
263: function mb_strrchr($haystack, $needle, $part = false, $encoding = null) {
264: return Multibyte::strrchr($haystack, $needle, $part);
265: }
266:
267: }
268:
269: if (!function_exists('mb_strrichr')) {
270:
271: /**
272: * Finds the last occurrence of a character in a string within another, case insensitive.
273: *
274: * @param string $haystack The string from which to get the last occurrence of $needle.
275: * @param string $needle The string to find in $haystack.
276: * @param bool $part Determines which portion of $haystack this function returns.
277: * If set to true, it returns all of $haystack from the beginning to the last occurrence of $needle.
278: * If set to false, it returns all of $haystack from the last occurrence of $needle to the end,
279: * Default value is false.
280: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
281: * @return string|bool The portion of $haystack. or false if $needle is not found.
282: */
283: function mb_strrichr($haystack, $needle, $part = false, $encoding = null) {
284: return Multibyte::strrichr($haystack, $needle, $part);
285: }
286:
287: }
288:
289: if (!function_exists('mb_strripos')) {
290:
291: /**
292: * Finds position of last occurrence of a string within another, case insensitive
293: *
294: * @param string $haystack The string from which to get the position of the last occurrence of $needle.
295: * @param string $needle The string to find in $haystack.
296: * @param int $offset The position in $haystack to start searching.
297: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
298: * @return int|bool The numeric position of the last occurrence of $needle in the $haystack string,
299: * or false if $needle is not found.
300: */
301: function mb_strripos($haystack, $needle, $offset = 0, $encoding = null) {
302: return Multibyte::strripos($haystack, $needle, $offset);
303: }
304:
305: }
306:
307: if (!function_exists('mb_strrpos')) {
308:
309: /**
310: * Find position of last occurrence of a string in a string.
311: *
312: * @param string $haystack The string being checked, for the last occurrence of $needle.
313: * @param string $needle The string to find in $haystack.
314: * @param int $offset May be specified to begin searching an arbitrary number of characters into the string.
315: * Negative values will stop searching at an arbitrary point prior to the end of the string.
316: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
317: * @return int|bool The numeric position of the last occurrence of $needle in the $haystack string.
318: * If $needle is not found, it returns false.
319: */
320: function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null) {
321: return Multibyte::strrpos($haystack, $needle, $offset);
322: }
323:
324: }
325:
326: if (!function_exists('mb_strstr')) {
327:
328: /**
329: * Finds first occurrence of a string within another
330: *
331: * @param string $haystack The string from which to get the first occurrence of $needle.
332: * @param string $needle The string to find in $haystack
333: * @param bool $part Determines which portion of $haystack this function returns.
334: * If set to true, it returns all of $haystack from the beginning to the first occurrence of $needle.
335: * If set to false, it returns all of $haystack from the first occurrence of $needle to the end,
336: * Default value is FALSE.
337: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
338: * @return string|bool The portion of $haystack, or true if $needle is not found.
339: */
340: function mb_strstr($haystack, $needle, $part = false, $encoding = null) {
341: return Multibyte::strstr($haystack, $needle, $part);
342: }
343:
344: }
345:
346: if (!function_exists('mb_strtolower')) {
347:
348: /**
349: * Make a string lowercase
350: *
351: * @param string $string The string being lowercased.
352: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
353: * @return string with all alphabetic characters converted to lowercase.
354: */
355: function mb_strtolower($string, $encoding = null) {
356: return Multibyte::strtolower($string);
357: }
358:
359: }
360:
361: if (!function_exists('mb_strtoupper')) {
362:
363: /**
364: * Make a string uppercase
365: *
366: * @param string $string The string being uppercased.
367: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
368: * @return string with all alphabetic characters converted to uppercase.
369: */
370: function mb_strtoupper($string, $encoding = null) {
371: return Multibyte::strtoupper($string);
372: }
373:
374: }
375:
376: if (!function_exists('mb_substr_count')) {
377:
378: /**
379: * Count the number of substring occurrences
380: *
381: * @param string $haystack The string being checked.
382: * @param string $needle The string being found.
383: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
384: * @return int The number of times the $needle substring occurs in the $haystack string.
385: */
386: function mb_substr_count($haystack, $needle, $encoding = null) {
387: return Multibyte::substrCount($haystack, $needle);
388: }
389:
390: }
391:
392: if (!function_exists('mb_substr')) {
393:
394: /**
395: * Get part of string
396: *
397: * @param string $string The string being checked.
398: * @param int $start The first position used in $string.
399: * @param int $length The maximum length of the returned string.
400: * @param string $encoding Character encoding name to use. If it is omitted, internal character encoding is used.
401: * @return string The portion of $string specified by the $string and $length parameters.
402: */
403: function mb_substr($string, $start, $length = null, $encoding = null) {
404: return Multibyte::substr($string, $start, $length);
405: }
406:
407: }
408:
409: if (!function_exists('mb_encode_mimeheader')) {
410:
411: /**
412: * Encode string for MIME header
413: *
414: * @param string $str The string being encoded
415: * @param string $charset specifies the name of the character set in which str is represented in.
416: * The default value is determined by the current NLS setting (mbstring.language).
417: * @param string $transferEncoding specifies the scheme of MIME encoding.
418: * It should be either "B" (Base64) or "Q" (Quoted-Printable). Falls back to "B" if not given.
419: * @param string $linefeed specifies the EOL (end-of-line) marker with which
420: * mb_encode_mimeheader() performs line-folding
421: * (a ยป RFC term, the act of breaking a line longer than a certain length into multiple lines.
422: * The length is currently hard-coded to 74 characters). Falls back to "\r\n" (CRLF) if not given.
423: * @param int $indent [definition unknown and appears to have no affect]
424: * @return string A converted version of the string represented in ASCII.
425: */
426: function mb_encode_mimeheader($str, $charset = 'UTF-8', $transferEncoding = 'B', $linefeed = "\r\n", $indent = 1) {
427: return Multibyte::mimeEncode($str, $charset, $linefeed);
428: }
429:
430: }
431:
432: Configure::bootstrap(isset($boot) ? $boot : true);
433:
434: if (function_exists('mb_internal_encoding')) {
435: $encoding = Configure::read('App.encoding');
436: if (!empty($encoding)) {
437: mb_internal_encoding($encoding);
438: }
439: if (!empty($encoding) && function_exists('mb_regex_encoding')) {
440: mb_regex_encoding($encoding);
441: }
442: }
443: