function event_nodeapi in Event 5.2
Same name and namespace in other branches
- 5 event.module \event_nodeapi()
hook_nodeapi implementation
Related topics
File
- ./
event.module, line 2175
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 'load':
global $user;
event_include_files();
$object = event_get_event_load($node->nid);
return array(
'event' => array(
'start' => $object->event_start,
'end' => $object->event_end,
'start_orig' => $object->event_start,
'end_orig' => $object->event_end,
'timezone' => $object->timezone,
'offset' => $object->offset,
'offset_dst' => $object->offset_dst,
'dst_region' => $object->dst_region,
'has_time' => $object->has_time,
'has_end_date' => $object->has_end_date,
'start_utc' => $object->event_start_utc,
'start_user' => $object->event_start_user,
'start_site' => $object->event_start_site,
'end_utc' => $object->event_end_utc,
'end_user' => $object->event_end_user,
'end_site' => $object->event_end_site,
'node_type' => $node->type,
),
);
break;
case 'view':
if (isset($node->in_preview) && $node->in_preview) {
global $user;
event_nodeapi($node, 'submit');
$node->event['start'] = $node->event_start;
$node->event['end'] = $node->event_end;
$node->event['start_exploded'] = event_explode_date($node->event_start);
$node->event['end_exploded'] = event_explode_date($node->event_end);
$node->event['start_user'] = event_date_later($node->event['start_exploded'], $user->timezone, 'seconds');
$node->event['end_user'] = event_date_later($node->event['end_exploded'], $user->timezone, 'seconds');
$node->event['start_site'] = event_date_later($node->event['start_exploded'], variable_get('date_default_timezone', 0), 'seconds');
$node->event['end_site'] = event_date_later($node->event['end_exploded'], variable_get('date_default_timezone', 0), 'seconds');
$node->event['timezone'] = $node->timezone;
}
switch (variable_get('event_timezone_display', 'event')) {
case 'site':
if (variable_get('date_default_timezone_id', 0) != $node->timezone) {
$node->event['start'] = $node->event['start_site'];
$node->event['end'] = $node->event['end_site'];
break;
}
// no break
case 'event':
break;
case 'user':
$node->event['start'] = $node->event['start_user'];
$node->event['end'] = $node->event['end_user'];
break;
}
$node->event['start_exploded'] = event_explode_date($node->event['start']);
$node->event['end_exploded'] = event_explode_date($node->event['end']);
$node->event['start_format'] = event_format_date($node->event['start_exploded'], 'small');
$node->event['start_time_format'] = event_format_date($node->event['start_exploded'], 'custom', variable_get('event_ampm', '0') ? 'g:i a' : 'H:i');
$node->event['end_format'] = event_format_date($node->event['end_exploded'], 'small');
$node->event['end_time_format'] = event_format_date($node->event['end_exploded'], 'custom', variable_get('event_ampm', '0') ? 'g:i a' : 'H:i');
$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;
case 'submit':
// $node->event_start is set for jscalendar and eventrepeat module
if (!isset($node->event_start)) {
if (variable_get('event_ampm', '0')) {
if ($node->start_ampm == 'pm' && $node->start_hour < 12) {
$node->start_hour += 12;
}
if ($node->end_ampm == 'pm' && $node->end_hour < 12) {
$node->end_hour += 12;
}
}
$node->event_start = $node->start_year . '-' . $node->start_month . '-' . $node->start_day . ' ' . str_pad($node->start_hour, 2, '0', STR_PAD_LEFT) . ':' . str_pad($node->start_minute, 2, '0', STR_PAD_LEFT) . ':00';
$node->event_end = $node->end_year . '-' . $node->end_month . '-' . $node->end_day . ' ' . str_pad($node->end_hour, 2, '0', STR_PAD_LEFT) . ':' . str_pad($node->end_minute, 2, '0', STR_PAD_LEFT) . ':00';
}
$node->start_in_dst = event_is_dst($node->timezone, $node->event_start);
$node->end_in_dst = event_is_dst($node->timezone, $node->event_end);
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);
// no break
case 'insert':
db_query("INSERT INTO {event} (nid, event_start, event_end, timezone, start_in_dst, end_in_dst, has_time, has_end_date) VALUES (%d, '%s', '%s', %d, %d, %d, %d, %d)", $node->nid, $node->event_start, $node->event_end, $node->timezone, $node->start_in_dst, $node->end_in_dst, $node->has_time, $node->has_end_date);
event_set_range();
break;
case 'delete':
db_query('DELETE FROM {event} WHERE nid = %d', $node->nid);
event_set_range();
break;
}
}
}