Open Journal Systems  3.3.0
PageHelper.php
1 <?php
2 /*
3  * citeproc-php
4  *
5  * @link http://github.com/seboettg/citeproc-php for the source repository
6  * @copyright Copyright (c) 2017 Sebastian Böttger.
7  * @license https://opensource.org/licenses/MIT
8  */
9 
10 namespace Seboettg\CiteProc\Util;
11 
13 
20 {
26  public static function processPageRangeFormats($ranges, $pageRangeFormat)
27  {
28  list($from, $to) = $ranges;
29 
30  if (!empty($pageRangeFormat)) {
31  switch ($pageRangeFormat) {
33  $resTo = self::renderMinimal($from, $to, 0);
34  break;
36  if (strlen($to) > 2) {
37  $resTo = self::renderMinimal($from, $to, strlen($to) - 2);
38  } else {
39  $resTo = $to;
40  }
41  break;
43  $resTo = self::renderChicago($from, $to);
44  break;
46  default:
47  $resTo = $to;
48  }
49  return "$from-$resTo";
50  }
51  return "$from-$to";
52  }
53 
61  private static function renderMinimal($from, $to, $limit = 1)
62  {
63  $resTo = "";
64  if (strlen($from) == strlen($to)) {
65  for ($i = strlen($to) - 1; $i >= $limit; --$i) {
66  $digitTo = $to[$i];
67 
68  $digitFrom = $from[$i];
69  if ($digitTo !== $digitFrom) {
70  $resTo = $digitTo.$resTo;
71  }
72  }
73  return $resTo;
74  }
75  return $to;
76  }
77 
78  private static function renderChicago($from, $to)
79  {
80  if ($from > 100 && ($from % 100 > 0) && intval(($from / 100), 10) === intval(($to / 100), 10)) {
81  return "".($to % 100);
82  } elseif ($from >= 10000) {
83  return "".($to % 1000);
84  }
85  return $to;
86  }
87 }
Seboettg\CiteProc\Util\PageHelper\processPageRangeFormats
static processPageRangeFormats($ranges, $pageRangeFormat)
Definition: PageHelper.php:26
Seboettg\CiteProc\Style\Options\PageRangeFormats
Definition: PageRangeFormats.php:25
Seboettg\CiteProc\Style\Options\PageRangeFormats\MINIMAL
const MINIMAL
Definition: PageRangeFormats.php:55
Seboettg\CiteProc\Util\PageHelper
Definition: PageHelper.php:19
Seboettg\CiteProc\Util
Definition: CiteProcHelper.php:10
Seboettg\CiteProc\Style\Options\PageRangeFormats\CHICAGO
const CHICAGO
Definition: PageRangeFormats.php:45
Seboettg\CiteProc\Style\Options\PageRangeFormats\EXPANDED
const EXPANDED
Definition: PageRangeFormats.php:50
Seboettg\CiteProc\Style\Options\PageRangeFormats\MINIMAL_TWO
const MINIMAL_TWO
Definition: PageRangeFormats.php:60