function event_nodeapi in Event 5
Same name and namespace in other branches
- 5.2 event.module \event_nodeapi()
hook_nodeapi implementation
Related topics
File
- ./
event.module, line 1979
Code
function event_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
// make sure it's an event enabled node
if (variable_get('event_nodeapi_' . $node->type, 'never') != 'never') {
switch ($op) {
case 'validate':
// no break. both need a node with a formatted date and event_start
// and event_end set, 'validate' for the previewing and 'submit' for
// update/insert.
case 'submit':
event_validate_form_date($node, 'start');
event_validate_form_date($node, 'end');
if ($node->event_end < $node->event_start) {
$node->event_end = $node->event_start;
}
switch (variable_get('event_timezone_display', 'event')) {
case 'event':
$node->start_offset = event_get_offset($node->timezone, $node->event_start);
$node->end_offset = event_get_offset($node->timezone, $node->event_end);
break;
case 'user':
global $user;
$node->start_offset = $node->end_offset = $user->timezone;
break;
case 'site':
$node->start_offset = $node->end_offset = variable_get('date_default_timezone', 0);
break;
}
$node->start_format = format_date($node->event_start, 'small', '', $node->start_offset);
$node->end_format = format_date($node->event_end, 'small', '', $node->end_offset);
break;
case 'insert':
db_query('INSERT INTO {event} (nid, event_start, event_end, timezone) VALUES (%d, %d, %d, %d)', $node->nid, $node->event_start, $node->event_end, $node->timezone);
event_set_range();
break;
case 'update':
// While the DELETE/INSERT is less efficient than single UPDATE, the
// UPDATE only works if there's an existing record in the events
// table. I.e. if you create a node and then enable the event module,
// there will be no record in the event table, so the dates cannot be
// changed.
db_query('DELETE FROM {event} WHERE nid = %d', $node->nid);
db_query('INSERT INTO {event} (nid, event_start, event_end, timezone) VALUES (%d, %d, %d, %d)', $node->nid, $node->event_start, $node->event_end, $node->timezone);
event_set_range();
break;
case 'delete':
db_query('DELETE FROM {event} WHERE nid = %d', $node->nid);
event_set_range();
break;
case 'load':
$object = db_fetch_object(db_query('SELECT event_start, event_end, timezone FROM {event} WHERE nid = %d', $node->nid));
switch (variable_get('event_timezone_display', 'event')) {
case 'event':
include_once EVENT_PATH . '/event_timezones.inc';
$start_offset = event_get_offset($object->timezone, $object->event_start);
$end_offset = event_get_offset($object->timezone, $object->event_end);
break;
case 'user':
global $user;
$start_offset = $end_offset = $user->timezone;
break;
case 'site':
$start_offset = $end_offset = variable_get('date_default_timezone', 0);
break;
}
$ctype = module_invoke('flexinode', 'load_content_type', $node->ctype_id);
return array(
'event_start' => $object->event_start,
'event_end' => $object->event_end,
'timezone' => $object->timezone,
'start_offset' => $start_offset,
'start_format' => format_date($object->event_start, 'small', '', $start_offset),
'start_time_format' => format_date($object->event_start, 'custom', variable_get('event_ampm', '0') ? 'g:i a' : 'H:i', $start_offset),
'end_offset' => $end_offset,
'end_format' => format_date($object->event_end, 'small', '', $end_offset),
'end_time_format' => format_date($object->event_end, 'custom', variable_get('event_ampm', '0') ? 'g:i a' : 'H:i', $end_offset),
'event_node_title' => $ctype->name ? $ctype->name : $node->type,
);
break;
case 'ical item':
break;
case 'view':
$node->content['event'] = array(
'#value' => theme('event_nodeapi', $node),
'#weight' => -10,
);
break;
case 'rss item':
$node->body = theme('event_nodeapi', $node) . $node->body;
$node->teaser = theme('event_nodeapi', $node) . $node->teaser;
break;
}
}
}