isAjax() публичный Метод

returns true if the page has been requested via a browser XMLHTTPRequest (AJAX call)
public isAjax ( )
Пример #1
0
 public static function preInit($baseDir)
 {
     //	Remove quotes added by magic_quotes
     if (get_magic_quotes_gpc()) {
         $process = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
         while (list($key, $val) = each($process)) {
             foreach ($val as $k => $v) {
                 unset($process[$key][$k]);
                 if (is_array($v)) {
                     $process[$key][stripslashes($k)] = $v;
                     $process[] =& $process[$key][stripslashes($k)];
                 } else {
                     $process[$key][stripslashes($k)] = stripslashes($v);
                 }
             }
         }
         unset($process);
     }
     self::$_baseDir = $baseDir;
     self::$_config = array();
     self::$_auth = null;
     self::$_escaping = false;
     require_once self::$_baseDir . 'classes/Pommo_Log.php';
     require_once self::$_baseDir . 'lib/SafeSQL.class.php';
     require_once self::$_baseDir . 'classes/Pommo_Db.php';
     require_once self::$_baseDir . 'classes/Pommo_Auth.php';
     // 	initialize logger
     //	Check where this config variable comes from
     self::$_logger = new Pommo_Log();
     self::$_workDir = empty($config['workDir']) ? self::$_baseDir . 'cache' : $config['workDir'];
     self::$_debug = strtolower($config['debug']) != 'on' ? false : true;
     self::$_default_subscriber_sort = empty($config['default_subscriber_sort']) ? 'email' : $config['default_subscriber_sort'];
     self::$_verbosity = empty($config['verbosity']) ? 3 : $config['verbosity'];
     self::$_logger->_verbosity = self::$_verbosity;
     self::$_dateformat = $config['date_format'] >= 1 && $cofig['date_format'] <= 3 ? intval($config['date_format']) : 1;
     //	set base URL (e.g. http://mysite.com/news/pommo => 'news/pommo/')
     if (isset($config['baseURL'])) {
         self::$_baseUrl = $config['baseURL'];
     } else {
         // 	If we're called from an embedded script, read baseURL from
         //	"last known good". Else, set it based off of REQUEST.
         if (defined('_poMMo_embed')) {
             require_once self::$_baseDir . 'classes/Pommo_Helper_Maintenance.php';
             self::$_baseUrl = Pommo_Helper_Maintenance::rememberBaseURL();
         } else {
             $regex = '@/(ajax|inc|setup|user|install|support(/tests|/util)?|' . 'admin(/subscribers|/user|/mailings|/setup)?' . '(/ajax|/mailing|/config)?)$@i';
             // This is to fix backslashes on windows systems
             $dirname = str_replace('\\', '/', dirname($_SERVER['PHP_SELF']));
             $baseUrl = preg_replace($regex, '', $dirname);
             self::$_baseUrl = $baseUrl == '/' ? $baseUrl : $baseUrl . '/';
         }
     }
     // read in config.php (configured by user)
     $config = Pommo_Helper::parseConfig(self::$_baseDir . 'config.php');
     //	check to see if config.php was "properly" loaded
     if (count($config) < 5) {
         self::$_hasConfigFile = false;
         return self::$_hasConfigFile;
     }
     self::$_hasConfigFile = true;
     //	the regex strips port info from hostname
     self::$_hostname = empty($config['hostname']) ? preg_replace('/:\\d+$/i', '', $_SERVER['HTTP_HOST']) : $config['hostname'];
     self::$_hostport = empty($config['hostport']) ? $_SERVER['SERVER_PORT'] : $config['hostport'];
     self::$_ssl = !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ? false : true;
     self::$_http = (self::$_ssl ? 'https://' : 'http://') . self::$_hostname;
     if (self::$_hostport != 80 && self::$_hostport != 443) {
         self::$_http .= ':' . self::$_hostport;
     }
     self::$_language = empty($config['lang']) ? 'en' : strtolower($config['lang']);
     self::$_slanguage = defined('_poMMo_lang') ? _poMMo_lang : false;
     //	include translation (l10n) methods if language is not English
     self::$_l10n = FALSE;
     if (self::$_language != 'en') {
         self::$_l10n = TRUE;
         require_once self::$_baseDir . 'classes/Pommo_Helper_L10n.php';
         Pommo_Helper_L10n::init(self::$_language, self::$_baseDir);
     }
     //	set the current "section" -- should be "user" for /user/* files,
     //	"mailings" for /admin/mailings/* files, etc. etc.
     self::$_section = preg_replace('@^admin/?@i', '', str_replace(self::$_baseUrl, '', dirname($_SERVER['PHP_SELF'])));
     $db_conn_compress = strtolower($config['db_conn_compress']) != 'on' ? 0 : MYSQL_CLIENT_COMPRESS;
     $db_conn_secure = strtolower($config['db_conn_secure']) != 'on' ? 0 : MYSQL_CLIENT_SSL;
     // 	initialize database link
     self::$_dbo = @new Pommo_Db($config['db_username'], $config['db_password'], $config['db_database'], $config['db_hostname'], $config['db_prefix'], $db_conn_compress, $db_conn_secure);
     // 	turn off debugging if in user area
     if (self::$_section == 'user') {
         self::$_debug = false;
         self::$_dbo->debug(FALSE);
     }
     // if debugging is set in config.php, enable debugging on the database.
     if (self::$_debug) {
         // don't enable debugging in ajax requests unless verbosity is < 3
         if (Pommo_Helper::isAjax() && self::$_verbosity > 2) {
             self::$_debug = false;
         } else {
             self::$_dbo->debug(TRUE);
         }
     }
     return true;
 }
