| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* The module file - sets up the MovieDB module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
|
| 10 |
//Some code adapted from moviereview module written by Emiliano <emiliano@webinteligente.com.br>
|
| 11 |
//
|
| 12 |
|
| 13 |
|
| 14 |
/**
|
| 15 |
* Include functions for the movie node
|
| 16 |
*
|
| 17 |
*/
|
| 18 |
include_once('mdb_movie.inc');
|
| 19 |
/**
|
| 20 |
* Include functions for the person node
|
| 21 |
*
|
| 22 |
*/
|
| 23 |
include_once('mdb_person.inc');
|
| 24 |
/**
|
| 25 |
* Include themeing functions
|
| 26 |
*
|
| 27 |
*/
|
| 28 |
include_once('mdb_theme.inc');
|
| 29 |
/**
|
| 30 |
* Include common functions
|
| 31 |
*
|
| 32 |
*/
|
| 33 |
include_once('mdb_common.inc');
|
| 34 |
|
| 35 |
|
| 36 |
/**
|
| 37 |
* Implementation of hook_help().
|
| 38 |
*
|
| 39 |
*/
|
| 40 |
function moviedb_help($section = '') {
|
| 41 |
|
| 42 |
$output = '';
|
| 43 |
switch ($section) {
|
| 44 |
case 'admin/help#moviedb':
|
| 45 |
$output .= t('Moviedb is a module to help you manage a movie database.');
|
| 46 |
case 'node/add#moviedb':
|
| 47 |
$output = t('Add a movie.');
|
| 48 |
break;
|
| 49 |
}
|
| 50 |
return $output;
|
| 51 |
}
|
| 52 |
|
| 53 |
|
| 54 |
/**
|
| 55 |
* Implementation of hook_node_info().
|
| 56 |
*/
|
| 57 |
function moviedb_node_info() {
|
| 58 |
return array(
|
| 59 |
'mdb_movie' => array('name' => t('Movie'), 'module' => 'mdb_movie'),
|
| 60 |
'mdb_person' => array('name' => t('Person'), 'module' => 'mdb_person'),
|
| 61 |
);
|
| 62 |
}
|
| 63 |
|
| 64 |
/**
|
| 65 |
* Implementation of hook_node_type().
|
| 66 |
*/
|
| 67 |
function moviedb_node_type($op, $info) {
|
| 68 |
if (!empty($info->old_type) && $info->old_type != $info->type) {
|
| 69 |
$update_count = node_type_update_nodes($info->old_type,
|
| 70 |
$info->type);
|
| 71 |
|
| 72 |
if ($update_count) {
|
| 73 |
$substr_pre = 'Changed the content type of ';
|
| 74 |
$substr_post = strtr(' from %old-type to %type.', array(
|
| 75 |
'%old-type' => theme('placeholder', $info->old_type),
|
| 76 |
'%type' => theme('placeholder', $info->type)));
|
| 77 |
drupal_set_message(format_plural($update_count, $substr_pre
|
| 78 |
.'@count post'. $substr_post, $substr_pre .'@count posts'.
|
| 79 |
$substr_post));
|
| 80 |
}
|
| 81 |
}
|
| 82 |
}
|
| 83 |
|
| 84 |
/**
|
| 85 |
* Implementation of hook_perm().
|
| 86 |
*/
|
| 87 |
function moviedb_perm() {
|
| 88 |
return array('create movies', 'edit own movies', 'view movies', 'edit people' );
|
| 89 |
}
|
| 90 |
|
| 91 |
/**
|
| 92 |
* Implementation of hook_menu().
|
| 93 |
*
|
| 94 |
*/
|
| 95 |
function moviedb_menu($may_cache) {
|
| 96 |
$items = array();
|
| 97 |
|
| 98 |
if ($may_cache) {
|
| 99 |
|
| 100 |
$items[] = array('path' => 'admin/settings/moviedb',
|
| 101 |
'title' => t('Movie Database'),
|
| 102 |
'description' => t('Set up the moviedb module'),
|
| 103 |
'callback' => 'drupal_get_form',
|
| 104 |
'callback arguments' => array('moviedb_admin_settings'),
|
| 105 |
'access' => user_access('administer site configuration'),
|
| 106 |
'type' => MENU_NORMAL_ITEM, );
|
| 107 |
|
| 108 |
$items[] = array('path' => 'moviedb/person/autocomplete',
|
| 109 |
'title' => t('Person autocomplete'),
|
| 110 |
'callback' => 'mdb_person_autocomplete',
|
| 111 |
'access' => user_access('view movies'),
|
| 112 |
'type' => MENU_CALLBACK,
|
| 113 |
);
|
| 114 |
}
|
| 115 |
else {
|
| 116 |
if ($css = variable_get('moviedb_css', drupal_get_path('module', 'moviedb') .'/moviedb.css')) {
|
| 117 |
//add stylesheet
|
| 118 |
drupal_add_css($css, 'all', TRUE);
|
| 119 |
}
|
| 120 |
}
|
| 121 |
return $items;
|
| 122 |
}
|
| 123 |
|
| 124 |
|
| 125 |
/**
|
| 126 |
* Settings Form
|
| 127 |
*
|
| 128 |
*/
|
| 129 |
function moviedb_admin_settings() {
|
| 130 |
if (!file_check_location(variable_get('moviedb_css', base_path() . drupal_get_path('module', 'moviedb') .'/moviedb.css'))) {
|
| 131 |
$error['moviedb_css'] = theme('error', t('File does not exist, or is not readable.'));
|
| 132 |
}
|
| 133 |
if (module_exists('taxonomy')) {
|
| 134 |
$vocs[0] = '<'. t('none') .'>';
|
| 135 |
foreach (taxonomy_get_vocabularies() as $vid => $voc) {
|
| 136 |
$vocs[$vid] = $voc->name;
|
| 137 |
}
|
| 138 |
}
|
| 139 |
|
| 140 |
$form['moviedb_settings'] = array(
|
| 141 |
'#type' => 'fieldset',
|
| 142 |
'#title' => t('moviedb settings'),
|
| 143 |
);
|
| 144 |
|
| 145 |
$form['moviedb_settings']['moviedb_css'] = array(
|
| 146 |
'#type' => 'textfield',
|
| 147 |
'#title' => t('Style sheet'),
|
| 148 |
'#default_value' => variable_get('moviedb_css', drupal_get_path('module', 'moviedb') .'/moviedb.css'),
|
| 149 |
'#size' => 70,
|
| 150 |
'#maxlength' => 255,
|
| 151 |
'#description' => t("Specify the relative path to your moviedb style sheet. The style sheet specified here will be used to style your moviedb pages. If you prefer to style your moviedb pages in your theme, you can leave this field blank") . $error['moviedb_css'],
|
| 152 |
);
|
| 153 |
if ($voc) {
|
| 154 |
$form['moviedb_settings']['moviedb_genre_vocab'] = array(
|
| 155 |
'#type' => 'select',
|
| 156 |
'#multiple' => FALSE,
|
| 157 |
'#title' => t('Select the vocabulary to use for movie genres.'),
|
| 158 |
'#default_value' => variable_get('moviedb_genre_vocab', 0),
|
| 159 |
'#options' => $vocs,
|
| 160 |
'#description' => t('Select the vocabulary you use to classify movie genres.'),
|
| 161 |
);
|
| 162 |
}
|
| 163 |
|
| 164 |
return system_settings_form($form);
|
| 165 |
}
|