auth_category][$row->biblio_type][] = $row->auth_type; } } $result = $auth_types[$auth_category][$biblio_type]; // fall back to defaults, if no author types are defined for this biblio_type if (empty($result)) $result = $auth_types[$auth_category][0]; return $result; } function _biblio_get_auth_type($auth_category, $biblio_type) { $result = (array)_biblio_get_auth_types($auth_category, $biblio_type); // return first element of the array return empty($result) ? NULL : current($result); } function _biblio_get_field_information($biblio_type) { $result = db_query("SELECT b.*, btd.*, btt.name AS type_name FROM {biblio_fields} AS b INNER JOIN {biblio_field_type} AS bt ON bt.fid = b.fid INNER JOIN {biblio_field_type_data} AS btd ON btd.ftdid = bt.ftdid INNER JOIN {biblio_types} as btt ON btt.tid = bt.tid WHERE bt.tid = %d ORDER BY bt.weight ASC", $biblio_type); while ($row = db_fetch_array($result)) { $fields[$row['fid']] = $row; } return $fields; } function biblio_init() { drupal_add_css(drupal_get_path('module', 'biblio') .'/biblio.css'); } function biblio_theme() { return array( 'biblio_alpha_line' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('type'), ), 'biblio_admin_author_types_form' => array( 'file' => 'biblio.admin.inc', 'arguments' => array('form'), ), 'biblio_admin_types_edit_form' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('form'), ), 'biblio_admin_author_edit_form' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('form'), ), 'biblio_admin_orphans_form' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('form'), ), 'biblio_admin_keyword_orphans_form' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('form'), ), 'biblio_coin_button' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('element'), ), 'biblio_openurl' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('openURL'), ), 'biblio_style' => array( 'file' => 'biblio_theme.inc', 'arguments' => array( 'node', 'base' => 'biblio', 'style_name' => 'classic', 'inline' => FALSE), ), 'biblio_long' => array( 'file' => 'biblio_theme.inc', 'arguments' => array( 'node', 'base' => 'biblio', 'style_name' => 'classic'), ), 'biblio_tabular' => array( 'file' => 'biblio_theme.inc', 'arguments' => array( 'node', 'base' => 'biblio', 'teaser' => FALSE), ), 'biblio_entry' => array( 'file' => 'biblio_theme.inc', 'arguments' => array( 'node', 'base' => 'biblio', 'style_name' => 'classic', 'inline' => FALSE), ), 'biblio_authors' => array( 'file' => 'biblio_theme.inc', 'arguments' => array( 'contributors', 'style' => 'classic', 'inline' => FALSE, 'glue' => ', '), ), 'biblio_format_authors' => array( 'file' => 'biblio_theme.inc', 'arguments' => array( 'contributors', 'options' => array(), 'inline' => FALSE,), ), 'biblio_filters' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('form'), ), 'form_filter' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('form'), ), 'biblio_tagged_link' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('base', 'nid'), ), 'biblio_xml_link' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('base', 'nid'), ), 'biblio_bibtex_link' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('base', 'nid'), ), 'biblio_export_links' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('nid'), ), 'biblio_download_links' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('node'), ), 'biblio_contributors' => array( 'file' => 'biblio_theme.inc', 'arguments' => array('form'), ), ); } function biblio_autocomplete($field, $string = '') { $matches = array(); if ($field == 'contributor') { $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); while ($data = db_fetch_object($result)) { $matches[$data->name] = check_plain($data->name); } }elseif ($field == 'biblio_keywords') { $sep = variable_get('biblio_keyword_sep', ','); $sep_pos = strrpos($string, $sep); //find the last separator $start = trim(drupal_substr($string, 0, $sep_pos)); // first part of the string upto the last separator $end_sep = ($sep_pos) ? $sep_pos + 1 :$sep_pos; $end = trim(drupal_substr($string, $end_sep)); // part of the string after the last separator $result = db_query_range("SELECT * FROM {biblio_keyword_data} WHERE LOWER(word) LIKE LOWER('%s%%') ORDER BY word ASC ", array($end), 0, 10); while ($data = db_fetch_object($result)) { // now glue the word found onto the end of the original string... $keywords = ($sep_pos) ? $start . ', ' . check_plain($data->word) : check_plain($data->word); $matches[$keywords] = $keywords; } }else{ $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); while ($data = db_fetch_object($result)) { $matches[$data-> $field] = check_plain($data-> $field); } } print drupal_to_js($matches); exit(); } function biblio_help_page() { $base = variable_get('biblio_base', 'biblio'); $text .= "
". 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( '!url' => l('', $base ))) ."
"; $text .= "". 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.') ."
"; $text .= "". t('It is possible to create complex filters by returning to the Filter tab and adding additional filters. Simply follow the steps outlined above and press the "Refine" button.') ."
"; $text .= "". t('All filters can be removed by clicking the Clear All Filters link at the top of the result page, or on the Filter tab they can be removed one at a time using the Undo button, or you can remove them all using the Clear All button.') ."
"; $text .= "". 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.') ."
"; $text .= "". 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.') ."
"; $text .= "". t('The information is exported in EndNote "Tagged" format similar to this...') ."
". t(' %0 Book %A John Smith %D 1959 %T The Works of John Smith ...') .''; $text .= "
". 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.') ."
"; return ($text); } /** * Implementation of hook_help(). * * Throughout Drupal, hook_help() is used to display help text at the top of * pages. Some other parts of Drupal pages get explanatory text from these hooks * as well. We use it here to provide a description of the module on the * module administration page. */ function biblio_help($path, $arg) { switch ($path) { case 'admin/help#biblio' : return biblio_help_page(); case 'admin/modules#description' : // This description is shown in the listing at admin/modules. return t('Manages a list of scholarly papers on your site'); case 'node/add#biblio' : // This description shows up when users click "create content." return t('This allows you to add a bibliographic entry to the database'); } } function biblio_node_info() { return array( 'biblio' => array( 'name' => t('Biblio'), 'module' => 'biblio', 'description' => t('Manages bibliographies') ) ); } /** * Implementation of hook_access(). * * Node modules may implement node_access() to determine the operations * users may perform on nodes. This example uses a very common access pattern. */ function biblio_access($op, $node = '') { global $user; if ($op == 'admin') { return user_access('administer biblio'); } if ($op == 'create') { // Only users with permission to do so may create this node type. return user_access('create biblio'); } if ($op == 'import') { // Only users with permission to do so may import entries from file. return user_access('import from file'); } if ($op == 'download') { // Only users with permission to do so may see download links to attached files. if (user_access('show download links') || (user_access('show own download links') && ($user->uid == $node->uid))) { return TRUE; } break; } if ($op == 'export') { // Only users with permission to do so may export entries from file. return user_access('show export links'); } if ($op == 'rss') { // Only users with permission to do so may export entries from file. return variable_get('biblio_rss', 0); } // Users who create a node may edit or delete it later, assuming they have the // necessary permissions. if ($op == 'update' || $op == 'delete') { if (user_access('edit own biblio entries') && ($user->uid == $node->uid)) { return TRUE; } else if (user_access('edit all biblio entries')) { return TRUE; } else { return FALSE; } } if ($op == 'view') { if (variable_get('biblio_view_only_own', 0)) { if ($user->uid == $node->uid) { return TRUE; } else { return FALSE; } } else { return TRUE; } } } /** * Implementation of hook_perm(). * * Since we are limiting the ability to create new nodes to certain users, * we need to define what those permissions are here. We also define a permission * to allow users to edit the nodes they created. */ function biblio_perm() { return array( 'administer biblio', 'create biblio', 'edit all biblio entries', 'edit own biblio entries', 'import from file', 'show export links', 'show download links', 'show own download links', 'show filter tab', 'show sort links', 'view full text' ); } /** * Implementation of hook_link(). * * This is implemented so that an edit link is displayed for users who have * the rights to edit a node. */ function biblio_link($type, $node = NULL, $teaser = FALSE) { $links = array(); if ($type == 'node' && $node->type == 'biblio') { // Don't display a redundant edit link if they are node administrators. if (biblio_access('update', $node) && !user_access('administer nodes')) { $links['biblio_edit'] = array( 'title' => t('edit this entry'), 'href' => "node/$node->nid/edit" ); return $links; } } return; } /** * Implementation of hook_link_alter to modifiy taxonomy links * * @param $links * @param $node * @return none */ //function biblio_link_alter(&$links, $node) { // foreach ($links AS $module => $link) { // if (strstr($module, 'taxonomy_term')) { // // Link back to the forum and not the taxonomy term page // $links[$module]['href'] = str_replace('taxonomy/term', 'biblio/term_id', $link['href']); // } // } //} /** * Implementation of hook_user(). */ function biblio_user($type, & $edit, & $user, $category = NULL) { if ($type == 'form' && $category == 'account' ) { //&& variable_get('biblio_show_user_profile_form', '1')) { $form = array(); include_once drupal_get_path('module', 'biblio') .'/biblio.admin.inc'; _biblio_get_user_profile_form($form, $user); return $form; } if ($type == 'validate' && $category == 'account') { // TODO: this is not reached at all if (($edit['biblio_my_pubs_menu'] || $edit['biblio_show_profile']) && $edit['biblio_contributor_id'] == 0) { $message = t('You did not supply an associated biblio author.'); form_set_error('biblio_contributor_id', $message); } } if ($type == 'after_update' && $category == 'account') { menu_rebuild(); } if ($type == 'update' && $category == 'account') { if ($edit['biblio_contributor_id'] > 0) { db_query('UPDATE {biblio_contributor_data} set drupal_uid = %d WHERE cid = %d ', $user->uid, $edit['biblio_contributor_id']); } } if ($type == 'categories') { // return array(array('name' => 'account', 'title' => t('Account settings'), 'weight' => 1)); } } function biblio_forms() { $forms['biblio_admin_author_types_form_new'] = array( 'callback' => 'biblio_admin_author_types_form', ); $forms['biblio_admin_author_types_form_edit'] = array( 'callback' => 'biblio_admin_author_types_form', ); return $forms; } /** * Return actual argument for %biblio_user placeholders in menu paths */ function biblio_user_to_arg($arg) { // Give back the current user uid when called from eg. tracker, aka. // with an empty arg. Also use the current user uid when called from // the menu with a % for the current account link. return (empty($arg) || $arg == '%') ? $GLOBALS['user']->uid : $arg; } /** * load user object from arg, used for %biblio_user placeholders in menu paths * @param $uid * @return $user */ function biblio_user_load($uid) { return user_load($uid); } /** * Implementation of hook_menu(). * * Here we define some built in links for the biblio module, links exposed are: * * */ function biblio_menu() { global $user; $items = array(); $base = variable_get('biblio_base', 'biblio'); $base_title = variable_get('biblio_base_title', 'Biblio'); $items["$base"] = array( 'title' => $base_title, 'page callback' => 'biblio_db_search', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'file' => 'biblio.pages.inc', //'type' => MENU_CALLBACK ); $items["$base/authors"] = array( 'title' => t('Authors'), 'page callback' => 'biblio_author_page', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'file' => 'biblio.pages.inc', 'weight' => 1, ); $items["$base/keywords"] = array( 'title' => t('Keywords'), 'page callback' => 'biblio_keyword_page', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'file' => 'biblio.pages.inc', 'weight' => 2, ); $items["$base/import"] = array( 'title' => t('Import'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_import_form'), 'file' => 'biblio.import.export.inc', 'access callback' => 'user_access', 'access arguments' => array('import from file'), // 'type' => MENU_CALLBACK 'weight' => 10, ); $items["$base/user/%biblio_user"] = array( 'title' => t('My publications'), 'page callback' => 'biblio_get_user_pubs', 'page arguments' => array(2), 'access callback' => '_biblio_profile_access', 'access arguments' => array(2, 'menu'), 'parent' => '', 'file' => 'biblio.pages.inc', ); /* $items["$base/backup"] = array( 'title' => '', 'page callback' => 'biblio_backup', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'file' => 'biblio.import.export.inc', 'type' => MENU_CALLBACK ); */ $items["$base/pot"] = array( 'title' => '', 'page callback' => 'biblio_dump_db_data_for_pot', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK); $items["$base/authors/%/edit"] = array( 'title' => t('Edit author information'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_author_edit_form', 2), 'access callback' => 'user_access', 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_CALLBACK); $items["$base/keyword/%/edit"] = array( 'title' => '', 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_keyword_edit_form', 2), 'access callback' => 'user_access', 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_CALLBACK); $items["$base/keyword/%/delete"] = array( 'title' => 'Delete', 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_keyword_delete_confirm', 2), 'access callback' => 'user_access', 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'weight' => 1, 'type' => MENU_CALLBACK); $items["user/%user/$base"] = array( 'title' => t('Publications'), 'page callback' => 'biblio_get_user_pubs', 'page arguments' => array(1, 'profile', 'no_filters'), 'access callback' => '_biblio_profile_access', 'access arguments' => array(1, 'profile'), 'file' => 'biblio.pages.inc', 'type' => MENU_LOCAL_TASK ); // The next two "LOCAL TASKS" are for the admin/settings/biblio page $items['admin/settings/biblio'] = array( 'title' => t('Biblio settings'), 'description' => 'Configure default behavior of the biblio module.', 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_settings'), 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', ); $items['admin/settings/biblio/ahah'] = array( 'title' => '', 'page callback' => 'biblio_admin_ahah', 'file' => 'biblio.admin.inc', 'access arguments' => array('administer biblio'), 'type' => MENU_CALLBACK, ); $items['admin/settings/biblio/basic'] = array( 'title' => t('Preferences'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10 ); $items['admin/settings/biblio/import'] = array( 'title' => t('Import'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_import_form'), 'access arguments' => array('administer biblio'), 'file' => 'biblio.import.export.inc', 'type' => MENU_LOCAL_TASK, 'weight' => 1 ); $items['admin/settings/biblio/export'] = array( 'title' => t('Export'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_export_form'), 'access arguments' => array('administer biblio'), 'file' => 'biblio.import.export.inc', 'type' => MENU_LOCAL_TASK, 'weight' => 2 ); $items['admin/settings/biblio/fields'] = array( 'title' => t('Fields'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_types_edit_form'), 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK, 'weight' => -9 ); $items['admin/settings/biblio/fields/common'] = array( 'title' => t('Common'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_types_edit_form'), 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -9 ); $items['admin/settings/biblio/fields/type'] = array( 'title' => t('Publication Types'), 'page callback' => 'biblio_admin_types_form', 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK, 'weight' => -8 ); $items['admin/settings/biblio/fields/type/edit'] = array( 'title' => '', 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_types_edit_form'), 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK ); $items['admin/settings/biblio/fields/type/delete'] = array( 'title' => '', 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_types_delete_form'), 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_CALLBACK ); $items['admin/settings/biblio/fields/type/new'] = array( 'title' => t('Add New Type'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_types_add_form'), 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK, 'weight' => -9 ); $items['admin/settings/biblio/fields/type/reset'] = array( 'title' => t('Reset all types to defaults'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_types_reset_form'), 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK ); $items['admin/settings/biblio/fields/type/hide'] = array( 'title' => '', 'page callback' => 'biblio_admin_types_hide', 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_CALLBACK ); $items['admin/settings/biblio/fields/type/show'] = array( 'title' => '', 'page callback' => 'biblio_admin_types_show', 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_CALLBACK ); $items['admin/settings/biblio/author'] = array( 'title' => t('Authors'), 'page callback' => 'biblio_author_page', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'file' => 'biblio.pages.inc', 'type' => MENU_LOCAL_TASK, 'weight' => -7 ); $items['admin/settings/biblio/author/list'] = array( 'title' => t('List'), 'page callback' => 'biblio_author_page', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'file' => 'biblio.pages.inc', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -7 ); $items['admin/settings/biblio/author/list/%/edit'] = array( 'title' => t('Edit author information'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_author_edit_form',5), 'access callback' => 'user_access', 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK, 'weight' => -6 ); $items['admin/settings/biblio/author/orphans'] = array( 'title' => t('Orphaned Authors'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_orphans_form'), 'access arguments' => array('administer biblio'), 'description' => t('Delete orphaned biblio authors.'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK, 'weight' => -6 ); $items['admin/settings/biblio/author/type'] = array( 'title' => t('Author Types'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_author_types_form', 6, 5), 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK, 'weight' => -5 ); $items['admin/settings/biblio/author/type/new'] = array( 'title' => t('Add New Author Type'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_author_types_form_new', 'new'), 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK, 'weight' => -9 ); $items['admin/settings/biblio/author/type/%/edit'] = array( 'title' => t('Add New Author Type'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_author_types_form_edit', 'edit', 6), 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK, 'weight' => -9 ); $items['admin/settings/biblio/author/type/%/delete'] = array( 'title' => t('Delete'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_author_type_delete_confirm', 5), 'access callback' => 'user_access', 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'weight' => 1, 'type' => MENU_LOCAL_TASK ); $items['admin/settings/biblio/keyword'] = array( 'title' => t('Keywords'), 'page callback' => 'biblio_keyword_page', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'file' => 'biblio.pages.inc', 'type' => MENU_LOCAL_TASK, 'weight' => -7 ); $items['admin/settings/biblio/keyword/list'] = array( 'title' => t('List'), 'page callback' => 'biblio_keyword_page', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'file' => 'biblio.pages.inc', 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -7 ); $items['admin/settings/biblio/keyword/list/%/edit'] = array( 'title' => t('Edit keyword information'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_keyword_edit_form',5), 'access callback' => 'user_access', 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK, 'weight' => -6 ); $items['admin/settings/biblio/keyword/orphans'] = array( 'title' => t('Orphaned Keywords'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_keyword_orphans_form'), 'access arguments' => array('administer biblio'), 'description' => t('Delete orphaned biblio keywords.'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK, 'weight' => -6 ); /* $items['admin/settings/biblio/authors/reset'] = array( 'title' => t('Reset all Author types to defaults'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_admin_author_type_reset_form'), 'access arguments' => array('administer biblio'), 'file' => 'biblio.admin.inc', 'type' => MENU_LOCAL_TASK ); */ $items['biblio/autocomplete'] = array( 'title' => 'Autocomplete ', 'page callback' => 'biblio_autocomplete', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK ); $items['biblio/js'] = array( 'title' => 'Javascript Contributors Form', 'page callback' => 'biblio_contributors_js', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); $items["$base/list"] = array( 'title' => t('List'), 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10 ); $items["$base/filter"] = array( 'title' => t('Filter'), 'page callback' => 'drupal_get_form', 'page arguments' => array('biblio_form_filter'), 'access callback' => 'user_access', 'access arguments' => array('show filter tab'), 'type' => MENU_LOCAL_TASK, 'file' => 'biblio.pages.inc', 'weight' => -9 ); $items["$base/filter/clear"] = array( 'title' => '', 'page callback' => 'biblio_filter_clear', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK ); $items["$base/help"] = array( 'title' => t('Help'), 'page callback' => 'biblio_help_page', 'access callback' => 'user_access', 'access arguments' => array('access content'), 'type' => MENU_CALLBACK ); $items["$base/export"] = array( 'title' => '', 'page callback' => 'biblio_export', 'access callback' => 'user_access', 'access arguments' => array('show export links'), 'file' => 'biblio.import.export.inc', 'type' => MENU_CALLBACK ); $items["$base/citekey"] = array( 'title' => '', 'page callback' => 'biblio_citekey_view', 'access arguments' => array('access content'), 'file' => 'biblio.pages.inc', 'type' => MENU_CALLBACK ); $items["$base/viewinline/%node"] = array( 'title' => '', 'page callback' => 'biblio_view_inline', 'page arguments' => array(2), 'access callback' => 'user_access', 'access arguments' => array('access content'), 'file' => 'biblio.pages.inc', 'type' => MENU_CALLBACK ); $items["$base/recent/rss.xml"] = array( 'title' => 'RSS feed', 'page callback' => 'biblio_recent_feed', 'access callback' => 'biblio_access', 'access arguments' => array('rss'), 'type' => MENU_CALLBACK ); return $items; } function biblio_filter_clear() { $_SESSION['biblio_filter'] = array(); $base = variable_get('biblio_base', 'biblio'); if (isset($_GET['sort'])) { $options .= "sort=". $_GET['sort']; } if (isset($_GET['order'])) { $options .= $options['query'] ? "&" : ""; $options .= "order=". $_GET['order']; } drupal_goto($base, $options); } function biblio_nodeapi(& $node, $op, $teaser, $page) { if ($node->type == 'biblio') { switch ($op) { case 'delete revision' : db_query('DELETE FROM {biblio} WHERE vid = %d', $node->vid); db_query('DELETE FROM {biblio_contributor} WHERE nid = %d AND vid = %d', array($node->nid, $node->vid)); db_query('DELETE FROM {biblio_keyword} WHERE nid = %d AND vid = %d', array($node->nid, $node->vid)); break; /* case 'presave': if ($node->type == 'biblio') { // $node->body = ''; // $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 // $node->body = theme('biblio_tabular', $node_clone, $base, $teaser); $style = variable_get('biblio_style', 'classic'); $node->teaser = theme('biblio_style', $node_clone, $base, $style); } break; */ case 'insert': if (variable_get('biblio_index', 0)) { _node_index_node($node); search_update_totals(); } break; case 'update': if (variable_get('biblio_index', 0)) { // _node_index_node performs a node_load without resetting the node_load cache, // so it would index the old version. We reset the cache here. // Don't assign node_load to $node because node_load resets e.g. the menus mlid etc. $mynode = node_load($node->nid, NULL, TRUE); _node_index_node($mynode); search_update_totals(); } break; } } } function biblio_form_alter(& $form, $form_state, $form_id) { 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 if (!isset($form_state['values']['biblio_type']) && empty($form_state['post']['biblio_type']) && empty($form_state['submitted']) && empty($form['vid']['#value'])) { foreach (element_children($form) as $form_element) { if ($form[$form_element]['#type'] == 'fieldset' || $form_element == 'buttons' || $form_element == 'taxonomy') { $form[$form_element] = NULL; } } } else { if (isset($form['menu']['#weight']) && $form['menu']['#weight'] < 20) $form['menu']['#weight'] = 20; if (isset($form['book']['#weight']) && $form['book']['#weight'] < 20) $form['book']['#weight'] = 20; if (isset($form['taxonomy']['#title'])) { $form['taxonomy']['#title'] = t('Keyword and Collection Settings (Taxonomy)'); } } } return $form; } /** * Implementation of hook_form(). * * Create the form for collecting the information * specific to this node type. This hook requires us to return some HTML * that will be later placed inside the form. */ function biblio_form($node, $form_state) { if (isset($form_state['post']['biblio_type'])) $tid = $form_state['post']['biblio_type']; else if (isset($form_state['values']['biblio_type'])) $tid = $form_state['values']['biblio_type']; else $tid = $node->biblio_type; $show_fields = !empty($tid); $form['#validate'][] = 'biblio_form_validate'; $form['#cache'] = TRUE; /* publication type */ $param['options'] = array( "enctype" => "multipart/form-data" ); $result = db_query('SELECT t.* FROM {biblio_types} as t WHERE tid > -2 AND visible = 1'); while ($option = db_fetch_object($result)) { $options["$option->tid"] = $option->name; } $form['biblio_type'] = array( '#type' => 'select', '#title' => t('Publication Type'), '#default_value' => $tid, '#options' => $options, '#description' => NULL, '#weight' => -15, '#attributes' => array( 'onchange' => 'document.getElementById(\'node-form\').submit()' ), '#multiple' => FALSE, '#required' => TRUE ); if ($show_fields) { $form['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#required' => TRUE, '#default_value' => $node->title, '#size' => 60, '#maxlength' => 255, '#weight' => -4 ); // Build the field array used to make the form $result = db_query("SELECT * FROM {biblio_fields} b INNER JOIN {biblio_field_type} bt ON b.fid = bt.fid INNER JOIN {biblio_field_type_data} btd ON btd.ftdid=bt.ftdid WHERE bt.tid=%d ORDER BY bt.weight ASC", $tid); while ($row = db_fetch_array($result)) { $fields[$row['name']] = $row; } $form['other_fields'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Other Biblio Fields'), '#description' => '', '#weight' => 0 ); $max_visible_weight = -5; foreach ($fields as $key => $fld) { $main_area = $fld['common'] || $fld['visible']; if ($fld['type'] == 'contrib_widget') { $auth_category = $fld['fid']; if ($main_area) $form += _biblio_contributor_widget($node, $fld, $auth_category, $tid); else $form['other_fields'] += _biblio_contributor_widget($node, $fld, $auth_category, $tid, TRUE); } else { if ($key == 'biblio_keywords' ) { $sep = variable_get('biblio_keyword_sep', ','); $keywords = ''; if (!empty($node->$key)) { foreach ($node->$key as $keyword) { $keywords .= (empty($keywords)?$keyword->word:"$sep " . $keyword->word); } } $node->$key = $keywords; $fld['hint'] = t('Separate keywords using the " @sep " character', array('@sep' => $sep)); } $field_widget = array( '#default_value' => $node->$key, '#type' => $fld['type'], '#title' => $fld['title'], '#size' => $fld['size'], '#required' => $fld['required'], '#maxlength' => $fld['maxsize'], '#weight' => $fld['weight'] / 10, '#autocomplete_path' => ($fld['autocomplete']) ? 'biblio/autocomplete/'. $fld['name'] : '', '#description' => $fld['hint'] ); if ($main_area && $fld['type'] == 'textarea') { /* wrap all textarea fields in collapsed field sets to save space on the page */ $field_widget = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => $fld['title'], '#description' => '', '#weight' => $fld['weight'] / 10, $key => $field_widget ); $key = $fld['name'] .'_field'; } // embed field directly or in "Other Fields" fieldset if ($main_area) { $form[$key] = $field_widget; $max_visible_weight = max($max_visible_weight, $field_widget['#weight']); } else { $form['other_fields'][$key] = $field_widget; } } } // place 'Other biblio fields' directly below visible fields $form['other_fields']['#weight'] = $max_visible_weight + 0.1; $form['body_field'] = array( '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => TRUE, '#title' => t('Full Text'), '#description' => '', '#weight' => $max_visible_weight + 0.2 ); $form['body_field']['body'] = array( '#type' => 'textarea', '#title' => t('Full Text'), '#default_value' => $node->body, '#rows' => 10, '#required' => FALSE, '#description' => t('You may enter a full text or HTML version of the publication here.'), '#weight' => 19 ); // embed filter form in "Full Text" fieldset, because it applies to the full text only $form['body_field']['format'] = filter_form($node->format, 20); } return $form; } /** * @param $node * @param $fld * @param $auth_category * @param $biblio_type * @param $other_fields * @return contributor fieldset form */ function _biblio_contributor_widget($node, $fld, $auth_category, $biblio_type, $other_fieldset = FALSE) { $fldname = $fld['name']; $type = str_replace('_', '-', $fldname); $contributors = (array) $node->biblio_contributors[$auth_category]; $contributor_count = max(4, count($contributors)); $ctypes = _biblio_get_auth_types($auth_category, $biblio_type); // if no author types are available skip this widget if (!isset($ctypes)) return array(); $ctypes = db_query('SELECT * FROM {biblio_contributor_type_data} WHERE auth_type IN ('. implode(',', $ctypes) .')'); while ($ctype = db_fetch_object($ctypes)) { $options[$ctype->auth_type] = $ctype->title; } // Add a wrapper for the choices and more button. $wrapper = array( '#tree' => TRUE, '#type' => 'fieldset', '#collapsible' => TRUE, '#collapsed' => !$fld['required'] && (count($contributors)==0), '#title' => $fld['title'], '#weight' => $fld['weight'] / 10, '#description' => t('Enter a single name per line using a format such as "Smith, John K" or "John K Smith" or "J.K. Smith"'), '#prefix' => '<bib>citekey</bib> or [bib]citekey[/bib]
. This will be replaced with a running number (the publication reference) and the publication referenced by the citekey within the <bib> tags will be printed at the bottom of the page (the reference).');
}
else {
return t('Use <bib>citekey</bib> or [bib]citekey[/bib] to insert automatically numbered references.');
}
break;
}
}
/**
* Implementation of hook_filter().
*
* The bulk of filtering work is done here. This hook is quite complicated, so
* we'll discuss each operation it defines.
*/
function biblio_filter($op, $delta = 0, $format = -1, $text = '') {
// The "list" operation provides the module an opportunity to declare both how
// many filters it defines and a human-readable name for each filter. Note that
// the returned name should be passed through t() for translation.
if ($op == 'list') {
return array(
0 => t('Biblio module references <bib> or [bib]'),
);
}
if ($op == 'no cache') {
return TRUE;
}
// All operations besides "list" provide a $delta argument so we know which
// filter they refer to. We'll switch on that argument now so that we can
// discuss each filter in turn.
switch ($delta) {
// First is the html footnotes filter
case 0 :
switch ($op) {
// This description is shown in the administrative interface, unlike the
// filter tips which are shown in the content editing interface.
case 'description' :
return t('Use <bib>citekey</bib> or [bib]citebkey[/bib]to insert automatically numbered references.');
// We don't need the "prepare" operation for this filter, but it's required
// to at least return the input text as-is.
//TODO: May need to escape