Example #1
0
 public function checkHttpCache($httpCacheConf)
 {
     $httpCacheObj = new HttpCache();
     $httpCacheConf = $httpCacheObj->checkCacheConf($httpCacheConf, $this->actionData);
     if (!empty($httpCacheConf)) {
         $httpCacheObj->checkHttpCache($httpCacheConf);
     }
 }
 function render()
 {
     // call the render method in the main view class... it will take care of sending the headers
     // for us and so on...
     parent::render();
     // if there is no resource to send... then we can quit right away!
     if ($this->_resource == null) {
         return;
     }
     // let's see if we really need to send some data or not...
     // send also some headers that will help caching, if configured to do so
     $config =& Config::getConfig();
     $useCaching = $config->getValue('resource_server_http_cache_enabled');
     if ($useCaching) {
         // send the "Last-Modified" header
         $resDate = $this->_resource->getTimestamp();
         $lastModified = $resDate->getDate(DATE_FORMAT_UNIXTIME);
         $cacheLifetime = $config->getValue('resource_server_http_cache_lifetime', DEFAULT_HTTP_CACHE_LIFETIME);
         // check if we have to resent the data and if not, then we're done!
         if (HttpCache::httpConditional($lastModified, $cacheLifetime)) {
             exit;
         }
     }
     // if we need to send something, then let's do it now and finish
     if ($this->_mode == RESOURCE_VIEW_MODE_PREVIEW) {
         print $this->_resource->getPreview();
     } elseif ($this->_mode == RESOURCE_VIEW_MODE_MEDIUM) {
         print $this->_resource->getMediumSizePreview();
     } else {
         while ($chunk =& $this->_resource->getDataChunk(RESOURCE_DEFAULT_CHUNK_SIZE)) {
             echo $chunk;
         }
     }
     return true;
 }
Example #3
0
function http_end($content)
{
    // 没有http-code默认给个
    if (!isset(HttpCache::$header['Http-Code'])) {
        $header = "HTTP/1.1 200 OK\r\n";
    } else {
        $header = HttpCache::$header['Http-Code'] . "\r\n";
        unset(HttpCache::$header['Http-Code']);
    }
    // 没有Content-Type默认给个
    if (!isset(HttpCache::$header['Content-Type'])) {
        $header .= "Content-Type: text/html;charset=utf-8\r\n";
    }
    // 其它header
    foreach (HttpCache::$header as $key => $item) {
        if ('Set-Cookie' == $key && is_array($item)) {
            foreach ($item as $it) {
                $header .= $it . "\r\n";
            }
        } else {
            $header .= $item . "\r\n";
        }
    }
    // header
    $header .= "Server: WorkerMan/2.1\r\nContent-Length: " . strlen($content) . "\r\n";
    $header .= "\r\n";
    HttpCache::$header = array();
    // 保存cookie
    session_write_close();
    $_POST = $_GET = $_COOKIE = $_REQUEST = $_SESSION = array();
    $GLOBALS['HTTP_RAW_POST_DATA'] = '';
    HttpCache::$instance = null;
    // 整个http包
    return $header . $content;
}
 function render()
 {
     // set the view character set based on the default locale
     $this->_getLocale();
     $this->setCharset($this->_locale->getCharset());
     $sendOutput = true;
     // check if support for conditional HTTP requests is enabled
     $config =& Config::getConfig();
     if ($config->getValue("template_http_cache_enabled")) {
         // some debug information
         $timestamp = $this->_template->getCreationTimestamp();
         // and now send the correct headers
         if (HttpCache::httpConditional($timestamp, $this->getCacheTimeSeconds())) {
             $sendOutput = false;
         }
         header("Last-Modified: " . gmdate('D, d M Y H:i:s', $timestamp) . ' GMT');
     } else {
         $sendOutput = true;
     }
     if ($sendOutput) {
         View::render();
         $this->sendUncachedOutput();
     }
 }
 /**
  * Renders the view using the Smarty template object that we created in the constructor. This method
  * sends data to the client so it should be called as the last bit of code in our custom classes
  * extending SmartyView.
  *
  * It has no paramaters and returns nothing.
  */
 function render()
 {
     // the View class also needs to do some things...
     parent::render();
     $sendOutput = true;
     // check if plog is configured to use conditional http headers and stuff like
     // that... Also, use the HttpCache class to determine whether we should send the
     // content or not
     if ($this->isTemplateHttpCacheEnabled() && $this->isCached()) {
         // some debug information
         $timestamp = $this->_template->getCreationTimestamp();
         // and now send the correct headers
         if (HttpCache::httpConditional($timestamp, $this->getCacheTimeSeconds())) {
             $sendOutput = false;
         }
         $header = "Last-Modified: " . gmdate('D, d M Y H:i:s', $timestamp) . ' GMT';
         header($header);
     } else {
         // send the results if needed
         $sendOutput = true;
     }
     if ($sendOutput) {
         // pass all the values to the template object
         $this->_template->assign($this->_params->getAsArray());
         // and finally send the contents of the template
         print $this->_template->fetch($this->getSmartyViewId());
     }
 }