]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/Event/eventlistitem.php
More info for a proper, fancy-url lighttpd setup
[quix0rs-gnu-social.git] / plugins / Event / eventlistitem.php
1 <?php
2 /**
3  * StatusNet - the distributed open-source microblogging tool
4  * Copyright (C) 2011, StatusNet, Inc.
5  *
6  * Notice-list representation of an event
7  *
8  * PHP version 5
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  * @category  Event
24  * @package   StatusNet
25  * @author    Evan Prodromou <evan@status.net>
26  * @copyright 2011 StatusNet, Inc.
27  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
28  * @link      http://status.net/
29  */
30
31 if (!defined('STATUSNET')) {
32     // This check helps protect against security problems;
33     // your code file can't be executed directly from the web.
34     exit(1);
35 }
36
37 /**
38  * Notice-list representation of an event
39  *
40  * @category  General
41  * @package   StatusNet
42  * @author    Evan Prodromou <evan@status.net>
43  * @copyright 2011 StatusNet, Inc.
44  * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
45  * @link      http://status.net/
46  */
47 class EventListItem extends NoticeListItemAdapter
48 {
49     function showNotice()
50     {
51         $this->nli->out->elementStart('div', 'entry-title');
52         $this->nli->showAuthor();
53         $this->showContent();
54         $this->nli->out->elementEnd('div');
55     }
56
57     function showContent()
58     {
59         $notice = $this->nli->notice;
60         $out    = $this->nli->out;
61
62         $profile = $notice->getProfile();
63         $event   = Happening::fromNotice($notice);
64
65         if (empty($event)) {
66             // TRANS: Content for a deleted RSVP list item (RSVP stands for "please respond").
67             $out->element('p', null, _m('Deleted.'));
68             return;
69         }
70
71         $out->elementStart('div', 'vevent event'); // VEVENT IN
72
73         $out->elementStart('h3');  // VEVENT/H3 IN
74
75         if (!empty($event->url)) {
76             $out->element('a',
77                           array('href' => $event->url,
78                                 'class' => 'event-title entry-title summary'),
79                           $event->title);
80         } else {
81             $out->text($event->title);
82         }
83
84         $out->elementEnd('h3'); // VEVENT/H3 OUT
85
86         $now       = new DateTime();
87         $startDate = new DateTime($event->start_time);
88         $endDate   = new DateTime($event->end_time);
89         $userTz    = new DateTimeZone(common_timezone());
90
91         // Localize the time for the observer
92         $now->setTimeZone($userTz);
93         $startDate->setTimezone($userTz);
94         $endDate->setTimezone($userTz);
95
96         $thisYear  = $now->format('Y');
97         $startYear = $startDate->format('Y');
98         $endYear   = $endDate->format('Y');
99
100         $dateFmt = 'D, F j, '; // e.g.: Mon, Aug 31
101
102         if ($startYear != $thisYear || $endYear != $thisYear) {
103             $dateFmt .= 'Y,'; // append year if we need to think about years
104         }
105
106         $startDateStr = $startDate->format($dateFmt);
107         $endDateStr = $endDate->format($dateFmt);
108
109         $timeFmt = 'g:ia';
110
111         $startTimeStr = $startDate->format($timeFmt);
112         $endTimeStr = $endDate->format("{$timeFmt} (T)");
113
114         $out->elementStart('div', 'event-times'); // VEVENT/EVENT-TIMES IN
115
116         // TRANS: Field label for event description.
117         $out->element('strong', null, _m('Time:'));
118
119         $out->element('abbr', array('class' => 'dtstart',
120                                     'title' => common_date_iso8601($event->start_time)),
121                       $startDateStr . ' ' . $startTimeStr);
122         $out->text(' – ');
123         if ($startDateStr == $endDateStr) {
124             $out->element('span', array('class' => 'dtend',
125                                         'title' => common_date_iso8601($event->end_time)),
126                           $endTimeStr);
127         } else {
128             $out->element('span', array('class' => 'dtend',
129                                         'title' => common_date_iso8601($event->end_time)),
130                           $endDateStr . ' ' . $endTimeStr);
131         }
132
133         $out->elementEnd('div'); // VEVENT/EVENT-TIMES OUT
134
135         if (!empty($event->location)) {
136             $out->elementStart('div', 'event-location');
137             // TRANS: Field label for event description.
138             $out->element('strong', null, _m('Location:'));
139             $out->element('span', 'location', $event->location);
140             $out->elementEnd('div');
141         }
142
143         if (!empty($event->description)) {
144             $out->elementStart('div', 'event-description');
145             // TRANS: Field label for event description.
146             $out->element('strong', null, _m('Description:'));
147             $out->element('span', 'description', $event->description);
148             $out->elementEnd('div');
149         }
150
151         $rsvps = $event->getRSVPs();
152
153         $out->elementStart('div', 'event-rsvps');
154         // TRANS: Field label for event description.
155
156         $out->text(_('Attending:'));
157         $out->elementStart('ul', 'attending-list');
158
159         foreach ($rsvps as $verb => $responses) {
160             $out->elementStart('li', 'rsvp-list');
161             switch ($verb)
162             {
163             case RSVP::POSITIVE:
164                 $out->text(_('Yes:'));
165                 break;
166             case RSVP::NEGATIVE:
167                 $out->text(_('No:'));
168                 break;
169             case RSVP::POSSIBLE:
170                 $out->text(_('Maybe:'));
171                 break;
172             }
173             $ids = array();
174             foreach ($responses as $response) {
175                 $ids[] = $response->profile_id;
176             }
177             $ids = array_slice($ids, 0, ProfileMiniList::MAX_PROFILES + 1);
178             $profiles = Profile::pivotGet('id', $ids);
179             $profile  = new ArrayWrapper(array_values($profiles));
180             $minilist = new ProfileMiniList($profile, $out);
181             $minilist->show();
182
183             $out->elementEnd('li');
184         }
185
186         $out->elementEnd('ul');
187         $out->elementEnd('div');
188
189         $user = common_current_user();
190
191         if (!empty($user)) {
192             $rsvp = $event->getRSVP($user->getProfile());
193
194             if (empty($rsvp)) {
195                 $form = new RSVPForm($event, $out);
196             } else {
197                 $form = new CancelRSVPForm($rsvp, $out);
198             }
199
200             $form->show();
201         }
202
203         $out->elementEnd('div'); // vevent out
204     }
205 }