PluginProbe
Advanced iFrame / 2025.2
Advanced iFrame v2025.2
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 2025.2, at advanced-iframe.php

1,932 lines 84.7 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: https://wordpress.org/plugins/advanced-iframe/
5 Version: 2025.2
6 Text Domain: advanced-iframe
7 Domain Path: /languages
8 Author: Michael Dempfle
9 Author URI: https://www.tinywebgallery.com
10 License: GPLv2 or later
11 Description: This plugin includes any web page as shortcode in an advanced iframe or embeds the content directly.
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17 This program 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 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25 define('_VALID_AI', '42');
26 define('AIP_URL', plugin_dir_url(__FILE__));
27 define('AIP_IMGURL', AIP_URL . 'img');
28
29 // enable this if nothing is working anymore to see as much output as possible on the page.
30 // ini_set('display_errors', 1);
31 // ini_set('display_startup_errors', 1);
32 // error_reporting(E_ALL);
33
34 $aiVersion = '2025.2';
35 // check $aiJsSize
36
37 $cons_advancediFrame = null;
38 $aiSlug = 'advanced-iframe';
39
40 if (function_exists('ai_fs')) {
41 ai_fs()->set_basename(false, __FILE__);
42 } else {
43 // DO NOT REMOVE THIS IF, IT IS ESSENTIAL FOR THE `function_exists` CALL ABOVE TO PROPERLY WORK.
44 if (!isset($aip_standalone) || !function_exists('ai_fs')) {
45 // Create a helper function for easy SDK access.
46 function ai_fs() {
47 global $ai_fs;
48 if (!isset($ai_fs)) {
49 // Include Freemius SDK.
50 require_once dirname(__FILE__) . '/vendor/freemius/start.php';
51 $ai_fs = fs_dynamic_init(array(
52 'id' => '13759',
53 'slug' => 'advanced-iframe',
54 'premium_slug' => 'advanced-iframe-pro',
55 'type' => 'plugin',
56 'public_key' => 'pk_c036fd9bca5f583ac92d1a58451a5',
57 'is_premium' => false,
58 'premium_suffix' => 'Pro',
59 'has_addons' => false,
60 'has_paid_plans' => true,
61 'trial' => array(
62 'days' => 30,
63 'is_require_payment' => true,
64 ),
65 'menu' => array(
66 'slug' => 'advanced-iframe',
67 'support' => false,
68 ),
69 'is_live' => true,
70 ));
71 }
72 return $ai_fs;
73 }
74
75 // Init Freemius.
76 ai_fs();
77 // Signal that SDK was initiated.
78 do_action('ai_fs_loaded');
79
80
81 function ai_fs_custom_connect_message_on_update($message, $user_first_name,
82 $product_title, $user_login, $site_link, $freemius_link) {
83 return sprintf(__('We have introduced this OPT-IN so you never miss an important update and help us make the plugin more compatible with your site and better at doing what you need it to.<br><br>OPT-IN to get email notifications for security & feature updates, educational content, and occasional offers, and to share some basic WordPress environment info. If you skip this, that\'s okay! %1$s will still shown just fine and after 10.000 views only a small notice is shown on the iframe.<br><br>If you OPT-IN you will get <strong>unlimited views</strong> in the free version.', 'advanced-iframe'), '<b>' . $product_title . '</b>');
84 }
85
86 ai_fs()->add_filter('connect_message_on_update', 'ai_fs_custom_connect_message_on_update', 10, 6);
87 ai_fs()->add_action('after_uninstall', 'ai_fs_uninstall_cleanup');
88 ai_fs()->add_filter( 'is_pricing_page_visible', '__return_true' );
89 ai_fs()->add_filter('default_currency', function () {
90 return 'eur';
91 });
92 }
93
94
95 if (isset($aip_standalone)) {
96 define('AIP_URL_CUSTOM', plugins_url() . '/../advanced-iframe-custom/');
97 } else {
98 define('AIP_URL_CUSTOM', plugins_url() . '/advanced-iframe-custom/');
99 }
100
101 include dirname(__FILE__) . '/includes/advanced-iframe-main-helper.php';
102 include dirname(__FILE__) . '/includes/advanced-iframe-main-cookie.php';
103
104 $isFreemius = true;
105 $isFreemiusMigration = true;
106 $showFreemiusMigration = false;
107
108 if (!class_exists('advancediFrame')) {
109 class advancediFrame {
110 public $adminOptionsName = 'advancediFrameAdminOptions';
111 public $page = 'advanced-iframe';
112 public $scriptsNeeded = false;
113 public $renderIframe = true;
114
115 /**
116 * wp activate
117 */
118 function activate() {
119 $options = $this->getAiAdminOptions();
120 if (!wp_next_scheduled('ai_check_iframes_event')) {
121 wp_schedule_event(time(), 'daily', 'ai_check_iframes_event');
122 }
123 if ($options['src'] === '//www.tinywebgallery.com') {
124 $options['src'] = '//www.tinywebgallery.com/blog/advanced-iframe';
125 }
126 update_option($this->adminOptionsName, $options);
127 $this->resetMetaBoxes();
128 $this->saveExternalJsFile();
129 }
130
131 function aiUpdate($upgrader_object, $options) {
132 global $aiVersion;
133 $current_plugin_path_name = plugin_basename(__FILE__);
134
135 if ($options['action'] === 'update' && $options['type'] === 'plugin' && is_array($options['plugins'])) {
136 foreach ($options['plugins'] as $each_plugin) {
137 if ($each_plugin == $current_plugin_path_name) {
138 $this->saveExternalJsFile(false);
139 }
140 }
141 } elseif ($options['action'] === 'install' && $options['type'] === 'plugin') {
142 $this->saveExternalJsFile(false);
143 }
144 }
145
146 function resetMetaBoxes() {
147 $options = get_option($this->adminOptionsName);
148 $current_user = wp_get_current_user();
149 delete_user_meta($current_user->ID, 'closedpostboxes_toplevel_page_advanced-iframe');
150 get_user_meta($current_user->ID, 'closedpostboxes_toplevel_page_advanced-iframe', true) ?: array();
151 $closed_widgets = array('id-advanced-features', 'id-advanced-resize', 'id-advanced-part', 'id-advanced-hide'
152 , 'id-advanced-modify-iframe', 'id-advanced-modify-parent', 'id-advanced-layer', 'id-advanced-zoom', 'id-advanced-lazy', 'id-external-ai-overview'
153 , 'id-external-ai-config-files', 'id-external-ai-config-files-url', 'id-files-overview', 'id-file-parent', 'id-file-iframe', 'id-files-include'
154 , 'id-file-parent', 'id-help-video', 'id-help-faq', 'id-help-forum', 'id-help-support', 'id-help-id', 'id-help-jquery', 'id-help-browser'
155 , 'id-help-communication', 'id-help-twg', 'id-advanced-parameters', 'id-options-display', 'id-options-debug', 'id-options-check-monitoring',
156 'id-options-other-iframe', 'id-options-share', 'id-options-technical', 'id-options-delete', 'id-options-widget', 'id-options-vote');
157
158 if (!empty($options['purchase_code'])) {
159 $closed_widgets[] = 'id-options-registration';
160 }
161 update_user_meta($current_user->ID, 'closedpostboxes_toplevel_page_advanced-iframe', $closed_widgets);
162 }
163
164 /*
165 * wp deactivate
166 */
167 function deactivate() {
168 wp_clear_scheduled_hook('ai_check_iframes_event');
169 $options = get_option($this->adminOptionsName);
170 delete_transient('aip_cache_check_' . $options['src']);
171 }
172
173 function aiCheckIframes() {
174 include_once dirname(__FILE__) . '/includes/advanced-iframe-admin-functions.php';
175 $options = get_option($this->adminOptionsName);
176 if ($options['check_iframe_cronjob'] === 'true') {
177 $before = time();
178 if (empty ($options['check_iframe_cronjob_email'])) {
179 $to = get_bloginfo('admin_email');
180 } else {
181 $to = $options['check_iframe_cronjob_email'];
182 }
183 $result = ai_check_all_iframes($options['src'], $options['check_iframe_batch_size']);
184 $total_time = time() - $before;
185
186 $body = '<html><head>';
187 $body .= '</head><body>';
188 $body .= __('Hello advanced iframe pro user,', 'advanced-iframe');
189 $body .= '<p>';
190 if ($result['overall_status'] === 'red') {
191 $subject = __('At least one of your iframes failed!', 'advanced-iframe');
192 $body .= __('At least one of the iframes you have configured has a src which does not work properly.<br>Please go to the administration of advanced iframe pro to get more details.</p>', 'advanced-iframe');
193
194 $body_links = '<ul>';
195 $downgrade = 0;
196 foreach ($result['links'] as $iframes) {
197 foreach ($iframes['links'] as $link => $resultLink) {
198 if ($resultLink['status'] === 'red') {
199 $body_links .= '<li>Page: ' . esc_html($iframes['link']) . ', link: ' . esc_attr($link) . '</li>';
200 if ($resultLink['http_downgrade']) {
201 $downgrade++;
202 }
203 }
204 }
205 }
206 $body_links .= '</ul>';
207
208 if ($downgrade > 0) {
209 $body .= '<p>' . $downgrade . ' of your iframes failed because your page was accessed by https and your iframes are http! Make sure that your users get redirected to the http version of your site or use https also in the iframes!</p>';
210 }
211
212 $body .= __('<p>The following iframe(s) failed:', 'advanced-iframe');
213 $body .= $body_links;
214
215 } elseif ($result['overall_status'] === 'orange') {
216 $subject = __('At least one of your iframes is not optimal configured!', 'advanced-iframe');
217 $body .= __('At least one of the iframes you have configured has most likely a src which is redirected.<br>Please go to the administration of advanced iframe pro to get more details.</p><p>The following iframe(s) have issues: ', 'advanced-iframe');
218 $body .= '<ul>';
219 foreach ($result['links'] as $iframes) {
220 foreach ($iframes['links'] as $link => $resultLink) {
221 if ($resultLink['status'] === 'orange') {
222 $body .= '<li>Page: ' . esc_html($iframes['link']) . ', link: ' . esc_attr($link) . '</li>';
223 }
224 }
225 }
226 $body .= '</ul>';
227 } else {
228 $subject = __('All your iframes look good.', 'advanced-iframe');
229 $body .= __('All your iframes look good.<br>Please go to the administration of advanced iframe pro to get more details.', 'advanced-iframe');
230 }
231 $body .= '</p><p>';
232 $body .= __('The test took ', 'advanced-iframe') . $total_time . __(' sec.', 'advanced-iframe');
233 $body .= '</p>';
234 $body .= __('Best regards,<br>Your advanced iframe plugin', 'advanced-iframe');
235 $body .= '</body></html>';
236 $headers = array('Content-Type: text/html; charset=UTF-8');
237 if ($options['check_iframe_cronjob_email_always'] === 'true' || $result['overall_status'] === 'red' || $result['overall_status'] === 'orange') {
238 wp_mail($to, $subject, $body, $headers);
239 }
240 }
241 }
242
243 /**
244 * Set the iframe default
245 */
246 function iframe_defaults() {
247 return array(
248 'securitykey' => '',
249 'src' => '//www.tinywebgallery.com/blog/advanced-iframe',
250 'width' => '100%',
251 'height' => '600',
252 'scrolling' => 'none',
253 'marginwidth' => '0',
254 'marginheight' => '0',
255 'frameborder' => '0',
256 'transparency' => 'true',
257 'loading' => 'lazy',
258 'content_id' => '',
259 'content_styles' => '',
260 'hide_elements' => '',
261 'class' => '',
262 'shortcode_attributes' => 'true',
263 'url_forward_parameter' => '',
264 'id' => 'advanced_iframe',
265 'name' => '',
266 'onload' => '',
267 'onload_resize' => 'false',
268 'onload_scroll_top' => 'false',
269 'additional_js' => '',
270 'additional_css' => '',
271 'store_height_in_cookie' => 'false',
272 'additional_height' => '0',
273 'iframe_content_id' => '',
274 'iframe_content_styles' => '',
275 'iframe_hide_elements' => '',
276 'version_counter' => '1',
277 'onload_show_element_only' => '',
278 'include_url' => '',
279 'include_content' => '',
280 'include_height' => '',
281 'include_fade' => '',
282 'include_hide_page_until_loaded' => 'false',
283 'donation_bottom' => 'false',
284 'onload_resize_width' => 'false',
285 'resize_on_ajax' => '',
286 'resize_on_ajax_jquery' => 'true',
287 'resize_on_click' => '',
288 'resize_on_click_elements' => 'a',
289 'hide_page_until_loaded' => 'false',
290 'show_part_of_iframe' => 'false',
291 'show_part_of_iframe_x' => '100',
292 'show_part_of_iframe_y' => '100',
293 'show_part_of_iframe_width' => '400',
294 'show_part_of_iframe_height' => '300',
295 'show_part_of_iframe_new_window' => '',
296 'show_part_of_iframe_new_url' => '',
297 'show_part_of_iframe_next_viewports_hide' => 'false',
298 'show_part_of_iframe_next_viewports' => '',
299 'show_part_of_iframe_next_viewports_loop' => 'false',
300 'style' => '',
301 'use_shortcode_attributes_only' => 'false',
302 'enable_external_height_workaround' => 'external',
303 'keep_overflow_hidden' => 'false',
304 'hide_page_until_loaded_external' => 'false',
305 'onload_resize_delay' => '',
306 'expert_mode' => 'false',
307 'show_part_of_iframe_allow_scrollbar_vertical' => 'false',
308 'show_part_of_iframe_allow_scrollbar_horizontal' => 'false',
309 'hide_part_of_iframe' => '',
310 'change_parent_links_target' => '',
311 'change_iframe_links' => '',
312 'change_iframe_links_target' => '',
313 'browser' => '',
314 'show_part_of_iframe_style' => '',
315 'map_parameter_to_url' => '',
316 'iframe_zoom' => '',
317 'accordeon_menu' => 'no',
318 'show_iframe_loader' => 'false',
319 'tab_visible' => '',
320 'tab_hidden' => '',
321 'enable_responsive_iframe' => 'false',
322 'allowfullscreen' => 'false',
323 'iframe_height_ratio' => '',
324 'enable_lazy_load' => 'false',
325 'enable_lazy_load_threshold' => '3000',
326 'enable_lazy_load_fadetime' => '0',
327 'enable_lazy_load_manual' => 'false',
328 'pass_id_by_url' => '',
329 'include_scripts_in_footer' => 'false',
330 'write_css_directly' => 'false',
331 'resize_on_element_resize' => '',
332 'resize_on_element_resize_delay' => '250',
333 'add_css_class_parent' => 'false',
334 'auto_zoom' => 'false',
335 'auto_zoom_by_ratio' => '',
336 'enable_lazy_load_manual_element' => '',
337 'alternative_shortcode' => '',
338 'iframe_redirect_url' => '',
339 'install_date' => 0,
340 'show_part_of_iframe_last_viewport_remove' => 'false',
341 'load_jquery' => 'true',
342 'show_iframe_as_layer' => 'false',
343 'add_iframe_url_as_param' => 'false',
344 'add_iframe_url_as_param_direct' => 'false',
345 'add_iframe_url_as_param_prefix' => '',
346 'use_iframe_title_for_parent' => 'false',
347 'reload_interval' => '',
348 'iframe_content_css' => '',
349 'additional_js_file_iframe' => '',
350 'additional_css_file_iframe' => '',
351 'add_css_class_iframe' => 'false',
352 'editorbutton' => 'src,width,height',
353 'iframe_zoom_ie8' => 'false',
354 'enable_lazy_load_reserve_space' => 'true',
355 'hide_content_until_iframe_color' => '',
356 'use_zoom_absolute_fix' => 'false',
357 'include_html' => '',
358 'enable_ios_mobile_scolling' => 'false',
359 'sandbox' => '',
360 'show_iframe_as_layer_header_file' => '',
361 'show_iframe_as_layer_header_height' => '100',
362 'show_iframe_as_layer_header_position' => 'top',
363 'resize_min_height' => '1',
364 'show_iframe_as_layer_full' => 'false',
365 'demo' => 'false',
366 'show_part_of_iframe_zoom' => 'false',
367 'external_height_workaround_delay' => '0',
368 'add_document_domain' => 'false',
369 'document_domain' => '',
370 'multi_domain_enabled' => 'true',
371 'check_shortcode' => 'false',
372 'use_post_message' => 'true',
373 'element_to_measure_offset' => '0',
374 'data_post_message' => '',
375 'element_to_measure' => 'default',
376 'show_iframe_as_layer_keep_content' => 'true',
377 'roles' => 'none',
378 'parent_content_css' => '',
379 'include_scripts_in_content' => 'false',
380 'debug_js' => 'false',
381 'check_iframe_cronjob' => 'false',
382 'check_iframe_cronjob_email' => '',
383 'enable_content_filter' => 'false',
384 'add_ai_external_local' => 'false',
385 'title' => '',
386 'check_iframes_when_save' => 'false',
387 'admin_was_loaded' => 'true',
388 'check_iframe_url_when_load' => 'true',
389 'modify_iframe_if_cookie' => 'false',
390 'allow' => '',
391 'safari_fix_url' => '',
392 'external_scroll_top' => '',
393 'change_iframe_links_href' => '',
394 'delete_options_db' => 'false',
395 'inline_config_file' => 'none',
396 'replace_iframe_tags' => 'false',
397 'check_iframe_batch_size' => 100,
398 'check_iframe_cronjob_email_always' => 'true',
399 'remove_elements_from_height' => '',
400 'add_ai_to_all_pages' => 'false',
401 'show_part_of_iframe_media_query' => '',
402 'remove_page_param_from_query' => 'false',
403 'src_hide' => '',
404 'purchase_code' => '',
405 'cookie_samesite_filter' => '',
406 'show_iframe_as_layer_autoclick_delay' => '0',
407 'show_iframe_as_layer_autoclick_hide_time' => '0',
408 'fullscreen_button' => 'false',
409 'fullscreen_button_hide_elements' => '',
410 'fullscreen_button_full' => 'false',
411 'fullscreen_button_style' => 'black',
412 'optimize_rendering' => 'false',
413 'referrerpolicy' => '',
414 'add_surrounding_p' => 'false',
415 'custom' => '',
416 'enable_ai_content_pages' => 'false'
417 );
418 }
419
420 /**
421 * Get the admin options
422 */
423 function getAiAdminOptions() {
424 $iframeAdminOptions = advancediFrame::iframe_defaults();
425 $devOptions = get_option($this->adminOptionsName);
426 if (!empty($devOptions)) {
427 foreach ($devOptions as $key => $option) {
428 $iframeAdminOptions[$key] = $option;
429 }
430 } else {
431 // new installations do now get postMessage as default
432 if (file_exists(dirname(__FILE__) . "/includes/class-cw-envato-api.php")) {
433 $iframeAdminOptions['use_post_message'] = 'true';
434 update_option($this->adminOptionsName, $iframeAdminOptions);
435 }
436 }
437 // read the external config file if present.
438 if (file_exists(dirname(__FILE__) . "/external_config.php")) {
439 include dirname(__FILE__) . '/external_config.php';
440 @unlink(dirname(__FILE__) . '/external_config.php');
441 update_option($this->adminOptionsName, $iframeAdminOptions);
442 }
443 return $iframeAdminOptions;
444 }
445
446 function aiAddHeader() {
447 $devOptions = $this->getAiAdminOptions();
448
449 // IE fix for cookies.
450 header('P3P: CP="ALL DSP NID CURa ADMa DEVa HISa OTPa OUR NOR NAV DEM"');
451
452 AdvancedIframeHelper::check_debug_get_parameter();
453 AdvancedIframeCookie::addCookieSameSite($devOptions['cookie_samesite_filter']);
454 }
455
456 /**
457 * Redirect to the real src. aiUrl has the hash where the real url is stored temp in the db.
458 */
459 function aiCheckRedirect() {
460 if (isset($_GET['aiUrl'])) {
461 $url = urlencode($_GET['aiUrl']);
462 $transient = "aip_" . $url;
463 if (false !== $redirectFull = get_transient($transient)) {
464 $redirectArray = explode('|', $redirectFull);
465 $redirect = $redirectArray[0];
466 if ($redirectArray[1] === '0') { // link can only be clicked once.
467 delete_transient("aip_" . $url);
468 }
469 wp_redirect($redirect, 307);
470 exit;
471 }
472 }
473 }
474
475 /**
476 * Initialize advance iframe
477 */
478 function initAi() {
479
480 load_plugin_textdomain('advanced-iframe', false, dirname(plugin_basename(__FILE__)) . '/languages');
481
482 $options = $this->getAiAdminOptions();
483 if ($options['load_jquery'] === 'true') {
484 wp_enqueue_script('jquery');
485 }
486
487 if (function_exists('register_block_type')) {
488 // Register our block editor script for Gutenberg.
489 wp_register_script(
490 'ai-block',
491 plugins_url('js/ai_block.js', __FILE__),
492 array('wp-blocks', 'wp-element', 'wp-components', 'wp-editor')
493 );
494
495 // Register our block, and explicitly define the attributes we accept.
496 register_block_type('ai/ai-block', array(
497 'attributes' => array(
498 'src' => array(
499 'type' => 'string',
500 ),
501 'width' => array(
502 'type' => 'string',
503 ),
504 'height' => array(
505 'type' => 'string',
506 ),
507 'add_surrounding_p_boolean' => array(
508 'type' => 'boolean',
509 ),
510 'additional' => array(
511 'type' => 'string',
512 ),
513 'className' => array(
514 'type' => 'string',
515 )
516 ),
517 'editor_script' => 'ai-block', // The script name we gave in the wp_register_script() call.
518 'render_callback' => 'render_ai_gutenberg',
519 ));
520 }
521 // end of Gutenberg
522
523 $add_iframe_url_as_param_prefix = $options['add_iframe_url_as_param_prefix'];
524 $map_parameter_to_url = $options['map_parameter_to_url'];
525
526 if (empty($map_parameter_to_url)) {
527 $map_parameter_to_url = 'iframe';
528 }
529
530 if ($options['enable_ai_content_pages'] !== 'false') {
531 register_post_type('ai_content_page', array(
532 'capabilities' => array(
533 'create_posts' => false,
534 ),
535 'labels' => array(
536 'name' => __('AI content pages', 'advanced-iframe'),
537 'singular_name' => __('AI content page', 'advanced-iframe'),
538 ),
539 'public' => true,
540 'hierarchical' => true,
541 'has_archive' => false,
542 'show_in_admin_bar' => false,
543 'menu_icon' => 'dashicons-admin-page',
544 'map_meta_cap' => true,
545 )
546 );
547 if ($options['enable_ai_content_pages'] === 'init') {
548 $options['enable_ai_content_pages'] = 'true';
549 update_option($this->adminOptionsName, $options);
550 flush_rewrite_rules();
551 }
552 }
553
554
555 if (AdvancedIframeHelper::ai_startsWith($add_iframe_url_as_param_prefix, 'hashrewrite')) {
556 $map_parameter_to_url_array = explode(":", $map_parameter_to_url);
557 $map_parameter_to_url = $map_parameter_to_url_array[0];
558 if (count($map_parameter_to_url_array) === 1) {
559 add_rewrite_rule(
560 '^(.*)/' . $map_parameter_to_url . '/([^/]*)/?',
561 'index.php?pagename=$matches[1]&' . $map_parameter_to_url . '=$matches[2]',
562 'top'
563 );
564 } else {
565 add_rewrite_rule(
566 '^(' . $map_parameter_to_url . ')/([^/]*)/?',
567 'index.php?pagename=$matches[1]&' . $map_parameter_to_url . '=$matches[2]',
568 'top'
569 );
570 }
571 flush_rewrite_rules();
572 }
573 }
574
575 /* CSS and js for the admin area - only loaded when needed */
576 function addAdminHeaderCode($hook) {
577 $options = $this->getAiAdminOptions();
578 // defaults
579 extract(array('version_counter' => $options['version_counter'],
580 'add_ai_external_local' => $options['add_ai_external_local']));
581 if ($add_ai_external_local === 'admin' || $add_ai_external_local === 'all') {
582 wp_enqueue_script('ai-external-js', plugins_url('js/ai_external.js', __FILE__), false, $version_counter);
583 }
584 wp_enqueue_script('ai-js', plugins_url('js/ai.min.js', __FILE__), false, $version_counter);
585 wp_localize_script('ai-js', 'MyAjax', array(
586 'ajaxurl' => admin_url('admin-ajax.php'),
587 'security' => wp_create_nonce('aip-close-message-nonce')
588 ));
589 if ($hook === 'settings_page_advanced-iframe' || $hook === 'toplevel_page_advanced-iframe') {
590 wp_enqueue_style('ai-css', plugins_url('css/ai.css', __FILE__), false, $version_counter);
591
592 wp_enqueue_script('ai-search', plugins_url('js/findAndReplaceDOMText.js', __FILE__), false, $version_counter);
593 wp_enqueue_script('postbox');
594 }
595
596 if ($hook === 'post.php' || $hook === 'post-new.php') {
597 if ($options['editorbutton'] != '' && $this->hasValidRole()) {
598 $additional_settings = '';
599 $elements = explode(',', $options['editorbutton']);
600 foreach ($elements as $setting) {
601 $setting = trim($setting);
602 if ($setting != 'securitykey') {
603 if (isset($options[$setting])) {
604 $new_setting = $options[$setting];
605 if (!empty($new_setting)) {
606 $additional_settings .= ' ' . esc_html($setting) . '="' . esc_html(trim($new_setting)) . '"';
607 }
608 }
609 }
610 }
611 $dep = ($options['load_jquery'] === 'true') ? array('jquery') : array();
612 wp_register_script('ai-editor-button', plugins_url('js/ai_editor_button.js', __FILE__), $dep, $options['version_counter'], 'true');
613 $ai_button_settings_array = array('securitykey' => $options['securitykey'], 'additionalSettings' => $additional_settings);
614 wp_localize_script('ai-editor-button', 'aiButtonSettings', $ai_button_settings_array);
615 wp_enqueue_script('ai-editor-button');
616 }
617 }
618 }
619
620 /* Add iframe button above the editor. */
621 function addAiButton($editor_id) {
622 $options = get_option($this->adminOptionsName);
623 if ($options['editorbutton'] != '' && $this->hasValidRole()) {
624 echo '<a title="Insert Advanced iFrame" class="button insert-iframe-button" href="#" data-editor="' .
625 esc_attr($editor_id) .
626 '"><img alt="" style="padding-bottom:3px;" src="' . AIP_IMGURL . '/logo_16x16.png" />Add Advanced iFrame</a>';
627 }
628 }
629
630 /* additional CSS for wp area */
631 function addWpHeaderCode($atts) {
632 $options = $this->getAiAdminOptions();
633 // defaults
634 extract(array('additional_css' => $options['additional_css'],
635 'additional_js' => $options['additional_js'],
636 'version_counter' => $options['version_counter'],
637 'enable_lazy_load' => $options['enable_lazy_load'],
638 'include_scripts_in_footer' => $options['include_scripts_in_footer'],
639 'add_css_class_parent' => $options['add_css_class_parent'],
640 'add_ai_external_local' => $options['add_ai_external_local'],
641 $atts));
642 $to_footer = ($include_scripts_in_footer === 'true' && $add_css_class_parent === 'false');
643
644 $older_version = version_compare(get_bloginfo('version'), '3.3') < 0; // wp < 3.3 - older version need to be included here
645 $this->include_additional_files($additional_css, $additional_js, $version_counter, $older_version, $to_footer);
646
647 $dep = ($options['load_jquery'] === 'true') ? array('jquery') : array();
648 wp_enqueue_script('ai-js', plugins_url('js/ai.min.js', __FILE__), $dep, $version_counter, $to_footer);
649 wp_localize_script('ai-js', 'MyAjax', array(
650 'ajaxurl' => admin_url('admin-ajax.php'),
651 'security' => wp_create_nonce('aip-parameter-nonce')
652 ));
653
654 if ($add_ai_external_local === 'true' || $add_ai_external_local === 'all') {
655 wp_enqueue_script('ai-external-js', plugins_url('js/ai_external.js', __FILE__), $dep, $version_counter, $to_footer);
656 }
657 }
658
659
660 function addAiExternalLocal() {
661 $options = get_option($this->adminOptionsName);
662 $dep = ($options['load_jquery'] === 'true') ? array('jquery') : array();
663 // we add this independent of the main settings to make the feature more save.
664 wp_register_script('ai-external-js', plugins_url('js/ai_external.js', __FILE__), $dep, $options['version_counter'], 'true');
665 $ai_external_settings_array = array('domainMultisite' => 'true', 'usePostMessage' => true);
666 wp_localize_script('ai-external-js', 'aiExternalSettings', $ai_external_settings_array);
667 wp_enqueue_script('ai-external-js');
668 }
669
670 function addCustomCss($parent_content_css) {
671 if (!empty($parent_content_css)) {
672 return wp_kses($parent_content_css, array());
673 }
674 return '';
675 }
676
677 /**
678 * Checks the parameter and returns the value. If only chars on the whitelist are in the request nothing is done
679 * Otherwise it is returned encoded.
680 */
681 function param($param, $content = null) {
682 // get and post parameters are checked. if both are set the get parameter is used.
683 $value = isset($_GET[$param]) ? $_GET[$param] : (isset($_POST[$param]) ? $_POST[$param] : '');
684
685 if (is_array($value)) {
686 $value = $value[0];
687 }
688 $value_check = $value;
689 // first we decode the param to be sure the it is not already encoded or doubleencoded as part of an attack
690 while ($value_check != @urldecode($value_check)) {
691 $value_check = @urldecode($value_check);
692 }
693 // If all chars are in the whitelist no additional encoding is done!
694 if (@preg_match('/^[.@~a-zA-Z0-9À-ÖØ-öø-ÿ\-|)(]*$/', $value_check)) {
695 return $value;
696 } else {
697 return @urlencode($value);
698 }
699 }
700
701 function addPx($value) {
702 if (strpos($value, '-') === false && strpos($value, '+') === false) {
703 $value = trim($value);
704 if (strpos($value, 'px') === false &&
705 strpos($value, '%') === false && strpos($value, '%') === false &&
706 strpos($value, 'vw') === false && strpos(strtolower($value), 'vh') === false
707 ) {
708 $value = $value . 'px';
709 }
710 }
711 return $value;
712 }
713
714 /**
715 * Formats the cacl string that it works even when entered slightly wrong
716 */
717 function formatCalcString($value) {
718 $value = preg_replace('/\s+/', '', $value);
719 $value = str_replace("-", " - ", $value);
720 $value = str_replace("+", " + ", $value);
721 $elements_px = array_map(array($this, 'addPx'), explode(' ', $value));
722 return implode(' ', $elements_px);
723 }
724
725 /**
726 * renders the iframe script
727 */
728 function do_iframe_script($atts, $content = null) {
729 global $isFreemiusMigration, $aiSlug;
730 $start = microtime(true);
731 // Avoids that iframes are called before the body!
732 if ($this->renderIframe === false) {
733 if (isset($_COOKIE['aiEnableDebugConsole'])) {
734 echo "<!-- advanced iframe not rendered -->";
735 }
736 return '';
737 }
738
739 global $aip_standalone, $iframeStandaloneDefaultOptions, $iframeStandaloneOptions, $isFreemius;
740 if (!is_array($atts)) {
741 $atts = array();
742 }
743
744 $isValidBrowser = true;
745 $html = ''; // the output
746 $error_html = ''; // any error
747 include dirname(__FILE__) . '/includes/advanced-iframe-main-read-config.php';
748
749 if ($error_html) {
750 return $error_html;
751 }
752 if (!$isValidBrowser) {
753 return '';
754 }
755
756 $error_html = include dirname(__FILE__) . '/includes/advanced-iframe-main-css.php';
757 if ($error_html) {
758 return $error_html;
759 }
760
761 // check if the ai_external.js does exist
762 $script_name = dirname(__FILE__) . '/js/ai_external.js';
763 if (!isset($aip_standalone) && !file_exists($script_name)) {
764 $retValue = $this->saveExternalJsFile(false);
765 if (!empty($retValue)) {
766 return $error_css . '<div class="errordiv">' . $retValue . '</div>';
767 }
768 }
769
770 if ($options['securitykey'] != '' && $options['securitykey'] != $securitykey && empty($alternative_shortcode)) {
771 return $error_css . '<div class="errordiv">' . __('No valid security key found. Please use at least the following shortcode:<br>&#91;advanced_iframe securitykey="&lt;your security key - see settings&gt;"&#93;<br /> Please also check in the html mode that your shortcode does only contain normal spaces and not a &amp;nbsp; instead. It is also possible that you use wrong quotes like &#8220; or &#8221;. Only &#34; is valid!', 'advanced-iframe') . '</div>';
772 } elseif ($src === "not set" && empty($include_url) && empty($include_html)) {
773 return $error_css . '<div class="errordiv">' . __('You have set "Use shortcode attributes only" (use_shortcode_attributes_only) to "true" which means that you have to specify all parameters as shortcode attributes. Please specify at least "securitykey" and "src". Examples are available in the administration.', 'advanced-iframe') . '</div>';
774 } else {
775 if (empty($include_url) && empty($include_html)) {
776 $error_html = include dirname(__FILE__) . '/includes/advanced-iframe-main-prepare.php';
777 if ($error_html) {
778 return $error_html;
779 }
780 $error_html = include dirname(__FILE__) . '/includes/advanced-iframe-main-iframe.php';
781 if ($error_html) {
782 return $error_html;
783 }
784 include dirname(__FILE__) . '/includes/advanced-iframe-main-after-iframe.php';
785 } else {
786 include dirname(__FILE__) . '/includes/advanced-iframe-main-include-directly.php';
787 }
788 if ($debug_js === 'bottom') {
789 $time_elapsed_secs = sprintf('%.6f', (microtime(true) - $start));
790 $html .= "<!-- advanced iframe rendered in " . $time_elapsed_secs . " s -->";
791 }
792 return $html;
793 }
794 }
795
796 /**
797 * Enqueue the additional js or css
798 */
799 function include_additional_files($additional_css, $additional_js, $version_counter, $version, $to_footer) {
800 if ($additional_css != '' && $version) { // wp >= 3.3
801 wp_enqueue_style('additional-advanced-iframe-css', $additional_css, false, $version_counter);
802 }
803 if ($additional_js != '' && $version) { // wp >= 3.3
804 wp_enqueue_script('additional-advanced-iframe-js', $additional_js, false, $version_counter, $to_footer);
805 }
806 }
807
808 function add_script_footer() {
809 $devOptions = $this->getAiAdminOptions();
810 if ($devOptions['add_ai_to_all_pages'] === 'true') {
811 $shortcode = '[advanced_iframe';
812 $securitykey = $devOptions['securitykey'];
813 if ($securitykey !== '') {
814 $shortcode .= ' securitykey="' . $securitykey . '"';
815 }
816 echo do_shortcode($shortcode . ']');
817 }
818
819 if (!$this->scriptsNeeded) {
820 if ($devOptions['enable_content_filter'] === 'true' && isset($_GET['ai-show-id-only'])) {
821 $ai_show_id_only = $_GET['ai-show-id-only'];
822
823 echo '<script type="text/javascript">var ai_show_id_only = "' . esc_js($ai_show_id_only) . '"</script>';
824 echo '<style>html, body { margin: 0 !important; padding: 0 !important; }</style>';
825 } else {
826 wp_dequeue_script('ai-js');
827 }
828 $add_ai_external_local = $devOptions['add_ai_external_local'];
829 // if ai_external.js is included locally we do not dequeue additional javascript!
830 // because we can place the code for the config switcher there easily.
831 if ($add_ai_external_local === 'false') {
832 wp_dequeue_script('additional-advanced-iframe-js');
833 }
834 wp_dequeue_script('ai-change-js');
835 wp_dequeue_script('ai-lazy-js');
836 } else {
837 // for this single line no external script file is used!
838 echo '<script type="text/javascript">if(window.aiModifyParent) {aiModifyParent();}</script>';
839 }
840 }
841
842 function printAdminPage() {
843 $this->ai_createCustomFolder();
844 require_once('advanced-iframe-admin-page.php');
845 }
846
847 function saveExternalJsFile($backend = true) {
848 global $aiVersion, $ai_fs, $aiSlug;
849 $devOptions = $this->getAiAdminOptions();
850 $template_name = dirname(__FILE__) . ($ai_fs->can_use_premium_code__premium_only() ?
851 '/includes/scripts/jquery.validation.js' : '/js/ai_external.template.js');
852
853 $jquery_path = site_url() . '/wp-includes/js/jquery/jquery.js';
854 $jquery_path = preg_replace("(^https?:)", "", $jquery_path);
855 $plugins_url = preg_replace("(^https?:)", "", plugins_url());
856
857 $content = file_get_contents($template_name);
858 $newContent = str_replace('PLUGIN_URL', $plugins_url . '/' . $aiSlug, $content);
859 $newContent = str_replace('PARAM_ID', $devOptions['id'], $newContent);
860 $newContent = str_replace('PARAM_IFRAME_HIDE_ELEMENTS', $devOptions['iframe_hide_elements'], $newContent);
861 $newContent = str_replace('PARAM_ONLOAD_SHOW_ELEMENT_ONLY', $devOptions['onload_show_element_only'], $newContent);
862 $newContent = str_replace('PARAM_IFRAME_CONTENT_ID', $devOptions['iframe_content_id'], $newContent);
863 $newContent = str_replace('PARAM_IFRAME_CONTENT_STYLES', $devOptions['iframe_content_styles'], $newContent);
864 $newContent = str_replace('PARAM_CHANGE_IFRAME_LINKS_TARGET', $devOptions['change_iframe_links_target'], $newContent);
865 $newContent = str_replace('PARAM_CHANGE_IFRAME_LINKS_HREF', $devOptions['change_iframe_links_href'], $newContent);
866 $newContent = str_replace('PARAM_CHANGE_IFRAME_LINKS', AdvancedIframeHelper::replace_brackets($devOptions['change_iframe_links']), $newContent);
867
868 $delay = empty($devOptions['external_height_workaround_delay']) ? '0' : $devOptions['external_height_workaround_delay'];
869 $newContent = str_replace('PARAM_ENABLE_EXTERNAL_HEIGHT_WORKAROUND_DELAY', $delay, $newContent);
870
871 // external and true = true, false = false
872 $isExternal = ($devOptions['enable_external_height_workaround'] === 'false') ? 'false' : 'true';
873 $newContent = str_replace('PARAM_ENABLE_EXTERNAL_HEIGHT_WORKAROUND', $isExternal, $newContent);
874 $newContent = str_replace('PARAM_KEEP_OVERFLOW_HIDDEN', $devOptions['keep_overflow_hidden'], $newContent);
875 $newContent = str_replace('PARAM_HIDE_PAGE_UNTIL_LOADED_EXTERNAL', $devOptions['hide_page_until_loaded_external'], $newContent);
876 $newContent = str_replace('PARAM_IFRAME_REDIRECT_URL', $devOptions['iframe_redirect_url'], $newContent);
877 $newContent = str_replace('PARAM_ENABLE_RESPONSIVE_IFRAME', $devOptions['enable_responsive_iframe'], $newContent);
878 $newContent = str_replace('PARAM_WRITE_CSS_DIRECTLY', $devOptions['write_css_directly'], $newContent);
879 $newContent = str_replace('PARAM_RESIZE_ON_ELEMENT_RESIZE_DELAY', $devOptions['resize_on_element_resize_delay'], $newContent);
880 $newContent = str_replace('PARAM_RESIZE_ON_ELEMENT_RESIZE', $devOptions['resize_on_element_resize'], $newContent);
881 $newContent = str_replace('PARAM_URL_ID', $devOptions['pass_id_by_url'], $newContent);
882
883 $newContent = str_replace('PARAM_JQUERY_PATH', $jquery_path, $newContent);
884 $newContent = str_replace('PARAM_ADD_IFRAME_URL_AS_PARAM', $devOptions['add_iframe_url_as_param'], $newContent);
885 $newContent = str_replace('PARAM_USE_IFRAME_TITLE_FOR_PARENT', $devOptions['use_iframe_title_for_parent'], $newContent);
886 $newContent = str_replace('PARAM_ADDITIONAL_CSS_FILE_IFRAME', $devOptions['additional_css_file_iframe'], $newContent);
887 $newContent = str_replace('PARAM_ADDITIONAL_JS_FILE_IFRAME', $devOptions['additional_js_file_iframe'], $newContent);
888 $newContent = str_replace('PARAM_ADD_CSS_CLASS_IFRAME', $devOptions['add_css_class_iframe'], $newContent);
889 $newContent = str_replace('PARAM_TIMESTAMP', date("Y-m-d H:i:s"), $newContent);
890
891 $newContent = str_replace('MULTI_DOMAIN_ENABLED', $devOptions['multi_domain_enabled'], $newContent);
892 $newContent = str_replace('USE_POST_MESSAGE', ($devOptions['use_post_message'] != 'false') ? 'true' : 'false', $newContent);
893 $newContent = str_replace('DEBUG_POST_MESSAGE', ($devOptions['use_post_message'] === 'debug') ? 'true' : 'false', $newContent);
894 $newContent = str_replace('DATA_POST_MESSAGE', $devOptions['data_post_message'], $newContent);
895
896 $newContent = str_replace('PARAM_SEND_CONSOLE_LOG', ($devOptions['debug_js'] === 'bottom') ? 'true' : 'false', $newContent);
897
898 $asParts = parse_url(site_url()); // PHP function
899 $home_url = (AdvancedIframeHelper::isSecure() ? 'https' : 'http') . '://' . $asParts['host'];
900 $post_domain = ($devOptions['multi_domain_enabled'] === 'true') ? '*' : $home_url;
901 $newContent = str_replace('POST_MESSAGE_DOMAIN', $post_domain, $newContent);
902
903 $newContent = str_replace('PARAM_ELEMENT_TO_MEASURE_OFFSET', $devOptions['element_to_measure_offset'], $newContent);
904 $newContent = str_replace('PARAM_MODIFY_IFRAME_IF_COOKIE', $devOptions['modify_iframe_if_cookie'], $newContent);
905 $newContent = str_replace('PARAM_ELEMENT_TO_MEASURE', $devOptions['element_to_measure'], $newContent);
906 $newContent = str_replace('PARAM_SCROLL_TO_TOP', $devOptions['external_scroll_top'], $newContent);
907 $newContent = str_replace('PARAM_SRC_HIDE', $devOptions['src_hide'], $newContent);
908 $newContent = str_replace('PARAM_VERSION', $aiVersion, $newContent);
909
910 // include a inline JS
911 $inlineConfigFile = $devOptions['inline_config_file'];
912 $inlineConfigContent = '';
913 if ($inlineConfigFile !== 'none') {
914 // do it
915 $fileName = dirname(__FILE__) . '/../advanced-iframe-custom/' . $inlineConfigFile;
916 if (file_exists($fileName)) {
917 $inlineConfigContent = trim(file_get_contents($fileName));
918 }
919 }
920
921 $newContent = str_replace('/* PARAM_INLINE_CONFIG_FILE */', $inlineConfigContent, $newContent);
922
923 clearstatcache();
924
925 $script_name = 'ai_external.js';
926 $returnValue = $this->handleWorkaroundFile($script_name, $newContent, $backend);
927
928 if ($returnValue !== '') {
929 return $returnValue;
930 }
931
932 $this->createMinimizedAiJs($backend);
933 return $this->createMinimizedAiExternalJs($newContent, $backend);
934 }
935
936 function createMinimizedAiExternalJs($newContent, $backend) {
937 global $aiVersion;
938 $url = 'https://www.toptal.com/developers/javascript-minifier/api/raw';
939
940 $postdata = array('http' => array(
941 'method' => 'POST',
942 'header' => 'Content-type: application/x-www-form-urlencoded',
943 'content' => http_build_query(array('input' => $newContent)),
944 'timeout' => 10));
945
946 $minifiedContent = @file_get_contents($url, false, stream_context_create($postdata));
947
948 if ($minifiedContent === false) {
949 $minifiedContent = $newContent;
950 } else {
951 // double check if it is somehow the expected content.
952 if ($this->aiContains($minifiedContent, 'var extendedDebug') && $this->aiContains($minifiedContent, 'ddOnloadEvent(aiExecuteWorkaround')) {
953 $type = $this->aiContains($newContent, 'Advanced iframe pro') ? 'pro' : 'free';
954 $minifiedContent = '/** Advanced iframe ' . $type . ' external workaround file ' . $aiVersion . '. Created: ' . date("Y-m-d H:i:s") . " */\n" . $minifiedContent;
955 } else {
956 $minifiedContent = $newContent;
957 }
958 }
959
960 $script_name = 'ai_external.min.js';
961 return $this->handleWorkaroundFile($script_name, $minifiedContent, $backend);
962 }
963
964 function createMinimizedAiJs($backend) {
965 global $aiVersion;
966 $aiJsSize = 87303;
967 $newContent = file_get_contents(dirname(__FILE__) . '/js/ai.js');
968 $oldFileName = dirname(__FILE__) . '/js/ai.min.js';
969 if ((strlen($newContent) == $aiJsSize) && file_exists($oldFileName)) {
970 return null;
971 }
972 $url = 'https://www.toptal.com/developers/javascript-minifier/api/raw';
973
974 $postdata = array('http' => array(
975 'method' => 'POST',
976 'header' => 'Content-type: application/x-www-form-urlencoded',
977 'content' => http_build_query(array('input' => $newContent)),
978 'timeout' => 10));
979 $minifiedContent = @file_get_contents($url, false, stream_context_create($postdata));
980
981 if ($minifiedContent === false) {
982 $minifiedContent = $newContent;
983 } else {
984 // double check if it is somehow the expected content.
985 if ($this->aiContains($minifiedContent, 'aiExtraSpace') && $this->aiContains($minifiedContent, 'aiOpenIframeOnClick')) {
986 $minifiedContent = '/** Advanced iframe functions v' . $aiVersion . '. Created: ' . date("Y-m-d H:i:s") . " */\n" . $minifiedContent;
987 } else {
988 $minifiedContent = $newContent;
989 }
990 }
991
992 $script_name = 'ai.min.js';
993 return $this->handleWorkaroundFile($script_name, $minifiedContent, $backend);
994 }
995
996 function handleWorkaroundFile($name, $newContent, $backend) {
997 $script_name = dirname(__FILE__) . '/js/' . $name;
998
999 if (@file_exists($script_name)) {
1000 if (!@unlink($script_name)) {
1001 if ($backend) {
1002 $errorText = __('The file "advanced-iframe/js/' . $name . '" can not be removed before saving. Please check the permissions of the js folder and the ' . $name . ' and save the settings again.', "advanced-iframe");
1003 AdvancedIframeHelper::aiPrintError($errorText);
1004 }
1005 return '';
1006 }
1007 }
1008 $fh = @fopen($script_name, 'w');
1009 if ($fh) {
1010 @fwrite($fh, $newContent);
1011 @fclose($fh);
1012 } else {
1013 $errorText = __('The file "advanced-iframe/js/' . $name . '" can not be saved. Please check the permissions of the js folder and save the settings again.', "advanced-iframe");
1014 if ($backend) {
1015 AdvancedIframeHelper::aiPrintError($errorText);
1016 } else {
1017 return $errorText;
1018 }
1019 }
1020 return '';
1021 }
1022
1023 function ai_startsWith($haystack, $needle) {
1024 return $needle === "" || strrpos($haystack, $needle, -strlen($haystack)) !== false;
1025 }
1026
1027 function ai_endsWith($haystack, $needle) {
1028 return $needle === "" || (($temp = strlen($haystack) - strlen($needle)) >= 0 && strpos($haystack, $needle, $temp) !== false);
1029 }
1030
1031 function aiContains($str, $substr) {
1032 return strpos($str, $substr) !== false;
1033 }
1034
1035 function aiContainsParam($str, $substr) {
1036 $substr .= '=';
1037 return strpos($str, '?' . $substr) !== false || strpos($str, '&amp;' . $substr) !== false;
1038 }
1039
1040 /**
1041 * remove query string and trailing backslash
1042 */
1043 function aiRemoveQueryString($str) {
1044 if ($this->aiContains($str, '?')) {
1045 $value = strstr($str, '?', true);
1046 return rtrim($value, '/');
1047 } else {
1048 return $str;
1049 }
1050 }
1051
1052 function ai_createCustomFolder() {
1053 $filenamedir = dirname(__FILE__) . '/../advanced-iframe-custom';
1054 if (!@file_exists($filenamedir)) {
1055 if (!@mkdir($filenamedir)) {
1056 echo 'The directory "advanced-iframe-custom" could not be created parallel to the advanced iframe plugin folder. Custom files are stored in this directory because Wordpress does delete the normal plugin folder during an update. Please create the folder manually.';
1057 return;
1058 }
1059 }
1060 $customPluginName = 'advanced-iframe-custom.php';
1061 if (!file_exists($filenamedir . '/' . $customPluginName)) {
1062 $src = dirname(__FILE__) . '/custom/custom.txt';
1063 @copy($src, $filenamedir . '/' . $customPluginName);
1064 }
1065 if (!file_exists($filenamedir . '/readme.txt')) {
1066 $src = dirname(__FILE__) . '/custom/readme.txt';
1067 @copy($src, $filenamedir . '/readme.txt');
1068 }
1069 if (!file_exists($filenamedir . '/hide_fullscreen.html')) {
1070 $src = dirname(__FILE__) . '/custom/hide_fullscreen.html';
1071 @copy($src, $filenamedir . '/hide_fullscreen.html');
1072 }
1073 }
1074
1075 function checkIE8() {
1076 $filenamedir = dirname(__FILE__) . '/../advanced-iframe-custom/browser-check-failed.txt';
1077 if (file_exists($filenamedir)) {
1078 return false;
1079 } else {
1080 $fh = @fopen($filenamedir, 'w');
1081 if ($fh) {
1082 @fwrite($fh, "Browser detection crashed. Please increase your php memory, delete this file and retry.");
1083 @fclose($fh);
1084 }
1085 @unlink($filenamedir);
1086 return ai_is_ie(8);
1087 }
1088 }
1089
1090 function ai_plugin_action_links($links, $file) {
1091 $plugin_file = basename(__FILE__);
1092 $file = basename($file);
1093 if ($file === $plugin_file) {
1094 $settings_link = '<a href="admin.php?page=advanced-iframe">' . __('Settings', 'advanced-iframe') . '</a>';
1095 array_unshift($links, $settings_link);
1096 }
1097 return $links;
1098 }
1099
1100 function ai_preview_post_link($link) {
1101 $sep = (strpos($link, '?') === false) ? '?' : "&";
1102 return $link . $sep . 'aiEnableCheckShortcode=true';
1103 }
1104
1105 function aiCheckContent($content) {
1106 // content contains [advanced AND role is not enough....
1107 if (!$this->hasValidRole() && strpos($content, '[advanced_iframe') !== false) {
1108 set_transient("ai_no_rights_post_errors", __('This page/post contains an advanced iframe shortcode but you don\'t have the needed role to use this plugin. Please contact your system administrator to get the needed role.', 'advanced-iframe'), 20);
1109 wp_redirect(admin_url());
1110 }
1111 return $content;
1112 }
1113
1114 function aiTemplateRedirect() {
1115 $options = $this->getAiAdminOptions();
1116 if (isset($options['optimize_rendering']) && $options['optimize_rendering'] === "true") {
1117 $this->renderIframe = false;
1118 }
1119 }
1120
1121 function aiWpHead() {
1122 $this->renderIframe = true;
1123 }
1124
1125 function aiHandleTempPages($content) {
1126 if (empty($content)) {
1127 return $content;
1128 } else {
1129 $devOptions = get_option($this->adminOptionsName);
1130 return AdvancedIframeHelper::handleTempPages($content, $devOptions, $this->adminOptionsName);
1131 }
1132 }
1133
1134 function aiDelecteAiContentPages() {
1135 AdvancedIframeHelper::aiDelecteAiContentPages();
1136 }
1137
1138 function aiReplaceIframes($content) {
1139 // This prevents that this method is called multiple times.
1140 static $aiReplaceIframes_called = false;
1141 if ($aiReplaceIframes_called || empty($content)) {
1142 return $content;
1143 }
1144 $aiReplaceIframes_called = true;
1145 $devOptions = get_option($this->adminOptionsName);
1146
1147 $content = AdvancedIframeHelper::handleTempPages($content, $devOptions, $this->adminOptionsName);
1148
1149 if ($devOptions['replace_iframe_tags'] !== 'true') {
1150 return $content;
1151 }
1152
1153 $dom = new DOMDocument;
1154 @$dom->loadHTML($content);
1155 $iframes = $dom->getElementsByTagName('iframe');
1156
1157 //Iterate over the extracted iframes and create advanced iframe shortcodes
1158 foreach ($iframes as $iframe) {
1159 $attributes = array('src', 'width', 'height', 'id', 'name', 'class', 'style');
1160 //Extract and show the "href" attribute.
1161 $shortcode = '[advanced_iframe';
1162 $securitykey = $devOptions['securitykey'];
1163 if ($securitykey !== '') {
1164 $shortcode .= ' securitykey="' . $securitykey . '"';
1165 }
1166
1167 foreach ($attributes as $attribute) {
1168 $value = $iframe->getAttribute($attribute);
1169 if ($value !== '') {
1170 $shortcode .= ' ' . $attribute . '="' . $value . '"';
1171 }
1172 }
1173 $shortcode .= ']';
1174 $content = preg_replace("/<iframe\s(.+?)>(.*?)<\/iframe>/is", $shortcode, $content);
1175 }
1176 return $content;
1177 }
1178
1179
1180 function aiShowValidationErrors() {
1181 global $aiVersion;
1182 global $isFreemius;
1183 global $isFreemiusMigration;
1184 global $ai_fs;
1185
1186 if ($error = get_transient("ai_no_rights_post_errors")) { ?>
1187 <div class="error">
1188 <p><?php echo $error ?></p>
1189 </div><?php
1190 delete_transient("ai_no_rights_post_errors");
1191 }
1192 if ($error = get_transient("ai_save_post_errors")) { ?>
1193 <div class="error">
1194 <p><?php echo $error; ?></p>
1195 </div><?php
1196 delete_transient("ai_save_post_errors");
1197 }
1198 if ($error = get_transient("ai_save_post_execution")) { ?>
1199 <div class="error">
1200 <p><?php echo $error; ?></p>
1201 </div><?php
1202 delete_transient("ai_save_post_execution");
1203 }
1204 if ($error = get_transient("ai_save_post_unfiltered_html")) { ?>
1205 <div class="error">
1206 <p><?php echo $error; ?></p>
1207 </div><?php
1208 delete_transient("ai_save_post_unfiltered_html");
1209 }
1210
1211 $this->ai_getlatestVersion();
1212 $devOptions = get_option($this->adminOptionsName);
1213
1214 $hasDiscount = get_transient('aip_discount') === "true";
1215 $showDiscountMessage = $hasDiscount && !(isset($devOptions['closed_messages']) && isset($devOptions['closed_messages']['show-discount-message']));
1216
1217 if ($showDiscountMessage) {
1218 echo '<script>jQuery(document).on( "click touchstart", "#show-discount-message.is-permanent-closable button", function() { closeInfoPermanent("show-discount-message"); });</script>';
1219 echo '<div id="show-discount-message" class="notice notice-success is-dismissible is-permanent-closable"><p><strong>';
1220 echo get_transient('aip_discount_message');
1221 echo '</strong></p></div>';
1222 }
1223
1224 $screen = get_current_screen();
1225 $viewsPercent = get_option('default_a_options') / 100;
1226
1227 if ((file_exists(dirname(__FILE__) . "/includes/class-cw-envato-api.php")) && empty($devOptions['purchase_code']) && !strstr($screen->id, $this->page) && !$isFreemius) {
1228 printf(
1229 '<div class="%s"><p>%s <a href="%s">%s</a>%s</p>',
1230 'notice notice-error',
1231 __('To unlock advanced iframe pro please add your personal purchase code in the ', 'advanced-iframe'),
1232 admin_url('admin.php?page=advanced-iframe'),
1233 __('Advanced iFrame administration', 'advanced-iframe'),
1234 __(' on the options tab. Otherwise you will still have the view limit of the free version where a notice is over all iframes.', 'advanced-iframe')
1235 );
1236 if ($viewsPercent > 100) {
1237 _e('<p><strong style="color: red"> The monthly view limit is reached. A small notice is shown over all iframes.</strong></p>', 'advanced-iframe');
1238 }
1239 echo '</div>';
1240 } else if ($viewsPercent > 100 && !$ai_fs->can_use_premium_code__premium_only() && !strstr($screen->id, $this->page)) {
1241
1242 $isRegistered = $isFreemiusMigration && $ai_fs->is_registered() && $ai_fs->is_tracking_allowed();
1243 if (!$isRegistered) {
1244 $text1 = __('<p><strong style="color: red">The monthly view limit of advanced iframe free is reached. A small notice is shown over all iframes.</strong></p>', 'advanced-iframe');
1245 $text2 = __('Please OPT-IN to get unlimited views. For more details go to the options tab of the ', 'advanced-iframe');
1246 printf(
1247 '<div class="%s">%s<p>%s <a href="%s">%s</a>.</p>',
1248 'notice notice-error',$text1,$text2, admin_url('admin.php?page=advanced-iframe'),
1249 __('Advanced iFrame administration', 'advanced-iframe')
1250 );
1251 echo '</div>';
1252 }
1253 }
1254 }
1255
1256 function ai_getlatestVersion() {
1257 global $aiVersion;
1258 global $isFreemius, $ai_fs;
1259
1260 $aip_version = get_transient('aip_version');
1261 if ($aip_version !== false) {
1262 return $aip_version;
1263 } else {
1264 $version_info = 0;
1265 $devOptions = get_option($this->adminOptionsName);
1266 $purchaseCode = (isset($devOptions['purchase_code']) && strlen($devOptions['purchase_code']) === 36) ? $devOptions['purchase_code'] : 'NOT_SET';
1267 $pro = $ai_fs->can_use_premium_code__premium_only() ? "1" : "2";
1268 $default_key = "put your unique phrase here";
1269 $auth_key = defined('AUTH_KEY') ? ((AUTH_KEY == $default_key) ? get_site_url() : substr(AUTH_KEY, -2)) : get_site_url();
1270 $urls = 'https://www.tinywebgallery.com/updatecheck/getAipVersion.php';
1271 $rand = substr(md5(microtime()), rand(0, 26), 2);
1272 $data = http_build_query(array('url' => get_site_url(), 'codehash' => $rand . base64_encode($purchaseCode), 'sitehash' => hash('sha256', $auth_key), 'type' => $pro, 'version' => $aiVersion, 'isFreemius' => $isFreemius ? 'true' : 'false'), '', '&');
1273 // use key 'http' even if you send the request to https://...
1274 $options = array(
1275 'ssl' => array(
1276 "verify_peer" => false,
1277 "verify_peer_name" => false
1278 ),
1279 'http' => array(
1280 'header' => "Content-type: application/x-www-form-urlencoded\r\n" .
1281 "User-Agent: Mozilla/5.0 (Windows 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36\r\n",
1282 'method' => 'POST',
1283 'content' => $data,
1284 'timeout' => 10
1285 )
1286 );
1287 $context = stream_context_create($options);
1288 $result = @file_get_contents($urls, false, $context);
1289 if ($result === false) { // Handle error
1290 $version_info = -1;
1291 }
1292
1293 if ($version_info === 0) {
1294 $version_info_array = json_decode(utf8_encode($result), true);
1295 $version_info = $version_info_array['version'];
1296 if ($version_info_array['discount'] === "true") {
1297 set_transient('aip_discount', 'true', 60 * 60 * 12);
1298 set_transient('aip_discount_message', $version_info_array['discountMessage'], 60 * 60 * 12);
1299 } else {
1300 if (isset($devOptions['closed_messages'])) {
1301 $closed_messages = $devOptions['closed_messages'];
1302 unset($closed_messages['show-discount-message']);
1303 $devOptions['closed_messages'] = $closed_messages;
1304 update_option($this->adminOptionsName, $devOptions);
1305 }
1306 }
1307
1308 if ($version_info_array['blocked'] === "true" && $devOptions['purchase_code'] !== '') {
1309 $devOptions['purchase_code'] = "";
1310 echo '<div class="error"><p><strong><p>';
1311 _e('Your advanced iframe pro purchase code was removed because of license issues. Please use your individual code from code canyon.', 'advanced-iframe');
1312 echo '</p></strong></p></div>';
1313 update_option($this->adminOptionsName, $devOptions);
1314 }
1315 if (!is_numeric(substr($version_info, 0, 1))) {
1316 $version_info = -1;
1317 }
1318 }
1319 }
1320 // we check every 12 hours
1321 set_transient('aip_version', $version_info, 60 * 60 * 12);
1322 return $version_info;
1323 }
1324
1325 function hasValidRole() {
1326 $options = get_option($this->adminOptionsName);
1327 $config_role = $options['roles'];
1328 if ($config_role === 'none' || $config_role === '') {
1329 return true;
1330 }
1331
1332 global $wp_roles;
1333 if (!isset($wp_roles)) {
1334 return true;
1335 }
1336 $roles_by_index = array_flip(array_keys($wp_roles->get_names()));
1337
1338 // get the user role
1339 $current_user = wp_get_current_user();
1340 $user_roles = $current_user->roles;
1341 $user_role = array_shift($user_roles);
1342
1343 $user_index = $roles_by_index[$user_role];
1344 $config_index = $roles_by_index[$config_role];
1345 return $user_index <= $config_index;
1346 }
1347
1348 function ai_show_id_only() {
1349 global $post;
1350 $options = $this->getAiAdminOptions();
1351
1352 if ($options['enable_content_filter'] === 'true' && isset($_GET['ai-show-id-only']) && isset($_GET['ai-server-side']) && is_singular()) {
1353 the_post();
1354
1355 echo '<html><head><meta name="robots" content="noindex,nofollow" />';
1356 wp_print_scripts();
1357 wp_head();
1358 wp_print_styles();
1359 if (function_exists('post_class')) {
1360 echo '</head><body ';
1361 post_class();
1362 echo '>';
1363 } else {
1364 echo '</head><body>';
1365 }
1366
1367 if (isset($_GET['plain'])) {
1368 $html = get_the_content();
1369 } else {
1370 $html = $this->my_the_content();
1371 }
1372
1373 $html = '<div>' . $html . '</div>';
1374
1375
1376 $dom = new DOMDocument();
1377 $dom->loadHTML($html);
1378 $xpath = new DOMXPath($dom);
1379 $xpath_resultset = $xpath->query('//div[@id="' . $_GET['ai-show-id-only'] . '"]');
1380
1381 if ($xpath_resultset->length > 0) {
1382 echo $dom->saveHTML($xpath_resultset->item(0));
1383 } else {
1384 echo "No content found for this id. Please check if your id is correct and the part you want to show is in the content area.";
1385 }
1386
1387 wp_footer();
1388
1389 $overflow = isset($_GET['ai-show-overflow']) ? '' : ' overflow: hidden;';
1390
1391 echo '<style>';
1392 echo 'html, body { margin: 0px !important; padding: 0px !important;' . $overflow . ' }';
1393 echo '</style>';
1394 echo '</body></html>';
1395 die();
1396 }
1397 }
1398
1399
1400 /**
1401 * Filters the post content.
1402 *
1403 * @param string $content Content of the current post.
1404 * @since 0.71
1405 *
1406 */
1407 function my_the_content($more_link_text = null, $strip_teaser = false) {
1408 $content = get_the_content($more_link_text, $strip_teaser);
1409 $content = apply_filters('the_content', $content);
1410 $content = str_replace(']]>', ']]&gt;', $content);
1411 return $content;
1412 }
1413
1414 // The function that handles the AJAX request
1415 function aip_map_url_callback() {
1416 check_ajax_referer('aip-parameter-nonce', 'security');
1417 $url = $_POST['url'];
1418 if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) {
1419 echo "URL_NOT_VALID";
1420 die();
1421 }
1422 // we use a default wp table as the data is normally quite small.
1423 $paramData = get_option("advancediFrameParameterData");
1424 if (!empty($paramData)) {
1425 if(count($paramData) > 1000) {
1426 echo "TOO_MANY_CACHE_ENTRIES";
1427 die();
1428 }
1429 $nextid = 1;
1430 foreach ($paramData as $entry) {
1431 if ($url === $entry->url) {
1432 echo $entry->base;
1433 die();
1434 } else {
1435 $nextid++;
1436 }
1437 }
1438 // not found
1439 $entry = $this->createEntry($nextid, $url);
1440 $paramData[$nextid] = $entry;
1441 $result = $entry->base;
1442 } else {
1443 $paramData = array();
1444 $entry = $this->createEntry(1, $url);
1445 $paramData[1] = $entry;
1446 $result = $entry->base;
1447 }
1448 update_option("advancediFrameParameterData", $paramData);
1449
1450 echo $result;
1451 die(); // this is required to return a proper result
1452 }
1453
1454 function aip_close_message_permanent() {
1455 check_ajax_referer('aip-close-message-nonce', 'security');
1456 $id = $_POST['id'];
1457 $options = get_option($this->adminOptionsName);
1458 if (!isset($options['closed_messages'])) {
1459 $closed_messages = array();
1460 } else {
1461 $closed_messages = $options['closed_messages'];
1462 }
1463 if ($id !== 'show-registration-message') {
1464 $closed_messages[$id] = 'true';
1465 $options['closed_messages'] = $closed_messages;
1466 update_option($this->adminOptionsName, $options);
1467 }
1468
1469 echo "OK";
1470 die(); // this is required to return a proper result
1471 }
1472
1473 function createEntry($id, $url) {
1474 $object = new stdClass();
1475 $object->id = $id;
1476
1477 $options = get_option($this->adminOptionsName);
1478 $add_iframe_url_as_param_prefix = $options['add_iframe_url_as_param_prefix'];
1479 $hashIdArray = explode(":", $add_iframe_url_as_param_prefix);
1480 if (count($hashIdArray) === 2) {
1481 $param = $hashIdArray[1];
1482 if (AdvancedIframeHelper::ai_startsWith($param, "fullpath")) {
1483 $decodedUrl = urldecode($url);
1484 $fullPath = trim(parse_url($decodedUrl, PHP_URL_PATH), "/");
1485 $fullQuery = parse_url($decodedUrl, PHP_URL_QUERY);
1486 $numToRemove = abs((int)filter_var($param, FILTER_SANITIZE_NUMBER_INT));
1487 $pathArray = explode('/', $fullPath);
1488 $output = array_slice($pathArray, $numToRemove);
1489 $value = implode('/', $output);
1490 if (!empty($fullQuery)) {
1491 $value = $value . "?" . $fullQuery;
1492 }
1493 } else {
1494 $value = AdvancedIframeHelper::aiExtractParam(@urldecode($url), $param);
1495 }
1496 $object->base = isset($value) ? $value : "";
1497 } else {
1498 $object->base = base_convert($id, 10, 32);
1499 }
1500 $object->url = $url;
1501 return $object;
1502 }
1503
1504 /**
1505 * Removes the page parameter from the $query object if it is not numeric
1506 * WP 5.5 does now a 301 redirect if the page param is not valid as it is used
1507 * internally for pagination.
1508 */
1509 function aiParseRequest($query) {
1510 $options = $this->getAiAdminOptions();
1511 $remove_page_param_from_query = $options['remove_page_param_from_query'];
1512 if ($remove_page_param_from_query === 'true') {
1513 if (isset($_GET['page']) && isset($query->query_vars['page'])) {
1514 if (!is_numeric($query->query_vars['page'])) {
1515 unset($query->query_vars['page']);
1516 }
1517 }
1518 }
1519 return $query;
1520 }
1521
1522 function ai_save_post($content) {
1523 $options = get_option($this->adminOptionsName);
1524 $check_save = $options['check_iframes_when_save'];
1525
1526
1527 $tags = array('advanced_iframe', 'advanced-iframe', 'iframe');
1528 $pattern = get_shortcode_regex($tags);
1529 if (preg_match_all('/' . $pattern . '/s', $content, $matches)) {
1530 $oldContent = $content;
1531 foreach ($matches[0] as $hit) {
1532 // check if the user has the capability unfiltered_html and is therefore allowed to use the custom and onload shortcode attribute.
1533 if (!current_user_can('unfiltered_html')) {
1534 $content = $this->filterAttribute('onload', $hit, $content);
1535 $content = $this->filterAttribute('custom', $hit, $content);
1536 $content = $this->filterAttribute('include_html', $hit, $content);
1537 $content = $this->filterAttribute('additional_js', $hit, $content);
1538 $content = $this->filterAttribute('additional_js_file_iframe', $hit, $content);
1539 $attsArray = shortcode_parse_atts($hit);
1540 $content = $this->filterXSSAttributes($attsArray, $content);
1541 }
1542 }
1543 if ($oldContent != $content) {
1544 $error_unfiltered = __('You are not allowed add unfiltered HTML. If you like to use the attributes "onload", "include_html", "additional_js", "additional_js_file_iframe" and "custom" in advanced iframe you need the unfiltered_html permission. By default, the unfiltered_html permission is only given to Super Admins, Administrators and Editors. On WordPress multi site networks, only Super Admins have the unfiltered_html permission.<br>All attributes which are used in the shortcode where filtered to avoid XSS attacks. Please check your filtered shortcode.', 'advanced-iframe');
1545 set_transient("ai_save_post_unfiltered_html", $error_unfiltered);
1546 }
1547 }
1548
1549 if ($check_save === 'false') {
1550 return $content;
1551 }
1552
1553 // disable the feature because if it fails is should not be executed again.
1554 $options['check_iframes_when_save'] = 'false';
1555 update_option($this->adminOptionsName, $options);
1556 $error_execution = __('The integrated check of iframes on save failed. "Check iframes on save" is now disabled. You can enable this again on the "Options" tab. Check the description of this options what maybe caused this problem.', 'advanced-iframe');
1557 set_transient("ai_save_post_execution", $error_execution, 0);
1558
1559 include_once dirname(__FILE__) . '/includes/advanced-iframe-admin-functions.php';
1560
1561 $result_array = array();
1562 $result_array['links'] = array();
1563 $result_array['overall_status'] = 'green';
1564 $all_links = array();
1565 $result_array = evaluatePageLinks($result_array, stripcslashes($content), 'link', 'title', $all_links, 'none');
1566 $error = '';
1567
1568 foreach ($result_array['links'] as $iframes) {
1569 foreach ($iframes['links'] as $link => $result) {
1570 $resultArray = ai_checkUrlStatus(array($link));
1571 $resultStatus = $resultArray[$link]['status'];
1572 $result['status'] = $resultStatus;
1573 if (isset($result['status'])) {
1574 if (($result['status'] === 'orange' && $check_save != 'error') || $result['status'] === 'red') {
1575 $error .= '<p>' . __('Please check this iframe url: ', 'advanced-iframe') . $result['url_orig'] . '</p>';
1576 }
1577 }
1578 }
1579 }
1580
1581 if (!empty($error)) {
1582 $error .= '<p>' . __('You can get more details about the problem on the basic tab where you can check all links. This check is not 100%. If the url is working, simply ignore it or disable the check on the options tab: "Check iframes on save".', 'advanced-iframe') . '</p>';
1583 set_transient("ai_save_post_errors", $error, 20);
1584 }
1585
1586 // Enabled the feature for the next save because it was working and the error was removed.
1587 $options['check_iframes_when_save'] = $check_save;
1588 update_option($this->adminOptionsName, $options);
1589 delete_transient("ai_save_post_execution");
1590
1591 return $content;
1592 }
1593
1594 function filterAttribute($attribute, $hit, $content) {
1595 if (AdvancedIframeHelper::aiContains($hit, $attribute)) {
1596 $content = str_replace($attribute, '', $content);
1597 }
1598 return $content;
1599 }
1600
1601 /**
1602 * Detects possible XSS attacks in the shortcode attributes.
1603 */
1604 function filterXSSAttributes($attsArray, $content) {
1605 $replaceArray = array("´", "`", "'", ' ', '(', ')', "\\x29", "\\x28");
1606 foreach ($attsArray as $element) {
1607 $checkedElement = str_replace($replaceArray, '', $element);
1608 if ($checkedElement != $element) {
1609 $content = str_replace(addslashes($element), addslashes($checkedElement), $content);
1610 }
1611 }
1612 return $content;
1613 }
1614
1615 /**
1616 * Intercepts the Ajax resize events in iframes.
1617 */
1618 function interceptAjaxResize($iframe_id, $resize_width, $timeout, $resize_on_ajax_jquery,
1619 $click_timeout, $resize_on_click_elements, $resize_min_height) {
1620 $debug = false;
1621 $val = '';
1622 if ($timeout != '' || $click_timeout != '') {
1623 $val .= 'function local_resize_' . $iframe_id . '(timeout) {
1624 if (timeout != 0) {
1625 setTimeout(function() { aiResizeIframe(ifrm_' . $iframe_id . ', "' . $resize_width . '","' . $resize_min_height . '")},timeout);
1626 } else {
1627 aiResizeIframe(ifrm_' . $iframe_id . ', "' . $resize_width . '","' . $resize_min_height . '");
1628 }
1629 }';
1630
1631 if ($resize_on_ajax_jquery === 'true' || $click_timeout != '') {
1632 $val .= 'function ai_jquery_ajax_resize_' . $iframe_id . '() {
1633 jQuery("#' . $iframe_id . '").bind("load",function(){
1634 doc = this.contentWindow.document;';
1635 if ($timeout != '' && $resize_on_ajax_jquery === 'true') {
1636 $val .= 'var instance = this.contentWindow.jQuery;';
1637 $val .= 'instance(doc).ajaxComplete(function(){';
1638 if ($debug) {
1639 $val .= 'alert("AJAX request completed.");';
1640 }
1641 $val .= 'local_resize_' . $iframe_id . '(' . $timeout . ');';
1642 $val .= '});';
1643 }
1644 if ($click_timeout != '' && $resize_on_click_elements != '') {
1645 $val .= 'doc.addEventListener("click", function(evt) { ';
1646 $val .= ' if (aiCheckIfValidTarget(evt,"' . $resize_on_click_elements . '")) {';
1647 if ($debug) {
1648 $val .= 'alert("Click event intercepted.");';
1649 }
1650 $val .= ' local_resize_' . $iframe_id . '(' . $click_timeout . ');';
1651 $val .= ' }';
1652 $val .= '}, true);';
1653 }
1654 $val .= '});
1655 }';
1656 $val .= 'ai_jquery_ajax_resize_' . $iframe_id . '();';
1657
1658 }
1659 if ($resize_on_ajax_jquery === 'false' && $timeout != '') {
1660 $val .= 'var send_' . $iframe_id . ' = ifrm_' . $iframe_id . '.contentWindow.XMLHttpRequest.prototype.send,
1661 onReadyStateChange_' . $iframe_id . ';
1662
1663 function sendReplacement_' . $iframe_id . '(data) {
1664 if(this.onreadystatechange) {
1665 this._onreadystatechange_' . $iframe_id . ' = this.onreadystatechange;
1666 }
1667 this.onreadystatechange = onReadyStateChangeReplacement_' . $iframe_id . ';
1668 return send_' . $iframe_id . '.apply(this, arguments);
1669 }
1670
1671 function onReadyStateChangeReplacement_' . $iframe_id . '() {
1672 if(this.readyState === 4 ) {
1673 var retValue;
1674 if (this._onreadystatechange_' . $iframe_id . ') {
1675 retValue = this._onreadystatechange_' . $iframe_id . '.apply(this, arguments);
1676 }';
1677 $val .= 'local_resize_' . $iframe_id . '(' . $timeout . ');';
1678 $val .= 'return retValue;
1679 }
1680 }';
1681 $val .= ' ifrm_' . $iframe_id . '.contentWindow.XMLHttpRequest.prototype.send = sendReplacement_' . $iframe_id . ';';
1682 }
1683 }
1684 return '<script type="text/javascript">' . $val . '</script>';
1685 }
1686 }
1687 }
1688
1689 if (!isset($aip_standalone)) {
1690 // setup new instance of plugin if not standalone
1691 if (class_exists("advancediFrame")) {
1692 $cons_advancediFrame = new advancediFrame();
1693 }
1694 }
1695 //Actions and Filters
1696 if (isset($cons_advancediFrame)) {
1697 //Initialize the admin panel
1698 if (!function_exists('advancediFrame_ap')) {
1699 function advancediFrame_ap() {
1700 global $cons_advancediFrame, $ai_fs;
1701 if (!isset($cons_advancediFrame)) {
1702 return;
1703 }
1704 $aiOptions = $cons_advancediFrame->getAiAdminOptions();
1705
1706 $pro = $ai_fs->can_use_premium_code__premium_only() ? " Pro" : "";
1707
1708 $cap = ai_map_role_to_capability($aiOptions['roles']);
1709 add_menu_page('Advanced iFrame' . $pro, 'Advanced iFrame' . $pro, $cap, 'advanced-iframe',
1710 array($cons_advancediFrame, 'printAdminPage'), AIP_IMGURL . '/logo_24x24.png', '80.001');
1711 if (!empty($aiOptions['alternative_shortcode'])) {
1712 // setup shortcode alternative style
1713 add_shortcode($aiOptions['alternative_shortcode'], array($cons_advancediFrame, 'do_iframe_script'));
1714 }
1715
1716 add_action('media_buttons', array($cons_advancediFrame, 'addAiButton'), 11);
1717 }
1718 }
1719 add_action('admin_menu', 'advancediFrame_ap', 11); //admin page
1720 add_action('init', array($cons_advancediFrame, 'initAi'), 1); // add languages
1721 add_action('admin_enqueue_scripts', array($cons_advancediFrame, 'addAdminHeaderCode'), 99); // load css
1722 add_action('wp_enqueue_scripts', array($cons_advancediFrame, 'addWpHeaderCode'), 98); // load js
1723 add_action('wp_footer', array($cons_advancediFrame, 'add_script_footer'), 2);
1724 add_action('admin_notices', array($cons_advancediFrame, 'aiShowValidationErrors'), 3);
1725
1726 add_action('ai_check_iframes_event', array($cons_advancediFrame, 'aiCheckIframes'));
1727 add_action('wp', array($cons_advancediFrame, 'ai_show_id_only'));
1728 add_action('send_headers', array($cons_advancediFrame, 'aiAddHeader'));
1729 add_action('plugins_loaded', array($cons_advancediFrame, 'aiCheckRedirect'), 1);
1730 add_action('parse_request', array($cons_advancediFrame, 'aiParseRequest'), 1);
1731 add_action('template_redirect', array($cons_advancediFrame, 'aiTemplateRedirect'), 1);
1732 add_action('wp_head', array($cons_advancediFrame, 'aiWpHead'), 9999);
1733 add_action('switch_theme', array($cons_advancediFrame, 'aiDelecteAiContentPages'), 1);
1734
1735
1736 add_shortcode('advanced_iframe', array($cons_advancediFrame, 'do_iframe_script')); // setup shortcode
1737 add_shortcode('advanced-iframe', array($cons_advancediFrame, 'do_iframe_script')); // setup shortcode alternative style
1738 add_shortcode('ai_advanced_js_local', array($cons_advancediFrame, 'addAiExternalLocal')); // setup shortcode for adding ai_external only
1739
1740 register_activation_hook(__FILE__, array($cons_advancediFrame, 'activate'));
1741 register_deactivation_hook(__FILE__, array($cons_advancediFrame, 'deactivate'));
1742 add_action('upgrader_process_complete', array($cons_advancediFrame, 'aiUpdate'), 99, 2);
1743
1744 add_filter('content_edit_pre', array($cons_advancediFrame, 'aiCheckContent'), 1);
1745 add_filter('the_content', array($cons_advancediFrame, 'aiReplaceIframes'), 1);
1746 add_filter('ai_handle_temp_pages', array($cons_advancediFrame, 'aiHandleTempPages'), 1);
1747 add_filter('widget_text', 'shortcode_unautop');
1748 add_filter('widget_text', 'do_shortcode');
1749 add_filter('plugin_action_links', array($cons_advancediFrame, 'ai_plugin_action_links'), 10, 2);
1750 add_filter('preview_post_link', array($cons_advancediFrame, 'ai_preview_post_link'), 10, 2);
1751
1752 // content_save_pre
1753 add_filter('content_save_pre', array($cons_advancediFrame, 'ai_save_post'), 11, 1);
1754
1755 if (is_admin()) {
1756 add_action('wp_ajax_aip_map_url_action', array($cons_advancediFrame, 'aip_map_url_callback'));
1757 add_action('wp_ajax_nopriv_aip_map_url_action', array($cons_advancediFrame, 'aip_map_url_callback'));
1758 add_action('wp_ajax_aip_close_message_permanent', array($cons_advancediFrame, 'aip_close_message_permanent'));
1759 add_action('wp_ajax_nopriv_aip_close_message_permanent', array($cons_advancediFrame, 'aip_close_message_permanent'));
1760 }
1761 }
1762
1763 // ==============================================
1764 // Setup for widget + remove update functionality
1765 // ==============================================
1766 function ai_remove_update($value) {
1767 if (isset($value) && is_object($value) && isset($value->response[plugin_basename(__FILE__)])) {
1768 unset($value->response[plugin_basename(__FILE__)]);
1769 }
1770 return $value;
1771 }
1772
1773 function ai_remove_auto_update($update, $item) {
1774 $plugins = array('advanced-iframe');
1775 if (isset($item->slug) && in_array($item->slug, $plugins)) {
1776 return false;
1777 }
1778 return $update;
1779 }
1780
1781 function advanced_iframe_widget_init() {
1782 register_widget('AdvancedIframe_Widget');
1783 }
1784
1785 if (!isset($aip_standalone) && file_exists(dirname(__FILE__) . "/includes/advanced-iframe-widget.php")) {
1786 require_once('includes/advanced-iframe-widget.php');
1787 add_action('widgets_init', 'advanced_iframe_widget_init');
1788 if (!$isFreemiusMigration) {
1789 add_filter('site_transient_update_plugins', 'ai_remove_update');
1790 add_filter('auto_update_plugin', 'ai_remove_auto_update', 10, 2);
1791 }
1792 }
1793
1794 // ==============================================
1795 // Get Plugin Version
1796 // ==============================================
1797 function advanced_iframe_plugin_version() {
1798 if (!function_exists('get_plugins')) {
1799 require_once(ABSPATH . 'wp-admin/includes/plugin.php');
1800 }
1801 $plugin_folder = get_plugins('/' . plugin_basename(dirname(__FILE__)));
1802 $plugin_file = basename((__FILE__));
1803 return $plugin_folder[$plugin_file]['Version'];
1804 }
1805
1806 // ==============================================
1807 // Add Links in Plugins Table
1808 // ==============================================
1809 function advanced_iframe_plugin_meta_free($links, $file) {
1810 global $isFreemiusMigration;
1811 if (strpos($file, '/advanced-iframe') !== false) {
1812 $iconstyle = ' style="-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;" ';
1813 $reviewlink = 'https://wordpress.org/support/view/plugin-reviews/advanced-iframe?rate=5#postform';
1814 if ($isFreemiusMigration) {
1815 $links = array_merge($links, array('<a href="' . $reviewlink . '"><span class="dashicons dashicons-star-filled" ' .
1816 $iconstyle . ' title="Give a 5 Star Review"></span></a>'));
1817 } else {
1818 $links = array_merge($links, array('<a target="_blank" href="https://1.envato.market/rNeNd">Advanced iFrame Pro</a>',
1819 '<a href="' . $reviewlink . '"><span class="dashicons dashicons-star-filled" ' . $iconstyle . ' title="Give a 5 Star Review"></span></a>'
1820 ));
1821 }
1822 }
1823 return $links;
1824 }
1825
1826 function advanced_iframe_plugin_meta_pro($links, $file) {
1827 global $isFreemiusMigration;
1828 if (strpos($file, '/advanced-iframe') !== false) {
1829 $links = array();
1830
1831 if ($isFreemiusMigration) {
1832 $aiLinks = array('Version ' . advanced_iframe_plugin_version(),
1833 'By <a href="https://www.tinywebgallery.com">Michael Dempfle</a>',
1834 '<a href="//www.tinywebgallery.com/blog/advanced-iframe/advanced-iframe-pro-demo">Demos</a>'
1835 );
1836 } else {
1837 $aiLinks = array('Version ' . advanced_iframe_plugin_version(),
1838 'By <a href="https://www.tinywebgallery.com">Michael Dempfle</a>',
1839 '<a target="_blank" href="https://1.envato.market/k2Q2x">Code canyon - Advanced iFrame Pro</a>',
1840 '<a href="//www.tinywebgallery.com/blog/advanced-iframe/advanced-iframe-pro-demo">Demos</a>'
1841 );
1842 }
1843 $links = array_merge($links, $aiLinks);
1844 }
1845 return $links;
1846 }
1847
1848 function render_ai_gutenberg($attributes) {
1849 global $cons_advancediFrame;
1850 global $isAiGutenberg;
1851 // remove the empty ones and extract the ones from the additional field.
1852 foreach ($attributes as $key => $value) {
1853 if (empty($value) || $key === 'className') {
1854 unset($attributes[$key]);
1855 }
1856 }
1857 // the u0022 is replaced by " - because of a unknown reason the gutenberg block editor replaces " with u0022
1858 $add_array = (isset($attributes['additional'])) ? shortcode_parse_atts(str_replace("u0022", '"', $attributes['additional'])) : array();
1859
1860 if (is_array($add_array)) {
1861 $new_attributes = array_merge($add_array, $attributes);
1862 } else {
1863 $new_attributes = $attributes;
1864 }
1865
1866 $new_attributes['add_surrounding_p'] = (isset($attributes['add_surrounding_p_boolean'])) ? 'true' : 'false';
1867
1868 unset($new_attributes['additional']);
1869 unset($new_attributes['add_surrounding_p_boolean']);
1870 $html = '';
1871 if (current_action() == "parse_request") {
1872 $html = '<style>';
1873 $html .= '.ai-iframe-select { border: 1px dotted transparent;} .ai-iframe-select:hover { border: 1px dotted #eeeeee; }';
1874 $html .= '.ai-iframe-select-text { padding-left: 5px; font-size: 14px; color: transparent; cursor:text; } .ai-iframe-select-text:hover { color: #000; background-color: #f8f8f8; }';
1875 $html .= '.errordiv { font-size: 15px; }';
1876 $html .= '</style>';
1877 $html .= '<div class="ai-iframe-select">';
1878 $html .= '<div class="ai-iframe-select-text">';
1879 $html .= 'Click here to edit the advanced iframe block.';
1880 $html .= '</div>';
1881 }
1882 $isAiGutenberg = true;
1883
1884 $new_attributes['enable_lazy_load'] = 'false';
1885 $new_attributes['hide_content_until_iframe_color'] = '';
1886
1887 $html .= $cons_advancediFrame->do_iframe_script($new_attributes, null);
1888 if (current_action() == "parse_request") {
1889 $html .= '</div>';
1890 }
1891 return $html;
1892 }
1893
1894 /**
1895 *
1896 *
1897 */
1898 function ai_map_role_to_capability($role) {
1899 $role_map = array('administrator' => 'manage_options', 'editor' => 'delete_others_pages',
1900 'author' => 'delete_published_posts', 'contributor' => 'delete_posts', 'subscriber' => 'read');
1901 return (isset ($role_map[$role])) ? $role_map[$role] : 'manage_options';
1902 }
1903
1904 if (!isset($aip_standalone)) {
1905 if (file_exists(dirname(__FILE__) . "/includes/advanced-iframe-widget.php")) {
1906 add_filter('plugin_row_meta', 'advanced_iframe_plugin_meta_pro', 10, 2);
1907 } else {
1908 add_filter('plugin_row_meta', 'advanced_iframe_plugin_meta_free', 10, 2);
1909 }
1910 }
1911
1912 /*
1913 * wp uninstall
1914 */
1915 function ai_uninstall() {
1916 $option_name = 'advancediFrameAdminOptions';
1917 $option_name2 = 'advancediFrameParameterData';
1918 $options = get_option($option_name);
1919
1920 if ('true' === $options['delete_options_db']) {
1921 delete_option($option_name);
1922 // for site options in Multisite
1923 delete_site_option($option_name);
1924 delete_option($option_name2);
1925 // for site options in Multisite
1926 delete_site_option($option_name2);
1927 }
1928 }
1929
1930 register_uninstall_hook(__FILE__, 'ai_uninstall');
1931 }
1932 ?>