| 1 |
<?php
|
| 2 |
// $Id: basicevent.module,v 1.6.2.1 2005/11/29 08:46:46 drewish Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* An extremly simple module to implement the event API.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_help().
|
| 11 |
*/
|
| 12 |
function basicevent_help($section) {
|
| 13 |
switch ($section) {
|
| 14 |
case 'admin/modules#description':
|
| 15 |
return t('A story-like node that implements the event API automatically. Depends on the event module (4.6 or later).');
|
| 16 |
case 'node/add#event':
|
| 17 |
return t('An event is a story which can be given a start and end date, thus appearing in the events calendar.');
|
| 18 |
}
|
| 19 |
}
|
| 20 |
|
| 21 |
/**
|
| 22 |
* Implementation of hook_node_name().
|
| 23 |
*/
|
| 24 |
function event_node_name($node) {
|
| 25 |
return t('event');
|
| 26 |
}
|
| 27 |
|
| 28 |
/**
|
| 29 |
* Implementation of hook_perm().
|
| 30 |
*/
|
| 31 |
function event_perm() {
|
| 32 |
return array('create events', 'edit own events');
|
| 33 |
}
|
| 34 |
|
| 35 |
/**
|
| 36 |
* Implementation of hook_access().
|
| 37 |
*/
|
| 38 |
function event_access($op, $node) {
|
| 39 |
global $user;
|
| 40 |
switch($op) {
|
| 41 |
case 'create':
|
| 42 |
return user_access('create events');
|
| 43 |
break;
|
| 44 |
case 'update':
|
| 45 |
case 'delete':
|
| 46 |
if (user_access('edit own events') && ($user->uid == $node->uid)) {
|
| 47 |
return TRUE;
|
| 48 |
}
|
| 49 |
break;
|
| 50 |
}
|
| 51 |
}
|
| 52 |
|
| 53 |
/**
|
| 54 |
* Implementation of hook_menu().
|
| 55 |
*/
|
| 56 |
function basicevent_menu($may_cache) {
|
| 57 |
$items = array();
|
| 58 |
|
| 59 |
if ($may_cache) {
|
| 60 |
$items[] = array('path' => 'node/add/event', 'title' => t('event'),
|
| 61 |
'access' => user_access('create events'));
|
| 62 |
}
|
| 63 |
|
| 64 |
return $items;
|
| 65 |
}
|
| 66 |
|
| 67 |
/**
|
| 68 |
* Implementation of hook_form().
|
| 69 |
*/
|
| 70 |
function event_form(&$node) {
|
| 71 |
$output = '';
|
| 72 |
|
| 73 |
if (function_exists('taxonomy_node_form')) {
|
| 74 |
$output .= implode('', taxonomy_node_form('event', $node));
|
| 75 |
}
|
| 76 |
|
| 77 |
//$output .= form_textfield(t('Location'), 'location', $node->location, 64, 255, t('Where this event is taking place.'));
|
| 78 |
$output .= form_textarea(t('Body'), 'body', $node->body, 60, 20, '', NULL, TRUE);
|
| 79 |
$output .= filter_form('format', $node->format);
|
| 80 |
|
| 81 |
return $output;
|
| 82 |
}
|
| 83 |
|
| 84 |
function basicevent_nodeapi(&$node, $op, $arg = 0) {
|
| 85 |
switch ($op) {
|
| 86 |
case 'load':
|
| 87 |
$object = db_fetch_object(db_query("SELECT location FROM {event} WHERE nid = %d", $node->nid));
|
| 88 |
return array('location' => $object->location);
|
| 89 |
break;
|
| 90 |
case 'view':
|
| 91 |
$node->body = theme('location_event', $node) . $node->body;
|
| 92 |
$node->teaser = theme('location_event', $node) . $node->teaser;
|
| 93 |
break;
|
| 94 |
}
|
| 95 |
}
|
| 96 |
|
| 97 |
function theme_location_event($node) {
|
| 98 |
return '<div class="event-nodeapi"><div class="event-location"><label>'. t('Location') .': </label>'. $node->location . '</div></div>';
|
| 99 |
}
|