Index: trunk/extensions/ArrayExtension/ArrayExtension.i18n.php |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | <?php |
3 | | - |
| 3 | + |
4 | 4 | /** |
5 | 5 | * Get translated magic words, if available |
6 | 6 | * |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | */ |
10 | 10 | function efArrayExtensionWords( $lang ) { |
11 | 11 | $words = array(); |
12 | | - |
| 12 | + |
13 | 13 | /** |
14 | 14 | * English |
15 | 15 | */ |
— | — | @@ -19,7 +19,7 @@ |
20 | 20 | 'arraysize' => array( 0, 'arraysize' ), |
21 | 21 | 'arrayindex' => array( 0, 'arrayindex' ), |
22 | 22 | 'arraysearch' => array( 0, 'arraysearch' ), |
23 | | - |
| 23 | + |
24 | 24 | 'arrayunique' => array( 0, 'arrayunique' ), |
25 | 25 | 'arraysort' => array( 0, 'arraysort' ), |
26 | 26 | 'arrayreset' => array( 0, 'arrayreset' ), |
— | — | @@ -32,7 +32,7 @@ |
33 | 33 | 'arraydiff' => array( 0, 'arraydiff' ), |
34 | 34 | 'arraysearcharray' => array( 0, 'arraysearcharray' ), |
35 | 35 | ); |
36 | | - |
| 36 | + |
37 | 37 | # English is used as a fallback, and the English synonyms are |
38 | 38 | # used if a translation has not been provided for a given word |
39 | 39 | return ( $lang == 'en' || !isset( $words[$lang] ) ) |
Index: trunk/extensions/ArrayExtension/ArrayExtension.php |
— | — | @@ -13,40 +13,40 @@ |
14 | 14 | |
15 | 15 | - add experimental table (2 dimension array) data structure |
16 | 16 | * table = header, row+ (1,1....) |
17 | | - * sort_table_by_header (header) |
18 | | - * sort_table_by_col (col) |
| 17 | + * sort_table_by_header (header) |
| 18 | + * sort_table_by_col (col) |
19 | 19 | * print_table (format) e.g. csv, ul, ol, |
20 | | - * add_table_row (array) |
| 20 | + * add_table_row (array) |
21 | 21 | * get_table_row (row) to an array |
22 | | - * add_table_col(array) |
| 22 | + * add_table_col(array) |
23 | 23 | * get_table_col (col) to an array |
24 | 24 | * get_table_header () to an array |
25 | 25 | * get_total_row |
26 | 26 | * get_total_col |
27 | 27 | |
28 | 28 | */ |
29 | | - |
| 29 | + |
30 | 30 | if ( ! defined( 'MEDIAWIKI' ) ) { |
31 | 31 | die( 'This file is a MediaWiki extension, it is not a valid entry point' ); |
32 | 32 | } |
33 | 33 | |
34 | 34 | $wgExtensionFunctions[] = 'efSetupArrayExtension'; |
35 | | - |
| 35 | + |
36 | 36 | $wgExtensionCredits['parserhook'][] = array( |
37 | 37 | 'name' => 'ArrayExtension', |
38 | 38 | 'url' => 'http://www.mediawiki.org/wiki/Extension:ArrayExtension', |
39 | | - 'author' => array ('Li Ding', 'Jie Bao', 'Daniel Werner'), |
| 39 | + 'author' => array ( 'Li Ding', 'Jie Bao', 'Daniel Werner' ), |
40 | 40 | 'description' => 'Store and compute named arrays', |
41 | 41 | 'version' => ArrayExtension::VERSION, |
42 | 42 | |
43 | 43 | ); |
44 | | - |
| 44 | + |
45 | 45 | $wgHooks['LanguageGetMagic'][] = 'efArrayExtensionLanguageGetMagic'; |
46 | 46 | |
47 | 47 | |
48 | 48 | /** |
49 | 49 | * named arrays - an array has a list of values, and could be set to a SET |
50 | | - */ |
| 50 | + */ |
51 | 51 | class ArrayExtension { |
52 | 52 | |
53 | 53 | const VERSION = '1.3.2'; |
— | — | @@ -57,18 +57,18 @@ |
58 | 58 | global $wgHooks; |
59 | 59 | $wgHooks['ParserClearState'][] = &$this; |
60 | 60 | } |
61 | | - |
| 61 | + |
62 | 62 | function onParserClearState( &$parser ) { |
63 | | - $this->mArrayExtension = array(); //remove all arrays to avoid conflicts with job queue or Special:Import or SMW semantic updates |
| 63 | + $this->mArrayExtension = array(); // remove all arrays to avoid conflicts with job queue or Special:Import or SMW semantic updates |
64 | 64 | return true; |
65 | 65 | } |
66 | | - |
67 | | - /////////////////////////////////////////////////////////// |
| 66 | + |
| 67 | + ////////////////////////////////////////////////////////// / |
68 | 68 | // PART 1. constructor |
69 | | - /////////////////////////////////////////////////////////// |
70 | | - |
| 69 | + ////////////////////////////////////////////////////////// / |
| 70 | + |
71 | 71 | /** |
72 | | - * Define an array by a list of 'values' deliminated by 'delimiter', |
| 72 | + * Define an array by a list of 'values' deliminated by 'delimiter', |
73 | 73 | * the delimiter should be perl regular expression pattern |
74 | 74 | * usage: |
75 | 75 | * {{#arraydefine:arrayid|values|delimiter|options}} |
— | — | @@ -76,61 +76,61 @@ |
77 | 77 | * http://us2.php.net/manual/en/book.pcre.php |
78 | 78 | * see also: http://us2.php.net/manual/en/function.preg-split.php |
79 | 79 | */ |
80 | | - function arraydefine( &$parser, $arrayid, $value='', $delimiter = '/\s*,\s*/', $options = '', $delimiter2= ', ', $search='@@@@', $subject='@@@@', $frame=null) { |
81 | | - if (!isset($arrayid)) |
| 80 | + function arraydefine( &$parser, $arrayid, $value = '', $delimiter = '/\s*,\s*/', $options = '', $delimiter2 = ', ', $search = '@@@@', $subject = '@@@@', $frame = null ) { |
| 81 | + if ( !isset( $arrayid ) ) |
82 | 82 | return ''; |
83 | 83 | |
84 | | - //normalize |
85 | | - $value = trim($value); |
86 | | - $delimiter = trim($delimiter); |
87 | | - |
88 | | - if (!$this->is_non_empty ($value) ){ |
| 84 | + // normalize |
| 85 | + $value = trim( $value ); |
| 86 | + $delimiter = trim( $delimiter ); |
| 87 | + |
| 88 | + if ( !$this->is_non_empty ( $value ) ) { |
89 | 89 | $this->mArrayExtension[$arrayid] = array(); |
90 | | - }else if (!$this->is_non_empty($delimiter)){ |
| 90 | + } else if ( !$this->is_non_empty( $delimiter ) ) { |
91 | 91 | $this->mArrayExtension[$arrayid] = array( $value ); |
92 | | - }else{ |
| 92 | + } else { |
93 | 93 | if ( !$this->isValidRegEx( $delimiter ) ) |
94 | | - $delimiter = '/\s*' . preg_quote( $delimiter, '/' ) . '\s*/'; //Anpassung von Daniel Werner (preg_quote) |
95 | | - |
96 | | - $this->mArrayExtension[$arrayid] = preg_split($delimiter, $value); |
97 | | - |
| 94 | + $delimiter = '/\s*' . preg_quote( $delimiter, '/' ) . '\s*/'; // Anpassung von Daniel Werner (preg_quote) |
| 95 | + |
| 96 | + $this->mArrayExtension[$arrayid] = preg_split( $delimiter, $value ); |
| 97 | + |
98 | 98 | // validate if the array has been successfully created |
99 | | - $ret = $this->validate_array_by_arrayid($arrayid); |
100 | | - if ($ret !== true){ |
| 99 | + $ret = $this->validate_array_by_arrayid( $arrayid ); |
| 100 | + if ( $ret !== true ) { |
101 | 101 | return ''; |
102 | 102 | } |
103 | | - |
| 103 | + |
104 | 104 | // now parse the options, and do posterior process on the created array |
105 | | - $ary_option = $this->parse_options($options); |
106 | | - |
| 105 | + $ary_option = $this->parse_options( $options ); |
| 106 | + |
107 | 107 | // make it unique if option is set |
108 | | - if (FALSE !== array_key_exists('unique', $ary_option)){ |
109 | | - $this->arrayunique($parser, $arrayid); |
| 108 | + if ( FALSE !== array_key_exists( 'unique', $ary_option ) ) { |
| 109 | + $this->arrayunique( $parser, $arrayid ); |
110 | 110 | } |
111 | | - |
| 111 | + |
112 | 112 | // sort array if the option is set |
113 | | - $this->arraysort($parser, $arrayid, $this->get_array_value($ary_option,"sort")); |
| 113 | + $this->arraysort( $parser, $arrayid, $this->get_array_value( $ary_option, "sort" ) ); |
114 | 114 | |
115 | 115 | // print the array upon request |
116 | | - if (strcmp("list", $this->get_array_value($ary_option,"print"))===0){ |
117 | | - return $this->arrayprint($parser, $arrayid); |
118 | | - }else if (strcmp("full", $this->get_array_value($ary_option,"print"))===0){ |
119 | | - return $this->arrayprint($parser, $arrayid, $delimiter2, $search, $subject, $frame); |
| 116 | + if ( strcmp( "list", $this->get_array_value( $ary_option, "print" ) ) === 0 ) { |
| 117 | + return $this->arrayprint( $parser, $arrayid ); |
| 118 | + } else if ( strcmp( "full", $this->get_array_value( $ary_option, "print" ) ) === 0 ) { |
| 119 | + return $this->arrayprint( $parser, $arrayid, $delimiter2, $search, $subject, $frame ); |
120 | 120 | } |
121 | 121 | } |
122 | | - |
| 122 | + |
123 | 123 | return ''; |
124 | 124 | } |
125 | 125 | |
126 | 126 | |
127 | | - /////////////////////////////////////////////////////////// |
| 127 | + ////////////////////////////////////////////////////////// / |
128 | 128 | // PART 2. print |
129 | | - /////////////////////////////////////////////////////////// |
| 129 | + ////////////////////////////////////////////////////////// / |
130 | 130 | |
131 | 131 | |
132 | 132 | /** |
133 | 133 | * print an array. |
134 | | - * foreach element of the array, print 'subject' where all occurrences of 'search' is replaced with the element, |
| 134 | + * foreach element of the array, print 'subject' where all occurrences of 'search' is replaced with the element, |
135 | 135 | * and each element print-out is deliminated by 'delimiter' |
136 | 136 | * The subject can embed parser functions; wiki links; and templates. |
137 | 137 | * usage: |
— | — | @@ -142,34 +142,34 @@ |
143 | 143 | * {{#arrayprint:b|<br/>|@@@|{{#set:prop=@@@}} }} -- embed parser function |
144 | 144 | * {{#arrayprint:b|<br/>|@@@|{{f.tag{{f.print.vbar}}prop{{f.print.vbar}}@@@}} }} -- embed template function |
145 | 145 | * {{#arrayprint:b|<br/>|@@@|[[name::@@@]]}} -- make SMW links |
146 | | - */ |
147 | | - function arrayprint( &$parser, $arrayid , $delimiter = ', ', $search='@@@@', $subject='@@@@', $frame=null) { |
148 | | - $ret = $this->validate_array_by_arrayid($arrayid); |
149 | | - if ($ret !== true){ |
| 146 | + */ |
| 147 | + function arrayprint( &$parser, $arrayid , $delimiter = ', ', $search = '@@@@', $subject = '@@@@', $frame = null ) { |
| 148 | + $ret = $this->validate_array_by_arrayid( $arrayid ); |
| 149 | + if ( $ret !== true ) { |
150 | 150 | return $ret; |
151 | 151 | } |
152 | | - |
153 | | - $values=$this->mArrayExtension[$arrayid]; |
154 | | - $rendered_values= array(); |
155 | | - foreach($values as $v){ |
156 | | - $temp_result_value = str_replace($search, $v, $subject); |
157 | | - if (isset($frame)){ |
158 | | - $temp_result_value = $parser->preprocessToDom($temp_result_value, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0); |
159 | | - $temp_result_value = trim($frame->expand($temp_result_value)); |
160 | | - } |
| 152 | + |
| 153 | + $values = $this->mArrayExtension[$arrayid]; |
| 154 | + $rendered_values = array(); |
| 155 | + foreach ( $values as $v ) { |
| 156 | + $temp_result_value = str_replace( $search, $v, $subject ); |
| 157 | + if ( isset( $frame ) ) { |
| 158 | + $temp_result_value = $parser->preprocessToDom( $temp_result_value, $frame->isTemplate() ? Parser::PTD_FOR_INCLUSION : 0 ); |
| 159 | + $temp_result_value = trim( $frame->expand( $temp_result_value ) ); |
| 160 | + } |
161 | 161 | $rendered_values[] = $temp_result_value ; |
162 | 162 | } |
163 | | - return array(implode( $delimiter, $rendered_values) , 'noparse' => false, 'isHTML' => false); |
| 163 | + return array( implode( $delimiter, $rendered_values ) , 'noparse' => false, 'isHTML' => false ); |
164 | 164 | } |
165 | | - |
| 165 | + |
166 | 166 | function arrayprintObj( &$parser, $frame, $args ) { |
167 | 167 | // Set variables |
168 | | - $arrayid = isset($args[0]) ? trim($frame->expand($args[0])) : ''; |
169 | | - $delimiter = isset($args[1]) ? trim($frame->expand($args[1])) : ', '; |
170 | | - $search = isset($args[2]) ? trim($frame->expand($args[2], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES)) : '@@@@'; |
171 | | - $subject = isset($args[3]) ? trim($frame->expand($args[3], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES)) : '@@@@'; |
| 168 | + $arrayid = isset( $args[0] ) ? trim( $frame->expand( $args[0] ) ) : ''; |
| 169 | + $delimiter = isset( $args[1] ) ? trim( $frame->expand( $args[1] ) ) : ', '; |
| 170 | + $search = isset( $args[2] ) ? trim( $frame->expand( $args[2], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@'; |
| 171 | + $subject = isset( $args[3] ) ? trim( $frame->expand( $args[3], PPFrame::NO_ARGS | PPFrame::NO_TEMPLATES ) ) : '@@@@'; |
172 | 172 | |
173 | | - return $this->arrayprint($parser, $arrayid, $delimiter, $search, $subject, $frame); |
| 173 | + return $this->arrayprint( $parser, $arrayid, $delimiter, $search, $subject, $frame ); |
174 | 174 | } |
175 | 175 | |
176 | 176 | |
— | — | @@ -178,23 +178,23 @@ |
179 | 179 | * usage: |
180 | 180 | * {{#arrayindex:arrayid|index}} |
181 | 181 | */ |
182 | | - function arrayindex( &$parser, $arrayid , $index , $options='') { |
| 182 | + function arrayindex( &$parser, $arrayid , $index , $options = '' ) { |
183 | 183 | // now parse the options, and do posterior process on the created array |
184 | | - $ary_option = $this->parse_options($options); |
| 184 | + $ary_option = $this->parse_options( $options ); |
185 | 185 | |
186 | | - $ret = $this->validate_array_by_arrayid($arrayid); |
187 | | - if ($ret !== true){ |
188 | | - return $this->get_array_value($ary_option,"default"); |
| 186 | + $ret = $this->validate_array_by_arrayid( $arrayid ); |
| 187 | + if ( $ret !== true ) { |
| 188 | + return $this->get_array_value( $ary_option, "default" ); |
189 | 189 | } |
190 | 190 | |
191 | | - $ret = $this->validate_array_index($index, $this->mArrayExtension[$arrayid]); |
192 | | - if ($ret !== true){ |
193 | | - return $this->get_array_value($ary_option,"default"); |
| 191 | + $ret = $this->validate_array_index( $index, $this->mArrayExtension[$arrayid] ); |
| 192 | + if ( $ret !== true ) { |
| 193 | + return $this->get_array_value( $ary_option, "default" ); |
194 | 194 | } |
195 | 195 | |
196 | 196 | return $this->mArrayExtension[$arrayid][$index]; |
197 | 197 | } |
198 | | - |
| 198 | + |
199 | 199 | /** |
200 | 200 | * return size of array. |
201 | 201 | * Print the size (number of elements) in the specified array |
— | — | @@ -203,19 +203,19 @@ |
204 | 204 | * |
205 | 205 | * See: http://www.php.net/manual/en/function.count.php |
206 | 206 | */ |
207 | | - function arraysize( &$parser, $arrayid) { |
208 | | - $ret = $this->validate_array_by_arrayid($arrayid); |
209 | | - if ($ret !== true){ |
| 207 | + function arraysize( &$parser, $arrayid ) { |
| 208 | + $ret = $this->validate_array_by_arrayid( $arrayid ); |
| 209 | + if ( $ret !== true ) { |
210 | 210 | return ''; |
211 | 211 | } |
212 | | - |
213 | | - return count ($this->mArrayExtension[$arrayid]); |
| 212 | + |
| 213 | + return count ( $this->mArrayExtension[$arrayid] ); |
214 | 214 | } |
215 | 215 | |
216 | 216 | |
217 | 217 | |
218 | 218 | |
219 | | - |
| 219 | + |
220 | 220 | /** |
221 | 221 | * locate the index of the first occurence of an element starting from the 'index' |
222 | 222 | * - print "-1" (not found) or index (found) to show the index of the first occurence of 'value' in the array identified by arrayid |
— | — | @@ -227,34 +227,34 @@ |
228 | 228 | * See: http://www.php.net/manual/en/function.array-search.php |
229 | 229 | * note it is extended to support regular expression match and index |
230 | 230 | */ |
231 | | - function arraysearch( &$parser, $arrayid, $needle = '/^\s*$/', $index = 0, $yes = null, $no = '-1') { |
232 | | - $ret = $this->validate_array_by_arrayid($arrayid); |
233 | | - if ($ret !== true) |
| 231 | + function arraysearch( &$parser, $arrayid, $needle = '/^\s*$/', $index = 0, $yes = null, $no = '-1' ) { |
| 232 | + $ret = $this->validate_array_by_arrayid( $arrayid ); |
| 233 | + if ( $ret !== true ) |
234 | 234 | return $no; |
235 | | - |
236 | | - $ret = $this->validate_array_index($index, $this->mArrayExtension[$arrayid]); |
| 235 | + |
| 236 | + $ret = $this->validate_array_index( $index, $this->mArrayExtension[$arrayid] ); |
237 | 237 | if ( !$ret ) |
238 | 238 | return $no; |
239 | | - |
| 239 | + |
240 | 240 | if ( !$this->isValidRegEx( $needle ) ) |
241 | 241 | $needle = '/^\s*' . preg_quote( $needle, '/' ) . '\s*$/'; |
242 | | - |
243 | | - //search for a match inside the array: |
244 | | - for ($i=$index; $i < count($this->mArrayExtension[$arrayid]); $i++){ |
| 242 | + |
| 243 | + // search for a match inside the array: |
| 244 | + for ( $i = $index; $i < count( $this->mArrayExtension[$arrayid] ); $i++ ) { |
245 | 245 | $value = $this->mArrayExtension[$arrayid][$i]; |
246 | 246 | |
247 | | - if (preg_match($needle, $value)){ |
248 | | - if (isset($yes)) |
| 247 | + if ( preg_match( $needle, $value ) ) { |
| 248 | + if ( isset( $yes ) ) |
249 | 249 | return $yes; |
250 | 250 | else |
251 | 251 | return $i; |
252 | 252 | } |
253 | 253 | } |
254 | | - |
255 | | - //no match: |
| 254 | + |
| 255 | + // no match: |
256 | 256 | return $no; |
257 | 257 | } |
258 | | - |
| 258 | + |
259 | 259 | /** |
260 | 260 | * search an array and create a new array with all the results. Transforming the new entries before storing them is possible too. |
261 | 261 | * usage: |
— | — | @@ -264,78 +264,78 @@ |
265 | 265 | * "$n" where "n" stands for a number to access a variable from the regex result. |
266 | 266 | */ |
267 | 267 | function arraysearcharray( &$parser, $arrayid_new, $arrayid, $needle = '/^(\s*)$/', $index = 0, $limit = -1, $transform = '' ) { |
268 | | - $ret = $this->validate_array_by_arrayid($arrayid); |
269 | | - if( !$ret ) |
| 268 | + $ret = $this->validate_array_by_arrayid( $arrayid ); |
| 269 | + if ( !$ret ) |
270 | 270 | return ''; |
271 | | - |
272 | | - if( !isset($arrayid_new) ) |
| 271 | + |
| 272 | + if ( !isset( $arrayid_new ) ) |
273 | 273 | return ''; |
274 | | - |
275 | | - if( !is_numeric($index) ) |
| 274 | + |
| 275 | + if ( !is_numeric( $index ) ) |
276 | 276 | $index = 0; |
277 | | - |
278 | | - if( !is_numeric($limit) ) |
| 277 | + |
| 278 | + if ( !is_numeric( $limit ) ) |
279 | 279 | $limit = -1; |
280 | | - |
281 | | - //calculate start index for negative start indexes: |
282 | | - if( $index < 0 ) { |
| 280 | + |
| 281 | + // calculate start index for negative start indexes: |
| 282 | + if ( $index < 0 ) { |
283 | 283 | $index = count( $this->mArrayExtension[$arrayid] ) + $index; |
284 | | - if( $index < 0 ) $index = 0; |
| 284 | + if ( $index < 0 ) $index = 0; |
285 | 285 | } |
286 | | - |
| 286 | + |
287 | 287 | $newArr = array(); |
288 | 288 | $newArrSize = 0; |
289 | | - |
| 289 | + |
290 | 290 | if ( !$this->isValidRegEx( $needle ) ) |
291 | 291 | $needle = '/^\s*(' . preg_quote( $needle, '/' ) . ')\s*$/'; |
292 | | - |
293 | | - //search the array for all matches and put them in the new array |
294 | | - for ($i = $index; $i < count($this->mArrayExtension[$arrayid]); $i++) |
295 | | - { |
| 292 | + |
| 293 | + // search the array for all matches and put them in the new array |
| 294 | + for ( $i = $index; $i < count( $this->mArrayExtension[$arrayid] ); $i++ ) |
| 295 | + { |
296 | 296 | $value = $this->mArrayExtension[$arrayid][$i]; |
297 | | - |
298 | | - if( preg_match($needle, $value) ) { |
299 | | - if( $transform != '' ) { |
| 297 | + |
| 298 | + if ( preg_match( $needle, $value ) ) { |
| 299 | + if ( $transform != '' ) { |
300 | 300 | $value = preg_replace( $needle, $transform, $value ); |
301 | 301 | } |
302 | 302 | $newArr[] = $value; |
303 | 303 | $newArrSize++; |
304 | | - //stop if limit is reached |
305 | | - if( $newArrSize == $limit ) |
| 304 | + // stop if limit is reached |
| 305 | + if ( $newArrSize == $limit ) |
306 | 306 | break; |
307 | 307 | } |
308 | 308 | } |
309 | | - |
| 309 | + |
310 | 310 | $this->mArrayExtension[$arrayid_new] = $newArr; |
311 | 311 | return ''; |
312 | 312 | } |
313 | | - |
314 | 313 | |
315 | 314 | |
316 | | - /////////////////////////////////////////////////////////// |
317 | | - // PART 3. alter an array |
318 | | - /////////////////////////////////////////////////////////// |
319 | | - |
| 315 | + |
| 316 | + ////////////////////////////////////////////////////////// / |
| 317 | + // PART 3. alter an array |
| 318 | + ////////////////////////////////////////////////////////// / |
| 319 | + |
320 | 320 | /** |
321 | 321 | * reset some or all defined arrayes |
322 | 322 | * usage: |
323 | 323 | * {{#arrayreset:}} |
324 | 324 | * {{#arrayreset:arrayid1,arrayid2,...arrayidn}} |
325 | 325 | */ |
326 | | - function arrayreset( &$parser, $arrayids) { |
327 | | - if (!$this->is_non_empty($arrayids)){ |
328 | | - //reset all |
| 326 | + function arrayreset( &$parser, $arrayids ) { |
| 327 | + if ( !$this->is_non_empty( $arrayids ) ) { |
| 328 | + // reset all |
329 | 329 | $this->mArrayExtension = array(); |
330 | | - }else{ |
331 | | - $arykeys = explode(',', $arrayids); |
332 | | - foreach ($arykeys as $arrayid){ |
| 330 | + } else { |
| 331 | + $arykeys = explode( ',', $arrayids ); |
| 332 | + foreach ( $arykeys as $arrayid ) { |
333 | 333 | $this->removeArray( $arrayids ); |
334 | 334 | } |
335 | 335 | } |
336 | 336 | return ''; |
337 | | - } |
338 | | - |
339 | | - |
| 337 | + } |
| 338 | + |
| 339 | + |
340 | 340 | /** |
341 | 341 | * convert an array to set |
342 | 342 | * convert the array identified by arrayid into a set (all elements are unique) |
— | — | @@ -345,20 +345,20 @@ |
346 | 346 | * see: http://www.php.net/manual/en/function.array-unique.php |
347 | 347 | */ |
348 | 348 | function arrayunique( &$parser, $arrayid ) { |
349 | | - $ret = $this->validate_array_by_arrayid($arrayid); |
350 | | - if ($ret !== true){ |
| 349 | + $ret = $this->validate_array_by_arrayid( $arrayid ); |
| 350 | + if ( $ret !== true ) { |
351 | 351 | return ''; |
352 | 352 | } |
353 | 353 | |
354 | | - $this->mArrayExtension[$arrayid]= array_unique ($this->mArrayExtension[$arrayid]); |
355 | | - $values= array(); |
356 | | - foreach ($this->mArrayExtension[$arrayid] as $v){ |
357 | | - //if (!isset($v)) |
358 | | - if (strlen($v)>0) |
359 | | - $values[]=$v; |
| 354 | + $this->mArrayExtension[$arrayid] = array_unique ( $this->mArrayExtension[$arrayid] ); |
| 355 | + $values = array(); |
| 356 | + foreach ( $this->mArrayExtension[$arrayid] as $v ) { |
| 357 | + // if (!isset($v)) |
| 358 | + if ( strlen( $v ) > 0 ) |
| 359 | + $values[] = $v; |
360 | 360 | } |
361 | 361 | $this->mArrayExtension[$arrayid] = $values; |
362 | | - } |
| 362 | + } |
363 | 363 | |
364 | 364 | |
365 | 365 | /** |
— | — | @@ -370,75 +370,75 @@ |
371 | 371 | * - reverse: Return an array with elements in reverse order |
372 | 372 | * usage: |
373 | 373 | * {{#arraysort:arrayid|order}} |
374 | | - * |
| 374 | + * |
375 | 375 | * see: http://www.php.net/manual/en/function.sort.php |
376 | 376 | * http://www.php.net/manual/en/function.rsort.php |
377 | 377 | * http://www.php.net/manual/en/function.shuffle.php |
378 | 378 | * http://us3.php.net/manual/en/function.array-reverse.php |
379 | | - */ |
380 | | - function arraysort( &$parser, $arrayid , $sort = 'none') { |
381 | | - $ret = $this->validate_array_by_arrayid($arrayid); |
382 | | - if ($ret !== true){ |
| 379 | + */ |
| 380 | + function arraysort( &$parser, $arrayid , $sort = 'none' ) { |
| 381 | + $ret = $this->validate_array_by_arrayid( $arrayid ); |
| 382 | + if ( $ret !== true ) { |
383 | 383 | return ''; |
384 | 384 | } |
385 | 385 | |
386 | 386 | |
387 | | - switch ($sort){ |
388 | | - case 'asc': |
389 | | - case 'asce': |
390 | | - case 'ascending': sort($this->mArrayExtension[$arrayid]); break; |
| 387 | + switch ( $sort ) { |
| 388 | + case 'asc': |
| 389 | + case 'asce': |
| 390 | + case 'ascending': sort( $this->mArrayExtension[$arrayid] ); break; |
391 | 391 | |
392 | 392 | |
393 | | - case 'desc': |
394 | | - case 'descending': rsort($this->mArrayExtension[$arrayid]); break; |
395 | | - |
396 | | - case 'random': shuffle($this->mArrayExtension[$arrayid]); break; |
| 393 | + case 'desc': |
| 394 | + case 'descending': rsort( $this->mArrayExtension[$arrayid] ); break; |
397 | 395 | |
| 396 | + case 'random': shuffle( $this->mArrayExtension[$arrayid] ); break; |
398 | 397 | |
399 | | - case 'reverse': $this->mArrayExtension[$arrayid]= array_reverse($this->mArrayExtension[$arrayid]); break; |
400 | | - }; |
401 | | - } |
402 | | - |
403 | | - |
404 | | - /////////////////////////////////////////////////////////// |
405 | | - // PART 4. create an array |
406 | | - /////////////////////////////////////////////////////////// |
407 | | - |
| 398 | + |
| 399 | + case 'reverse': $this->mArrayExtension[$arrayid] = array_reverse( $this->mArrayExtension[$arrayid] ); break; |
| 400 | + } ; |
| 401 | + } |
| 402 | + |
| 403 | + |
| 404 | + ////////////////////////////////////////////////////////// / |
| 405 | + // PART 4. create an array |
| 406 | + ////////////////////////////////////////////////////////// / |
| 407 | + |
408 | 408 | /** |
409 | | - * merge two arrays, keep duplicated values |
| 409 | + * merge two arrays, keep duplicated values |
410 | 410 | * usage: |
411 | 411 | * {{#arraymerge:arrayid_new|arrayid1|arrayid2}} |
412 | | - * |
| 412 | + * |
413 | 413 | * merge values two arrayes identified by arrayid1 and arrayid2 into a new array identified by arrayid_new. |
414 | 414 | * this merge differs from array_merge of php because it merges values. |
415 | | - */ |
416 | | - function arraymerge( &$parser, $arrayid_new, $arrayid1, $arrayid2='' ) { |
417 | | - if (!isset($arrayid_new) ) |
| 415 | + */ |
| 416 | + function arraymerge( &$parser, $arrayid_new, $arrayid1, $arrayid2 = '' ) { |
| 417 | + if ( !isset( $arrayid_new ) ) |
418 | 418 | return ''; |
419 | 419 | |
420 | | - $ret = $this->validate_array_by_arrayid($arrayid1); |
421 | | - if ($ret !== true){ |
| 420 | + $ret = $this->validate_array_by_arrayid( $arrayid1 ); |
| 421 | + if ( $ret !== true ) { |
422 | 422 | return ''; |
423 | 423 | } |
424 | | - |
| 424 | + |
425 | 425 | $temp_array = array(); |
426 | | - foreach ($this->mArrayExtension[$arrayid1] as $entry){ |
427 | | - array_push ($temp_array, $entry); |
| 426 | + foreach ( $this->mArrayExtension[$arrayid1] as $entry ) { |
| 427 | + array_push ( $temp_array, $entry ); |
428 | 428 | } |
429 | 429 | |
430 | | - if ( isset($arrayid2) && strlen($arrayid2)>0){ |
431 | | - $ret = $this->validate_array_by_arrayid($arrayid2); |
432 | | - if ( $ret === true ){ |
433 | | - foreach ($this->mArrayExtension[$arrayid2] as $entry){ |
434 | | - array_push ($temp_array, $entry); |
| 430 | + if ( isset( $arrayid2 ) && strlen( $arrayid2 ) > 0 ) { |
| 431 | + $ret = $this->validate_array_by_arrayid( $arrayid2 ); |
| 432 | + if ( $ret === true ) { |
| 433 | + foreach ( $this->mArrayExtension[$arrayid2] as $entry ) { |
| 434 | + array_push ( $temp_array, $entry ); |
435 | 435 | } |
436 | 436 | } |
437 | 437 | } |
438 | | - |
| 438 | + |
439 | 439 | $this->mArrayExtension[$arrayid_new] = $temp_array; |
440 | 440 | return ''; |
441 | 441 | } |
442 | | - |
| 442 | + |
443 | 443 | /** |
444 | 444 | * extract a slice from an array |
445 | 445 | * usage: |
— | — | @@ -446,32 +446,32 @@ |
447 | 447 | * |
448 | 448 | * extract a slice from an array |
449 | 449 | * see: http://www.php.net/manual/en/function.array-slice.php |
450 | | - */ |
451 | | - function arrayslice( &$parser, $arrayid_new , $arrayid , $offset, $length='') { |
452 | | - if (!isset($arrayid_new) ) |
| 450 | + */ |
| 451 | + function arrayslice( &$parser, $arrayid_new , $arrayid , $offset, $length = '' ) { |
| 452 | + if ( !isset( $arrayid_new ) ) |
453 | 453 | return ''; |
454 | 454 | |
455 | | - $ret = $this->validate_array_by_arrayid($arrayid); |
456 | | - if ($ret !== true){ |
| 455 | + $ret = $this->validate_array_by_arrayid( $arrayid ); |
| 456 | + if ( $ret !== true ) { |
457 | 457 | return ''; |
458 | 458 | } |
459 | 459 | |
460 | | - //$ret = $this->validate_array_offset($offset, $this->mArrayExtension[$arrayid]); |
461 | | - //if ($ret !== true){ |
| 460 | + // $ret = $this->validate_array_offset($offset, $this->mArrayExtension[$arrayid]); |
| 461 | + // if ($ret !== true){ |
462 | 462 | // return ''; |
463 | | - //} |
464 | | - |
| 463 | + // } |
| 464 | + |
465 | 465 | $temp_array = array(); |
466 | | - if (is_numeric($offset)){ |
467 | | - if ($this->is_non_empty($length) && is_numeric($length)){ |
468 | | - $temp = array_slice($this->mArrayExtension[$arrayid], $offset, $length); |
469 | | - }else{ |
470 | | - $temp = array_slice($this->mArrayExtension[$arrayid], $offset); |
| 466 | + if ( is_numeric( $offset ) ) { |
| 467 | + if ( $this->is_non_empty( $length ) && is_numeric( $length ) ) { |
| 468 | + $temp = array_slice( $this->mArrayExtension[$arrayid], $offset, $length ); |
| 469 | + } else { |
| 470 | + $temp = array_slice( $this->mArrayExtension[$arrayid], $offset ); |
471 | 471 | } |
472 | | - |
473 | | - if (!empty($temp) && is_array($temp)) |
474 | | - $temp_array = array_values($temp); |
475 | | - } |
| 472 | + |
| 473 | + if ( !empty( $temp ) && is_array( $temp ) ) |
| 474 | + $temp_array = array_values( $temp ); |
| 475 | + } |
476 | 476 | $this->mArrayExtension[$arrayid_new] = $temp_array; |
477 | 477 | return ''; |
478 | 478 | } |
— | — | @@ -480,225 +480,225 @@ |
481 | 481 | * set operation, {red, white} = {red, white} union {red} |
482 | 482 | * usage: |
483 | 483 | * {{#arrayunion:arrayid_new|arrayid1|arrayid2}} |
484 | | - |
| 484 | + |
485 | 485 | * similar to arraymerge, this union works on values. |
486 | | - */ |
| 486 | + */ |
487 | 487 | function arrayunion( &$parser, $arrayid_new , $arrayid1 , $arrayid2 ) { |
488 | | - if (!isset($arrayid_new) ) |
| 488 | + if ( !isset( $arrayid_new ) ) |
489 | 489 | return ''; |
490 | 490 | |
491 | 491 | |
492 | | - $ret = $this->validate_array_by_arrayid($arrayid1); |
493 | | - if ($ret !== true){ |
| 492 | + $ret = $this->validate_array_by_arrayid( $arrayid1 ); |
| 493 | + if ( $ret !== true ) { |
494 | 494 | return ''; |
495 | 495 | } |
496 | 496 | |
497 | | - $ret = $this->validate_array_by_arrayid($arrayid2); |
498 | | - if ($ret !== true){ |
| 497 | + $ret = $this->validate_array_by_arrayid( $arrayid2 ); |
| 498 | + if ( $ret !== true ) { |
499 | 499 | return ''; |
500 | 500 | } |
501 | | - |
502 | | - $this->arraymerge($parser, $arrayid_new, $arrayid1, $arrayid2); |
503 | | - $this->mArrayExtension[$arrayid_new] = array_unique ($this->mArrayExtension[$arrayid_new]); |
504 | | - |
| 501 | + |
| 502 | + $this->arraymerge( $parser, $arrayid_new, $arrayid1, $arrayid2 ); |
| 503 | + $this->mArrayExtension[$arrayid_new] = array_unique ( $this->mArrayExtension[$arrayid_new] ); |
| 504 | + |
505 | 505 | return ''; |
506 | 506 | } |
507 | 507 | |
508 | | - ////////////////////////////////////////////////// |
| 508 | + ///////////////////////////////////////////////// / |
509 | 509 | // SET OPERATIONS: a set does not have duplicated element |
510 | | - |
| 510 | + |
511 | 511 | /** |
512 | 512 | * set operation, {red} = {red, white} intersect {red,black} |
513 | 513 | * usage: |
514 | 514 | * {{#arrayintersect:arrayid_new|arrayid1|arrayid2}} |
515 | 515 | * See: http://www.php.net/manual/en/function.array-intersect.php |
516 | | - */ |
| 516 | + */ |
517 | 517 | function arrayintersect( &$parser, $arrayid_new , $arrayid1 , $arrayid2 ) { |
518 | | - if (!isset($arrayid_new) ) |
| 518 | + if ( !isset( $arrayid_new ) ) |
519 | 519 | return ''; |
520 | 520 | |
521 | | - $ret = $this->validate_array_by_arrayid($arrayid1); |
522 | | - if ($ret !== true){ |
| 521 | + $ret = $this->validate_array_by_arrayid( $arrayid1 ); |
| 522 | + if ( $ret !== true ) { |
523 | 523 | return ''; |
524 | 524 | } |
525 | | - |
526 | | - $ret = $this->validate_array_by_arrayid($arrayid2); |
527 | | - if ($ret !== true){ |
| 525 | + |
| 526 | + $ret = $this->validate_array_by_arrayid( $arrayid2 ); |
| 527 | + if ( $ret !== true ) { |
528 | 528 | return ''; |
529 | 529 | } |
530 | | - |
531 | | - //keys will be preserved... |
532 | | - $newArray = array_intersect( array_unique($this->mArrayExtension[$arrayid1]), array_unique($this->mArrayExtension[$arrayid2]) ); |
533 | | - |
534 | | - //...so we have to reorganize the key order |
535 | | - $this->mArrayExtension[$arrayid_new] = $this->reorganizeArrayKeys($newArray); |
536 | | - |
| 530 | + |
| 531 | + // keys will be preserved... |
| 532 | + $newArray = array_intersect( array_unique( $this->mArrayExtension[$arrayid1] ), array_unique( $this->mArrayExtension[$arrayid2] ) ); |
| 533 | + |
| 534 | + // ...so we have to reorganize the key order |
| 535 | + $this->mArrayExtension[$arrayid_new] = $this->reorganizeArrayKeys( $newArray ); |
| 536 | + |
537 | 537 | return ''; |
538 | 538 | } |
539 | | - |
| 539 | + |
540 | 540 | /** |
541 | 541 | * |
542 | 542 | * usage: |
543 | 543 | * {{#arraydiff:arrayid_new|arrayid1|arrayid2}} |
544 | | - |
| 544 | + |
545 | 545 | * set operation, {white} = {red, white} - {red} |
546 | 546 | * see: http://www.php.net/manual/en/function.array-diff.php |
547 | 547 | */ |
548 | 548 | function arraydiff( &$parser, $arrayid_new , $arrayid1 , $arrayid2 ) { |
549 | | - if (!isset($arrayid_new) ) |
| 549 | + if ( !isset( $arrayid_new ) ) |
550 | 550 | return ''; |
551 | 551 | |
552 | | - $ret = $this->validate_array_by_arrayid($arrayid1); |
553 | | - if ($ret !== true){ |
| 552 | + $ret = $this->validate_array_by_arrayid( $arrayid1 ); |
| 553 | + if ( $ret !== true ) { |
554 | 554 | return ''; |
555 | 555 | } |
556 | 556 | |
557 | | - $ret = $this->validate_array_by_arrayid($arrayid2); |
558 | | - if ($ret !== true){ |
| 557 | + $ret = $this->validate_array_by_arrayid( $arrayid2 ); |
| 558 | + if ( $ret !== true ) { |
559 | 559 | return ''; |
560 | 560 | } |
561 | 561 | |
562 | | - //keys will be preserved... |
563 | | - $newArray = array_diff( array_unique($this->mArrayExtension[$arrayid1]),array_unique($this->mArrayExtension[$arrayid2])); |
| 562 | + // keys will be preserved... |
| 563 | + $newArray = array_diff( array_unique( $this->mArrayExtension[$arrayid1] ), array_unique( $this->mArrayExtension[$arrayid2] ) ); |
564 | 564 | |
565 | | - //...so we have to reorganize the key order |
566 | | - $this->mArrayExtension[$arrayid_new] = $this->reorganizeArrayKeys($newArray); |
567 | | - |
| 565 | + // ...so we have to reorganize the key order |
| 566 | + $this->mArrayExtension[$arrayid_new] = $this->reorganizeArrayKeys( $newArray ); |
| 567 | + |
568 | 568 | return ''; |
569 | | - } |
| 569 | + } |
570 | 570 | |
571 | 571 | |
572 | 572 | |
573 | | - ////////////////////////////////////////////////// |
| 573 | + ///////////////////////////////////////////////// / |
574 | 574 | // private functions |
575 | | - ////////////////////////////////////////////////// |
576 | | - |
577 | | - function is_non_empty($var){ |
578 | | - return isset($var) && strlen($var)>0; |
| 575 | + ///////////////////////////////////////////////// / |
| 576 | + |
| 577 | + function is_non_empty( $var ) { |
| 578 | + return isset( $var ) && strlen( $var ) > 0; |
579 | 579 | } |
580 | | - |
| 580 | + |
581 | 581 | // private functions for validating the index of an array |
582 | | - function validate_array_index($index, $array){ |
583 | | - if (!isset($index)) |
| 582 | + function validate_array_index( $index, $array ) { |
| 583 | + if ( !isset( $index ) ) |
584 | 584 | return false; |
585 | 585 | |
586 | | - if (!is_numeric($index)) |
| 586 | + if ( !is_numeric( $index ) ) |
587 | 587 | return false; |
588 | 588 | |
589 | | - if (!isset($array) || !is_array($array)) |
| 589 | + if ( !isset( $array ) || !is_array( $array ) ) |
590 | 590 | return false; |
591 | | - |
592 | | - if (!array_key_exists($index, $array)) /*($index<0 || $index>=count($array))*/ |
| 591 | + |
| 592 | + if ( !array_key_exists( $index, $array ) ) /*($index<0 || $index>=count($array))*/ |
593 | 593 | return false; |
594 | | - |
| 594 | + |
595 | 595 | return true; |
596 | | - } |
| 596 | + } |
597 | 597 | |
598 | 598 | // private functions for validating the index of an array |
599 | | - function validate_array_offset($offset, $array){ |
600 | | - if (!isset($offset)) |
| 599 | + function validate_array_offset( $offset, $array ) { |
| 600 | + if ( !isset( $offset ) ) |
601 | 601 | return false; |
602 | 602 | |
603 | 603 | |
604 | | - if (!is_numeric($offset)) |
| 604 | + if ( !is_numeric( $offset ) ) |
605 | 605 | return false; |
606 | 606 | |
607 | 607 | |
608 | | - if (!isset($array) || !is_array($array)) |
| 608 | + if ( !isset( $array ) || !is_array( $array ) ) |
609 | 609 | return false; |
610 | | - |
611 | | - if ( $offset>=count($array)) |
| 610 | + |
| 611 | + if ( $offset >= count( $array ) ) |
612 | 612 | return false; |
613 | | - |
| 613 | + |
614 | 614 | return true; |
615 | 615 | } |
616 | | - |
617 | | - //private function for validating array by name |
618 | | - function validate_array_by_arrayid($array_name){ |
619 | | - if (!isset($array_name)) |
| 616 | + |
| 617 | + // private function for validating array by name |
| 618 | + function validate_array_by_arrayid( $array_name ) { |
| 619 | + if ( !isset( $array_name ) ) |
620 | 620 | return ''; |
621 | | - |
622 | | - if (!isset($this->mArrayExtension)) |
| 621 | + |
| 622 | + if ( !isset( $this->mArrayExtension ) ) |
623 | 623 | return "undefined array: $array_name"; |
624 | | - |
625 | | - if (!array_key_exists($array_name,$this->mArrayExtension) || !is_array($this->mArrayExtension[$array_name])) |
| 624 | + |
| 625 | + if ( !array_key_exists( $array_name, $this->mArrayExtension ) || !is_array( $this->mArrayExtension[$array_name] ) ) |
626 | 626 | return "undefined array: $array_name"; |
627 | | - |
| 627 | + |
628 | 628 | return true; |
629 | 629 | } |
630 | 630 | |
631 | | - function get_array_value($array, $field){ |
632 | | - if (is_array($array) && FALSE !== array_key_exists($field, $array)) |
| 631 | + function get_array_value( $array, $field ) { |
| 632 | + if ( is_array( $array ) && FALSE !== array_key_exists( $field, $array ) ) |
633 | 633 | return $array[$field]; |
634 | 634 | else |
635 | 635 | return ''; |
636 | 636 | } |
637 | 637 | |
638 | | - function parse_options($options){ |
639 | | - if (isset($options)){ |
| 638 | + function parse_options( $options ) { |
| 639 | + if ( isset( $options ) ) { |
640 | 640 | // now parse the options, and do posterior process on the created array |
641 | | - $ary_option = preg_split ('/\s*[,]\s*/', strtolower($options)); |
| 641 | + $ary_option = preg_split ( '/\s*[,]\s*/', strtolower( $options ) ); |
642 | 642 | } |
643 | | - |
| 643 | + |
644 | 644 | $ret = array(); |
645 | | - if (isset($ary_option) && is_array($ary_option) && sizeof($ary_option)>0){ |
646 | | - foreach ($ary_option as $option){ |
647 | | - $ary_pair = explode('=', $option,2); |
648 | | - if (sizeof($ary_pair)==1){ |
| 645 | + if ( isset( $ary_option ) && is_array( $ary_option ) && sizeof( $ary_option ) > 0 ) { |
| 646 | + foreach ( $ary_option as $option ) { |
| 647 | + $ary_pair = explode( '=', $option, 2 ); |
| 648 | + if ( sizeof( $ary_pair ) == 1 ) { |
649 | 649 | $ret[$ary_pair[0]] = true; |
650 | | - }else{ |
| 650 | + } else { |
651 | 651 | $ret[$ary_pair[0]] = $ary_pair[1]; |
652 | 652 | } |
653 | 653 | } |
654 | | - } |
| 654 | + } |
655 | 655 | return $ret; |
656 | 656 | } |
657 | | - |
658 | | - /* ============================ */ |
| 657 | + |
659 | 658 | /* ============================ */ |
| 659 | + /* ============================ */ |
660 | 660 | /* === === */ |
661 | 661 | /* === HELPER FUNCTIONS === */ |
662 | 662 | /* === === */ |
663 | | - /* ============================ */ |
664 | 663 | /* ============================ */ |
| 664 | + /* ============================ */ |
665 | 665 | |
666 | | - function getArrayValue( $arrayId='', $key='' ) { |
| 666 | + function getArrayValue( $arrayId = '', $key = '' ) { |
667 | 667 | $arrayId = trim( $arrayId ); |
668 | | - if( $this->arrayExists( $arrayId ) && array_key_exists( $key, $this->mArrayExtension[ $arrayId ] ) ) |
| 668 | + if ( $this->arrayExists( $arrayId ) && array_key_exists( $key, $this->mArrayExtension[ $arrayId ] ) ) |
669 | 669 | return $this->mArrayExtension[ $arrayId ][ $key ]; |
670 | 670 | else |
671 | 671 | return ''; |
672 | 672 | } |
673 | | - |
674 | | - //return an array identified by $arrayId. If it doesn't exist this will return null. |
675 | | - function getArray( $arrayId='' ) { |
676 | | - if( $this->arrayExists( $arrayId ) ) |
| 673 | + |
| 674 | + // return an array identified by $arrayId. If it doesn't exist this will return null. |
| 675 | + function getArray( $arrayId = '' ) { |
| 676 | + if ( $this->arrayExists( $arrayId ) ) |
677 | 677 | return $this->mArrayExtension[ $arrayId ]; |
678 | 678 | else |
679 | 679 | return null; |
680 | 680 | } |
681 | | - |
682 | | - function arrayExists( $arrayId='' ) { |
683 | | - if( array_key_exists( trim( $arrayId ), $this->mArrayExtension ) ) |
684 | 681 | |
| 682 | + function arrayExists( $arrayId = '' ) { |
| 683 | + if ( array_key_exists( trim( $arrayId ), $this->mArrayExtension ) ) |
685 | 684 | |
686 | 685 | |
| 686 | + |
687 | 687 | return true; |
688 | 688 | else |
689 | 689 | return false; |
690 | 690 | } |
691 | | - |
692 | | - //add a new array or overwrite existing one. Values delivered as real array. |
693 | | - function createArray( $arrayId='', $arr=array() ) { |
| 691 | + |
| 692 | + // add a new array or overwrite existing one. Values delivered as real array. |
| 693 | + function createArray( $arrayId = '', $arr = array() ) { |
694 | 694 | $arr = $this->reorganizeArrayKeys( $arr ); |
695 | 695 | $this->mArrayExtension[ trim( $arrayId ) ] = $arr; |
696 | 696 | } |
697 | 697 | |
698 | | - |
699 | | - //remove an existing array. If array doesn't exist this will return false, otherwise true. |
700 | | - function removeArray( $arrayId='' ) { |
| 698 | + |
| 699 | + // remove an existing array. If array doesn't exist this will return false, otherwise true. |
| 700 | + function removeArray( $arrayId = '' ) { |
701 | 701 | $arrayId = trim( $arrayId ); |
702 | | - if( $this->arrayExists( $arrayId ) ) { |
| 702 | + if ( $this->arrayExists( $arrayId ) ) { |
703 | 703 | unset( $this->mArrayExtension[ $arrayId ] ); |
704 | 704 | return true; |
705 | 705 | } else { |
— | — | @@ -707,30 +707,30 @@ |
708 | 708 | |
709 | 709 | |
710 | 710 | } |
711 | | - |
712 | | - //Rebuild the array and reorganize all keys. This means all gaps between array items will be closed. |
713 | | - function reorganizeArrayKeys( $arr = array() ) { |
714 | | - $newArray = array(); |
715 | | - foreach ($arr as $val){ |
| 711 | + |
| 712 | + // Rebuild the array and reorganize all keys. This means all gaps between array items will be closed. |
| 713 | + function reorganizeArrayKeys( $arr = array() ) { |
| 714 | + $newArray = array(); |
| 715 | + foreach ( $arr as $val ) { |
716 | 716 | $newArray[] = trim( $val ); |
717 | | - } |
| 717 | + } |
718 | 718 | return $newArray; |
719 | 719 | } |
720 | | - |
721 | | - //Decide for the given $pattern if its a valid regular expression or not |
722 | | - function isValidRegEx( $pattern ) { |
| 720 | + |
| 721 | + // Decide for the given $pattern if its a valid regular expression or not |
| 722 | + function isValidRegEx( $pattern ) { |
723 | 723 | return preg_match( '/^([\\/\\|%]).*\\1[imsSuUx]*$/', $pattern ); |
724 | 724 | } |
725 | 725 | } |
726 | | - |
| 726 | + |
727 | 727 | function efSetupArrayExtension() { |
728 | 728 | global $wgParser, $wgArrayExtension; |
729 | 729 | |
730 | | - $wgArrayExtension = new ArrayExtension; |
| 730 | + $wgArrayExtension = new ArrayExtension; |
731 | 731 | $wgParser->setFunctionHook( 'arraydefine', array( &$wgArrayExtension, 'arraydefine' ) ); |
732 | 732 | |
733 | | - if( defined( get_class( $wgParser) . '::SFH_OBJECT_ARGS' ) ) { |
734 | | - $wgParser->setFunctionHook('arrayprint', array( &$wgArrayExtension, 'arrayprintObj' ), SFH_OBJECT_ARGS); |
| 733 | + if ( defined( get_class( $wgParser ) . '::SFH_OBJECT_ARGS' ) ) { |
| 734 | + $wgParser->setFunctionHook( 'arrayprint', array( &$wgArrayExtension, 'arrayprintObj' ), SFH_OBJECT_ARGS ); |
735 | 735 | } else { |
736 | 736 | $wgParser->setFunctionHook( 'arrayprint', array( &$wgArrayExtension, 'arrayprint' ) ); |
737 | 737 | } |
— | — | @@ -751,10 +751,10 @@ |
752 | 752 | $wgParser->setFunctionHook( 'arraydiff', array( &$wgArrayExtension, 'arraydiff' ) ); |
753 | 753 | $wgParser->setFunctionHook( 'arraysearcharray', array( &$wgArrayExtension, 'arraysearcharray' ) ); |
754 | 754 | } |
755 | | - |
| 755 | + |
756 | 756 | function efArrayExtensionLanguageGetMagic( &$magicWords, $langCode ) { |
757 | 757 | require_once( dirname( __FILE__ ) . '/ArrayExtension.i18n.php' ); |
758 | | - foreach( efArrayExtensionWords( $langCode ) as $word => $trans ) |
| 758 | + foreach ( efArrayExtensionWords( $langCode ) as $word => $trans ) |
759 | 759 | $magicWords[$word] = $trans; |
760 | 760 | return true; |
761 | 761 | } |
\ No newline at end of file |