]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/showstream.php
correct path to DB_DataObject
[quix0rs-gnu-social.git] / actions / showstream.php
index 1eb060fdc943c2b653b541e6c53acb5e988f4a5a..c477ae29b7a29a64437d7ecc11ac53c48576aede 100644 (file)
@@ -1,4 +1,23 @@
 <?php
+/* 
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, Inc.
+ * 
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('LACONICA')) { exit(1); }
 
 define('SUBSCRIPTIONS_PER_ROW', 5);
 define('SUBSCRIPTIONS', 80);
@@ -9,34 +28,43 @@ class ShowstreamAction extends StreamAction {
                
                parent::handle($args);
 
-               $nickname = $this->arg('profile');
-               $profile = Profile::staticGet('nickname', strtolower($nickname));
-       
-               if (!$profile) {
-                       $this->no_such_user();
-               } 
-               
-               $user = User::staticGet($profile->id);
-               
+               $nickname = common_canonicalize_nickname($this->arg('profile'));
+               $user = User::staticGet('nickname', $nickname);
+
                if (!$user) {
-                       // remote profile
                        $this->no_such_user();
+               } 
+
+               $profile = $user->getProfile();
+
+               if (!$profile) {
+                       common_server_error(_t('User record exists without profile.'));
                }
                
                # Looks like we're good; show the header
                
                common_show_header($profile->nickname);
+
+               $cur = common_current_user();
                
-               if ($profile->id == current_user()->id) {
+               if ($cur && $profile->id == $cur->id) {
                        $this->notice_form();
                }
        
                $this->show_profile($profile);
 
                $this->show_last_notice($profile);
+
+               if ($cur) {
+                       if ($cur->isSubscribed($profile)) {
+                               $this->show_unsubscribe_form($profile);
+                       } else {
+                               $this->show_subscribe_form($profile);
+                       }
+               }
                
                $this->show_statistics($profile);
-               
+
                $this->show_subscriptions($profile);
                
                $this->show_notices($profile);
@@ -58,6 +86,14 @@ class ShowstreamAction extends StreamAction {
        
        function show_profile($profile) {
                common_start_element('div', 'profile');
+               $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
+               if ($avatar) {
+                       common_element('img', array('src' => $avatar->url,
+                                                                               'class' => 'avatar profile',
+                                                                               'width' => AVATAR_PROFILE_SIZE,
+                                                                               'height' => AVATAR_PROFILE_SIZE,
+                                                                               'title' => $profile->nickname));
+               }
                common_element('span', 'nickname', $profile->nickname);
                if ($profile->fullname) {
                        if ($profile->homepage) {
@@ -75,13 +111,33 @@ class ShowstreamAction extends StreamAction {
                        common_element('div', 'bio', $profile->bio);
                }
        }
+
+       function show_subscribe_form($profile) {
+               common_start_element('form', array('id' => 'subscribe', 'method' => 'POST',
+                                                                                  'action' => common_local_url('subscribe')));
+               common_element('input', array('id' => 'subscribeto',
+                                                                         'name' => 'subscribeto',
+                                                                         'type' => 'hidden',
+                                                                         'value' => $profile->nickname));
+               common_element('input', array('type' => 'submit'), _t('subscribe'));
+               common_end_element('form');
+       }
+
+       function show_unsubscribe_form($profile) {
+               common_start_element('form', array('id' => 'unsubscribe', 'method' => 'POST',
+                                                                                  'action' => common_local_url('unsubscribe')));
+               common_element('input', array('id' => 'unsubscribeto',
+                                                                         'name' => 'unsubscribeto',
+                                                                         'type' => 'hidden',
+                                                                         'value' => $profile->nickname));
+               common_element('input', array('type' => 'submit'), _t('unsubscribe'));
+               common_end_element('form');
+       }
        
        function show_subscriptions($profile) {
-
-               # XXX: add a limit
                
+               # XXX: add a limit
                $subs = $profile->getLink('id', 'subscription', 'subscriber');
-
                common_start_element('div', 'subscriptions');
                
                $cnt = 0;
@@ -96,8 +152,11 @@ class ShowstreamAction extends StreamAction {
                                                                                                   $subs->nickname,
                                                                                        'href' => $subs->profileurl,
                                                                                        'class' => 'subscription'));
-                       common_element('img', array('src' => $subs->avatar,
-                                                                               'class' => 'avatar'));
+                       $avatar = $subs->getAvatar(AVATAR_MINI_SIZE);
+                       common_element('img', array('src' => (($avatar) ? $avatar->url : DEFAULT_MINI_AVATAR),
+                                                                               'width' => AVATAR_MINI_SIZE,
+                                                                               'height' => AVATAR_MINI_SIZE,
+                                                                               'class' => 'avatar mini'));
                        common_end_element('a');
                        
                        if ($cnt % SUBSCRIPTIONS_PER_ROW == 0) {
@@ -110,10 +169,10 @@ class ShowstreamAction extends StreamAction {
                }
 
                common_element('a', array('href' => common_local_url('subscriptions', 
-                                                                                                                        array('profile' => $profile->nickname))
+                                                                                                                        array('profile' => $profile->nickname)),
                                                                  'class' => 'moresubscriptions'),
                                           _t('All subscriptions'));
-               
+
                common_end_element('div');
        }
 
@@ -174,7 +233,8 @@ class ShowstreamAction extends StreamAction {
                
                while ($notice->fetch()) {
                        # FIXME: URL, image, video, audio
-                       common_element('span', array('class' => 'content'), $notice->content);
+                       common_element('span', array('class' => 'content'), 
+                                                  $notice->content);
                        common_element('span', array('class' => 'date'),
                                                   common_date_string($notice->created));
                }