4 * Copyright (C) 2010, Free Software Foundation, Inc.
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.
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.
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/>.
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
28 //functions to sort replies
29 class NoticeTree extends NoticeList
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'));
40 while ($this->notice->fetch() && $cnt <= NOTICES_PER_PAGE) {
41 if (!empty($this->notice->reply_to))
46 if ($cnt > NOTICES_PER_PAGE) {
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());
60 $this->out->elementEnd('ol');
61 $this->out->elementEnd('div');
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; }
69 function showNoticePlus($item)
71 $replies = new Notice();
72 $replies->reply_to = $item->notice->id;
74 // We take responsibility for doing the li
76 $this->out->elementStart('li', array('class' => 'hentry notice',
77 'id' => 'notice-' . $item->notice->id));
81 if ($replies->find()) {
82 $this->out->elementStart('ol', array('class' => 'notices'));
84 $replieslist = array();
85 while ($replies->fetch()) {
86 $replieslist[] = $this->newListItem(clone($replies));
89 //Sorting based on url argument
90 if($_GET['sort'] == 'faves')
91 usort($replieslist, array($this, '_cmpFav'));
93 usort($replieslist, array($this, '_cmpDate'));
96 foreach($replieslist as $reply) {
97 $this->showNoticePlus($reply);
100 $this->out->elementEnd('ol');
103 $this->out->elementEnd('li');
106 function newListItem($notice)
108 return new NoticeTreeItem($notice, $this->out);
112 class NoticeTreeItem extends NoticeListItem
114 function __construct($notice, $out=null)
116 parent::__construct($notice, $out);
118 //Showing number of favorites
120 $fave->notice_id = $this->notice->id;
123 while ($fave->fetch())
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...
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);
145 $this->out->elementEnd('div');
149 function showContext()
154 //Just changing the link...
155 function showReplyLink()
157 if (common_logged_in()) {
158 $this->out->text(' ');
159 //Why doesn't common_local_url work here?
160 $reply_url = '/notice/respond?replyto=' . $this->profile->nickname . '&inreplyto=' . $this->notice->id;
161 $this->out->elementStart('a', array('href' => $reply_url,
162 'class' => 'notice_reply',
163 'title' => _('Reply to this notice')));
164 $this->out->text(_('Reply'));
165 $this->out->text(' ');
166 $this->out->element('span', 'notice_id', $this->notice->id);
167 $this->out->elementEnd('a');
173 class ReplyForm extends NoticeForm
175 //Changing the text. We have to either repeat ids or get hacky. I vote repeat ids.
178 if (Event::handle('StartShowNoticeFormData', array($this))) {
179 // XXX: vary by defined max size
180 $this->out->element('textarea', array('id' => 'notice_data-text',
183 'name' => 'status_textarea'),
184 ($this->content) ? $this->content : '');
186 $contentLimit = Notice::maxContent();
188 if ($contentLimit > 0) {
189 $this->out->elementStart('dl', 'form_note');
190 $this->out->element('dt', null, _('Available characters'));
191 $this->out->element('dd', array('id' => 'notice_text-count'),
193 $this->out->elementEnd('dl');
196 if (common_config('attachments', 'uploads')) {
197 $this->out->element('label', array('for' => 'notice_data-attach'),_('Attach'));
198 $this->out->element('input', array('id' => 'notice_data-attach',
201 'title' => _('Attach a file')));
202 $this->out->hidden('MAX_FILE_SIZE', common_config('attachments', 'file_quota'));
205 $this->out->hidden('notice_return-to', $this->action, 'returnto');
207 $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto');
209 if ($this->profile->shareLocation()) {
210 $this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat');
211 $this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon');
212 $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');
213 $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');
215 $this->out->elementStart('div', array('id' => 'notice_data-geo_wrap',
216 'title' => common_local_url('geocode')));
217 $this->out->checkbox('notice_data-geo', _('Share my location'), true);
218 $this->out->elementEnd('div');
219 $this->out->inlineScript(' var NoticeDataGeo_text = {'.
220 'ShareDisable: ' .json_encode(_('Do not share my location')).','.
221 'ErrorTimeout: ' .json_encode(_('Sorry, retrieving your geo location is taking longer than expected, please try again later')).
225 Event::handle('EndShowNoticeFormData', array($this));