| 1 |
<?php |
<?php |
| 2 |
// $Id: biblio.inc,v 1.4 2007/10/07 19:09:51 agentken Exp $ |
// $Id: biblio.inc,v 1.5 2008/01/05 20:47:55 agentken Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 6 |
* Handles bibliographies created by the Biblio module |
* Handles bibliographies created by the Biblio module |
| 7 |
*/ |
* |
|
|
|
|
/** |
|
| 8 |
* INSTALLATION |
* INSTALLATION |
| 9 |
* |
* |
| 10 |
* Requires: biblio.module |
* Requires: biblio.module |
| 12 |
* Settings: No |
* Settings: No |
| 13 |
* |
* |
| 14 |
* Author: csc4 |
* Author: csc4 |
| 15 |
|
* |
| 16 |
|
* @ingroup mysite_plugins |
| 17 |
*/ |
*/ |
| 18 |
|
|
| 19 |
/** |
/** |
| 20 |
* Implements mysite_type_hook(). |
* Implements mysite_type_hook(). |
| 21 |
* |
* |
| 22 |
* Biblio module must be enabled for this plugin to register. |
* Biblio module must be enabled for this plugin to register. |
|
* |
|
| 23 |
*/ |
*/ |
| 24 |
function mysite_type_biblio($get_options = TRUE) { |
function mysite_type_biblio($get_options = TRUE) { |
| 25 |
if (module_exists('biblio')) { |
if (module_exists('biblio')) { |
| 26 |
$type = array( |
$type = array( |
| 27 |
'name' => t('Bibliographies'), |
'name' => t('Bibliographies'), |
| 28 |
'description' => t('<b>Bibliographies</b>: All bibliographies from a specific user'), |
'description' => t('<b>Bibliographies</b>: All bibliographies from a specific user'), |
| 29 |
'include' => 'biblio', |
'include' => 'biblio', |
| 30 |
'prefix' => t(''), |
'prefix' => t(''), |
| 31 |
'suffix' => t('bibliographies'), |
'suffix' => t('bibliographies'), |
| 32 |
'category' => t('Content'), |
'category' => t('Content'), |
| 37 |
'search' => TRUE |
'search' => TRUE |
| 38 |
); |
); |
| 39 |
$basic_settings = variable_get('mysite_basic_bilbio_settings', array()); |
$basic_settings = variable_get('mysite_basic_bilbio_settings', array()); |
| 40 |
$type = array_merge($type, $basic_settings); |
$type = array_merge($type, $basic_settings); |
| 41 |
if ($get_options) { |
if ($get_options) { |
| 42 |
$type['options'] = mysite_type_biblio_options(); |
$type['options'] = mysite_type_biblio_options(); |
| 43 |
} |
} |
| 53 |
// there must be active and allowed bibliographies |
// there must be active and allowed bibliographies |
| 54 |
$value = TRUE; |
$value = TRUE; |
| 55 |
$message = ''; |
$message = ''; |
| 56 |
$br = ''; |
$br = ''; |
| 57 |
// some users must be allowed to creation bibliographies, otherwise, give a configuration message |
// some users must be allowed to creation bibliographies, otherwise, give a configuration message |
| 58 |
$result = db_query("SELECT perm FROM {permission}"); |
$result = db_query("SELECT perm FROM {permission}"); |
| 59 |
$check = ''; |
$check = ''; |
| 83 |
$sql = "SELECT DISTINCT(u.uid), u.name, n.nid FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status = 1 AND n.type = 'biblio' ORDER BY n.nid DESC"; |
$sql = "SELECT DISTINCT(u.uid), u.name, n.nid FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status = 1 AND n.type = 'biblio' ORDER BY n.nid DESC"; |
| 84 |
$result = db_query($sql); |
$result = db_query($sql); |
| 85 |
$biblios = array(); |
$biblios = array(); |
| 86 |
while($item = db_fetch_object($result)) { |
while ($item = db_fetch_object($result)) { |
| 87 |
$biblios[] =$item; |
$biblios[] =$item; |
| 88 |
} |
} |
| 89 |
foreach ($biblios as $key => $value) { |
foreach ($biblios as $key => $value) { |
| 90 |
$options['name'][] = mysite_type_biblio_title($value->uid, $value->name); |
$options['name'][] = mysite_type_biblio_title($value->uid, $value->name); |
| 91 |
$options['type_id'][] = $value->uid; |
$options['type_id'][] = $value->uid; |
| 92 |
$options['type'][] = 'biblio'; |
$options['type'][] = 'biblio'; |
| 93 |
$options['icon'][] = mysite_get_icon('biblio', $term->tid); |
$options['icon'][] = mysite_get_icon('biblio', $term->tid); |
| 94 |
} |
} |
| 95 |
return $options; |
return $options; |
| 96 |
} |
} |
| 97 |
|
|
| 98 |
/** |
/** |
| 99 |
* Implements mysite_type_hook_title(). |
* Implements mysite_type_hook_title(). |
| 100 |
*/ |
*/ |
| 101 |
function mysite_type_biblio_title($type_id = NULL, $title = NULL) { |
function mysite_type_biblio_title($type_id = NULL, $title = NULL) { |
| 102 |
if(!empty($type_id)) { |
if (!empty($type_id)) { |
| 103 |
if (is_null($title)) { |
if (is_null($title)) { |
| 104 |
$biblio = user_load(array('uid' => $type_id)); |
$biblio = user_load(array('uid' => $type_id)); |
| 105 |
$title = $biblio->name; |
$title = $biblio->name; |
| 106 |
} |
} |
| 107 |
$type = mysite_type_biblio(FALSE); |
$type = mysite_type_biblio(FALSE); |
| 108 |
$title = $type['prefix'] .' '. $title . t("'s") .' '. $type['suffix']; |
$title = $type['prefix'] .' '. $title . t("'s") .' '. $type['suffix']; |
| 109 |
$title = trim(rtrim($title)); |
$title = trim(rtrim($title)); |
| 114 |
} |
} |
| 115 |
|
|
| 116 |
/** |
/** |
| 117 |
* Implements mysite_type_hook_data(). |
* Implements mysite_type_hook_data(). |
| 118 |
*/ |
*/ |
| 119 |
function mysite_type_biblio_data($type_id = NULL) { |
function mysite_type_biblio_data($type_id = NULL) { |
| 120 |
if(!empty($type_id)) { |
if (!empty($type_id)) { |
| 121 |
$sql = "SELECT nid, created FROM {node} WHERE type = 'biblio' AND status = 1 AND uid = %d ORDER BY created DESC"; |
$sql = "SELECT nid, created FROM {node} WHERE type = 'biblio' AND status = 1 AND uid = %d ORDER BY created DESC"; |
| 122 |
$result = db_query($sql, $type_id); |
$result = db_query($sql, $type_id); |
| 123 |
$data = array( |
$data = array( |
| 126 |
); |
); |
| 127 |
$items = array(); |
$items = array(); |
| 128 |
$i = 0; |
$i = 0; |
| 129 |
$type = mysite_type_bilbio(FALSE); |
$type = mysite_type_bilbio(FALSE); |
| 130 |
while ($nid = db_fetch_object($result)) { |
while ($nid = db_fetch_object($result)) { |
| 131 |
$node = node_load(array('nid' => $nid->nid)); |
$node = node_load(array('nid' => $nid->nid)); |
| 132 |
$items[$i]['type'] = $node->type; |
$items[$i]['type'] = $node->type; |
| 133 |
$items[$i]['link'] = l($node->title, 'node/'. $nid->nid, array('target' => $type['link_target'])); |
$items[$i]['link'] = l($node->title, 'node/'. $nid->nid, array('target' => $type['link_target'])); |
| 134 |
$items[$i]['title'] = check_plain($node->title); |
$items[$i]['title'] = check_plain($node->title); |
| 135 |
$items[$i]['subtitle'] = NULL; |
$items[$i]['subtitle'] = NULL; |
| 136 |
$items[$i]['date'] = $node->changed; |
$items[$i]['date'] = $node->changed; |
| 137 |
$items[$i]['uid'] = $node->uid; |
$items[$i]['uid'] = $node->uid; |
| 138 |
$items[$i]['author'] = check_plain($node->name); |
$items[$i]['author'] = check_plain($node->name); |
| 139 |
$items[$i]['teaser'] = mysite_teaser($node); |
$items[$i]['teaser'] = mysite_teaser($node); |
| 140 |
$items[$i]['nid'] = $node->nid; |
$items[$i]['nid'] = $node->nid; |
| 141 |
$i++; |
$i++; |
| 142 |
} |
} |
| 144 |
return $data; |
return $data; |
| 145 |
} |
} |
| 146 |
drupal_set_message(t('Could not find data'), 'error'); |
drupal_set_message(t('Could not find data'), 'error'); |
| 147 |
return; |
return; |
| 148 |
|
|
| 149 |
} |
} |
| 150 |
|
|
| 151 |
/** |
/** |
| 152 |
* Implements mysite_type_hook_block(). |
* Implements mysite_type_hook_block(). |
| 153 |
*/ |
*/ |
| 154 |
function mysite_type_biblio_block($arg, $op = 'view') { |
function mysite_type_biblio_block($arg, $op = 'view') { |
| 155 |
global $user; |
global $user; |
| 162 |
$data['type_id'] = $biblio->uid; |
$data['type_id'] = $biblio->uid; |
| 163 |
$content = mysite_block_handler($data); |
$content = mysite_block_handler($data); |
| 164 |
return $content; |
return $content; |
| 165 |
} |
} |
| 166 |
} |
} |
| 167 |
} |
} |
| 168 |
|
|
| 169 |
/** |
/** |
| 170 |
* Implements mysite_type_hook_search(). |
* Implements mysite_type_hook_search(). |
|
* |
|
|
* @ingroup forms |
|
| 171 |
*/ |
*/ |
| 172 |
function mysite_type_biblio_search($uid = NULL) { |
function mysite_type_biblio_search($uid = NULL) { |
| 173 |
if (!is_null($uid)) { |
if (!is_null($uid)) { |
| 178 |
|
|
| 179 |
/** |
/** |
| 180 |
* FormsAPI for mysite_type_biblio_search() |
* FormsAPI for mysite_type_biblio_search() |
|
* |
|
|
* @ingroup forms |
|
| 181 |
*/ |
*/ |
| 182 |
function mysite_type_biblio_search_form($uid) { |
function mysite_type_biblio_search_form($uid) { |
| 183 |
$form['add_biblio']['biblio_title'] = array('#type' => 'textfield', |
$form['add_biblio']['biblio_title'] = array('#type' => 'textfield', |
| 186 |
'#description' => t('The user name of the author of the bibliography you wish to add.'), |
'#description' => t('The user name of the author of the bibliography you wish to add.'), |
| 187 |
'#required' => TRUE, |
'#required' => TRUE, |
| 188 |
'#autocomplete_path' => 'autocomplete/mysite/biblio' |
'#autocomplete_path' => 'autocomplete/mysite/biblio' |
| 189 |
); |
); |
| 190 |
$form['add_biblio']['uid'] = array('#type' => 'hidden', '#value' => $uid); |
$form['add_biblio']['uid'] = array('#type' => 'hidden', '#value' => $uid); |
| 191 |
$form['add_biblio']['type'] = array('#type' => 'hidden', '#value' => 'biblio'); |
$form['add_biblio']['type'] = array('#type' => 'hidden', '#value' => 'biblio'); |
| 192 |
$form['add_biblio']['submit'] = array('#type' => 'submit', '#value' =>t('Add biblio')); |
$form['add_biblio']['submit'] = array('#type' => 'submit', '#value' => t('Add biblio')); |
| 193 |
return $form; |
return $form; |
| 194 |
} |
} |
| 195 |
|
|
| 196 |
/** |
/** |
| 197 |
* Implements mysite_type_hook_search_form_submit(). |
* Implements mysite_type_hook_search_form_submit(). |
| 198 |
* |
*/ |
|
* @ingroup forms |
|
|
*/ |
|
| 199 |
function mysite_type_biblio_search_submit($form_id, $form_values) { |
function mysite_type_biblio_search_submit($form_id, $form_values) { |
| 200 |
// we use LIKE here in case JavaScript autocomplete support doesn't work. |
// we use LIKE here in case JavaScript autocomplete support doesn't work. |
| 201 |
// or in case the user doesn't autocomplete the form |
// or in case the user doesn't autocomplete the form |
| 206 |
$data[$count]['type'] = $form_values['type']; |
$data[$count]['type'] = $form_values['type']; |
| 207 |
$data[$count]['type_id'] = $biblio->uid; |
$data[$count]['type_id'] = $biblio->uid; |
| 208 |
$data[$count]['title'] = mysite_type_biblio_title($biblio->uid, $biblio->name); |
$data[$count]['title'] = mysite_type_biblio_title($biblio->uid, $biblio->name); |
| 209 |
$data[$count]['description'] = t('The bibliographies of %user', array('%user' => $biblio->name)); |
$data[$count]['description'] = t('The bibliographies of %user', array('%user' => $biblio->name)); |
| 210 |
$count++; |
$count++; |
| 211 |
} |
} |
| 212 |
// pass the $data to the universal handler |
// pass the $data to the universal handler |
| 215 |
} |
} |
| 216 |
|
|
| 217 |
/** |
/** |
| 218 |
* Implements mysite_type_hook_autocomplete(). |
* Implements mysite_type_hook_autocomplete(). |
|
* |
|
|
* @ingroup forms |
|
| 219 |
*/ |
*/ |
| 220 |
function mysite_type_biblio_autocomplete($string) { |
function mysite_type_biblio_autocomplete($string) { |
| 221 |
$matches = array(); |
$matches = array(); |
| 225 |
} |
} |
| 226 |
return $matches; |
return $matches; |
| 227 |
} |
} |
| 228 |
|
|
| 229 |
/** |
/** |
| 230 |
* Implements mysite_type_hook_clear(). |
* Implements mysite_type_hook_clear(). |
| 231 |
*/ |
*/ |
| 232 |
function mysite_type_biblio_clear($type) { |
function mysite_type_biblio_clear($type) { |
| 233 |
// fetch all the active records of this type and see if they really exist in the proper table |
// fetch all the active records of this type and see if they really exist in the proper table |
| 234 |
$sql = "SELECT mid, uid, type_id, title FROM {mysite_data} WHERE type = '%s'"; |
$sql = "SELECT mid, uid, type_id, title FROM {mysite_data} WHERE type = '%s'"; |
| 237 |
while ($item = db_fetch_array($result)) { |
while ($item = db_fetch_array($result)) { |
| 238 |
$sql = "SELECT DISTINCT(u.uid) FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status = 1 AND n.type = 'biblio' AND u.uid = %d"; |
$sql = "SELECT DISTINCT(u.uid) FROM {users} u INNER JOIN {node} n ON u.uid = n.uid WHERE n.status = 1 AND n.type = 'biblio' AND u.uid = %d"; |
| 239 |
$check = db_fetch_object(db_query($sql, $item['type_id'], $implode)); |
$check = db_fetch_object(db_query($sql, $item['type_id'], $implode)); |
| 240 |
if(empty($check->uid)) { |
if (empty($check->uid)) { |
| 241 |
$data[$item['mid']] = $item; |
$data[$item['mid']] = $item; |
| 242 |
} |
} |
| 243 |
} |
} |
| 244 |
return $data; |
return $data; |
| 245 |
} |
} |