From e4028960013836620afedf1ecfbde9e7637b22f1 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 13 Feb 2012 22:30:27 +0100 Subject: [PATCH 01/22] Gallery: Remove autoloaded includes from galleryOp.php --- apps/gallery/ajax/galleryOp.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php index 8df692c7735..c0623c90d94 100644 --- a/apps/gallery/ajax/galleryOp.php +++ b/apps/gallery/ajax/galleryOp.php @@ -22,8 +22,7 @@ */ require_once('../../../lib/base.php'); -require_once(OC::$CLASSPATH['OC_Gallery_Album']); -require_once(OC::$CLASSPATH['OC_Gallery_Scanner']); + OC_JSON::checkAppEnabled('gallery'); function handleRename($oldname, $newname) { From e084386770167945b77559ca3d291b6cad39acf6 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 13 Feb 2012 22:32:27 +0100 Subject: [PATCH 02/22] Gallery: Move login check to beginning of galleryOp.php --- apps/gallery/ajax/galleryOp.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php index c0623c90d94..db6c79d6cdc 100644 --- a/apps/gallery/ajax/galleryOp.php +++ b/apps/gallery/ajax/galleryOp.php @@ -23,16 +23,15 @@ require_once('../../../lib/base.php'); +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']; @@ -41,7 +40,6 @@ 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 @@ -53,13 +51,11 @@ function handleGetThumbnails($albumname) { } 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); @@ -68,7 +64,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')); @@ -79,7 +74,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; From 7208abf6184ddb1f5628c4665a848d5f1e04622b Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 13 Feb 2012 22:35:48 +0100 Subject: [PATCH 03/22] OC_Response: fix var name bugs --- lib/response.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/response.php b/lib/response.php index 7733168b5b9..f0d1aaab530 100644 --- a/lib/response.php +++ b/lib/response.php @@ -46,12 +46,12 @@ 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 = $expires->format(DateTime::RFC2822); } - header('Expires: '.expires); + header('Expires: '.$expires); } static public function setETagHeader($etag) { From 363fdc40b82f5e7ba0de7a11f031bc8d86af68be Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 13 Feb 2012 22:37:27 +0100 Subject: [PATCH 04/22] OC_Response: Set Expire and Cache-Control headers in enableCaching --- lib/response.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/response.php b/lib/response.php index f0d1aaab530..b5fca1cb227 100644 --- a/lib/response.php +++ b/lib/response.php @@ -11,9 +11,23 @@ class OC_Response { const STATUS_NOT_MODIFIED = 304; const STATUS_TEMPORARY_REDIRECT = 307; - 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 setStatus($status) { From e137020f67f97bb04e59c04205e1815229d95fae Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 13 Feb 2012 22:38:34 +0100 Subject: [PATCH 05/22] Gallery: Use OC_Respone::enableCaching for (album)thumbnails --- apps/gallery/ajax/galleryOp.php | 6 +----- apps/gallery/ajax/thumbnail.php | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php index db6c79d6cdc..9273de2599d 100644 --- a/apps/gallery/ajax/galleryOp.php +++ b/apps/gallery/ajax/galleryOp.php @@ -40,13 +40,9 @@ function handleRemove($name) { } function handleGetThumbnails($albumname) { + OC_Response::enableCaching(3600 * 24); // 24 hour $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(); } 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(); } From 169ddc5b0b14697088ca394eb07fa7c8473b1fcc Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 13 Feb 2012 22:39:30 +0100 Subject: [PATCH 06/22] Gallery: Only get local file when generating photo thumbnail --- apps/gallery/lib/photo.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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; From 0fd5252cfc7c6d85d27bf1ec62fadbbc3267c0a1 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 13 Feb 2012 22:41:05 +0100 Subject: [PATCH 07/22] OC_Image: Move Content-Type header to show function --- lib/image.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/image.php b/lib/image.php index 9081a3c7021..df8f76352a0 100644 --- a/lib/image.php +++ b/lib/image.php @@ -102,6 +102,7 @@ class OC_Image { * @returns bool */ public function show() { + header('Content-Type: '.$this->mimeType()); return $this->_output(); } @@ -117,17 +118,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; From 594dcf13f2d311ba2161e33effe6e297939e3595 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 13 Feb 2012 22:47:31 +0100 Subject: [PATCH 08/22] Contacts+OC_Respone: Move enableCaching out of setEtagHeader and setLastModifiedHeader --- apps/contacts/photo.php | 1 + apps/contacts/thumbnail.php | 1 + lib/response.php | 3 +-- 3 files changed, 3 insertions(+), 2 deletions(-) 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/thumbnail.php b/apps/contacts/thumbnail.php index c020c29ac8c..39da6bc2bf7 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; diff --git a/lib/response.php b/lib/response.php index b5fca1cb227..a768366b02c 100644 --- a/lib/response.php +++ b/lib/response.php @@ -63,6 +63,7 @@ class OC_Response { $expires->add(new DateInterval($interval)); } if ($expires instanceof DateTime) { + $expires->setTimezone(new DateTimeZone('GMT')); $expires = $expires->format(DateTime::RFC2822); } header('Expires: '.$expires); @@ -72,7 +73,6 @@ class OC_Response { 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); @@ -88,7 +88,6 @@ class OC_Response { 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); From 29fc82c364e2e90330d9858528e50d785e5e66bd Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 13 Feb 2012 23:35:33 +0100 Subject: [PATCH 09/22] Send gallery album thumbnail with OC_Response::sendFile --- apps/gallery/ajax/galleryOp.php | 6 +++--- lib/image.php | 5 +++++ lib/response.php | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/apps/gallery/ajax/galleryOp.php b/apps/gallery/ajax/galleryOp.php index 9273de2599d..5ac6d295108 100644 --- a/apps/gallery/ajax/galleryOp.php +++ b/apps/gallery/ajax/galleryOp.php @@ -41,9 +41,9 @@ function handleRemove($name) { function handleGetThumbnails($albumname) { OC_Response::enableCaching(3600 * 24); // 24 hour - $photo = new OC_Image(); - $photo->loadFromFile(OC::$CONFIG_DATADIRECTORY.'/../gallery/'.$albumname.'.png'); - $photo->show(); + $thumbnail = OC::$CONFIG_DATADIRECTORY.'/../gallery/'.$albumname.'.png'; + header('Content-Type: '.OC_Image::getMimeTypeForFile($thumbnail)); + OC_Response::sendFile($thumbnail); } function handleGalleryScanning() { diff --git a/lib/image.php b/lib/image.php index df8f76352a0..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. diff --git a/lib/response.php b/lib/response.php index a768366b02c..f47534aeefb 100644 --- a/lib/response.php +++ b/lib/response.php @@ -10,6 +10,7 @@ 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)) { @@ -47,6 +48,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); } @@ -85,6 +89,9 @@ 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); } @@ -95,4 +102,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); + } + } } From 525306c1e2930c6b378b0a4e9fb92eeb90865b0a Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 13 Feb 2012 23:48:05 +0100 Subject: [PATCH 10/22] Replace Expires and caching headers by OC_Response functions --- apps/files_sharing/get.php | 4 +--- apps/media/ajax/api.php | 13 +++---------- apps/media/tomahawk.php | 4 +--- files/download.php | 4 +--- lib/files.php | 4 +--- lib/response.php | 3 +++ 6 files changed, 10 insertions(+), 22 deletions(-) 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/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']); diff --git a/files/download.php b/files/download.php index 71f91d352f7..d1f5ba486d7 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/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/response.php b/lib/response.php index f47534aeefb..2fa0a5adcd3 100644 --- a/lib/response.php +++ b/lib/response.php @@ -30,6 +30,9 @@ class OC_Response { } } + static public function disableCaching() { + self::enableCaching(0); + } static public function setStatus($status) { $protocol = $_SERVER['SERVER_PROTOCOL']; From 777804fac231f031ccbaed49590400dca91fab6b Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 14 Feb 2012 00:12:22 +0100 Subject: [PATCH 11/22] Gallery: remove unused cover.php --- apps/gallery/ajax/cover.php | 81 ------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 apps/gallery/ajax/cover.php 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 @@ -. -* -*/ - -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); -?> From a37bd932223f6fbcad9be8a2129a09502f4bd762 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Tue, 14 Feb 2012 00:13:04 +0100 Subject: [PATCH 12/22] External: Use OC_Util::checkLoggedIn --- apps/external/index.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) 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'])){ From 7323b525607385ff37854533e1b585d17fd8648c Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 13 Feb 2012 10:25:45 +0100 Subject: [PATCH 13/22] some additional test cases for file storage backends --- tests/lib/filestorage.php | 51 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/lib/filestorage.php b/tests/lib/filestorage.php index edb029d916f..7f024dafaa3 100644 --- a/tests/lib/filestorage.php +++ b/tests/lib/filestorage.php @@ -34,10 +34,41 @@ abstract class Test_FileStorage extends UnitTestCase { $this->assertTrue($this->instance->is_readable('/'),'Root folder is not readable'); $this->assertTrue($this->instance->is_dir('/'),'Root folder is not a directory'); $this->assertFalse($this->instance->is_file('/'),'Root folder is a file'); + $this->assertEqual('dir',$this->instance->filetype('/')); //without this, any further testing would be useless, not an acutal requirement for filestorage though $this->assertTrue($this->instance->is_writable('/'),'Root folder is not writable'); } + + public function testDirectories(){ + $this->assertFalse($this->instance->file_exists('/folder')); + + $this->assertTrue($this->instance->mkdir('/folder')); + + $this->assertTrue($this->instance->file_exists('/folder')); + $this->assertTrue($this->instance->is_dir('/folder')); + $this->assertFalse($this->instance->is_file('/folder')); + $this->assertEqual('dir',$this->instance->filetype('/folder')); + $this->assertEqual(0,$this->instance->filesize('/folder')); + $this->assertTrue($this->instance->is_readable('/folder')); + $this->assertTrue($this->instance->is_writable('/folder')); + + $dh=$this->instance->opendir('/'); + $content=array(); + while($file=readdir($dh)){ + if($file!='.' and $file!='..'){ + $content[]=$file; + } + } + $this->assertEqual(array('folder'),$content); + + $this->assertFalse($this->instance->mkdir('/folder'));//cant create existing folders + $this->assertTrue($this->instance->rmdir('/folder')); + + $this->assertFalse($this->instance->file_exists('/folder')); + + $this->assertFalse($this->instance->rmdir('/folder'));//cant remove non existing folders + } /** * test the various uses of file_get_contents and file_put_contents @@ -58,6 +89,26 @@ abstract class Test_FileStorage extends UnitTestCase { $this->instance->file_put_contents('/lorem.txt',''); $this->assertEqual('',$this->instance->file_get_contents('/lorem.txt'),'file not emptied'); } + + /** + * test various known mimetypes + */ + public function testMimeType(){ + $this->assertEqual('httpd/unix-directory',$this->instance->getMimeType('/')); + $this->assertEqual(false,$this->instance->getMimeType('/non/existing/file')); + + $textFile=OC::$SERVERROOT.'/tests/data/lorem.txt'; + $this->instance->file_put_contents('/lorem.txt',fopen($textFile,'r')); + $this->assertEqual('text/plain',$this->instance->getMimeType('/lorem.txt')); + + $pngFile=OC::$SERVERROOT.'/tests/data/logo-wide.png'; + $this->instance->file_put_contents('/logo-wide.png',fopen($pngFile,'r')); + $this->assertEqual('image/png',$this->instance->getMimeType('/logo-wide.png')); + + $svgFile=OC::$SERVERROOT.'/tests/data/logo-wide.svg'; + $this->instance->file_put_contents('/logo-wide.svg',fopen($svgFile,'r')); + $this->assertEqual('image/svg+xml',$this->instance->getMimeType('/logo-wide.svg')); + } } From bfa18fde19427179aa1ec5132810b429dee33cf7 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 13 Feb 2012 10:26:40 +0100 Subject: [PATCH 14/22] dummy data for tests cases --- tests/data/logo-wide.png | Bin 0 -> 3559 bytes tests/data/logo-wide.svg | 875 +++++++++++++++++++++++++++++++++++++++ tests/data/lorem.txt | 4 + 3 files changed, 879 insertions(+) create mode 100644 tests/data/logo-wide.png create mode 100644 tests/data/logo-wide.svg create mode 100644 tests/data/lorem.txt diff --git a/tests/data/logo-wide.png b/tests/data/logo-wide.png new file mode 100644 index 0000000000000000000000000000000000000000..b2c16a0f60a6991eb6a98109d017b48e3b3a3a3b GIT binary patch literal 3559 zcmVlt;FJ-)^=>*#vPHQ2|+G6E#Lfg@7?8(YT@+ zjW=eQ#CziyCz-isG-k4x#4(G>L^C&uGbW>=aY;)v52R@6@TKRU$%b;2k)otH#-GhO3Knw6;PQW-u5W9UUFA z_4>*~`31#Wa?^Gvwo1cov?{9B7%+iD#?5qWr}^lG|C-t%JUBod(60}U8VwgOT_OEU z7GKA2EzY@gb#GBg;nUekyNg@gfHqnW5oxgmsKQ51PI&r%78d0f7KtU+ZcNaHjhuX~ zM{rDVOWM$uS~oS>!}JV$sJqIb8g64}>s?u?PpvQ-4|a5R{qK>(A{MS(w#dnvI*y-A z=b5>SFB%JN{L|An=$d3m8^0>HjV+*3sZ;?&$G_IKW2cuNiH)@H?bY2WCH+j%?!?1J zjf1_z(l_Q?HCO-!h4*LD<1w8#ZQb=g@N#2qY2!Z7SeFzuWZeAOFD<-NuGNYuFTV1Y z?AUWi8jDV+m(UTD3cE!--tK<8+qTqjYLtiRJ22MO#i_%>oa4aZ6U=@7cg&1?yiS`XrDa5o zpIvnA_N^gTPwhS1Vm)u8X;>Q_dwY-4gpHc~W8CaN-nn%j-Bx>AjiQl|kVkSN($*Gz3shY)TG|KAu?8Af@t=S2x|@yK@}g?n?t{GXr#W== z=+NXTa@xd4*qwNUA9wD@QRBd&pHFfs<1D2m}9UU4u@!E$gR%?$Xr^(%tQu!`nuPpiKi#k(8 zZN|pESSR*q4y)E|krk`rE$Zw&@UwAXblmNL2ggs4`|qx;NuDCIQA9S2$TK1mDk8Qf z`M>!o>6bYsA}a20LH>O=ZC(5Kt}nm%l*6F#{y4R7M{34dLIV9P4m-WRl8Oo)9vxg; zY$y*53nC*k%c4$H^Bul!(gxY0lqD6T#s&DxP0{nf&Kb4s2ew7j7!FutSP`1;0*9WeZ zgaGBhX~5k1hz&3q=+}a61_8OijTWl2HugY&z!gxT%tUIy(bmn`C1&`L0d)=(tMT*k z=3I6T1x3ZbtW-?V>Gb&Y_Tv17OD%5og`8aacz3r-w|{^yt}f0`pq!8S0HwejlsLhZ zJ-}F?qL%y`FbJr<;)(}e0&bhg+<;F|;*u0V1B3xq zLwTXE0pHcq-2*(-Kz)A(P6DR40o;M*zz`snntcXvvej1_!UO#3|AKAQYUa-IzeRR!h0If?hqlG4F+$4cKTsrDf&V*w|3}-c5aU@^t6Q^_yB% zRMa%tx33b20RDyYU`!uMca*QDHqMwojO~KrC8}`+enL46eab{`2P^^-fYCtpenkY3 zY*i=fCjj^Xm=A0cxHmZz>fTw5mi#h>} zN7>VGX+hJLp#-q2YsvM%>nNUTj)~kJXwH3Q8{nV7lhhn60GEJ=foUjHV{`ZncpJq_ z){ENS-u8B0eqn>PEm<^=FII14_S{8u_Vi%s8}o5>QLgXWsMU1#bSFC}x0yEIaB!EHT{jDyuW!oM@#+mG-oV4BB%w$JW)16nKy!hIvG5?UAX&uHw$4#9~j^Q>J@W-JhGtmZGeh>RZjc4t&GC4?zcfT_vxN2;lNB2TOquj+-(d zYD(UYJwMfZ>BV3$%KX2)U-86@xdwB0W3Jt}CBcys^LmCx1%!^6v}5{nuNGNzAenSB z!}vh#lX*cy$IbT&dw6K@@CmoR{AQERXf#?Zw|>hGeMD4T!M;Psb428M5pk{RkGm*` zcxfWyQ|kcDQ$#L`$P5v&7m;WYNfME%B9bK{GeyKfM23k-qKHg3DLX_&{v{0`(xr%q z#*ExoL=K6_Cn7S+#9q_%t%!UoB3>pkHxW4@A|HrI*D6^%5s9m^d9;~&o~g1Ux~iXu zh_{HW5|M2pVpmJwu1dbDO0QaOD z>v+O;0H48QU_%6L=N) z2=kkDHYocXkto6DSHRy*@|~;lX9BU@i@)rESAcOSUZn*1xvJmw#Q-5FdqZI;(@i$8 zrmD^Qcm|k((pMeIrsQ^%mEl>lm%zRH#|%>2sRw(wxX&f}8v=tS;AZkaA=Dbc + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/data/lorem.txt b/tests/data/lorem.txt new file mode 100644 index 00000000000..b62c3fb2ffd --- /dev/null +++ b/tests/data/lorem.txt @@ -0,0 +1,4 @@ +Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. +Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. \ No newline at end of file From 3c52ac7af3a5e03e8a740f195ca020cf67871c35 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Mon, 13 Feb 2012 10:27:00 +0100 Subject: [PATCH 15/22] make local filestorage comply with test cases --- lib/filestorage/local.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index 292d2a84e7d..2e66943cad2 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); @@ -80,8 +76,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 +163,8 @@ class OC_Filestorage_Local extends OC_Filestorage{ $mimeType=(isset(self::$mimetypes[$extention]))?self::$mimetypes[$extention]:'application/octet-stream'; } return $mimeType; + }else{ + return false; } } From 024405e4f1a645f640803ad41e24e59a43f27890 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Mon, 13 Feb 2012 13:02:54 +0100 Subject: [PATCH 16/22] Added function for later testing. --- apps/contacts/js/contacts.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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; From 3adaacc0ce8cbbcb070cd06fb52d98e4f590751a Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 14 Feb 2012 00:56:50 +0100 Subject: [PATCH 17/22] Added OC_Contacts_VCard::moveToAddressBook --- apps/contacts/lib/vcard.php | 40 +++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index f9ca427354e..a0eacd0e63b 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -384,4 +384,44 @@ 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); + OC_Log::write('contacts','SQL:'.$prep,OC_Log::DEBUG); + return false; + } + } + + OC_Contacts_Addressbook::touch($aid); + return true; + } + } From 07c422d81d51b476717c5e0178ddbab073466e38 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 14 Feb 2012 01:02:01 +0100 Subject: [PATCH 18/22] Removed superfluous debug. --- apps/contacts/lib/vcard.php | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index a0eacd0e63b..f10af83964c 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -415,7 +415,6 @@ class OC_Contacts_VCard{ } 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); - OC_Log::write('contacts','SQL:'.$prep,OC_Log::DEBUG); return false; } } From 4446854f758b96f717ffb0f8a20e05356b5b93c5 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 14 Feb 2012 01:11:21 +0100 Subject: [PATCH 19/22] Don't try to load a profile picture for contacts the doesn't have any. --- apps/contacts/thumbnail.php | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/apps/contacts/thumbnail.php b/apps/contacts/thumbnail.php index 39da6bc2bf7..5082626499b 100644 --- a/apps/contacts/thumbnail.php +++ b/apps/contacts/thumbnail.php @@ -56,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(); From 53503148f3208ac5aa47e7ea654932a5c5af5c5a Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 14 Feb 2012 01:47:18 +0100 Subject: [PATCH 20/22] Use proper index file. --- apps/contacts/contacts.php | 62 ------------------------- apps/contacts/index.php | 73 ++++++++++++------------------ apps/contacts/templates/index.php | 4 +- apps/contacts/templates/index2.php | 27 ----------- 4 files changed, 32 insertions(+), 134 deletions(-) delete mode 100644 apps/contacts/contacts.php delete mode 100644 apps/contacts/templates/index2.php 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 @@ - 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 @@ . - * + * Copyright (c) 2012 Thomas Tanghus + * 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/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 @@
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 4c0dfad6177..00000000000 --- a/apps/contacts/templates/index2.php +++ /dev/null @@ -1,27 +0,0 @@ - -
-
- - -
-
-
-
    - inc("part.contacts"); ?> -
-
-
- inc('part.contact'); - } - else{ - echo $this->inc('part.no_contacts'); - } - ?> -
- -
- From dc20900e10f9a080f1ffa164c1e6b0dd62f6c46b Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 14 Feb 2012 01:56:38 +0100 Subject: [PATCH 21/22] Modify check for missing UID. --- apps/contacts/lib/vcard.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index f10af83964c..cc25c009d67 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -124,10 +124,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 +175,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 +186,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 +212,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())); From f7161bb48b6bb71b04f4167f8c4cfb4096824ed8 Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Tue, 14 Feb 2012 02:15:21 +0100 Subject: [PATCH 22/22] Added some error checking as mentioned in http://bugs.owncloud.org/thebuggenie/owncloud/issues/oc-227 --- apps/contacts/lib/vcard.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index cc25c009d67..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;