/[drupal]/contributions/sandbox/frjo/event/event.module-fj.patch
ViewVC logotype

Contents of /contributions/sandbox/frjo/event/event.module-fj.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download) (as text)
Fri Apr 22 07:25:33 2005 UTC (4 years, 7 months ago) by frjo
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +26 -17 lines
File MIME type: text/x-patch
My patch version2 of event.module for Drupal 4.5
1 --- event/event.module Thu Dec 23 04:00:03 2004
2 +++ event-fj/event.module Fri Apr 22 09:16:32 2005
3 @@ -1,10 +1,20 @@
4 <?php
5 -// $Id: event.module,v 1.96.2.6 2004/12/22 21:32:31 killes Exp $
6 +// $Id: event.module, frjo Exp $
7
8 /**
9 * Retrieves all of the fields from fields.inc. To add extra fields you might need, add them to the file called
10 * fields.inc in the event module directory.
11 *
12 + * This version add end time, you need to add a end field to the event table:
13 + * ALTER TABLE event ADD end int(10) unsigned NOT NULL default '0';
14 + *
15 + * You probably need to change the time zone for the iCalender.
16 + * Do a search/replace for "Europe/Stockholm" to whatever you want.
17 + * I know, this you be set automatically or via a setting.
18 + *
19 + * This version of the event.module can be downloaded from my sandbox
20 + * <http://cvs.drupal.org/viewcvs/drupal/contributions/sandbox/frjo/>
21 + *
22 * @return an array of fields
23 */
24 function event_fields() {
25 @@ -65,9 +75,12 @@
26 $block['content'] = event_display('event_calendar_simple', $year, $month, $day);
27 return $block;
28 case 1:
29 + $ical_url = l(t('subscribe iCal'), 'event/ical', array('title' => t('Add this calendar to your iCalendar')), NULL, NULL, true);
30 + $ical_url = preg_replace("|http://|","webcal://", $ical_url);
31 +
32 $block['subject'] = t('Upcoming events');
33 $block['content'] = event_block_upcoming();
34 - $block['content'] .= '<div class="more-link">'. l(t('more'), 'event', array('title' => t('More events.'))) .'</div>';
35 + $block['content'] .= '<div class="more-link">'. $ical_url .' | '. l(t('more'), 'event', array('title' => t('More events.'))) .'</div>';
36 return $block;
37 }
38 }
39 @@ -81,14 +94,16 @@
40 */
41 function event_settings() {
42 $output = form_textarea(t('Explanation or submission guidelines'), 'event_help', variable_get('event_help', ''), 70, 5, t('This text will be displayed at the top of the event submission form. Useful for helping or instructing your users.'));
43 - $output .= form_radios(t('Time notation preference'), 'event_ampm', variable_get('event_ampm', '0'), array('0' => t('24h'),'1' => t('12h')), t('The time notation system used for entering event start times.'));
44 + $output .= form_radios(t('Time notation preference'), 'event_ampm', variable_get('event_ampm', '0'), array('0' => t('24h'), '1' => t('12h')), t('The time notation system used for entering event start times.'));
45 $output .= form_radios(t('Timezone handling'), 'event_timezone', variable_get('event_timezone', '1'), array('1' => t('Yes'), '0' => t('No')), t("Yes: Times are saved relative to the user's timezone. No: Times are displayed exactly as the user inputted them."));
46 $output .= form_select(t('Type of overview'), 'event_overview', variable_get('event_overview', 'calendar'), array('calendar' => t('Calendar'), 'table' => t('Table')), t('The type of overview to show the user when he clicks on the block calendar.'));
47
48 $extra = event_fields();
49 $headerarray = array();
50 foreach($extra as $key => $value) {
51 - if ($value[0] == ('textfield' || 'textarea' || 'select') && $value[3]) $headerarray['e.'. $key] = $value[1];
52 + if ($value[0] == ('textfield' || 'textarea' || 'select') && $value[3]) {
53 + $headerarray['e.'. $key] = $value[1];
54 + }
55 }
56 $headerarray = array_merge(array('e.start' => t('Date'), 'n.title' => t('Title'), 'n.teaser' => t('Teaser'), 'n.body' => t('Body')), $headerarray);
57 $output .= form_select(t('Table headers'), 'event_table_headers', variable_get('event_table_headers', array('e.start', 'n.title', 'n.teaser')), $headerarray, t('The table headers used in the table view. Only entries that have their own database column in the event table and are of type "textfield", "textarea", or "select" can be used.'), 0, 1);
58 @@ -124,8 +139,8 @@
59 unset($node->start); // we need to select e.start for pgsql's sake but it confuses node_load.
60 $output .= node_view(node_load($node), 1);
61 }
62 - $output .= theme("pager", NULL, variable_get("default_nodes_main", 10));
63 - print theme('page', $output, t("Upcoming Events"), $breadcrumbs);
64 + $output .= theme("pager", NULL, variable_get('default_nodes_main', 10));
65 + print theme('page', $output, t('Upcoming events'), $breadcrumbs);
66 return;
67 }
68 }
69 @@ -149,7 +164,9 @@
70 else {
71 $output .= event_display('event_calendar_expanded', $year, $month, $day, 1);
72 }
73 - $output .= theme('links', array( l(t('search events'), "event/search") ));
74 + $ical_url = l(t('subscribe iCal'), 'event/ical', array('title' => t('Add this calendar to your iCalendar')), NULL, NULL, true);
75 + $ical_url = preg_replace("|http://|","webcal://", $ical_url);
76 + $output .= '<br />'.theme('links', array(l(t('search events'), "event/search"), $ical_url));
77 $output .= '</div>';
78
79 $timestamp = gmmktime(0, 0, 0, $month, ($day ? $day : 1), $year);
80 @@ -233,6 +250,10 @@
81 $items[] = array('path' => 'event/search', 'title' => t('search'),
82 'callback' => 'event_page',
83 'type' => MENU_SUGGESTED_ITEM);
84 + $items[] = array('path' => 'event/ical', 'title' => t('iCal'),
85 + 'access' => user_access('access content'),
86 + 'callback' => '_event_ical',
87 + 'type' => MENU_SUGGESTED_ITEM);
88 }
89 else {
90 drupal_set_html_head(event_html_head());
91 @@ -291,39 +312,58 @@
92 * @return any error messages this method generates.
93 */
94 function event_validate(&$node) {
95 - // Re-calculate $node->start if we have all the parameters.
96 - if (isset($node->year) && isset($node->month) && isset($node->day) && isset($node->hour) && isset($node->minute)) {
97 - $hour = $node->hour;
98 + // Re-calculate $node->start and $node->end if we have all the parameters.
99 + event_validate_time($node, 'start');
100 + event_validate_time($node, 'end');
101 +
102 + $fields = event_fields();
103 + foreach ($fields as $field => $def) {
104 + if ($def[2] && isset($node->$field) && empty($node->$field)) {
105 + form_set_error($field, t($def[1]).' '.t('is a required field.'));
106 + }
107 + }
108 + if (isset($node->body) && empty($node->body)) {
109 + form_set_error('body', t('Specify details for this event'));
110 + }
111 +}
112 +
113 +
114 +function event_validate_time(&$node, $time) {
115 + $year = $time . '_year';
116 + $month = $time . '_month';
117 + $day = $time . '_day';
118 + $hour = $time . '_hour';
119 + $minute = $time . '_minute';
120 + $ampm = $time . '_ampm';
121 + if (isset($node->$year) && isset($node->$month) && isset($node->$day) && isset($node->$hour) && isset($node->$minute)) {
122 + $the_hour = $node->$hour;
123 if (variable_get('event_ampm', '0')) {
124 - if (($node->ampm == 'pm') && ($hour != 12)) {
125 - $hour += 12;
126 + if ($node->$ampm == 'pm' && $the_hour != 12) {
127 + $the_hour += 12;
128 }
129 - elseif (($node->ampm == 'am') && ($hour == 12)) {
130 - $hour -= 12;
131 + if ($the_hour == 12 && $node->$ampm == 'am') {
132 + $the_hour -= 12;
133 }
134 }
135 - $node->start = _event_mktime($hour, $node->minute, 0, $node->month, $node->day, $node->year);
136 + $node->$time = _event_mktime($the_hour, $node->$minute, 0, $node->$month, $node->$day, $node->$year);
137 if (variable_get('event_timezone', '1')) {
138 - $node->start -= $GLOBALS['user']->timezone;
139 + $node->$time -= $GLOBALS['user']->timezone;
140 }
141 }
142
143 - if (empty($node->start)) {
144 - $node->start = time();
145 - // Round to nearest hour:
146 - $node->start -= $node->start % (60 * 60);
147 - }
148 -
149 - $fields = event_fields();
150 - foreach ($fields as $field => $def) {
151 - if ($def[2] && empty($node->$field)) {
152 - $error[$field] = t("Required.");
153 + if (empty($node->$time)) {
154 + if ($time == 'start') {
155 + $node->$time = time();
156 + }
157 + else {
158 + $node->$time = $node->start - 0;
159 }
160 + // Round to nearest hour:
161 + $node->$time -= $node->$time % (60 * 60);
162 }
163 -
164 - return $error;
165 }
166
167 +
168 /**
169 * Completes an event node by setting the teaser and body fields.
170 *
171 @@ -337,7 +377,10 @@
172
173 $output = '<div class="event">';
174 $output .= '<div class="details">';
175 - $output .= form_item(t('Start'), event_format_date($node->start));
176 + $output .= form_item(t('Start'), event_format_date($node->start, 'large'));
177 + if ($node->end > $node->start) {
178 + $output .= form_item(t('End'), event_format_date($node->end, 'large'));
179 + }
180 foreach ($fields as $field => $def) {
181 if ($node->$field) {
182 if ($def[0] == "select") {
183 @@ -358,8 +401,8 @@
184 }
185 $output .= '</div>';
186
187 - $node->teaser = $output . ($node->teaser ? '<div class="content">'. check_output($node->teaser) .'</div></div>' : '</div>');
188 - $node->body = $output . ($node->body ? '<div class="content">'. check_output($node->body) .'</div></div>' : '</div>');
189 + $node->teaser = $output . ($node->teaser ? '<div class="content">'. check_output($node->teaser, $node->format) .'</div></div>' : '</div>');
190 + $node->body = $output . ($node->body ? '<div class="content">'. check_output($node->body, $node->format) .'</div></div>' : '</div>');
191
192 $node->readmore = (strlen($node->teaser) < strlen($node->body));
193
194 @@ -456,16 +499,12 @@
195 if (module_exist('taxonomy')) {
196 $output .= implode('', taxonomy_node_form('event', $node));
197 }
198 - $output .= form_item(t('Start'), event_form_date($node->start), t('When is this event taking place.'));
199 + $output .= form_item(t('Start'), event_form_date($node->start, 'start_'), t('When is this event taking place.'));
200 + $output .= form_item(t('End'), event_form_date($node->end, 'end_'), t('Scheduled end time. If you do not wish to display and end time for this event, do not adjust this time.'));
201 $fields = event_fields();
202 foreach ($fields as $field => $def) {
203 $function = "form_$def[0]";
204 - if (in_array($def[0], array('password', 'textfield', 'textarea'))) {
205 - $output .= $function($def[1], $field, $node->$field, $def[7], $def[8], $def[9] . theme_error($error[$field]), $def[10]);
206 - }
207 - else {
208 - $output .= $function($def[1], $field, $node->$field, $def[7], $def[8] . theme_error($error[$field]), $def[9], $def[10]);
209 - }
210 + $output .= $function($def[1], $field, $node->$field, $def[7], $def[8], $def[9], NULL, $def[2]);
211 }
212 $output .= form_textarea(t('Details'), 'body', $node->body, 60, 15, '', NULL, TRUE);
213 $output .= filter_form('format', $node->format);
214 @@ -523,7 +562,7 @@
215 * @param @$node The node that is being inserted.
216 */
217 function event_insert(&$node) {
218 - $fields = array('nid', 'start', 'data');
219 + $fields = array('nid', 'start', 'end', 'data');
220 $sql = event_create_query($fields, $node, $values);
221 foreach ($values as $value) {
222 $vals[] = is_array($value) ? serialize($value) : $value;
223 @@ -538,7 +577,7 @@
224 * @param &$node The node that is being updated.
225 */
226 function event_update(&$node) {
227 - $fields = array('start', 'data');
228 + $fields = array('start', 'end', 'data');
229 $sql = event_create_query($fields, $node, $values, 0);
230 foreach ($values as $value) {
231 $vals[] = is_array($value) ? serialize($value) : $value;
232 @@ -645,11 +684,11 @@
233 $data[$year][$month][event_format_date($node->start, 'custom', 'j')] = $node;
234 }
235 }
236 - if($data[$year][$month][$day]) {
237 + if ($data[$year][$month][$day]) {
238 $title = array();
239 $node = $data[$year][$month][$day];
240 - $title[] = event_format_date($node->start, 'custom', 'H:i') . ": " . $node->title;
241 - if(module_exist("over_text")){
242 + $title[] = event_format_date($node->start, 'custom', 'H:i') .": ". $node->title;
243 + if (module_exist('over_text')) {
244 $params = over_text_make(event_format_date($node->start, 'custom', 'l F jS'), join(" | ", $title));
245 }
246 else {
247 @@ -771,13 +810,15 @@
248
249 // Initialize the header/week days:
250 if (variable_get('event_start_min', 0) < $date) {
251 - $prev = '<span class="prev">'. l('&laquo;', 'event/'. ($month - 1 < 1 ? $year - 1 .'/12' : "$year/". ($month - 1)) . ($day ? "/$day" : '')) .'</span>';
252 + // $prev = '<span class="prev">'. l('&laquo;', 'event/'. ($month - 1 < 1 ? $year - 1 .'/12' : "$year/". ($month - 1)) . ($day ? "/$day" : '')) .'</span>';
253 + $prev = '<span class="prev">'. l('&laquo;', 'event/'. ($month - 1 < 1 ? $year - 1 .'/12' : "$year/". ($month - 1))) .'</span>';
254 }
255 else {
256 $prev = '<span class="prev">&nbsp;</span>';
257 }
258 if (variable_get('event_start_max', 10000000000) > $eom) {
259 - $next = '<span class="next">'. l('&raquo;', 'event/'. ($month + 1 > 12 ? $year + 1 .'/1' : "$year/". ($month + 1)) . ($day ? "/$day" : '')) .'</span>';
260 + // $next = '<span class="next">'. l('&raquo;', 'event/'. ($month + 1 > 12 ? $year + 1 .'/1' : "$year/". ($month + 1)) . ($day ? "/$day" : '')) .'</span>';
261 + $next = '<span class="next">'. l('&raquo;', 'event/'. ($month + 1 > 12 ? $year + 1 .'/1' : "$year/". ($month + 1))) .'</span>';
262 }
263 else {
264 $next = '<span class="next">&nbsp;</span>';
265 @@ -875,7 +916,7 @@
266 foreach ($headerarray as $name => $column) {
267 $header[] = array('data' => $name, 'field' => $column);
268 }
269 - $sql = 'SELECT DISTINCT(n.nid), n.title, n.teaser, n.body, e.* FROM {node} n '. node_access_join_sql() .' INNER JOIN {event} e ON n.nid = e.nid WHERE '. node_access_where_sql() ." AND n.status = 1 AND e.start > $start AND e.start < $end GROUP BY e.start, n.title";
270 + $sql = 'SELECT n.nid, n.title, n.teaser, n.body, e.* FROM {node} n '. node_access_join_sql() .' INNER JOIN {event} e ON n.nid = e.nid WHERE '. node_access_where_sql() ." AND n.status = 1 AND e.start > $start AND e.start < $end";
271 $sql .= tablesort_sql($header);
272 $result = pager_query($sql, 10);
273 $rows = array();
274 @@ -986,7 +1027,7 @@
275 if ($def[0] == "select" && $def[10]) { // multi-select
276 foreach ($edit->$field as $value) {
277 if ($value) {
278 - $or[] = "e.$field LIKE '%". check_query($value). "%'";
279 + $or[] = "e.$field LIKE '%". check_query($value) ."%'";
280 }
281 }
282 }
283 @@ -999,7 +1040,9 @@
284 $query[] = '('. implode(' OR ', $or). ')';
285 }
286
287 - $sql = 'SELECT DISTINCT(n.nid) FROM {event} e INNER JOIN {node} n USING (nid) '. node_access_join_sql() .' WHERE '. node_access_where_sql() .' AND '. implode(' AND ', $query);
288 + $sql = 'SELECT DISTINCT(n.nid)
289 + FROM {event} e INNER JOIN {node} n USING (nid) '. node_access_join_sql() .'
290 + WHERE '. node_access_where_sql() .' AND '. implode(' AND ', $query);
291 return db_query($sql);
292 }
293
294 @@ -1026,7 +1069,7 @@
295 }
296
297 $output .= form_submit(t('Search'));
298 - return form($output, 'post', NULL, array ('id' => 'event-search'));
299 + return form($output, 'post', NULL, array('id' => 'event-search'));
300 }
301
302 /**
303 @@ -1058,7 +1101,11 @@
304 global $user;
305 // For two hours, we display "NOW"
306 $time = time()-(2*60*60);
307 - $result = db_query_range('SELECT DISTINCT(n.nid), n.title, n.status, n.moderate, e.* FROM {node} n '. node_access_join_sql() ." INNER JOIN {event} e ON n.nid = e.nid WHERE n.type='event' AND ". node_access_where_sql() ." AND n.status = 1 AND e.start >= $time ORDER BY e.start", 0, $limit);
308 + $result = db_query_range('SELECT DISTINCT(n.nid), n.title, n.status, n.moderate, e.*
309 + FROM {node} n '. node_access_join_sql() ."
310 + INNER JOIN {event} e ON n.nid = e.nid
311 + WHERE n.type='event' AND ". node_access_where_sql() ." AND n.status = 1 AND e.start >= $time
312 + ORDER BY e.start", 0, $limit);
313
314 while ($node = db_fetch_object($result)) {
315 $links[] = $node;
316 @@ -1103,9 +1150,9 @@
317 $timeleft = format_plural(floor($minutesleft/(24*60)), '1 day', '%count days');
318 }
319
320 - $items[] = l($node->title, "node/$node->nid", array("title" => $node->title)) . " ($timeleft)";
321 + $items[] = l($node->title, "node/$node->nid", array("title" => $node->title)) ." ($timeleft)";
322 }
323 - return theme("item_list", $items);
324 + return theme('item_list', $items);
325 }
326 }
327
328 @@ -1118,6 +1165,85 @@
329 }
330 return $aResult;
331 }
332 +}
333 +
334 +/**
335 + * This iCal file will only support the very minimum
336 + * of what is needed to publish simple events
337 + */
338 +function _event_ical() {
339 + header('Content-Type: text/calendar; charset=utf-8');
340 +
341 + $output = _event_iCalHeader(variable_get('site_name','') . ': ' . t('Upcoming events'));
342 + $output .= _event_iCalGetEvents();
343 + $output .= _event_iCalFooter();
344 +
345 + print $output;
346 + exit(0);
347 +}
348 +
349 +/**
350 + * Very minimal iCal header
351 + */
352 +function _event_iCalHeader($calname) {
353 + $output = "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nX-WR-CALNAME:$calname\r\n";
354 + $output .= "X-WR-TIMEZONE:Europe/Stockholm\r\nCALSCALE:GREGORIAN\r\n";
355 +
356 + return $output;
357 +}
358 +
359 +/**
360 + * Very minimal iCal event
361 + */
362 +function _event_iCalEvent($name, $starttime, $endtime, $venue='', $description='', $url='') {
363 + global $base_url;
364 + $host = preg_replace("|http://|","",$base_url);
365 + $endtime = ($starttime < $endtime ? $endtime : $starttime + 3600);
366 + $icalstart = event_format_date($starttime, 'custom', "Ymd") .'T'. event_format_date($starttime, 'custom', "His");
367 + $icalend = event_format_date($endtime, 'custom', "Ymd") .'T'. event_format_date($endtime, 'custom', "His");
368 +
369 + $output = "BEGIN:VEVENT\r\n"
370 + . ($venue != '' ? "LOCATION:$venue\r\n" : '')
371 + ."UID:". uniqid('') ."@$host\r\n"
372 + ."DTSTART;TZID=Europe/Stockholm:". $icalstart ."\r\n"
373 + ."DTEND;TZID=Europe/Stockholm:". $icalend ."\r\n"
374 + ."SUMMARY:$name\r\n"
375 + . ($description != '' ? "DESCRIPTION:$description\r\n" : '')
376 + . ($url != '' ? "URL;VALUE=URI:$url\r\n" : '')
377 + ."END:VEVENT\r\n";
378 +
379 + return $output;
380 +}
381 +
382 +/**
383 + * Very minimal iCal footer
384 + */
385 +function _event_iCalFooter($calname = "") {
386 + return "END:VCALENDAR\r\n";
387 +}
388 +
389 +/**
390 + * Get iCal events
391 + */
392 +function _event_iCalGetEvents() {
393 + global $base_url;
394 +
395 + $sql = "SELECT n.nid, n.title, e.location, e.start, e.end
396 + FROM {event} e,{node} n
397 + WHERE e.nid = n.nid";
398 + $res = db_query($sql);
399 +
400 + while ($temp = db_fetch_array($res)) {
401 + $events .= _event_iCalEvent(
402 + $temp['title'],
403 + $temp['start'],
404 + $temp['end'],
405 + $temp['location'],
406 + '',
407 + "{$base_url}/node/{$temp['nid']}"
408 + );
409 + }
410 + return $events;
411 }
412
413 ?>

  ViewVC Help
Powered by ViewVC 1.1.2