These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace FRUIT\Popup\Controller; |
||
4 | |||
5 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
||
6 | |||
7 | /*************************************************************** |
||
8 | * Copyright notice |
||
9 | * |
||
10 | * (c) 2009 Tim Lochmueller <[email protected]> |
||
11 | * 2003-2006 Martin Kutschker <[email protected]> |
||
12 | * 2003: Traktor Wien (formerly Global Spanking Industries) |
||
13 | * 2005: ACTIVE SOLUTION Software AG |
||
14 | * All rights reserved |
||
15 | * |
||
16 | * This script is part of the Typo3 project. The Typo3 project is |
||
17 | * free software; you can redistribute it and/or modify |
||
18 | * it under the terms of the GNU General Public License as published by |
||
19 | * the Free Software Foundation; either version 2 of the License, or |
||
20 | * (at your option) any later version. |
||
21 | * |
||
22 | * The GNU General Public License can be found at |
||
23 | * http://www.gnu.org/copyleft/gpl.html. |
||
24 | * |
||
25 | * This script is distributed in the hope that it will be useful, |
||
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
28 | * GNU General Public License for more details. |
||
29 | * |
||
30 | * This copyright notice MUST APPEAR in all copies of the script! |
||
31 | ***************************************************************/ |
||
32 | class PluginController extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin |
||
33 | { |
||
34 | |||
35 | /** |
||
36 | * Same as class name |
||
37 | */ |
||
38 | public $prefixId = 'tx_popup_pi1'; |
||
39 | |||
40 | |||
41 | /** |
||
42 | * Path to this script relative to the extension dir. |
||
43 | */ |
||
44 | var $scriptRelPath = 'pi1/class.tx_popup_pi1.php'; |
||
45 | |||
46 | |||
47 | /** |
||
48 | * The extension key. |
||
49 | */ |
||
50 | var $extKey = 'popup'; |
||
51 | |||
52 | |||
53 | /** |
||
54 | * Init the popup frontend plugin |
||
55 | * |
||
56 | * @return void |
||
57 | */ |
||
58 | private function init() |
||
59 | { |
||
60 | $this->popup = GeneralUtility::makeInstance('FRUIT\\Popup\\Popup'); |
||
61 | $this->allowedParams = $this->popup->allowedParams; |
||
62 | $this->customParams = $this->popup->advancedParams; |
||
63 | } # function - init |
||
64 | |||
65 | |||
66 | /** |
||
67 | * Generate JS code for opening pop-up |
||
68 | * Main Plugin function for T3 |
||
69 | * |
||
70 | * @param $content String |
||
71 | * @param $conf Array Plugin configuration |
||
72 | * @return The Plugin Output |
||
73 | */ |
||
74 | function main($content, $conf) |
||
0 ignored issues
–
show
|
|||
75 | { |
||
76 | // Init |
||
77 | $this->init(); |
||
78 | |||
79 | |||
80 | $link = $this->cObj->data['tx_popup_auto']; |
||
81 | if (!$link) { |
||
82 | GeneralUtility::devLog('No link defined', $this->extKey); |
||
83 | return ''; |
||
84 | } |
||
85 | |||
86 | // get session data |
||
87 | if ($conf['advancedParams.']['once_per_session']) { |
||
88 | $popups = $GLOBALS['TSFE']->fe_user->getKey('ses', $this->prefixId); |
||
89 | if ($conf['advancedParams.']['once_per_link']) { |
||
90 | if ($popups['links'][$link]) { |
||
91 | GeneralUtility::devLog('Pop-up link "' . $link . '" already shown.', $this->extKey); |
||
92 | return ''; |
||
93 | } else { |
||
94 | $popups['links'][$link] = 1; |
||
95 | } |
||
96 | } else { |
||
97 | if ($popups['pages'][$GLOBALS['TSFE']->id]) { // we have been on the current page |
||
98 | GeneralUtility::devLog('Pop-up already shown on this page.', $this->extKey); |
||
99 | return ''; |
||
100 | } else { |
||
101 | $popups['pages'][$GLOBALS['TSFE']->id] = 1; |
||
102 | } |
||
103 | } |
||
104 | $GLOBALS['TSFE']->fe_user->setKey('ses', $this->prefixId, $popups); |
||
105 | } |
||
106 | |||
107 | // create the url |
||
108 | $url = $this->cObj->getTypoLink_URL($link); |
||
109 | if (!$url) { |
||
110 | GeneralUtility::devLog('No valid pop-up (e.g. a hidden page):' . $link, $this->extKey); |
||
111 | return ''; |
||
112 | } |
||
113 | |||
114 | // get the JS window parameters directly (protect from errors in TS?) |
||
115 | $params = $conf['allowedParams.']; |
||
116 | |||
117 | // get the custom parameters |
||
118 | $cParams = []; |
||
119 | foreach ($this->customParams as $name => $type) { |
||
120 | $v = $conf['advancedParams.'][$name]; |
||
121 | $cParams[$name] = ($v === '1' || $v == 'yes' || $v == 'on') ? true : false; |
||
122 | } |
||
123 | |||
124 | |||
125 | // thanks to Alex Widschwendter |
||
126 | if ($cParams['maximize']) { |
||
127 | $params['left'] = 0; |
||
128 | $params['top'] = 0; |
||
129 | $params['width'] = '\' + screen.width + \''; |
||
130 | $params['height'] = '\' + screen.height + \''; |
||
131 | } // thanks to Daniel Rampanelli |
||
132 | elseif ($cParams['center'] && $params['width'] > 0 && $params['height'] > 0) { |
||
133 | $params['left'] = '\' + ((screen.width - ' . $params['width'] . ') / 2) + \''; |
||
134 | $params['top'] = '\' + ((screen.height - ' . $params['height'] . ') / 2) + \''; |
||
135 | $params['screenX'] = '\' + ((screen.width - ' . $params['width'] . ') / 2) + \''; |
||
136 | $params['screenY'] = '\' + ((screen.height - ' . $params['height'] . ') / 2) + \''; |
||
137 | } |
||
138 | |||
139 | while (list($key, $val) = each($params)) { |
||
140 | if (isset($val) && $val != '') { |
||
141 | $tmp_params[] = $key . '=' . $val; |
||
142 | } |
||
143 | } |
||
144 | $params = implode(",", $tmp_params); |
||
145 | |||
146 | |||
147 | // Build Javascript |
||
148 | $content = '<script type="text/javascript"> |
||
149 | /*<![CDATA[*/ |
||
150 | <!-- |
||
151 | '; |
||
152 | $window = uniqid('_popup_'); |
||
153 | |||
154 | $content .= "var $window = window.open('$url', 'Window', '$params');\n"; |
||
155 | |||
156 | // thanks to Tom Binder for the timeout |
||
157 | if ($cParams['popunder']) { |
||
158 | $content .= "if ($window) { window.setTimeout('$window.blur()',500); window.focus(); }"; |
||
159 | } else { |
||
160 | $content .= "if ($window) { window.setTimeout('$window.focus()',500); }"; |
||
161 | } |
||
162 | |||
163 | $content .= "\n// -->\n/*]]>*/</script>\n"; |
||
164 | |||
165 | return $content; |
||
166 | } |
||
167 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.