[ Index ] |
PHP Cross Reference of phpBB-3.1.12-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\user */ 22 protected $user; 23 24 /** 25 * Constructor 26 * 27 * @param \phpbb\template\context $context 28 * @param \phpbb\user $user 29 * @return \phpbb\template\twig\extension 30 */ 31 public function __construct(\phpbb\template\context $context, $user) 32 { 33 $this->context = $context; 34 $this->user = $user; 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 new \Twig_SimpleFilter('addslashes', 'addslashes'), 75 ); 76 } 77 78 /** 79 * Returns a list of global functions to add to the existing list. 80 * 81 * @return array An array of global functions 82 */ 83 public function getFunctions() 84 { 85 return array( 86 new \Twig_SimpleFunction('lang', array($this, 'lang')), 87 ); 88 } 89 90 /** 91 * Returns a list of operators to add to the existing list. 92 * 93 * @return array An array of operators 94 */ 95 public function getOperators() 96 { 97 return array( 98 array( 99 '!' => array('precedence' => 50, 'class' => 'Twig_Node_Expression_Unary_Not'), 100 ), 101 array( 102 // precedence settings are copied from similar operators in Twig core extension 103 '||' => array('precedence' => 10, 'class' => 'Twig_Node_Expression_Binary_Or', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 104 '&&' => array('precedence' => 15, 'class' => 'Twig_Node_Expression_Binary_And', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 105 106 'eq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Equal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 107 108 'ne' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 109 'neq' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 110 '<>' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_NotEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 111 112 '===' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\equalequal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 113 '!==' => array('precedence' => 20, 'class' => '\phpbb\template\twig\node\expression\binary\notequalequal', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 114 115 'gt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Greater', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 116 'gte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 117 'ge' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_GreaterEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 118 'lt' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_Less', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 119 'lte' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 120 'le' => array('precedence' => 20, 'class' => 'Twig_Node_Expression_Binary_LessEqual', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 121 122 'mod' => array('precedence' => 60, 'class' => 'Twig_Node_Expression_Binary_Mod', 'associativity' => \Twig_ExpressionParser::OPERATOR_LEFT), 123 ), 124 ); 125 } 126 127 /** 128 * Grabs a subset of a loop 129 * 130 * @param \Twig_Environment $env A Twig_Environment instance 131 * @param mixed $item A variable 132 * @param integer $start Start of the subset 133 * @param integer $end End of the subset 134 * @param Boolean $preserveKeys Whether to preserve key or not (when the input is an array) 135 * 136 * @return mixed The sliced variable 137 */ 138 function loop_subset(\Twig_Environment $env, $item, $start, $end = null, $preserveKeys = false) 139 { 140 // We do almost the same thing as Twig's slice (array_slice), except when $end is positive 141 if ($end >= 1) 142 { 143 // When end is > 1, subset will end on the last item in an array with the specified $end 144 // This is different from slice in that it is the number we end on rather than the number 145 // of items to grab (length) 146 147 // Start must always be the actual starting number for this calculation (not negative) 148 $start = ($start < 0) ? sizeof($item) + $start : $start; 149 $end = $end - $start; 150 } 151 152 // We always include the last element (this was the past design) 153 $end = ($end == -1 || $end === null) ? null : $end + 1; 154 155 return twig_slice($env, $item, $start, $end, $preserveKeys); 156 } 157 158 /** 159 * Get output for a language variable (L_FOO, LA_FOO) 160 * 161 * This function checks to see if the language var was outputted to $context 162 * (e.g. in the ACP, L_TITLE) 163 * If not, we return the result of $user->lang() 164 * 165 * @return string 166 */ 167 function lang() 168 { 169 $args = func_get_args(); 170 $key = $args[0]; 171 172 $context_vars = $this->context->get_root_ref(); 173 174 if (isset($context_vars['L_' . $key])) 175 { 176 return $context_vars['L_' . $key]; 177 } 178 179 // LA_ is transformed into lang(\'$1\')|addslashes, so we should not 180 // need to check for it 181 182 return call_user_func_array(array($this->user, 'lang'), $args); 183 } 184 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |