From 330ac5dd12a197b033e7e619e45119a356176ff7 Mon Sep 17 00:00:00 2001 From: Max Shinn Date: Tue, 28 Dec 2010 08:31:34 -0600 Subject: [PATCH] Photo albums on photos page --- .../GNUsocialPhotos/GNUsocialPhotosPlugin.php | 1 + plugins/GNUsocialPhotos/actions/photos.php | 52 ++++++++++++++----- .../GNUsocialPhotos/actions/photoupload.php | 1 - .../classes/gnusocialphotoalbum.php | 16 +++++- 4 files changed, 56 insertions(+), 14 deletions(-) diff --git a/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php b/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php index bb00f32000..f6173c29c6 100644 --- a/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php +++ b/plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php @@ -86,6 +86,7 @@ class GNUsocialPhotosPlugin extends Plugin function onRouterInitialized($m) { $m->connect(':nickname/photos', array('action' => 'photos')); + $m->connect(':nickname/photos/:albumid', array('action' => 'photos')); $m->connect('main/uploadphoto', array('action' => 'photoupload')); $m->connect('photo/:photoid', array('action' => 'photo')); return true; diff --git a/plugins/GNUsocialPhotos/actions/photos.php b/plugins/GNUsocialPhotos/actions/photos.php index 7f47974d77..c16bb80789 100644 --- a/plugins/GNUsocialPhotos/actions/photos.php +++ b/plugins/GNUsocialPhotos/actions/photos.php @@ -23,6 +23,7 @@ * @package GNU Social * @author Ian Denhardt * @author Sean Corbett + * @author Max Shinn * @copyright 2010 Free Software Foundation, Inc. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 */ @@ -43,6 +44,7 @@ class PhotosAction extends Action $args = $this->returnToArgs(); $username = $args[1]['nickname']; + $this->albumid = $args[1]['albumid']; if (common_valid_profile_tag($username) == 0) { $this->user = null; } else { @@ -72,29 +74,46 @@ class PhotosAction extends Action $nav->show(); } - function showContent() + function showAlbums() + { + $album = new GNUsocialPhotoAlbum(); + $album->user_id = $this->user->id; + + $albums = array(); + if (!$album->find()) { + GNUsocialPhotoAlbum::newAlbum($cur->id, 'Default'); + } + $this->elementStart('ul', array('class' => 'photothumbs')); + while ($album->fetch()) { + $this->elementStart('li'); + $this->element('h3', array(), $album->title); + $this->elementStart('a', array('href' => $album->getPageLink())); + $this->element('img', array('src' => $album->getThumbUri())); + $this->elementEnd('a'); + $this->elementEnd('li'); + } + $this->elementEnd('ul'); + + } + + function showAlbum($album_id) { - if(empty($this->user)) { + $album = GNUSocialPhotoAlbum::staticGet('album_id', $album_id); + if (!$album) { return; } + $page = $_GET['pageid']; if (!filter_var($page, FILTER_VALIDATE_INT)){ $page = 1; } - - //TODO choice of available albums by user. - //Currently based on fact that each user can only have one album. - $album = GNUSocialPhotoAlbum::staticGet('profile_id', $this->user->id); - if (!$album) { - $album = GNUSocialPhotoAlbum::newAlbum($this->user->id, 'Default'); - } - $photos = GNUsocialPhoto::getGalleryPage($page, $album->album_id, 9); + $photos = GNUsocialPhoto::getGalleryPage($page, $album->album_id, 9); if ($page > 1) { - $this->element('a', array('href' => 'photos?pageid=' . ($page-1)), 'Previous page'); + $this->element('a', array('href' => $album->getPageLink() . '?pageid=' . ($page-1)), 'Previous page'); } if (GNUsocialPhoto::getGalleryPage($page+1, $album->album_id, 9)) { - $this->element('a', array('href' => 'photos?pageid=' . ($page+1) ), 'Next page'); + $this->element('a', array('href' => $album->getPageLink() . '?pageid=' . ($page+1) ), 'Next page'); } $this->elementStart('ul', array('class' => 'photothumbs')); @@ -107,4 +126,13 @@ class PhotosAction extends Action } $this->elementEnd('ul'); } + + + function showContent() + { + if (!empty($this->albumid)) + $this->showAlbum($this->albumid); + else + $this->showAlbums(); + } } diff --git a/plugins/GNUsocialPhotos/actions/photoupload.php b/plugins/GNUsocialPhotos/actions/photoupload.php index 28405bc58f..fc86b8e3ab 100644 --- a/plugins/GNUsocialPhotos/actions/photoupload.php +++ b/plugins/GNUsocialPhotos/actions/photoupload.php @@ -193,7 +193,6 @@ class PhotouploadAction extends Action $thumb_uri = 'http://' . common_config('site', 'server') . '/file/thumb.' . $filename; $profile_id = $cur->id; - // TODO: proper multiple album support $album = GNUsocialPhotoAlbum::staticGet('album_id', $this->trimmed('album')); if ($album->profile_id != $profile_id) { $this->showForm(_('Error: This is not your album!')); diff --git a/plugins/GNUsocialPhotos/classes/gnusocialphotoalbum.php b/plugins/GNUsocialPhotos/classes/gnusocialphotoalbum.php index ed18f1f338..848f92dffa 100644 --- a/plugins/GNUsocialPhotos/classes/gnusocialphotoalbum.php +++ b/plugins/GNUsocialPhotos/classes/gnusocialphotoalbum.php @@ -74,6 +74,20 @@ class GNUsocialPhotoAlbum extends Memcached_DataObject return array('album_id', true, false); } + function getPageLink() + { + $profile = Profile::StaticGet('id', $this->profile_id); + return '/' . $profile->nickname . '/photos/' . $this->album_id; + } + + function getThumbUri() + { + $photo = GNUsocialPhoto::staticGet('album_id', $this->album_id); + if (empty($photo)) + return '/theme/default/default-avatar-profile.png'; //For now... + return $photo->thumb_uri; + } + static function newAlbum($profile_id, $album_name, $album_description) { //TODO: Should use foreign key instead... @@ -94,6 +108,6 @@ class GNUsocialPhotoAlbum extends Memcached_DataObject } common_log(LOG_INFO, 'album_id : ' . $album->album_id); return $album; - } + } } -- 2.39.2