git.gnu.io has moved to IP address 209.51.188.249 -- please double check where you are logging in.

tagsubsaction.php 7.03 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
<?php
/**
 * StatusNet, the distributed open-source microblogging tool
 *
 * List of a user's subscriptions
 *
 * PHP version 5
 *
 * LICENCE: 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/>.
 *
 * @category  Social
 * @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://status.net/
 */

if (!defined('STATUSNET') && !defined('LACONICA')) {
    exit(1);
}

/**
 * A list of the user's subscriptions
 *
 * @category Social
 * @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://status.net/
 */
class TagSubsAction extends GalleryAction
{
    function title()
    {
        if ($this->page == 1) {
            // TRANS: Header for subscriptions overview for a user (first page).
            // TRANS: %s is a user nickname.
            return sprintf(_m('%s\'s tag subscriptions'), $this->user->nickname);
        } else {
            // TRANS: Header for subscriptions overview for a user (not first page).
            // TRANS: %1$s is a user nickname, %2$d is the page number.
            return sprintf(_m('%1$s\'s tag subscriptions, page %2$d'),
                           $this->user->nickname,
                           $this->page);
        }
    }

    function showPageNotice()
    {
        $user = common_current_user();
        if ($user && ($user->id == $this->profile->id)) {
            $this->element('p', null,
                           // TRANS: Page notice for page with an overview of all tag subscriptions
                           // TRANS: of the logged in user's own profile.
68
                           _m('You have subscribed to receive all notices on this site containing the following tags:'));
69 70 71 72
        } else {
            $this->element('p', null,
                           // TRANS: Page notice for page with an overview of all subscriptions of a user other
                           // TRANS: than the logged in user. %s is the user nickname.
73
                           sprintf(_m('%s has subscribed to receive all notices on this site containing the following tags:'),
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
                                   $this->profile->nickname));
        }
    }

    function showContent()
    {
        if (Event::handle('StartShowTagSubscriptionsContent', array($this))) {
            parent::showContent();

            $offset = ($this->page-1) * PROFILES_PER_PAGE;
            $limit =  PROFILES_PER_PAGE + 1;

            $cnt = 0;

            $tagsub = new TagSub();
            $tagsub->profile_id = $this->user->id;
90
            $tagsub->limit($limit, $offset);
91 92 93 94 95 96 97 98
            $tagsub->find();

            if ($tagsub->N) {
                $list = new TagSubscriptionsList($tagsub, $this->user, $this);
                $cnt = $list->show();
                if (0 == $cnt) {
                    $this->showEmptyListMessage();
                }
99 100
            } else {
                $this->showEmptyListMessage();
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
            }

            $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
                              $this->page, 'tagsubs',
                              array('nickname' => $this->user->nickname));


            Event::handle('EndShowTagSubscriptionsContent', array($this));
        }
    }

    function showEmptyListMessage()
    {
        if (common_logged_in()) {
            $current_user = common_current_user();
            if ($this->user->id === $current_user->id) {
117
                // TRANS: Tag subscription list text when the logged in user has no tag subscriptions.
118
                $message = _m('You are not listening to any hash tags right now. You can push the "Subscribe" button ' .
119 120
                              'on any hashtag page to automatically receive any public messages on this site that use that ' .
                              'tag, even if you are not subscribed to the poster.');
121
            } else {
122 123
                // TRANS: Tag subscription list text when looking at the subscriptions for a of a user other
                // TRANS: than the logged in user that has no tag subscriptions. %s is the user nickname.
124
                $message = sprintf(_m('%s is not following any tags.'), $this->user->nickname);
125 126 127 128 129
            }
        }
        else {
            // TRANS: Subscription list text when looking at the subscriptions for a of a user that has none
            // TRANS: as an anonymous user. %s is the user nickname.
130
            $message = sprintf(_m('%s is not following any tags.'), $this->user->nickname);
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
        }

        $this->elementStart('div', 'guide');
        $this->raw(common_markup_to_html($message));
        $this->elementEnd('div');
    }
}

// XXX SubscriptionsList and SubscriptionList are dangerously close

class TagSubscriptionsList extends SubscriptionList
{
    function newListItem($tagsub)
    {
        return new TagSubscriptionsListItem($tagsub, $this->owner, $this->action);
    }
}

class TagSubscriptionsListItem extends SubscriptionListItem
{
151 152 153 154 155
    function startItem()
    {
        $this->out->elementStart('li', array('class' => 'tagsub'));
    }

156 157
    function showProfile()
    {
158 159 160
        $tagsub = $this->profile;
        $tag = $tagsub->tag;

161 162 163 164 165
        // Relevant portion!
        $cur = common_current_user();
        if (!empty($cur) && $cur->id == $this->owner->id) {
            $this->showOwnerControls();
        }
166

167
        $url = common_local_url('tag', array('tag' => $tag));
168 169 170
        // TRANS: %1$s is a URL to a tag, %2$s is a tag,
        // TRANS: %3$s a date string.
        $linkline = sprintf(_m('#<a href="%1$s">%2$s</a> since %3$s'),
171 172 173 174 175 176 177 178 179 180 181 182
                            htmlspecialchars($url),
                            htmlspecialchars($tag),
                            common_date_string($tagsub->created));

        $this->out->elementStart('div', 'tagsub-item');
        $this->out->raw($linkline);
        $this->out->element('div', array('style' => 'clear: both'));
        $this->out->elementEnd('div');
    }

    function showActions()
    {
183 184 185 186
    }

    function showOwnerControls()
    {
187 188
        $this->out->elementStart('div', 'entity_actions');

189
        $tagsub = $this->profile; // ?
190
        $form = new TagUnsubForm($this->out, $tagsub->tag);
191
        $form->show();
192 193

        $this->out->elementEnd('div');
194 195 196
        return;
    }
}