Base for a static organization website

bootstrap.php 14KB

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