| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * citeproc-php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @link        http://github.com/seboettg/citeproc-php for the source repository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright   Copyright (c) 2016 Sebastian Böttger. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license     https://opensource.org/licenses/MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | namespace Seboettg\CiteProc\Rendering; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Seboettg\CiteProc\CiteProc; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Seboettg\CiteProc\Exception\CiteProcException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Seboettg\CiteProc\RenderingState; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Seboettg\CiteProc\Styles\AffixesTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Seboettg\CiteProc\Styles\ConsecutivePunctuationCharacterTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Seboettg\CiteProc\Styles\DisplayTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Seboettg\CiteProc\Styles\FormattingTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Seboettg\CiteProc\Styles\QuotesTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | use Seboettg\CiteProc\Styles\TextCaseTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | use Seboettg\CiteProc\Terms\Locator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | use Seboettg\CiteProc\Util\CiteProcHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | use Seboettg\CiteProc\Util\NumberHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | use Seboettg\CiteProc\Util\PageHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | use Seboettg\CiteProc\Util\StringHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  | use SimpleXMLElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | use stdClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | use function Seboettg\CiteProc\ucfirst; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * Class Term | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  * @package Seboettg\CiteProc\Node\Style | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  * @author Sebastian Böttger <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | class Text implements Rendering | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     use FormattingTrait, | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         AffixesTrait, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         TextCaseTrait, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         DisplayTrait, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         ConsecutivePunctuationCharacterTrait, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         QuotesTrait; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     private $toRenderType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     private $toRenderTypeValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     private $form = "long"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * Text constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      * @param SimpleXMLElement $node | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 119 |  |     public function __construct(SimpleXMLElement $node) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 | 119 |  |         foreach ($node->attributes() as $attribute) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 119 |  |             $name = $attribute->getName(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 119 |  |             if (in_array($name, ['value', 'variable', 'macro', 'term'])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 119 |  |                 $this->toRenderType = $name; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 | 119 |  |                 $this->toRenderTypeValue = (string) $attribute; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 | 119 |  |             if ($name === "form") { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 43 |  |                 $this->form = (string) $attribute; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 119 |  |         $this->initFormattingAttributes($node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 119 |  |         $this->initDisplayAttributes($node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 119 |  |         $this->initTextCaseAttributes($node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 119 |  |         $this->initAffixesAttributes($node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 | 119 |  |         $this->initQuotesAttributes($node); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 | 119 |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |      * @param  stdClass $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |      * @param  int|null $citationNumber | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 89 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 90 | 103 |  |     public function render($data, $citationNumber = null) | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 92 | 103 |  |         $lang = (isset($data->language) && $data->language != 'en') ? $data->language : 'en'; | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 94 | 103 |  |         $renderedText = ""; | 
            
                                                                        
                            
            
                                    
            
            
                | 95 | 103 |  |         switch ($this->toRenderType) { | 
            
                                                                        
                            
            
                                    
            
            
                | 96 | 103 |  |             case 'value': | 
            
                                                                        
                            
            
                                    
            
            
                | 97 | 26 |  |                 $renderedText = $this->applyTextCase($this->toRenderTypeValue, $lang); | 
            
                                                                        
                            
            
                                    
            
            
                | 98 | 26 |  |                 break; | 
            
                                                                        
                            
            
                                    
            
            
                | 99 | 96 |  |             case 'variable': | 
            
                                                                        
                            
            
                                    
            
            
                | 100 | 86 |  |                 if ($this->toRenderTypeValue === "locator" && CiteProc::getContext()->isModeCitation()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 101 | 8 |  |                     $renderedText = $this->renderLocator($data, $citationNumber); | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |                 // for test sort_BibliographyCitationNumberDescending.json | 
            
                                                                        
                            
            
                                    
            
            
                | 103 | 86 |  |                 } elseif ($this->toRenderTypeValue === "citation-number") { | 
            
                                                                        
                            
            
                                    
            
            
                | 104 | 16 |  |                     $renderedText = $this->renderCitationNumber($data, $citationNumber); | 
            
                                                                        
                            
            
                                    
            
            
                | 105 | 16 |  |                     break; | 
            
                                                                        
                            
            
                                    
            
            
                | 106 | 82 |  |                 } elseif (in_array($this->toRenderTypeValue, ["page", "chapter-number", "folio"])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 107 | 34 |  |                     $renderedText = !empty($data->{$this->toRenderTypeValue}) ? | 
            
                                                                        
                            
            
                                    
            
            
                | 108 | 34 |  |                         $this->renderPage($data->{$this->toRenderTypeValue}) : ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |                 } else { | 
            
                                                                        
                            
            
                                    
            
            
                | 110 | 78 |  |                     $renderedText = $this->renderVariable($data, $lang); | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 112 | 84 |  |                 if (CiteProc::getContext()->getRenderingState()->getValue() === RenderingState::SUBSTITUTION) { | 
            
                                                                        
                            
            
                                    
            
            
                | 113 | 7 |  |                     unset($data->{$this->toRenderTypeValue}); | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 115 | 84 |  |                 if (!CiteProcHelper::isUsingAffixesByMarkupExtentsion($data, $this->toRenderTypeValue)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 116 | 84 |  | 					$renderedText = $this->applyAdditionalMarkupFunction($data, $renderedText); | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  | 				} | 
            
                                                                        
                            
            
                                    
            
            
                | 118 | 84 |  |                 break; | 
            
                                                                        
                            
            
                                    
            
            
                | 119 | 70 |  |             case 'macro': | 
            
                                                                        
                            
            
                                    
            
            
                | 120 | 63 |  |                 $renderedText = $this->renderMacro($data); | 
            
                                                                        
                            
            
                                    
            
            
                | 121 | 63 |  |                 break; | 
            
                                                                        
                            
            
                                    
            
            
                | 122 | 26 |  |             case 'term': | 
            
                                                                        
                            
            
                                    
            
            
                | 123 | 26 |  |                 $term = CiteProc::getContext() | 
            
                                                                        
                            
            
                                    
            
            
                | 124 | 26 |  |                     ->getLocale() | 
            
                                                                        
                            
            
                                    
            
            
                | 125 | 26 |  |                     ->filter("terms", $this->toRenderTypeValue, $this->form) | 
            
                                                                        
                            
            
                                    
            
            
                | 126 | 26 |  |                     ->single; | 
            
                                                                        
                            
            
                                    
            
            
                | 127 | 26 |  |                 $renderedText = !empty($term) ? $this->applyTextCase($term, $lang) : ""; | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 129 | 103 |  |         if (!empty($renderedText)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 130 | 103 |  |             $renderedText = $this->formatRenderedText($data, $renderedText); | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 132 | 103 |  |         return $renderedText; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 | 67 |  |     public function getSource() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 | 67 |  |         return $this->toRenderType; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 | 67 |  |     public function getVariable() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 | 67 |  |         return $this->toRenderTypeValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 | 23 |  |     private function renderPage($page) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 | 23 |  |         if (preg_match(NumberHelper::PATTERN_COMMA_AMPERSAND_RANGE, $page)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 | 21 |  |             $page = $this->normalizeDateRange($page); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 | 21 |  |             $ranges = preg_split("/[-–]/", trim($page)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 | 21 |  |             if (count($ranges) > 1) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 | 20 |  |                 if (!empty(CiteProc::getContext()->getGlobalOptions()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 | 20 |  |                     && !empty(CiteProc::getContext()->getGlobalOptions()->getPageRangeFormat()) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |                 ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 | 9 |  |                     return PageHelper::processPageRangeFormats( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 | 9 |  |                         $ranges, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 | 9 |  |                         CiteProc::getContext()->getGlobalOptions()->getPageRangeFormat() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |                     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 | 11 |  |                 list($from, $to) = $ranges; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 | 11 |  |                 return $from . "–" . $to; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 | 4 |  |         return $page; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 | 8 |  |     private function renderLocator($data, $citationNumber) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 | 8 |  |         $citationItem = CiteProc::getContext()->getCitationItemById($data->id); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 | 8 |  |         if (!empty($citationItem->label)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 | 4 |  |             $locatorData = new stdClass(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 | 4 |  |             $propertyName = Locator::mapLocatorLabelToRenderVariable($citationItem->label); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 | 4 |  |             $locatorData->{$propertyName} = trim($citationItem->locator); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 | 4 |  |             $renderTypeValueTemp = $this->toRenderTypeValue; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 | 4 |  |             $this->toRenderTypeValue = $propertyName; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 | 4 |  |             $result = $this->render($locatorData, $citationNumber); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 | 4 |  |             $this->toRenderTypeValue = $renderTypeValueTemp; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 | 4 |  |             return $result; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 | 4 |  |         return isset($citationItem->locator) ? trim($citationItem->locator) : ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 | 21 |  |     private function normalizeDateRange($page) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 | 21 |  |         if (preg_match("/^(\d+)\s?--?\s?(\d+)$/", trim($page), $matches)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 | 20 |  |             return $matches[1]."-".$matches[2]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 | 1 |  |         return $page; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |      * @param  $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |      * @param  $renderedText | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |      * @return mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 | 86 |  |     private function applyAdditionalMarkupFunction($data, $renderedText) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 | 86 |  |         return CiteProcHelper::applyAdditionMarkupFunction($data, $this->toRenderTypeValue, $renderedText); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |      * @param  $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |      * @param  $lang | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 | 78 |  |     private function renderVariable($data, $lang) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |         // check if there is an attribute with prefix short or long e.g. shortTitle or longAbstract | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         // test case group_ShortOutputOnly.json | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 | 78 |  |         $value = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 | 78 |  |         if (in_array($this->form, ["short", "long"])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 | 78 |  |             $attrWithPrefix = $this->form . ucfirst($this->toRenderTypeValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 | 78 |  |             $attrWithSuffix = $this->toRenderTypeValue . "-" . $this->form; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 | 78 |  |             if (isset($data->{$attrWithPrefix}) && !empty($data->{$attrWithPrefix})) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 | 1 |  |                 $value = $data->{$attrWithPrefix}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |             } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 | 77 |  |                 if (isset($data->{$attrWithSuffix}) && !empty($data->{$attrWithSuffix})) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 | 3 |  |                     $value = $data->{$attrWithSuffix}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |                 } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 | 77 |  |                     if (isset($data->{$this->toRenderTypeValue})) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 | 78 |  |                         $value = $data->{$this->toRenderTypeValue}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |             if (!empty($data->{$this->toRenderTypeValue})) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |                 $value = $data->{$this->toRenderTypeValue}; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 | 78 |  |         return $this->applyTextCase( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 | 78 |  |             StringHelper::clearApostrophes( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 | 78 |  |                 htmlspecialchars($value, ENT_HTML5) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |             ), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |             $lang | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  | 	 * @param  $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  | 	 * @param  $renderedText | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 | 103 |  |     private function formatRenderedText($data, $renderedText) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 | 103 |  |         $text = $this->format($renderedText); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 | 103 |  |         $res = $this->addAffixes($text); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 | 103 |  | 		if (CiteProcHelper::isUsingAffixesByMarkupExtentsion($data, $this->toRenderTypeValue)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 | 1 |  | 			$res = $this->applyAdditionalMarkupFunction($data, $res); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 | 103 |  |         if (!empty($res)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 | 103 |  |             $res = $this->removeConsecutiveChars($res); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 | 103 |  |         $res = $this->addSurroundingQuotes($res); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 | 103 |  |         return $this->wrapDisplayBlock($res); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |      * @param  $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |      * @param  $citationNumber | 
            
                                                                                                            
                            
            
                                    
            
            
                | 265 |  |  |      * @return int|mixed | 
            
                                                                                                            
                            
            
                                    
            
            
                | 266 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 267 | 16 |  |     private function renderCitationNumber($data, $citationNumber) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 268 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 269 | 16 |  |         $renderedText = $citationNumber + 1; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 270 | 16 |  | 		if (!CiteProcHelper::isUsingAffixesByMarkupExtentsion($data, $this->toRenderTypeValue)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 271 | 15 |  | 			$renderedText = $this->applyAdditionalMarkupFunction($data, $renderedText); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 272 |  |  | 		} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 273 | 16 |  |         return $renderedText; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 274 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 275 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 276 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 277 |  |  |      * @param  $data | 
            
                                                                                                            
                            
            
                                    
            
            
                | 278 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 279 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 280 | 63 |  |     private function renderMacro($data) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 281 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 282 | 63 |  |         $macro = CiteProc::getContext()->getMacro($this->toRenderTypeValue); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 283 | 63 |  |         if (is_null($macro)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 284 |  |  |             try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 285 | 1 |  |                 throw new CiteProcException("Macro \"".$this->toRenderTypeValue."\" does not exist."); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 286 | 1 |  |             } catch (CiteProcException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 287 | 1 |  |                 $renderedText = ""; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 288 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 289 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 290 | 63 |  |             $renderedText = $macro->render($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 291 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 292 | 63 |  |         return $renderedText; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 293 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 294 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 295 |  |  |  |