function theme_biblio_page_number in Bibliography Module 7.2
Same name and namespace in other branches
- 5 biblio.module \theme_biblio_page_number()
- 6.2 includes/biblio_theme.inc \theme_biblio_page_number()
- 6 biblio_theme.inc \theme_biblio_page_number()
- 7 includes/biblio_theme.inc \theme_biblio_page_number()
1 call to theme_biblio_page_number()
4 theme calls to theme_biblio_page_number()
- biblio_style_ama in styles/
biblio_style_ama.inc - biblio_style_chicago in styles/
biblio_style_chicago.inc - Apply a bibliographic style to the node
- biblio_style_mla in styles/
biblio_style_mla.inc - Apply a bibliographic style to the node
- biblio_style_vancouver in styles/
biblio_style_vancouver.inc
File
- includes/
biblio.theme.inc, line 634
Code
function theme_biblio_page_number($variables) {
$orig_page_info = $variables['orig_page_info'];
$page_range_delim = $variables['page_range_delim'];
$single_page_prefix = $variables['single_page_prefix'];
$page_range_prefix = $variables['page_range_prefix'];
$total_pages_prefix = $variables['total_pages_prefix'];
$single_page_suffix = $variables['single_page_suffix'];
$page_range_suffix = $variables['page_range_prefix'];
$total_pages_suffix = $variables['total_pages_prefix'];
$shorten_page_range_end = $variables['single_page_suffix'];
list($alnum, $alpha, $cntrl, $dash, $digit, $graph, $lower, $print, $punct, $space, $upper, $word, $patternModifiers) = _biblio_get_regex_patterns();
// Check original page info for any recognized page locators, and process them appropriately:
if (preg_match("/\\w*\\d+\\w* *[{$dash}]+ *(?:\\w*\\d+\\w*)?/{$patternModifiers}", $orig_page_info)) {
// the original page info contains a page range (like: "127-127", "127-132", "A1 - A3", "4a-4c", or "127-" if only start page given)
// Remove any whitespace around dashes or hyphens that indicate a page range:
$orig_page_info = preg_replace("/(\\w*\\d+\\w*) *([{$dash}]+) *(\\w*\\d+\\w*)?(?=[^\\w\\d]|\$)/{$patternModifiers}", "\\1\\2\\3", $orig_page_info);
// Split original page info into its functional parts:
// NOTE: ATM, we simply split on any whitespace characters, then process all parts with page ranges
// (this will also reduce runs of whitespace to a single space)
$partsArray = preg_split("/ +/", $orig_page_info);
$partsCount = count($partsArray);
for ($i = 0; $i < $partsCount; $i++) {
// Format parts with page ranges:
// - single-page item:
if (preg_match("/(\\w*\\d+\\w*)[{$dash}]+\\1(?=[^\\w\\d]|\$)/{$patternModifiers}", $partsArray[$i])) {
// this part contains a page range with identical start & end numbers (like: "127-127")
$partsArray[$i] = preg_replace("/(\\w*\\d+\\w*)[{$dash}]+\\1(?=[^\\w\\d]|\$)/{$patternModifiers}", $single_page_prefix . "\\1" . $single_page_suffix, $partsArray[$i]);
}
elseif (preg_match("/\\w*\\d+\\w*[{$dash}]+(?:\\w*\\d+\\w*)?(?=[^\\w\\d]|\$)/{$patternModifiers}", $partsArray[$i])) {
// this part contains a page range (like: "127-132", or "127-" if only start page given)
// In case of '$shorten_page_range_end=TRUE', we abbreviate ending page numbers so that digits aren't repeated unnecessarily:
if ($shorten_page_range_end and preg_match("/\\d+[{$dash}]+\\d+/{$patternModifiers}", $partsArray[$i])) {
// ATM, only digit-only page locators (like: "127-132") are supported
// NOTE: the logic of this 'if' clause doesn't work if the original page info contains something like "173-190; 195-195" (where, for the first page range, '$endPage' would be "190;" and not "190")
list($startPage, $endPage) = preg_split("/[{$dash}]+/{$patternModifiers}", $partsArray[$i]);
$countStartPage = strlen($startPage);
$countEndPage = strlen($endPage);
if ($countStartPage == $countEndPage and $startPage < $endPage) {
for ($j = 0; $j < $countStartPage; $j++) {
if (preg_match("/^" . substr($startPage, $j, 1) . "/", $endPage)) {
// if the ending page number has a digit that's identical to the starting page number (at the same digit offset)
$endPage = substr($endPage, 1);
// remove the first digit from the remaining ending page number
}
else {
break;
}
}
}
$partsArray[$i] = $page_range_prefix . $startPage . $page_range_delim . $endPage . $page_range_suffix;
}
else {
// don't abbreviate ending page numbers:
$partsArray[$i] = preg_replace("/(\\w*\\d+\\w*)[{$dash}]+(\\w*\\d+\\w*)?(?=[^\\w\\d]|\$)/{$patternModifiers}", $page_range_prefix . "\\1" . $page_range_delim . "\\2" . $page_range_suffix, $partsArray[$i]);
}
}
}
$newPageInfo = join(" ", $partsArray);
// merge again all parts
}
else {
$newPageInfo = $orig_page_info;
// page info is ambiguous, so we don't mess with it
}
return $newPageInfo;
}