]> source.dussan.org Git - nextcloud-server.git/commitdiff
port oc_response
authorFrank Karlitschek <frank@owncloud.org>
Thu, 3 May 2012 08:46:27 +0000 (10:46 +0200)
committerFrank Karlitschek <frank@owncloud.org>
Thu, 3 May 2012 08:46:27 +0000 (10:46 +0200)
12 files changed:
apps/calendar/lib/app.php
apps/contacts/lib/app.php
apps/contacts/photo.php
apps/contacts/thumbnail.php
apps/files/download.php
apps/files_sharing/get.php
apps/gallery/ajax/galleryOp.php
apps/gallery/ajax/sharing.php
apps/gallery/ajax/thumbnail.php [changed mode: 0644->0755]
apps/media/ajax/api.php
apps/media/tomahawk.php
lib/public/response.php [new file with mode: 0644]

index f3e9bea86a3e21a0248bc677c60b838b50ca03c8..8e2679a43f4504252327687a3da5cbd399f53ab8 100755 (executable)
@@ -334,8 +334,8 @@ class OC_Calendar_App{
                        $calendar_id = $_GET['calendar_id'];
                        if (is_numeric($calendar_id)) {
                                $calendar = self::getCalendar($calendar_id);
-                               OC_Response::enableCaching(0);
-                               OC_Response::setETagHeader($calendar['ctag']);
+                               OCP\Response::enableCaching(0);
+                               OCP\Response::setETagHeader($calendar['ctag']);
                                $events = OC_Calendar_Object::allInPeriod($calendar_id, $start, $end);
                        } else {
                                OC_Hook::emit('OC_Calendar', 'getEvents', array('calendar_id' => $calendar_id, 'events' => &$events));
index 636b9a84b9d3d9de7fee582dfe7655b4db51b5ed..f4b9562605e268fa0b2346f79905b841d2f28db9 100755 (executable)
@@ -176,7 +176,7 @@ class OC_Contacts_App {
                $rev = $contact->getAsString('REV');
                if ($rev) {
                        $rev = DateTime::createFromFormat(DateTime::W3C, $rev);
-                       OC_Response::setLastModifiedHeader($rev);
+                       OCP\Response::setLastModifiedHeader($rev);
                }
        }
 }
index 60723b7f0b554a279d2ac1b5f7ae2c3bee712f19..6fe68cefb6d0ce4dd5894160ac2b4f1e6e05adef 100755 (executable)
@@ -14,9 +14,9 @@ OCP\User::checkLoggedIn();
 OCP\App::checkAppEnabled('contacts');
 
 function getStandardImage(){
-       OC_Response::setExpiresHeader('P10D');
-       OC_Response::enableCaching();
-       OC_Response::redirect(OCP\Util::imagePath('contacts', 'person_large.png'));
+       OCP\Response::setExpiresHeader('P10D');
+       OCP\Response::enableCaching();
+       OCP\Response::redirect(OCP\Util::imagePath('contacts', 'person_large.png'));
 }
 
 $id = isset($_GET['id']) ? $_GET['id'] : null;
@@ -35,19 +35,19 @@ if(!$image) {
 if( is_null($contact)) {
        OCP\Util::writeLog('contacts','photo.php. The VCard for ID '.$id.' is not RFC compatible',OCP\Util::ERROR);
 } else {
-       OC_Response::enableCaching($caching);
+       OCP\Response::enableCaching($caching);
        OC_Contacts_App::setLastModifiedHeader($contact);
 
        // Photo :-)
        if($image->loadFromBase64($contact->getAsString('PHOTO'))) {
                // OK
-               OC_Response::setETagHeader(md5($contact->getAsString('PHOTO')));
+               OCP\Response::setETagHeader(md5($contact->getAsString('PHOTO')));
        }
        else
        // Logo :-/
        if($image->loadFromBase64($contact->getAsString('LOGO'))) {
                // OK
-               OC_Response::setETagHeader(md5($contact->getAsString('LOGO')));
+               OCP\Response::setETagHeader(md5($contact->getAsString('LOGO')));
        }
        if ($image->valid()) {
                $max_size = 200;
index cf54b4ffd4fa79f216d7818e351906b4b462ab47..d7bf1fd8c3c2d72d043e0893a21bc8d517a59e60 100755 (executable)
@@ -27,9 +27,9 @@ OC_JSON::checkLoggedIn();
 OCP\App::checkAppEnabled('contacts');
 
 function getStandardImage(){
-       OC_Response::setExpiresHeader('P10D');
-       OC_Response::enableCaching();
-       OC_Response::redirect(OCP\Util::imagePath('contacts', 'person.png'));
+       OCP\Response::setExpiresHeader('P10D');
+       OCP\Response::enableCaching();
+       OCP\Response::redirect(OCP\Util::imagePath('contacts', 'person.png'));
 }
 
 if(!function_exists('imagecreatefromjpeg')) {
@@ -49,7 +49,7 @@ if(is_null($contact)){
        getStandardImage();
        exit();
 }
-OC_Response::enableCaching($caching);
+OCP\Response::enableCaching($caching);
 OC_Contacts_App::setLastModifiedHeader($contact);
 
 $thumbnail_size = 23;
@@ -58,7 +58,7 @@ $thumbnail_size = 23;
 $image = new OC_Image();
 $photo = $contact->getAsString('PHOTO');
 if($photo) {
-       OC_Response::setETagHeader(md5($photo));
+       OCP\Response::setETagHeader(md5($photo));
 
        if($image->loadFromBase64($photo)) {
                if($image->centerCrop()) {
index a4077b9f0428024cf28760ca642a989de89b7d3d..e98cf2ecd312037b13c839e0512ae3d0e3cfa2bf 100755 (executable)
@@ -41,7 +41,7 @@ $ftype=OC_Filesystem::getMimeType( $filename );
 
 header('Content-Type:'.$ftype);
 header('Content-Disposition: attachment; filename="'.basename($filename).'"');
-OC_Response::disableCaching();
+OCP\Response::disableCaching();
 header('Content-Length: '.OC_Filesystem::filesize($filename));
 
 @ob_end_clean();
index a741139b929dd37eb11a8e529ce559bfad7942f8..b17dc85c5baecc89465e1ed5c67fa50e676e3538 100755 (executable)
@@ -68,7 +68,7 @@ if ($source !== false) {
                //get time mimetype and set the headers
                $mimetype = OC_Filesystem::getMimeType($source);
                header("Content-Transfer-Encoding: binary");
-               OC_Response::disableCaching();
+               OCP\Response::disableCaching();
                header('Content-Disposition: filename="'.basename($source).'"');
                header("Content-Type: " . $mimetype);
                header("Content-Length: " . OC_Filesystem::filesize($source));
index 75b18c6f7bf48bdb5ebdf1ae207ab004a13c62f8..c302a3a734c7fbb3bc65910df89133feaaf0121c 100755 (executable)
@@ -41,10 +41,10 @@ function handleRemove($name) {
 }
 
 function handleGetThumbnails($albumname) {
-  OC_Response::enableCaching(3600 * 24); // 24 hour
+  OCP\Response::enableCaching(3600 * 24); // 24 hour
   $thumbnail = OC::$CONFIG_DATADIRECTORY.'/../gallery/'.urldecode($albumname).'.png';
   header('Content-Type: '.OC_Image::getMimeTypeForFile($thumbnail));
-  OC_Response::sendFile($thumbnail);
+  OCP\Response::sendFile($thumbnail);
 }
 
 function handleGalleryScanning() {
index 04de57eb1778b51ea386ebde03c565a13626adbf..a1af75ad461171f9cd88198d6bebd02f68ff318f 100755 (executable)
@@ -72,7 +72,7 @@ function handleGetThumbnail($token, $imgpath) {
   $owner = OC_Gallery_Sharing::getTokenOwner($token);
   $image = OC_Gallery_Photo::getThumbnail($imgpath, $owner);
   if ($image) {
-    OC_Response::enableCaching(3600 * 24); // 24 hour
+    OCP\Response::enableCaching(3600 * 24); // 24 hour
     $image->show();
   }
 }
@@ -86,7 +86,7 @@ function handleGetAlbumThumbnail($token, $albumname)
     $image->centerCrop();
     $image->resize(200);
     $image->fixOrientation();
-    OC_Response::enableCaching(3600 * 24); // 24 hour
+    OCP\Response::enableCaching(3600 * 24); // 24 hour
     $image->show();
   }
 }
@@ -95,7 +95,7 @@ function handleGetPhoto($token, $photo) {
   $owner = OC_Gallery_Sharing::getTokenOwner($token);
   $file = OCP\Config::getSystemValue( "datadirectory", OC::$SERVERROOT."/data" ).'/'.$owner.'/files'.urldecode($photo);
   header('Content-Type: '.OC_Image::getMimeTypeForFile($file));
-  OC_Response::sendFile($file);
+  OCP\Response::sendFile($file);
 }
 
 switch ($operation) {
old mode 100644 (file)
new mode 100755 (executable)
index bf42fd2..92e9fd4
@@ -29,6 +29,6 @@ $img = $_GET['img'];
 
 $image = OC_Gallery_Photo::getThumbnail($img);
 if ($image) {
-       OC_Response::enableCaching(3600 * 24); // 24 hour
+       OCP\Response::enableCaching(3600 * 24); // 24 hour
        $image->show();
 }
index d648e6fe975e005b667f8d24c14b0038c5ae2b2f..95259fdefa068f51ccd19c13557cae2867305ec0 100755 (executable)
@@ -110,11 +110,11 @@ if($arguments['action']){
                        OC_MEDIA_COLLECTION::registerPlay($songId);
                        
                        header('Content-Type:'.$ftype);
-                       OC_Response::enableCaching(3600 * 24); // 24 hour
+                       OCP\Response::enableCaching(3600 * 24); // 24 hour
                        header('Accept-Ranges: bytes');
                        header('Content-Length: '.OC_Filesystem::filesize($arguments['path']));
                        $mtime = OC_Filesystem::filemtime($arguments['path']);
-                       OC_Response::setLastModifiedHeader($mtime);
+                       OCP\Response::setLastModifiedHeader($mtime);
                        
                        OC_Filesystem::readfile($arguments['path']);
                        exit;
index af97c444eb5b92b20c9bf9769024c54032059a1c..d4f5ac6afadb15e4682101a43ca986fbfbdf6ef0 100755 (executable)
@@ -43,7 +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);
-       OC_Response::disableCaching();
+       OCP\Response::disableCaching();
        header('Content-Length: '.OC_Filesystem::filesize($song['song_path']));
 
        OC_Filesystem::readfile($song['song_path']);
diff --git a/lib/public/response.php b/lib/public/response.php
new file mode 100644 (file)
index 0000000..2efa74e
--- /dev/null
@@ -0,0 +1,106 @@
+<?php
+/**
+* ownCloud
+*
+* @author Frank Karlitschek
+* @copyright 2010 Frank Karlitschek karlitschek@kde.org
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library.  If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+/**
+ * Public interface of ownCloud for apps to use.
+ * Response Class.
+ *
+ */
+
+// use OCP namespace for all classes that are considered public. 
+// This means that they should be used by apps instead of the internal ownCloud classes
+namespace OCP;
+
+class Response {
+
+
+       /**
+       * @brief Enable response caching by sending correct HTTP headers
+       * @param $cache_time time to cache the response
+       *  >0           cache time in seconds
+       *  0 and <0     enable default browser caching
+       *  null         cache indefinitly
+       */
+       static public function enableCaching($cache_time = null) {
+               return(\OC_Response::enableCaching($cache_time));
+       }
+
+
+       /**
+       * Checks and set Last-Modified header, when the request matches sends a
+       * 'not modified' response
+       * @param $lastModified time when the reponse was last modified
+       */
+       static public function setLastModifiedHeader($lastModified) {
+               return(\OC_Response::setLastModifiedHeader($lastModified));
+       }
+
+
+       /**
+       * @brief disable browser caching
+       * @see enableCaching with cache_time = 0
+       */
+       static public function disableCaching() {
+               return(\OC_Response::disableCaching());
+       }
+
+
+       /**
+       * Checks and set ETag header, when the request matches sends a
+       * 'not modified' response
+       * @param $etag token to use for modification check
+       */
+       static public function setETagHeader($etag) {
+               return(\OC_Response::setETagHeader($etag));
+       }
+
+
+       /**
+       * @brief Send file as response, checking and setting caching headers
+       * @param $filepath of file to send
+       */
+       static public function sendFile($filepath) {
+               return(\OC_Response::sendFile($filepath));
+       }
+
+       /**
+       * @brief Set reponse expire time
+       * @param $expires date-time when the response expires
+       *  string for DateInterval from now
+       *  DateTime object when to expire response
+       */
+       static public function setExpiresHeader($expires) {
+               return(\OC_Response::setExpiresHeader($expires));
+       }
+
+       /**
+       * @brief Send redirect response
+       * @param $location to redirect to
+       */
+       static public function redirect($location) {
+               return(\OC_Response::redirect($location));
+       }
+
+
+}
+
+?>