Esempio n. 1
0
 public function output($files, $cache_key)
 {
     header('Content-Type: ' . $this->contentType);
     OC_Response::enableCaching();
     $etag = $this->generateETag($files);
     $cache_key .= '-' . $etag;
     $gzout = false;
     $cache = OC_Cache::getGlobalCache();
     if (!OC_Request::isNoCache() && (!defined('DEBUG') || !DEBUG)) {
         OC_Response::setETagHeader($etag);
         $gzout = $cache->get($cache_key . '.gz');
     }
     if (!$gzout) {
         $out = $this->minimizeFiles($files);
         $gzout = gzencode($out);
         $cache->set($cache_key . '.gz', $gzout);
         OC_Response::setETagHeader($etag);
     }
     if ($encoding = OC_Request::acceptGZip()) {
         header('Content-Encoding: ' . $encoding);
         $out = $gzout;
     } else {
         $out = gzdecode($gzout);
     }
     header('Content-Length: ' . strlen($out));
     echo $out;
 }
Esempio n. 2
0
 /**
  * Checks and set ETag header, when the request matches sends a
  * 'not modified' response
  * @param string $etag token to use for modification check
  */
 public static function setETagHeader($etag)
 {
     \OC_Response::setETagHeader($etag);
 }
Esempio n. 3
0
 public static function getTmpAvatar($args)
 {
     \OC_JSON::checkLoggedIn();
     \OC_JSON::callCheck();
     $tmpavatar = \OC_Cache::get('tmpavatar');
     if (is_null($tmpavatar)) {
         $l = new \OC_L10n('core');
         \OC_JSON::error(array("data" => array("message" => $l->t("No temporary profile picture available, try again"))));
         return;
     }
     $image = new \OC_Image($tmpavatar);
     \OC_Response::disableCaching();
     \OC_Response::setLastModifiedHeader(time());
     \OC_Response::setETagHeader(crc32($image->data()));
     $image->show();
 }
Esempio n. 4
0
 /**
  * Generate JSON response for routing in javascript
  */
 public static function JSRoutes()
 {
     $router = OC::getRouter();
     $etag = $router->getCacheKey();
     OC_Response::enableCaching();
     OC_Response::setETagHeader($etag);
     $root = $router->getCollection('root');
     $routes = array();
     foreach ($root->all() as $name => $route) {
         $compiled_route = $route->compile();
         $defaults = $route->getDefaults();
         unset($defaults['action']);
         $routes[$name] = array('tokens' => $compiled_route->getTokens(), 'defaults' => $defaults);
     }
     OCP\JSON::success(array('data' => $routes));
 }
Esempio n. 5
0
 public static function loadfile()
 {
     if (file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE)) {
         if (substr(OC::$REQUESTEDFILE, -3) == 'css') {
             $appswebroot = (string) OC::$APPSWEBROOT;
             $webroot = (string) OC::$WEBROOT;
             $filepath = OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE;
             header('Content-Type: text/css');
             OC_Response::enableCaching();
             OC_Response::setLastModifiedHeader(filemtime($filepath));
             $cssfile = file_get_contents($filepath);
             $cssfile = str_replace('%appswebroot%', $appswebroot, $cssfile);
             $cssfile = str_replace('%webroot%', $webroot, $cssfile);
             OC_Response::setETagHeader(md5($cssfile));
             header('Content-Length: ' . strlen($cssfile));
             echo $cssfile;
             exit;
         } elseif (substr(OC::$REQUESTEDFILE, -3) == 'php') {
             require_once OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/' . OC::$REQUESTEDFILE;
         }
     } else {
         header('HTTP/1.0 404 Not Found');
         exit;
     }
 }