Esempio n. 1
1
 /**
  * print either html or xml content given oModule object
  * @remark addon execution and the trigger execution are included within this method, which might create inflexibility for the fine grained caching
  * @param ModuleObject $oModule the module object
  * @return void
  */
 function printContent(&$oModule)
 {
     // Check if the gzip encoding supported
     if (defined('__OB_GZHANDLER_ENABLE__') && __OB_GZHANDLER_ENABLE__ == 1 && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== FALSE && function_exists('ob_gzhandler') && extension_loaded('zlib') && $oModule->gzhandler_enable) {
         $this->gz_enabled = TRUE;
     }
     // Extract contents to display by the request method
     if (Context::get('xeVirtualRequestMethod') == 'xml') {
         require_once _XE_PATH_ . "classes/display/VirtualXMLDisplayHandler.php";
         $handler = new VirtualXMLDisplayHandler();
     } else {
         if (Context::getRequestMethod() == 'XMLRPC') {
             require_once _XE_PATH_ . "classes/display/XMLDisplayHandler.php";
             $handler = new XMLDisplayHandler();
             if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
                 $this->gz_enabled = FALSE;
             }
         } else {
             if (Context::getRequestMethod() == 'JSON') {
                 require_once _XE_PATH_ . "classes/display/JSONDisplayHandler.php";
                 $handler = new JSONDisplayHandler();
             } else {
                 if (Context::getRequestMethod() == 'JS_CALLBACK') {
                     require_once _XE_PATH_ . "classes/display/JSCallbackDisplayHandler.php";
                     $handler = new JSCallbackDisplayHandler();
                 } else {
                     require_once _XE_PATH_ . "classes/display/HTMLDisplayHandler.php";
                     $handler = new HTMLDisplayHandler();
                 }
             }
         }
     }
     $output = $handler->toDoc($oModule);
     // call a trigger before display
     ModuleHandler::triggerCall('display', 'before', $output);
     // execute add-on
     $called_position = 'before_display_content';
     $oAddonController = getController('addon');
     $addon_file = $oAddonController->getCacheFilePath(Mobile::isFromMobilePhone() ? "mobile" : "pc");
     if (file_exists($addon_file)) {
         include $addon_file;
     }
     if (method_exists($handler, "prepareToPrint")) {
         $handler->prepareToPrint($output);
     }
     // header output
     if ($this->gz_enabled) {
         header("Content-Encoding: gzip");
     }
     $httpStatusCode = $oModule->getHttpStatusCode();
     if ($httpStatusCode && $httpStatusCode != 200) {
         $this->_printHttpStatusCode($httpStatusCode);
     } else {
         if (Context::getResponseMethod() == 'JSON' || Context::getResponseMethod() == 'JS_CALLBACK') {
             $this->_printJSONHeader();
         } else {
             if (Context::getResponseMethod() != 'HTML') {
                 $this->_printXMLHeader();
             } else {
                 $this->_printHTMLHeader();
             }
         }
     }
     // debugOutput output
     $this->content_size = strlen($output);
     $output .= $this->_debugOutput();
     // results directly output
     if ($this->gz_enabled) {
         print ob_gzhandler($output, 5);
     } else {
         print $output;
     }
     // call a trigger after display
     ModuleHandler::triggerCall('display', 'after', $output);
 }
