PluginProbe
Advanced iFrame / 2.1
Advanced iFrame v2.1
trunk 1.3 2.1 2024.5 2025.10 2025.2 2025.6 2026.0 3.0
advanced-iframe / advanced-iframe.php

advanced-iframe.php in Advanced iFrame 2.1, at advanced-iframe.php

402 lines 22.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Advanced iframe
4 Plugin URI: http://www.tinywebgallery.com/blog/advanced-iframe
5 Version: 2.1
6 Author: Michael Dempfle
7 Author URI: http://www.tinywebgallery.com
8 Description: This plugin includes any webpage as shortcode in an advanced iframe.
9 This program is 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 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 if (!class_exists('advancediFrame')) {
22 class advancediFrame {
23 var $adminOptionsName = 'advancediFrameAdminOptions';
24
25 //
26 // class constructor
27 //
28 function advancediFrame() {
29 }
30
31 function init() {
32 $this->getAdminOptions();
33 }
34
35 function activate() {
36 $this->getAdminOptions();
37 }
38
39 function iframe_defaults() {
40 $iframeAdminOptions = array(
41 'securitykey' => sha1(session_id()),
42 'src' => 'http://www.tinywebgallery.com', 'width' => '100%',
43 'height' => '600', 'scrolling' => 'no', 'marginwidth' => '0', 'marginheight' => '0',
44 'frameborder' => '0', 'transparency' => 'true', 'content_id' => '', 'content_styles' => '',
45 'hide_elements' => '', 'class' => '', 'shortcode_attributes' => 'true', 'url_forward_parameter' => '',
46 'id' => 'advanced_iframe', 'name' => '',
47 'onload' => '', 'onload_resize' => 'false', 'onload_scroll_top' => 'false',
48 'additional_js' => '', 'additional_css' => '', 'store_height_in_cookie' => 'false',
49 'additional_height' => '0', 'iframe_content_id' => '', 'iframe_content_styles' => '',
50 'iframe_hide_elements' => '', 'version_counter' => '1', 'onload_show_element_only' => ''
51 );
52 return $iframeAdminOptions;
53 }
54
55 function getAdminOptions() {
56 $iframeAdminOptions = advancediFrame::iframe_defaults();
57 $devOptions = get_option("advancediFrameAdminOptions");
58 if (!empty($devOptions)) {
59 foreach ($devOptions as $key => $option)
60 $iframeAdminOptions[$key] = $option;
61 }
62 update_option("advancediFrameAdminOptions", $iframeAdminOptions);
63 return $iframeAdminOptions;
64 }
65
66 function loadLanguage() {
67 load_plugin_textdomain('advanced-iframe', false, dirname(plugin_basename(__FILE__)) . '/languages/');
68 wp_enqueue_script('jquery');
69 }
70
71 /* CSS for the admin area */
72 function addAdminHeaderCode() {
73 echo '<link type="text/css" rel="stylesheet" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/advanced-iframe/css/ai.css" />' . "\n";
74 echo '<script type="text/javascript" src="' . get_bloginfo('wpurl') . '/wp-content/plugins/advanced-iframe/js/ai.js" ></script>' . "\n";
75 }
76
77 /* additional CSS for wp area */
78 function addWpHeaderCode($atts) {
79 $options = get_option('advancediFrameAdminOptions');
80 // defaults
81 extract(array('additional_css' => $options['additional_css'],
82 'additional_js' => $options['additional_js'],
83 'version_counter' => $options['version_counter'],
84 $atts));
85 // read the shortcode attributes
86 if ($options['shortcode_attributes'] == 'true') {
87 extract(shortcode_atts(array('additional_css' => $options['additional_css'],
88 'additional_js' => $options['additional_js']), $atts));
89 }
90 if ($additional_css != '') {
91 wp_register_style( 'additional-advanced-iframe', $additional_css, false, $version_counter);
92 wp_enqueue_style( 'additional-advanced-iframe' );
93 // wp_enqueue_style( 'additional-advanced-iframe', $additional_css , false );
94 }
95 if ($additional_js != '' && version_compare(get_bloginfo('version'), '3.3') < 0 ) { // wp < 3.3
96 wp_register_script( 'additional-advanced-iframe', $additional_js, false, $version_counter);
97 wp_enqueue_script( 'additional-advanced-iframe');
98 }
99 }
100
101 function param($param, $content = null) {
102 $value = isset($_GET[$param]) ? $_GET[$param] : '';
103 return esc_html($value);
104 }
105
106 function do_iframe_script($atts) {
107 $options = get_option('advancediFrameAdminOptions');
108 // defaults for new settings in 2.0
109 if (!isset ($options['id'])) { $options['id'] = ''; }
110 if (!isset ($options['name'])) { $options['name'] = ''; }
111 if (!isset ($options['onload'])) { $options['onload'] = ''; }
112 if (!isset ($options['onload_resize'])) { $options['onload_resize'] = 'false'; }
113 if (!isset ($options['onload_scroll_top'])) { $options['onload_scroll_top'] = 'false'; }
114 if (!isset ($options['additional_js'])) { $options['additional_js'] = ''; }
115 if (!isset ($options['additional_css'])) { $options['additional_css'] = ''; }
116 if (!isset ($options['store_height_in_cookie'])) { $options['store_height_in_cookie'] = 'false'; }
117 if (!isset ($options['additional_height'])) { $options['additional_height'] = 0; }
118 if (!isset ($options['iframe_content_id'])) { $options['iframe_content_id'] = ''; }
119 if (!isset ($options['iframe_content_styles'])) { $options['iframe_content_styles'] = ''; }
120 if (!isset ($options['iframe_hide_elements'])) { $options['iframe_hide_elements'] = ''; }
121 if (!isset ($options['version_counter'])) { $options['version_counter'] = '1'; }
122 if (!isset ($options['onload_show_element_only'])) { $options['onload_show_element_only'] = ''; }
123
124 // defaults from main config
125 extract(array('securitykey' => 'not set',
126 'src' => $options['src'], 'height' => $options['height'], 'width' => $options['width'],
127 'frameborder' => $options['frameborder'], 'scrolling' => $options['scrolling'],
128 'marginheight' => $options['marginheight'], 'marginwidth' => $options['marginwidth'],
129 'transparency' => $options['transparency'], 'content_id' => $options['content_id'],
130 'content_styles' => $options['content_styles'], 'hide_elements' => $options['hide_elements'],
131 'class' => $options['class'], 'url_forward_parameter' => $options['url_forward_parameter'],
132 'id' => $options['id'], 'name' => $options['name'],
133 'onload' => $options['onload'], 'onload_resize' => $options['onload_resize'],
134 'onload_scroll_top'=> $options['onload_scroll_top'],
135 'additional_js'=> $options['additional_js'],
136 'additional_css'=> $options['additional_css'],
137 'store_height_in_cookie'=> $options['store_height_in_cookie'],
138 'additional_height' => $options['additional_height'],
139 'iframe_content_id' => $options['iframe_content_id'],
140 'iframe_content_styles' => $options['iframe_content_styles'],
141 'iframe_hide_elements' => $options['iframe_hide_elements'],
142 'version_counter' => $options['version_counter'],
143 'onload_show_element_only' => $options['onload_show_element_only'],
144 $atts));
145 // read the shortcode attributes
146 if ($options['shortcode_attributes'] == 'true') {
147 // src value can be hidden in [0] and [1] if the editor does hotlink the url. Therefore I look in there if the src is not set!
148 if (!isset($atts['src'])) {
149 if (isset($atts[0]) && (stristr($atts[0], 'src') !== FALSE)) {
150 if (isset($atts[1])) {
151 $input = '<a ' . $atts[1];
152 $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>";
153 if(preg_match_all("/$regexp/siU", $input, $matches)) {
154 if (isset($matches[2])) {
155 $atts['src'] = $matches[2][0];
156 }
157 }
158 }
159 }
160 }
161 extract(shortcode_atts(array('securitykey' => 'not set',
162 'src' => $options['src'], 'height' => $options['height'], 'width' => $options['width'],
163 'frameborder' => $options['frameborder'], 'scrolling' => $options['scrolling'],
164 'marginheight' => $options['marginheight'], 'marginwidth' => $options['marginwidth'],
165 'transparency' => $options['transparency'], 'content_id' => $options['content_id'],
166 'content_styles' => $options['content_styles'], 'hide_elements' => $options['hide_elements'],
167 'class' => $options['class'], 'url_forward_parameter' => $options['url_forward_parameter'],
168 'id' => $options['id'], 'name' => $options['name'],
169 'onload' => $options['onload'],
170 'onload_resize' => $options['onload_resize'],
171 'onload_scroll_top'=> $options['onload_scroll_top'],
172 'additional_js'=> $options['additional_js'],
173 'additional_css'=> $options['additional_css'],
174 'store_height_in_cookie'=> $options['store_height_in_cookie'],
175 'additional_height' => $options['additional_height'],
176 'iframe_content_id' => $options['iframe_content_id'],
177 'iframe_content_styles' => $options['iframe_content_styles'],
178 'iframe_hide_elements' => $options['iframe_hide_elements'],
179 'onload_show_element_only' => $options['onload_show_element_only'],
180 )
181 , $atts));
182 } else {
183 // only the secrity key is read.
184 extract(shortcode_atts(array('securitykey' => 'not set'), $atts));
185 }
186
187 if (empty ($id)) {
188 $id = 'advanced_iframe';
189 }
190 if (empty ($name)) {
191 $name = 'advanced_iframe';
192 }
193
194 echo '<link type="text/css" rel="stylesheet" href="' . get_bloginfo('wpurl') . '/wp-content/plugins/advanced-iframe/css/ai.css" />' . "\n";
195 echo '<script type="text/javascript" src="' . get_bloginfo('wpurl') . '/wp-content/plugins/advanced-iframe/js/ai.js" ></script>' . "\n";
196
197 if ($store_height_in_cookie == 'true') {
198 echo '<script type="text/javascript">aiEnableCookie=true; aiId="' . $id . '";</script>';
199 }
200 if ($additional_height != 0) {
201 echo '<script type="text/javascript">aiExtraSpace=' . $additional_height . ';</script>';
202 }
203 echo '<script type="text/javascript">function aiResizeIframeHeight(height) { aiResizeIframeHeightById("'.$id.'",height); }</script>' . "\n";
204
205 if ($options['securitykey'] != $securitykey) {
206 echo '<div class="errordiv">' . __('An invalid security key was specified. Please use at least the following shortcode:<br>[advanced_iframe securitykey="&lt;your security key - see settings&gt;"]. Please also check in the html mode that your shortcode does only contain notmal spaces and not a &amp;nbsp; instead.', 'advanced-iframe') . '</div>';
207 return;
208 } else {
209 // add parameters
210 if ($url_forward_parameter != '') {
211 $sep = "&amp;";
212 if (strpos($src, '?') === false) {
213 $sep = '?';
214 }
215 $parameters = explode(",", $url_forward_parameter);
216 foreach ($parameters as $parameter) {
217 $read_param_esc = $this->param($parameter);
218 if ($read_param_esc != '') {
219 $src .= $sep . $parameter . "=" . $read_param_esc;
220 $sep = "&amp;";
221 }
222 }
223 }
224
225 $html = '';
226
227 if ((!empty($content_id) && !empty($content_styles)) || !empty($hide_elements)) {
228
229
230 // hide elements is called directy in the page to hide elements as fast as quickly
231 $hidehtml = '';
232 if (!empty($hide_elements)) {
233 $hidehtml .= "jQuery('" . esc_html($hide_elements) . "').css('display', 'none');";
234 }
235 if (!empty($content_id)) {
236 $elements = esc_html($content_id); // this field should not have a problem if they are encoded.
237 $values = esc_html($content_styles); // this field style should not have a problem if they are encoded.
238 $elementArray = explode("|", $elements);
239 $valuesArray = explode("|", $values);
240 if (count($elementArray) != count($valuesArray)) {
241 echo '</script><div class="errordiv">' . __('Configuration error: The attributes content_id and content_styles have to have the amount of value sets separated by |.', 'advanced-iframe') . '</div>';
242 return;
243 } else {
244 for ($x = 0; $x < count($elementArray); ++$x) {
245 $valuesArrayPairs = explode(";", trim($valuesArray[$x], " ;:"));
246 for ($y = 0; $y < count($valuesArrayPairs); ++$y) {
247 $elements = explode(":", $valuesArrayPairs[$y]);
248 $hidehtml .= "jQuery('" . $elementArray[$x] . "').css('" . $elements[0] . "', '" . $elements[1] . "');";
249 }
250 }
251 }
252 }
253 $html .= '<script type="text/javascript">';
254 $html .= 'function aiModifyParent() { ';
255 $html .= $hidehtml;
256 $html .= '}';
257 $html .= 'jQuery(document).ready(function() { ';
258 $html .= 'aiModifyParent();';
259 $html .= ' });';
260 $html .= 'aiModifyParent();';
261 $html .= '</script>';
262 }
263
264 // jQuery("#advanced_iframe").contents().find("#iframe-div").css("border","4px solid blue");
265 $hideiframehtml = '';
266 if ((!empty($iframe_content_id) && !empty($iframe_content_styles))|| !empty($iframe_hide_elements)) {
267
268 // hide elements is called directy in the page to hide elements as fast as quickly
269 $hideiframehtml = '';
270 if (!empty($iframe_hide_elements)) {
271 $hideiframehtml .= "jQuery('#".$id."').contents().find('" .
272 esc_html($iframe_hide_elements) . "').css('display', 'none');";
273 }
274 if (!empty($iframe_content_id)) {
275 $elements = esc_html($iframe_content_id); // this field should not have a problem if they are encoded.
276 $values = esc_html($iframe_content_styles); // this field style should not have a problem if they are encoded.
277 $elementArray = explode("|", $elements);
278 $valuesArray = explode("|", $values);
279 if (count($elementArray) != count($valuesArray)) {
280 echo '</script><div class="errordiv">' . __('Configuration error: The attributes iframe_content_id and iframe_content_styles have to have the amount of value sets separated by |.', 'advanced-iframe') . '</div>';
281 return;
282 } else {
283 for ($x = 0; $x < count($elementArray); ++$x) {
284 $valuesArrayPairs = explode(";", trim($valuesArray[$x], " ;:"));
285 for ($y = 0; $y < count($valuesArrayPairs); ++$y) {
286 $elements = explode(":", $valuesArrayPairs[$y]);
287 $hideiframehtml .= "jQuery('#".$id."').contents().find('" . $elementArray[$x]
288 . "').css('" . $elements[0] . "', '" . $elements[1] . "');";
289 }
290 }
291 }
292 }
293 if ($hideiframehtml != '') {
294 $html .= '<script type="text/javascript">';
295 $html .= 'function aiModifyIframe() { ';
296 $html .= $hideiframehtml;
297 $html .= '}';
298 $html .= '</script>';
299 }
300 }
301
302
303
304
305 $html .= "<iframe id='" . esc_html($id) . "' ";
306 if (!empty ($name)) {
307 $html .= " name='" . esc_html($name) . "' ";
308 }
309 $html .= " src='" . $src . "' width='" . esc_html($width) . "' height='" . esc_html($height) .
310 "' scrolling='" . esc_html($scrolling) . "' ";
311
312 if (!empty ($marginwidth)) {
313 $html .= " marginwidth='" . esc_html($marginwidth) . "' ";
314 }
315 if (!empty ($marginheight)) {
316 $html .= " marginheight='" . esc_html($marginheight) . "' ";
317 }
318 if ($frameborder != '') {
319 $html .= " frameborder='" . esc_html($frameborder) . "' ";
320 if ($frameborder == 0) {
321 $html .= " border='0' ";
322 }
323 }
324 if (!empty ($transparency)) {
325 $html .= " allowtransparency='" . esc_html($transparency) . "' ";
326 }
327 if (!empty ($class)) {
328 $html .= " class='" . esc_html($class) . "' ";
329 }
330 // create onload string
331 $onload_str = '';
332 if ($hideiframehtml) {
333 $onload_str .= ';aiModifyIframe();';
334 }
335
336 if (!empty ($onload)) {
337 $onload_str .= esc_html($onload);
338 }
339 if (!empty($onload_show_element_only)) {
340 $onload_str .= ';aiShowElementOnly("#'.$id.'","'.$onload_show_element_only.'");';
341 }
342 if ($onload_resize == 'true') {
343 $onload_str .= ';aiResizeIframe(this);';
344 }
345 if ($onload_scroll_top == 'true') {
346 $onload_str .= ';aiScrollToTop();';
347 }
348 if ($onload_str != '') {
349 $html .= " onload='" . esc_js($onload_str) . "' ";
350 }
351 $html .= "></iframe>\n ";
352 if ($store_height_in_cookie == 'true') {
353 $html .= '<script type="text/javascript">aiUseCookie();</script>';
354 }
355 if ($additional_js != '' && version_compare(get_bloginfo('version'), '3.3') >= 0 ) { // wp >= 3.3
356 wp_register_script( 'additional-advanced-iframe', $additional_js, false, $version_counter);
357 wp_enqueue_script( 'additional-advanced-iframe');
358 }
359
360 }
361 return $html;
362 }
363
364 function add_script_footer() {
365 echo '<script type="text/javascript">if(window.aiModifyParent) {aiModifyParent();}</script>';
366 }
367
368
369 function printAdminPage() {
370 require_once('advanced-iframe-admin-page.php');
371 }
372 }
373 }
374 // setup new instance of plugin
375 if (class_exists("advancediFrame")) {
376 $cons_advancediFrame = new advancediFrame();
377 }
378 //Actions and Filters
379 if (isset($cons_advancediFrame)) {
380 //Initialize the admin panel
381 if (!function_exists('advancediFrame_ap')) {
382 function advancediFrame_ap() {
383 global $cons_advancediFrame;
384 if (!isset($cons_advancediFrame)) {
385 return;
386 }
387 $options = $cons_advancediFrame->getAdminOptions();
388 if (function_exists('add_options_page')) {
389 add_options_page('Advanced iFrame', 'Advanced iFrame', 'manage_options', basename(__FILE__), array(&$cons_advancediFrame, 'printAdminPage'));
390 }
391 }
392 }
393 add_action('admin_menu', 'advancediFrame_ap', 1); //admin page
394 add_action('init', array(&$cons_advancediFrame, 'loadLanguage'), 1); // add languages
395 add_action('admin_head', array(&$cons_advancediFrame, 'addAdminHeaderCode'), 99); // load css
396 add_action('wp_enqueue_scripts', array(&$cons_advancediFrame, 'addWpHeaderCode'), 98); // load css
397 add_action('wp_footer', array(&$cons_advancediFrame, 'add_script_footer'), 2);
398
399 add_shortcode('advanced_iframe', array(&$cons_advancediFrame, 'do_iframe_script'), 1); // setup shortcode [twg]
400 register_activation_hook(__FILE__, array(&$cons_advancediFrame, 'activate'));
401 }
402 ?>