]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/profileaction.php
Merge branch '0.9.x' into 1.0.x
[quix0rs-gnu-social.git] / lib / profileaction.php
index 2519922b2b28e8292e9a4a51e270b8e6af3e8416..504b77566993ccdbab8d08197888aac194a13868 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Laconica, the distributed open-source microblogging tool
+ * StatusNet, the distributed open-source microblogging tool
  *
  * Common parent of Personal and Profile actions
  *
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  * @category  Personal
- * @package   Laconica
- * @author    Evan Prodromou <evan@controlyourself.ca>
- * @author    Sarven Capadisli <csarven@controlyourself.ca>
- * @copyright 2008-2009 Control Yourself, Inc.
+ * @package   StatusNet
+ * @author    Evan Prodromou <evan@status.net>
+ * @author    Sarven Capadisli <csarven@status.net>
+ * @copyright 2008-2009 StatusNet, Inc.
  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link      http://laconi.ca/
+ * @link      http://status.net/
  */
 
-if (!defined('LACONICA')) {
+if (!defined('STATUSNET') && !defined('LACONICA')) {
     exit(1);
 }
 
@@ -41,10 +41,10 @@ require_once INSTALLDIR.'/lib/groupminilist.php';
  * Abstracts out common code from profile and personal tabs
  *
  * @category Personal
- * @package  Laconica
- * @author   Evan Prodromou <evan@controlyourself.ca>
+ * @package  StatusNet
+ * @author   Evan Prodromou <evan@status.net>
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
- * @link     http://laconi.ca/
+ * @link     http://status.net/
  */
 
 class ProfileAction extends OwnerDesignAction
@@ -105,26 +105,30 @@ class ProfileAction extends OwnerDesignAction
 
         $this->elementStart('div', array('id' => 'entity_subscriptions',
                                          'class' => 'section'));
+        if (Event::handle('StartShowSubscriptionsMiniList', array($this))) {
+            $this->element('h2', null, _('Subscriptions'));
 
-        $this->element('h2', null, _('Subscriptions'));
+            $cnt = 0;
 
-        if ($profile) {
-            $pml = new ProfileMiniList($profile, $this);
-            $cnt = $pml->show();
-            if ($cnt == 0) {
-                $this->element('p', null, _('(None)'));
+            if (!empty($profile)) {
+                $pml = new ProfileMiniList($profile, $this);
+                $cnt = $pml->show();
+                if ($cnt == 0) {
+                    $this->element('p', null, _('(None)'));
+                }
             }
-        }
 
-        if ($cnt > PROFILES_PER_MINILIST) {
-            $this->elementStart('p');
-            $this->element('a', array('href' => common_local_url('subscriptions',
-                                                                 array('nickname' => $this->profile->nickname)),
-                                      'class' => 'more'),
-                           _('All subscriptions'));
-            $this->elementEnd('p');
-        }
+            if ($cnt > PROFILES_PER_MINILIST) {
+                $this->elementStart('p');
+                $this->element('a', array('href' => common_local_url('subscriptions',
+                                                                     array('nickname' => $this->profile->nickname)),
+                                          'class' => 'more'),
+                               _('All subscriptions'));
+                $this->elementEnd('p');
+            }
 
+            Event::handle('EndShowSubscriptionsMiniList', array($this));
+        }
         $this->elementEnd('div');
     }
 
@@ -135,23 +139,30 @@ class ProfileAction extends OwnerDesignAction
         $this->elementStart('div', array('id' => 'entity_subscribers',
                                          'class' => 'section'));
 
-        $this->element('h2', null, _('Subscribers'));
+        if (Event::handle('StartShowSubscribersMiniList', array($this))) {
+
+            $this->element('h2', null, _('Subscribers'));
 
-        if ($profile) {
-            $pml = new ProfileMiniList($profile, $this);
-            $cnt = $pml->show();
-            if ($cnt == 0) {
-                $this->element('p', null, _('(None)'));
+            $cnt = 0;
+
+            if (!empty($profile)) {
+                $sml = new SubscribersMiniList($profile, $this);
+                $cnt = $sml->show();
+                if ($cnt == 0) {
+                    $this->element('p', null, _('(None)'));
+                }
+            }
+
+            if ($cnt > PROFILES_PER_MINILIST) {
+                $this->elementStart('p');
+                $this->element('a', array('href' => common_local_url('subscribers',
+                                                                     array('nickname' => $this->profile->nickname)),
+                                          'class' => 'more'),
+                               _('All subscribers'));
+                $this->elementEnd('p');
             }
-        }
 
-        if ($cnt > PROFILES_PER_MINILIST) {
-            $this->elementStart('p');
-            $this->element('a', array('href' => common_local_url('subscribers',
-                                                                 array('nickname' => $this->profile->nickname)),
-                                      'class' => 'more'),
-                           _('All subscribers'));
-            $this->elementEnd('p');
+            Event::handle('EndShowSubscribersMiniList', array($this));
         }
 
         $this->elementEnd('div');
@@ -159,18 +170,16 @@ class ProfileAction extends OwnerDesignAction
 
     function showStatistics()
     {
-        // XXX: WORM cache this
-        $subs = new Subscription();
-        $subs->subscriber = $this->profile->id;
-        $subs_count = (int) $subs->count() - 1;
-
-        $subbed = new Subscription();
-        $subbed->subscribed = $this->profile->id;
-        $subbed_count = (int) $subbed->count() - 1;
-
-        $notices = new Notice();
-        $notices->profile_id = $this->profile->id;
-        $notice_count = (int) $notices->count();
+        $subs_count   = $this->profile->subscriptionCount();
+        $subbed_count = $this->profile->subscriberCount();
+        $notice_count = $this->profile->noticeCount();
+        $group_count  = $this->user->getGroups()->N;
+        $age_days     = (time() - strtotime($this->profile->created)) / 86400;
+        if ($age_days < 1) {
+            // Rather than extrapolating out to a bajillion...
+            $age_days = 1;
+        }
+        $daily_count = round($notice_count / $age_days);
 
         $this->elementStart('div', array('id' => 'entity_statistics',
                                          'class' => 'section'));
@@ -195,7 +204,7 @@ class ProfileAction extends OwnerDesignAction
                                                              array('nickname' => $this->profile->nickname))),
                        _('Subscriptions'));
         $this->elementEnd('dt');
-        $this->element('dd', null, (is_int($subs_count)) ? $subs_count : '0');
+        $this->element('dd', null, $subs_count);
         $this->elementEnd('dl');
 
         $this->elementStart('dl', 'entity_subscribers');
@@ -204,12 +213,27 @@ class ProfileAction extends OwnerDesignAction
                                                              array('nickname' => $this->profile->nickname))),
                        _('Subscribers'));
         $this->elementEnd('dt');
