Пример #1
0
 /**
  * Create new Ajax backend object and start output buffer (buffer will be catched in destructor)
  */
 public function __construct($request)
 {
     $this->result_ids = !empty($request['result_ids']) ? explode(',', str_replace(' ', '', $request['result_ids'])) : array();
     $this->full_render = !empty($request['full_render']);
     $this->_skip_result_ids_check = !empty($request['skip_result_ids_check']);
     $this->_result = !empty($request['_ajax_data']) ? $request['_ajax_data'] : array();
     $this->_request_type = !empty($request['is_ajax']) ? $request['is_ajax'] : self::REQUEST_XML;
     if (!empty($request['callback'])) {
         $this->_request_type = self::REQUEST_JSONP;
         $this->callback = $request['callback'];
     }
     $this->redirect_type = $this->_request_type;
     // Start OB handling early.
     if ($this->_request_type != self::REQUEST_COMET) {
         ob_start();
     } else {
         $this->redirect_type = Ajax::REQUEST_IFRAME;
         Registry::set('runtime.comet', true);
     }
     $origin = !empty($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : $_SERVER['HTTP_REFERER'];
     if (!empty($request['force_embedded']) && !empty($request['init_context'])) {
         $origin = $request['init_context'];
     }
     if (!empty($origin)) {
         $_purl = parse_url($origin);
         $origin_host = $_purl['host'];
         $origin_scheme = $_purl['scheme'];
         $_chost = Registry::get('config.current_host');
         if (empty($_chost) || strpos($_chost, '%') !== false) {
             $_chost = $_SERVER['HTTP_HOST'];
         }
         if ($origin_host != $_chost) {
             // cross-domain request
             Embedded::enable();
             if (!empty($request['init_context'])) {
                 Embedded::setUrl($request['init_context']);
             }
             header('Access-Control-Allow-Origin: ' . $origin_scheme . '://' . $origin_host);
             header('Access-Control-Allow-Credentials: true');
         }
     }
     // Check if headers are already sent (see Content-Type library usage).
     // If true - generate debug message and exit.
     $file = $line = null;
     if (headers_sent($file, $line)) {
         trigger_error("HTTP headers are already sent" . ($line !== null ? " in {$file} on line {$line}" : "") . ". " . "Possibly you have extra spaces (or newlines) before first line of the script or any library. " . "Please note that Subsys_Ajax uses its own Content-Type header and fails if " . "this header cannot be set. See header() function documentation for details", E_USER_ERROR);
         exit;
     }
 }
Пример #2
0
 /**
  * Create new Ajax backend object and start output buffer (buffer will be catched in destructor)
  */
 public function __construct($request)
 {
     $this->result_ids = !empty($request['result_ids']) ? explode(',', str_replace(' ', '', $request['result_ids'])) : array();
     $this->full_render = !empty($request['full_render']);
     $this->anchor = !empty($request['anchor']) ? $request['anchor'] : NULL;
     $this->_skip_result_ids_check = !empty($request['skip_result_ids_check']);
     $this->_result = !empty($request['_ajax_data']) ? $request['_ajax_data'] : array();
     $this->_request_type = !empty($request['is_ajax']) ? $request['is_ajax'] : self::REQUEST_XML;
     $this->_internal_request = self::isInternalRequest($request);
     if (!$this->_internal_request) {
         return true;
     }
     if (!empty($request['callback'])) {
         $this->_request_type = self::REQUEST_JSONP;
         $this->_content_type = 'text/javascript';
         $this->callback = $request['callback'];
     }
     $this->redirect_type = $this->_request_type;
     // Start OB handling early.
     if ($this->_request_type != self::REQUEST_COMET) {
         $ajax_obj =& $this;
         ob_start(function ($content) use($ajax_obj) {
             $ajax_obj->destruct($content);
         });
     } else {
         // This is workaround for nginx + php-fpm, as COMET progress won't work if compression on nginx side is used.
         if (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false) {
             ob_start('ob_gzhandler');
         }
         $this->redirect_type = Ajax::REQUEST_IFRAME;
         Registry::set('runtime.comet', true);
         header('X-Accel-Buffering: no');
     }
     $_SERVER['HTTP_REFERER'] = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
     $origin = !empty($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : $_SERVER['HTTP_REFERER'];
     if (!empty($request['force_embedded']) && !empty($request['init_context'])) {
         $origin = $request['init_context'];
     }
     if (!empty($origin)) {
         $_purl = parse_url($origin);
         $origin_host = $_purl['host'] . (empty($_purl['port']) ? '' : ':' . $_purl['port']);
         $origin_scheme = $_purl['scheme'];
         $_chost = Registry::get('config.current_host');
         if (empty($_chost) || strpos($_chost, '%') !== false) {
             $_chost = $_SERVER['HTTP_HOST'];
         }
         if ($origin_host != $_chost) {
             // cross-domain request
             Embedded::enable();
             if (!empty($request['init_context'])) {
                 Embedded::setUrl($request['init_context']);
             }
             header('Access-Control-Allow-Origin: ' . $origin_scheme . '://' . $origin_host);
             header('Access-Control-Allow-Credentials: true');
         }
     }
     // Check if headers are already sent (see Content-Type library usage).
     // If true - generate debug message and exit.
     $file = $line = null;
     if (headers_sent($file, $line)) {
         trigger_error("HTTP headers are already sent" . ($line !== null ? " in {$file} on line {$line}" : "") . ". " . "Possibly you have extra spaces (or newlines) before first line of the script or any library. " . "Please note that Subsys_Ajax uses its own Content-Type header and fails if " . "this header cannot be set. See header() function documentation for details", E_USER_ERROR);
         exit;
     }
 }