These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /*************************************************************** |
||
3 | * Copyright notice |
||
4 | * |
||
5 | * (c) 2009 Tim Lochmueller ([email protected]) |
||
6 | * All rights reserved |
||
7 | * |
||
8 | * This script is part of the Typo3 project. The Typo3 project is |
||
9 | * free software; you can redistribute it and/or modify |
||
10 | * it under the terms of the GNU General Public License as published by |
||
11 | * the Free Software Foundation; either version 2 of the License, or |
||
12 | * (at your option) any later version. |
||
13 | * |
||
14 | * The GNU General Public License can be found at |
||
15 | * http://www.gnu.org/copyleft/gpl.html. |
||
16 | * |
||
17 | * This script is distributed in the hope that it will be useful, |
||
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
20 | * GNU General Public License for more details. |
||
21 | * |
||
22 | * This copyright notice MUST APPEAR in all copies of the script! |
||
23 | ***************************************************************/ |
||
24 | |||
25 | namespace FRUIT\Popup; |
||
26 | |||
27 | use TYPO3\CMS\Core\Utility\ArrayUtility; |
||
28 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||
29 | use TYPO3\CMS\Core\Utility\MathUtility; |
||
30 | use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer; |
||
31 | use TYPO3\CMS\Frontend\Page\PageRepository; |
||
32 | |||
33 | /** |
||
34 | * base class for the popup extension |
||
35 | * |
||
36 | * @author Tim Lochmueller <[email protected]> |
||
37 | * @package popup |
||
38 | * @subpackage tx_popup |
||
39 | */ |
||
40 | class Popup |
||
41 | { |
||
42 | |||
43 | /** |
||
44 | * cObj for the RTE replacement |
||
45 | * |
||
46 | * @var ContentObjectRenderer |
||
47 | */ |
||
48 | public $cObj; |
||
49 | |||
50 | /** |
||
51 | * init the convert functions |
||
52 | */ |
||
53 | private $convertParams = []; |
||
54 | |||
55 | /** |
||
56 | * Possible popup parameter |
||
57 | */ |
||
58 | public $allowedParams = [ |
||
59 | 'height' => 'integer', |
||
60 | 'width' => 'integer', |
||
61 | 'resizable' => 'boolean', |
||
62 | 'scrollbars' => 'boolean', |
||
63 | 'menubar' => 'boolean', |
||
64 | 'status' => 'boolean', |
||
65 | 'location' => 'boolean', |
||
66 | 'toolbar' => 'boolean', |
||
67 | 'dependent' => 'boolean', |
||
68 | 'top' => 'integer', |
||
69 | 'left' => 'integer', |
||
70 | ]; |
||
71 | |||
72 | /** |
||
73 | * Possible popup parameter |
||
74 | */ |
||
75 | public $advancedParams = [ |
||
76 | 'once_per_session' => 'boolean', |
||
77 | 'once_per_link' => 'boolean', |
||
78 | 'center' => 'boolean', |
||
79 | 'maximize' => 'boolean', |
||
80 | 'popunder' => 'boolean', |
||
81 | ]; |
||
82 | |||
83 | /** |
||
84 | * Static Funktion for hooking the menu link generation |
||
85 | * |
||
86 | * @param array|int $pageOrPageID The Page row or the page ID |
||
87 | * @param array $LD A reference of the Link Data |
||
88 | */ |
||
89 | public static function makeMenuLink($pageOrPageID, &$LD) |
||
90 | { |
||
91 | $popup = GeneralUtility::makeInstance('FRUIT\\Popup\\Popup'); |
||
92 | if ($target = $popup->getPopupTarget($pageOrPageID)) { |
||
93 | $LD['target'] = $target; |
||
94 | } |
||
95 | } # function - makeMenuLink |
||
96 | |||
97 | |||
98 | /** |
||
99 | * Get the target of a page |
||
100 | * |
||
101 | * @param array|integer $pageOrPageID The Page row or the page ID |
||
102 | * |
||
103 | * @return string |
||
104 | */ |
||
105 | public function getPopupTarget($pageOrPageID) |
||
106 | { |
||
107 | if (MathUtility::canBeInterpretedAsInteger($pageOrPageID)) { |
||
108 | $pageOrPageID = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'pages', |
||
109 | 'uid=' . $pageOrPageID, '', '', 1)); |
||
110 | } # if |
||
111 | |||
112 | if (!is_array($pageOrPageID) || isset($pageOrPageID['tx_popup_configuration']) == false) { |
||
113 | return ''; |
||
114 | } |
||
115 | |||
116 | $config = $pageOrPageID['tx_popup_configuration']; |
||
117 | if (!strlen(trim($config))) { |
||
118 | return ''; |
||
119 | } |
||
120 | return $config; |
||
121 | } # function - getPopupTarget |
||
122 | |||
123 | |||
124 | /** |
||
125 | * Return the default configuration |
||
126 | * |
||
127 | * @param $page |
||
128 | * @param bool $advanced |
||
129 | * |
||
130 | * @return array The default configuration |
||
131 | */ |
||
132 | public function getDefaultConfiguration($page, $advanced = false) |
||
133 | { |
||
134 | $config = $this->loadTypoScript($page); |
||
135 | |||
136 | if (!isset($config['allowedParams.'])) { |
||
137 | return []; |
||
138 | } |
||
139 | $c = $config['allowedParams.']; |
||
140 | if ($advanced && isset($config['advancedParams.'])) { |
||
141 | $c = array_merge($c, $config['advancedParams.']); |
||
142 | } |
||
143 | |||
144 | return $c; |
||
145 | } # function - getDefaultConfiguration |
||
146 | |||
147 | |||
148 | /** |
||
149 | * Text parser for internal popup links |
||
150 | * |
||
151 | * @author Tim Lochmueller |
||
152 | * @author before 2009 Mathias Schreiber, Rene Fritz |
||
153 | */ |
||
154 | function textParse($content, $conf) |
||
155 | { |
||
156 | |||
157 | // ################ |
||
158 | // Default vars |
||
159 | // Noch auslagern und f�r beides benutzen |
||
160 | // ######################### |
||
161 | |||
162 | $JSpopup['link'] = $content['url']; |
||
163 | $JSpopup['ATagParams'] = $content['ATagParams']; |
||
164 | $JSpopup['windowname'] = 'Easy Popup'; |
||
165 | |||
166 | $JSpopup['properties']['dependent'] = 'yes'; |
||
167 | $JSpopup['properties.']['height'] = '300'; |
||
168 | $JSpopup['properties.']['left'] = '10'; |
||
169 | $JSpopup['properties.']['location'] = 'yes'; |
||
170 | $JSpopup['properties.']['menubar'] = 'no'; |
||
171 | $JSpopup['properties.']['resizable'] = 'yes'; |
||
172 | $JSpopup['properties.']['scrollbars'] = 'yes'; |
||
173 | $JSpopup['properties.']['status'] = 'no'; |
||
174 | $JSpopup['properties.']['toolbar'] = 'no'; |
||
175 | $JSpopup['properties.']['top'] = '10'; |
||
176 | $JSpopup['properties.']['width'] = '300'; |
||
177 | |||
178 | |||
179 | $linkContent = ''; |
||
180 | if ($conf['link'] OR is_array($conf['link.'])) { |
||
181 | $conf['link'] = $this->cObj->stdWrap($conf['link'], $conf['link.']); |
||
182 | $conf['ATagParams'] = $this->cObj->stdWrap($conf['ATagParams'], $conf['ATagParams.']); |
||
183 | $conf['windowname'] = $this->cObj->stdWrap($conf['windowname'], $conf['windowname.']); |
||
184 | |||
185 | $JSpopup = $this->array_merge_recursive_overrule($JSpopup, $conf, true); |
||
186 | |||
187 | $linkContent = $this->cObj->stdWrap($conf['linkContent'], $conf['linkContent.']); |
||
188 | } else { |
||
189 | if (isset($this->cObj->parameters['slim'])) { |
||
190 | $JSpopup['properties.']['location'] = 'no'; |
||
191 | $JSpopup['properties.']['menubar'] = 'no'; |
||
192 | $JSpopup['properties.']['status'] = 'no'; |
||
193 | $JSpopup['properties.']['toolbar'] = 'no'; |
||
194 | } |
||
195 | if (isset($this->cObj->parameters['fixed'])) { |
||
196 | $JSpopup['properties.']['resizable'] = 'no'; |
||
197 | $JSpopup['properties.']['scrollbars'] = 'no'; |
||
198 | } |
||
199 | $JSpopup['properties.'] = $this->array_merge_recursive_overrule($JSpopup['properties.'], |
||
200 | $this->cObj->parameters, true); |
||
0 ignored issues
–
show
|
|||
201 | } |
||
202 | |||
203 | $temp = []; |
||
204 | while (list($key, $val) = each($JSpopup['properties.'])) { |
||
205 | $temp[] = $key . '=' . $val; |
||
206 | } |
||
207 | |||
208 | $props = implode(',', $temp); |
||
209 | |||
210 | if (!$JSpopup['link']) { |
||
211 | return ''; |
||
212 | } |
||
213 | |||
214 | $TAG = '<a href="' . $JSpopup['link'] . '" onClick="openPic(this.href,\'' . str_replace(' ', '', |
||
215 | $JSpopup['windowname']) . '\',\'' . $props . '\'); return false;" class="linkpop"' . $JSpopup['ATagParams'] . '>'; |
||
216 | if ($linkContent) { |
||
217 | $TAG .= $linkContent . '</a>'; |
||
218 | } |
||
219 | |||
220 | return $TAG; |
||
221 | } # function - textParse |
||
222 | |||
223 | |||
224 | /** |
||
225 | * Merges two arrays recursively, overruling the values of the first array |
||
226 | * in case of identical keys, ie. keeping the values of the second. |
||
227 | */ |
||
228 | function array_merge_recursive_overrule($arr0, $arr1, $notAddKeys = 0) |
||
229 | { |
||
230 | reset($arr1); |
||
231 | while (list($key, $val) = each($arr1)) { |
||
232 | if (is_array($arr0[$key])) { |
||
233 | if (is_array($arr1[$key])) { |
||
234 | ArrayUtility::mergeRecursiveWithOverrule($arr0[$key], $arr1[$key], $notAddKeys); |
||
235 | } |
||
236 | } else { |
||
237 | if ($notAddKeys) { |
||
238 | if (isset($arr0[$key])) { |
||
239 | $arr0[$key] = $val; |
||
240 | } |
||
241 | } else { |
||
242 | $arr0[$key] = $val; |
||
243 | } |
||
244 | } |
||
245 | } |
||
246 | reset($arr0); |
||
247 | return $arr0; |
||
248 | } # function - array_merge_recursive_overrule |
||
249 | |||
250 | |||
251 | /** |
||
252 | * Load TypoScript for the backend |
||
253 | * This is important for the single configuration concept in the popup extension |
||
254 | */ |
||
255 | function loadTypoScript($pid, $pluginExtKey = 'tx_popup_pi1') |
||
256 | { |
||
257 | |||
258 | $sysPageObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository'); |
||
259 | $rootLine = $sysPageObj->getRootLine($pid); |
||
260 | $TSObj = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\ExtendedTemplateService'); |
||
261 | $TSObj->tt_track = 0; |
||
262 | $TSObj->init(); |
||
263 | $TSObj->runThroughTemplates($rootLine); |
||
264 | $TSObj->generateConfig(); |
||
265 | return $TSObj->setup['plugin.'][$pluginExtKey . '.']; |
||
266 | } # function - loadTypoScript |
||
267 | |||
268 | |||
269 | /** |
||
270 | * Start the convertion prcess |
||
271 | * Init this process mit the parameter for the convertion |
||
272 | * all iligal parameter will be removed |
||
273 | */ |
||
274 | public function convertInit($params) |
||
275 | { |
||
276 | $this->convertParams = $params; |
||
277 | } # function - convertInit |
||
278 | |||
279 | |||
280 | /** |
||
281 | * Convert a TYPO3 Popup configuration String to an Array |
||
282 | * |
||
283 | * @param string $configString The T3 configuration string (Like "width:height:param1=value,param2=value2") |
||
284 | * @param boolean $advanced If set, the advanced parameter will be included in the array |
||
285 | * |
||
286 | * @return array |
||
287 | */ |
||
288 | public function convertCfg2Array($configString, $advanced = false) |
||
289 | { |
||
290 | $params = $this->allowedParams; |
||
291 | if ($advanced) { |
||
292 | $params = array_merge($params, $this->advancedParams); |
||
293 | } |
||
294 | |||
295 | $parts = explode(':', $configString); |
||
296 | if (sizeof($parts) != 2) { |
||
297 | return false; |
||
298 | } |
||
299 | $size = explode('x', $parts[0]); |
||
300 | if (sizeof($size) != 2) { |
||
301 | return false; |
||
302 | } |
||
303 | |||
304 | $config = $this->convertJs2Array('width=' . $size[0] . ',height=' . $size[1] . ',' . $parts[1], $params); |
||
305 | return $this->setAllFields($params, $config); |
||
306 | } # function - convertCfg2Array |
||
307 | |||
308 | |||
309 | /** |
||
310 | * Convert JavaScript Params to an array |
||
311 | * |
||
312 | * @param string $string |
||
313 | * @param string $params Javascript param String (Like "param1=value,param2=value2") |
||
314 | * |
||
315 | * @return array |
||
316 | */ |
||
317 | public function convertJs2Array($string, $params) |
||
318 | { |
||
319 | $config_pre = explode(',', $string); |
||
320 | $config = []; |
||
321 | foreach ($config_pre as $check) { |
||
322 | $p = explode('=', $check); |
||
323 | switch ($params[$p[0]]) { |
||
324 | case 'integer': |
||
325 | $config[$p[0]] = intval($p[1]); |
||
326 | break; |
||
327 | case 'boolean': |
||
328 | $config[$p[0]] = ($p[1] == "yes") ? true : false; |
||
329 | break; |
||
330 | } |
||
331 | } |
||
332 | return $config; |
||
333 | } # function - javaScriptParamsToArray |
||
334 | |||
335 | |||
336 | /** |
||
337 | * Convert an array to a TYPO3 Popup configuration String |
||
338 | * |
||
339 | * @param array $array Data Array of the field (key value pairs) |
||
340 | * @param boolean $advanced If set, the advanced parameter will be included in the array |
||
341 | * |
||
342 | * @return string |
||
343 | */ |
||
344 | public function convertArray2Cfg($array, $advanced = false) |
||
345 | { |
||
346 | $params = $this->allowedParams; |
||
347 | if ($advanced) { |
||
348 | $params = array_merge($params, $this->advancedParams); |
||
349 | } |
||
350 | |||
351 | $array = $this->setAllFields($params, $array); |
||
352 | |||
353 | $cfg = ''; |
||
354 | if (isset($array['height']) && isset($array['width'])) { |
||
355 | $cfg = $array['width'] . 'x' . $array['height'] . ':'; |
||
356 | unset($array['width']); |
||
357 | unset($array['height']); |
||
358 | } |
||
359 | |||
360 | foreach ($array as $key => $value) { |
||
361 | switch ($params[$key]) { |
||
362 | case 'integer': |
||
363 | $cfg .= $key . '=' . intval($value); |
||
364 | break; |
||
365 | case 'boolean': |
||
366 | $cfg .= $key . '=' . (($value) ? 'yes' : 'no'); |
||
367 | break; |
||
368 | } # switch |
||
369 | $cfg .= ','; |
||
370 | } # froeach |
||
371 | |||
372 | return $cfg; |
||
373 | } # function - convertArray2Cfg |
||
374 | |||
375 | |||
376 | /** |
||
377 | * Convert an array to a JS configuration String |
||
378 | */ |
||
379 | public function convertArray2Js($array) |
||
380 | { |
||
381 | $params = $this->allowedParams; |
||
382 | $array = $this->setAllFields($params, $array); |
||
383 | |||
384 | $out = ''; |
||
385 | foreach ($array as $key => $value) { |
||
386 | $out .= ($out != '') ? ',' : ''; |
||
387 | |||
388 | switch ($params[$key]) { |
||
389 | case 'integer': |
||
390 | $out .= $key . '=' . intval($value); |
||
391 | break; |
||
392 | case 'boolean': |
||
393 | $out .= $key . '=' . (($value) ? 'yes' : 'no'); |
||
394 | break; |
||
395 | } # switch |
||
396 | } # foreach |
||
397 | |||
398 | return $out; |
||
399 | } # function - convertArray2Js |
||
400 | |||
401 | |||
402 | /** |
||
403 | * Convert a TYPO3 Popup configuration String to a JS configuration String |
||
404 | */ |
||
405 | public function convertCfg2Js($string) |
||
406 | { |
||
407 | return $this->convertArray2Js($this->convertCfg2Array($string)); |
||
408 | } # function - convertCfg2Js |
||
409 | |||
410 | |||
411 | /** |
||
412 | * Convert a JS configuration string to a TYPO3 Popup configuration |
||
413 | */ |
||
414 | public function convertJs2Cfg($string) |
||
415 | { |
||
416 | return $this->convertArray2Cfg($this->convertJs2Array($string, [])); |
||
417 | } # function - convertJs2Cfg |
||
418 | |||
419 | |||
420 | /** |
||
421 | * Set all fields in the given configuration by the param parameter |
||
422 | */ |
||
423 | private function setAllFields($params, $config) |
||
424 | { |
||
425 | $param = []; |
||
426 | foreach (array_keys($params) as $p) { |
||
427 | if (!in_array($p, array_keys($config))) { |
||
428 | switch ($params[$p]) { |
||
429 | case 'integer': |
||
430 | $config[$p] = 0; |
||
431 | break; |
||
432 | case 'boolean': |
||
433 | $config[$p] = false; |
||
434 | break; |
||
435 | } # switch |
||
436 | } # if |
||
437 | } # foreach |
||
438 | return $config; |
||
439 | } # function - setAllFields |
||
440 | |||
441 | |||
442 | } |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: