| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  * citeproc-php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @link        http://github.com/seboettg/citeproc-php for the source repository | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @copyright   Copyright (c) 2017 Sebastian Böttger. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @license     https://opensource.org/licenses/MIT | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | namespace Seboettg\CiteProc\Util; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Seboettg\CiteProc\CiteProc; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use stdClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | class CiteProcHelper | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      * Applies additional functions for markup extension | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |      * @param stdClass $dataItem the actual item | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @param string $valueToRender value the has to apply on | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @param string $renderedText actual by citeproc rendered text | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 | 170 |  |     public static function applyAdditionMarkupFunction($dataItem, $valueToRender, $renderedText) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 | 170 |  |         $markupExtension = CiteProc::getContext()->getMarkupExtension(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 | 170 |  |         if (array_key_exists($valueToRender, $markupExtension)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 | 3 |  |         	if (is_array($markupExtension[$valueToRender]) && array_key_exists('function', $markupExtension[$valueToRender])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 | 1 |  | 				$function = $markupExtension[$valueToRender]['function']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 			} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 | 2 |  | 				$function = $markupExtension[$valueToRender]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 			} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 | 3 |  |             if (is_callable($function)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 | 3 |  |                 $renderedText = $function($dataItem, $renderedText); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 | 170 |  |         } elseif (array_key_exists($mode = CiteProc::getContext()->getMode(), $markupExtension)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 | 2 |  |             if (array_key_exists($valueToRender, $markupExtension[$mode])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 | 2 |  | 				if (is_array($markupExtension[$mode][$valueToRender]) && array_key_exists('function', $markupExtension[$mode][$valueToRender])) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 					$function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]['function']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 				} else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 | 2 |  | 					$function = CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 				} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 | 2 |  |                 if (is_callable($function)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 | 2 |  |                     $renderedText = $function($dataItem, $renderedText); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 | 170 |  |         return $renderedText; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      * @param array $array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 166 |  |     public static function cloneArray(array $array) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 166 |  |         $newArray = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 166 |  |         foreach ($array as $key => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 166 |  |             $newArray[$key] = clone $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 166 |  |         return $newArray; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	 * @param stdClass $dataItem the actual item | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	 * @param string $valueToRender value the has to apply on | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	 * @return bool | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 70 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 71 | 103 |  |     public static function isUsingAffixesByMarkupExtentsion($dataItem, $valueToRender) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 73 | 103 |  | 		$markupExtension = CiteProc::getContext()->getMarkupExtension(); | 
            
                                                                        
                            
            
                                    
            
            
                | 74 | 103 |  | 		if (array_key_exists($valueToRender, $markupExtension)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 75 | 3 |  | 			if (is_array($markupExtension[$valueToRender]) && array_key_exists('affixes', $markupExtension[$valueToRender])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 76 | 3 |  | 				return $markupExtension[$valueToRender]['affixes']; | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 78 | 103 |  | 		} elseif (array_key_exists($mode = CiteProc::getContext()->getMode(), $markupExtension)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 79 | 2 |  | 			if (array_key_exists($valueToRender, $markupExtension[$mode])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 80 | 1 |  | 				if (is_array($markupExtension[$mode][$valueToRender]) && array_key_exists('affixes', $markupExtension[$mode][$valueToRender])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  | 					return CiteProc::getContext()->getMarkupExtension()[$mode][$valueToRender]['affixes']; | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  | 				} | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  | 			} | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  | 		} | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 86 | 103 |  | 		return FALSE; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 	} | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 88 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |  | 
            
                        
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.