/[drupal]/contributions/modules/biblio/biblio.module
ViewVC logotype

Contents of /contributions/modules/biblio/biblio.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.196 - (show annotations) (download) (as text)
Fri Oct 23 20:19:37 2009 UTC (4 weeks, 5 days ago) by rjerome
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-7--1
Changes since 1.195: +4 -4 lines
File MIME type: text/x-php
merged changes from DRUPAL-6--1 branch
1 <?php
2 // $Id: biblio.module,v 1.195 2009/10/01 01:45:42 rjerome Exp $
3 /**
4 * biblio.module for Drupal
5 *
6 * Copyright (C) 2006-2008 Ron Jerome
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 *
22 */
23
24 function _biblio_get_auth_types($auth_category, $biblio_type) {
25 static $auth_types = array();
26 if (empty($auth_types)) {
27 $db_res = db_query("SELECT * FROM {biblio_contributor_type");
28 while ($row = db_fetch_object($db_res)) {
29 $auth_types[$row->auth_category][$row->biblio_type][] = $row->auth_type;
30 }
31 }
32 $result = $auth_types[$auth_category][$biblio_type];
33 // fall back to defaults, if no author types are defined for this biblio_type
34 if (empty($result)) $result = $auth_types[$auth_category][0];
35 return $result;
36 }
37 function _biblio_get_auth_type($auth_category, $biblio_type) {
38 $result = (array)_biblio_get_auth_types($auth_category, $biblio_type);
39 // return first element of the array
40 return empty($result) ? NULL : current($result);
41 }
42 function _biblio_get_field_information($biblio_type, $only_visible = FALSE) {
43 $fields = array();
44 $visible = $only_visible ? ' AND (bt.common = 1 OR bt.visible=1) ' : '';
45 $result = db_query("SELECT b.*, btd.*, btt.name AS type_name
46 FROM {biblio_fields} AS b
47 INNER JOIN {biblio_field_type} AS bt ON bt.fid = b.fid
48 INNER JOIN {biblio_field_type_data} AS btd ON btd.ftdid = bt.ftdid
49 INNER JOIN {biblio_types} as btt ON btt.tid = bt.tid
50 WHERE bt.tid = %d $visible
51 ORDER BY bt.weight ASC", $biblio_type);
52 while ($row = db_fetch_array($result)) {
53 $fields[$row['fid']] = $row;
54 }
55
56 return $fields;
57 }
58
59 function biblio_init() {
60 global $user, $conf;
61 drupal_add_css(drupal_get_path('module', 'biblio') .'/biblio.css');
62
63 if ($user->uid === 0) { // Prevent caching of biblio pages for anonymous users so session variables work and thus filering works
64 $base = variable_get('biblio_base', 'biblio');
65 if (drupal_match_path($_GET['q'], "$base\n$base/*"))
66 $conf['cache'] = FALSE;
67 }
68 }
69 function biblio_theme() {
70 $path = drupal_get_path('module', 'biblio');
71 return array(
72 // 'views_view_unformatted__biblio_year' => array(
73 // 'template' => 'views-view-unformatted--biblio-year',
74 // 'path' => $path,
75 // ),
76 'biblio_alpha_line' => array(
77 'file' => 'biblio_theme.inc',
78 'arguments' => array('type'),
79 ),
80 'biblio_admin_author_types_form' => array(
81 'file' => 'biblio.admin.inc',
82 'arguments' => array('form'),
83 ),
84 'biblio_admin_type_mapper_form' => array(
85 'file' => 'biblio.admin.inc',
86 'arguments' => array('form'),
87 ) ,
88 'biblio_admin_types_edit_form' => array(
89 'file' => 'biblio_theme.inc',
90 'arguments' => array('form'),
91 ),
92 'biblio_admin_types_form' => array(
93 'file' => 'biblio_theme.inc',
94 'arguments' => array('form')
95 ),
96 'biblio_admin_author_edit_form' => array(
97 'file' => 'biblio_theme.inc',
98 'arguments' => array('form'),
99 ),
100 'biblio_admin_orphans_form' => array(
101 'file' => 'biblio_theme.inc',
102 'arguments' => array('form'),
103 ),
104 'biblio_admin_keyword_orphans_form' => array(
105 'file' => 'biblio_theme.inc',
106 'arguments' => array('form'),
107 ),
108 'biblio_coin_button' => array(
109 'file' => 'biblio_theme.inc',
110 'arguments' => array('element'),
111 ),
112 'biblio_openurl' => array(
113 'file' => 'biblio_theme.inc',
114 'arguments' => array('openURL'),
115 ),
116 'biblio_style' => array(
117 'file' => 'biblio_theme.inc',
118 'arguments' => array(
119 'node',
120 'base' => 'biblio',
121 'style_name' => 'classic',
122 'inline' => FALSE),
123 ),
124 'biblio_long' => array(
125 'file' => 'biblio_theme.inc',
126 'arguments' => array(
127 'node',
128 'base' => 'biblio',
129 'style_name' => 'classic'),
130 ),
131 'biblio_tabular' => array(
132 'file' => 'biblio_theme.inc',
133 'arguments' => array(
134 'node',
135 'base' => 'biblio',
136 'teaser' => FALSE),
137 ),
138 'biblio_entry' => array(
139 'file' => 'biblio_theme.inc',
140 'arguments' => array(
141 'node',
142 'base' => 'biblio',
143 'style_name' => 'classic',
144 'inline' => FALSE),
145 ),
146 'biblio_authors' => array(
147 'file' => 'biblio_theme.inc',
148 'arguments' => array(
149 'contributors',
150 'style' => 'classic',
151 'inline' => FALSE,
152 'glue' => ', '),
153 ),
154 'biblio_format_authors' => array(
155 'file' => 'biblio_theme.inc',
156 'arguments' => array(
157 'contributors',
158 'options' => array(),
159 'inline' => FALSE,),
160 ),
161 'biblio_author_link' => array(
162 'file' => 'biblio_theme.inc',
163 'arguments' => array(
164 'author',
165 'authorID',
166 'base' => 'biblio',
167 'inline' => FALSE),
168 ),
169 'biblio_filters' => array(
170 'file' => 'biblio_theme.inc',
171 'arguments' => array('form'),
172 ),
173 'form_filter' => array(
174 'file' => 'biblio_theme.inc',
175 'arguments' => array('form'),
176 ),
177 'biblio_export_links' => array(
178 'file' => 'biblio_theme.inc',
179 'arguments' => array('node'),
180 ),
181 'biblio_download_links' => array(
182 'file' => 'biblio_theme.inc',
183 'arguments' => array('node'),
184 ),
185 'biblio_contributors' => array(
186 'file' => 'biblio_theme.inc',
187 'arguments' => array('form'),
188 ),
189 );
190 }
191 function biblio_autocomplete($field, $string = '') {
192 $matches = array();
193 if ($field == 'contributor') {
194 $result = db_query_range("SELECT * FROM {biblio_contributor_data} WHERE LOWER(lastname) LIKE LOWER('%s%%') OR LOWER(firstname) LIKE LOWER('%s%%') ORDER BY lastname ASC ", array($string, $string), 0, 10);
195 while ($data = db_fetch_object($result)) {
196 $matches[$data->name] = check_plain($data->name);
197 }
198 }elseif ($field == 'biblio_keywords') {
199 $sep = variable_get('biblio_keyword_sep', ',');
200 $sep_pos = strrpos($string, $sep); //find the last separator
201 $start = trim(drupal_substr($string, 0, $sep_pos)); // first part of the string upto the last separator
202 $end_sep = ($sep_pos) ? $sep_pos + 1 :$sep_pos;
203 $end = trim(drupal_substr($string, $end_sep)); // part of the string after the last separator
204 $result = db_query_range("SELECT * FROM {biblio_keyword_data} WHERE LOWER(word) LIKE LOWER('%s%%') ORDER BY word ASC ", array($end), 0, 10);
205 while ($data = db_fetch_object($result)) {
206 // now glue the word found onto the end of the original string...
207 $keywords = ($sep_pos) ? $start . ', ' . check_plain($data->word) : check_plain($data->word);
208 $matches[$keywords] = $keywords;
209 }
210 }else{
211 $result = db_query_range("SELECT %s FROM {biblio} WHERE LOWER(%s) LIKE LOWER('%s%%') ORDER BY %s ASC", array($field, $field, $string, $field) , 0, 10);
212 while ($data = db_fetch_object($result)) {
213 $matches[$data-> $field] = check_plain($data-> $field);
214 }
215 }
216 print drupal_to_js($matches);
217 exit();
218 }
219 function biblio_help_page() {
220 $base = variable_get('biblio_base', 'biblio');
221 $text .= "<h3>". t('General:') ."</h3>";
222 $text .= "<p>". t('By default, the !url page will list all of the entries in the database sorted by Year in descending order. If you wish to sort by "Title" or "Type", you may do so by clicking on the appropriate links at the top of the page. To reverse the sort order, simply click the link a second time.', array(
223 '!url' => l('',
224 $base
225 ))) ."</p>";
226 $text .= "<h3>". t('Filtering Search Results:') ."</h3>";
227 $text .= "<p>". t('If you wish to filter the results, click on the "Filter" tab at the top of the page. To add a filter, click the radio button to the left of the filter type you wish to apply, then select the filter criteria from the drop down list on the right, then click the filter button.') ."</p>";
228 $text .= "<p>". t('It is possible to create complex filters by returning to the <i>Filter</i> tab and adding additional filters. Simply follow the steps outlined above and press the "Refine" button.') ."</p>";
229 $text .= "<p>". t('All filters can be removed by clicking the <i>Clear All Filters</i> link at the top of the result page, or on the <i>Filter</i> tab they can be removed one at a time using the <i>Undo</i> button, or you can remove them all using the <i>Clear All</i> button.') ."</p>";
230 $text .= "<p>". t('You may also construct URLs which filter. For example, /biblio/year/2005 will show all of the entries for 2005. /biblio/year/2005/author/smith will show all of entries from 2005 for smith.') ."</p>";
231 $text .= "<h3>". t('Exporting Search Results:') ."</h3>";
232 $text .= "<p>". t('Assuming this option has been enabled by the administrator, you can export search results directly into EndNote. The link at the top of the result page will export all of the search results, and the links on individual entries will export the information related to that single entry.') ."</p>";
233 $text .= "<p>". t('The information is exported in EndNote "Tagged" format similar to this...') ."<pre>". t('
234 %0 Book
235 %A John Smith
236 %D 1959
237 %T The Works of John Smith
238 ...') .'</pre></p>';
239 $text .= "<p>". t('Clicking on one of the export links should cause your browser to ask you whether you want to Open, or Save To Disk, the file endnote.enw. If you choose to open it, Endnote should start and ask you which library you would like store the results in. Alternatively, you can save the file to disk and manually import it into EndNote.') ."</p>";
240 return ($text);
241 }
242 /**
243 * Implementation of hook_help().
244 *
245 * Throughout Drupal, hook_help() is used to display help text at the top of
246 * pages. Some other parts of Drupal pages get explanatory text from these hooks
247 * as well. We use it here to provide a description of the module on the
248 * module administration page.
249 */
250 function biblio_help($path, $arg) {
251 switch ($path) {
252 case 'admin/help#biblio' :
253 return biblio_help_page();
254 case 'admin/modules#description' :
255 // This description is shown in the listing at admin/modules.
256 return t('Manages a list of scholarly papers on your site');
257 case 'node/add#biblio' :
258 // This description shows up when users click "create content."
259 return t('This allows you to add a bibliographic entry to the database');
260 }
261 }
262 function biblio_node_info() {
263 return array(
264 'biblio' => array(
265 'name' => t('Biblio'),
266 'module' => 'biblio',
267 'description' => t('Manages bibliographies')
268 )
269 );
270 }
271 /**
272 * Implementation of hook_access().
273 *
274 * Node modules may implement node_access() to determine the operations
275 * users may perform on nodes. This example uses a very common access pattern.
276 */
277 function biblio_access($op, $node = '', $user = '') {
278 switch ($op) {
279 case 'create':
280 return user_access('create biblio');
281 case 'delete':
282 case 'update':
283 if (user_access('edit all biblio entries')) return TRUE;
284 if (user_access('edit own biblio entries') && $user->uid == $node->uid) return TRUE;
285 if (user_access('edit own biblio entries') && $user->uid != $node->uid) return FALSE;
286 break;
287 case 'view':
288 if ((variable_get('biblio_view_only_own', 0)) && $user->uid != $node->uid) return FALSE;
289 break;
290 case 'admin':
291 return user_access('administer biblio');
292 case 'import':
293 return user_access('import from file');
294 case 'export':
295 return user_access('show export links');
296 case 'edit_author':
297 if (user_access('administer biblio') || user_access('edit biblio authors')) return TRUE;
298 break;
299 case 'download':
300 if (user_access('show download links') || (user_access('show own download links') && ($user->uid == $node->uid))) return TRUE;
301 break;
302 case 'rss':
303 return variable_get('biblio_rss', 0);
304 default:
305 }
306 return;
307 }
308 /**
309 * Implementation of hook_perm().
310 *
311 * Since we are limiting the ability to create new nodes to certain users,
312 * we need to define what those permissions are here. We also define a permission
313 * to allow users to edit the nodes they created.
314 */
315 function biblio_perm() {
316 return array(
317 'administer biblio',
318 'access biblio content',
319 'create biblio',
320 'edit all biblio entries',
321 'edit own biblio entries',
322 'edit biblio authors',
323 'import from file',
324 'show export links',
325 'show download links',
326 'show own download links',
327 'show filter tab',
328 'show sort links',
329 'view full text'
330 );
331 }
332 /**
333 * Implementation of hook_link().
334 *
335 * This is implemented so that an edit link is displayed for users who have
336 * the rights to edit a node.
337 */
338 function biblio_link($type, $node = NULL, $teaser = FALSE) {
339 $links = array();
340 $base = variable_get('biblio_base', 'biblio');
341
342 if ($type == 'node' && $node->type == 'biblio') {
343 // Don't display a redundant edit link if they are node administrators.
344 if (biblio_access('update', $node) && !user_access('administer nodes')) {
345 $links['biblio_edit'] = array(
346 'title' => t('edit this entry'),
347 'href' => "node/$node->nid/edit"
348 );
349
350 }
351 if (biblio_access('export', $node)) {
352 $show_link = variable_get('biblio_export_links', array('tagged' => TRUE, 'xml' => TRUE, 'bibtex' => TRUE));
353 $show_link['google'] = variable_get('biblio_google_link', 1);
354 if ($show_link['tagged']) $links['biblio_tagged'] = _build_biblio_tagged_link($base, $node->nid);
355 if ($show_link['xml']) $links['biblio_xml'] = _build_biblio_xml_link($base, $node->nid);
356 if ($show_link['bibtex']) $links['biblio_bibtex'] = _build_biblio_bibtex_link($base, $node->nid);
357 if ($show_link['google']) $links['biblio_google_scholar'] = _build_google_scholar_link($node);
358 }
359
360
361 }
362 return $links;
363 }
364 /**
365 * Implementation of hook_link_alter to modifiy taxonomy links
366 *
367 * @param $links
368 * @param $node
369 * @return none
370 */
371 //function biblio_link_alter(&$links, $node) {
372 // foreach ($links AS $module => $link) {
373 // if (strstr($module, 'taxonomy_term')) {
374 // // Link back to the forum and not the taxonomy term page
375 // $links[$module]['href'] = str_replace('taxonomy/term', 'biblio/term_id', $link['href']);
376 // }
377 // }
378 //}
379 /**
380 * Implementation of hook_user().
381 */
382 function biblio_user($type, & $edit, & $user, $category = NULL) {
383 if ($type == 'form' && $category == 'account' ) {
384 $form['biblio_fieldset'] = array(
385 '#type' => 'fieldset',
386 '#title' => t('Biblio settings'),
387 '#weight' => 5,
388 '#collapsible' => TRUE,
389 '#collapsed' => TRUE,
390 );
391 include_once drupal_get_path('module', 'biblio') .'/biblio.admin.inc';
392 if (variable_get('biblio_show_user_profile_form', '1')) {
393 _biblio_get_user_profile_form($form['biblio_fieldset'], $user);
394 _biblio_get_user_openurl_form($form['biblio_fieldset'], $user);
395 }
396 if (user_access('create biblio')) _biblio_get_user_doi_form($form['biblio_fieldset'], $user);
397
398 return $form;
399 }
400 if ($type == 'validate' && $category == 'account') { // TODO: this is not reached at all
401 if (($edit['biblio_my_pubs_menu'] || $edit['biblio_show_profile']) && $edit['biblio_contributor_id'] == 0) {
402 $message = t('You did not supply an associated biblio author.');
403 drupal_set_message($message, 'warning');
404 }
405 }
406 if ($type == 'after_update' && $category == 'account') {
407 menu_rebuild();
408 }
409 if ($type == 'update' && $category == 'account') {
410 if (isset($edit['biblio_contributor_id'])) {
411 db_query("UPDATE {biblio_contributor_data} SET drupal_uid = 0 WHERE drupal_uid = %d", $user->uid);
412 db_query('UPDATE {biblio_contributor_data} set drupal_uid = %d WHERE cid = %d ', $user->uid, $edit['biblio_contributor_id']);
413 }
414 }
415 if ($type == 'categories') {
416 // return array(array('name' => 'account', 'title' => t('Account settings'), 'weight' => 1));
417 }
418 }
419 function biblio_forms() {
420 $forms['biblio_admin_author_types_form_new'] = array(
421 'callback' => 'biblio_admin_author_types_form',
422 );
423 $forms['biblio_admin_author_types_form_edit'] = array(
424 'callback' => 'biblio_admin_author_types_form',
425 );
426 return $forms;
427
428 }
429 /**
430 * Return actual argument for %biblio_user placeholders in menu paths
431 */
432 function biblio_user_to_arg($arg) {
433 // Give back the current user uid when called from eg. tracker, aka.
434 // with an empty arg. Also use the current user uid when called from
435 // the menu with a % for the current account link.
436 return (empty($arg) || $arg == '%') ? $GLOBALS['user']->uid : $arg;
437 }
438 /**
439 * load user object from arg, used for %biblio_user placeholders in menu paths
440 * @param $uid
441 * @return $user
442 */
443 function biblio_user_load($uid) {
444 return user_load($uid);
445 }
446 /**
447 * Implementation of hook_menu().
448 *
449 * Here we define some built in links for the biblio module, links exposed are:
450 *
451 *
452 */
453 function biblio_menu() {
454 global $user;
455 $items = array();
456 $base = variable_get('biblio_base', 'biblio');
457 $base_title = variable_get('biblio_base_title', 'Biblio');
458 $items["$base"] = array(
459 'title' => $base_title,
460 'page callback' => 'biblio_db_search',
461 'access callback' => 'user_access',
462 'access arguments' => array('access biblio content'),
463 'file' => 'biblio.pages.inc',
464 );
465 $items["$base/authors"] = array(
466 'title' => 'Authors',
467 'page callback' => 'biblio_author_page',
468 'access callback' => 'user_access',
469 'access arguments' => array('access biblio content'),
470 'file' => 'biblio.pages.inc',
471 'weight' => 1,
472 );
473 $items["$base/keywords"] = array(
474 'title' => 'Keywords',
475 'page callback' => 'biblio_keyword_page',
476 'access callback' => 'user_access',
477 'access arguments' => array('access biblio content'),
478 'file' => 'biblio.pages.inc',
479 // 'type' => MENU_LOCAL_TASK,
480 'weight' => 2,
481 );
482 $items["$base/import"] = array(
483 'title' => 'Import',
484 'page callback' => 'drupal_get_form',
485 'page arguments' => array('biblio_import_form'),
486 'file' => 'biblio.import.export.inc',
487 'access callback' => 'user_access',
488 'access arguments' => array('import from file'),
489 // 'type' => MENU_LOCAL_TASK,
490 'weight' => 10,
491 );
492 $items["$base/user/%biblio_user"] = array(
493 'title' => 'My publications',
494 'page callback' => 'biblio_get_user_pubs',
495 'page arguments' => array(2),
496 'access callback' => '_biblio_profile_access',
497 'access arguments' => array(2, 'menu'),
498 'parent' => '',
499 'file' => 'biblio.pages.inc',
500 );
501 /*
502 $items["$base/backup"] = array(
503 'title' => '',
504 'page callback' => 'biblio_backup',
505 'access callback' => 'user_access',
506 'access arguments' => array('access content'),
507 'file' => 'biblio.import.export.inc',
508 'type' => MENU_CALLBACK
509 );
510 */
511 $items["$base/pot"] = array(
512 'title' => '',
513 'page callback' => 'biblio_dump_db_data_for_pot',
514 'access callback' => 'user_access',
515 'access arguments' => array('access biblio content'),
516 'type' => MENU_CALLBACK
517 );
518
519 $wildcard = 2 + (count(explode("/", $base)) - 1);
520
521 $items["$base/authors/%/edit"] = array(
522 'title' => 'Edit author information',
523 'page callback' => 'drupal_get_form',
524 'page arguments' => array('biblio_admin_author_edit_form', $wildcard),
525 'access callback' => 'biblio_access',
526 'access arguments' => array('edit_author'),
527 'file' => 'biblio.admin.inc',
528 'type' => MENU_CALLBACK
529 );
530 $items["$base/keywords/%/edit"] = array(
531 'title' => '',
532 'page callback' => 'drupal_get_form',
533 'page arguments' => array('biblio_admin_keyword_edit_form', $wildcard),
534 'access callback' => 'user_access',
535 'access arguments' => array('administer biblio'),
536 'file' => 'biblio.admin.inc',
537 'type' => MENU_CALLBACK
538 );
539 $items["$base/keyword/%/delete"] = array(
540 'title' => 'Delete',
541 'page callback' => 'drupal_get_form',
542 'page arguments' => array('biblio_admin_keyword_delete_confirm', $wildcard),
543 'access callback' => 'user_access',
544 'access arguments' => array('administer biblio'),
545 'file' => 'biblio.admin.inc',
546 'weight' => 1,
547 'type' => MENU_CALLBACK
548 );
549 $items["user/%user/$base"] = array(
550 'title' => 'Publications',
551 'page callback' => 'biblio_get_user_pubs',
552 'page arguments' => array(1, 'profile', 'no_filters'),
553 'access callback' => '_biblio_profile_access',
554 'access arguments' => array(1, 'profile'),
555 'file' => 'biblio.pages.inc',
556 'type' => MENU_LOCAL_TASK
557 );
558 // The next two "LOCAL TASKS" are for the admin/settings/biblio page
559 $items['admin/settings/biblio'] = array(
560 'title' => 'Biblio settings',
561 'description' => 'Configure default behavior of the biblio module.',
562 'page callback' => 'drupal_get_form',
563 'page arguments' => array('biblio_admin_settings'),
564 'access arguments' => array('administer biblio'),
565 'file' => 'biblio.admin.inc',
566 );
567 $items['admin/settings/biblio/ahah'] = array(
568 'title' => '',
569 'page callback' => 'biblio_admin_ahah',
570 'file' => 'biblio.admin.inc',
571 'access arguments' => array('administer biblio'),
572 'type' => MENU_CALLBACK,
573 );
574
575 $items['admin/settings/biblio/basic'] = array(
576 'title' => 'Preferences',
577 'type' => MENU_DEFAULT_LOCAL_TASK,
578 'weight' => -10
579 );
580 $items['admin/settings/biblio/import'] = array(
581 'title' => 'Import',
582 'page callback' => 'drupal_get_form',
583 'page arguments' => array('biblio_import_form'),
584 'access arguments' => array('administer biblio'),
585 'file' => 'biblio.import.export.inc',
586 'type' => MENU_LOCAL_TASK,
587 'weight' => 1
588 );
589 $items['admin/settings/biblio/export'] = array(
590 'title' => 'Export',
591 'page callback' => 'drupal_get_form',
592 'page arguments' => array('biblio_export_form'),
593 'access arguments' => array('administer biblio'),
594 'file' => 'biblio.import.export.inc',
595 'type' => MENU_LOCAL_TASK,
596 'weight' => 2
597 );
598 $items['admin/settings/biblio/fields'] = array(
599 'title' => 'Fields',
600 'page callback' => 'drupal_get_form',
601 'page arguments' => array('biblio_admin_types_edit_form'),
602 'access arguments' => array('administer biblio'),
603 'file' => 'biblio.admin.inc',
604 'type' => MENU_LOCAL_TASK,
605 'weight' => -9
606 );
607 $items['admin/settings/biblio/fields/common'] = array(
608 'title' => 'Common',
609 'page callback' => 'drupal_get_form',
610 'page arguments' => array('biblio_admin_types_edit_form'),
611 'access arguments' => array('administer biblio'),
612 'file' => 'biblio.admin.inc',
613 'type' => MENU_DEFAULT_LOCAL_TASK,
614 'weight' => -9
615 );
616 $items['admin/settings/biblio/fields/type'] = array(
617 'title' => 'Publication Types',
618 'page callback' => 'biblio_admin_types_form',
619 // 'page arguments' => array('biblio_admin_types_form'),
620 'access arguments' => array('administer biblio'),
621 'file' => 'biblio.admin.inc',
622 'type' => MENU_LOCAL_TASK,
623 'weight' => -8
624 );
625 $items['admin/settings/biblio/fields/typemap'] = array(
626 'title' => t('Type Mapping'),
627 'page callback' => 'biblio_admin_type_mapper_page',
628 // 'page arguments' => array('biblio_admin_type_mapper_page'),
629 'access arguments' => array('administer biblio'),
630 'file' => 'biblio.admin.inc',
631 'type' => MENU_LOCAL_TASK,
632 'weight' => -1
633 );
634 $items['admin/settings/biblio/fields/typemap/%'] = array(
635 'title' => t('Type Mapping'),
636 'page callback' => 'drupal_get_form',
637 'page arguments' => array('biblio_admin_type_mapper_form', 5),
638 'access arguments' => array('administer biblio'),
639 'file' => 'biblio.admin.inc',
640 'type' => MENU_CALLBACK,
641 'weight' => -1
642 );
643 $items['admin/settings/biblio/fields/type/edit'] = array(
644 'title' => '',
645 'page callback' => 'drupal_get_form',
646 'page arguments' => array('biblio_admin_types_edit_form'),
647 'access arguments' => array('administer biblio'),
648 'file' => 'biblio.admin.inc',
649 'type' => MENU_CALLBACK
650 );
651 $items['admin/settings/biblio/fields/type/delete'] = array(
652 'title' => '',
653 'page callback' => 'drupal_get_form',
654 'page arguments' => array('biblio_admin_types_delete_form'),
655 'access arguments' => array('administer biblio'),
656 'file' => 'biblio.admin.inc',
657 'type' => MENU_CALLBACK
658 );
659 $items['admin/settings/biblio/fields/type/new'] = array(
660 'title' => 'Add New Type',
661 'page callback' => 'drupal_get_form',
662 'page arguments' => array('biblio_admin_types_add_form'),
663 'access arguments' => array('administer biblio'),
664 'file' => 'biblio.admin.inc',
665 'type' => MENU_LOCAL_TASK,
666 'weight' => -9
667 );
668 $items['admin/settings/biblio/fields/type/reset'] = array(
669 'title' => 'Reset all types to defaults',
670 'page callback' => 'drupal_get_form',
671 'page arguments' => array('biblio_admin_types_reset_form'),
672 'access arguments' => array('administer biblio'),
673 'file' => 'biblio.admin.inc',
674 'type' => MENU_LOCAL_TASK
675 );
676 $items['admin/settings/biblio/fields/type/hide'] = array(
677 'title' => '',
678 'page callback' => 'biblio_admin_types_hide',
679 'access arguments' => array('administer biblio'),
680 'file' => 'biblio.admin.inc',
681 'type' => MENU_CALLBACK
682 );
683 $items['admin/settings/biblio/fields/type/show'] = array(
684 'title' => '',
685 'page callback' => 'biblio_admin_types_show',
686 'access arguments' => array('administer biblio'),
687 'file' => 'biblio.admin.inc',
688 'type' => MENU_CALLBACK
689 );
690 $items['admin/settings/biblio/author'] = array(
691 'title' => 'Authors',
692 'page callback' => 'biblio_author_page',
693 'access callback' => 'user_access',
694 'access arguments' => array('access biblio content'),
695 'file' => 'biblio.pages.inc',
696 'type' => MENU_LOCAL_TASK,
697 'weight' => -7
698 );
699 $items['admin/settings/biblio/author/list'] = array(
700 'title' => 'List',
701 'page callback' => 'biblio_author_page',
702 'access callback' => 'user_access',
703 'access arguments' => array('access biblio content'),
704 'file' => 'biblio.pages.inc',
705 'type' => MENU_DEFAULT_LOCAL_TASK,
706 'weight' => -7
707 );
708 $items['admin/settings/biblio/author/%/edit'] = array(
709 'title' => 'Edit author information',
710 'page callback' => 'drupal_get_form',
711 'page arguments' => array('biblio_admin_author_edit_form',4),
712 'access callback' => 'biblio_access',
713 'access arguments' => array('edit_author'),
714 'file' => 'biblio.admin.inc',
715 'type' => MENU_CALLBACK,
716 'weight' => -6
717 );
718 $items['admin/settings/biblio/author/orphans'] = array(
719 'title' => 'Orphaned Authors',
720 'page callback' => 'drupal_get_form',
721 'page arguments' => array('biblio_admin_orphans_form'),
722 'access arguments' => array('administer biblio'),
723 'description' => 'Delete orphaned biblio authors.',
724 'file' => 'biblio.admin.inc',
725 'type' => MENU_LOCAL_TASK,
726 'weight' => -6
727 );
728 $items['admin/settings/biblio/author/type'] = array(
729 'title' => 'Author Types',
730 'page callback' => 'drupal_get_form',
731 'page arguments' => array('biblio_admin_author_types_form', 6, 5),
732 'access arguments' => array('administer biblio'),
733 'file' => 'biblio.admin.inc',
734 'type' => MENU_LOCAL_TASK,
735 'weight' => -5
736 );
737
738 $items['admin/settings/biblio/author/type/new'] = array(
739 'title' => 'Add New Author Type',
740 'page callback' => 'drupal_get_form',
741 'page arguments' => array('biblio_admin_author_types_form_new', 'new'),
742 'access arguments' => array('administer biblio'),
743 'file' => 'biblio.admin.inc',
744 'type' => MENU_LOCAL_TASK,
745 'weight' => -9
746 );
747 $items['admin/settings/biblio/author/type/%/edit'] = array(
748 'title' => 'Add New Author Type',
749 'page callback' => 'drupal_get_form',
750 'page arguments' => array('biblio_admin_author_types_form_edit', 'edit', 5),
751 'access arguments' => array('administer biblio'),
752 'file' => 'biblio.admin.inc',
753 'type' => MENU_CALLBACK,
754 'weight' => -9
755 );
756 $items['admin/settings/biblio/author/type/%/delete'] = array(
757 'title' => 'Delete',
758 'page callback' => 'drupal_get_form',
759 'page arguments' => array('biblio_admin_author_type_delete_confirm', 5),
760 'access callback' => 'user_access',
761 'access arguments' => array('administer biblio'),
762 'file' => 'biblio.admin.inc',
763 'weight' => 1,
764 'type' => MENU_CALLBACK
765 );
766 $items['admin/settings/biblio/keywords'] = array(
767 'title' => 'Keywords',
768 'page callback' => 'biblio_keyword_page',
769 'access callback' => 'user_access',
770 'access arguments' => array('access biblio content'),
771 'file' => 'biblio.pages.inc',
772 'type' => MENU_LOCAL_TASK,
773 'weight' => -7
774 );
775 $items['admin/settings/biblio/keywords/list'] = array(
776 'title' => 'List',
777 'page callback' => 'biblio_keyword_page',
778 'access callback' => 'user_access',
779 'access arguments' => array('access biblio content'),
780 'file' => 'biblio.pages.inc',
781 'type' => MENU_DEFAULT_LOCAL_TASK,
782 'weight' => -7
783 );
784 $items['admin/settings/biblio/keywords/%/edit'] = array(
785 'title' => 'Edit keyword information',
786 'page callback' => 'drupal_get_form',
787 'page arguments' => array('biblio_admin_keyword_edit_form',4),
788 'access callback' => 'user_access',
789 'access arguments' => array('administer biblio'),
790 'file' => 'biblio.admin.inc',
791 'type' => MENU_CALLBACK,
792 'weight' => -6
793 );
794 $items['admin/settings/biblio/keywords/orphans'] = array(
795 'title' => 'Orphaned Keywords',
796 'page callback' => 'drupal_get_form',
797 'page arguments' => array('biblio_admin_keyword_orphans_form'),
798 'access arguments' => array('administer biblio'),
799 'description' => 'Delete orphaned biblio keywords.',
800 'file' => 'biblio.admin.inc',
801 'type' => MENU_LOCAL_TASK,
802 'weight' => -6
803 );
804 /* $items['admin/settings/biblio/authors/reset'] = array(
805 'title' => t('Reset all Author types to defaults'),
806 'page callback' => 'drupal_get_form',
807 'page arguments' => array('biblio_admin_author_type_reset_form'),
808 'access arguments' => array('administer biblio'),
809 'file' => 'biblio.admin.inc',
810 'type' => MENU_LOCAL_TASK
811 );
812 */
813 $items['biblio/autocomplete'] = array(
814 'title' => 'Autocomplete ',
815 'page callback' => 'biblio_autocomplete',
816 'access callback' => 'user_access',
817 'access arguments' => array('access biblio content'),
818 'type' => MENU_CALLBACK
819 );
820 $items['biblio/js'] = array(
821 'title' => 'Javascript Contributors Form',
822 'page callback' => 'biblio_contributors_js',
823 'access arguments' => array('access biblio content'),
824 'type' => MENU_CALLBACK,
825 );
826 $items["$base/list"] = array(
827 'title' => 'List',
828 'type' => MENU_DEFAULT_LOCAL_TASK,
829 'weight' => -10
830 );
831 $items["$base/filter"] = array(
832 'title' => 'Filter',
833 'page callback' => 'drupal_get_form',
834 'page arguments' => array('biblio_form_filter'),
835 'access callback' => 'user_access',
836 'access arguments' => array('show filter tab'),
837 'type' => MENU_LOCAL_TASK,
838 'file' => 'biblio.pages.inc',
839 'weight' => -9
840 );
841 $items["$base/filter/clear"] = array(
842 'title' => '',
843 'page callback' => 'biblio_filter_clear',
844 'access callback' => 'user_access',
845 'access arguments' => array('access biblio content'),
846 'type' => MENU_CALLBACK
847 );
848 $items["$base/help"] = array(
849 'title' => 'Help',
850 'page callback' => 'biblio_help_page',
851 'access callback' => 'user_access',
852 'access arguments' => array('access biblio content'),
853 'type' => MENU_CALLBACK
854 );
855 $items["$base/export"] = array(
856 'title' => '',
857 'page callback' => 'biblio_export',
858 'access callback' => 'user_access',
859 'access arguments' => array('show export links'),
860 'file' => 'biblio.import.export.inc',
861 'type' => MENU_CALLBACK
862 );
863 $items["$base/citekey"] = array(
864 'title' => '',
865 'page callback' => 'biblio_citekey_view',
866 'access arguments' => array('access biblio content'),
867 'file' => 'biblio.pages.inc',
868 'type' => MENU_CALLBACK
869 );
870 $items["$base/viewinline/%node"] = array(
871 'title' => '',
872 'page callback' => 'biblio_view_inline',
873 'page arguments' => array(2),
874 'access callback' => 'user_access',
875 'access arguments' => array('access biblio content'),
876 'file' => 'biblio.pages.inc',
877 'type' => MENU_CALLBACK
878 );
879 $items["$base/recent/rss.xml"] = array(
880 'title' => 'RSS feed',
881 'page callback' => 'biblio_recent_feed',
882 'access callback' => 'biblio_access',
883 'access arguments' => array('rss'),
884 'type' => MENU_CALLBACK
885 );
886 return $items;
887 }
888 function biblio_filter_clear() {
889 $_SESSION['biblio_filter'] = array();
890 $base = variable_get('biblio_base', 'biblio');
891 if (isset($_GET['sort'])) {
892 $options .= "sort=". $_GET['sort'];
893 }
894 if (isset($_GET['order'])) {
895 $options .= $options['query'] ? "&" : "";
896 $options .= "order=". $_GET['order'];
897 }
898 drupal_goto($base, $options);
899 }
900 function biblio_remove_brace($title_string){
901 //$title_string = utf8_encode($title_string);
902 $matchpattern = '/\{\$(?:(?!\$\}).)*\$\}|(\{[^}]*\})/';
903 $output = preg_replace_callback($matchpattern,'biblio_remove_brace_callback',$title_string);
904 return $output;
905 }
906
907 function biblio_remove_brace_callback($match){
908 if(isset($match[1])){
909 $braceless = str_replace('{', '', $match[1]);
910 $braceless = str_replace('}', '', $braceless);
911 return $braceless;
912 }
913 return $match[0];
914 }
915
916 function biblio_nodeapi(& $node, $op, $a3, $a4) {
917 if ($node->type == 'biblio') {
918 switch ($op) {
919 case 'delete revision' :
920 db_query('DELETE FROM {biblio} WHERE vid = %d', $node->vid);
921 db_query('DELETE FROM {biblio_contributor} WHERE nid = %d AND vid = %d', array($node->nid, $node->vid));
922 db_query('DELETE FROM {biblio_keyword} WHERE nid = %d AND vid = %d', array($node->nid, $node->vid));
923 break;
924 /* case 'presave':
925 if ($node->type == 'biblio')
926 {
927 // $node->body = '';
928 // $node_clone = clone($node); // we need a clone since objects get passed by reference regardless and we don't want to change the whole node object
929 // $node->body = theme('biblio_tabular', $node_clone, $base, $teaser);
930 $style = biblio_get_style();
931 $node->teaser = theme('biblio_style', $node_clone, $base, $style);
932 }
933 break;
934 */
935 case 'insert':
936 if (variable_get('biblio_index', 0)) {
937 _node_index_node($node);
938 search_update_totals();
939 }
940 break;
941 case 'update':
942 if (variable_get('biblio_index', 0)) {
943 // _node_index_node performs a node_load without resetting the node_load cache,
944 // so it would index the old version. We reset the cache here.
945 // Don't assign node_load to $node because node_load resets e.g. the menus mlid etc.
946 $mynode = node_load($node->nid, NULL, TRUE);
947 _node_index_node($mynode);
948 search_update_totals();
949 }
950 break;
951 case 'view':
952 if ($node->type == 'biblio' && variable_get('biblio_hide_bibtex_braces', 0)) {
953 drupal_set_title(filter_xss($node->title, biblio_get_allowed_tags()));
954 }
955 break;
956 }
957
958 }
959 }
960 function biblio_form_alter(&$form, $form_state, $form_id) {
961
962 if ($form_id == "biblio_node_form") { // this next bit is to remove all the form elements execpt the pub type select box the first time through
963 if (!isset($form_state['values']['biblio_type']) &&
964 empty($form_state['post']['biblio_type']) &&
965 empty($form_state['submitted']) &&
966 empty($form['vid']['#value'])) {
967
968 foreach (element_children($form) as $form_element) {
969 if ($form_element == 'doi_lookup') continue;
970 if ($form_element == 'cut_paste') continue;
971 if ($form[$form_element]['#type'] == 'fieldset' ||
972 $form_element == 'buttons' ||
973 $form_element == 'taxonomy' ||
974 strstr($form_element, 'field_')) {
975 $form[$form_element] = NULL;
976 }
977 }
978
979 }
980 else {
981 if (isset($form['menu']['#weight']) && $form['menu']['#weight'] < 20) $form['menu']['#weight'] = 20;
982 if (isset($form['book']['#weight']) && $form['book']['#weight'] < 20) $form['book']['#weight'] = 20;
983 if (isset($form['taxonomy'])) {
984 if (!isset($form['taxonomy']['#title'])) {
985 $form['taxonomy'] += array(
986 '#type' => 'fieldset',
987 '#title' => t('Vocabularies'),
988 '#collapsible' => TRUE,
989 '#collapsed' => FALSE,
990 );
991 }
992 $form['taxonomy']['#description'] = t('Select taxonomy terms which will be related to this ').variable_get('biblio_base_title', 'Biblio').t(' entry.');
993 $form['taxonomy']['copy_to_biblio'] = array(
994 '#type' => 'checkbox',
995 '#title' => t('Copy these terms to the biblio keyword database'),
996 '#return_value' => 1,
997 '#default_value' => variable_get('biblio_copy_taxo_terms_to_keywords', 0),
998 '#description' => t('If this option is selected, the selected taxonomy terms will be copied to the '.variable_get('biblio_base_title', 'Biblio').' keyword database and be displayed as keywords (as well as taxonomy terms) for this entry.')
999 );
1000 }
1001 $kw_vocab = variable_get('biblio_keyword_vocabulary', 0);
1002 $freetagging = variable_get('biblio_keyword_freetagging', 0);
1003 if ($freetagging && $kw_vocab && isset($form['taxonomy']['tags'][$kw_vocab])) {
1004 unset($form['taxonomy']['tags'][$kw_vocab]);
1005
1006 }
1007 }
1008 }
1009 return $form;
1010 }
1011 /**
1012 * Implementation of hook_form().
1013 *
1014 * Create the form for collecting the information
1015 * specific to this node type. This hook requires us to return some HTML
1016 * that will be later placed inside the form.
1017 */
1018 function biblio_form($node, $form_state) {
1019 global $user;
1020
1021 if (isset($form_state['post']['biblio_type'])) {
1022 $tid = $form_state['post']['biblio_type'];
1023 }
1024 elseif (isset($form_state['values']['biblio_type'])) {
1025 $tid = $form_state['values']['biblio_type'];
1026 }
1027 else {
1028 $tid = $node->biblio_type;
1029 }
1030 $show_fields = !empty($tid);
1031
1032 $form['#validate'][] = 'biblio_form_validate';
1033 $form['#cache'] = TRUE;
1034
1035 /* publication type */
1036 $param['options'] = array(
1037 "enctype" => "multipart/form-data"
1038 );
1039 $result = db_query('SELECT t.* FROM {biblio_types} as t WHERE tid > -2 AND visible = 1');
1040 while ($option = db_fetch_object($result)) {
1041 $options["$option->tid"] = $option->name;
1042 }
1043 if (!isset($node->nid)) {// only show the doi lookup and paste boxes if this is a new entry
1044 if(phpversion() > 5 && !isset($form_state['storage']['biblio_doi'])) {
1045 $form['doi_lookup'] = array(
1046 '#type' => 'fieldset',
1047 '#title' => t('DOI Lookup'),
1048 '#weight' => -20,
1049 '#collapsible' => TRUE,
1050 '#collapsed' => TRUE,
1051 );
1052 $have_pid = (isset($user->biblio_crossref_pid) && !empty($user->biblio_crossref_pid)) ? FALSE : TRUE;
1053 if ($have_pid) {
1054 $form['doi_lookup']['doi_register'] = array(
1055 '#prefix' => '<p><b>',
1056 '#suffix' => '</b></p>',
1057 '#value' => l('You need to register with CrossRef', 'http://www.crossref.org/requestaccount/', array('attributes' => array('target' => '_blank'), 'absolue' => TRUE)). t(' and then enter your CrossRef UserID in the "<i>CrossRef Login Information</i>" section of your account profile '). l('here...',"user/$user->uid/edit"),
1058 );
1059 }
1060
1061 $form['doi_lookup']['doi_data'] = array(
1062 '#type' => 'textfield',
1063 '#title' => t('DOI'),
1064 '#required' => FALSE,
1065 '#default_value' => '',
1066 '#description' => t('Enter a DOI name in the form: <b>10.1000/123456</b>'),
1067 '#disabled' => $have_pid,
1068 '#size' => 60,
1069 '#maxlength' => 255,
1070 '#weight' => -4
1071 );
1072 $form['doi_lookup']['doi_submit'] = array(
1073