function theme_biblio_page_number in Bibliography Module 7
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.2 includes/biblio.theme.inc \theme_biblio_page_number()
Format page information:.
NOTES: - this function (and refbase in general) assumes following rules for the original formatting of page information in '$orig_page_info':
- single-page items are given as a page range with identical start & end numbers (e.g. "127-127")
- multi-page items are given as a page range where the end number is greater than the start number (e.g. "127-132")
- for multi-page items where only the start page is known, a hyphen is appended to the start page (e.g. "127-")
- total number of pages are given with a "pp" suffix (e.g. "498 pp"), see todo.
- the given page info is left as is if it does not match any of the above rules (e.g. a single page number is ambiguous since it
could mean a single page or the total number of pages)
- the function attempts to deal with page locators that contain letters (e.g. "A1 - A3" or "4a-4c") but, ATM, locator parts (e.g. "A1")
must contain at least one digit character & must not contain any whitespace.
@todo should we only use Unicode-aware regex expressions (i.e. always use '$space', '$digit' or '$word' instead of ' ', '\d' or '\w', etc)?
- recognize & process total number of pages
- for '$shortenPageRangeEnd=TRUE', add support for page locators that contain letters (e.g. "A1 - A3" or "4a-4c")
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 716
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:
// the original page info contains a page range (like: "127-127", "127-132", "A1 - A3", "4a-4c", or "127-" if only start page given)
if (preg_match("/\\w*\\d+\\w* *[{$dash}]+ *(?:\\w*\\d+\\w*)?/{$patternModifiers}", $orig_page_info)) {
// 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:
// this part contains a page range with identical start & end numbers (like: "127-127")
if (preg_match("/(\\w*\\d+\\w*)[{$dash}]+\\1(?=[^\\w\\d]|\$)/{$patternModifiers}", $partsArray[$i])) {
$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])) {
// In case of '$shorten_page_range_end=TRUE', we abbreviate ending page numbers so that digits aren't repeated unnecessarily:
// ATM, only digit-only page locators (like: "127-132") are supported.
if ($shorten_page_range_end and preg_match("/\\d+[{$dash}]+\\d+/{$patternModifiers}", $partsArray[$i])) {
// 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 the ending page number has a digit that's identical to the starting page number (at the same digit offset)
if (preg_match("/^" . substr($startPage, $j, 1) . "/", $endPage)) {
// Remove the first digit from the remaining ending page number.
$endPage = substr($endPage, 1);
}
else {
break;
}
}
}
$partsArray[$i] = $page_range_prefix . $startPage . $page_range_delim . $endPage . $page_range_suffix;
}
else {
$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]);
}
}
}
// Merge again all parts.
$newPageInfo = join(" ", $partsArray);
}
else {
// Page info is ambiguous, so we don't mess with it.
$newPageInfo = $orig_page_info;
}
return $newPageInfo;
}