Пример #2
0
    public static function preInit($baseDir)
    {
        self::$_baseDir = $baseDir;
        self::$_config = array();
        self::$_auth = null;
        self::$_escaping = false;
        require_once self::$_baseDir . 'classes/Pommo_Log.php';
        require_once self::$_baseDir . 'lib/SafeSQL.class.php';
        require_once self::$_baseDir . 'classes/Pommo_Db.php';
        require_once self::$_baseDir . 'classes/Pommo_Auth.php';
        // 	initialize logger
        //	Check where this config variable comes from
        self::$_logger = new Pommo_Log();
        self::$_workDir = empty($config['workDir']) ? self::$_baseDir . 'cache' : $config['workDir'];
        self::$_debug = strtolower($config['debug']) != 'on' ? false : true;
        self::$_default_subscriber_sort = empty($config['default_subscriber_sort']) ? 'email' : $config['default_subscriber_sort'];
        self::$_verbosity = empty($config['verbosity']) ? 3 : $config['verbosity'];
        self::$_logger->_verbosity = self::$_verbosity;
        self::$_dateformat = $config['date_format'] >= 1 && $cofig['date_format'] <= 3 ? intval($config['date_format']) : 1;
        //	set base URL (e.g. http://mysite.com/news/pommo => 'news/pommo/')
        if (isset($config['baseURL'])) {
            self::$_baseUrl = $config['baseURL'];
        } else {
            // 	If we're called from an embedded script, read baseURL from
            //	"last known good". Else, set it based off of REQUEST.
            if (defined('_poMMo_embed')) {
                require_once self::$_baseDir . 'classes/Pommo_Helper_Maintenance.php';
                self::$_baseUrl = Pommo_Helper_Maintenance::rememberBaseURL();
            } else {
                $regex = '@/(ajax|inc|setup|user|install|support(/tests|/util)?|' . 'admin(/subscribers|/user|/mailings|/setup)?' . '(/ajax|/mailing|/config)?)$@i';
                $baseUrl = preg_replace($regex, '', dirname($_SERVER['PHP_SELF']));
                self::$_baseUrl = $baseUrl == '/' ? $baseUrl : $baseUrl . '/';
            }
        }
        // read in config.php (configured by user)
        $config = Pommo_Helper::parseConfig(self::$_baseDir . 'config.php');
        //	check to see if config.php was "properly" loaded
        if (count($config) < 5) {
            self::$_hasConfigFile = false;
            return self::$_hasConfigFile;
        }
        self::$_hasConfigFile = true;
        //	the regex strips port info from hostname
        self::$_hostname = empty($config['hostname']) ? preg_replace('/:\\d+$/i', '', $_SERVER['HTTP_HOST']) : $config['hostname'];
        self::$_hostport = empty($config['hostport']) ? $_SERVER['SERVER_PORT'] : $config['hostport'];
        self::$_ssl = !isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) != 'on' ? false : true;
        self::$_http = (self::$_ssl ? 'https://' : 'http://') . self::$_hostname;
        if (self::$_hostport != 80 && self::$_hostport != 443) {
            self::$_http .= ':' . self::$_hostport;
        }
        self::$_language = empty($config['lang']) ? 'en' : strtolower($config['lang']);
        self::$_slanguage = defined('_poMMo_lang') ? _poMMo_lang : false;
        //	include translation (l10n) methods if language is not English
        self::$_l10n = FALSE;
        if (self::$_language != 'en') {
            self::$_l10n = TRUE;
            require_once self::$_baseDir . 'classes/Pommo_Helper_L10n.php';
            Pommo_Helper_L10n::init(self::$_language, self::$_baseDir);
        }
        //	make sure workDir is writable
        if (!is_dir(self::$_workDir . '/pommo/smarty')) {
            $wd = self::$_workDir;
            self::$_workDir = null;
            if (!is_dir($wd)) {
                Pommo::kill(sprintf(Pommo::_T('Work Directory (%s) not found!
						Make sure it exists and the webserver can write to it.
						You can change its location from the config.php file.'), $wd));
            }
            if (!is_writable($wd)) {
                Pommo::kill(sprintf(Pommo::_T('Cannot write to Work Directory
						(%s). Make sure it has the proper permissions.'), $wd));
            }
            if ('1' == ini_get('safe_mode')) {
                Pommo::kill(sprintf(Pommo::_T('Working Directory (%s) cannot be
						created under PHP SAFE MODE. See Documentation, or
						disable SAFE MODE.'), $wd));
            }
            if (!is_dir($wd . '/pommo')) {
                if (!mkdir($wd . '/pommo')) {
                    Pommo::kill(Pommo::_T('Could not create directory') . ' ' . $wd . '/pommo');
                }
            }
            if (!mkdir($wd . '/pommo/smarty')) {
                Pommo::kill(Pommo::_T('Could not create directory') . ' ' . $wd . '/pommo/smarty');
            }
            self::$_workdir = $wd;
        }
        //	set the current "section" -- should be "user" for /user/* files,
        //	"mailings" for /admin/mailings/* files, etc. etc.
        self::$_section = preg_replace('@^admin/?@i', '', str_replace(self::$_baseUrl, '', dirname($_SERVER['PHP_SELF'])));
        // 	initialize database link
        self::$_dbo = @new Pommo_Db($config['db_username'], $config['db_password'], $config['db_database'], $config['db_hostname'], $config['db_prefix']);
        // 	turn off debugging if in user area
        if (self::$_section == 'user') {
            self::$_debug = false;
            self::$_dbo->debug(FALSE);
        }
        // if debugging is set in config.php, enable debugging on the database.
        if (self::$_debug) {
            // don't enable debugging in ajax requests unless verbosity is < 3
            if (Pommo_Helper::isAjax() && self::$_verbosity > 2) {
                self::$_debug = false;
            } else {
                self::$_dbo->debug(TRUE);
            }
        }
        return true;
    }