Esempio n. 2
0
function epb($buffer, $mode)
{
    //@ob_gzhandler($buffer, $mode);
    @ob_gzhandler($buffer);
    //return $buffer; // uncomment if you're messing with output buffering so errors show. ~pb
    return expProcessBuffer($buffer);
}
Esempio n. 3
0
function gzip_ops( &$buffer, $mode = 5 )
{
	if ( GZIP === true && function_exists('ob_gzhandler') && substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') )
	{
		$buffer = ob_gzhandler($buffer, $mode);
	}
	return $buffer;
}
Esempio n. 4
0
function compress_handler($p_buffer, $p_mode)
{
    if (compress_is_enabled()) {
        return ob_gzhandler($p_buffer, $p_mode);
    } else {
        return $p_buffer;
    }
}
Esempio n. 5
0
 static function do_end($buffer, $mode)
 {
     // write contents to file
     chdir(dirname($_SERVER['SCRIPT_FILENAME']));
     file_put_contents(Cache::cache_file(), $buffer);
     // use gz_handler to output if possible
     if (headers_sent() || true) {
         return false;
     } else {
         return ob_gzhandler($buffer, $mode);
     }
 }
 /**
  * Corrects HTTP "Content-length" header if it was sent by TYPO3 and compression
  * is enabled.
  *
  * @param	string	$outputBuffer	Output buffer to compress
  * @param	int	$mode	One of PHP_OUTPUT_HANDLER_xxx contants
  * @return	string	Compressed string
  * @see	ob_start()
  * @see	ob_gzhandler()
  */
 function compressionOutputHandler($outputBuffer, $mode)
 {
     // Compress the content
     $outputBuffer = ob_gzhandler($outputBuffer, $mode);
     if ($outputBuffer !== false) {
         // Save compressed size
         $this->contentLength += strlen($outputBuffer);
         // Check if this was the last content chunk
         if (0 != ($mode & PHP_OUTPUT_HANDLER_END)) {
             // Check if we have content-length header
             foreach (headers_list() as $header) {
                 if (0 == strncasecmp('Content-length:', $header, 15)) {
                     header('Content-length: ' . $this->contentLength);
                     break;
                 }
             }
         }
     }
     return $outputBuffer;
 }
 /**
  * @brief 모듈객체를 받아서 content 출력
  **/
 function printContent(&$oModule)
 {
     // gzip encoding 지원 여부 체크
     if (defined('__OB_GZHANDLER_ENABLE__') && __OB_GZHANDLER_ENABLE__ == 1 && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false && function_exists('ob_gzhandler') && extension_loaded('zlib')) {
         $this->gz_enabled = true;
     }
     // request method에 따른 컨텐츠 결과물 추출
     if (Context::get('xeVirtualRequestMethod') == 'xml') {
         $output = $this->_toVirtualXmlDoc($oModule);
     } else {
         if (Context::getRequestMethod() == 'XMLRPC') {
             $output = $this->_toXmlDoc($oModule);
         } else {
             if (Context::getRequestMethod() == 'JSON') {
                 $output = $this->_toJSON($oModule);
             } else {
                 $output = $this->_toHTMLDoc($oModule);
             }
         }
     }
     // HTML 출력 요청일 경우 레이아웃 컴파일과 더블어 완성된 코드를 제공
     if (Context::getResponseMethod() == "HTML") {
         // 관리자 모드일 경우 #xeAdmin id를 가지는 div 추가
         if (Context::get('module') != 'admin' && strpos(Context::get('act'), 'Admin') > 0) {
             $output = '<div id="xeAdmin">' . $output . '</div>';
         }
         // 내용을 content라는 변수로 설정 (layout에서 {$output}에서 대체됨)
         Context::set('content', $output);
         // 레이아웃을 컴파일
         $oTemplate =& TemplateHandler::getInstance();
         // layout이라는 변수가 none으로 설정되면 기본 레이아웃으로 변경
         if (Context::get('layout') != 'none') {
             if (__DEBUG__ == 3) {
                 $start = getMicroTime();
             }
             $layout_path = $oModule->getLayoutPath();
             $layout_file = $oModule->getLayoutFile();
             $edited_layout_file = $oModule->getEditedLayoutFile();
             // 현재 요청된 레이아웃 정보를 구함
             $oLayoutModel =& getModel('layout');
             $current_module_info = Context::get('current_module_info');
             $layout_srl = $current_module_info->layout_srl;
             // 레이아웃과 연결되어 있으면 레이아웃 컴파일
             if ($layout_srl > 0) {
                 $layout_info = Context::get('layout_info');
                 // faceoff 레이아웃일 경우 별도 처리
                 if ($layout_info && $layout_info->type == 'faceoff') {
                     $oLayoutModel->doActivateFaceOff($layout_info);
                     Context::set('layout_info', $layout_info);
                 }
                 // 관리자 레이아웃 수정화면에서 변경된 CSS가 있는지 조사
                 $edited_layout_css = $oLayoutModel->getUserLayoutCss($layout_srl);
                 if (file_exists($edited_layout_css)) {
                     Context::addCSSFile($edited_layout_css, true, 'all', '', 100);
                 }
             }
             if (!$layout_path) {
                 $layout_path = "./common/tpl";
             }
             if (!$layout_file) {
                 $layout_file = "default_layout";
             }
             $output = $oTemplate->compile($layout_path, $layout_file, $edited_layout_file);
             if (__DEBUG__ == 3) {
                 $GLOBALS['__layout_compile_elapsed__'] = getMicroTime() - $start;
             }
         }
     }
     // 출력하기 전에 trigger 호출 (before)
     ModuleHandler::triggerCall('display', 'before', $output);
     // 애드온 실행
     $called_position = 'before_display_content';
     $oAddonController =& getController('addon');
     $addon_file = $oAddonController->getCacheFilePath();
     if (file_exists($addon_file)) {
         @(include $addon_file);
     }
     // HTML 출력일 경우 최종적으로 common layout을 씌워서 출력
     if (Context::getResponseMethod() == "HTML") {
         if (__DEBUG__ == 3) {
             $start = getMicroTime();
         }
         // body 내의 <style ..></style>를 header로 이동
         $output = preg_replace_callback('!<style(.*?)<\\/style>!is', array($this, 'moveStyleToHeader'), $output);
         // 메타 파일 변경 (캐싱기능등으로 인해 위젯등에서 <!--Meta:경로--> 태그를 content에 넣는 경우가 있음
         $output = preg_replace_callback('/<!--Meta:([a-z0-9\\_\\/\\.\\@]+)-->/is', array($this, 'transMeta'), $output);
         // rewrite module 사용시 생기는 상대경로에 대한 처리를 함
         if (Context::isAllowRewrite()) {
             $url = parse_url(Context::getRequestUri());
             $real_path = $url['path'];
             $pattern = '/src=("|\'){1}(\\.\\/)?(files\\/attach|files\\/cache|files\\/faceOff|files\\/member_extra_info|modules|common|widgets|widgetstyle|layouts|addons)\\/([^"\']+)\\.(jpg|jpeg|png|gif)("|\'){1}/s';
             $output = preg_replace($pattern, 'src=$1' . $real_path . '$3/$4.$5$6', $output);
             if (Context::get('vid')) {
                 $pattern = '/\\/' . Context::get('vid') . '\\?([^=]+)=/is';
                 $output = preg_replace($pattern, '/?$1=', $output);
             }
         }
         // 간혹 background-image에 url(none) 때문에 request가 한번 더 일어나는 경우가 생기는 것을 방지
         $output = preg_replace('/url\\((["\']?)none(["\']?)\\)/is', 'none', $output);
         if (__DEBUG__ == 3) {
             $GLOBALS['__trans_content_elapsed__'] = getMicroTime() - $start;
         }
         // 불필요한 정보 제거
         $output = preg_replace('/member\\_\\-([0-9]+)/s', 'member_0', $output);
         // 최종 레이아웃 변환
         Context::set('content', $output);
         $output = $oTemplate->compile('./common/tpl', 'common_layout');
         // 사용자 정의 언어 변환
         $oModuleController =& getController('module');
         $oModuleController->replaceDefinedLangCode($output);
     }
     // header 출력
     if ($this->gz_enabled) {
         header("Content-Encoding: gzip");
     }
     if (Context::getResponseMethod() == 'JSON') {
         $this->_printJSONHeader();
     } else {
         if (Context::getResponseMethod() != 'HTML') {
             $this->_printXMLHeader();
         } else {
             $this->_printHTMLHeader();
         }
     }
     // debugOutput 출력
     $this->content_size = strlen($output);
     $output .= $this->_debugOutput();
     // 결과물 직접 출력
     if ($this->gz_enabled) {
         print ob_gzhandler($output, 5);
     } else {
         print $output;
     }
     // 출력 후 trigger 호출 (after)
     ModuleHandler::triggerCall('display', 'after', $content);
 }
Esempio n. 8
0
function SendImageFromCache($src, $cached = true)
{
    // set header
    header('Content-type: image/jpg');
    header('Cache-Control: public');
    // set cache signal
    header('Sd-signature: ' . ($cached ? 'Cached Image' : 'Created Image'));
    // gzhandler
    die(ob_gzhandler(file_get_contents($src), 9));
}
 function _httpConditionalCallBack($buffer, $mode = 5)
 {
     //Private function automatically called at the end of the script when compression is enabled
     //rfc2616-sec14.html#sec14.11
     //You can adjust the level of compression with zlib.output_compression_level in php.ini
     if (extension_loaded('zlib') && !ini_get('zlib.output_compression')) {
         $buffer2 = ob_gzhandler($buffer, $mode);
         //Will check HTTP_ACCEPT_ENCODING and put correct headers
         if (strlen($buffer2) > 1) {
             //When ob_gzhandler succeeded
             $buffer = $buffer2;
         }
     }
     header('Content-Length: ' . strlen($buffer));
     //Allows persistant connections //rfc2616-sec14.html#sec14.13
     return $buffer;
 }
Esempio n. 10
0
 /**
  * Returns the Asset Types content.
  * It will try and use Gzip to compress the content and save bandwidth
  *
  * @return string
  */
 public function render()
 {
     $content = $this->assetType->getContent();
     /**
      * Do not use ob_gzhandler() if zlib.output_compression ini option is set
      * This will gzip the output twice and the text will be garbled
      */
     if (@ini_get('zlib.output_compression')) {
         $ret = $content;
     } else {
         if (!($ret = ob_gzhandler($content, PHP_OUTPUT_HANDLER_START | PHP_OUTPUT_HANDLER_END))) {
             $ret = $content;
         }
     }
     return $ret;
 }
Esempio n. 11
0
 public function gzHandler($buffer = '', $mode = 0)
 {
     if (!is_string($buffer)) {
         return Error::set(lang('Error', 'stringParameter', 'buffer'));
     }
     if (!is_numeric($mode)) {
         return Error::set(lang('Error', 'numericParameter', 'mode'));
     }
     return ob_gzhandler($buffer, $mode);
 }
Esempio n. 12
0
function dolphin_handler($str)
{
    $str = ob_gzhandler($str, 5);
    header("Content-length: " . strlen($str));
    return $str;
}
Esempio n. 13
0
/**
 * Launch output compression if enabled
 */
function atm_compress_handler($p_buffer, $p_mode)
{
    if (ENABLE_HTML_COMPRESSION && APPLICATION_EXEC_TYPE == 'http' && !headers_sent() && 'ob_gzhandler' != ini_get('output_handler') && extension_loaded('zlib') && strpos(strtolower(@$_SERVER['HTTP_ACCEPT_ENCODING']), 'gzip') !== false && !ini_get('zlib.output_compression')) {
        //no output compression should already defined at PHP level
        if (!defined('HTML_COMPRESSION_STARTED')) {
            define('HTML_COMPRESSION_STARTED', true);
        }
        return ob_gzhandler($p_buffer, $p_mode);
    } else {
        return $p_buffer;
    }
}
Esempio n. 14
0
 /**
  * Output callback method which will be called when the output buffer
  * is flushed at the end of the request.
  *
  * @param string    $uValue     the generated content
  * @param int       $uStatus    the status of the output buffer
  *
  * @return string final content
  */
 public static function output($uValue, $uStatus)
 {
     $tParms = array('exitStatus' => &self::$exitStatus, 'responseFormat' => &self::$responseFormat, 'content' => &$uValue);
     Events::invoke('output', $tParms);
     if (ini_get('output_handler') === "") {
         $tParms['content'] = mb_output_handler($tParms['content'], $uStatus);
         // PHP_OUTPUT_HANDLER_START | PHP_OUTPUT_HANDLER_END
         if (!ini_get('zlib.output_compression') && PHP_SAPI !== 'cli' && Config::get('options/gzip', true) === true) {
             $tParms['content'] = ob_gzhandler($tParms['content'], $uStatus);
             // PHP_OUTPUT_HANDLER_START | PHP_OUTPUT_HANDLER_END
         }
     }
     return $tParms['content'];
 }
Esempio n. 15
0
function handler($buffer, $mode)
{
    $buffer = ob_gzhandler($buffer, $mode);
    return $buffer;
}
Esempio n. 16
0
 /**
  * Enables compression. (warning: may not work)
  * @return bool
  */
 public function enableCompression()
 {
     if (headers_sent()) {
         return FALSE;
     }
     if ($this->getHeader('Content-Encoding') !== NULL) {
         return FALSE;
         // called twice
     }
     $ok = ob_gzhandler('', PHP_OUTPUT_HANDLER_START);
     if ($ok === FALSE) {
         return FALSE;
         // not allowed
     }
     if (function_exists('ini_set')) {
         ini_set('zlib.output_compression', 'Off');
         ini_set('zlib.output_compression_level', '6');
     }
     ob_start('ob_gzhandler', 1);
     return TRUE;
 }
Esempio n. 17
0
<?php

defined('LOAD_SAFE') or die('Server Error');
$start_time = microtime();
$gzip = ob_gzhandler($buffer, 1);
if ($gzip) {
    header("Content-Encoding: gzip");
    ob_start('ob_gzhandler');
} else {
    ob_start();
}
if (version_compare(phpversion(), '5.1.0', '<') == true) {
    die("PHP5 = false : PHP5 required");
}
////////////////////////////////////
// Define root directory
////////////////////////////////////
define('__SITE_PATH', realpath(dirname(__FILE__)));
////////////////////////////////////
// Get Configuration Object
////////////////////////////////////
include __SITE_PATH . "/core/library/config.class.php";
$configuration = configuration::getInstance();
////////////////////////////////////
//  Set system time
////////////////////////////////////
$date_time = date($configuration->config_values['application']['date_format']);
////////////////////////////////////
// Set Time Zone
////////////////////////////////////
date_default_timezone_set($configuration->config_values['application']['timezone']);
Esempio n. 18
0
 /**
  * 执行Api控制器
  */
 public static function execApi()
 {
     include_once SITE_PATH . '/api/' . API_VERSION . '/' . MODULE_NAME . 'Api.class.php';
     $className = MODULE_NAME . 'Api';
     $module = new $className();
     $action = ACTION_NAME;
     //执行当前操作
     $data = call_user_func(array(&$module, $action));
     $format = in_array($_REQUEST['format'], array('json', 'php', 'test')) ? $_REQUEST['format'] : 'json';
     $format = strtolower($format);
     /* json */
     if ($format == 'json') {
         ob_end_clean();
         ob_start(function ($buffer, $mode) {
             if (extension_loaded('zlib') and function_exists('ob_gzhandler')) {
                 return ob_gzhandler($buffer, $mode);
             }
             return $buffer;
         });
         header('Content-type:application/json;charset=utf-8');
         echo json_encode($data);
         ob_end_flush();
         exit;
         /* php */
     } elseif ($format == 'php') {
         var_export($data);
         exit;
         /* test */
     } elseif ($format == 'test') {
         dump($data);
         exit;
     }
     return;
 }
<?php

if (false !== ob_gzhandler("", PHP_OUTPUT_HANDLER_START)) {
    ini_set("zlib.output_compression", 0);
    ob_start("ob_gzhandler");
}
echo "hi\n";
Esempio n. 20
0
/**
 * Output Buffering handler that either compresses the buffer or just.
 * returns it, depending on the return value of compress_handler_is_enabled()
 * @param string $p_buffer
 * @param int $p_mode
 * @return string
 * @access public
 */
function compress_handler( & $p_buffer, $p_mode ) {
	global $g_compression_started;
	if( $g_compression_started && compress_handler_is_enabled() ) {
		return ob_gzhandler( $p_buffer, $p_mode );
	} else {
		return $p_buffer;
	}
}
Esempio n. 21
0
            break;
    }
    # Strip badwords
    $fetch->return = str_replace($badWords, '####', $fetch->return);
    # Post parsing
    if (!empty($foundPlugin) && function_exists('postParse')) {
        $fetch->return = postParse($fetch->return, $fetch->docType);
    }
    # Print debug info
    if (DEBUG_MODE) {
        echo '<pre>', print_r($fetch, true), '</pre>';
        ## Send output
    } else {
        # Do we want to compress? Yes if option is set, browser supports it, and zlib is available but compression not automated
        if (optGZIP && isset($_SERVER['HTTP_ACCEPT_ENCODING']) && strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false && extension_loaded('zlib') && !ini_get('zlib.output_compression')) {
            echo ob_gzhandler($fetch->return, 5);
        } else {
            ## Send content-length header
            header('Content-Length: ' . strlen($fetch->return));
            echo $fetch->return;
        }
    }
}
##########################################
## Save cache
##########################################
if (isset($useCache)) {
    # Find filename
    $saveAs = optCACHEPATH . $cacheName;
    # Save file if not already
    if ($fetch->docType) {