Photo albums on photos page

This commit is contained in:
Max Shinn 2010-12-28 08:31:34 -06:00
parent 22fe5d0215
commit 330ac5dd12
4 changed files with 56 additions and 14 deletions

View File

@ -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;

View File

@ -23,6 +23,7 @@
* @package GNU Social
* @author Ian Denhardt <ian@zenhack.net>
* @author Sean Corbett <sean@gnu.org>
* @author Max Shinn <trombonechamp@gmail.com>
* @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()
{
if(empty($this->user)) {
$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)
{
$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();
}
}

View File

@ -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!'));

View File

@ -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;
}
}
}