diff options
author | Frank Karlitschek <karlitschek@kde.org> | 2012-02-14 16:34:33 +0100 |
---|---|---|
committer | Frank Karlitschek <karlitschek@kde.org> | 2012-02-14 16:34:33 +0100 |
commit | 127c0c7033f2d215cd9759d71154084d91d22744 (patch) | |
tree | 5632470e5ef8d9c51e42c7cae3725e492d1f3481 /lib | |
parent | d53ed4b40bedc5c967f92839629379a91925bd87 (diff) | |
parent | 31dab0372dd0d9b7a7b4b1e27faeaaf89c420ef3 (diff) | |
download | nextcloud-server-127c0c7033f2d215cd9759d71154084d91d22744.tar.gz nextcloud-server-127c0c7033f2d215cd9759d71154084d91d22744.zip |
Merge branch 'master' of gitorious.org:owncloud/owncloud
Diffstat (limited to 'lib')
-rw-r--r-- | lib/connector/sabre/node.php | 12 | ||||
-rw-r--r-- | lib/files.php | 4 | ||||
-rw-r--r-- | lib/filestorage/local.php | 30 | ||||
-rw-r--r-- | lib/filesystem.php | 4 | ||||
-rw-r--r-- | lib/filesystemview.php | 4 | ||||
-rw-r--r-- | lib/image.php | 15 | ||||
-rw-r--r-- | lib/response.php | 51 |
7 files changed, 77 insertions, 43 deletions
diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index b8b675c1203..41acb48dfb6 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -97,12 +97,8 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr * in the second parameter or to now if the second param is empty. * Even if the modification time is set to a custom value the access time is set to now. */ - public function setLastModifiedTime($mtime) { - OC_Filesystem::setFileMtime($this->path, $mtime); - } - - public function endsWith( $str, $sub ) { - return ( substr( $str, strlen( $str ) - strlen( $sub ) ) === $sub ); + public function touch($mtime) { + OC_Filesystem::touch($this->path, $mtime); } /** @@ -123,8 +119,8 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } } else { - if( $this->endsWith( $propertyName, "modificationTime")) { - $this->setLastModifiedTime($propertyValue); + if( strcmp( $propertyName, "lastmodified")) { + $this->touch($propertyValue); } else { if(!array_key_exists( $propertyName, $existing )){ $query = OC_DB::prepare( 'INSERT INTO *PREFIX*properties (userid,propertypath,propertyname,propertyvalue) VALUES(?,?,?,?)' ); diff --git a/lib/files.php b/lib/files.php index 457c8ea38f2..1f8331afb21 100644 --- a/lib/files.php +++ b/lib/files.php @@ -91,9 +91,7 @@ class OC_Files { if($zip or OC_Filesystem::is_readable($filename)){ header('Content-Disposition: attachment; filename="'.basename($filename).'"'); header('Content-Transfer-Encoding: binary'); - header('Expires: 0'); - header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); - header('Pragma: public'); + OC_Response::disableCaching(); if($zip){ header('Content-Type: application/zip'); header('Content-Length: ' . filesize($filename)); diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 292d2a84e7d..dcb516a3afb 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -12,14 +12,10 @@ class OC_Filestorage_Local extends OC_Filestorage{ } } public function mkdir($path){ - if($return=mkdir($this->datadir.$path)){ - } - return $return; + return @mkdir($this->datadir.$path); } public function rmdir($path){ - if($return=rmdir($this->datadir.$path)){ - } - return $return; + return @rmdir($this->datadir.$path); } public function opendir($path){ return opendir($this->datadir.$path); @@ -65,13 +61,16 @@ class OC_Filestorage_Local extends OC_Filestorage{ public function filemtime($path){ return filemtime($this->datadir.$path); } - - public function setFileMtime($path, $mtime){ - // sets the modification time of the file to the given value. If mtime is nil the current time is set. - // note that the access time of the file always changes to the current time. - return touch($this->datadir.$path, $mtime); - } - + public function touch($path, $mtime){ + // sets the modification time of the file to the given value. + // If mtime is nil the current time is set. + // note that the access time of the file always changes to the current time. + if( touch( $this->datadir.$path, $mtime ) ) { + clearstatcache( true, $this->datadir.$path ); + } + + return touch($this->datadir.$path, $mtime); + } public function file_get_contents($path){ return file_get_contents($this->datadir.$path); } @@ -80,8 +79,7 @@ class OC_Filestorage_Local extends OC_Filestorage{ } } public function unlink($path){ - $return=$this->delTree($path); - return $return; + return $this->delTree($path); } public function rename($path1,$path2){ if(! $this->file_exists($path1)){ @@ -168,6 +166,8 @@ class OC_Filestorage_Local extends OC_Filestorage{ $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream'; } return $mimeType; + }else{ + return false; } } diff --git a/lib/filesystem.php b/lib/filesystem.php index 75997c244ff..90195bc2130 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -345,8 +345,8 @@ class OC_Filesystem{ static public function filemtime($path){ return self::$defaultInstance->filemtime($path); } - static public function setFileMtime($path, $mtime){ - return self::$defaultInstance->setFileMtime($path, $mtime); + static public function touch($path, $mtime){ + return self::$defaultInstance->touch($path, $mtime); } static public function file_get_contents($path){ return self::$defaultInstance->file_get_contents($path); diff --git a/lib/filesystemview.php b/lib/filesystemview.php index 0f1c546f4c5..91c6cd17720 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -156,8 +156,8 @@ class OC_FilesystemView { public function filemtime($path){ return $this->basicOperation('filemtime',$path); } - public function setFileMtime($path, $mtime){ - return $this->basicOperation('setFileMtime',$path, array('write'), $mtime); + public function touch($path, $mtime){ + return $this->basicOperation('touch', $path, array('write'), $mtime); } public function file_get_contents($path){ return $this->basicOperation('file_get_contents',$path,array('read')); diff --git a/lib/image.php b/lib/image.php index 9081a3c7021..b1d3a14f415 100644 --- a/lib/image.php +++ b/lib/image.php @@ -48,6 +48,11 @@ class OC_Image { protected $imagetype = IMAGETYPE_PNG; // Default to png if file type isn't evident. protected $filepath = null; + static public function getMimeTypeForFile($filepath) { + $imagetype = exif_imagetype($filepath); + return $imagetype ? image_type_to_mime_type($imagetype) : ''; + } + /** * @brief Constructor. * @param $imageref The path to a local file, a base64 encoded string or a resource created by an imagecreate* function. @@ -102,6 +107,7 @@ class OC_Image { * @returns bool */ public function show() { + header('Content-Type: '.$this->mimeType()); return $this->_output(); } @@ -117,17 +123,14 @@ class OC_Image { } elseif($filepath === null && $this->filepath !== null) { $filepath = $this->filepath; } - return $this->_output($filepath, true); + return $this->_output($filepath); } /** * @brief Outputs/saves the image. */ - private function _output($filepath=null, $really=false) { - if($really === false) { - header('Content-Type: '.$this->mimeType()); - $filepath = null; // Just being cautious ;-) - } else { + private function _output($filepath=null) { + if($filepath) { if(!is_writable(dirname($filepath))) { OC_Log::write('core',__METHOD__.'(): Directory \''.dirname($filepath).'\' is not writable.', OC_Log::ERROR); return false; diff --git a/lib/response.php b/lib/response.php index 7733168b5b9..2fa0a5adcd3 100644 --- a/lib/response.php +++ b/lib/response.php @@ -10,10 +10,28 @@ class OC_Response { const STATUS_FOUND = 304; const STATUS_NOT_MODIFIED = 304; const STATUS_TEMPORARY_REDIRECT = 307; + const STATUS_NOT_FOUND = 404; + + static public function enableCaching($cache_time = null) { + if (is_numeric($cache_time)) { + header('Pragma: public');// enable caching in IE + if ($cache_time > 0) { + self::setExpiresHeader('PT'.$cache_time.'S'); + header('Cache-Control: max-age='.$cache_time.', must-revalidate'); + } + else { + self::setExpiresHeader(0); + header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); + } + } + else { + header('Cache-Control: cache'); + header('Pragma: cache'); + } - static public function enableCaching() { - header('Cache-Control: cache'); - header('Pragma: cache'); + } + static public function disableCaching() { + self::enableCaching(0); } static public function setStatus($status) { @@ -33,6 +51,9 @@ class OC_Response { case self::STATUS_FOUND; $status = $status . ' Found'; break; + case self::STATUS_NOT_FOUND; + $status = $status . ' Not Found'; + break; } header($protocol.' '.$status); } @@ -46,19 +67,19 @@ class OC_Response { if (is_string($expires) && $expires[0] == 'P') { $interval = $expires; $expires = new DateTime('now'); - $expires->add(new DateInterval(expires)); + $expires->add(new DateInterval($interval)); } if ($expires instanceof DateTime) { + $expires->setTimezone(new DateTimeZone('GMT')); $expires = $expires->format(DateTime::RFC2822); } - header('Expires: '.expires); + header('Expires: '.$expires); } static public function setETagHeader($etag) { if (empty($etag)) { return; } - self::enableCaching(); if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag) { self::setStatus(self::STATUS_NOT_MODIFIED); @@ -71,10 +92,12 @@ class OC_Response { if (empty($lastModified)) { return; } + if (is_int($lastModified)) { + $lastModified = gmdate(DateTime::RFC2822, $lastModified); + } if ($lastModified instanceof DateTime) { $lastModified = $lastModified->format(DateTime::RFC2822); } - self::enableCaching(); if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && trim($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $lastModified) { self::setStatus(self::STATUS_NOT_MODIFIED); @@ -82,4 +105,18 @@ class OC_Response { } header('Last-Modified: '.$lastModified); } + + static public function sendFile($filepath=null) { + $fp = fopen($filepath, 'rb'); + if ($fp) { + self::setLastModifiedHeader(filemtime($filepath)); + self::setETagHeader(md5_file($filepath)); + + header('Content-Length: '.filesize($filepath)); + fpassthru($fp); + } + else { + self::setStatus(self::STATUS_NOT_FOUND); + } + } } |