]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/SearchSub/actions/searchsubs.php
Added more checked type-hints.
[quix0rs-gnu-social.git] / plugins / SearchSub / actions / searchsubs.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * List of a user's subscriptions
6  *
7  * PHP version 5
8  *
9  * LICENCE: This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU Affero General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Affero General Public License for more details.
18  *
19  * You should have received a copy of the GNU Affero General Public License
20  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21  *
22  * @category  Social
23  * @package   StatusNet
24  * @author    Evan Prodromou <evan@status.net>
25  * @author    Sarven Capadisli <csarven@status.net>
26  * @copyright 2008-2009 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET') && !defined('LACONICA')) {
32     exit(1);
33 }
34
35 /**
36  * A list of the user's subscriptions
37  *
38  * @category Social
39  * @package  StatusNet
40  * @author   Evan Prodromou <evan@status.net>
41  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
42  * @link     http://status.net/
43  */
44 class SearchSubsAction extends GalleryAction
45 {
46     function title()
47     {
48         if ($this->page == 1) {
49             // TRANS: Header for subscriptions overview for a user (first page).
50             // TRANS: %s is a user nickname.
51             return sprintf(_m('%s\'s search subscriptions'), $this->user->nickname);
52         } else {
53             // TRANS: Header for subscriptions overview for a user (not first page).
54             // TRANS: %1$s is a user nickname, %2$d is the page number.
55             return sprintf(_m('%1$s\'s search subscriptions, page %2$d'),
56                            $this->user->nickname,
57                            $this->page);
58         }
59     }
60
61     function showPageNotice()
62     {
63         $user = common_current_user();
64         if ($user && ($user->id == $this->profile->id)) {
65             $this->element('p', null,
66                            // TRANS: Page notice for page with an overview of all search subscriptions
67                            // TRANS: of the logged in user's own profile.
68                            _m('You have subscribed to receive all notices on this site matching the following searches:'));
69         } else {
70             $this->element('p', null,
71                            // TRANS: Page notice for page with an overview of all subscriptions of a user other
72                            // TRANS: than the logged in user. %s is the user nickname.
73                            sprintf(_m('%s has subscribed to receive all notices on this site matching the following searches:'),
74                                    $this->profile->nickname));
75         }
76     }
77
78     function showContent()
79     {
80         if (Event::handle('StartShowTagSubscriptionsContent', array($this))) {
81             parent::showContent();
82
83             $offset = ($this->page-1) * PROFILES_PER_PAGE;
84             $limit =  PROFILES_PER_PAGE + 1;
85
86             $cnt = 0;
87
88             $searchsub = new SearchSub();
89             $searchsub->profile_id = $this->user->id;
90             $searchsub->limit($limit, $offset);
91             $searchsub->find();
92
93             if ($searchsub->N) {
94                 $list = new SearchSubscriptionsList($searchsub, $this->user, $this);
95                 $cnt = $list->show();
96                 if (0 == $cnt) {
97                     $this->showEmptyListMessage();
98                 }
99             } else {
100                 $this->showEmptyListMessage();
101             }
102
103             $this->pagination($this->page > 1, $cnt > PROFILES_PER_PAGE,
104                               $this->page, 'searchsubs',
105                               array('nickname' => $this->user->nickname));
106
107
108             Event::handle('EndShowTagSubscriptionsContent', array($this));
109         }
110     }
111
112     function showEmptyListMessage()
113     {
114         if (common_logged_in()) {
115             $current_user = common_current_user();
116             if ($this->user->id === $current_user->id) {
117                 // TRANS: Search subscription list text when the logged in user has no search subscriptions.
118                 $message = _m('You are not subscribed to any text searches right now. You can push the "Subscribe" button ' .
119                              'on any notice text search to automatically receive any public messages on this site that match that ' .
120                              'search, even if you are not subscribed to the poster.');
121             } else {
122                 // TRANS: Search subscription list text when looking at the subscriptions for a of a user other
123                 // TRANS: than the logged in user that has no search subscriptions. %s is the user nickname.
124                 $message = sprintf(_m('%s is not subscribed to any searches.'), $this->user->nickname);
125             }
126         }
127         else {
128             // TRANS: Subscription list text when looking at the subscriptions for a of a user that has none
129             // TRANS: as an anonymous user. %s is the user nickname.
130             $message = sprintf(_m('%s is not subscribed to any searches.'), $this->user->nickname);
131         }
132
133         $this->elementStart('div', 'guide');
134         $this->raw(common_markup_to_html($message));
135         $this->elementEnd('div');
136     }
137 }
138
139 // XXX SubscriptionsList and SubscriptionList are dangerously close
140
141 class SearchSubscriptionsList extends SubscriptionList
142 {
143     function newListItem(SearchSub $searchsub)
144     {
145         return new SearchSubscriptionsListItem($searchsub, $this->owner, $this->action);
146     }
147 }
148
149 class SearchSubscriptionsListItem extends SubscriptionListItem
150 {
151     function startItem()
152     {
153         $this->out->elementStart('li', array('class' => 'searchsub'));
154     }
155
156     function showProfile()
157     {
158         $searchsub = $this->profile;
159         $search = $searchsub->search;
160
161         // Relevant portion!
162         $cur = common_current_user();
163         if (!empty($cur) && $cur->id == $this->owner->id) {
164             $this->showOwnerControls();
165         }
166
167         $url = common_local_url('noticesearch', array('q' => $search));
168         // TRANS: Search subscription list item. %1$s is a URL to a notice search,
169         // TRANS: %2$s are the search criteria, %3$s is a datestring.
170         $linkline = sprintf(_m('"<a href="%1$s">%2$s</a>" since %3$s'),
171                             htmlspecialchars($url),
172                             htmlspecialchars($search),
173                             common_date_string($searchsub->created));
174
175         $this->out->elementStart('div', 'searchsub-item');
176         $this->out->raw($linkline);
177         $this->out->element('div', array('style' => 'clear: both'));
178         $this->out->elementEnd('div');
179     }
180
181     function showActions()
182     {
183     }
184
185     function showOwnerControls()
186     {
187         $this->out->elementStart('div', 'entity_actions');
188
189         $searchsub = $this->profile; // ?
190         $form = new SearchUnsubForm($this->out, $searchsub->search);
191         $form->show();
192
193         $this->out->elementEnd('div');
194         return;
195     }
196 }