| @@ -1,19 +1,25 @@ | ||
| 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: 5.2 | |
| 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', '5.2'); | |
| 17 | + | |
| 18 | + | |
| 19 | +function iframe_plugin_add_shortcode_cb( $atts ) { | |
| 14 | 20 | $defaults = array( |
| 15 | - 'src' => 'http://www.youtube.com/embed/4qsGTXLnmKs', | |
| 21 | + //'src' => 'http://www.youtube.com/embed/7_nAZQt9qu0', | |
| 16 | 22 | 'width' => '100%', |
| 17 | 23 | 'height' => '500', |
| 18 | 24 | 'scrolling' => 'yes', |
| 19 | 25 | 'class' => 'iframe-class', |
| @@ -19,8 +25,12 @@ | ||
| 19 | 25 | 'class' => 'iframe-class', |
| 20 | 26 | 'frameborder' => '0' |
| 21 | 27 | ); |
| 22 | 28 | |
| 29 | + if ( ! is_array( $atts ) ) { | |
| 30 | + $atts = array(); | |
| 31 | + } | |
| 32 | + | |
| 23 | 33 | foreach ( $defaults as $default => $value ) { // add defaults |
| 24 | 34 | if ( ! @array_key_exists( $default, $atts ) ) { // mute warning with "@" when no params at all |
| 25 | 35 | $atts[$default] = $value; |
| 26 | 36 | } |
| @@ -25,19 +35,30 @@ | ||
| 25 | 35 | $atts[$default] = $value; |
| 26 | 36 | } |
| 27 | 37 | } |
| 28 | 38 | |
| 29 | - $html = "\n".'<!-- iframe plugin v.4.2 wordpress.org/plugins/iframe/ -->'."\n"; | |
| 39 | + $html = "\n".'<!-- iframe plugin v.'.IFRAME_PLUGIN_VERSION.' wordpress.org/plugins/iframe/ -->'."\n"; | |
| 30 | 40 | $html .= '<iframe'; |
| 31 | 41 | 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 | - } | |
| 42 | + if ( strtolower($attr) == 'src' ) { // sanitize url | |
| 43 | + $value = esc_url( $value ); | |
| 39 | 44 | } |
| 45 | + | |
| 46 | + // Remove 'srcdoc' attribute | |
| 47 | + if ( strtolower($attr) == 'srcdoc' ) { | |
| 48 | + continue; | |
| 49 | + } | |
| 50 | + | |
| 51 | + // Skip attributes starting with "on". Examples: onload, onmouseover, onfocus, onpageshow, onclick | |
| 52 | + if ( strpos( strtolower( $attr ), 'on' ) === 0 ) { | |
| 53 | + continue; | |
| 54 | + } | |
| 55 | + | |
| 56 | + if ($value !== '') { // adding all attributes | |
| 57 | + $html .= ' ' . esc_attr($attr) . '="' . esc_attr($value) . '"'; | |
| 58 | + } else { // adding empty attributes | |
| 59 | + $html .= ' ' . esc_attr($attr); | |
| 60 | + } | |
| 40 | 61 | } |
| 41 | 62 | $html .= '></iframe>'."\n"; |
| 42 | 63 | |
| 43 | 64 | if ( isset( $atts["same_height_as"] ) ) { |
| @@ -54,19 +75,18 @@ | ||
| 54 | 75 | } |
| 55 | 76 | |
| 56 | 77 | return $html; |
| 57 | 78 | } |
| 58 | -add_shortcode( 'iframe', 'iframe_unqprfx_embed_shortcode' ); | |
| 79 | +add_shortcode( 'iframe', 'iframe_plugin_add_shortcode_cb' ); | |
| 59 | 80 | |
| 60 | 81 | |
| 61 | -function iframe_unqprfx_plugin_meta( $links, $file ) { // add links to plugin meta row | |
| 82 | +function iframe_plugin_row_meta_cb( $links, $file ) { | |
| 62 | 83 | if ( $file == plugin_basename( __FILE__ ) ) { |
| 63 | 84 | $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>' | |
| 85 | + 'support' => '<a href="http://web-profile.net/wordpress/plugins/iframe/" target="_blank">' . __( 'Iframe', 'iframe' ) . '</a>', | |
| 86 | + 'donate' => '<a href="http://web-profile.net/donate/" target="_blank">' . __( 'Donate', 'iframe' ) . '</a>' | |
| 67 | 87 | ); |
| 68 | 88 | $links = array_merge( $links, $row_meta ); |
| 69 | 89 | } |
| 70 | 90 | return (array) $links; |
| 71 | 91 | } |
| 72 | -add_filter( 'plugin_row_meta', 'iframe_unqprfx_plugin_meta', 10, 2 ); | |
| 92 | +add_filter( 'plugin_row_meta', 'iframe_plugin_row_meta_cb', 10, 2 ); | |