]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Photo albums on photos page
authorMax Shinn <trombonechamp@gmail.com>
Tue, 28 Dec 2010 14:31:34 +0000 (08:31 -0600)
committerMax Shinn <trombonechamp@gmail.com>
Tue, 28 Dec 2010 14:31:34 +0000 (08:31 -0600)
plugins/GNUsocialPhotos/GNUsocialPhotosPlugin.php
plugins/GNUsocialPhotos/actions/photos.php
plugins/GNUsocialPhotos/actions/photoupload.php
plugins/GNUsocialPhotos/classes/gnusocialphotoalbum.php

index bb00f32000edf56b9d0d31db38d5164dbdcad4b2..f6173c29c60e9ac4dc684224c880a56a8bbabcb4 100644 (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;
index 7f47974d771a1430bfeba7f4359a60883336d703..c16bb80789cb5080fa330a7e019561bcaea524f1 100644 (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()
+    {
+        $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();
+    }
 }
index 28405bc58fcc4f6f522191de3e9d4f438f1b2613..fc86b8e3abe079b27688d943cf367d6e1df0ecff 100644 (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!'));
index ed18f1f338b2a22faa6df9f47fdd34cd7650c107..848f92dffabdaed1488a71f2d23314b15cf65437 100644 (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;
-    } 
+    }
 
 }