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 2 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
64 changes: 36 additions & 28 deletions includes/google_scholar.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

/**
* @file
* Module used to embed meta tags in the HEAD for use in indexing in Google
Expand Down Expand Up @@ -44,36 +43,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:name')) as $name_xml) {
Copy link
Member

Choose a reason for hiding this comment

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

This is good, we should definitely not be using the hardcoded xpath if a configurable one exists.

$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 +112,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 +124,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 +178,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_parse_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.

This change breaks the page load for me; the function islandora_parse_date_foryear does not exist in any of the Islandora modules. islandora_scholar_parse_date_foryear does exist later on in this same file though at https://github.com/Islandora/islandora_scholar/blob/7.x/includes/google_scholar.inc#L210-L229.

I'm assuming this is just a typo, but this needs to be changed back to the way it was originally before this PR can be accepted.

Copy link
Author

Choose a reason for hiding this comment

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

yep, it is a typo. Fixing it

if ($date_string) {
$tags['citation_online_date'] = $date_string;
}
Expand Down Expand Up @@ -267,3 +274,4 @@ function islandora_scholar_embed_tags($tags) {
}
}
}