bootstrap.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <?php
  2. define('FORMAT_DB_DATETIME', 'Y-m-d H:i:s');
  3. define('FORMAT_DB_DATE', 'Y-m-d');
  4. define('FORMAT_DB_TIME', 'H:i:s');
  5. if (!defined('FORMAT_NICE_YMDHMS')) {
  6. define('FORMAT_NICE_YMDHMS', 'd.m.Y, H:i:s');
  7. define('FORMAT_NICE_YMDHM', 'd.m.Y, H:i');
  8. define('FORMAT_NICE_YM', 'm.Y');
  9. define('FORMAT_NICE_YMD', 'd.m.Y');
  10. define('FORMAT_NICE_MD', 'd.m.');
  11. define('FORMAT_NICE_D', 'd'); # xx
  12. define('FORMAT_NICE_W_NUM', 'w'); # xx (0=sunday to 6=saturday)
  13. define('FORMAT_NICE_W_ABBR', 'D'); # needs manual translation
  14. define('FORMAT_NICE_W_FULL', 'l'); # needs manual translation
  15. define('FORMAT_NICE_M', 'm'); # xx
  16. define('FORMAT_NICE_M_ABBR', 'M'); # needs manual translation
  17. define('FORMAT_NICE_M_FULL', 'F'); # needs manual translation
  18. define('FORMAT_NICE_Y_ABBR', 'y'); # xx
  19. define('FORMAT_NICE_Y', 'Y'); # xxxx
  20. define('FORMAT_NICE_HM', 'H:i');
  21. define('FORMAT_NICE_HMS', 'H:i:s');
  22. // localDate strings
  23. define('FORMAT_LOCAL_WA_YMDHMS', '%a, %d.%m.%Y, %H:%M:%S');
  24. define('FORMAT_LOCAL_WF_YMDHMS', '%A, %d.%m.%Y, %H:%M:%S');
  25. define('FORMAT_LOCAL_WA_YMDHM', '%a, %d.%m.%Y, %H:%M');
  26. define('FORMAT_LOCAL_WF_YMDHM', '%A, %d.%m.%Y, %H:%M');
  27. define('FORMAT_LOCAL_YMDHMS', '%d.%m.%Y, %H:%M:%S');
  28. define('FORMAT_LOCAL_YMDHM', '%d.%m.%Y, %H:%M');
  29. define('FORMAT_LOCAL_YMD', '%d.%m.%Y');
  30. define('FORMAT_LOCAL_MD', '%d.%m.');
  31. define('FORMAT_LOCAL_D', '%d'); # xx
  32. define('FORMAT_LOCAL_W_NUM', '%w'); # xx (0=sunday to 6=saturday)
  33. define('FORMAT_LOCAL_W_ABBR', '%a'); # needs translation
  34. define('FORMAT_LOCAL_W_FULL', '%A'); # needs translation
  35. define('FORMAT_LOCAL_M', '%m'); # xx
  36. define('FORMAT_LOCAL_M_ABBR', '%b'); # needs translation
  37. define('FORMAT_LOCAL_M_FULL', '%B'); # needs translation
  38. define('FORMAT_LOCAL_Y_ABBR', '%y'); # xx
  39. define('FORMAT_LOCAL_YMS_ABBR', '%d.%m.%y');
  40. define('FORMAT_LOCAL_Y', '%Y'); # xxxx
  41. define('FORMAT_LOCAL_H', '%H');
  42. define('FORMAT_LOCAL_S', '%S');
  43. define('FORMAT_LOCAL_HM', '%H:%M');
  44. define('FORMAT_LOCAL_HMS', '%H:%M:%S');
  45. }
  46. // Make the app and L10n play nice with Windows.
  47. if (!defined('WINDOWS')) {
  48. if (DS === '\\' || substr(PHP_OS, 0, 3) === 'WIN') {
  49. define('WINDOWS', true);
  50. } else {
  51. define('WINDOWS', false);
  52. }
  53. }
  54. /**
  55. * Convenience function to check on "empty()"
  56. *
  57. * @param mixed $var
  58. * @return bool Result
  59. */
  60. if (!function_exists('isEmpty')) {
  61. function isEmpty($var = null) {
  62. if (empty($var)) {
  63. return true;
  64. }
  65. return false;
  66. }
  67. }
  68. /**
  69. * Returns of what type the specific value is
  70. *
  71. * //TODO: use Debugger::exportVar() instead?
  72. *
  73. * @param mixed $value
  74. * @return mixed Type (NULL, array, bool, float, int, string, object, unknown) + value
  75. */
  76. if (!function_exists('returns')) {
  77. function returns($value)
  78. {
  79. if ( $value === null ) {
  80. return 'NULL';
  81. }
  82. if ( is_array($value) ) {
  83. return '(array)' . '<pre>' . print_r($value, true) . '</pre>';
  84. }
  85. if ( $value === true ) {
  86. return '(bool)TRUE';
  87. }
  88. if ( $value === false ) {
  89. return '(bool)FALSE';
  90. }
  91. if ( is_numeric($value) && is_float($value) ) {
  92. return '(float)' . $value;
  93. }
  94. if ( is_numeric($value) && is_int($value) ) {
  95. return '(int)' . $value;
  96. }
  97. if ( is_string($value) ) {
  98. return '(string)' . $value;
  99. }
  100. if ( is_object($value) ) {
  101. return '(object)' . get_class($value) . '<pre>' . print_r($value, true) .
  102. '</pre>';
  103. }
  104. return '(unknown)' . $value;
  105. }
  106. }
  107. /**
  108. * Returns htmlentities - string
  109. *
  110. * ENT_COMPAT = Will convert double-quotes and leave single-quotes alone.
  111. * ENT_QUOTES = Will convert both double and single quotes. !!!
  112. * ENT_NOQUOTES = Will leave both double and single quotes unconverted.
  113. *
  114. * @param string $text
  115. * @return string Converted text
  116. */
  117. if (!function_exists('ent')) {
  118. function ent($text)
  119. {
  120. return ! empty($text) ? htmlentities($text, ENT_QUOTES, 'UTF-8') : '';
  121. }
  122. }
  123. /**
  124. * Convenience method for htmlspecialchars_decode
  125. *
  126. * @param string $text Text to wrap through htmlspecialchars_decode
  127. * @param int $quoteStyle
  128. * @return string Converted text
  129. */
  130. if (!function_exists('hDec')) {
  131. function hDec($text, $quoteStyle = ENT_QUOTES)
  132. {
  133. if ( is_array($text) ) {
  134. return array_map('hDec', $text);
  135. }
  136. return trim(htmlspecialchars_decode($text, $quoteStyle));
  137. }
  138. }
  139. /**
  140. * Convenience method for html_entity_decode
  141. *
  142. * @param string $text Text to wrap through htmlspecialchars_decode
  143. * @param int $quoteStyle
  144. * @return string Converted text
  145. */
  146. if (!function_exists('entDec')) {
  147. function entDec($text, $quoteStyle = ENT_QUOTES)
  148. {
  149. if ( is_array($text) ) {
  150. return array_map('entDec', $text);
  151. }
  152. return ! empty($text) ? trim(html_entity_decode($text, $quoteStyle, 'UTF-8')) : '';
  153. }
  154. }
  155. /**
  156. * Focus is on the filename (without path)
  157. *
  158. * @deprecated Use native method instead
  159. *
  160. * @param string $filename to check on
  161. * @param string|null $type (extension/ext, filename/file, basename/base, dirname/dir)
  162. * @return mixed
  163. */
  164. if (!function_exists('extractFileInfo')) {
  165. function extractFileInfo($filename, $type = null)
  166. {
  167. $info = extractPathInfo($filename, $type);
  168. if ( $info ) {
  169. return $info;
  170. }
  171. $pos = strrpos($filename, '.');
  172. $res = '';
  173. switch ($type) {
  174. case 'extension':
  175. case 'ext':
  176. $res = ($pos !== false) ? substr($filename, $pos + 1) : '';
  177. break;
  178. case 'filename':
  179. case 'file':
  180. $res = ($pos !== false) ? substr($filename, 0, $pos) : '';
  181. break;
  182. default:
  183. break;
  184. }
  185. return $res;
  186. }
  187. }
  188. /**
  189. * Uses native PHP function to retrieve infos about a filename etc.
  190. * Improves it by not returning non-file-name characters from url files if specified.
  191. * So "filename.ext?foo=bar#hash" would simply be "filename.ext" then.
  192. *
  193. * @deprecated Use native method instead
  194. *
  195. * @param string $filename to check on
  196. * @param string|null $type (extension/ext, filename/file, basename/base, dirname/dir)
  197. * @param bool $fromUrl
  198. * @return mixed
  199. */
  200. if (!function_exists('extractPathInfo')) {
  201. function extractPathInfo($filename, $type = null, $fromUrl = false)
  202. {
  203. switch ($type) {
  204. case 'extension':
  205. case 'ext':
  206. $infoType = PATHINFO_EXTENSION;
  207. break;
  208. case 'filename':
  209. case 'file':
  210. $infoType = PATHINFO_FILENAME;
  211. break;
  212. case 'basename':
  213. case 'base':
  214. $infoType = PATHINFO_BASENAME;
  215. break;
  216. case 'dirname':
  217. case 'dir':
  218. $infoType = PATHINFO_DIRNAME;
  219. break;
  220. default:
  221. $infoType = $type;
  222. }
  223. $result = pathinfo($filename, $infoType);
  224. if ( $fromUrl ) {
  225. if ( ($pos = strpos($result, '#')) !== false ) {
  226. $result = substr($result, 0, $pos);
  227. }
  228. if ( ($pos = strpos($result, '?')) !== false ) {
  229. $result = substr($result, 0, $pos);
  230. }
  231. }
  232. return $result;
  233. }
  234. }
  235. /**
  236. * Shows pr() messages, even with debug = 0.
  237. * Also allows additional customization.
  238. *
  239. * @param mixed $var
  240. * @param bool $collapsedAndExpandable
  241. * @param array $options
  242. * - class, showHtml, showFrom, jquery, returns, debug
  243. * @return string HTML
  244. */
  245. if (!function_exists('pre')) {
  246. function pre($var, $collapsedAndExpandable = false, $options = [])
  247. {
  248. $defaults = [
  249. 'class' => 'cake-debug',
  250. 'showHtml' => false, // Escape < and > (or manually escape with h() prior to calling this function)
  251. 'showFrom' => false, // Display file + line
  252. 'jquery' => null, // null => Auto - use jQuery (true/false to manually decide),
  253. 'debug' => false, // Show only with debug > 0
  254. ];
  255. $options += $defaults;
  256. if ( $options['debug'] && ! Configure::read('debug') ) {
  257. return '';
  258. }
  259. if ( PHP_SAPI === 'cli' ) {
  260. return sprintf("\n%s\n", print_r($var, true));
  261. }
  262. $res = '<div class="' . $options['class'] . '">';
  263. $pre = '';
  264. if ( $collapsedAndExpandable ) {
  265. $js = 'if (this.parentNode.getElementsByTagName(\'pre\')[0].style.display==\'block\') {this.parentNode.getElementsByTagName(\'pre\')[0].style.display=\'none\'} else {this.parentNode.getElementsByTagName(\'pre\')[0].style.display=\'block\'}';
  266. $jsJquery = 'jQuery(this).parent().children(\'pre\').slideToggle(\'fast\')';
  267. if ( $options['jquery'] === true ) {
  268. $js = $jsJquery;
  269. } elseif ( $options['jquery'] !== false ) {
  270. // auto
  271. $js = 'if (typeof jQuery == \'undefined\') {' . $js . '} else {' . $jsJquery . '}';
  272. }
  273. $res .= '<span onclick="' . $js . '" style="cursor: pointer; font-weight: bold">Debug</span>';
  274. if ( $options['showFrom'] ) {
  275. $calledFrom = debug_backtrace();
  276. $from = '<em>' . substr(str_replace(ROOT, '', $calledFrom[0]['file']), 1) . '</em>';
  277. $from .= ' (line <em>' . $calledFrom[0]['line'] . '</em>)';
  278. $res .= '<div>' . $from . '</div>';
  279. }
  280. $pre = ' style="display: none"';
  281. }
  282. $var = print_r($var, true);
  283. if ( ! $options['showHtml'] ) {
  284. $var = h($var);
  285. }
  286. $res .= '<pre' . $pre . '>' . $var . '</pre>';
  287. $res .= '</div>';
  288. return $res;
  289. }
  290. }
  291. /**
  292. * Checks if the string [$haystack] contains [$needle]
  293. *
  294. * @param string $haystack Input string.
  295. * @param string $needle Needed char or string.
  296. * @param bool $caseSensitive
  297. * @return bool
  298. */
  299. if (!function_exists('contains')) {
  300. function contains($haystack, $needle, $caseSensitive = false)
  301. {
  302. $result = ! $caseSensitive ? stripos($haystack, $needle) : strpos($haystack, $needle);
  303. return $result !== false;
  304. }
  305. }
  306. /**
  307. * Checks if the string [$haystack] starts with [$needle]
  308. *
  309. * @param string $haystack Input string.
  310. * @param string $needle Needed char or string.
  311. * @param bool $caseSensitive
  312. * @return bool
  313. */
  314. if (!function_exists('startsWith')) {
  315. function startsWith($haystack, $needle, $caseSensitive = false)
  316. {
  317. if ( $caseSensitive ) {
  318. return mb_strpos($haystack, $needle) === 0;
  319. }
  320. return mb_stripos($haystack, $needle) === 0;
  321. }
  322. }
  323. /**
  324. * Checks if the String [$haystack] ends with [$needle]
  325. *
  326. * @param string $haystack Input string.
  327. * @param string $needle Needed char or string
  328. * @param bool $caseSensitive
  329. * @return bool
  330. */
  331. if (!function_exists('endsWith')) {
  332. function endsWith($haystack, $needle, $caseSensitive = false)
  333. {
  334. if ( $caseSensitive ) {
  335. return mb_strrpos($haystack, $needle) === mb_strlen($haystack) - mb_strlen($needle);
  336. }
  337. return mb_strripos($haystack, $needle) === mb_strlen($haystack) - mb_strlen($needle);
  338. }
  339. }