| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* The person settings
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Implementation of hook_access().
|
| 10 |
*/
|
| 11 |
function mdb_person_access($op, $node) {
|
| 12 |
global $user;
|
| 13 |
|
| 14 |
if ($op == 'create') {
|
| 15 |
return user_access('create movies');
|
| 16 |
}
|
| 17 |
|
| 18 |
if ($op == 'update' || $op == 'delete') {
|
| 19 |
if (user_access('edit people')) {
|
| 20 |
return TRUE;
|
| 21 |
}
|
| 22 |
}
|
| 23 |
}
|
| 24 |
|
| 25 |
/**
|
| 26 |
* Implementation of hook_form().
|
| 27 |
*/
|
| 28 |
function mdb_person_form(&$node) {
|
| 29 |
$form['title'] = array('#type' => 'textfield', '#title' => t('Name'), '#required' => TRUE, '#default_value' => $node->title, '#weight' => -5);
|
| 30 |
$form['body_filter']['body'] = array('#type' => 'textarea', '#title' => t('Biography'), '#default_value' => $node->body, '#rows' => 6);
|
| 31 |
$form['body_filter']['format'] = filter_form($node->format);
|
| 32 |
return $form;
|
| 33 |
}
|
| 34 |
|
| 35 |
/**
|
| 36 |
* Implementation of hook_delete().
|
| 37 |
*
|
| 38 |
*/
|
| 39 |
function mdb_person_delete($node) {
|
| 40 |
db_query("DELETE FROM {moviedb_actors} WHERE pid = %d", $node->nid);
|
| 41 |
db_query("DELETE FROM {moviedb_directors} WHERE pid = %d", $node->nid);
|
| 42 |
db_query("DELETE FROM {moviedb_writers} WHERE pid = %d", $node->nid);
|
| 43 |
|
| 44 |
}
|
| 45 |
|
| 46 |
|
| 47 |
/**
|
| 48 |
* Implementation of hook_load().
|
| 49 |
*
|
| 50 |
*/
|
| 51 |
function mdb_person_load($node) {
|
| 52 |
|
| 53 |
//Get the person's filmography
|
| 54 |
|
| 55 |
if ($actor = moviedb_person_movies($node->nid, 'actor')) {
|
| 56 |
$movies->actor = $actor;
|
| 57 |
}
|
| 58 |
|
| 59 |
|
| 60 |
if ($director = moviedb_person_movies($node->nid, 'director')) {
|
| 61 |
$movies->director = $director;
|
| 62 |
}
|
| 63 |
|
| 64 |
if ($writer = moviedb_person_movies($node->nid, 'writer')) {
|
| 65 |
$movies->writer = $writer;
|
| 66 |
}
|
| 67 |
|
| 68 |
if ($producer = moviedb_person_movies($node->nid, 'producer')) {
|
| 69 |
$movies->producer = $producer;
|
| 70 |
}
|
| 71 |
|
| 72 |
return $movies;
|
| 73 |
|
| 74 |
}
|
| 75 |
|
| 76 |
/**
|
| 77 |
* Implementation of hook_view().
|
| 78 |
*
|
| 79 |
*/
|
| 80 |
function mdb_person_view(&$node, $teaser = FALSE, $page = TRUE) {
|
| 81 |
|
| 82 |
$node = node_prepare($node, $teaser);
|
| 83 |
$node->content['data'] = array(
|
| 84 |
'#value' => theme('mdb_person', $node),
|
| 85 |
'#weight' => 0, );
|
| 86 |
$node->content['body']['#value'] = '';
|
| 87 |
|
| 88 |
return $node;
|
| 89 |
}
|
| 90 |
|
| 91 |
function mdb_person_autocomplete($string) {
|
| 92 |
|
| 93 |
// The user enters a comma-separated list of tags. We only autocomplete the last tag.
|
| 94 |
// This regexp allows the following types of user input:
|
| 95 |
// this, "somecmpany, llc", "and ""this"" w,o.rks", foo bar
|
| 96 |
$regexp = '%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
|
| 97 |
preg_match_all($regexp, $string, $matches);
|
| 98 |
$array = $matches[1];
|
| 99 |
|
| 100 |
// Fetch last tag
|
| 101 |
$last_string = trim(array_pop($array));
|
| 102 |
if ($last_string != '') {
|
| 103 |
$result = db_query_range(db_rewrite_sql("SELECT title FROM {node} WHERE LOWER(title) LIKE LOWER('%s%%')"), $last_string, 0, 10);
|
| 104 |
|
| 105 |
$prefix = count($array) ? implode(', ', $array) .', ' : '';
|
| 106 |
|
| 107 |
$matches = array();
|
| 108 |
while ($person = db_fetch_object($result)) {
|
| 109 |
$n = $person->title;
|
| 110 |
// Commas and quotes in terms are special cases, so encode 'em.
|
| 111 |
if (preg_match('/,/', $person->title) || preg_match('/"/', $person->title)) {
|
| 112 |
$n = '"'. preg_replace('/"/', '""', $person->title) .'"';
|
| 113 |
}
|
| 114 |
$matches[$prefix . $n] = check_plain($person->title);
|
| 115 |
}
|
| 116 |
print drupal_to_js($matches);
|
| 117 |
exit();
|
| 118 |
}
|
| 119 |
}
|