function biblio_crossref_form_biblio_node_form_validate in Bibliography Module 6.2
1 string reference to 'biblio_crossref_form_biblio_node_form_validate'
- biblio_crossref_form_biblio_node_form_alter in modules/
crossref/ biblio_crossref.module
File
- modules/
crossref/ biblio_crossref.module, line 110
Code
function biblio_crossref_form_biblio_node_form_validate($form, &$form_state) {
global $user;
$node_data = array();
$clicked_button = $form_state['clicked_button']['#value'];
if ($clicked_button == t('Populate using DOI') || $clicked_button == t('Search for DOI by Author and Title')) {
$crossref_pid = variable_get('biblio_crossref_pid', '');
$user_pid = isset($user->biblio_crossref_pid) && !empty($user->biblio_crossref_pid) ? $user->biblio_crossref_pid : '';
if (variable_get('biblio_show_crossref_profile_form', '1') && !empty($user_pid)) {
$crossref_pid = $user_pid;
}
if (empty($crossref_pid)) {
form_set_error('doi_data', t(l('You need to register with CrossRef', 'http://www.crossref.org/requestaccount/', array(
'attributes' => array(
'target' => '_blank',
),
'absolue' => TRUE,
)) . t(' and then enter your CrossRef UserID in the "<i>CrossRef Login Information</i>" section of your account profile ') . l('here...', "user/{$user->uid}/edit")));
return;
}
if ($clicked_button == t('Populate using DOI') && strlen($doi = $form_state['values']['doi_data'])) {
if (($doi_start = strpos($form_state['values']['doi_data'], '10.')) !== FALSE) {
if (!($dup = biblio_crossref_check_doi($doi))) {
module_load_include('php', 'biblio_crossref', 'biblio.crossref.client');
$client = new BiblioCrossRefClient($doi, $crossref_pid);
$node_data = $client
->fetch();
if (!empty($node_data)) {
$form_state['values'] = array_merge($form_state['values'], $node_data);
$form_state['storage']['biblio_type'] = $node_data['biblio_type'];
return;
}
}
else {
$message = t('The DOI that you are trying to import already exists in the database, see ');
$message .= l('node/' . $dup, 'node/' . $dup);
form_set_error('doi_data', $message);
$form_state['rebuild'] = TRUE;
$form_state['submitted'] = FALSE;
unset($form_state['values']['biblio_type']);
return;
}
}
else {
form_set_error('doi_data', t('This does not appear to be a valid DOI name, it should start with "10." '));
$form_state['rebuild'] = TRUE;
$form_state['submitted'] = FALSE;
unset($form_state['values']['biblio_type']);
return;
}
}
if ($clicked_button == t('Search for DOI by Author and Title') && empty($form_state['values']['doi_search_author'])) {
form_set_error('doi_search_author', t('You must supply an author name'));
}
if ($clicked_button == t('Search for DOI by Author and Title') && empty($form_state['values']['doi_search_title'])) {
form_set_error('doi_search_title', t('You must supply a title'));
}
if ($clicked_button == t('Search for DOI by Author and Title') && !empty($form_state['values']['doi_search_author']) && !empty($form_state['values']['doi_search_title'])) {
module_load_include('php', 'biblio_crossref', 'biblio.crossref.client');
$client = new BiblioCrossRefClient('', $crossref_pid);
$client
->setUrl('http://doi.crossref.org/servlet/query');
$results = $client
->fetchByAuthorTitle($form_state['values']['doi_search_author'], $form_state['values']['doi_search_title']);
$form_state['values']['doi_search_results'] = $results;
$form_state['rebuild'] = TRUE;
$form_state['submitted'] = FALSE;
$form_state['values']['biblio_type'] = NULL;
}
}
}