".t('By default, the ').l('',$base).
t(' 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.')."
";
$text .= "
".t('Filtering Search Results:')."
";
$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 .= "
";
$text .= t('It is possible to create complex filters by returning to the ');
$text .= "".t('"Filter"')."";
$text .= t(' 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 ')."".
t('"Clear All Filters"')."".
t('link at the top of the result page, or on the ')."".
t('"Filter"')."".
t(' tab they can be removed one at a time using the ')."".t('"Undo"')."".
t(' button, or you can remove them all using the ')."".t('"Clear All"')."".
t(' 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('Exporting Search Results:')."
";
$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($section) {
switch ($section) {
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('Maintains list of 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 == '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 == 'export') {
// Only users with permission to do so may export entries from file.
return user_access('show export links');
}
// 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('create biblio', 'edit all biblio entries', 'edit own biblio entries', 'import from file','show export 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;
}
function theme_biblio_coin_button($element) {
// Make sure not to overwrite classes.
return '';
}
/**
* Implementation of hook_settings().
*/
function biblio_settings() {
$version = '$Revision: 1.36.2.120 $ $Date: 2007-09-20 00:30:30 $';
$version = str_replace('$','',$version);
$form['biblio_rev'] = array(
'#value' => $version,
);
$form['biblio_base'] = array(
'#type' => 'textfield',
'#title' => t('Base URL'),
'#size' => 20,
'#default_value' => variable_get('biblio_base', 'biblio'),
'#description' => t('This sets the base URL used to access the biblio module (e.g. /biblio ).'),
);
$form['biblio_rowsperpage'] = array(
'#type' => 'textfield',
'#title' => t('Number of results per page.'),
'#default_value' => variable_get('biblio_rowsperpage', 25),
'#size' => 6,
'#maxlength' => 6,
'#description' => t('This sets the number of results that will be displayed per page.'),
);
$form['biblio_view_only_own'] = array(
'#type' => 'checkbox',
'#title' => t('Restrict users such that they can only view their own biblio entries'),
'#return_value' => 1,
'#default_value' => variable_get('biblio_view_only_own', 0),
'#description' => t('This option restricts the users capability to view biblio entries. They will only be able to see the entries which they have created and own.') );
$form['block'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Block settings'),
'#description' => t(''),
);
$form['block']['biblio_block_title'] = array(
'#type' => 'textfield',
'#title' => t('Title for the "New Publications" block'),
'#default_value' => variable_get('biblio_block_title', 'New Publications'),
'#size' => 40,
'#maxlength' => 40,
'#description' => t(''),
);
$form['block']['biblio_rowsperblock'] = array(
'#type' => 'textfield',
'#title' => t('Number of results in the "New Publications" block'),
'#default_value' => variable_get('biblio_rowsperblock', 4),
'#size' => 2,
'#maxlength' => 2,
'#description' => t('This sets the number of results that will be displayed in the "New Publications" block.'),
);
$form['block']['biblio_block_order'] = array(
'#type' => 'radios',
'#title' => t('Order by'),
'#default_value' => variable_get('biblio_block_order', 'n.created'),
'#options' => array('n.created'=>t('Date Created'), 'b.biblio_year'=>t('Year Published')),
);
$form['footnotes'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Footnotes'),
'#description' => t('You can integrate with the '. l('footnotes',url("http://www.drupal.org/project/footnotes",NULL,NULL,TRUE)).' module here.'),
);
if (!module_exists('footnotes')) {
$additional_text = '
';
$disabled = FALSE;
}
$form['footnotes']['biblio_footnotes_integration'] = array(
'#type' => 'checkbox',
'#title' => t('Integration with the footnotes module') . $additional_text,
'#disabled' => $disabled,
'#return_value' => 1,
'#default_value' => variable_get('biblio_footnotes_integration', 0),
'#description' => t('This will convert <bib> tags into <fn> tags. This will cause intermingled <bib> and <fn> tags to be sequentially numbered. For this to work, you must put the <bib> filter ahead of the <fn> filter in the filter chain. If this option is not set, <bib> and <fn> tags will be handled separately.'),
);
$form['keywords'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Keywords'),
'#description' => t('' ),
);
$form['keywords']['biblio_keyword_sep'] = array(
'#type' => 'textfield',
'#title' => t('Keyword separator'),
'#size' => 2,
'#default_value' => variable_get('biblio_keyword_sep', ','),
'#description' => t('Enter the character which will be used to separate multiple keywords in the keyword field'),
);
$form['openurl'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('OpenURL'),
'#description' => t('You can set an openurl link here'),
);
$form['openurl']['biblio_baseopenurl'] = array(
'#type' => 'textfield',
'#title' => t('OpenURL Base URL'),
'#size' => 95,
'#default_value' => variable_get('biblio_baseopenurl', ''),
'#description' => t('This sets your institution\'s base OpenURL gateway, which is used to generate OpenURL links. To implement a "Universal" OpenURL system, try using OCLC\'s OpenURL Resolver Registry gateway: http://worldcatlibraries.org/registry/gateway'),
);
$form['openurl']['biblio_openurlimage'] = array(
'#type' => 'textfield',
'#title' => t('OpenURL Image'),
'#size' => 95,
'#default_value' => variable_get('biblio_openurlimage', ''),
'#description' => t('Enter a path to your image here, this image will be used as button which when clicked will find the entry via the OpenURL link'),
);
$form['sort'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Sorting'),
'#description' => t('You can set the default sorting and ordering for the /biblio page here.'),
);
$form['sort']['biblio_sort'] = array(
'#type' => 'radios',
'#title' => t('Sort by'),
'#default_value' => variable_get('biblio_sort', 'year'),
'#options' => array('author'=>t('Author'), 'title'=>t('Title'),'type'=>t('Type'),'year'=>t('Year')),
);
$form['sort']['biblio_sort_tabs'] = array(
'#type' => 'checkboxes',
'#title' => t('Show sort links'),
'#default_value' => variable_get('biblio_sort_tabs', array('author','title','type','year')),
'#options' => array('author'=>t('Author'), 'title'=>t('Title'),'type'=>t('Type'),'year'=>t('Year')),
'#description' => t('You turn the sorting links at the top of the /biblio page here.'),
);
$form['sort']['biblio_order'] = array(
'#type' => 'radios',
'#title' => t('Order'),
'#default_value' => variable_get('biblio_order', 'DESC'),
'#options' => array('DESC'=>t('Descending'), 'ASC'=>t('Ascending')),
);
$form['style'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Styling'),
'#description' => t('You can set the default style for the /biblio page here.'),
);
$form['style']['biblio_normalize'] = array(
'#type' => 'checkbox',
'#title' => t('Normalize author names when displaying biblio records'),
'#return_value' => 1,
'#default_value' => variable_get('biblio_normalize', 0),
'#description' => t('Tries (doesn\'t always work) to reformat author names so that they are displayed in the format "Lastname, Initials" e.g. Smith, J.S. (Note: This setting does not modify the entry in the database, it only reformats it\'s presentation. This option can be turned off at any time to diplay the oringal format.)'), );
$form['style']['biblio_links_target_new_window'] = array(
'#type' => 'checkbox',
'#title' => t('Links open in new browser'),
'#return_value' => 1,
'#default_value' => variable_get('biblio_links_target_new_window', 0),
'#description' => t('This causes related URLs to open in a new browser window') );
$form['style']['biblio_node_layout'] = array(
'#type' => 'radios',
'#title' => t('Node Layout'),
'#default_value' => variable_get('biblio_node_layout', 'orig'),
'#options' => array('orig'=>t('Original'), 'ft'=>t('Only Fulltext if available'),'tabular'=>t('Tabular')),
'#description' => t('This alters the layout of the "node" (full) view.'),
);
$form['style']['biblio_annotations'] = array(
'#type' => 'select',
'#title' => t('Annotations'),
'#default_value' => variable_get('biblio_annotations', 'none'),
'#options' => array('none'=>t('none'),'biblio_notes'=>t('notes'),'biblio_custom1'=>t('custom1'),'biblio_custom2'=>t('custom2'),'biblio_custom3'=>t('custom3'),'biblio_custom4'=>t('custom4'),'biblio_custom5'=>t('custom5'),'biblio_custom6'=>t('custom6'),'biblio_custom7'=>t('custom7')),
'#description' => t('Select a field from which an annotation will be displayed below biblo entry in "short" listings'),
'#multiple' => FALSE,
'#size' => 0
);
$form['style']['biblio_style'] = array(
'#type' => 'radios',
'#title' => t('Style'),
'#default_value' => variable_get('biblio_style', 'classic'),
'#options' => _biblio_get_styles(),
'#description' => t('This alters the layout of the "list" (short) view.'),
);
$form['syndication'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Syndication'),
'#description' => t('You can set the RSS defaults here.'),
);
$form['syndication']['biblio_rss'] = array(
'#type' => 'checkbox',
'#title' => t('Allow RSS feeds of new biblio entries'),
'#return_value' => 1,
'#default_value' => variable_get('biblio_rss', 0),
'#description' => t('This will create an rss feed of the 10 most recent biblio entries. It will be available at /biblio/rss.xml'),
);
$form['syndication']['biblio_rss_number_of_entries'] = array(
'#type' => 'textfield',
'#title' => t('Number of items in the RSS feed.'),
'#default_value' => variable_get('biblio_rss_number_of_entries', 10),
'#size' => 6,
'#maxlength' => 6,
'#description' => t('Limits the number of items in the /biblio/rss.xml feed to this number.'),
);
$form['taxo'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Taxonomy'),
'#description' => t('You can set the Taxonomy defaults here.'),
);
$form['taxo']['biblio_keyword_freetagging'] = array(
'#type' => 'checkbox',
'#title' => t('Use keywords from biblio entries as taxonomy "free tags"'),
'#return_value' => 1,
'#default_value' => variable_get('biblio_keyword_freetagging', 0),
'#description' => t('This option allows user to add keywords (free tags) to describe their documents. These keywords will be registered as taxonomy.'),
);
$vocabularies = module_invoke('taxonomy', 'get_vocabularies');
// ... and print a form to select the terms in each of them
$choice = new stdClass();
$choice->option = array(0 => '<'. t('none') .'>');
$options[0] = $choice;
if (count($vocabularies)){
foreach ($vocabularies as $voc) {
$choice = new stdClass();
$choice->option = array($voc->vid => $voc->name);
$options[] = $choice;
}
$form['taxo']['biblio_freetagging_vocab'] = array(
'#type' => 'select',
'#title' => t('Vocabulary'),
'#default_value' => variable_get('biblio_freetagging_vocab', 0),
'#options' => $options,
'#description' => t('Select vocabulary (category) to use for free tags.'),
'#multiple' => FALSE,
'#disabled' => (!variable_get('biblio_keyword_freetagging', 0)),
'#size' => $multiple ? min(9, count($options)) : 0,
'#weight' => 15,
);
}
return system_settings_form($form);
}
/* This function parses the module directory for 'style' files, loads them and
* calls the info fuction to get some basic information like the short and long
* names of the style
*/
function _biblio_get_styles(){
$styles = array();
$dir = drupal_get_path('module', 'biblio');
$files = array();
if ($dh = opendir($dir)) {
while (($files[] = readdir($dh)) !== false) {
}
closedir($dh);
foreach ($files as $file){
if (strstr ( $file, 'biblio_style_')){ //find the style files
include_once $dir."/".$file;
if (function_exists(basename($file, ".inc").'_info')){
$styles = array_merge($styles, call_user_func(basename($file, ".inc").'_info')); //build and array of the short and long names
}
}
}
}
return($styles);
}
/**
* Implementation of hook_menu().
*
* Here we define some built in links for the biblio module, links exposed are:
* /node/add/biblio => to add a single entry
* /biblio => lists all entries in the biblio database
* /biblio/list => default local task for /biblio
* /biblio/filter => local task which allows users to add filters to their query
* /biblio/filter/clear => used internally to remove all filters
* /biblio/help => displays a help page
* /biblio/export/endnote => used to export information in Endnote Tagged format
* /biblio/import/form => presents a form to allow the user to upload a file to import
*
*
*/
function biblio_menu($may_cache) {
$items = array();
if ($may_cache) {
$items[] = array('path' => 'node/add/biblio', 'title' => t('bibliography'),
'access' => user_access('create biblio'));
// The next two "LOCAL TASKS" are for the admin/settings/biblio page
$items[] = array('path' => 'admin/settings/biblio', 'title' => t('Biblio settings'),
'description' => t('Configure default behavior of the biblio module.'),
'callback' => 'drupal_get_form', 'callback arguments' => array('biblio_settings'));
$items[] = array('path' => 'admin/settings/biblio/basic', 'title' => t('Preferences'),
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
$items[] = array('path' => 'admin/settings/biblio/import', 'title' => t('File Import'),
'callback' => 'drupal_get_form', 'callback arguments' => array('biblio_form_import'),
'type' => MENU_LOCAL_TASK, 'weight' => -7);
$items[] = array('path' => 'admin/settings/biblio/types', 'title' => t('Type Customization'),
'callback' => 'biblio_form_types',
'type' => MENU_LOCAL_TASK, 'weight' => -8);
$items[] = array('path' => 'admin/settings/biblio/defaults', 'title' => t('Field Defaults'),
'callback' => 'drupal_get_form', 'callback arguments' => array('biblio_form_types_edit'),
'type' => MENU_LOCAL_TASK , 'weight' => -9);
$items[] = array('path' => 'admin/settings/biblio/types/add', 'title' => t(''),
'callback' => 'drupal_get_form', 'callback arguments' => array('biblio_form_types_add'),
'type' => MENU_CALLBACK );
$items[] = array('path' => 'admin/settings/biblio/types/edit', 'title' => t(''),
'callback' => 'drupal_get_form', 'callback arguments' => array('biblio_form_types_edit'),
'type' => MENU_CALLBACK );
$items[] = array('path' => 'admin/settings/biblio/types/delete', 'title' => t(''),
'callback' => 'drupal_get_form', 'callback arguments' => array('biblio_form_types_delete'),
'type' => MENU_CALLBACK );
$items[] = array('path' => 'admin/settings/biblio/types/new', 'title' => t('Add New Type'),
'callback' => 'drupal_get_form', 'callback arguments' => array('biblio_form_types_add'),
'type' => MENU_LOCAL_TASK, 'weight' => -9);
$items[] = array('path' => 'admin/settings/biblio/types/reset', 'title' => t('Reset all types to defaults '),
'callback' => 'drupal_get_form', 'callback arguments' => array('biblio_types_reset'),
'type' => MENU_LOCAL_TASK );
$items[] = array('path' => 'admin/settings/biblio/types/hide', 'title' => t(''),
'callback' => 'biblio_types_hide',
'type' => MENU_CALLBACK );
$items[] = array('path' => 'admin/settings/biblio/types/show', 'title' => t(''),
'callback' => 'biblio_types_show',
'type' => MENU_CALLBACK );
$items[] = array('path' => 'biblio/autocomplete',
'title' => t('Autocomplete '),
'callback' => 'biblio_autocomplete',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
}
$base = variable_get('biblio_base', 'biblio');
$items[] = array('path' => $base, 'title' => t(''),
'callback' => 'biblio_db_search',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
$items[] = array('path' => "$base/list", 'title' => t('List'),
'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => -10);
$items[] = array('path' => "$base/filter", 'title' => t('Filter'),
'callback' => 'drupal_get_form', 'callback arguments' => array('biblio_form_filter'),
'access' => user_access('show filter tab'),
'type' => MENU_LOCAL_TASK, 'weight' => -9);
$items[] = array('path' => "$base/filter/clear", 'title' => t(''),
'callback' => 'biblio_filter_clear',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
$items[] = array('path' => "$base/help", 'title' => t('Help'),
'callback' => 'biblio_help_page',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
$items[] = array('path' => "$base/import/form", 'title' => t(''),
'callback' => 'drupal_get_form', 'callback arguments' => array('biblio_form_import'),
'access' => user_access('import from file'),
'type' => MENU_CALLBACK);
$items[] = array('path' => "$base/export", 'title' => t(''),
'callback' => '_biblio_export',
'access' => user_access('show export links'),
'type' => MENU_CALLBACK);
$items[] = array('path' => "$base/type/add", 'title' => t(''),
'callback' => 'biblio_type_add',
'type' => MENU_CALLBACK);
$items[] = array('path' => "$base/type/remove", 'title' => t(''),
'callback' => 'biblio_type_remove',
'type' => MENU_CALLBACK);
$items[] = array('path' => "$base/citekey", 'title' => t(''),
'callback' => 'biblio_citekey_view',
'type' => MENU_CALLBACK);
if (arg(1) == 'viewinline' && is_numeric(arg(2))) {
$node = node_load(arg(2));
if ($node->nid) {
$items[] = array('path' => "$base/viewinline/". arg(2), 'title' => t(''),
'callback' => 'biblio_view_inline',
'callback arguments' => array($node),
'access' => node_access('view', $node),
'type' => MENU_CALLBACK);
}
}
if (variable_get('biblio_rss', 0)){
$items[] = array('path' => "$base/rss.xml", 'title' => t('RSS feed'),
'callback' => 'biblio_feed',
'access' => user_access('access content'),
'type' => MENU_CALLBACK);
}
return $items;
}
function biblio_form_types_add(){
$form['type_name'] = array('#type'=>'textfield',
'#title'=>t('Type Name'),
'#size'=>20,
'#weight'=>1,
'#required'=>true,
'#maxlength'=>64);
$form['type_description'] = array('#type'=>'textfield',
'#title'=>t('Description'),
'#size'=>60,
'#weight'=>2,
'#maxlength'=>255);
$form['type_button'] = array('#type' => 'submit',
'#value' => t('Create New Type'),
'#weight'=>3);
return $form;
}
function biblio_form_types_add_submit($form_id, $edit){
$tid = variable_get('biblio_max_user_tid', '999') + 1;
$query = "INSERT INTO {biblio_types} (`name`,`description`,`tid`) VALUES ('%s', '%s','%d')";
db_query($query,$edit['type_name'],$edit['type_description'],$tid);
variable_set('biblio_max_user_tid',$tid);
drupal_goto('admin/settings/biblio/types');
}
function biblio_types_hide(){
$args = func_get_args();
if ($args[0] > 0 && is_numeric($args[0]) ) {
$result = db_query('UPDATE {biblio_types} SET visible = 0 WHERE tid = %d ', $args[0]);
}
drupal_goto('admin/settings/biblio/types');
}
function biblio_types_show(){
$args = func_get_args();
if ($args[0] > 0 && is_numeric($args[0]) ) {
$result = db_query('UPDATE {biblio_types} SET visible = 1 WHERE tid = %d ', $args[0]);
}
drupal_goto('admin/settings/biblio/types');
}
function biblio_form_types_delete(){
$args = func_get_args();
if ($args[0] > 0 && is_numeric($args[0]) ) {
$result = db_query('SELECT t.* FROM {biblio_types} as t WHERE t.tid = %d ', $args[0]);
$row = db_fetch_array($result);
$result = db_query('SELECT b.* FROM {biblio} as b WHERE b.biblio_type = %d',$row['tid']);
if ($num_rows = db_num_rows($result)){
$existing_msg = 'There are '.$num_rows.' biblio entries of this type, you should change the type of these entries before proceeding otherwise they will be deleted';
}
$form['tid'] = array('#type' => 'value', '#value' => $row['tid']);
$output = confirm_form( $form,
t('Are you sure you want to delete the custom biblio type: %title ? ', array('%title'=>$row['name'])).$existing_msg,
$_GET['destination'] ? $_GET['destination'] : 'admin/settings/biblio/types', t('This action cannot be undone.'),
t('Delete'), t('Cancel') );
return $output;
}else{
drupal_goto('admin/settings/biblio/types');
}
}
function biblio_form_types_delete_submit($form_id, $edit){
if ($form_id = "biblio_form_types_delete" ){
db_query('DELETE FROM {biblio_types} WHERE tid = %d', $edit['tid']);
}
drupal_goto('admin/settings/biblio/types');
}
function biblio_form_types(){
$result = db_query('SELECT t.* FROM {biblio_types as t WHERE t.tid > 0}');
//$rows[] = array('',t('Fields Common To All Types'),l('edit', 'admin/settings/biblio/types/edit'),'');
while ($row = db_fetch_object($result)) {
if ($row->tid < 999){
$rows[] = array($row->tid,$row->name,($row->visible)?l(t('edit'), 'admin/settings/biblio/types/edit/'. $row->tid):'',($row->visible)?l(t('hide'), 'admin/settings/biblio/types/hide/'. $row->tid):l(t('show'), 'admin/settings/biblio/types/show/'. $row->tid));
}else{
$rows[] = array($row->tid,$row->name,l(t('edit'), 'admin/settings/biblio/types/edit/'. $row->tid),l(t('delete'), 'admin/settings/biblio/types/delete/'. $row->tid));
}
}
$header =array(t('Type Id'),t('Type Name'), array('data' => t('Operations'), 'colspan' => '2'));
$output = theme('table',$header,$rows);
$output .= '
[ '.l(t('Add New Type'),'admin/settings/biblio/types/add').' ]';
$output .= ' [ '.l(t('Reset all types to defaults'),'admin/settings/biblio/types/reset').' ]';
return $output;
}
function biblio_types_reset(){
$form['reset'] = array('#type' => 'value', '#value' => 'reset');
$output = confirm_form( $form,
t('Are you sure you want to reset ALL the field definitions to the defaults? '),
$_GET['destination'] ? $_GET['destination'] : 'admin/settings/biblio/types',
t('This action will reset any and all field customizations to the defaults, and cannot be undone!'),
t('Reset'), t('Cancel') );
return $output;
}
function biblio_types_reset_submit($form_id, $edit){
require_once( drupal_get_path('module', 'biblio') . "/biblio.install");
biblio_reset_types();
drupal_goto("admin/settings/biblio/types");
}
function biblio_show_node($node,$base){
$tid=$node->biblio_type;
$result = db_query('SELECT * FROM {biblio_fields} as b ORDER BY b.weight ASC');
while ($row = db_fetch_array($result)){
if ($row['common']){
$fields[$row['fid']] = $row;
}
}
$result = db_query('SELECT t.* FROM {biblio_types} as t WHERE t.tid = %d',$tid);
$row = db_fetch_array($result);
$type_name=$row['name'];
$rows[] =array(array('data' => ''.t('Publication Type').'','align'=>'right'),
array('data' => $type_name));
$result = db_query('SELECT d.*, f.name FROM {biblio_type_details} as d INNER JOIN {biblio_fields} as f on d.fid=f.fid where d.tid=%d ORDER BY d.weight ASC', $tid);
while ($row = db_fetch_array($result)){
$fields[$row['fid']] = (isset($fields[$row['fid']])) ? array_merge($fields[$row['fid']],$row) : $row;
}
uasort($fields, "_biblio_form_sort"); // resort the fields since the weight may have changed
if($node->biblio_authors){
if (variable_get('biblio_normalize', 0)) {
$node->biblio_authors = _biblio_parse_authors($node->biblio_authors);
}
$node->biblio_authors = _biblio_author_links($node->biblio_authors,$base);
}
if($node->biblio_keywords){
$node->biblio_keywords = _biblio_keyword_links($node->biblio_keywords,$base);
}
if($node->biblio_url){
$node->biblio_url = l(t("Click Here"),$node->biblio_url,$attrib);
}
foreach ($fields as $key => $row){
if (!empty($node->$row['name'])){
switch($key){
case 1:
case 23:
case 25:
// check_plain is not need on these since they have gone through
// the l() function which does a check_plain
$data = $node->$row['name'];
break;
case 44:
$row['title']="";
$data = "";
break;
default:
$data = check_markup($node->$row['name'],FILTER_HTML_ESCAPE,FALSE);
}
$rows[] = array(array('data' => ''.$row['title'].'','align'=>'right','valign'=>'top','width'=>'20%'),
array('data' => $data));
}
}
if ( strlen(trim($node->body)) && user_access('view full text') ) {
$rows[] = array(array('data' => ''.t('Full Text').'','align'=>'right','valign'=>'center','width'=>'20%'),
array('data' => check_markup($node->body,FILTER_HTML_ESCAPE,FALSE))
);
}
if ( biblio_access('export',$node)) {
$rows[] = array(array('data' => ''.t('Export').'','align'=>'right','valign'=>'center','width'=>'20%'),
array('data' => l(t("Tagged"),"$base/export/tagged/$nid").' '.
l(t("XML"),"$base/export/xml/$nid").' '.
l(t("BibTex"),"$base/export/bib/$nid")
));
}
$output = '
';
return $output;
}
function biblio_form_types_edit(){
if ($arg_list = func_get_args()){// show an existing type
$tid = $arg_list[0];
}
// first get all of the field info
$result = db_query('SELECT * FROM {biblio_fields} as b ORDER BY b.weight ASC');
while ($row = db_fetch_array($result)){
if($tid){
if ($row['common']){
$fields[$row['fid']] = $row;
}else{
$other_fields[$row['fid']] = $row;
}
}else{
$fields[$row['fid']] = $row;
}
}
$form['configured_flds']= array('#tree'=>1);
$form['cust'] = array('#tree'=>1);
if ($tid){// show an existing type
$result = db_query('SELECT t.* FROM {biblio_types} as t WHERE t.tid = %d',$tid);
$row = db_fetch_array($result);
$form['type_name'] =array('#type'=>'value','#title'=>'tid','#value'=>$row['name']);
// now get any type specific customizations
$result = db_query('SELECT d.*, f.name FROM {biblio_type_details} as d INNER JOIN {biblio_fields} as f on d.fid=f.fid where d.tid=%d ORDER BY d.weight ASC', $tid);
while ($row = db_fetch_array($result)){
$type_fields[$row['fid']] = $row;
$form['cust'][$row['fid']] =array('#type'=>'value','#value'=>$row['fid']);
unset($other_fields[$row['fid']]);
}
if(count($type_fields)){
// now merge the customizations with the main field array
foreach($type_fields as $key=>$value){
$fields[$key] = (isset($fields[$key])) ? array_merge($fields[$key],$value) : $value;
}
}
$form['tid'] =array('#type'=>'value','#value'=>$tid);
}
uasort($fields, "_biblio_form_sort"); // resort the fields since the weight may have changed
$vis_comm = $tid?'visible':'common';
if (!$tid) $options["$vis_comm"] = '';
$options['required'] = '';
if (!$tid) $options['autocomplete'] = '';
foreach($fields as $key=>$fld){
if ($fld['common']) $def_values[$fld['name']][] = 'common';
if ($fld['required']) $def_values[$fld['name']][] = 'required';
if ($fld['autocomplete']) $def_values[$fld['name']][] = 'autocomplete';
$form['configured_flds'][$key]['name'] = array('#type'=>'markup', '#value'=>$fld['name'],'#weight'=>$fld['weight']);
$form['configured_flds'][$key]['title'] = array('#type'=>'textfield','#default_value' => $fld['title'],'#size'=>15,'#weight'=>$fld['weight']);
$form['configured_flds'][$key]['weight'] = array('#type'=>'textfield','#default_value' => $fld['weight'],'#size'=>2,'#weight'=>$fld['weight']);
$form['configured_flds'][$key]['hint'] = array('#type'=>'textfield','#default_value' => $fld['hint'],'#size'=>10,'#weight'=>$fld['weight']);
//if (!$tid){
// $form['configured_flds'][$key]['hint']['#type']= 'markup';
// $form['configured_flds'][$key]['title']['#type']= 'markup';
//}
$form['configured_flds'][$key]['checkboxes'] = array('#type'=>'checkboxes','#options'=>$options,'#default_value' =>$def_values[$fld['name']],'#weight'=>$fld['weight']);
}
if($tid){
foreach($other_fields as $key=>$fld){
$form['avail_flds'][$key]['name'] = array('#type'=>'markup', '#value'=>$fld['name'],'#weight'=>$fld['weight']);
$form['avail_flds'][$key]['title'] = array('#type'=>'markup','#value' => $fld['title'],'#weight'=>$fld['weight']);
$form['avail_flds'][$key]['size'] = array('#type'=>'markup','#value' => $fld['maxsize'],'#weight'=>$fld['weight']);
}
}
$form['submit'] = array('#type' => 'submit', '#value' => t('Save'));
return $form;
}
function theme_biblio_form_types_edit($form){
$base = variable_get('biblio_base', 'biblio');
$tid = (!empty($form['tid']['#value'])) ? $form['tid']['#value'] : FALSE;
drupal_set_title($form['type_name']?$form['type_name']['#value']:"Default");
// build the table with all the fields if no $tid is given, or only the common
// and customized fields if $tid is given
$conf_table = array();
foreach(element_children($form['configured_flds']) as $fld){
$conf_row = array();
$conf_row[] = array('data' => drupal_render($form['configured_flds'][$fld]['name']));
$conf_row[] = array('data' => drupal_render($form['configured_flds'][$fld]['title']),'align' => 'center');
$conf_row[] = array('data' => drupal_render($form['configured_flds'][$fld]['hint']),'align' => 'center');
foreach (element_children($form['configured_flds'][$fld]['checkboxes']) as $oid) {
if (is_array($form['configured_flds'][$fld]['checkboxes'])) {
$conf_row[] = array('data' => drupal_render($form['configured_flds'][$fld]['checkboxes'][$oid]), 'align' => 'center', 'title' => t('!oid',array('!oid'=>$oid)));
}
}
$conf_row[] = array('data' => drupal_render($form['configured_flds'][$fld]['weight']),'align' => 'center');
if ($tid){
if($form['cust'][$fld]) {
$conf_row[] = array('data' => l('remove',"$base/type/remove/$tid/$fld"),'align' => 'left');
}else{
$conf_row[] = array('data' => "common",'align' => 'left');
}
}
$conf_table[] = $conf_row;
}
if ($tid){
$header =array(t('Field Name'),t('Default Title'),t('Hint'),t('Required'),t('Weight'),t('Action'));
}else{
$header =array(t('Field Name'),t('Default Title'),t('Hint'),t('Common'),t('Required'),t('Auto Complete'),t('Weight'));
}
$output .= '
';
$output .= drupal_render($form);
return $output;
}
/*function theme_biblio_node_form($form){
echo "in node form";die;
}
*/
function biblio_submit(&$node){
if (variable_get('biblio_keyword_freetagging',0) && variable_get('biblio_freetagging_vocab',0)){
$vid = variable_get('biblio_freetagging_vocab',0);
$node->taxonomy['tags'][$vid] = $node->biblio_keywords;
}
}
//function biblio_pre_render($form_id, &$form, $next_page = TRUE) {
function biblio_form_alter($form_id, &$form){
global $form_values;
if ($form_id == "biblio_node_form") {
if (!empty($form['#node']->biblio_type)) $type = $form['#node']->biblio_type;
if (!empty($form['#post']['biblio_type'])) $type = $form['#post']['biblio_type'];
//$type = $form['#post']['biblio_type'] ? $form['#post']['biblio_type']:;
if ( $type >0 ){
$form['title']['#type'] = 'textfield';
$form['body']['#type'] = 'textarea';
$result = db_query('SELECT * FROM {biblio_fields} as b ORDER BY b.weight ASC');
while ($row = db_fetch_array($result)){
$fields[$row['fid']] = $row;
if($row['common']) $form[$row['name']]['#type'] = $row['type'];
}
$result = db_query('SELECT b.*, c.name, c.type FROM {biblio_type_details} as b INNER JOIN {biblio_fields} as c ON b.fid = c.fid where tid= %d ORDER BY b.weight ASC',$type);
while ($row = db_fetch_array($result)){
$type_fields[$row['fid']] = $row;
$form[$row['name']]['#type'] = $row['type'];
}
if(count($type_fields)){
// now merge the customizations with the main field array
foreach($type_fields as $key=>$value){
$fields[$key] = array_merge($fields[$key],$value);
}
}
foreach ($fields as $key=>$fld){
$form[$fld['name']] = array_merge($form[$fld['name']],array(
'#default_value' =>$form['#node']->$fld['name'],
'#title' => t('!title',array('!title'=>$fld['title'])),
'#required' => $fld['required'],
'#size' => $fld['size'],
'#maxlength' => $fld['maxsize'],
'#weight' => $fld['weight']/10,
'#description' => $fld['hint'])
); // end array_merge
} //end foreach
$form['biblio_keywords']['#description'] = t("Separate key words with a ")."".variable_get('biblio_keyword_sep', ',')."".t(" character");
} //endif type > 0
} //endif ($form_id == 'biblio_node_form...
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, &$param) {
global $form_values;
$output = '';
$param['options'] = array("enctype" => "multipart/form-data");
//$form['#pre_render'] = array('biblio_pre_render');
$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"] = t('!name',array('!name'=>$option->name));
}
$form['biblio_type'] = array(
'#type' => 'select',
'#title' => t('Publication Type'),
'#default_value' => $node->biblio_type,
'#options' => $options,
'#description' => null,
'#weight' => -5,
'#attributes' => array('onchange'=>'document.getElementById(\'node-form\').submit()'),
'#multiple' => false, '#required' => true);
$form['title']= array( // this will be set to textfield type in pre_render once the pub type is set.
'#type' => 'value',
'#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} as b ORDER BY b.weight ASC');
while ($row = db_fetch_array($result)){
// if($row['common']){
$fields[$row['fid']] = $row;
// }
}
// Now set all the fields to "value" type so the will not be visible, and
// then in biblio_pre_render the correct type will be set.
foreach ($fields as $key=>$fld){
$form[$fld['name']] = array(
'#default_value' => $node->$fld['name'],
'#type' => 'value',
'#title' => t('!title',array('!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']
);
}
/* $form['authors1'] = array('#type' => 'fieldset',
'#title' => t('First Authors'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 0);
$form['authors1']['author1_lastname'] = array(
'#default_value' => $node->$fld['name'],
'#type' => 'textfield',
'#title' => t('lastname'),
'#size' => 20,
'#required' => 1,
'#maxlength' => 75,
'#weight' => 1,
'#description' => ''
);
$form['authors2'] = array('#type' => 'value',
'#title' => t('More Authors...'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#weight' => 0);
*/
$form['body'] = array('#type' => 'value',
'#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);
$form['format'] = filter_form($node->format,20);
return $form;
}
/**
* Implementation of hook_validate().
*
*
* Errors should be signaled with form_set_error().
*/
function biblio_validate(&$node) {
if ($node->biblio_type == 0) {
form_set_error('biblio_type', t('You must select the type of publication'));
return;
}
if (!$node->biblio_authors) {
form_set_error('biblio_authors', t('You must supply at least one author name'));
}
/* if (!strstr("$node->biblio_authors", ";")) {
form_set_error('biblio_authors', t('You must separate the author names with semicolons'));
}
*/
if (!isset($node->biblio_year)) {
form_set_error('biblio_year', t('You must supply the year of publication'));
} else {
$today = getdate();
if (($node->biblio_year == t("In Press")) or ($node->biblio_year == 0)) {
$node->biblio_year = 0;
}
elseif ($node->biblio_year < 1 || $node->biblio_year > $today['year']) form_set_error('biblio_year', t('Year of Publication must be a number between 1 and ') . $today['year']);
}
/* if (!$node->biblio_secondary_title) {
form_set_error('biblio_secondary_title', t('You must supply the Journal Title, Conference Name or Book Title'));
}
*/
}
function biblio_insert_authors($nid, $authors=array() ){
}
/**
* Implementation of hook_insert().
*
* As a new node is being inserted into the database, we need to do our own
* database inserts.
*/
function biblio_insert($node) {
// Prepare the query:
$fields = biblio_get_db_fields();
$node->biblio_coins = biblio_coins($node);
foreach ($node as $key => $value) {
if (in_array((string) $key, $fields)) {
$k[] = db_escape_string($key);
$v[] = $value;
$s[] = "'%s'";
}
}
// Insert the node into the database:
db_query("INSERT INTO {biblio} (" . implode(", ", $k) . ") VALUES(" . implode(", ", $s) . ")", $v);
}
/**
* Implementation of hook_update().
*
* As an existing node is being updated in the database, we need to do our own
* database updates.
*/
function biblio_update($node) {
$fields = biblio_get_db_fields();
$node->biblio_coins = biblio_coins($node);
foreach ($node as $key => $value) {
if (in_array($key, $fields) && $key !="0") { //$key != "0" to fix a bug related to book module
$k[] = db_escape_string($key);
$q[] = end($k) . " = '%s'";
$v[] = $value;
$s[] = "'%s'";
}
}
// Update the node in the database:
if ($node->revision){
db_query("INSERT INTO {biblio} (" . implode(", ", $k) . ") VALUES(" . implode(", ", $s) . ")", $v);
}else{
db_query("UPDATE {biblio} SET " . implode(', ', $q) . " WHERE vid = '$node->vid'", $v);
}
}
/**
* Implementation of hook_delete().
*
* When a node is deleted, we need to clean up related tables.
*/
function biblio_delete($node) {
db_query('DELETE FROM {biblio} WHERE nid = %d', $node->nid);
}
/**
* Implementation of hook_load().
*
* This hook is called
* every time a node is loaded, and allows us to do some loading of our own.
*
*/
function biblio_load($node) {
$additions = db_fetch_object(db_query('SELECT * FROM {biblio} WHERE vid = %d', $node->vid));
return $additions;
}
function biblio_citekey_view(){
$citekey = arg(2);
$nid = db_fetch_object(db_query("SELECT nid FROM {biblio} WHERE biblio_citekey = '%s' ORDER BY vid DESC", $citekey));
if ($nid->nid > 0){
$node = node_load($nid->nid);
return node_page_view($node);
} else {
return t("Sorry, citekey: ").$citekey.t(" not found");
}
}
function biblio_citekey_generate(){
$result = db_query("SELECT n.title, b.biblio_citekey, b.biblio_authors, b.biblio_year FROM {node} AS n LEFT JOIN {biblio} AS b ON n.nid = b.nid WHERE n.type = 'biblio' ");
while ($node = db_fetch_object($result)) {
if (!$node->biblio_citekey){
$author_array = explode(";", _biblio_parse_authors($node->biblio_authors));
$auth = $author_array[0];
if (strstr($auth, ",")) {
$parts = split(",", $auth);
$lastname = $parts[0];
} else {
$parts = split(" ", $auth);
$lastname = end($parts);
}
}
}
}
function biblio_view_inline(&$node){
$style = variable_get('biblio_style', 'classic');
$base = variable_get('biblio_base', 'biblio');
$output = '
';
}
if(user_access('show sort links')){
$sort_attr = array("title"=>t("Click a second time to reverse the sort order"));
$sort_links = variable_get('biblio_sort_tabs', array('author'=>'author','title'=>'title','type'=>'type','year'=>'year'));
$content .= '
";
}
$session = &$_SESSION['biblio_filter'];
// if there are any filters in place, print them at the top of the list
if (count($args)) {
$content .= ''.t('Filters').': ';
while ($args) {
$type = $args[0];
array_shift($args);
$value = db_escape_string($args[0]);
if ($type == 'term_id'){
$term_result = db_query('SELECT name FROM {term_data} as td WHERE td.tid = %d',$value);
$term = db_fetch_object($term_result);
$value = $term->name;
$type = t("Taxonomy Term");
}
if ($type == 'type') $value = $pub_type["$value"];
array_shift($args);
$params = array('%a' => $type , '%b' => $value );
$content .= ($i++ ? t(' and%a is %b', $params) : t('%a is %b', $params)) ;
}
$content .= ' '.l('['.t('Clear All Filters').']',"$base/filter/clear");
}
}
if($inline) print '
';
while ($node = db_fetch_object($result)) {
switch ($attrib['sort']) {
case 'title':
if ( drupal_substr(drupal_ucfirst(ltrim($node->title)), 0, 1) != $_char) {
$_char = drupal_substr(drupal_ucfirst(ltrim($node->title)), 0, 1) ;
$content .= '
\n";
}
break;
case 'type':
if ($node->biblio_type != $_type) {
$_type = $node->biblio_type;
$name = db_result(db_query("SELECT name FROM {biblio_types} as t where t.tid=%d", $node->biblio_type)) ;
$content .= '
' . $name . "
\n";
}
break;
case 'year':
default:
if ($node->biblio_year != $_year) {
$_year = $node->biblio_year;
$content .= '
\n";
} //end while
$content .= theme('pager', 0, variable_get('biblio_rowsperpage', 25));
if (!db_num_rows($result)) {
$content .= "
".t("No items found")."
";
if (strstr($content, "Filters:")) {
$content .= l(t('Modify'),"$base/filter");
$content .= ' or '.l(t('remove'),"$base/filter/clear").' your filters and try again.';
}
}
if (!$inline) {
print theme('page', $content);
}else{
print $content . "
";
}
}
function biblio_db_search() {
global $user;
$inline = false;
$join = array();
$join[] = "left join {biblio} b on n.vid=b.vid";
if (variable_get('biblio_view_only_own', 0) ){
$limit .= " AND n.uid=$user->uid ";
}
$pager_attrib = array("sort" => variable_get('biblio_sort', 'year'), 'order' => variable_get('biblio_order', 'DESC'));
$limits = null;
if (isset($_GET['order'])){
$pager_attrib['order'] = ($_GET['order'] == 'desc') ? 'desc' : 'asc';
}
if (isset($_GET['sort'])) {
$pager_attrib['sort'] = check_plain($_GET['sort']);
}
switch ($pager_attrib['sort']) {
case 'type':
$sortby = "ORDER BY b.biblio_type %s, b.biblio_year DESC, SUBSTRING(n.title,1,1) ASC ";
break;
case 'title':
$sortby = "ORDER BY SUBSTRING(n.title,1,1) %s, b.biblio_year DESC ";
break;
case 'author':
/*$join[] = "inner join {biblio_has_author} as ha on a.aid = ha.aid";
$join[] = "inner join {biblio_author_index} as a on b.nid= ha.nid";
$sortby = " ORDER BY a.author %s ";
$where[] = "ha.rank = 1 ";
*/
$sortby = "ORDER BY SUBSTRING(LTRIM(b.biblio_authors),1,1) %s, b.biblio_year DESC ";
break;
case 'year':
default:
$sortby = "ORDER BY b.biblio_year %s, b.biblio_date DESC, SUBSTRING(n.title,1,1) ASC, b.biblio_type ASC ";
} //end switch
if (!isset($_SESSION['biblio_filter']) || !is_array($_SESSION['biblio_filter'])) {
$_SESSION['biblio_filter'] = array();
}
$session = &$_SESSION['biblio_filter'];
$numargs = func_num_args();
$arg_list = func_get_args();
foreach ($session as $filter) {
$arg_list = array_merge($arg_list, $filter);
}
if (count($arg_list) >= 2) {
$args = array();
while ($arg_list) {
$type = $arg_list[0];
array_shift($arg_list);
$operator = ($operator)?$operator:" AND "; //defaults to AND
switch ($type) {
case 'and':
$operator = " AND ";
break;
case 'or':
$operator = " OR ";
break;
case 'inline':
$inline = true;
break;
case 'term':
case 'term_id':
$term = explode("?",$arg_list[0]);
array_shift($arg_list);
$join[] = "inner join {term_node} as tn on n.nid = tn.nid";
if ($type == 'term'){
$join[] = "inner join {term_data} as td on tn.tid= td.tid";
$where[] = "td.name = '%s' ";
}elseif ($type == 'term_id'){
$where[] = "tn.tid = '%d' ";
}
$terms[] = db_escape_string($term[0]);
array_push($args, $type, $term[0]);
break;
case 'author':
$term = explode("?",$arg_list[0]);
array_shift($arg_list);
$where[] = 'b.biblio_authors RLIKE "[[:<:]]%s[[:>:]]" ';
$terms[] = db_escape_string($term[0]);
array_push($args, $type, $term[0]);
$operator = NULL;
break;
case 'publisher':
$term = explode("?",$arg_list[0]);
array_shift($arg_list);
$where[] = "b.biblio_publisher RLIKE '%s' ";
$terms[] = db_escape_string($term[0]);
array_push($args, $type, $term[0]);
$operator = NULL;
break;
case 'year':
$term = db_escape_string($arg_list[0]);
array_shift($arg_list);
$where[] = "b.biblio_year=%d ";
//$limit .= " AND b.biblio_year=%d ";
$terms[] = (int)$term;
array_push($args, $type, (int)$term);
$operator = NULL;
break;
case 'keyword':
$term = explode("?",$arg_list[0]);
array_shift($arg_list);
$where[] = "b.biblio_keywords RLIKE '%s' ";
$terms[] = db_escape_string($term[0]);
array_push($args, $type, $term[0]);
$operator = NULL;
break;
case 'type':
$term = db_escape_string($arg_list[0]);
array_shift($arg_list);
$limit .= $operator. "b.biblio_type=%d ";
$terms[] = (int)$term;
array_push($args, $type, (int)$term);
$operator = NULL;
break;
case 'order':
$term = (db_escape_string($arg_list[0]) == 'desc')?'desc':'asc';
array_shift($arg_list);
$pager_attrib['order'] = $term;
array_push($args, $type, $term);
break;
case 'sort':
$term = db_escape_string($arg_list[0]);
array_shift($arg_list);
$pager_attrib['sort'] = $term;
array_push($args, $type, $term);
switch ($term) {
case 'type':
$sortby = "ORDER BY b.biblio_type %s, b.biblio_year DESC, SUBSTRING(n.title,1,1) ASC ";
break;
case 'title':
$sortby = "ORDER BY SUBSTRING(n.title,1,1) %s, b.biblio_year DESC ";
break;
case 'year':
default:
$sortby = "ORDER BY b.biblio_year %s, SUBSTRING(n.title,1,1) ASC, b.biblio_type ASC ";
} //end switch
break;
default:
$fields = biblio_get_db_fields();
$term = explode("?",$arg_list[0]);
array_shift($arg_list);
if (in_array("biblio_$type",$fields))
{
$where[] = "b.biblio_$type RLIKE '%s' ";
$terms[] = db_escape_string($term[0]);
array_push($args, $type, $term[0]);
$operator = NULL;
}
break;
}
}
}
$where[] = "n.type='biblio' ";
if ($user->uid != 1 ) {
$where[] = 'n.status = 1 ';
}//show only published entries to everyone except admin
$joins = implode(' ', $join);
$where_clause = count($where) > 1 ? '('. implode(') AND (', $where) .')': $where[0];
$query = db_rewrite_sql("SELECT DISTINCT n.*, b.* FROM {node} n $joins WHERE $where_clause $published $limit $sortby ");
$count_query = db_rewrite_sql("SELECT DISTINCT COUNT(*) FROM {node} n $joins WHERE $where_clause $published $limit ");
//echo $query; die;
$_SESSION['last_biblio_query'] = $query;
$terms[] = $pager_attrib['order'];
$_SESSION['last_biblio_query_terms'] = $terms;
$result = pager_query($query, variable_get('biblio_rowsperpage', 25),0,$count_query,$terms);
biblio_show_results($result, $pager_attrib, $args,$inline);
}
function _biblio_export($format="tagged", $nid = null, $version = 7) {
$params=array();
if ($nid === null && isset($_SESSION['last_biblio_query']) && !empty($_SESSION['last_biblio_query']) ) {
$query = $_SESSION['last_biblio_query'];
$params = $_SESSION['last_biblio_query_terms'];
} elseif (!empty($nid)) {
$query = db_rewrite_sql("SELECT * FROM {node} n left join {biblio} b on n.vid=b.vid
WHERE n.nid=%d ");
$params[] = $nid;
}else{
return;
}
$result = db_query($query,$params);
if (db_num_rows($result)) {
switch($format){
case "tagged":
_endnote_tagged_export($result);
break;
case "xml":
_endnote_XML_export($result, $version );
break;
case "bib":
_bibtex_export($result);
break;
}
}
}
function _bibtex_export($result){
$bibtex = '';
while ($pub = db_fetch_object($result)) {
$type = "article";
$journal = $series = $booktitle = $school = $organization = null;
switch ($pub->biblio_type){
case 102:
$type = "article";
$journal = $pub->biblio_secondary_title;
break;
case 100:
$type = "book";
$series = $pub->biblio_secondary_title;
break;
case 101:
$type = "inbook";
$booktitle = $pub->biblio_secondary_title;
break;
case 103:
$type = "conference";
break;
case 100:
$type = "incollection";
break;
case 103:
$type = "inproceedings";
break;
case 129:
$type = "misc";
break;
case 108:
$type = "phdthesis";
$school = $pub->biblio_publisher;
$pub->biblio_publisher = null;
break;
case 104:
$type = "proceedings";
break;
case 109:
$type = "techreport";
$organization = $pub->biblio_publisher;
$pub->biblio_publisher = null;
break;
case 124:
$type = "unpublished";
break;
}
$bibtex .= '@'.$type.' { ';
$bibtex .= ($pub->biblio_citekey)? $pub->biblio_citekey.",\n":",\n";
if($pub->title) $bibtex .= "\ttitle = {".$pub->title."},\n";
if($journal) $bibtex .= "\tjournal = {".$journal."},\n";
if($booktitle) $bibtex .= "\tbooktitle = {".$booktitle."},\n";
if($series) $bibtex .= "\tseries = {".$series."},\n";
if($pub->biblio_secondary_authors) $bibtex .= "\teditor = {".$pub->biblio_secondary_authors."},\n";
if($pub->biblio_volume) $bibtex .= "\tvolume = {".$pub->biblio_volume."},\n";
if($pub->biblio_number) $bibtex .= "\tnumber = {".$pub->biblio_number."},\n";
if($pub->biblio_year) $bibtex .= "\tyear = {".$pub->biblio_year."},\n";
if($pub->biblio_notes) $bibtex .= "\tnote = {".$pub->biblio_notes."},\n";
if($pub->biblio_date) $bibtex .= "\tmonth = {".$pub->biblio_date."},\n";
if($pub->biblio_pages) $bibtex .= "\tpages = {".$pub->biblio_pages."},\n";
if($pub->biblio_publisher) $bibtex .= "\tpublisher = {".$pub->biblio_publisher."},\n";
if($school) $bibtex .= "\tschool = {".$school."},\n";
if($organization) $bibtex .= "\torganization = {".$organization."},\n";
if($institution) $bibtex .= "\tinstitution = {".$institution."},\n";
if($pub->biblio_type_of_work) $bibtex .= "\ttype = {".$pub->biblio_type_of_work."},\n";
if($pub->biblio_edition) $bibtex .= "\tedition = {".$pub->biblio_edition."},\n";
if($pub->biblio_section) $bibtex .= "\tchapter = {".$pub->biblio_section."},\n";
if($pub->biblio_place_published) $bibtex .= "\taddress = {".$pub->biblio_place_published."},\n";
if($pub->biblio_abst_e) $bibtex .= "\tabstract = {".$pub->biblio_abst_e."},\n";
if($pub->biblio_keywords) $bibtex .= "\tkeywords = {".$pub->biblio_keywords."},\n";
if($pub->biblio_isbn) $bibtex .= "\tISBN = {".$pub->biblio_isbn."},\n";
if($pub->biblio_url) $bibtex .= "\tURL = {".$pub->biblio_url."},\n";
$author = str_replace("; ", " and ", $pub->biblio_authors);
$bibtex .= "\tauthor = {".$author."}\n";
$bibtex.="}\n\n";
}
header('Content-type: application/text');
header('Content-Disposition: filename="bibtex.bib"');
print utf8_decode($bibtex);
}
function _endnote_XML_export($result, $version = 7) {
if ($version == 8){
require_once(drupal_get_path('module', 'biblio') . '/endnote8_export.inc');
$xml = _endnote8_XML_export($result);
}elseif ($version == 7){
require_once(drupal_get_path('module', 'biblio') . '/endnote7_export.inc');
$xml = _endnote7_XML_export($result);
}
header('Content-type: application/xml; charset=utf-8');
header('Content-Disposition: attachment; filename="endnote'.$version.'.xml"');
echo $xml;
}
function _endnote_tagged_export($result) {
$doc = "";
while ($pub = db_fetch_object($result)) {
switch ($pub->biblio_type) {
case 1:
case 102: $doc .= "%0 Journal Article\r\n";
if ($pub->biblio_secondary_title) $doc .= "%J " . trim($pub->biblio_secondary_title) . "\r\n";
break; // journal
case 2:
case 103: $doc .= "%0 Conference Paper\r\n";
if ($pub->biblio_secondary_title) $doc .= "%B " . trim($pub->biblio_secondary_title) . "\r\n";
break;
case 3: // are all
case 4: $doc .= "%0 Conference Proceedings\r\n";
if ($pub->biblio_secondary_title) $doc .= "%B " . trim($pub->biblio_secondary_title) . "\r\n";
break; // conference proceedings
case 5:
case 109:
$doc .= "%0 Report\r\n";
break; // report
case 6:
case 101:
$doc .= "%0 Book Section\r\n";
if ($pub->biblio_secondary_title) $doc .= "%B " . trim($pub->biblio_secondary_title) . "\r\n";
break; // book section
case 7:
case 108:
$doc .= "%0 Thesis\r\n";
if ($pub->biblio_secondary_title) $doc .= "%B " . trim($pub->biblio_secondary_title) . "\r\n";
break; // thesis
case 8:
case 119:
$doc .= "%0 Patent\r\n";
if ($pub->biblio_secondary_title) $doc .= "%B " . trim($pub->biblio_secondary_title) . "\r\n";
break; // patent
case 9:
default:
$doc .= "%0 Generic\r\n";
break; // generic
}
$doc .= "%D " . trim($pub->biblio_year) . "\r\n";
$doc .= "%T " . trim($pub->title) . "\r\n";
$author_array = _parse_author_array(explode(';', $pub->biblio_authors));
foreach($author_array as $auth) {
$doc .= "%A " . $auth['last_name'] . ($auth['first_name'] ? (', ' . $auth['first_name']) : ($auth['initials'] ? (', ' . $auth['initials']) : '')) . "\r\n";
}
if ($pub->biblio_place_published) $doc .= "%C " . trim($pub->biblio_place_published) . "\r\n";
if ($pub->biblio_secondary_authors) {
$author_array = explode(";", $pub->biblio_secondary_authors);
foreach($author_array as $auth) {
$doc .= "%E " . trim($auth) . "\r\n";
}
}
if ($pub->biblio_publisher) $doc .= "%I " . trim($pub->biblio_publisher) . "\r\n";
if (trim($pub->biblio_keywords)) $doc .= "%K " . trim($pub->biblio_keywords) . "\r\n";
if ($pub->biblio_call_number) $doc .= "%L " . trim($pub->biblio_call_number) . "\r\n";
if ($pub->biblio_accession_number) $doc .= "%M " . trim($pub->biblio_accession_number) . "\r\n";
if ($pub->biblio_issue) $doc .= "%N " . trim($pub->biblio_issue) . "\r\n";
if ($pub->biblio_pages) $doc .= "%P " . trim($pub->biblio_pages) . "\r\n";
if ($pub->biblio_tertiary_title) $doc .= "%S " . trim($pub->biblio_tertiary_title) . "\r\n";
if ($pub->biblio_url) $doc .= "%U " . trim($pub->biblio_url) . "\r\n";
if ($pub->biblio_volume) $doc .= "%V " . trim($pub->biblio_volume) . "\r\n";
$abst = "";
if ($pub->biblio_abst_e) $abst .= trim($pub->biblio_abst_e);
if ($pub->biblio_abst_f) $abst .= trim($pub->biblio_abst_f);
if ($abst) {
$search = array("/\r/", "/\n/");
$replace = " ";
$abst = preg_replace($search, $replace, $abst);
$doc .= "%X " . $abst . "\r\n";
}
if ($pub->biblio_tertiary_authors) {
$author_array = explode(";", $pub->biblio_tertiary_authors);
foreach($author_array as $auth) {
$doc .= "%Y " . trim($auth) . "\r\n";
}
}
if ($pub->biblio_notes) $doc .= "%Z " . trim($pub->biblio_notes) . "\r\n";
if ($pub->biblio_edition) $doc .= "%7 " . trim($pub->biblio_edition) . "\r\n";
if ($pub->biblio_date) $doc .= "%8 " . trim($pub->biblio_date) . "\r\n";
if ($pub->biblio_type_of_work) $doc .= "%9 " . trim($pub->biblio_type_of_work) . "\r\n";
if ($pub->biblio_isbn) $doc .= "%@ " . trim($pub->biblio_isbn) . "\r\n";
$doc .= "\r\n";
}
header('Content-type: application/x-endnote-refer');
header('Content-Disposition: filename="endnote.enw"');
print utf8_decode($doc);
}
function biblio_form_import() {
if (biblio_access('import', $node)) { // && !user_access('administer nodes')) {
$form['#attributes']['enctype'] = 'multipart/form-data';
$form["file_upload"] = array(
'#type' => 'file',
'#title' => t('Import file'),
'#default_value' => $edit['file_upload'],
'#size' => 60,
);
$form['filetype'] = array(
'#type' => 'radios',
'#title' => t('File Type'),
'#default_value' => $edit['filetype'],
'#options' => array('tagged' => t('EndNote Tagged'),'ris' => t('RIS') , 'xml'=>t('EndNote 7 XML'), 'xml8'=>t('EndNote 8+ XML'), 'bib'=>t('BibTex')),
);
// Get the vocabularies attached to the biblio node type ...
$vocabularies = module_invoke('taxonomy', 'get_vocabularies', 'biblio');
// ... and print a form to select the terms in each of them
$form['import_taxonomy'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'#title' => t('Taxonomy Settings'),
'#description' => t('Here you may select terms to be assigned to imported records (if any vocabularies are assigned to the biblio node type)'),
);
if (count($vocabularies)){
$i=0;
foreach ($vocabularies as $vocabulary) {
$form['import_taxonomy']['vocabulary'.$i] = module_invoke('taxonomy', 'form', $vocabulary->vid, 0);
$form['import_taxonomy']['vocabulary'.$i++]['#description'] = t("Select taxonomy term to assigned to imported entries");
}
}else{
$vocab_msg = t('There are currently no vocabularies assigned to the biblio node type, please go the the ').l(t('admin/taxonomy'),'admin/taxonomy').t(' page to fix this');
$form['import_taxonomy']['vocabulary_message'] = array('#value' => '
'.$vocab_msg.'
');
}
if (variable_get('biblio_keyword_freetagging', 0)){
$freetag_vocab = module_invoke('taxonomy', 'get_vocabulary', variable_get('biblio_freetagging_vocab', 0));
$msg = t('Keywords will be added to the').' "'.$freetag_vocab->name.'" '.t('vocabulary as specified in the Taxonomy section of the ').l(t('admin/settings/biblio'),'admin/settings/biblio').t(' page.');
}else{
$msg = t('Keywords will').' '.t('NOT').' '.t('be added to the vocabulary as specified in the Taxonomy section of the ').l(t('admin/settings/biblio'),'admin/settings/biblio').t(' page.');
}
$form['import_taxonomy']['freetagging_information'] = array('#value' => '
'.$msg.'
');
$form['button'] = array(
'#type' => 'submit',
'#value' => t('Import')
);
return $form;
//print theme('page', form($form, 'post', null, $attributes));
} else {
drupal_set_message("You are not authorized to access the biblio import page", 'error');
print theme('page', '');
}
}
function biblio_form_import_validate($form_id, $form_values) {
$op = $form_values['op'];
$filetype = $form_values['filetype'];
$edit = $_POST;
if (!file_check_upload('file_upload')){
form_set_error('',t("You must provide a file name"));
}
if($op == t('Import') && $filetype == '') {
form_set_error('',t("You must select a file type"));
}
}
function biblio_form_import_submit($form_id, $form_values) {
$op = $form_values['op'];
if ($form_values['op'] == t('Import') && isset($form_values['filetype'])) {
$import = file_check_upload('file_upload');
if ($import) {
$import = file_save_upload($import);
drupal_set_message($import->filename.t(" was uploaded"), 'status');
// Concatenate all the terms of the different vocabularies
// in a single array to be sent to _biblio_import
$terms = array();
foreach (array_keys($form_values) as $key) {
if (preg_match('/(vocabulary[0-9]+)/', $key)){
if ($form_values[$key] > 0) $terms[] = $form_values[$key];
}
}
// Added the $terms argument
// the array of terms to be attached to the node(s)
$content = _biblio_import($import->filepath,$form_values['filetype'], $terms);
file_delete($import->filepath);
} else {
drupal_set_message(t("File was NOT successfully uploaded"), 'error');
}
}
}
function _biblio_import($filename = null,$type='tagged',$terms = null) {
global $user;
$node = array();
if (file_exists($filename)) {
if (($file_content = @file_get_contents($filename)) === false) {
return false;
} else {
$options = variable_get('node_options_biblio',array('status'));
$node['type'] = "biblio";
$node['created'] = time();
$node['changed'] = time();
$node['comment'] = variable_get('comment_biblio',0);
$node['promote'] = in_array('promote',$options);
$node['moderate'] = in_array('moderate',$options);
$node['sticky'] = in_array('sticky',$options);
$node['format'] = 0;
$node['status'] = in_array('status',$options);
$node['uid'] = $user->uid;
switch($type){
case 'tagged': // EndNote Tagged
require_once(drupal_get_path('module', 'biblio') . '/tagged_parser.inc');
$node_ids = _endnote_tagged_import($file_content,$node);
break;
case 'xml': // EndNote 7 XML
$node_ids = _endnote_XML_import($file_content ,$node, 7 );
break;
case 'xml8': // EndNote 8+ XML
$node_ids = _endnote_XML_import($file_content ,$node, 8 );
break;
case 'bib': // BibTex
$node_ids = _bibtex_import($file_content ,$node );
break;
case 'ris': // RIS
require_once(drupal_get_path('module', 'biblio') . '/ris_parser.inc');
$node_ids = _ris_tagged_import($file_content,$node);
break;
}
if ($terms){
// set the vocabulary for the returned nodes
foreach ($node_ids as $node_id){
module_invoke('taxonomy', 'node_save', $node_id, $terms);
}
}
return $node_ids;
}
} else {
return false;
}
}
function _endnote_XML_import(&$data ,$nodedata, $version = 8) {
global $user,$records, $rec_count,$node_array,$node,$node_id;
$node_array = array();
$node = $nodedata;
$xml_parser = drupal_xml_parser_create($data);
// use case-folding so we are sure to find the tag in
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
xml_parser_set_option($xml_parser, XML_OPTION_SKIP_WHITE, true);
if ($version == 8){
require_once(drupal_get_path('module', 'biblio') . '/endnote8_parser.inc');
xml_set_element_handler($xml_parser, "en8_startElement", "en8_endElement");
xml_set_character_data_handler($xml_parser, "en8_characterData");
xml_parse($xml_parser, $data,1);
}elseif ($version == 7){
require_once(drupal_get_path('module', 'biblio') . '/endnote7_parser.inc');
xml_parse_into_struct($xml_parser, $data, $values);
en7_parse($values,$node_array,$node) ;
}
xml_parser_free($xml_parser);
$node_ids = _biblio_save_imported_nodes($node_array);
return ($node_ids);
}
function _bibtex_import(&$data, $node) {
require_once(drupal_get_path('module', 'biblio') . '/bibtex.php');
$node_array = array();
$bibtex = new Structures_BibTex();
$bibtex->loadString($data);
$bibtex->parse();
if ($bibtex->amount()){
$bibtex->bib2node($node_array, $node);
$node_ids = _biblio_save_imported_nodes($node_array);
}
return $node_ids;
}
function _biblio_save_imported_nodes(&$node_array){
if (function_exists('node_save')) {
foreach ($node_array as $node) {
$node = (object)$node;
if (variable_get('biblio_keyword_freetagging',0) && variable_get('biblio_freetagging_vocab',0)){
$vid = variable_get('biblio_freetagging_vocab',0);
$node->taxonomy['tags'][$vid] = $node->biblio_keywords;
}
node_save($node);
if ($node->nid) {
$node_ids[] = $node->nid;
}
}
}
drupal_set_message(t("Succesfully imported ").count($node_ids).t(" entries."), 'status');
return $node_ids;
}
function biblio_get_db_fields() {
$fields = array();
$fields[] = 'nid';
$fields[] = 'vid';
$fields[] = 'biblio_type';
$result = db_query('SELECT name FROM {biblio_fields} ');
while ($field = db_fetch_array($result)){
$fields[] = $field['name'];
}
return $fields ;
}
function _biblio_author_links($author,$base='biblio',$inline=false) {
$query = null;
$inline = $inline ? "/inline" : "";
//$attrib = (variable_get('biblio_links_target_new_window',null)) ? array('target'=>'_blank') : null;
$attrib = null;
if (isset($_GET['sort'])) {
$query .= "sort=" . $_GET['sort'];
}
if (isset($_GET['order'])) {
$query .= $query ?"&":"";
$query .= "order=" . $_GET['order'];
}
$html = "";
$author_array = explode(";", $author);
foreach($author_array as $auth) {
$html .= (empty($html))? "" : "; ";
if (strstr($auth, ",")) {
$parts = split(",", $auth);
$lastname = $parts[0];
} else {
$parts = split(" ", $auth);
$lastname = end($parts);
}
// list($lastname, $init) = split(",", $auth);
$html .= l(trim($auth), "$base/author/" . trim($lastname) . $inline,$attrib, $query );
}
return $html;
}
function biblio_author_index_shutdown(){
global $biblio_last_nid;
if ($biblio_last_nid) {
variable_set('biblio_ai_last_nid', $biblio_last_nid);
}
}
function biblio_update_author_index() {
global $biblio_last_nid;
//register_shutdown_function('biblio_author_index_shutdown');
$biblio_last_nid = variable_get('biblio_ai_last_nid', 0);
$biblio_max_count = variable_get('biblio_ai_max_count', 100);
$count = 0;
$result = db_query("SELECT nid, biblio_authors FROM {biblio} WHERE nid > %d",$biblio_last_nid);
while ( ($row = db_fetch_object($result)) && ($count < $biblio_max_count) ){
$author_array = explode(";", $row->biblio_authors);
$rank = 0;
foreach($author_array as $auth) {
$rank++;
if (strstr($auth, ",")) {
$parts = split(",", $auth);
$lastname = $parts[0];
} else {
$parts = split(" ", $auth);
$lastname = end($parts);
}
_biblio_author_index_insert($row->nid, $lastname,$rank);
$biblio_last_nid = $row->nid;
}
$count++;
}
variable_set('biblio_ai_last_nid', $biblio_last_nid);
return ;
}
function _biblio_author_index_insert($nid, $author,$rank) {
$uc_author = trim(drupal_strtoupper($author));
$result = db_query("SELECT * FROM {biblio_author_index} WHERE author = '%s'",$uc_author);
$author_exist = db_num_rows($result);
if ($author_exist){
$row = db_fetch_object($result);
$result = db_query("INSERT INTO {biblio_has_author} (`nid`,`aid`,`rank`) VALUES (%d,%d,%d)",$nid,$row->aid,$rank);
}else{
$aid = db_next_id('{biblio_author_index}_aid');
$result = db_query("INSERT INTO {biblio_author_index} (`aid`,`author`) VALUES (%d,'%s')",$aid,$uc_author);
$result = db_query("INSERT INTO {biblio_has_author} (`nid`,`aid`,`rank`) VALUES (%d, %d, %d)",$nid,$aid,$rank);
}
return ;
}
function _biblio_keyword_links($keywords,$base='biblio') {
if (isset($_GET['sort'])) {
$query .= "sort=" . $_GET['sort'];
}
if (isset($_GET['order'])) {
$query .= $query ?"&":"";
$query .= "order=" . $_GET['order'];
}
$html = "";
$sep = variable_get('biblio_keyword_sep', ',');
// if (strstr($keywords,';')){
$keyword_array = explode($sep, $keywords);
/* }elseif(strstr($keywords,',')){
$keyword_array = explode(",", $keywords);
}else{
$keyword_array = explode(" ", $keywords);
}
*/
foreach($keyword_array as $kw) {
$html .= (empty($html))? "" : "; ";
$html .= l(trim($kw), "$base/keyword/" . trim($kw) . $sort, NULL, $query);
}
return $html;
}
function _biblio_parse_authors($authors) {
$and = array(" and ", " And ", " AND ");
$authors = str_replace($and, ", ", $authors); // change the word "and" to a comma
$authors = str_replace(" ,", ",", $authors); // fix some potential typos
$authors = str_replace(",,", ",", $authors); // ditto
// $authors = str_replace(";",",",$authors);
$chunks = explode(";", $authors); // split the authors on the semicolon
$num_chunks = count($chunks);
for($i = 0; $i < count($chunks); $i++) {
$suffix = _biblio_get_suffix($chunks[$i]); // get and strip out the suffix
$prefix = _biblio_get_prefix($chunks[$i]); // get and strip out the prefix
if (strstr($chunks[$i], ",")) { // we probably have lastname first
$subchunks = explode(",", trim($chunks[$i]));
$lastname = $subchunks[0];
$subchunks = explode(" ", trim($subchunks[1]));
$initials = "";
for ($j = 0; $j < count($subchunks) ; $j++) {
if (substr_count($subchunks[$j], '.')) {
$initials .= $subchunks[$j];
} else {
$initials .= drupal_substr($subchunks[$j], 0, 1) . ".";
}
}
} else { // we have some form of firstname first (Fistname I. Lastname)
$subchunks = explode(" ", trim($chunks[$i]));
$lastname = end($subchunks);
$initials = "";
for ($j = 0;
$j < count($subchunks) - 1 ;
$j++) {
if (substr_count($subchunks[$j], '.')) {
$initials .= $subchunks[$j];
} else {
$initials .= drupal_substr($subchunks[$j], 0, 1) . ".";
}
}
}
$chunks[$i] = trim($prefix . ' ' . $lastname . ', ' . $initials . ' ' . $suffix);
}
return implode("; ", $chunks);
}
function _biblio_get_suffix(&$name) {
$suffix = null;
if (preg_match("/[, \.]+(Jr|Sr|Snr)\.?\s*$/", $name, $match)) {
$suffix = $match[0];
$Text = str_replace($Suffix, "", $name);
} elseif (preg_match("/([, \.]+)(Jr|Sr|Snr)[. ]/", $name, $match)) {
$suffix = $match[1];
$name = str_replace($Suffix, "", $name);
}
return $suffix;
}
function _biblio_get_prefix(&$name) {
$prefix = null;
$name = " " . $name;
$prefs = array(" Van ", " van ", " von ", " den ", " der ", " de ", " De ", " ter ", " Ter ", "Vander ");
if (strstr($name, " Van ")) $prefix .= "Van ";
if (strstr($name, " van ")) $prefix .= "van ";
if (strstr($name, " Vander ")) $prefix .= "Vander ";
if (strstr($name, " von ")) $prefix .= "von ";
if (strstr($name, " de ")) $prefix .= "de ";
if (strstr($name, " De ")) $prefix .= "De ";
if (strstr($name, " den ")) $prefix .= "den ";
if (strstr($name, " der ")) $prefix .= "der ";
if (strstr($name, " ter ")) $prefix .= "ter ";
if (strstr($name, " Ter ")) $prefix .= "Ter ";
if (strlen($prefix)) $name = str_replace($prefs, "", $name);
$name = trim($name);
return $prefix;
}
function author_test(){
$result = db_query("SELECT nid, biblio_authors FROM {biblio} ");
$carray = array();
while ($row = db_fetch_object($result)){
// $carray = explode(";",$authors->biblio_authors);
// $creators = _parse_author_array($carray);
_biblio_author_index($row->nid,$row->biblio_authors);
// echo $authors->nid;
}
$creators = _parse_author_array($carray);
}
function _parse_author_array($authorArray)
{
// $input = trim($input);
// split on ' and '
// $authorArray = preg_split("/\s(and)\s/i", $input);
// check if there's anything that looks like et. al
$count=1;
foreach($authorArray as $value)
{
$appellation = $prefix = $surname = $firstname = $initials = '';
$author = explode(",", preg_replace("/\s{2,}/", ' ', trim($value)));
$size = sizeof($author);
// No commas therefore something like Mark Grimshaw, Mark Nicholas Grimshaw, M N Grimshaw, Mark N. Grimshaw
if($size == 1)
{
$author = split(" ", $value);
// last of array is surname (no prefix if entered correctly)
$surname = array_pop($author);
}
// Something like Grimshaw, Mark or Grimshaw, Mark Nicholas or Grimshaw, M N or Grimshaw, Mark N.
else if($size == 2)
{
// first of array is surname (perhaps with prefix)
list($surname, $prefix) = _grabSurname(array_shift($author));
}
// If $size is > 2, we're looking at something like Bush, George W, III
else
{
// last of array is 'Jr.', 'IV' etc.
$appellation = array_pop($author);
// first of array is surname (perhaps with prefix)
list($surname, $prefix) = _grabSurname(array_shift($author));
}
$remainder = join(" ", $author);
list($firstname, $initials) = _grabFirstnameInitials($remainder);
$surname = $surname . ' ' . $appellation;
$creators[] = array('first_name'=> trim("$firstname"),
'initials' => trim("$initials"),
'last_name' => trim("$surname"),
'prefix' => trim("$prefix"),
'order' => "$count");
$count++;
}
if(isset($creators))
return $creators;
return FALSE;
}
// grab firstname and initials which may be of form "A.B.C." or "A. B. C. " or " A B C " etc.
function _grabFirstnameInitials($remainder)
{
$firstname = $initials = '';
$array = split(" ", $remainder);
foreach($array as $value)
{
if(preg_match("/[a-zA-Z]{2,}/", trim($value)))
$firstnameArray[] = trim($value);
else
$initialsArray[] = str_replace(".", " ", trim($value));
}
if(isset($initialsArray))
{
foreach($initialsArray as $initial)
$initials .= ' ' . trim($initial);
}
if(isset($firstnameArray))
$firstname = join(" ", $firstnameArray);
return array($firstname, $initials);
}
// surname may have title such as 'den', 'von', 'de la' etc. - characterised by first character lowercased
function _grabSurname($input)
{
$surnameArray = split(" ", $input);
foreach($surnameArray as $value)
{
$firstChar = substr($value, 0, 1);
if((ord($firstChar) >= 97) && (ord($firstChar) <= 122))
$prefix[] = $value;
else
$surname[] = $value;
}
if(isset($surname)) $surname = join(" ", $surname);
if(isset($prefix))
{
$prefix = join(" ", $prefix);
return array($surname, $prefix);
}
return array($surname, FALSE);
}
function biblio_views_tables() {
$table = views_new_table('biblio', 'internal', 'node', 'vid', 'vid');
$result = db_query('SELECT name,title FROM {biblio_fields} ');
while ($field = db_fetch_array($result)){
views_table_add_field($table, $field['name'], "Biblio: ".$field['title'], "", array(
'sortable' => true,
'notafield' => false,
));
}
$tables['biblio'] = $table;
$table = views_new_table('biblio_types', 'internal', 'biblio', 'tid', 'tid');
$tables['biblio_types'] = $table;
return $tables;
}
function biblio_views_default_views(){
$view = new stdClass();
$view->name = 'biblioview';
$view->description = 'Shows a summary view of biblio entries';
$view->access = array ();
$view->view_args_php = '';
$view->page = TRUE;
$view->page_title = 'Biblio';
$view->page_header = '';
$view->page_header_format = '1';
$view->page_footer = '';
$view->page_footer_format = '1';
$view->page_empty = '';
$view->page_empty_format = '1';
$view->page_type = 'table';
$view->url = 'biblioview';
$view->use_pager = TRUE;
$view->nodes_per_page = '10';
$view->sort = array ();
$view->argument = array (
array (
'type' => 'nodetype',
'argdefault' => '2',
'title' => '',
'options' => '',
'wildcard' => 'biblio',
'wildcard_substitution' => '',
),
);
$view->field = array (
array (
'tablename' => 'biblio',
'field' => 'biblio_year',
'label' => 'Year',
'sortable' => '1',
'defaultsort' => 'DESC',
),
array (
'tablename' => 'biblio',
'field' => 'biblio_authors',
'sortable' => '1',
'label' => 'Author',
),
array (
'tablename' => 'node',
'field' => 'title',
'label' => 'Title',
'handler' => 'views_handler_field_nodelink',
'sortable' => '1',
'options' => 'link',
),
);
$view->filter = array ();
$view->exposed_filter = array ();
$view->requires = array(biblio, node);
$views[$view->name] = $view;
return $views;
}
function biblio_nodeapi($node, $op){
switch ($op){
case 'delete revision':
db_query('DELETE FROM {biblio} WHERE vid = %d', $node->vid);
break;
}
}
/*******************************************
* Filter
* Largely inspired from the footnote module
*
*******************************************/
function _biblio_citekey_print($citekey){
$nid = db_fetch_object(db_query("SELECT nid FROM {biblio} WHERE biblio_citekey = '%s' ORDER BY vid DESC", $citekey));
if ($nid->nid > 0){
$style = variable_get('biblio_style', 'classic');
$base = variable_get('biblio_base', 'biblio');
$node = node_load($nid->nid);
return theme('biblio_short', $node, $base, $style);
} else {
return t("Citekey: ").$citekey.t(" not found");
}
}
/**
* Implementation of hook_filter_tips().
*
* This hook allows filters to provide help text to users during the content
* editing process. Short tips are provided on the content editing screen, while
* long tips are provided on a separate linked page. Short tips are optional,
* but long tips are highly recommended.
*/
function biblio_filter_tips($delta, $format, $long = FALSE) {
switch ($delta) {
case 0:
if ($long) {
return t('You can cite references directly into texts with <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 print to the bottom of the page (the reference).');
}
else {
return t('Use <bib>...</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('References <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>...</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 if we use HTML filter too, but Footnotes could be first
case 'prepare':
return $text;
// The actual filtering is performed here. The supplied text should be
// returned, once any necessary substitutions have taken place.
case 'process':
if (variable_get('biblio_footnotes_integration', 0) && module_exists('footnotes'))
{ // this is used with footnote module integration to replace the tags with tags
$text = preg_replace_callback('|(.*?)|s', '_biblio_filter_footnote_callback', $text);
return $text;
}else{
$text = preg_replace_callback('|(.*?)|s', '_biblio_filter_replace_callback', $text);
//Replace tag with the list of footnotes.
//If tag is not present, by default add the footnotes at the end.
//Thanks to acp on drupal.org for this idea. see http://drupal.org/node/87226
$footer = '';
$footer = _biblio_filter_replace_callback(NULL, 'output footer');
if( preg_match( '//', $text ) > 0 ) {
$text = preg_replace('//', $footer, $text, 1);
return $text;
}
else {
return $text . "\n\n" . $footer;
}
}
}
break;
}
}
function _biblio_filter_footnote_callback( $matches ) {
$text = '' . _biblio_citekey_print($matches[1]) . "";
return $text;
}
/**
* Helper function called from preg_replace_callback() above
*
* Uses static vars to temporarily store footnotes found.
* In my understanding, this is not threadsafe?!
*/
function _biblio_filter_replace_callback( $matches, $op = '' ) {
static $n = 0;
static $store_matches = array();
$str = '';
if( $op == 'output footer' ) {
theme('biblio_add_css');
if( $n > 0 ) {
$str = '