| @@ -1,26 +1,27 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /* |
| 3 | 3 | Plugin Name: iframe |
| 4 | -Plugin URI: http://wordpress.org/extend/plugins/iframe/ | |
| 5 | -Description: [iframe src="http://player.vimeo.com/video/819138" width="100%" height="480"] shortcode | |
| 6 | -Version: 2.4 | |
| 4 | +Plugin URI: http://wordpress.org/plugins/iframe/ | |
| 5 | +Description: [iframe src="http://www.youtube.com/embed/A3PDXmYoF5U" width="100%" height="480"] shortcode | |
| 6 | +Version: 2.8 | |
| 7 | 7 | Author: webvitaly |
| 8 | -Author URI: http://profiles.wordpress.org/webvitaly/ | |
| 9 | -License: GPLv2 or later | |
| 8 | +Author URI: http://web-profile.com.ua/wordpress/plugins/ | |
| 9 | +License: GPLv3 | |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | |
| 13 | -if ( !function_exists( 'iframe_embed_shortcode' ) ) : | |
| 13 | +if ( ! function_exists( 'iframe_unqprfx_embed_shortcode' ) ) : | |
| 14 | 14 | |
| 15 | - function iframe_enqueue_script() { | |
| 15 | + function iframe_unqprfx_enqueue_script() { | |
| 16 | 16 | wp_enqueue_script( 'jquery' ); |
| 17 | 17 | } |
| 18 | - add_action('wp_enqueue_scripts', 'iframe_enqueue_script'); | |
| 18 | + add_action( 'wp_enqueue_scripts', 'iframe_unqprfx_enqueue_script' ); | |
| 19 | 19 | |
| 20 | - function iframe_embed_shortcode($atts, $content = null) { | |
| 20 | + | |
| 21 | + function iframe_unqprfx_embed_shortcode( $atts, $content = null ) { | |
| 21 | 22 | $defaults = array( |
| 22 | - 'src' => 'http://player.vimeo.com/video/819138', | |
| 23 | + 'src' => 'http://www.youtube.com/embed/A3PDXmYoF5U', | |
| 23 | 24 | 'width' => '100%', |
| 24 | 25 | 'height' => '480', |
| 25 | 26 | 'scrolling' => 'no', |
| 26 | 27 | 'class' => 'iframe-class', |
| @@ -26,18 +27,29 @@ | ||
| 26 | 27 | 'class' => 'iframe-class', |
| 27 | 28 | 'frameborder' => '0' |
| 28 | 29 | ); |
| 29 | 30 | |
| 30 | - foreach ($defaults as $default => $value) { // add defaults | |
| 31 | - if (!@array_key_exists($default, $atts)) { // hide warning with "@" when no params at all | |
| 31 | + foreach ( $defaults as $default => $value ) { // add defaults | |
| 32 | + if ( ! @array_key_exists( $default, $atts ) ) { // hide warning with "@" when no params at all | |
| 32 | 33 | $atts[$default] = $value; |
| 33 | 34 | } |
| 34 | 35 | } |
| 35 | 36 | |
| 36 | - $src_cut = substr($atts["src"], 0, 35); // special case maps | |
| 37 | - if(strpos($src_cut, 'maps.google' )){ | |
| 38 | - $atts["src"] .= '&output=embed'; | |
| 37 | + // get_params_from_url | |
| 38 | + if( isset( $atts["get_params_from_url"] ) && ( $atts["get_params_from_url"] == '1' || $atts["get_params_from_url"] == 1 || $atts["get_params_from_url"] == 'true' ) ) { | |
| 39 | + if( $_GET != NULL ){ | |
| 40 | + if( strpos( $atts["src"], '?' ) ){ // if we already have '?' and GET params | |
| 41 | + $encode_string = '&'; | |
| 42 | + }else{ | |
| 43 | + $encode_string = '?'; | |
| 44 | + } | |
| 45 | + foreach( $_GET as $key => $value ){ | |
| 46 | + $encode_string .= $key.'='.$value.'&'; | |
| 47 | + } | |
| 48 | + } | |
| 49 | + $atts["src"] .= $encode_string; | |
| 39 | 50 | } |
| 51 | + | |
| 40 | 52 | $html = ''; |
| 41 | 53 | if( isset( $atts["same_height_as"] ) ){ |
| 42 | 54 | $same_height_as = $atts["same_height_as"]; |
| 43 | 55 | }else{ |
| @@ -53,12 +65,11 @@ | ||
| 53 | 65 | $target_selector = '"' . $same_height_as . '"'; |
| 54 | 66 | } |
| 55 | 67 | $html .= ' |
| 56 | 68 | <script> |
| 57 | - jQuery(document).ready(function($) { | |
| 69 | + jQuery(function($){ | |
| 58 | 70 | var target_height = $(' . $target_selector . ').height(); |
| 59 | 71 | $("iframe.' . $atts["class"] . '").height(target_height); |
| 60 | - //alert(target_height); | |
| 61 | 72 | }); |
| 62 | 73 | </script> |
| 63 | 74 | '; |
| 64 | 75 | }else{ // set the actual height of the iframe (show all content of the iframe without scroll) |
| @@ -63,9 +74,9 @@ | ||
| 63 | 74 | '; |
| 64 | 75 | }else{ // set the actual height of the iframe (show all content of the iframe without scroll) |
| 65 | 76 | $html .= ' |
| 66 | 77 | <script> |
| 67 | - jQuery(document).ready(function($) { | |
| 78 | + jQuery(function($){ | |
| 68 | 79 | $("iframe.' . $atts["class"] . '").bind("load", function() { |
| 69 | 80 | var embed_height = $(this).contents().find("body").height(); |
| 70 | 81 | $(this).height(embed_height); |
| 71 | 82 | }); |
| @@ -73,11 +84,11 @@ | ||
| 73 | 84 | </script> |
| 74 | 85 | '; |
| 75 | 86 | } |
| 76 | 87 | } |
| 77 | - $html .= "\n".'<!-- iframe plugin v.2.4 wordpress.org/extend/plugins/iframe/ -->'."\n"; | |
| 88 | + $html .= "\n".'<!-- iframe plugin v.2.8 wordpress.org/plugins/iframe/ -->'."\n"; | |
| 78 | 89 | $html .= '<iframe'; |
| 79 | - foreach ($atts as $attr => $value) { | |
| 90 | + foreach( $atts as $attr => $value ) { | |
| 80 | 91 | if( $attr != 'same_height_as' ){ // remove some attributes |
| 81 | 92 | if( $value != '' ) { // adding all attributes |
| 82 | 93 | $html .= ' ' . $attr . '="' . $value . '"'; |
| 83 | 94 | } else { // adding empty attributes |
| @@ -84,20 +95,20 @@ | ||
| 84 | 95 | $html .= ' ' . $attr; |
| 85 | 96 | } |
| 86 | 97 | } |
| 87 | 98 | } |
| 88 | - $html .= '></iframe>'; | |
| 99 | + $html .= '></iframe>'."\n"; | |
| 89 | 100 | return $html; |
| 90 | 101 | } |
| 91 | - add_shortcode('iframe', 'iframe_embed_shortcode'); | |
| 102 | + add_shortcode( 'iframe', 'iframe_unqprfx_embed_shortcode' ); | |
| 92 | 103 | |
| 93 | -endif; | |
| 94 | 104 | |
| 95 | - | |
| 96 | -function iframe_unqprfx_plugin_meta( $links, $file ) { // add 'Support' and 'Donate' links to plugin meta row | |
| 97 | - if ( strpos( $file, 'iframe.php' ) !== false ) { | |
| 98 | - $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/wordpress/plugins/iframe/" title="Need help?">' . __('Support') . '</a>' ) ); | |
| 99 | - $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/donate/" title="Support the development">' . __('Donate') . '</a>' ) ); | |
| 105 | + function iframe_unqprfx_plugin_meta( $links, $file ) { // add 'Plugin page' and 'Donate' links to plugin meta row | |
| 106 | + if ( strpos( $file, 'iframe.php' ) !== false ) { | |
| 107 | + $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/wordpress/plugins/iframe/" title="Plugin page">Iframe</a>' ) ); | |
| 108 | + $links = array_merge( $links, array( '<a href="http://web-profile.com.ua/donate/" title="Support the development">Donate</a>' ) ); | |
| 109 | + } | |
| 110 | + return $links; | |
| 100 | 111 | } |
| 101 | - return $links; | |
| 102 | -} | |
| 103 | -add_filter( 'plugin_row_meta', 'iframe_unqprfx_plugin_meta', 10, 2 ); | |
| 112 | + add_filter( 'plugin_row_meta', 'iframe_unqprfx_plugin_meta', 10, 2 ); | |
| 113 | + | |
| 114 | +endif; // end of if(function_exists('iframe_unqprfx_embed_shortcode')) | |