]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/GNUsocialProfileExtensions/lib/noticetree.php
Updates to reply status box
[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
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->notice);
52             } catch (Exception $e) {
53                 // we log exceptions and continue
54                 common_log(LOG_ERR, $e->getMessage());
55                 continue;
56             }
57         }
58
59         $this->out->elementEnd('ol');
60         $this->out->elementEnd('div');
61
62         return $cnt;
63     }
64
65
66     function showNoticePlus($notice)
67     {
68         $replies = new Notice();
69         $replies->reply_to = $notice->id;
70
71         // We take responsibility for doing the li
72
73          $this->out->elementStart('li', array('class' => 'hentry notice',
74                                              'id' => 'notice-' . $id));
75
76         $item = $this->newListItem($notice);
77         $item->show();
78
79         if ($replies->find()) {
80             $this->out->elementStart('ol', array('class' => 'notices'));
81
82             while ($replies->fetch()) {
83                 $this->showNoticePlus($replies);
84             }
85
86             $this->out->elementEnd('ol');
87         }
88
89         $this->out->elementEnd('li');
90     }
91
92     function newListItem($notice)
93     {
94         return new NoticeTreeItem($notice, $this->out);
95     }
96 }
97
98 class NoticeTreeItem extends NoticeListItem
99 {
100     function showStart()
101     {
102         return;
103     }
104
105     function showEnd()
106     {
107         //TODO: Rewrite this
108         //Showing number of favorites
109         $fave = new Fave();
110         $fave->notice_id = $this->notice->id;
111         $cnt = 0;
112         if ($fave->find()) {
113             while ($fave->fetch())
114                 $cnt++;
115         }
116         if ($cnt > 0) {
117             $this->out->text(_m("Favorited by $cnt user"));
118             if ($cnt > 1) $this->out->text("s"); //there has to be a better way to do this...
119         }
120
121         //Show response form
122         $this->out->elementStart('div', array('id' => 'form' . $this->notice->id, 'class' => 'replyform'));
123         $noticeform = new ReplyForm($this->out, null, null, null, $this->notice->id);
124         $noticeform->show();
125         $this->out->elementEnd('div');
126         return;
127     }
128
129     function showContext()
130     {
131         return;
132     }
133
134     //Just changing the link...
135     function showReplyLink()
136     {
137         if (common_logged_in()) {
138             $this->out->text(' ');
139             //Why doesn't common_local_url work here?
140             $reply_url = '/notice/respond?replyto=' . $this->profile->nickname . '&inreplyto=' . $this->notice->id;
141             $this->out->elementStart('a', array('href' => $reply_url,
142                                                 'class' => 'notice_reply',
143                                                 'title' => _('Reply to this notice')));
144             $this->out->text(_('Reply'));
145             $this->out->text(' ');
146             $this->out->element('span', 'notice_id', $this->notice->id);
147             $this->out->elementEnd('a');
148         }
149     }
150
151 }
152
153 class ReplyForm extends NoticeForm
154 {
155     //Changing the text.  We have to either repeat ids or get hacky.  I vote repeat ids.
156     function formData()
157     {
158         if (Event::handle('StartShowNoticeFormData', array($this))) {
159             // XXX: vary by defined max size
160             $this->out->element('textarea', array('id' => 'notice_data-text',
161                                                   'cols' => 35,
162                                                   'rows' => 4,
163                                                   'name' => 'status_textarea'),
164                                 ($this->content) ? $this->content : '');
165
166             $contentLimit = Notice::maxContent();
167
168             if ($contentLimit > 0) {
169                 $this->out->elementStart('dl', 'form_note');
170                 $this->out->element('dt', null, _('Available characters'));
171                 $this->out->element('dd', array('id' => 'notice_text-count'),
172                                     $contentLimit);
173                 $this->out->elementEnd('dl');
174             }
175
176             if (common_config('attachments', 'uploads')) {
177                 $this->out->element('label', array('for' => 'notice_data-attach'),_('Attach'));
178                 $this->out->element('input', array('id' => 'notice_data-attach',
179                                                    'type' => 'file',
180                                                    'name' => 'attach',
181                                                    'title' => _('Attach a file')));
182                 $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
183             }
184             if ($this->action) {
185                 $this->out->hidden('notice_return-to', $this->action, 'returnto');
186             }
187             $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
188
189             if ($this->user->shareLocation()) {
190                 $this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
191                 $this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
192                 $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');
193                 $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');
194
195                 $this->out->elementStart('div', array('id' => 'notice_data-geo_wrap',
196                                                       'title' => common_local_url('geocode')));
197                 $this->out->checkbox('notice_data-geo', _('Share my location'), true);
198                 $this->out->elementEnd('div');
199                 $this->out->inlineScript(' var NoticeDataGeo_text = {'.
200                     'ShareDisable: ' .json_encode(_('Do not share my location')).','.
201                     'ErrorTimeout: ' .json_encode(_('Sorry, retrieving your geo location is taking longer than expected, please try again later')).
202                     '}');
203             }
204
205             Event::handle('EndShowNoticeFormData', array($this));
206         }
207     }
208 }