Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This is a replacement pull request for #323 #332

Open
wants to merge 3 commits into
base: 7.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 35 additions & 27 deletions includes/google_scholar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -44,36 +44,46 @@ function islandora_scholar_create_meta_tags($object) {
else {
return FALSE;
}
foreach ($mods_xml->xpath('mods:name') as $name_xml) {
foreach ($mods_xml->xpath(variable_get('islandora_scholar_xpaths_authors_xpath', '//mods:mods[1]/mods:name/mods:role[mods:roleTerm = "author"]/..')) as $name_xml) {
$name_parts = array();
$name_xml->registerXPathNamespace('mods', 'http://www.loc.gov/mods/v3');
$roles = $name_xml->xpath('mods:role/mods:roleTerm');
bryjbrown marked this conversation as resolved.
Show resolved Hide resolved
$role = strtolower((string) reset($roles));
if ($role) {
if ($role == 'author') {
foreach ($name_xml->xpath('mods:namePart') as $name_part) {
if ((string) $name_part != '') {
// Strip periods off the end.
$np = (string) rtrim($name_part, '.');
if ($name_part['type'] == 'given') {
$name_parts['first_name'] = (string) $name_part;
}
if ($name_part['type'] == 'family') {
$name_parts['last_name'] = $np;
}
if (!isset($name_part['type'])) {
$name_parts['no_type'] = $np;
}
// Use Mods DisplayForm as a backup source for name.
// Only taking the first result for displayForm.
$name_displayForm = '';
$mods_displayform = $name_xml->xpath('mods:displayForm');
if (is_array($mods_displayform)) {
$name_displayForm = array_shift($mods_displayform);
}
foreach ($name_xml->xpath('mods:namePart') as $name_part) {
if ((string) $name_part != '') {
// Strip periods off the end.
$np = (string) rtrim($name_part, '.');
if ($name_part['type'] == 'given') {
// Middle name is also marked as given name in MODS.
if (isset($name_parts['first_name'])) {
$name_parts['first_name'] = $name_parts['first_name'] . ' ' . (string) $name_part;
}
else {
$name_parts['first_name'] = (string) $name_part;
}
}
}
if (isset($name_parts['last_name']) && isset($name_parts['first_name'])) {
$tags['citation_author'][] = $name_parts['last_name'] . ', ' . $name_parts['first_name'];
}
elseif (isset($name_parts['no_type'])) {
$tags['citation_author'][] = $name_parts['no_type'];
if ($name_part['type'] == 'family') {
$name_parts['last_name'] = $np;
}
if (!isset($name_part['type'])) {
$name_parts['no_type'] = $np;
}
}
}
if (isset($name_parts['last_name']) && isset($name_parts['first_name'])) {
$tags['citation_author'][] = $name_parts['last_name'] . ', ' . $name_parts['first_name'];
}
elseif ($name_displayForm != '') {
$tags['citation_author'][] = $name_displayForm;
}
elseif (isset($name_parts['no_type'])) {
$tags['citation_author'][] = $name_parts['no_type'];
}
}
if (count($tags['citation_author']) == 0) {
return FALSE;
Expand Down Expand Up @@ -103,7 +113,6 @@ function islandora_scholar_create_meta_tags($object) {
// Google requires dates in yy/mm/dd format or just the year. As dates suck
// and we don't have a consistent structure of input we will just return the
// year for now.

if ($date) {
$date_string = islandora_scholar_parse_date_foryear($date);
if ($date_string) {
Expand All @@ -116,7 +125,6 @@ function islandora_scholar_create_meta_tags($object) {

$host_title = $mods_xml->xpath(variable_get('islandora_scholar_xpaths_host_title', '//mods:relatedItem[@type="host"]//mods:title'));
$genre = $mods_xml->xpath(variable_get('islandora_scholar_xpaths_genre', '//mods:mods[1]/mods:genre'));

$genre = strtolower((string) reset($genre));
switch ($genre) {
case 'book section':
Expand Down Expand Up @@ -171,7 +179,7 @@ function islandora_scholar_create_meta_tags($object) {

$online_date = $mods_xml->xpath(variable_get('islandora_scholar_xpaths_online_date', '//mods:recordInfo/mods:recordCreationDate'));
if ($online_date) {
$date_string = islandora_scholar_parse_date_foryear($online_date);
$date_string = islandora_scholar_date_foryear($online_date);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We originally had islandora_scholar_parse_date_foryear which was correct but the original commits changed this to islandora_parse_date_foryear leaving out the _scholar_ bit. Now it appears that you have added _scholar_ but in the process left out the _parse_ part. This needs to be islandora_scholar_parse_date_foryear, anything else causes the object page to fail to load. Please test a page load for the object before committing to verify that the object page loads.

if ($date_string) {
$tags['citation_online_date'] = $date_string;
}
Expand Down