inc("part.details");
+ echo $this->inc('part.contact');
}
else{
- echo $this->inc("part.addcardform");
+ echo $this->inc('part.no_contacts');
}
?>
diff --git a/apps/contacts/templates/index2.php b/apps/contacts/templates/index2.php
deleted file mode 100644
index 4c0dfad617..0000000000
--- a/apps/contacts/templates/index2.php
+++ /dev/null
@@ -1,27 +0,0 @@
-
-
- inc('part.contact');
- }
- else{
- echo $this->inc('part.no_contacts');
- }
- ?>
-
-
-';
+ // Change breadcrumb classes
+ $('#controls .last').removeClass('last');
+ $('#controls').append(editorbarhtml);
+ $('#editorcontrols').fadeIn('slow');
}
function bindControlEvents(){
@@ -182,8 +180,10 @@ function showFileEditor(dir,filename){
// Save mtime
$('#editor').attr('data-mtime', result.data.mtime);
// Initialise the editor
- showControls(filename,result.data.write);
+ $('.actions,#file_action_panel').fadeOut('slow');
$('table').fadeOut('slow', function() {
+ // Show the control bar
+ showControls(filename,result.data.write);
// Update document title
document.title = filename;
$('#editor').text(result.data.filecontents);
@@ -215,8 +215,9 @@ function showFileEditor(dir,filename){
// Fades out the editor.
function hideFileEditor(){
// Fades out editor controls
- $('#controls > :not(.actions,#file_access_panel,.crumb),#breadcrumb_file').fadeOut('slow',function(){
+ $('#editorcontrols').fadeOut('slow',function(){
$(this).remove();
+ $(".crumb:last").addClass('last');
});
// Fade out editor
$('#editor').fadeOut('slow', function(){
diff --git a/apps/gallery/ajax/cover.php b/apps/gallery/ajax/cover.php
deleted file mode 100644
index 068a6e9c4e..0000000000
--- a/apps/gallery/ajax/cover.php
+++ /dev/null
@@ -1,81 +0,0 @@
-.
-*
-*/
-
-require_once('../../../lib/base.php');
-OC_JSON::checkLoggedIn();
-OC_JSON::checkAppEnabled('gallery');
-
-function CroppedThumbnail($imgSrc,$thumbnail_width,$thumbnail_height) { //$imgSrc is a FILE - Returns an image resource.
- //getting the image dimensions
- list($width_orig, $height_orig) = getimagesize($imgSrc);
- switch (strtolower(substr($imgSrc, strrpos($imgSrc, '.')+1))) {
- case "jpeg":
- case "jpg":
- $myImage = imagecreatefromjpeg($imgSrc);
- break;
- default:
- exit();
- }
- $ratio_orig = $width_orig/$height_orig;
-
- if ($thumbnail_width/$thumbnail_height > $ratio_orig) {
- $new_height = $thumbnail_width/$ratio_orig;
- $new_width = $thumbnail_width;
- } else {
- $new_width = $thumbnail_height*$ratio_orig;
- $new_height = $thumbnail_height;
- }
-
- $x_mid = $new_width/2; //horizontal middle
- $y_mid = $new_height/2; //vertical middle
-
- $process = imagecreatetruecolor(round($new_width), round($new_height));
-
- imagecopyresampled($process, $myImage, 0, 0, 0, 0, $new_width, $new_height, $width_orig, $height_orig);
- $thumb = imagecreatetruecolor($thumbnail_width, $thumbnail_height);
- imagecopyresampled($thumb, $process, 0, 0, ($x_mid-($thumbnail_width/2)), ($y_mid-($thumbnail_height/2)), $thumbnail_width, $thumbnail_height, $thumbnail_width, $thumbnail_height);
-
- imagedestroy($process);
- imagedestroy($myImage);
- return $thumb;
-}
-
-$box_size = 200;
-$album_name = $_GET['album'];
-$x = $_GET['x'];
-
-$stmt = OC_DB::prepare('SELECT `file_path` FROM *PREFIX*gallery_photos,*PREFIX*gallery_albums WHERE *PREFIX*gallery_albums.`uid_owner` = ? AND `album_name` = ? AND *PREFIX*gallery_photos.`album_id` == *PREFIX*gallery_albums.`album_id`');
-$result = $stmt->execute(array(OC_User::getUser(), $album_name));
-$x = min((int)($x/($box_size/$result->numRows())), $result->numRows()-1); // get image to display
-$result->seek($x); // never throws
-$path = $result->fetchRow();
-$path = $path['file_path'];
-$imagePath = OC_Filesystem::getLocalFile($img);
-$imagesize = getimagesize($imagePath);
-
-header('Content-Type: image/png');
-$image = CroppedThumbnail($imagePath, $box_size, $box_size);
-
-imagepng($image);
-imagedestroy($image);
-?>
diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php
index 8df692c773..5ac6d29510 100644
--- a/apps/gallery/ajax/galleryOp.php
+++ b/apps/gallery/ajax/galleryOp.php
@@ -22,18 +22,16 @@
*/
require_once('../../../lib/base.php');
-require_once(OC::$CLASSPATH['OC_Gallery_Album']);
-require_once(OC::$CLASSPATH['OC_Gallery_Scanner']);
+
+OC_JSON::checkLoggedIn();
OC_JSON::checkAppEnabled('gallery');
function handleRename($oldname, $newname) {
- OC_JSON::checkLoggedIn();
OC_Gallery_Album::rename($oldname, $newname, OC_User::getUser());
OC_Gallery_Album::changeThumbnailPath($oldname, $newname);
}
function handleRemove($name) {
- OC_JSON::checkLoggedIn();
$album_id = OC_Gallery_Album::find(OC_User::getUser(), $name);
$album_id = $album_id->fetchRow();
$album_id = $album_id['album_id'];
@@ -42,25 +40,18 @@ function handleRemove($name) {
}
function handleGetThumbnails($albumname) {
- OC_JSON::checkLoggedIn();
- $photo = new OC_Image();
- $photo->loadFromFile(OC::$CONFIG_DATADIRECTORY.'/../gallery/'.$albumname.'.png');
- $offset = 3600 * 24; // 24 hour
- // calc the string in GMT not localtime and add the offset
- header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
- header('Cache-Control: max-age='.$offset.', must-revalidate');
- header('Pragma: public');
- $photo->show();
+ OC_Response::enableCaching(3600 * 24); // 24 hour
+ $thumbnail = OC::$CONFIG_DATADIRECTORY.'/../gallery/'.$albumname.'.png';
+ header('Content-Type: '.OC_Image::getMimeTypeForFile($thumbnail));
+ OC_Response::sendFile($thumbnail);
}
function handleGalleryScanning() {
- OC_JSON::checkLoggedIn();
OC_Gallery_Scanner::cleanup();
OC_JSON::success(array('albums' => OC_Gallery_Scanner::scan('/')));
}
function handleFilescan($cleanup) {
- OC_JSON::checkLoggedIn();
if ($cleanup) OC_Gallery_Album::cleanup();
$root = OC_Preferences::getValue(OC_User::getUser(), 'gallery', 'root', '').'/';
$pathlist = OC_Gallery_Scanner::find_paths($root);
@@ -69,7 +60,6 @@ function handleFilescan($cleanup) {
}
function handlePartialCreate($path) {
- OC_JSON::checkLoggedIn();
if (empty($path)) OC_JSON::error(array('cause' => 'No path specified'));
if (!OC_Filesystem::is_dir($path)) OC_JSON::error(array('cause' => 'Invalid path given'));
@@ -80,7 +70,6 @@ function handlePartialCreate($path) {
}
function handleStoreSettings($root, $order) {
- OC_JSON::checkLoggedIn();
if (!OC_Filesystem::file_exists($root)) {
OC_JSON::error(array('cause' => 'No such file or directory'));
return;
diff --git a/apps/gallery/ajax/thumbnail.php b/apps/gallery/ajax/thumbnail.php
index 2dfe936d9d..184171f8fc 100644
--- a/apps/gallery/ajax/thumbnail.php
+++ b/apps/gallery/ajax/thumbnail.php
@@ -29,10 +29,6 @@ $img = $_GET['img'];
$image = OC_Gallery_Photo::getThumbnail($img);
if ($image) {
- $offset = 3600 * 24; // 24 hour
- // calc the string in GMT not localtime and add the offset
- header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
- header('Cache-Control: max-age='.$offset.', must-revalidate');
- header('Pragma: public');
+ OC_Response::enableCaching(3600 * 24); // 24 hour
$image->show();
}
diff --git a/apps/gallery/lib/photo.php b/apps/gallery/lib/photo.php
index 15783cb341..4eb313bfc3 100644
--- a/apps/gallery/lib/photo.php
+++ b/apps/gallery/lib/photo.php
@@ -67,10 +67,6 @@ class OC_Gallery_Photo {
}
public static function getThumbnail($image_name) {
- $imagePath = OC_Filesystem::getLocalFile($image_name);
- if(!file_exists($imagePath)) {
- return null;
- }
$save_dir = OC_Config::getValue("datadirectory").'/'. OC_User::getUser() .'/gallery/';
$save_dir .= dirname($image_name). '/';
$image_name = basename($image_name);
@@ -78,6 +74,10 @@ class OC_Gallery_Photo {
if (file_exists($thumb_file)) {
$image = new OC_Image($thumb_file);
} else {
+ $imagePath = OC_Filesystem::getLocalFile($image_name);
+ if(!file_exists($imagePath)) {
+ return null;
+ }
$image = new OC_Image($imagePath);
if ($image->valid()) {
$image->centerCrop();
@@ -90,7 +90,6 @@ class OC_Gallery_Photo {
}
}
if ($image->valid()) {
- //var_dump($image, $image->resource());
return $image;
}
return null;
diff --git a/apps/media/ajax/api.php b/apps/media/ajax/api.php
index ac6739a138..bb4502690b 100644
--- a/apps/media/ajax/api.php
+++ b/apps/media/ajax/api.php
@@ -111,18 +111,11 @@ if($arguments['action']){
OC_MEDIA_COLLECTION::registerPlay($songId);
header('Content-Type:'.$ftype);
- // calc an offset of 24 hours
- $offset = 3600 * 24;
- // calc the string in GMT not localtime and add the offset
- $expire = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
- //output the HTTP header
- header($expire);
- header('Cache-Control: max-age=3600, must-revalidate');
- header('Pragma: public');
+ OC_Response::enableCaching(3600 * 24); // 24 hour
header('Accept-Ranges: bytes');
header('Content-Length: '.OC_Filesystem::filesize($arguments['path']));
- $gmt_mtime = gmdate('D, d M Y H:i:s', OC_Filesystem::filemtime($arguments['path']) ) . ' GMT';
- header("Last-Modified: " . $gmt_mtime );
+ $mtime = OC_Filesystem::filemtime($arguments['path']);
+ OC_Response::setLastModifiedHeader($mtime);
OC_Filesystem::readfile($arguments['path']);
exit;
diff --git a/apps/media/tomahawk.php b/apps/media/tomahawk.php
index 68401db67a..6dd41233f1 100644
--- a/apps/media/tomahawk.php
+++ b/apps/media/tomahawk.php
@@ -43,9 +43,7 @@ if(isset($_POST['play']) and $_POST['play']=='true'){
$song=OC_MEDIA_COLLECTION::getSong($_POST['song']);
$ftype=OC_Filesystem::getMimeType( $song['song_path'] );
header('Content-Type:'.$ftype);
- header('Expires: 0');
- header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
- header('Pragma: public');
+ OC_Response::disableCaching();
header('Content-Length: '.OC_Filesystem::filesize($song['song_path']));
OC_Filesystem::readfile($song['song_path']);
diff --git a/files/download.php b/files/download.php
index 71f91d352f..d1f5ba486d 100644
--- a/files/download.php
+++ b/files/download.php
@@ -41,9 +41,7 @@ $ftype=OC_Filesystem::getMimeType( $filename );
header('Content-Type:'.$ftype);
header('Content-Disposition: attachment; filename="'.basename($filename).'"');
-header('Expires: 0');
-header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
-header('Pragma: public');
+OC_Response::disableCaching();
header('Content-Length: '.OC_Filesystem::filesize($filename));
@ob_end_clean();
diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php
index b8b675c120..41acb48dfb 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/filecache.php b/lib/filecache.php
index 921d4a2790..6ae2f8253d 100644
--- a/lib/filecache.php
+++ b/lib/filecache.php
@@ -380,8 +380,7 @@ class OC_FileCache{
$fullOldPath=$root.$oldPath;
$fullNewPath=$root.$newPath;
if(($id=self::getFileId($fullOldPath))!=-1){
- $oldInfo=self::get($fullOldPath);
- $oldSize=$oldInfo['size'];
+ $oldSize=self::getCachedSize($oldPath,$root);
}else{
return;
}
diff --git a/lib/files.php b/lib/files.php
index 457c8ea38f..1f8331afb2 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 292d2a84e7..dcb516a3af 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 75997c244f..90195bc213 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 0f1c546f4c..91c6cd1772 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/helper.php b/lib/helper.php
index 4d1219d78d..6d3df6d97e 100644
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -75,18 +75,25 @@ class OC_Helper {
*
* Returns the path to the image.
*/
- public static function imagePath( $app, $image ){
- // Check if the app is in the app folder
- if( file_exists( OC::$SERVERROOT."/apps/$app/img/$image" )){
- return OC::$WEBROOT."/apps/$app/img/$image";
- }
- elseif( !empty( $app )){
- return OC::$WEBROOT."/$app/img/$image";
- }
- else{
- return OC::$WEBROOT."/core/img/$image";
- }
- }
+ public static function imagePath( $app, $image ){
+ // Read the selected theme from the config file
+ $theme=OC_Config::getValue( "theme" );
+
+ // Check if the app is in the app folder
+ if( file_exists( OC::$SERVERROOT."/themes/$theme/apps/$app/img/$image" )){
+ return OC::$WEBROOT."/themes/$theme/apps/$app/img/$image";
+ }elseif( file_exists( OC::$SERVERROOT."/apps/$app/img/$image" )){
+ return OC::$WEBROOT."/apps/$app/img/$image";
+ }elseif( !empty( $app ) and file_exists( OC::$SERVERROOT."/themes/$theme/$app/img/$image" )){
+ return OC::$WEBROOT."/themes/$theme/$app/img/$image";
+ }elseif( !empty( $app ) and file_exists( OC::$SERVERROOT."/$app/img/$image" )){
+ return OC::$WEBROOT."/$app/img/$image";
+ }elseif( file_exists( OC::$SERVERROOT."/themes/$theme/core/img/$image" )){
+ return OC::$WEBROOT."/themes/$theme/core/img/$image";
+ }else{
+ return OC::$WEBROOT."/core/img/$image";
+ }
+ }
/**
* @brief get path to icon of file type
diff --git a/lib/image.php b/lib/image.php
index 9081a3c702..fe8349be54 100644
--- a/lib/image.php
+++ b/lib/image.php
@@ -48,6 +48,16 @@ class OC_Image {
protected $imagetype = IMAGETYPE_PNG; // Default to png if file type isn't evident.
protected $filepath = null;
+ /**
+ * @brief Get mime type for an image file.
+ * @param $filepath The path to a local image file.
+ * @returns string The mime type if the it could be determined, otherwise an empty string.
+ */
+ 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 +112,7 @@ class OC_Image {
* @returns bool
*/
public function show() {
+ header('Content-Type: '.$this->mimeType());
return $this->_output();
}
@@ -117,17 +128,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;
@@ -278,24 +286,46 @@ class OC_Image {
/**
* @brief Loads an image from a local file, a base64 encoded string or a resource created by an imagecreate* function.
- * @param $imageref The path to a local file, a base64 encoded string or a resource created by an imagecreate* function.
+ * @param $imageref The path to a local file, a base64 encoded string or a resource created by an imagecreate* function or a file resource (file handle ).
* @returns An image resource or false on error
*/
public function load($imageref) {
- if($this->loadFromFile($imageref) !== false) {
+ if(is_resource($imageref)) {
+ if(get_resource_type($imageref) == 'gd') {
+ $this->resource = $res;
+ return $this->resource;
+ } elseif(in_array(get_resource_type($imageref), array('file','stream'))) {
+ return $this->loadFromFileHandle($imageref);
+ }
+ } elseif($this->loadFromFile($imageref) !== false) {
return $this->resource;
} elseif($this->loadFromBase64($imageref) !== false) {
return $this->resource;
} elseif($this->loadFromData($imageref) !== false) {
return $this->resource;
- } elseif($this->loadFromResource($imageref) !== false) {
- return $this->resource;
} else {
OC_Log::write('core',__METHOD__.'(): couldn\'t load anything. Giving up!', OC_Log::DEBUG);
return false;
}
}
+ /**
+ * @brief Loads an image from an open file handle.
+ * It is the responsibility of the caller to position the pointer at the correct place and to close the handle again.
+ * @param $handle
+ * @returns An image resource or false on error
+ */
+ public function loadFromFileHandle($handle) {
+ OC_Log::write('core',__METHOD__.'(): Trying', OC_Log::DEBUG);
+ $contents = '';
+ while (!feof($handle)) {
+ $contents .= fread($handle, 8192);
+ }
+ if($this->loadFromData($contents)) {
+ return $this->resource;
+ }
+ }
+
/**
* @brief Loads an image from a local file.
* @param $imageref The path to a local file.
@@ -421,18 +451,6 @@ class OC_Image {
}
}
- /**
- * @brief Checks if image resource is valid and assigns it to $this->resource.
- * @param $res An image resource.
- * @returns An image resource or false on error
- */
- public function loadFromResource($res) {
- if(!is_resource($res)) {
- return false;
- }
- $this->resource = $res;
- }
-
/**
* @brief Resizes the image preserving ratio.
* @param $maxsize The maximum size of either the width or height.
diff --git a/lib/response.php b/lib/response.php
index 7733168b5b..2fa0a5adcd 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() {
- header('Cache-Control: cache');
- header('Pragma: cache');
+ 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 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);
+ }
+ }
}
diff --git a/tests/data/logo-wide.png b/tests/data/logo-wide.png
new file mode 100644
index 0000000000..b2c16a0f60
Binary files /dev/null and b/tests/data/logo-wide.png differ
diff --git a/tests/data/logo-wide.svg b/tests/data/logo-wide.svg
new file mode 100644
index 0000000000..73b37cc7aa
--- /dev/null
+++ b/tests/data/logo-wide.svg
@@ -0,0 +1,875 @@
+
+
+
+