diff options
author | Klaas Freitag <freitag@owncloud.com> | 2012-02-14 10:01:20 +0100 |
---|---|---|
committer | Klaas Freitag <freitag@owncloud.com> | 2012-02-14 10:01:20 +0100 |
commit | 064f87680b15b64703f972e9a654e402de197f8f (patch) | |
tree | 3fe49af4e8aa3a5198a8e881506603188ef6141c /apps | |
parent | 60a03580fff65d969faea8e5788b278ed8b15481 (diff) | |
parent | f7161bb48b6bb71b04f4167f8c4cfb4096824ed8 (diff) | |
download | nextcloud-server-064f87680b15b64703f972e9a654e402de197f8f.tar.gz nextcloud-server-064f87680b15b64703f972e9a654e402de197f8f.zip |
Merge branch 'master' of gitorious.org:owncloud/owncloud
Diffstat (limited to 'apps')
-rw-r--r-- | apps/contacts/contacts.php | 62 | ||||
-rw-r--r-- | apps/contacts/index.php | 73 | ||||
-rw-r--r-- | apps/contacts/js/contacts.js | 15 | ||||
-rw-r--r-- | apps/contacts/lib/vcard.php | 69 | ||||
-rw-r--r-- | apps/contacts/photo.php | 1 | ||||
-rw-r--r-- | apps/contacts/templates/index.php | 4 | ||||
-rw-r--r-- | apps/contacts/templates/index2.php | 27 | ||||
-rw-r--r-- | apps/contacts/thumbnail.php | 32 | ||||
-rw-r--r-- | apps/external/index.php | 7 | ||||
-rw-r--r-- | apps/files_sharing/get.php | 4 | ||||
-rw-r--r-- | apps/gallery/ajax/cover.php | 81 | ||||
-rw-r--r-- | apps/gallery/ajax/galleryOp.php | 23 | ||||
-rw-r--r-- | apps/gallery/ajax/thumbnail.php | 6 | ||||
-rw-r--r-- | apps/gallery/lib/photo.php | 9 | ||||
-rw-r--r-- | apps/media/ajax/api.php | 13 | ||||
-rw-r--r-- | apps/media/tomahawk.php | 4 |
16 files changed, 143 insertions, 287 deletions
diff --git a/apps/contacts/contacts.php b/apps/contacts/contacts.php deleted file mode 100644 index 938a6b13a04..00000000000 --- a/apps/contacts/contacts.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php -require_once('../../lib/base.php'); - -// Check if we are a user -OC_Util::checkLoggedIn(); -// Get active address books. This creates a default one if none exists. -$ids = OC_Contacts_Addressbook::activeIds(OC_User::getUser()); -$contacts = OC_Contacts_VCard::all($ids); - -$addressbooks = OC_Contacts_Addressbook::active(OC_User::getUser()); - -// Load the files we need -OC_App::setActiveNavigationEntry( 'contacts_index' ); - -// Load a specific user? -$id = isset( $_GET['id'] ) ? $_GET['id'] : null; -$details = array(); - -// FIXME: This cannot work..? -if(is_null($id) && count($contacts) > 0) { - $id = $contacts[0]['id']; -} -if(!is_null($id)) { - $vcard = OC_Contacts_App::getContactVCard($id); - $details = OC_Contacts_VCard::structureContact($vcard); -} -$property_types = OC_Contacts_App::getAddPropertyOptions(); -$phone_types = OC_Contacts_App::getTypesOfProperty('TEL'); - -$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize')); -$post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size')); -$maxUploadFilesize = min($upload_max_filesize, $post_max_size); - -$freeSpace=OC_Filesystem::free_space('/'); -$freeSpace=max($freeSpace,0); -$maxUploadFilesize = min($maxUploadFilesize ,$freeSpace); - -OC_Util::addScript('','jquery.multiselect'); -//OC_Util::addScript('contacts','interface'); -OC_Util::addScript('contacts','contacts'); -OC_Util::addScript('contacts','jquery.combobox'); -OC_Util::addScript('contacts','jquery.inview'); -OC_Util::addScript('contacts','jquery.Jcrop'); -OC_Util::addScript('contacts','jquery.jec-1.3.3'); -OC_Util::addStyle('','jquery.multiselect'); -//OC_Util::addStyle('contacts','styles'); -OC_Util::addStyle('contacts','jquery.combobox'); -OC_Util::addStyle('contacts','jquery.Jcrop'); -OC_Util::addStyle('contacts','contacts'); - -$tmpl = new OC_Template( "contacts", "index2", "user" ); -$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); -$tmpl->assign('uploadMaxHumanFilesize', OC_Helper::humanFileSize($maxUploadFilesize)); -$tmpl->assign('property_types',$property_types); -$tmpl->assign('phone_types',$phone_types); -$tmpl->assign('addressbooks', $addressbooks); -$tmpl->assign('contacts', $contacts); -$tmpl->assign('details', $details ); -$tmpl->assign('id',$id); -$tmpl->printPage(); - -?> diff --git a/apps/contacts/index.php b/apps/contacts/index.php index 9012e5d8af8..c5115d16074 100644 --- a/apps/contacts/index.php +++ b/apps/contacts/index.php @@ -1,36 +1,15 @@ <?php /** - * ownCloud - Addressbook - * - * @author Jakob Sack - * @copyright 2011 Jakob Sack mail@jakobsack.de - * - * 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/>. - * + * Copyright (c) 2012 Thomas Tanghus <thomas@tanghus.net> + * Copyright (c) 2011 Jakob Sack mail@jakobsack.de + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. */ - -function contacts_namesort($a,$b){ - return strcmp($a['fullname'],$b['fullname']); -} - -// Init owncloud require_once('../../lib/base.php'); // Check if we are a user OC_Util::checkLoggedIn(); -OC_Util::checkAppEnabled('contacts'); - // Get active address books. This creates a default one if none exists. $ids = OC_Contacts_Addressbook::activeIds(OC_User::getUser()); $contacts = OC_Contacts_VCard::all($ids); @@ -47,33 +26,41 @@ $details = array(); if(is_null($id) && count($contacts) > 0) { $id = $contacts[0]['id']; } -$vcard = null; -$details = null; if(!is_null($id)) { $vcard = OC_Contacts_App::getContactVCard($id); - if(!is_null($vcard)) { - $details = OC_Contacts_VCard::structureContact($vcard); - } + $details = OC_Contacts_VCard::structureContact($vcard); } - -// Include Style and Script -OC_Util::addScript('contacts','interface'); -OC_Util::addScript('contacts','jquery.inview'); -OC_Util::addScript('', 'jquery.multiselect'); -OC_Util::addStyle('contacts','styles'); -//OC_Util::addStyle('contacts','formtastic'); - $property_types = OC_Contacts_App::getAddPropertyOptions(); -$adr_types = OC_Contacts_App::getTypesOfProperty('ADR'); $phone_types = OC_Contacts_App::getTypesOfProperty('TEL'); -// Process the template -$tmpl = new OC_Template( 'contacts', 'index', 'user' ); +$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize')); +$post_max_size = OC_Helper::computerFileSize(ini_get('post_max_size')); +$maxUploadFilesize = min($upload_max_filesize, $post_max_size); + +$freeSpace=OC_Filesystem::free_space('/'); +$freeSpace=max($freeSpace,0); +$maxUploadFilesize = min($maxUploadFilesize ,$freeSpace); + +OC_Util::addScript('','jquery.multiselect'); +OC_Util::addScript('contacts','contacts'); +OC_Util::addScript('contacts','jquery.combobox'); +OC_Util::addScript('contacts','jquery.inview'); +OC_Util::addScript('contacts','jquery.Jcrop'); +OC_Util::addStyle('','jquery.multiselect'); +//OC_Util::addStyle('contacts','styles'); +OC_Util::addStyle('contacts','jquery.combobox'); +OC_Util::addStyle('contacts','jquery.Jcrop'); +OC_Util::addStyle('contacts','contacts'); + +$tmpl = new OC_Template( "contacts", "index", "user" ); +$tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); +$tmpl->assign('uploadMaxHumanFilesize', OC_Helper::humanFileSize($maxUploadFilesize)); $tmpl->assign('property_types',$property_types); -$tmpl->assign('adr_types',$adr_types); $tmpl->assign('phone_types',$phone_types); $tmpl->assign('addressbooks', $addressbooks); $tmpl->assign('contacts', $contacts); $tmpl->assign('details', $details ); $tmpl->assign('id',$id); $tmpl->printPage(); + +?> diff --git a/apps/contacts/js/contacts.js b/apps/contacts/js/contacts.js index 9071038b50a..d61489b63c3 100644 --- a/apps/contacts/js/contacts.js +++ b/apps/contacts/js/contacts.js @@ -3,6 +3,21 @@ function ucwords (str) { return $1.toUpperCase(); }); } +/* TODO: Test this. + * http://snipplr.com/view/45323/remove-duplicate-values-from-array/ +Array.prototype.unique = function unique() { + var i = 0; + while (i < this.length) { + var current = this[i]; + for (k = this.length; k > i; k--) { + if (this[k] === current) { + this.splice(k,1); + } + } i++; + } + return this; +} +*/ String.prototype.strip_tags = function(){ tags = this; diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index f9ca427354e..ece203bd458 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -47,6 +47,7 @@ class OC_Contacts_VCard{ * ['carddata'] */ public static function all($id){ + $result = null; if(is_array($id)) { $id_sql = join(',', array_fill(0, count($id), '?')); $prep = 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid IN ('.$id_sql.') ORDER BY fullname'; @@ -58,13 +59,20 @@ class OC_Contacts_VCard{ OC_Log::write('contacts','OC_Contacts_VCard:all, ids: '.join(',', $id),OC_Log::DEBUG); OC_Log::write('contacts','SQL:'.$prep,OC_Log::DEBUG); } - } else { - $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? ORDER BY fullname' ); - $result = $stmt->execute(array($id)); + } elseif($id) { + try { + $stmt = OC_DB::prepare( 'SELECT * FROM *PREFIX*contacts_cards WHERE addressbookid = ? ORDER BY fullname' ); + $result = $stmt->execute(array($id)); + } catch(Exception $e) { + OC_Log::write('contacts','OC_Contacts_VCard:all:, exception: '.$e->getMessage(),OC_Log::DEBUG); + OC_Log::write('contacts','OC_Contacts_VCard:all, ids: '. $id,OC_Log::DEBUG); + } } $cards = array(); - while( $row = $result->fetchRow()){ - $cards[] = $row; + if(!is_null($result)) { + while( $row = $result->fetchRow()){ + $cards[] = $row; + } } return $cards; @@ -124,10 +132,9 @@ class OC_Contacts_VCard{ OC_Log::write('contacts','OC_Contacts_VCard::add. Added missing \'N\' field: '.$n,OC_Log::DEBUG); } $uid = $card->getAsString('UID'); - if(is_null($uid)){ + if(!$uid){ $card->setUID(); $uid = $card->getAsString('UID'); - //$data = $card->serialize(); }; $uri = $uid.'.vcf'; @@ -176,7 +183,7 @@ class OC_Contacts_VCard{ * @return insertid */ public static function addFromDAVData($id,$uri,$data){ - $fn = $n = null; + $fn = $n = $uid = null; $email = null; $card = OC_VObject::parse($data); if(!is_null($card)){ @@ -187,6 +194,9 @@ class OC_Contacts_VCard{ if($property->name == 'N'){ $n = $property->value; } + if($property->name == 'UID'){ + $uid = $property->value; + } if($property->name == 'EMAIL' && is_null($email)){ $email = $property->value; } @@ -210,6 +220,10 @@ class OC_Contacts_VCard{ $data = $card->serialize(); OC_Log::write('contacts','OC_Contacts_VCard::add. Added missing \'N\' field: '.$n,OC_Log::DEBUG); } + if(!$uid) { + $card->setUID(); + $data = $card->serialize(); + } $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' ); $result = $stmt->execute(array($id,$fn,$data,$uri,time())); @@ -384,4 +398,43 @@ class OC_Contacts_VCard{ } return $temp; } + + /** + * @brief Move card(s) to an address book + * @param integer $aid Address book id + * @param $id Array or integer of cards to be moved. + * @return boolean + * + */ + public static function moveToAddressBook($aid, $id){ + OC_Contacts_App::getAddressbook($aid); // check for user ownership. + if(is_array($id)) { + $id_sql = join(',', array_fill(0, count($id), '?')); + $prep = 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id IN ('.$id_sql.')'; + try { + $stmt = OC_DB::prepare( $prep ); + //$aid = array($aid); + $vals = array_merge((array)$aid, $id); + $result = $stmt->execute($vals); + } catch(Exception $e) { + OC_Log::write('contacts','OC_Contacts_VCard::moveToAddressBook:, exception: '.$e->getMessage(),OC_Log::DEBUG); + OC_Log::write('contacts','OC_Contacts_VCard::moveToAddressBook, ids: '.join(',', $vals),OC_Log::DEBUG); + OC_Log::write('contacts','SQL:'.$prep,OC_Log::DEBUG); + return false; + } + } else { + try { + $stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?' ); + $result = $stmt->execute(array($aid, $id)); + } catch(Exception $e) { + OC_Log::write('contacts','OC_Contacts_VCard::moveToAddressBook:, exception: '.$e->getMessage(),OC_Log::DEBUG); + OC_Log::write('contacts','OC_Contacts_VCard::moveToAddressBook, id: '.$id,OC_Log::DEBUG); + return false; + } + } + + OC_Contacts_Addressbook::touch($aid); + return true; + } + } diff --git a/apps/contacts/photo.php b/apps/contacts/photo.php index 314bce7cecc..8dfbcb6fb10 100644 --- a/apps/contacts/photo.php +++ b/apps/contacts/photo.php @@ -21,6 +21,7 @@ $image = new OC_Image(); if( is_null($contact)) { OC_Log::write('contacts','photo.php. The VCard for ID '.$id.' is not RFC compatible',OC_Log::ERROR); } else { + OC_Response::enableCaching(); OC_Contacts_App::setLastModifiedHeader($contact); // Photo :-) diff --git a/apps/contacts/templates/index.php b/apps/contacts/templates/index.php index 5d9c312712f..4c0dfad6177 100644 --- a/apps/contacts/templates/index.php +++ b/apps/contacts/templates/index.php @@ -15,10 +15,10 @@ <div id="rightcontent" class="rightcontent" data-id="<?php echo $_['id']; ?>"> <?php if ($_['id']){ - echo $this->inc("part.details"); + echo $this->inc('part.contact'); } else{ - echo $this->inc("part.addcardform"); + echo $this->inc('part.no_contacts'); } ?> </div> diff --git a/apps/contacts/templates/index2.php b/apps/contacts/templates/index2.php deleted file mode 100644 index 4c0dfad6177..00000000000 --- a/apps/contacts/templates/index2.php +++ /dev/null @@ -1,27 +0,0 @@ -<script type='text/javascript'> - var totalurl = '<?php echo OC_Helper::linkTo('contacts', 'carddav.php', null, true); ?>/addressbooks'; -</script> -<div id="controls"> - <form> - <input type="button" id="contacts_newcontact" value="<?php echo $l->t('Add Contact'); ?>"> - <input type="button" id="chooseaddressbook" value="<?php echo $l->t('Addressbooks'); ?>"> - </form> -</div> -<div id="leftcontent" class="leftcontent"> - <ul id="contacts"> - <?php echo $this->inc("part.contacts"); ?> - </ul> -</div> -<div id="rightcontent" class="rightcontent" data-id="<?php echo $_['id']; ?>"> - <?php - if ($_['id']){ - echo $this->inc('part.contact'); - } - else{ - echo $this->inc('part.no_contacts'); - } - ?> -</div> -<!-- Dialogs --> -<div id="dialog_holder"></div> -<!-- End of Dialogs --> diff --git a/apps/contacts/thumbnail.php b/apps/contacts/thumbnail.php index c020c29ac8c..5082626499b 100644 --- a/apps/contacts/thumbnail.php +++ b/apps/contacts/thumbnail.php @@ -48,6 +48,7 @@ if(is_null($contact)){ getStandardImage(); exit(); } +OC_Response::enableCaching(); OC_Contacts_App::setLastModifiedHeader($contact); $thumbnail_size = 23; @@ -55,25 +56,26 @@ $thumbnail_size = 23; // Find the photo from VCard. $image = new OC_Image(); $photo = $contact->getAsString('PHOTO'); +if($photo) { + OC_Response::setETagHeader(md5($photo)); -OC_Response::setETagHeader(md5($photo)); - -if($image->loadFromBase64($photo)) { - if($image->centerCrop()) { - if($image->resize($thumbnail_size)) { - if($image->show()) { - // done - exit(); + if($image->loadFromBase64($photo)) { + if($image->centerCrop()) { + if($image->resize($thumbnail_size)) { + if($image->show()) { + // done + exit(); + } else { + OC_Log::write('contacts','thumbnail.php. Couldn\'t display thumbnail for ID '.$id,OC_Log::ERROR); + } } else { - OC_Log::write('contacts','thumbnail.php. Couldn\'t display thumbnail for ID '.$id,OC_Log::ERROR); + OC_Log::write('contacts','thumbnail.php. Couldn\'t resize thumbnail for ID '.$id,OC_Log::ERROR); } - } else { - OC_Log::write('contacts','thumbnail.php. Couldn\'t resize thumbnail for ID '.$id,OC_Log::ERROR); + }else{ + OC_Log::write('contacts','thumbnail.php. Couldn\'t crop thumbnail for ID '.$id,OC_Log::ERROR); } - }else{ - OC_Log::write('contacts','thumbnail.php. Couldn\'t crop thumbnail for ID '.$id,OC_Log::ERROR); + } else { + OC_Log::write('contacts','thumbnail.php. Couldn\'t load image string for ID '.$id,OC_Log::ERROR); } -} else { - OC_Log::write('contacts','thumbnail.php. Couldn\'t load image string for ID '.$id,OC_Log::ERROR); } getStandardImage(); diff --git a/apps/external/index.php b/apps/external/index.php index 86b19abc10e..51cdc344bbf 100644 --- a/apps/external/index.php +++ b/apps/external/index.php @@ -23,12 +23,7 @@ require_once('../../lib/base.php'); -// Check if we are a user -if( !OC_User::isLoggedIn()){ - header( "Location: ".OC_Helper::linkTo( '', 'index.php' )); - exit(); -} - +OC_Util::checkLoggedIn(); if(isset($_GET['id'])){ diff --git a/apps/files_sharing/get.php b/apps/files_sharing/get.php index c80b0c2ef03..3a3db6dd38e 100644 --- a/apps/files_sharing/get.php +++ b/apps/files_sharing/get.php @@ -67,9 +67,7 @@ if ($source !== false) { //get time mimetype and set the headers $mimetype = OC_Filesystem::getMimeType($source); 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(); header('Content-Disposition: filename="'.basename($source).'"'); header("Content-Type: " . $mimetype); header("Content-Length: " . OC_Filesystem::filesize($source)); diff --git a/apps/gallery/ajax/cover.php b/apps/gallery/ajax/cover.php deleted file mode 100644 index 068a6e9c4ec..00000000000 --- a/apps/gallery/ajax/cover.php +++ /dev/null @@ -1,81 +0,0 @@ -<?php - -/** -* ownCloud - gallery application -* -* @author Bartek Przybylski -* @copyright 2012 Bartek Przybylski bart.p.pl@gmail.com -* -* 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 Lesser General Public -* License along with this library. If not, see <http://www.gnu.org/licenses/>. -* -*/ - -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 8df692c7735..5ac6d295108 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 2dfe936d9dd..184171f8fca 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 15783cb341a..4eb313bfc33 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 ac6739a1386..bb4502690b5 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 68401db67ae..6dd41233f12 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']); |