예제 #1
0
파일: cjax_config.php 프로젝트: glensc/cjax
 /**
  * get an instance of CJAX
  * with singleton pattern 
  * @return CJAX_FRAMEWORK OBJECT
  */
 public static function getInstance()
 {
     if (self::$CJAX) {
         return self::$CJAX;
     }
     CoreEvents::errorHandlingConfig();
     $ajax = new CJAX_FRAMEWORK();
     if (!defined('JSON_FORCE_OBJECT')) {
         define('JSON_FORCE_OBJECT', 16);
     }
     if (!isset($ajax->format) || !$ajax->format) {
         $ajax->format = new cjaxFormat();
         $config = new ext();
         if (file_exists($f = CJAX_HOME . '/' . 'config.php')) {
             include $f;
             if (isset($config)) {
                 $config = new ext($config);
             }
         }
         $ajax->config = $config;
         $ajax->initiate($ajax);
         if (!$ajax->isAjaxRequest()) {
             //$ajax->flushCache();
             if (defined('AJAX_CD')) {
                 @setcookie('AJAX_CD', AJAX_CD, null, '/');
             } else {
                 //@setcookie ('AJAX_CD', null, time()-(3600*1000),'/');
             }
         } else {
             if (isset($_COOKIE['AJAX_CD']) && !defined('AJAX_CD')) {
                 define('AJAX_CD', $_COOKIE['AJAX_CD']);
             }
             if (!function_exists('cleanInput')) {
                 function cleanInput($input)
                 {
                     return $input;
                 }
             }
         }
     }
     if ($ajax->config->camelize === null) {
         if (version_compare($ajax->version, '>', '5.0-RC2')) {
             $ajax->config->camelize = true;
         }
     }
     if ($ajax->config->ip_debug) {
         if (is_array($ajax->config->ip_debug)) {
             if (in_array(@$_SERVER['REMOTE_ADDR'], $ajax->config->ip_debug)) {
                 $ajax->config->ip_debug = false;
             }
         } else {
             if (@$_SERVER['REMOTE_ADDR'] != $ajax->config->ip_debug) {
                 $ajax->config->ip_debug = false;
             }
         }
     }
     if ($ajax->config->caching) {
         if (isset($_SERVER['REQUEST_URI'])) {
             $ajax->crc32 = crc32($_SERVER['REQUEST_URI']);
             $cache = $ajax->readCache('cjax-' . $ajax->crc32);
             $ajax->caching = $cache;
         }
     }
     if ($ajax->config->debug) {
         @ini_set('display_errors', 1);
         @ini_set('log_errors', 1);
     }
     if (!($js_dir = $ajax->config->js_path)) {
         if (@is_dir('cjax/')) {
             $js_dir = "cjax/core/js/";
         } else {
             if (@is_dir('core/js/')) {
                 $js_dir = "core/js/";
             } else {
                 if (@is_dir('../cjax')) {
                     $js_dir = "../cjax/core/js/";
                 } else {
                     if (@is_dir('../../cjax')) {
                         $js_dir = "../../cjax/core/js/";
                     } else {
                         if (@is_dir('../../../cjax')) {
                             $js_dir = "../../../cjax/core/js/";
                         } else {
                             die("Cannot find the correct path to Js directory.");
                         }
                     }
                 }
             }
         }
         $error = error_get_last();
         if ($error && preg_match('%.*(open_basedir).*File\\(([^\\)]+)%', $error['message'], $match)) {
             die(sprintf('Restriction <b>open_basedir</b> is turned on. File or directory %s will not be accessible while this setting is on due to security directory range.', $match[2]));
         }
     }
     $ajax->js($js_dir);
     return self::$CJAX = $ajax;
 }