-
Notifications
You must be signed in to change notification settings - Fork 57
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
base: 7.x
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
@@ -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) { | ||
$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; | ||
|
@@ -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) { | ||
|
@@ -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': | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change breaks the page load for me; the function 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
@@ -267,3 +274,4 @@ function islandora_scholar_embed_tags($tags) { | |
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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.