]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - lib/personal.php
34ebe68942aa42aa022ef8bec721bf52b969d3ca
[quix0rs-gnu-social.git] / lib / personal.php
1 <?php
2 /*
3  * Laconica - a distributed open-source microblogging tool
4  * Copyright (C) 2008, Controlez-Vous, Inc.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Affero General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU Affero General Public License for more details.
15  *
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 if (!defined('LACONICA')) { exit(1); }
21
22 class PersonalAction extends Action {
23     
24     function is_readonly()
25     {
26         return true;
27     }
28     
29     function handle($args)
30     {
31         parent::handle($args);
32         common_set_returnto($this->self_url());
33     }
34
35     function views_menu()
36     {
37
38         $user = null;
39         $action = $this->trimmed('action');
40         $nickname = $this->trimmed('nickname');
41
42         if ($nickname) {
43             $user = User::staticGet('nickname', $nickname);
44             $user_profile = $user->getProfile();
45         } else {
46             $user_profile = false;
47         }
48
49         common_element_start('ul', array('id' => 'nav_views'));
50
51         common_menu_item(common_local_url('all', array('nickname' =>
52                                                        $nickname)),
53                          _('Personal'),
54                          sprintf(_('%s and friends'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)),
55                          $action == 'all');
56         common_menu_item(common_local_url('replies', array('nickname' =>
57                                                               $nickname)),
58                          _('Replies'),
59                          sprintf(_('Replies to %s'), (($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname)),
60                          $action == 'replies');
61         common_menu_item(common_local_url('showstream', array('nickname' =>
62                                                               $nickname)),
63                          _('Profile'),
64                          ($user_profile && $user_profile->fullname) ? $user_profile->fullname : $nickname,
65                          $action == 'showstream');
66         common_menu_item(common_local_url('showfavorites', array('nickname' =>
67                                                               $nickname)),
68                          _('Favorites'),
69                          sprintf(_('%s\'s favorite notices'), ($user_profile) ? $user_profile->getBestName() : _('User')),
70                          $action == 'showfavorites');
71         
72         $cur = common_current_user();
73         
74         if ($cur && $cur->id == $user->id) {
75             
76             common_menu_item(common_local_url('inbox', array('nickname' =>
77                                                                      $nickname)),
78                              _('Inbox'),
79                              _('Your incoming messages'),
80                              $action == 'inbox');
81             common_menu_item(common_local_url('outbox', array('nickname' =>
82                                                                      $nickname)),
83                              _('Outbox'),
84                              _('Your sent messages'),
85                              $action == 'outbox');
86         }
87         
88         common_element_end('ul');
89     }
90
91     function show_feeds_list($feeds)
92     {
93         common_element_start('div', array('class' => 'feeds'));
94         common_element('p', null, 'Feeds:');
95         common_element_start('ul', array('class' => 'xoxo'));
96
97         foreach ($feeds as $key => $value) {
98             $this->common_feed_item($feeds[$key]);
99         }
100         common_element_end('ul');
101         common_element_end('div');
102     }
103
104     function common_feed_item($feed)
105     {
106         $nickname = $this->trimmed('nickname');
107
108         switch($feed['item']) {
109             case 'notices': default:
110                 $feed_classname = $feed['type'];
111                 $feed_mimetype = "application/".$feed['type']."+xml";
112                 $feed_title = "$nickname's ".$feed['version']." notice feed";
113                 $feed['textContent'] = "RSS";
114                 break;
115
116             case 'allrss':
117                 $feed_classname = $feed['type'];
118                 $feed_mimetype = "application/".$feed['type']."+xml";
119                 $feed_title = $feed['version']." feed for $nickname and friends";
120                 $feed['textContent'] = "RSS";
121                 break;
122
123             case 'repliesrss':
124                 $feed_classname = $feed['type'];
125                 $feed_mimetype = "application/".$feed['type']."+xml";
126                 $feed_title = $feed['version']." feed for replies to $nickname";
127                 $feed['textContent'] = "RSS";
128                 break;
129
130             case 'publicrss':
131                 $feed_classname = $feed['type'];
132                 $feed_mimetype = "application/".$feed['type']."+xml";
133                 $feed_title = "Public timeline ".$feed['version']." feed";
134                 $feed['textContent'] = "RSS";
135                 break;
136
137             case 'publicatom':
138                 $feed_classname = "atom";
139                 $feed_mimetype = "application/".$feed['type']."+xml";
140                 $feed_title = "Public timeline ".$feed['version']." feed";
141                 $feed['textContent'] = "Atom";
142                 break;
143
144             case 'tagrss':
145                 $feed_classname = $feed['type'];
146                 $feed_mimetype = "application/".$feed['type']."+xml";
147                 $feed_title = $feed['version']." feed for this tag";
148                 $feed['textContent'] = "RSS";
149                 break;
150
151             case 'favoritedrss':
152                 $feed_classname = $feed['type'];
153                 $feed_mimetype = "application/".$feed['type']."+xml";
154                 $feed_title = "Favorited ".$feed['version']." feed";
155                 $feed['textContent'] = "RSS";
156                 break;
157
158             case 'foaf':
159                 $feed_classname = "foaf";
160                 $feed_mimetype = "application/".$feed['type']."+xml";
161                 $feed_title = "$nickname's FOAF file";
162                 $feed['textContent'] = "FOAF";
163                 break;
164
165             case 'favoritesrss':
166                 $feed_classname = "favorites";
167                 $feed_mimetype = "application/".$feed['type']."+xml";
168                 $feed_title = "Feed for favorites of $nickname";
169                 $feed['textContent'] = "RSS";
170                 break;
171
172             case 'usertimeline':
173                 $feed_classname = "atom";
174                 $feed_mimetype = "application/".$feed['type']."+xml";
175                 $feed_title = "$nickname's ".$feed['version']." notice feed";
176                 $feed['textContent'] = "Atom";
177                 break;
178         }
179         common_element_start('li');
180         common_element('a', array('href' => $feed['href'],
181                                   'class' => $feed_classname,
182                                   'type' => $feed_mimetype,
183                                   'title' => $feed_title),
184                             $feed['textContent']);
185         common_element_end('li');
186     }
187
188     
189     function source_link($source)
190     {
191         $source_name = _($source);
192         switch ($source) {
193          case 'web':
194          case 'xmpp':
195          case 'mail':
196          case 'omb':
197          case 'api':
198             common_element('span', 'noticesource', $source_name);
199             break;
200          default:
201             $ns = Notice_source::staticGet($source);
202             if ($ns) {
203                 common_element('a', array('href' => $ns->url),
204                                $ns->name);
205             } else {
206                 common_element('span', 'noticesource', $source_name);
207             }
208             break;
209         }
210         return;
211     }
212 }