-        $this->element('dd', 'subscribers', (is_int($subbed_count)) ? $subbed_count : '0');
+        $this->element('dd', 'subscribers', $subbed_count);
+        $this->elementEnd('dl');
+
+        $this->elementStart('dl', 'entity_groups');
+        $this->elementStart('dt');
+        $this->element('a', array('href' => common_local_url('usergroups',
+                                                             array('nickname' => $this->profile->nickname))),
+                       _('Groups'));
+        $this->elementEnd('dt');
+        $this->element('dd', 'groups', $group_count);
         $this->elementEnd('dl');
 
         $this->elementStart('dl', 'entity_notices');
         $this->element('dt', null, _('Notices'));
-        $this->element('dd', null, (is_int($notice_count)) ? $notice_count : '0');
+        $this->element('dd', null, $notice_count);
+        $this->elementEnd('dl');
+
+        $this->elementStart('dl', 'entity_daily_notices');
+        // TRANS: Average count of posts made per day since account registration
+        $this->element('dt', null, _('Daily average'));
+        $this->element('dd', null, $daily_count);
         $this->elementEnd('dl');
 
         $this->elementEnd('div');
@@ -221,27 +245,49 @@ class ProfileAction extends OwnerDesignAction
 
         $this->elementStart('div', array('id' => 'entity_groups',
                                          'class' => 'section'));
+        if (Event::handle('StartShowGroupsMiniList', array($this))) {
+            $this->element('h2', null, _('Groups'));
+
+            if ($groups) {
+                $gml = new GroupMiniList($groups, $this->user, $this);
+                $cnt = $gml->show();
+                if ($cnt == 0) {
+                    $this->element('p', null, _('(None)'));
+                }
+            }
 
-        $this->element('h2', null, _('Groups'));
-
-        if ($groups) {
-            $gml = new GroupMiniList($groups, $this->user, $this);
-            $cnt = $gml->show();
-            if ($cnt == 0) {
-                $this->element('p', null, _('(None)'));
+            if ($cnt > GROUPS_PER_MINILIST) {
+                $this->elementStart('p');
+                $this->element('a', array('href' => common_local_url('usergroups',
+                                                                     array('nickname' => $this->profile->nickname)),
+                                          'class' => 'more'),
+                               _('All groups'));
+                $this->elementEnd('p');
             }
-        }
 
-        if ($cnt > GROUPS_PER_MINILIST) {
-            $this->elementStart('p');
-            $this->element('a', array('href' => common_local_url('usergroups',
-                                                                 array('nickname' => $this->profile->nickname)),
-                                      'class' => 'more'),
-                           _('All groups'));
-            $this->elementEnd('p');
+            Event::handle('EndShowGroupsMiniList', array($this));
         }
+            $this->elementEnd('div');
+    }
+}
 
-        $this->elementEnd('div');
+class SubscribersMiniList extends ProfileMiniList
+{
+    function newListItem($profile)
+    {
+        return new SubscribersMiniListItem($profile, $this->action);
+    }
+}
+
+class SubscribersMiniListItem extends ProfileMiniListItem
+{
+    function linkAttributes()
+    {
+        $aAttrs = parent::linkAttributes();
+        if (common_config('nofollow', 'subscribers')) {
+            $aAttrs['rel'] .= ' nofollow';
+        }
+        return $aAttrs;
     }
 }