| @@ -1,26 +1,43 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: iframe |
| 4 | 4 | Plugin URI: http://wordpress.org/plugins/iframe/ |
| 5 | -Description: [iframe src="http://www.youtube.com/embed/4qsGTXLnmKs" width="100%" height="500"] shortcode | |
| 6 | -Version: 4.2 | |
| 5 | +Description: [iframe src="http://www.youtube.com/embed/7_nAZQt9qu0" width="100%" height="500"] shortcode | |
| 6 | +Version: 6.0 | |
| 7 | 7 | Author: webvitaly |
| 8 | -Author URI: http://web-profile.com.ua/wordpress/plugins/ | |
| 8 | +Author URI: http://web-profile.net/wordpress/plugins/ | |
| 9 | 9 | License: GPLv3 |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | +if ( ! defined( 'ABSPATH' ) ) { // Avoid direct calls to this file and prevent full path disclosure | |
| 13 | + exit; | |
| 14 | +} | |
| 12 | 15 | |
| 13 | -function iframe_unqprfx_embed_shortcode( $atts ) { | |
| 16 | +define('IFRAME_PLUGIN_VERSION', '6.0'); | |
| 17 | + | |
| 18 | +// Load settings page functionality | |
| 19 | +require_once( plugin_dir_path( __FILE__ ) . 'iframe-settings.php' ); | |
| 20 | + | |
| 21 | + | |
| 22 | +function iframe_plugin_add_shortcode_cb( $atts ) { | |
| 23 | + // Get plugin settings | |
| 24 | + $settings = iframe_plugin_get_settings(); | |
| 25 | + | |
| 14 | 26 | $defaults = array( |
| 15 | - 'src' => 'http://www.youtube.com/embed/4qsGTXLnmKs', | |
| 27 | + //'src' => 'http://www.youtube.com/embed/7_nAZQt9qu0', | |
| 16 | 28 | 'width' => '100%', |
| 17 | 29 | 'height' => '500', |
| 18 | 30 | 'scrolling' => 'yes', |
| 19 | 31 | 'class' => 'iframe-class', |
| 20 | - 'frameborder' => '0' | |
| 32 | + 'frameborder' => '0', | |
| 33 | + 'loading' => $settings['loading'] // Global setting from settings array | |
| 21 | 34 | ); |
| 22 | 35 | |
| 36 | + if ( ! is_array( $atts ) ) { | |
| 37 | + $atts = array(); | |
| 38 | + } | |
| 39 | + | |
| 23 | 40 | foreach ( $defaults as $default => $value ) { // add defaults |
| 24 | 41 | if ( ! @array_key_exists( $default, $atts ) ) { // mute warning with "@" when no params at all |
| 25 | 42 | $atts[$default] = $value; |
| 26 | 43 | } |
| @@ -25,19 +42,35 @@ | ||
| 25 | 42 | $atts[$default] = $value; |
| 26 | 43 | } |
| 27 | 44 | } |
| 28 | 45 | |
| 29 | - $html = "\n".'<!-- iframe plugin v.4.2 wordpress.org/plugins/iframe/ -->'."\n"; | |
| 46 | + $html = "\n".'<!-- iframe plugin v.'.IFRAME_PLUGIN_VERSION.' wordpress.org/plugins/iframe/ -->'."\n"; | |
| 30 | 47 | $html .= '<iframe'; |
| 31 | 48 | foreach( $atts as $attr => $value ) { |
| 32 | - if ( strtolower($attr) != 'same_height_as' AND strtolower($attr) != 'onload' | |
| 33 | - AND strtolower($attr) != 'onpageshow' AND strtolower($attr) != 'onclick') { // remove some attributes | |
| 34 | - if ( $value != '' ) { // adding all attributes | |
| 35 | - $html .= ' ' . esc_attr( $attr ) . '="' . esc_attr( $value ) . '"'; | |
| 36 | - } else { // adding empty attributes | |
| 37 | - $html .= ' ' . esc_attr( $attr ); | |
| 38 | - } | |
| 49 | + if ( strtolower($attr) == 'src' ) { // sanitize url | |
| 50 | + $value = esc_url( $value ); | |
| 39 | 51 | } |
| 52 | + | |
| 53 | + // Remove 'srcdoc' attribute | |
| 54 | + if ( strtolower($attr) == 'srcdoc' ) { | |
| 55 | + continue; | |
| 56 | + } | |
| 57 | + | |
| 58 | + // Skip attributes starting with "on". Examples: onload, onmouseover, onfocus, onpageshow, onclick | |
| 59 | + if ( strpos( strtolower( $attr ), 'on' ) === 0 ) { | |
| 60 | + continue; | |
| 61 | + } | |
| 62 | + | |
| 63 | + // Skip loading attribute if set to 'none' (browser default) | |
| 64 | + if ( strtolower($attr) == 'loading' && strtolower($value) == 'none' ) { | |
| 65 | + continue; | |
| 66 | + } | |
| 67 | + | |
| 68 | + if ($value !== '') { // adding all attributes | |
| 69 | + $html .= ' ' . esc_attr($attr) . '="' . esc_attr($value) . '"'; | |
| 70 | + } else { // adding empty attributes | |
| 71 | + $html .= ' ' . esc_attr($attr); | |
| 72 | + } | |
| 40 | 73 | } |
| 41 | 74 | $html .= '></iframe>'."\n"; |
| 42 | 75 | |
| 43 | 76 | if ( isset( $atts["same_height_as"] ) ) { |
| @@ -54,19 +87,18 @@ | ||
| 54 | 87 | } |
| 55 | 88 | |
| 56 | 89 | return $html; |
| 57 | 90 | } |
| 58 | -add_shortcode( 'iframe', 'iframe_unqprfx_embed_shortcode' ); | |
| 91 | +add_shortcode( 'iframe', 'iframe_plugin_add_shortcode_cb' ); | |
| 59 | 92 | |
| 60 | 93 | |
| 61 | -function iframe_unqprfx_plugin_meta( $links, $file ) { // add links to plugin meta row | |
| 94 | +function iframe_plugin_row_meta_cb( $links, $file ) { | |
| 62 | 95 | if ( $file == plugin_basename( __FILE__ ) ) { |
| 63 | 96 | $row_meta = array( |
| 64 | - 'support' => '<a href="http://web-profile.com.ua/wordpress/plugins/iframe/" target="_blank"><span class="dashicons dashicons-editor-help"></span> ' . __( 'Iframe', 'iframe' ) . '</a>', | |
| 65 | - 'donate' => '<a href="http://web-profile.com.ua/donate/" target="_blank"><span class="dashicons dashicons-heart"></span> ' . __( 'Donate', 'iframe' ) . '</a>', | |
| 66 | - 'pro' => '<a href="http://codecanyon.net/item/advanced-iframe-pro/5344999?ref=webvitalii" target="_blank"><span class="dashicons dashicons-star-filled"></span> ' . __( 'Advanced iFrame Pro', 'iframe' ) . '</a>' | |
| 97 | + 'support' => '<a href="http://web-profile.net/wordpress/plugins/iframe/" target="_blank">' . __( 'Iframe', 'iframe' ) . '</a>', | |
| 98 | + 'donate' => '<a href="http://web-profile.net/donate/" target="_blank">' . __( 'Donate', 'iframe' ) . '</a>' | |
| 67 | 99 | ); |
| 68 | 100 | $links = array_merge( $links, $row_meta ); |
| 69 | 101 | } |
| 70 | 102 | return (array) $links; |
| 71 | 103 | } |
| 72 | -add_filter( 'plugin_row_meta', 'iframe_unqprfx_plugin_meta', 10, 2 ); | |
| 104 | +add_filter( 'plugin_row_meta', 'iframe_plugin_row_meta_cb', 10, 2 ); | |