@@ -29,19 +29,19 @@ |
||
| 29 | 29 | |
| 30 | 30 | if (!function_exists('vendorPath')) { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @return bool|string returns path of composer vendor folder, and false if folder does not exist |
|
| 34 | - */ |
|
| 35 | - function vendorPath() { |
|
| 32 | + /** |
|
| 33 | + * @return bool|string returns path of composer vendor folder, and false if folder does not exist |
|
| 34 | + */ |
|
| 35 | + function vendorPath() { |
|
| 36 | 36 | |
| 37 | - if (file_exists(__DIR__ . '/vendor/')) { |
|
| 38 | - return __DIR__ . '/vendor'; |
|
| 39 | - } else { |
|
| 40 | - if (!file_exists(__DIR__ . '/../../')) { |
|
| 41 | - return false; |
|
| 42 | - } else { |
|
| 43 | - return __DIR__ . '/../..'; |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - } |
|
| 37 | + if (file_exists(__DIR__ . '/vendor/')) { |
|
| 38 | + return __DIR__ . '/vendor'; |
|
| 39 | + } else { |
|
| 40 | + if (!file_exists(__DIR__ . '/../../')) { |
|
| 41 | + return false; |
|
| 42 | + } else { |
|
| 43 | + return __DIR__ . '/../..'; |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | \ No newline at end of file |
@@ -112,6 +112,10 @@ |
||
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | + /** |
|
| 116 | + * @param string $csl |
|
| 117 | + * @param string $lang |
|
| 118 | + */ |
|
| 115 | 119 | private function init($csl, $lang) { |
| 116 | 120 | // define field values appropriate to your data in the csl_mapper class and un-comment the next line. |
| 117 | 121 | $this->mapper = new Mapper(); |
@@ -108,7 +108,7 @@ |
||
| 108 | 108 | */ |
| 109 | 109 | function __construct($csl = NULL, $lang = 'en') { |
| 110 | 110 | if ($csl) { |
| 111 | - $this->init($csl, $lang); |
|
| 111 | + $this->init($csl, $lang); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
@@ -92,13 +92,13 @@ |
||
| 92 | 92 | * @throws \Exception |
| 93 | 93 | */ |
| 94 | 94 | public static function loadStyleSheet($name) { |
| 95 | - include_once __DIR__.'/../vendorPath.php'; |
|
| 95 | + include_once __DIR__ . '/../vendorPath.php'; |
|
| 96 | 96 | |
| 97 | 97 | if (!($vendorPath = vendorPath())) { |
| 98 | 98 | throw new \Exception('Error: vendor path not found. Use composer to initialize your project'); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - return file_get_contents($vendorPath.'/academicpuma/styles/'.$name.'.csl'); |
|
| 101 | + return file_get_contents($vendorPath . '/academicpuma/styles/' . $name . '.csl'); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -35,6 +35,9 @@ |
||
| 35 | 35 | parent::initFormatting(); |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | + /** |
|
| 39 | + * @param string $mode |
|
| 40 | + */ |
|
| 38 | 41 | public function render($data, $mode = null) |
| 39 | 42 | { |
| 40 | 43 | //$text = ''; |
@@ -91,6 +91,9 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | protected $styleLocale; |
| 93 | 93 | |
| 94 | + /** |
|
| 95 | + * @param string $lang |
|
| 96 | + */ |
|
| 94 | 97 | private static function getLocalesFileName($lang) { |
| 95 | 98 | |
| 96 | 99 | include_once __DIR__.'/../vendorPath.php'; |
@@ -136,6 +139,10 @@ discard block |
||
| 136 | 139 | } |
| 137 | 140 | } |
| 138 | 141 | |
| 142 | + /** |
|
| 143 | + * @param string $type |
|
| 144 | + * @param string $arg3 |
|
| 145 | + */ |
|
| 139 | 146 | public function locale($type, $arg1, $arg2 = NULL, $arg3 = NULL) { |
| 140 | 147 | |
| 141 | 148 | switch ($type) { |
@@ -113,7 +113,7 @@ |
||
| 113 | 113 | public function __construct($lang = 'en') { |
| 114 | 114 | |
| 115 | 115 | $this->module_path = dirname(__FILE__); |
| 116 | - $this->locale = new \SimpleXMLElement(self::getLocalesFileName($lang)); |
|
| 116 | + $this->locale = new \SimpleXMLElement(self::getLocalesFileName($lang)); |
|
| 117 | 117 | |
| 118 | 118 | if ($this->locale) { |
| 119 | 119 | $this->locale->registerXPathNamespace('cs', 'http://purl.org/net/xbiblio/csl'); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | private static function getLocalesFileName($lang) { |
| 95 | 95 | |
| 96 | - include_once __DIR__.'/../vendorPath.php'; |
|
| 96 | + include_once __DIR__ . '/../vendorPath.php'; |
|
| 97 | 97 | |
| 98 | 98 | if (!($vendorPath = vendorPath())) { |
| 99 | 99 | throw new \Exception('Error: vendor path not found. Use composer to initialize your project'); |
@@ -101,10 +101,10 @@ discard block |
||
| 101 | 101 | |
| 102 | 102 | $localeFile = null; |
| 103 | 103 | |
| 104 | - if(isset(self::$langBase[$lang])) { |
|
| 105 | - $localeFile = file_get_contents($vendorPath.'/academicpuma/locales/locales-' . self::$langBase[$lang] . '.xml'); |
|
| 104 | + if (isset(self::$langBase[$lang])) { |
|
| 105 | + $localeFile = file_get_contents($vendorPath . '/academicpuma/locales/locales-' . self::$langBase[$lang] . '.xml'); |
|
| 106 | 106 | } else { |
| 107 | - $localeFile = file_get_contents($vendorPath.'/academicpuma/locales/locales-en-US.xml'); |
|
| 107 | + $localeFile = file_get_contents($vendorPath . '/academicpuma/locales/locales-en-US.xml'); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | return $localeFile; |
@@ -218,8 +218,9 @@ |
||
| 218 | 218 | $option = $this->locale->xpath("//cs:style-options[@$arg1]"); |
| 219 | 219 | } |
| 220 | 220 | foreach ($option[0]->attributes() as $name => $value) { |
| 221 | - if ($name == $arg1) |
|
| 222 | - return (string) $value; |
|
| 221 | + if ($name == $arg1) { |
|
| 222 | + return (string) $value; |
|
| 223 | + } |
|
| 223 | 224 | } |
| 224 | 225 | break; |
| 225 | 226 | } |
@@ -306,6 +306,9 @@ |
||
| 306 | 306 | $print, $punct, $space, $upper, $word, $patternModifiers); |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | + /** |
|
| 310 | + * @return string |
|
| 311 | + */ |
|
| 309 | 312 | protected function format($text, $part = 'base') |
| 310 | 313 | { |
| 311 | 314 | |
@@ -169,9 +169,9 @@ |
||
| 169 | 169 | |
| 170 | 170 | if ($this->form == 'count') { |
| 171 | 171 | if (!$et_al_triggered) { |
| 172 | - return (int)count($authors); |
|
| 172 | + return (int) count($authors); |
|
| 173 | 173 | } else { |
| 174 | - return (int)(count($authors) - 1); |
|
| 174 | + return (int) (count($authors) - 1); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | // strip out the last delimiter if not required |
@@ -58,8 +58,9 @@ discard block |
||
| 58 | 58 | $auth_count = 0; |
| 59 | 59 | $et_al_triggered = false; |
| 60 | 60 | |
| 61 | - if (!$this->attr_init || $this->attr_init != $mode) |
|
| 62 | - $this->initAttributes($mode); |
|
| 61 | + if (!$this->attr_init || $this->attr_init != $mode) { |
|
| 62 | + $this->initAttributes($mode); |
|
| 63 | + } |
|
| 63 | 64 | |
| 64 | 65 | $initialize_with = $this->{'initialize-with'}; |
| 65 | 66 | |
@@ -123,8 +124,9 @@ discard block |
||
| 123 | 124 | } |
| 124 | 125 | $authors[] = trim($this->format($text)); |
| 125 | 126 | } |
| 126 | - if (isset($this->{'et-al-min'}) && $count >= $this->{'et-al-min'}) |
|
| 127 | - break; |
|
| 127 | + if (isset($this->{'et-al-min'}) && $count >= $this->{'et-al-min'}) { |
|
| 128 | + break; |
|
| 129 | + } |
|
| 128 | 130 | } |
| 129 | 131 | if (isset($this->{'et-al-min'}) && |
| 130 | 132 | $count >= $this->{'et-al-min'} && |
@@ -309,8 +311,9 @@ discard block |
||
| 309 | 311 | protected function format($text, $part = 'base') |
| 310 | 312 | { |
| 311 | 313 | |
| 312 | - if (empty($text) || $this->noOp[$part]) |
|
| 313 | - return $text; |
|
| 314 | + if (empty($text) || $this->noOp[$part]) { |
|
| 315 | + return $text; |
|
| 316 | + } |
|
| 314 | 317 | if (isset($this->{$part}['text-case'])) { |
| 315 | 318 | switch ($this->{$part}['text-case']) { |
| 316 | 319 | case 'uppercase': |
@@ -332,8 +335,9 @@ discard block |
||
| 332 | 335 | $close_quote = isset($this->{$part}['close-quote']) ? $this->{$part}['close-quote'] : ''; |
| 333 | 336 | $prefix = isset($this->{$part}['prefix']) ? $this->{$part}['prefix'] : ''; |
| 334 | 337 | $suffix = isset($this->{$part}['suffix']) ? $this->{$part}['suffix'] : ''; |
| 335 | - if ($text[(strlen($text) - 1)] == $suffix) |
|
| 336 | - unset($suffix); |
|
| 338 | + if ($text[(strlen($text) - 1)] == $suffix) { |
|
| 339 | + unset($suffix); |
|
| 340 | + } |
|
| 337 | 341 | if (!empty($this->format[$part])) { |
| 338 | 342 | $text = '<span style="' . $this->format[$part] . '">' . $text . '</span>'; |
| 339 | 343 | } |
@@ -381,10 +385,12 @@ discard block |
||
| 381 | 385 | $this->noOp[$part] = false; |
| 382 | 386 | } |
| 383 | 387 | |
| 384 | - if (isset($attribs['prefix'])) |
|
| 385 | - $this->{$part}['prefix'] = $attribs['prefix']; |
|
| 386 | - if (isset($attribs['suffix'])) |
|
| 387 | - $this->{$part}['suffix'] = $attribs['suffix']; |
|
| 388 | + if (isset($attribs['prefix'])) { |
|
| 389 | + $this->{$part}['prefix'] = $attribs['prefix']; |
|
| 390 | + } |
|
| 391 | + if (isset($attribs['suffix'])) { |
|
| 392 | + $this->{$part}['suffix'] = $attribs['suffix']; |
|
| 393 | + } |
|
| 388 | 394 | |
| 389 | 395 | $this->format[$part] .= (isset($attribs['font-style'])) ? 'font-style: ' . $attribs['font-style'] . ';' : ''; |
| 390 | 396 | $this->format[$part] .= (isset($attribs['font-family'])) ? 'font-family: ' . $attribs['font-family'] . ';' : ''; |
@@ -397,8 +403,9 @@ discard block |
||
| 397 | 403 | $this->noOp[$part] = false; |
| 398 | 404 | $this->{$part}['text-case'] = $attribs['text-case']; |
| 399 | 405 | } |
| 400 | - if (!empty($this->format[$part])) |
|
| 401 | - $this->noOp[$part] = false; |
|
| 406 | + if (!empty($this->format[$part])) { |
|
| 407 | + $this->noOp[$part] = false; |
|
| 408 | + } |
|
| 402 | 409 | } |
| 403 | 410 | |
| 404 | 411 | } |
| 405 | 412 | \ No newline at end of file |
@@ -56,7 +56,7 @@ |
||
| 56 | 56 | if (empty(HierAttributes::$arr)) { |
| 57 | 57 | $refClass = new \ReflectionClass('\AcademicPuma\CiteProc\HierAttributes'); |
| 58 | 58 | $constants = $refClass->getConstants(); |
| 59 | - array_walk($constants, function ($value) { |
|
| 59 | + array_walk($constants, function($value) { |
|
| 60 | 60 | HierAttributes::$arr[$value] = $value; |
| 61 | 61 | }); |
| 62 | 62 | } |
@@ -94,9 +94,10 @@ |
||
| 94 | 94 | } |
| 95 | 95 | // now re-order the elements |
| 96 | 96 | foreach ($parts as $part) { |
| 97 | - foreach ($locale_elements as $key => $element) |
|
| 98 | - if ($element->name == $part) { |
|
| 97 | + foreach ($locale_elements as $key => $element) { |
|
| 98 | + if ($element->name == $part) { |
|
| 99 | 99 | $this->elements[] = $element; |
| 100 | + } |
|
| 100 | 101 | unset($locale_elements[$key]); |
| 101 | 102 | } |
| 102 | 103 | } |
@@ -55,8 +55,9 @@ discard block |
||
| 55 | 55 | foreach ($domNode->childNodes as $node) { |
| 56 | 56 | if ($node->nodeType == 1) { |
| 57 | 57 | $element = Factory::create($node, $citeProc); |
| 58 | - if (($element instanceof Label)) |
|
| 59 | - $element->variable = $var; |
|
| 58 | + if (($element instanceof Label)) { |
|
| 59 | + $element->variable = $var; |
|
| 60 | + } |
|
| 60 | 61 | if (($element instanceof Name) && $etal) { |
| 61 | 62 | $element->etal = $etal; |
| 62 | 63 | } |
@@ -79,8 +80,9 @@ discard block |
||
| 79 | 80 | $variables = explode(' ', $this->variable); |
| 80 | 81 | |
| 81 | 82 | foreach ($variables as $var) { |
| 82 | - if (in_array($var, $this->citeProc->quash)) |
|
| 83 | - continue; |
|
| 83 | + if (in_array($var, $this->citeProc->quash)) { |
|
| 84 | + continue; |
|
| 85 | + } |
|
| 84 | 86 | if (isset($data->{$var}) && (!empty($data->{$var}))) { |
| 85 | 87 | $matches[] = $var; |
| 86 | 88 | } |
@@ -100,18 +102,21 @@ discard block |
||
| 100 | 102 | } else { // if it's not a "names" element, just render it |
| 101 | 103 | $text = $element->render($data, $mode); |
| 102 | 104 | $this->citeProc->quash[] = isset($element->variable) ? $element->variable : $element->var; |
| 103 | - if (!empty($text)) |
|
| 104 | - $variable_parts[] = $text; |
|
| 105 | + if (!empty($text)) { |
|
| 106 | + $variable_parts[] = $text; |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + if (!empty($matches)) { |
|
| 110 | + break; |
|
| 105 | 111 | } |
| 106 | - if (!empty($matches)) |
|
| 107 | - break; |
|
| 108 | 112 | } |
| 109 | 113 | } |
| 110 | 114 | } |
| 111 | 115 | |
| 112 | 116 | foreach ($matches as $var) { |
| 113 | - if (in_array($var, $this->citeProc->quash) && in_array($var, $variables)) |
|
| 114 | - continue; |
|
| 117 | + if (in_array($var, $this->citeProc->quash) && in_array($var, $variables)) { |
|
| 118 | + continue; |
|
| 119 | + } |
|
| 115 | 120 | $text = ''; |
| 116 | 121 | if (!empty($data->{$var})) { |
| 117 | 122 | foreach ($this->elements as $element) { |
@@ -123,8 +128,9 @@ discard block |
||
| 123 | 128 | } |
| 124 | 129 | } |
| 125 | 130 | } |
| 126 | - if (!empty($text)) |
|
| 127 | - $variable_parts[] = $text; |
|
| 131 | + if (!empty($text)) { |
|
| 132 | + $variable_parts[] = $text; |
|
| 133 | + } |
|
| 128 | 134 | } |
| 129 | 135 | |
| 130 | 136 | if (!empty($variable_parts)) { |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | $element_count++; |
| 37 | 37 | if (($element instanceof Text) && |
| 38 | 38 | ($element->source == 'term' || |
| 39 | - $element->source == 'value' )) { |
|
| 39 | + $element->source == 'value')) { |
|
| 40 | 40 | $terms++; |
| 41 | 41 | } |
| 42 | 42 | if (($element instanceof Label)) { |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | } |
| 63 | 63 | } |
| 64 | 64 | //give the text parts a name |
| 65 | - if($element instanceof Text) { |
|
| 65 | + if ($element instanceof Text) { |
|
| 66 | 66 | $text_parts[$element->getVar()] = $text; |
| 67 | 67 | } else { |
| 68 | 68 | $text_parts[$element_count] = $text; |
@@ -78,12 +78,17 @@ |
||
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | - if (empty($text_parts)) |
|
| 82 | - return; |
|
| 83 | - if ($variables && !$have_variables) |
|
| 84 | - return; // there has to be at least one other none empty value before the term is output |
|
| 85 | - if (count($text_parts) == $terms) |
|
| 86 | - return; // there has to be at least one other none empty value before the term is output |
|
| 81 | + if (empty($text_parts)) { |
|
| 82 | + return; |
|
| 83 | + } |
|
| 84 | + if ($variables && !$have_variables) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + // there has to be at least one other none empty value before the term is output |
|
| 88 | + if (count($text_parts) == $terms) { |
|
| 89 | + return; |
|
| 90 | + } |
|
| 91 | + // there has to be at least one other none empty value before the term is output |
|
| 87 | 92 | $delimiter = $this->delimiter; |
| 88 | 93 | //$text = implode($delimiter, $text_parts); // insert the delimiter if supplied. |
| 89 | 94 | $text = $this->implodeGroup($delimiter, $text_parts); |