From 7e8ff72c0b9c2cd1c73537edc886e6b6208a50fb Mon Sep 17 00:00:00 2001 From: Sean Corbett Date: Sat, 4 Sep 2010 17:17:52 -0400 Subject: Quick function to get an array of thumbnails for a gallery page. --- plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php | 2 ++ plugins/GNUsocialPhotos/actions/photos.php | 5 ++++ plugins/GNUsocialPhotos/actions/photoupload.php | 3 +- plugins/GNUsocialPhotos/classes/gnusocialphoto.php | 33 +++++++++++++++++++++- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php b/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php index 79da70321..f67cfec34 100644 --- a/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php +++ b/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php @@ -62,6 +62,8 @@ class GNUsocialPhotosPlugin extends Plugin $schema = Schema::get(); $schema->ensureTable('GNUsocialPhoto', array(new ColumnDef('notice_id', 'int(11)', null, false), + new ColumnDef('album_id', 'int(11)', null, false), + //new ColumnDef('album_name', 'varchar(30)', null, false), new ColumnDef('uri', 'varchar(512)', null, false), new ColumnDef('thumb_uri', 'varchar(512)', null, false))); } diff --git a/plugins/GNUsocialPhotos/actions/photos.php b/plugins/GNUsocialPhotos/actions/photos.php index 29a70e458..bc54ae993 100644 --- a/plugins/GNUsocialPhotos/actions/photos.php +++ b/plugins/GNUsocialPhotos/actions/photos.php @@ -86,6 +86,11 @@ class PhotosAction extends Action $pathparts = explode('/', $args[1]['nickname']); $username = $pathparts[0]; $this->elementStart('ul', array('class' => 'photothumbs')); + + //scorbett + $photo_obj = new GNUsocialPhoto(); + $photo_obj->getGalleryPage(1, 0, 9); + while (false !== ($file = readdir($dir))) { $fparts = explode('-', $file); if ($fparts[0] == $username // uploaded by this user diff --git a/plugins/GNUsocialPhotos/actions/photoupload.php b/plugins/GNUsocialPhotos/actions/photoupload.php index 216f1768f..84caf4747 100644 --- a/plugins/GNUsocialPhotos/actions/photoupload.php +++ b/plugins/GNUsocialPhotos/actions/photoupload.php @@ -137,7 +137,8 @@ class PhotouploadAction extends Action $uri = 'http://' . common_config('site', 'server') . '/file/' . $filename; $thumb_uri = 'http://' . common_config('site', 'server') . '/file/thumb.' . $filename; $profile_id = $cur->id; - GNUsocialPhoto::saveNew($profile_id, $thumb_uri, $uri, 'web'); + //scorbett: the second arg below should be set to the album ID + GNUsocialPhoto::saveNew($profile_id, 0, $thumb_uri, $uri, 'web'); } } diff --git a/plugins/GNUsocialPhotos/classes/gnusocialphoto.php b/plugins/GNUsocialPhotos/classes/gnusocialphoto.php index 4965cd0d9..f218d570f 100644 --- a/plugins/GNUsocialPhotos/classes/gnusocialphoto.php +++ b/plugins/GNUsocialPhotos/classes/gnusocialphoto.php @@ -36,9 +36,16 @@ class GNUsocialPhoto extends Memcached_DataObject { public $__table = 'GNUsocialPhoto'; public $notice_id; // int(11) + public $album_id; // int(11) public $uri; // varchar(512) public $thumb_uri; // varchar(512) + + /** + * + * k key + * v value + */ function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('GNUsocialPhoto',$k,$v); @@ -58,6 +65,7 @@ class GNUsocialPhoto extends Memcached_DataObject function table() { return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL, + 'album_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL, 'uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL, 'thumb_uri' => DB_DATAOBJECT_STR + DB_DATAOBJECT_NOTNULL); } @@ -77,11 +85,12 @@ class GNUsocialPhoto extends Memcached_DataObject return array(false, false, false); } - function saveNew($profile_id, $thumb_uri, $uri, $source) + function saveNew($profile_id, $album_id, $thumb_uri, $uri, $source) { $photo = new GNUsocialPhoto(); $photo->thumb_uri = $thumb_uri; $photo->uri = $uri; + $photo->album_id = $album_id; $notice = Notice::saveNew($profile_id, $uri, $source); $photo->notice_id = $notice->id; @@ -92,6 +101,28 @@ class GNUsocialPhoto extends Memcached_DataObject } } + + /* + * TODO: -Sanitize input + * @param int page_id The desired page of the gallery to show. + * @param int album_id The id of the album to get photos from. + * @param int gallery_size The number of thumbnails to show per page in the gallery. + * @return array Array of GNUsocialPhotos for this gallery page. + */ + function getGalleryPage($page_id, $album_id, $gallery_size) + { + $page_offset = ($page_id-1) * $gallery_size; + $sql = 'SELECT * FROM GNUsocialPhoto order by notice_id limit ' . $page_offset . ',' . $gallery_size; + $this->query($sql); + $thumbs = array(); + + while ($this->fetch()) { + $thumbs[] = clone($this); + } + + return $thumbs; + } + /* function asActivityNoun($element) { -- cgit v1.2.3