00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 define('SECOND', 1);
00033 define('MINUTE', 60 * SECOND);
00034 define('HOUR', 60 * MINUTE);
00035 define('DAY', 24 * HOUR);
00036 define('WEEK', 7 * DAY);
00037 define('MONTH', 30 * DAY);
00038 define('YEAR', 365 * DAY);
00039
00040
00041
00042 if (!function_exists("ob_get_clean")) {
00043 function ob_get_clean() {
00044 $ob_contents = ob_get_contents();
00045 ob_end_clean();
00046 return $ob_contents;
00047 }
00048 }
00049
00050
00051
00052 if (version_compare(phpversion(), '5.0') < 0) {
00053 eval ('
00054 function clone($object) {
00055 return $object;
00056 }');
00057 }
00058
00059
00060
00061
00062
00063
00064
00065 if (!function_exists('array_diff_key')) {
00066 function array_diff_key() {
00067 $valuesDiff = array();
00068
00069 if (func_num_args() < 2) {
00070 return false;
00071 }
00072
00073 foreach (func_get_args() as $param) {
00074 if (!is_array($param)) {
00075 return false;
00076 }
00077 }
00078
00079 $args = func_get_args();
00080 foreach ($args[0] as $valueKey => $valueData) {
00081 for ($i = 1; $i < func_num_args(); $i++) {
00082 if (isset($args[$i][$valueKey])) {
00083 continue 2;
00084 }
00085 }
00086 $valuesDiff[$valueKey] = $valueData;
00087 }
00088 return $valuesDiff;
00089 }
00090 }
00091
00092
00093
00094
00095
00096
00097
00098 if (!function_exists('array_intersect_key')) {
00099 function array_intersect_key($arr1, $arr2) {
00100 $res = array();
00101 foreach ($arr1 as $key=>$value) {
00102 if (array_key_exists($key, $arr2)) {
00103 $res[$key] = $arr1[$key];
00104 }
00105 }
00106 return $res;
00107 }
00108 }
00109
00110
00111
00112 function loadModels() {
00113 if (!class_exists('Model')) {
00114 require LIBS . 'model' . DS . 'model.php';
00115 }
00116 $path = Configure::getInstance();
00117 if (!class_exists('AppModel')) {
00118 if (file_exists(APP . 'app_model.php')) {
00119 require(APP . 'app_model.php');
00120 } else {
00121 require(CAKE . 'app_model.php');
00122 }
00123 if (phpversion() < 5 && function_exists("overload")) {
00124 overload('AppModel');
00125 }
00126 }
00127
00128 foreach ($path->modelPaths as $path) {
00129 foreach (listClasses($path)as $model_fn) {
00130 list($name) = explode('.', $model_fn);
00131 $className = Inflector::camelize($name);
00132
00133 if (!class_exists($className)) {
00134 require($path . $model_fn);
00135
00136 if (phpversion() < 5 && function_exists("overload")) {
00137 overload($className);
00138 }
00139 }
00140 }
00141 }
00142 }
00143
00144
00145
00146
00147
00148
00149 function loadPluginModels($plugin) {
00150 if (!class_exists('AppModel')) {
00151 loadModel();
00152 }
00153 $pluginAppModel = Inflector::camelize($plugin . '_app_model');
00154 $pluginAppModelFile = APP . 'plugins' . DS . $plugin . DS . $plugin . '_app_model.php';
00155 if (!class_exists($pluginAppModel)) {
00156 if (file_exists($pluginAppModelFile)) {
00157 require($pluginAppModelFile);
00158 } else {
00159 die('Plugins must have a class named ' . $pluginAppModel);
00160 }
00161 if (phpversion() < 5 && function_exists("overload")) {
00162 overload($pluginAppModel);
00163 }
00164 }
00165
00166 $pluginModelDir = APP . 'plugins' . DS . $plugin . DS . 'models' . DS;
00167
00168 foreach (listClasses($pluginModelDir)as $modelFileName) {
00169 list($name) = explode('.', $modelFileName);
00170 $className = Inflector::camelize($name);
00171
00172 if (!class_exists($className)) {
00173 require($pluginModelDir . $modelFileName);
00174
00175 if (phpversion() < 5 && function_exists("overload")) {
00176 overload($className);
00177 }
00178 }
00179 }
00180 }
00181
00182
00183
00184
00185 function loadView($viewClass) {
00186 if (!class_exists($viewClass . 'View')) {
00187 $paths = Configure::getInstance();
00188 $file = Inflector::underscore($viewClass) . '.php';
00189
00190 foreach ($paths->viewPaths as $path) {
00191 if (file_exists($path . $file)) {
00192 return require($path . $file);
00193 }
00194 }
00195
00196 if ($viewFile = fileExistsInPath(LIBS . 'view' . DS . $file)) {
00197 if (file_exists($viewFile)) {
00198 require($viewFile);
00199 return true;
00200 } else {
00201 return false;
00202 }
00203 }
00204 }
00205 }
00206
00207
00208
00209 function loadModel($name = null) {
00210 if (!class_exists('Model')) {
00211 require LIBS . 'model' . DS . 'model.php';
00212 }
00213 if (!class_exists('AppModel')) {
00214 if (file_exists(APP . 'app_model.php')) {
00215 require(APP . 'app_model.php');
00216 } else {
00217 require(CAKE . 'app_model.php');
00218 }
00219 if (phpversion() < 5 && function_exists("overload")) {
00220 overload('AppModel');
00221 }
00222 }
00223
00224 if (!is_null($name) && !class_exists($name)) {
00225 $className = $name;
00226 $name = Inflector::underscore($name);
00227 $paths = Configure::getInstance();
00228
00229 foreach ($paths->modelPaths as $path) {
00230 if (file_exists($path . $name . '.php')) {
00231 require($path . $name . '.php');
00232 if (phpversion() < 5 && function_exists("overload")) {
00233 overload($className);
00234 }
00235 return true;
00236 }
00237 }
00238 return false;
00239 } else {
00240 return true;
00241 }
00242 }
00243
00244
00245
00246 function loadControllers() {
00247 $paths = Configure::getInstance();
00248 if (!class_exists('AppController')) {
00249 if (file_exists(APP . 'app_controller.php')) {
00250 require(APP . 'app_controller.php');
00251 } else {
00252 require(CAKE . 'app_controller.php');
00253 }
00254 }
00255 $loadedControllers = array();
00256
00257 foreach ($paths->controllerPaths as $path) {
00258 foreach (listClasses($path) as $controller) {
00259 list($name) = explode('.', $controller);
00260 $className = Inflector::camelize(str_replace('_controller', '', $name));
00261
00262 if (loadController($className)) {
00263 $loadedControllers[$controller] = $className;
00264 }
00265 }
00266 }
00267 return $loadedControllers;
00268 }
00269
00270
00271
00272
00273
00274
00275 function loadController($name) {
00276 $paths = Configure::getInstance();
00277 if (!class_exists('AppController')) {
00278 if (file_exists(APP . 'app_controller.php')) {
00279 require(APP . 'app_controller.php');
00280 } else {
00281 require(CAKE . 'app_controller.php');
00282 }
00283 }
00284
00285 if ($name === null) {
00286 return true;
00287 }
00288
00289 if (!class_exists($name . 'Controller')) {
00290 $name = Inflector::underscore($name);
00291
00292 foreach ($paths->controllerPaths as $path) {
00293 if (file_exists($path . $name . '_controller.php')) {
00294 require($path . $name . '_controller.php');
00295 return true;
00296 }
00297 }
00298
00299 if ($controller_fn = fileExistsInPath(LIBS . 'controller' . DS . $name . '_controller.php')) {
00300 if (file_exists($controller_fn)) {
00301 require($controller_fn);
00302 return true;
00303 } else {
00304 return false;
00305 }
00306 }
00307 } else {
00308 return false;
00309 }
00310 }
00311
00312
00313
00314
00315
00316
00317
00318 function loadPluginController($plugin, $controller) {
00319 $pluginAppController = Inflector::camelize($plugin . '_app_controller');
00320 $pluginAppControllerFile = APP . 'plugins' . DS . $plugin . DS . $plugin . '_app_controller.php';
00321 if (!class_exists($pluginAppController)) {
00322 if (file_exists($pluginAppControllerFile)) {
00323 require($pluginAppControllerFile);
00324 } else {
00325 return false;
00326 }
00327 }
00328
00329 if (empty($controller)) {
00330 if (!class_exists($plugin . 'Controller')) {
00331 if (file_exists(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php')) {
00332 require(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php');
00333 return true;
00334 }
00335 }
00336 }
00337
00338 if (!class_exists($controller . 'Controller')) {
00339 $controller = Inflector::underscore($controller);
00340 $file = APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $controller . '_controller.php';
00341
00342 if (file_exists($file)) {
00343 require($file);
00344 return true;
00345 } elseif (!class_exists(Inflector::camelize($plugin . '_controller'))) {
00346 if (file_exists(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php')) {
00347 require(APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . $plugin . '_controller.php');
00348 return true;
00349 } else {
00350 return false;
00351 }
00352 }
00353 }
00354 return true;
00355 }
00356
00357
00358
00359
00360
00361
00362 function loadHelper($name) {
00363 $paths = Configure::getInstance();
00364
00365 if ($name === null) {
00366 return true;
00367 }
00368
00369 if (!class_exists($name . 'Helper')) {
00370 $name=Inflector::underscore($name);
00371
00372 foreach ($paths->helperPaths as $path) {
00373 if (file_exists($path . $name . '.php')) {
00374 require($path . $name . '.php');
00375 return true;
00376 }
00377 }
00378
00379 if ($helper_fn = fileExistsInPath(LIBS . 'view' . DS . 'helpers' . DS . $name . '.php')) {
00380 if (file_exists($helper_fn)) {
00381 require($helper_fn);
00382 return true;
00383 } else {
00384 return false;
00385 }
00386 }
00387 } else {
00388 return true;
00389 }
00390 }
00391
00392
00393
00394
00395
00396
00397
00398 function loadPluginHelper($plugin, $helper) {
00399 if (!class_exists($helper . 'Helper')) {
00400 $helper = Inflector::underscore($helper);
00401 $file = APP . 'plugins' . DS . $plugin . DS . 'views' . DS . 'helpers' . DS . $helper . '.php';
00402 if (file_exists($file)) {
00403 require($file);
00404 return true;
00405 } else {
00406 return false;
00407 }
00408 } else {
00409 return true;
00410 }
00411 }
00412
00413
00414
00415
00416
00417
00418 function loadComponent($name) {
00419 $paths = Configure::getInstance();
00420
00421 if ($name === null) {
00422 return true;
00423 }
00424
00425 if (!class_exists($name . 'Component')) {
00426 $name=Inflector::underscore($name);
00427
00428 foreach ($paths->componentPaths as $path) {
00429 if (file_exists($path . $name . '.php')) {
00430 require($path . $name . '.php');
00431 return true;
00432 }
00433 }
00434
00435 if ($component_fn = fileExistsInPath(LIBS . 'controller' . DS . 'components' . DS . $name . '.php')) {
00436 if (file_exists($component_fn)) {
00437 require($component_fn);
00438 return true;
00439 } else {
00440 return false;
00441 }
00442 }
00443 } else {
00444 return true;
00445 }
00446 }
00447
00448
00449
00450
00451
00452
00453
00454 function loadPluginComponent($plugin, $component) {
00455 if (!class_exists($component . 'Component')) {
00456 $component = Inflector::underscore($component);
00457 $file = APP . 'plugins' . DS . $plugin . DS . 'controllers' . DS . 'components' . DS . $component . '.php';
00458 if (file_exists($file)) {
00459 require($file);
00460 return true;
00461 } else {
00462 return false;
00463 }
00464 } else {
00465 return true;
00466 }
00467 }
00468
00469
00470
00471
00472
00473
00474 function listClasses($path) {
00475 $dir = opendir($path);
00476 $classes=array();
00477 while (false !== ($file = readdir($dir))) {
00478 if ((substr($file, -3, 3) == 'php') && substr($file, 0, 1) != '.') {
00479 $classes[] = $file;
00480 }
00481 }
00482 closedir($dir);
00483 return $classes;
00484 }
00485
00486
00487
00488
00489
00490 function config() {
00491 $args = func_get_args();
00492 foreach ($args as $arg) {
00493 if (('database' == $arg) && file_exists(CONFIGS . $arg . '.php')) {
00494 include_once(CONFIGS . $arg . '.php');
00495 } elseif (file_exists(CONFIGS . $arg . '.php')) {
00496 include_once(CONFIGS . $arg . '.php');
00497
00498 if (count($args) == 1) {
00499 return true;
00500 }
00501 } else {
00502 if (count($args) == 1) {
00503 return false;
00504 }
00505 }
00506 }
00507 return true;
00508 }
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519 function uses() {
00520 $args = func_get_args();
00521 foreach ($args as $arg) {
00522 require_once(LIBS . strtolower($arg) . '.php');
00523 }
00524 }
00525
00526
00527
00528
00529
00530
00531 function vendor($name) {
00532 $args = func_get_args();
00533 foreach ($args as $arg) {
00534 if (file_exists(APP . 'vendors' . DS . $arg . '.php')) {
00535 require_once(APP . 'vendors' . DS . $arg . '.php');
00536 } else {
00537 require_once(VENDORS . $arg . '.php');
00538 }
00539 }
00540 }
00541
00542
00543
00544
00545
00546
00547
00548
00549 function debug($var = false, $showHtml = false) {
00550 if (Configure::read() > 0) {
00551 print "\n<pre class=\"cake_debug\">\n";
00552 ob_start();
00553 print_r($var);
00554 $var = ob_get_clean();
00555
00556 if ($showHtml) {
00557 $var = str_replace('<', '<', str_replace('>', '>', $var));
00558 }
00559 print "{$var}\n</pre>\n";
00560 }
00561 }
00562
00563
00564
00565
00566
00567 if (!function_exists('getMicrotime')) {
00568 function getMicrotime() {
00569 list($usec, $sec) = explode(" ", microtime());
00570 return ((float)$usec + (float)$sec);
00571 }
00572 }
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582 if (!function_exists('sortByKey')) {
00583 function sortByKey(&$array, $sortby, $order = 'asc', $type = SORT_NUMERIC) {
00584 if (!is_array($array)) {
00585 return null;
00586 }
00587
00588 foreach ($array as $key => $val) {
00589 $sa[$key] = $val[$sortby];
00590 }
00591
00592 if ($order == 'asc') {
00593 asort($sa, $type);
00594 } else {
00595 arsort($sa, $type);
00596 }
00597
00598 foreach ($sa as $key => $val) {
00599 $out[] = $array[$key];
00600 }
00601 return $out;
00602 }
00603 }
00604
00605
00606
00607
00608
00609
00610
00611
00612 if (!function_exists('array_combine')) {
00613 function array_combine($a1, $a2) {
00614 $a1 = array_values($a1);
00615 $a2 = array_values($a2);
00616 $c1 = count($a1);
00617 $c2 = count($a2);
00618
00619 if ($c1 != $c2) {
00620 return false;
00621 }
00622 if ($c1 <= 0) {
00623 return false;
00624 }
00625
00626 $output=array();
00627 for ($i = 0; $i < $c1; $i++) {
00628 $output[$a1[$i]] = $a2[$i];
00629 }
00630 return $output;
00631 }
00632 }
00633
00634
00635
00636
00637
00638
00639 function h($text) {
00640 if (is_array($text)) {
00641 return array_map('h', $text);
00642 }
00643 return htmlspecialchars($text);
00644 }
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660 function a() {
00661 $args = func_get_args();
00662 return $args;
00663 }
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679 function aa() {
00680 $args = func_get_args();
00681 for ($l = 0, $c = count($args); $l < $c; $l++) {
00682 if ($l + 1 < count($args)) {
00683 $a[$args[$l]] = $args[$l + 1];
00684 } else {
00685 $a[$args[$l]] = null;
00686 }
00687 $l++;
00688 }
00689 return $a;
00690 }
00691
00692
00693
00694
00695
00696 function e($text) {
00697 echo $text;
00698 }
00699
00700
00701
00702
00703
00704 function low($str) {
00705 return strtolower($str);
00706 }
00707
00708
00709
00710
00711
00712 function up($str) {
00713 return strtoupper($str);
00714 }
00715
00716
00717
00718
00719
00720
00721
00722 function r($search, $replace, $subject) {
00723 return str_replace($search, $replace, $subject);
00724 }
00725
00726
00727
00728
00729
00730
00731
00732 function pr($var) {
00733 if (Configure::read() > 0) {
00734 echo "<pre>";
00735 print_r($var);
00736 echo "</pre>";
00737 }
00738 }
00739
00740
00741
00742
00743
00744
00745 function params($p) {
00746 if (!is_array($p) || count($p) == 0) {
00747 return null;
00748 } else {
00749 if (is_array($p[0]) && count($p) == 1) {
00750 return $p[0];
00751 } else {
00752 return $p;
00753 }
00754 }
00755 }
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765 function am() {
00766 $r = array();
00767 foreach (func_get_args()as $a) {
00768 if (!is_array($a)) {
00769 $a = array($a);
00770 }
00771 $r = array_merge($r, $a);
00772 }
00773 return $r;
00774 }
00775
00776
00777
00778
00779
00780
00781 function setUri() {
00782 if (env('HTTP_X_REWRITE_URL')) {
00783 $uri = env('HTTP_X_REWRITE_URL');
00784 } elseif (env('REQUEST_URI')) {
00785 $uri = env('REQUEST_URI');
00786 } else {
00787 if (env('argv')) {
00788 $uri = env('argv');
00789
00790 if (defined('SERVER_IIS')) {
00791 $uri = BASE_URL . $uri[0];
00792 } else {
00793 $uri = env('PHP_SELF') . '/' . $uri[0];
00794 }
00795 } else {
00796 $uri = env('PHP_SELF') . '/' . env('QUERY_STRING');
00797 }
00798 }
00799 return $uri;
00800 }
00801
00802
00803
00804
00805
00806
00807
00808 function env($key) {
00809
00810 if ($key == 'HTTPS') {
00811 if (isset($_SERVER) && !empty($_SERVER)) {
00812 return (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on');
00813 } else {
00814 return (strpos(env('SCRIPT_URI'), 'https:
00815 }
00816 }
00817
00818 if (isset($_SERVER[$key])) {
00819 return $_SERVER[$key];
00820 } elseif (isset($_ENV[$key])) {
00821 return $_ENV[$key];
00822 } elseif (getenv($key) !== false) {
00823 return getenv($key);
00824 }
00825
00826 if ($key == 'SCRIPT_FILENAME' && defined('SERVER_IIS') && SERVER_IIS === true) {
00827 return str_replace('\\\\', '\\', env('PATH_TRANSLATED') );
00828 }
00829
00830 if ($key == 'DOCUMENT_ROOT') {
00831 $offset = 0;
00832 if (!strpos(env('SCRIPT_NAME'), '.php')) {
00833 $offset = 4;
00834 }
00835 return substr(env('SCRIPT_FILENAME'), 0, strlen(env('SCRIPT_FILENAME')) - (strlen(env('SCRIPT_NAME')) + $offset));
00836 }
00837 if ($key == 'PHP_SELF') {
00838 return r(env('DOCUMENT_ROOT'), '', env('SCRIPT_FILENAME'));
00839 }
00840 return null;
00841 }
00842
00843
00844
00845
00846
00847
00848
00849 if (!function_exists('file_get_contents')) {
00850 function file_get_contents($fileName, $useIncludePath = false) {
00851 $res=fopen($fileName, 'rb', $useIncludePath);
00852
00853 if ($res === false) {
00854 trigger_error('file_get_contents() failed to open stream: No such file or directory', E_USER_WARNING);
00855 return false;
00856 }
00857 clearstatcache();
00858
00859 if ($fileSize = @filesize($fileName)) {
00860 $data = fread($res, $fileSize);
00861 } else {
00862 $data = '';
00863
00864 while (!feof($res)) {
00865 $data .= fread($res, 8192);
00866 }
00867 }
00868 return "$data\n";
00869 }
00870 }
00871
00872
00873
00874
00875
00876
00877
00878
00879 if (!function_exists('file_put_contents')) {
00880 function file_put_contents($fileName, $data) {
00881 if (is_array($data)) {
00882 $data = join('', $data);
00883 }
00884 $res = @fopen($fileName, 'w+b');
00885 if ($res) {
00886 $write = @fwrite($res, $data);
00887 if ($write === false) {
00888 return false;
00889 } else {
00890 return $write;
00891 }
00892 }
00893 }
00894 }
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904 function cache($path, $data = null, $expires = '+1 day', $target = 'cache') {
00905 $now = time();
00906 if (!is_numeric($expires)) {
00907 $expires = strtotime($expires, $now);
00908 }
00909
00910 switch(strtolower($target)) {
00911 case 'cache':
00912 $filename = CACHE . $path;
00913 break;
00914 case 'public':
00915 $filename = WWW_ROOT . $path;
00916 break;
00917 }
00918
00919 $timediff = $expires - $now;
00920 $filetime = false;
00921 if (file_exists($filename)) {
00922 $filetime = @filemtime($filename);
00923 }
00924
00925 if ($data === null) {
00926
00927 if (file_exists($filename) && $filetime !== false) {
00928 if ($filetime + $timediff < $now) {
00929
00930 @unlink($filename);
00931 } else {
00932 $data = file_get_contents($filename);
00933 }
00934 }
00935 } else {
00936 file_put_contents($filename, $data);
00937 }
00938 return $data;
00939 }
00940
00941
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951 function clearCache($params = null, $type = 'views', $ext = '.php') {
00952 if (is_string($params) || $params === null) {
00953 $params = preg_replace('/\/\
00954 $cache = CACHE . $type . DS . $params;
00955
00956 if (is_file($cache . $ext)) {
00957 @unlink($cache . $ext);
00958 return true;
00959 } elseif (is_dir($cache)) {
00960 $files = glob("$cache*");
00961
00962 if ($files === false) {
00963 return false;
00964 }
00965
00966 foreach ($files as $file) {
00967 if (is_file($file)) {
00968 @unlink($file);
00969 }
00970 }
00971 return true;
00972 } else {
00973 $cache = CACHE . $type . DS . '*' . $params . $ext;
00974 $files = glob($cache);
00975
00976 $cache = CACHE . $type . DS . '*' . $params . '_*' . $ext;
00977 $files = array_merge($files, glob($cache));
00978
00979 if ($files === false) {
00980 return false;
00981 }
00982
00983 foreach ($files as $file) {
00984 if (is_file($file)) {
00985 @unlink($file);
00986 }
00987 }
00988 return true;
00989 }
00990 } elseif (is_array($params)) {
00991 foreach ($params as $key => $file) {
00992 clearCache($file, $type, $ext);
00993 }
00994 return true;
00995 }
00996 return false;
00997 }
00998
00999
01000
01001
01002
01003
01004 function stripslashes_deep($value) {
01005 if (is_array($value)) {
01006 $return = array_map('stripslashes_deep', $value);
01007 return $return;
01008 } else {
01009 $return = stripslashes($value);
01010 return $return ;
01011 }
01012 }
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022 function __($msg, $return = null) {
01023 if (is_null($return)) {
01024 echo($msg);
01025 } else {
01026 return $msg;
01027 }
01028 }
01029
01030
01031
01032
01033
01034
01035 function countdim($array) {
01036 if (is_array(reset($array))) {
01037 $return = countdim(reset($array)) + 1;
01038 } else {
01039 $return = 1;
01040 }
01041 return $return;
01042 }
01043
01044
01045
01046 function LogError($message) {
01047 if (!class_exists('CakeLog')) {
01048 uses('cake_log');
01049 }
01050 $bad = array("\n", "\r", "\t");
01051 $good = ' ';
01052 CakeLog::write('error', str_replace($bad, $good, $message));
01053 }
01054
01055
01056
01057
01058
01059
01060 function fileExistsInPath($file) {
01061 $paths = explode(PATH_SEPARATOR, ini_get('include_path'));
01062 foreach ($paths as $path) {
01063 $fullPath = $path . DIRECTORY_SEPARATOR . $file;
01064
01065 if (file_exists($fullPath)) {
01066 return $fullPath;
01067 } elseif (file_exists($file)) {
01068 return $file;
01069 }
01070 }
01071 return false;
01072 }
01073
01074
01075
01076
01077
01078
01079 function convertSlash($string) {
01080 $string = trim($string,"/");
01081 $string = preg_replace('/\/\
01082 $string = str_replace('/', '_', $string);
01083 return $string;
01084 }
01085
01086
01087
01088
01089
01090
01091
01092
01093 function chmodr($path, $mode = 0755) {
01094 if (!is_dir($path)) {
01095 return chmod($path, $mode);
01096 }
01097 $dir = opendir($path);
01098
01099 while ($file = readdir($dir)) {
01100 if ($file != '.' && $file != '..') {
01101 $fullpath = $path . '/' . $file;
01102
01103 if (!is_dir($fullpath)) {
01104 if (!chmod($fullpath, $mode)) {
01105 return false;
01106 }
01107 } else {
01108 if (!chmodr($fullpath, $mode)) {
01109 return false;
01110 }
01111 }
01112 }
01113 }
01114 closedir($dir);
01115
01116 if (chmod($path, $mode)) {
01117 return true;
01118 } else {
01119 return false;
01120 }
01121 }
01122
01123
01124
01125
01126
01127
01128
01129 function strip_plugin($base, $plugin) {
01130 if ($plugin != null) {
01131 $base = preg_replace('/' . $plugin . '/', '', $base);
01132 $base = str_replace('
01133 $pos1 = strrpos($base, '/');
01134 $char = strlen($base) - 1;
01135
01136 if ($pos1 == $char) {
01137 $base = substr($base, 0, $char);
01138 }
01139 }
01140 return $base;
01141 }
01142
01143
01144
01145
01146
01147
01148
01149
01150 function ife($condition, $val1 = null, $val2 = null) {
01151 if (!empty($condition)) {
01152 return $val1;
01153 }
01154 return $val2;
01155 }
01156 ?>