[ Index ] |
PHP Cross Reference of phpBB-3.2.11-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\template\twig; 15 16 class extension extends \Twig_Extension 17 { 18 /** @var \phpbb\template\context */ 19 protected $context; 20 21 /** @var \phpbb\language\language */ 22 protected $language; 23 24 /** 25 * Constructor 26 * 27 * @param \phpbb\template\context $context 28 * @param \phpbb\language\language $language 29 * @return \phpbb\template\twig\extension 30 */ 31 public function __construct(\phpbb\template\context $context, $language) 32 { 33 $this->context = $context; 34 $this->language = $language; 35 } 36 37 /** 38 * Get the name of this extension 39 * 40 * @return string 41 */ 42 public function getName() 43 { 44 return 'phpbb'; 45 } 46 47 /** 48 * Returns the token parser instance to add to the existing list. 49 * 50 * @return array An array of Twig_TokenParser instances 51 */ 52 public function getTokenParsers() 53 { 54 return array( 55 new \phpbb\template\twig\tokenparser\defineparser, 56 new \phpbb\template\twig\tokenparser\includeparser, 57 new \phpbb\template\twig\tokenparser\includejs, 58 new \phpbb\template\twig\tokenparser\includecss, 59 new \phpbb\template\twig\tokenparser\event, 60 new \phpbb\template\twig\tokenparser\includephp, 61 new \phpbb\template\twig\tokenparser\php, 62 ); 63 } 64 65 /** 66 * Returns a list of filters to add to the existing list. 67 * 68 * @return array An array of filters 69 */ 70 public function getFilters() 71 { 72 return array( 73 new \Twig_SimpleFilter('subset', array($this, 'loop_subset'), array('needs_environment' => true)), 74 // @deprecated 3.2.0 Uses twig's JS escape method instead of addslashes 75 new \Twig_SimpleFilter('addslashes', 'addslashes'), 76 ); 77 } 78 79 /** 80 * Returns a list of global functions to add to the existing list. 81 * 82 * @return array An array of global functions 83 */ 84 public function getFunctions() 85 { 86 return array( 87 new \Twig_SimpleFunction('lang', array($this, 'lang')), 88 ); 89 } 90 91 /** 92 * Returns a list of operators to add to the existing list. 93 * 94 * @return array An array of operators 95 */ 96 public function getOperators() 97 { 98 return array( 99 array( 100 '!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'), 101 ), 102 array( 103 // precedence settings are copied from similar operators in Twig core extension 104 '||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 105 '&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 106 107 'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 108 109 'ne' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 110 'neq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 111 '<>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 112 113 '===' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\equalequal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 114 '!==' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\notequalequal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 115 116 'gt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 117 'gte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 118 'ge' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 119 'lt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 120 'lte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 121 'le' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 122 123 'mod' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 124 ), 125 ); 126 } 127 128 /** 129 * Grabs a subset of a loop 130 * 131 * @param \Twig_Environment $env A Twig_Environment instance 132 * @param mixed $item A variable 133 * @param integer $start Start of the subset 134 * @param integer $end End of the subset 135 * @param Boolean $preserveKeys Whether to preserve key or not (when the input is an array) 136 * 137 * @return mixed The sliced variable 138 */ 139 function loop_subset(\Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false) 140 { 141 // We do almost the same thing as Twig's slice (array_slice), except when $end is positive 142 if ($end >= 1) 143 { 144 // When end is > 1, subset will end on the last item in an array with the specified $end 145 // This is different from slice in that it is the number we end on rather than the number 146 // of items to grab (length) 147 148 // Start must always be the actual starting number for this calculation (not negative) 149 $start = ($start < 0) ? count($item) + $start : $start; 150 $end = $end - $start; 151 } 152 153 // We always include the last element (this was the past design) 154 $end = ($end == -1 || $end === null) ? null : $end + 1; 155 156 return twig_slice($env, $item, $start, $end, $preserveKeys); 157 } 158 159 /** 160 * Get output for a language variable (L_FOO, LA_FOO) 161 * 162 * This function checks to see if the language var was outputted to $context 163 * (e.g. in the ACP, L_TITLE) 164 * If not, we return the result of $user->lang() 165 * 166 * @return string 167 */ 168 function lang() 169 { 170 $args = func_get_args(); 171 $key = $args[0]; 172 173 $context_vars = $this->context->get_root_ref(); 174 175 if (is_string($key) && isset($context_vars['L_' . $key])) 176 { 177 return $context_vars['L_' . $key]; 178 } 179 180 // LA_ is transformed into lang(\'$1\')|escape('js'), so we should not 181 // need to check for it 182 183 return call_user_func_array(array($this->language, 'lang'), $args); 184 } 185 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 11 20:33:01 2020 | Cross-referenced by PHPXref 0.7.1 |