]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialProfileExtensions/lib/noticetree.php
XSS vulnerability when remote-subscribing
[quix0rs-gnu-social.git] / plugins / GNUsocialProfileExtensions / lib / noticetree.php
1 <?php
2 /**
3  * GNU Social
4  * Copyright (C) 2010, Free Software Foundation, Inc.
5  *
6  * PHP version 5
7  *
8  * LICENCE:
9  * 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  Widget
23  * @package   GNU Social
24  * @author    Max Shinn <trombonechamp@gmail.com>
25  * @copyright 2011 Free Software Foundation, Inc.
26  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
27  */
28             //functions to sort replies
29 class NoticeTree extends NoticeList
30 {
31     function show()
32     {
33         $this->out->elementStart('div', array('id' =>'notices_primary'));
34         // TRANS: Header on conversation page. Hidden by default (h2).
35         $this->out->element('h2', null, _('Notices'));
36         $this->out->elementStart('ol', array('class' => 'notices xoxo'));
37
38         $cnt = 0;
39
40         while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
41             if (!empty($this->notice->reply_to))
42                 continue;
43
44             $cnt++;
45
46             if ($cnt > NOTICES_PER_PAGE) {
47                 break;
48             }
49
50             try {
51                 $this->showNoticePlus($this->newListItem($this->notice));
52             } catch (Exception $e) {
53                 // we log exceptions and continue
54                 print "ERROR!" . $e->getMessage();
55                 common_log(LOG_ERR, $e->getMessage());
56                 continue;
57             }
58         }
59
60         $this->out->elementEnd('ol');
61         $this->out->elementEnd('div');
62
63         return $cnt;
64     }
65
66     function _cmpDate($a, $b) { return strcmp($a->notice->modified, $b->notice->modified); }
67     function _cmpFav($a, $b) { return (int)$a->faves < (int)$b->faves; }
68
69     function showNoticePlus($item)
70     {
71         $replies = new Notice();
72         $replies->reply_to = $item->notice->id;
73
74         // We take responsibility for doing the li
75
76         $this->out->elementStart('li', array('class' => 'h-entry notice',
77                                              'id' => 'notice-' . $item->notice->id));
78
79         $item->show();
80
81         if ($replies->find()) {
82             $this->out->elementStart('ol', array('class' => 'notices'));
83
84             $replieslist = array();
85             while ($replies->fetch()) {
86                 $replieslist[] = $this->newListItem(clone($replies));
87             }
88
89             //Sorting based on url argument
90             if($_GET['sort'] == 'faves')
91                 usort($replieslist, array($this, '_cmpFav'));
92             else
93                 usort($replieslist, array($this, '_cmpDate'));
94
95
96             foreach($replieslist as $reply) {
97                 $this->showNoticePlus($reply);
98             }
99
100             $this->out->elementEnd('ol');
101         }
102
103         $this->out->elementEnd('li');
104     }
105
106     function newListItem($notice)
107     {
108         return new NoticeTreeItem($notice, $this->out);
109     }
110 }
111
112 class NoticeTreeItem extends NoticeListItem
113 {
114     function __construct($notice, $out=null)
115     {
116         parent::__construct($notice, $out);
117         //TODO: Rewrite this
118         //Showing number of favorites
119         $fave = new Fave();
120         $fave->notice_id = $this->notice->id;
121         $cnt = 0;
122         if ($fave->find()) {
123             while ($fave->fetch())
124                 $cnt++;
125         }
126         $this->faves = $cnt;
127     }        
128
129     function showStart()
130     {
131         return;
132     }
133
134     function showEnd()
135     {
136         if ($this->faves > 0) {
137             $this->out->text(_m("Favorited by $this->faves user"));
138             if ($this->faves > 1) $this->out->text("s"); //there has to be a better way to do this...
139         }
140
141         //Show response form
142         $this->out->elementStart('div', array('id' => 'form' . $this->notice->id, 'class' => 'replyform'));
143         $noticeform = new ReplyForm($this->out, null, null, null, $this->notice->id);
144         $noticeform->show();
145         $this->out->elementEnd('div');
146         return;
147     }
148
149     //Just changing the link...
150     function showReplyLink()
151     {
152         if (common_logged_in()) {
153             $this->out->text(' ');
154             //Why doesn't common_local_url work here?
155             $reply_url = '/notice/respond?replyto=' . $this->profile->nickname . '&inreplyto=' . $this->notice->id;
156             $this->out->elementStart('a', array('href' => $reply_url,
157                                                 'class' => 'notice_reply',
158                                                 'title' => _('Reply to this notice')));
159             $this->out->text(_('Reply'));
160             $this->out->text(' ');
161             $this->out->element('span', 'notice_id', $this->notice->id);
162             $this->out->elementEnd('a');
163         }
164     }
165
166 }
167
168 class ReplyForm extends NoticeForm
169 {
170     //Changing the text.  We have to either repeat ids or get hacky.  I vote repeat ids.
171     function formData()
172     {
173         if (Event::handle('StartShowNoticeFormData', array($this))) {
174             // XXX: vary by defined max size
175             $this->out->element('textarea', array('id' => 'notice_data-text',
176                                                   'cols' => 35,
177                                                   'rows' => 4,
178                                                   'name' => 'status_textarea'),
179                                 ($this->content) ? $this->content : '');
180
181             $contentLimit = Notice::maxContent();
182
183             if ($contentLimit > 0) {
184                 $this->out->elementStart('dl', 'form_note');
185                 $this->out->element('dt', null, _('Available characters'));
186                 $this->out->element('dd', array('id' => 'notice_text-count'),
187                                     $contentLimit);
188                 $this->out->elementEnd('dl');
189             }
190
191             if (common_config('attachments', 'uploads')) {
192                 $this->out->element('label', array('for' => 'notice_data-attach'),_('Attach'));
193                 $this->out->element('input', array('id' => 'notice_data-attach',
194                                                    'type' => 'file',
195                                                    'name' => 'attach',
196                                                    'title' => _('Attach a file')));
197                 $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
198             }
199             if ($this->action) {
200                 $this->out->hidden('notice_return-to', $this->action, 'returnto');
201             }
202             $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
203
204             if ($this->profile->shareLocation()) {
205                 $this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
206                 $this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
207                 $this->out->hidden('notice_data-location_id', empty($this->location_id) ? (empty($this->profile->location_id) ? null : $this->profile->location_id) : $this->location_id, 'location_id');
208                 $this->out->hidden('notice_data-location_ns', empty($this->location_ns) ? (empty($this->profile->location_ns) ? null : $this->profile->location_ns) : $this->location_ns, 'location_ns');
209
210                 $this->out->elementStart('div', array('id' => 'notice_data-geo_wrap',
211                                                       'title' => common_local_url('geocode')));
212                 $this->out->checkbox('notice_data-geo', _('Share my location'), true);
213                 $this->out->elementEnd('div');
214                 $this->out->inlineScript(' var NoticeDataGeo_text = {'.
215                     'ShareDisable: ' .json_encode(_('Do not share my location')).','.
216                     'ErrorTimeout: ' .json_encode(_('Sorry, retrieving your geo location is taking longer than expected, please try again later')).
217                     '}');
218             }
219
220             Event::handle('EndShowNoticeFormData', array($this));
221         }
222     }
223 }