Plugin Directory

Changeset 701765


Ignore:
Timestamp:
04/22/2013 08:02:59 PM (13 years ago)
Author:
jmagnone
Message:

Adding new support for oEmbed with improved height

File:
1 edited

Legend:

Unmodified
Added
Removed
  • slideonline/trunk/slideonline.php

    r663817 r701765  
    44Plugin URI: http://slideonline.com/
    55Description: Easily embed your presentations in a WordPress blog. SlideOnline.com is a free service to share PowerPoint presentations online.
    6 Version: 1.1
     6Version: 1.2
    77Author: Julian Magnone
    88Author URI: http://magn.com
     9
     10This plugin allows WordPress users to embed SlideOnline presentations into the blog posts. The code below is organized in the following way:
     11First section contains procedures to embed the presentations using the shortcode [slideonline id=""]
     12The second section contains directives to configure the oEmbed functionality into the WordPress by using a hook. This will allow to add
     13SlideOnline as an oEmbed provider and then be able to use it by pasting the links.
    914*/ 
    1015
     16/* Section #2: Configure Embed options by using IFRAME and defaults */
    1117
    1218$slideonline_options = array(
     
    9399}
    94100
     101/* Section #2: Configure oEmbed functionality */
     102
     103function add_oembed_slideonline(){
     104    //wp_oembed_add_provider( 'http://slideonline.com/presentation/*', 'http://slideonline.com/oembed');
     105    wp_oembed_add_provider("#http://(.+)?slideonline\.com/presentation/.*#i", "http://slideonline.com/oembed", true);
     106}
     107add_action('init','add_oembed_slideonline');
     108
     109function slideonline_oembed_html($html, $url, $args) {
     110    global $content_width;
     111
     112    preg_match('/width="([0-9]*)"/', $html, $matches);
     113    if (!empty($matches) AND !empty($matches[1]))
     114    {   
     115        $width = (int)$matches[1];
     116    }
     117
     118    // Set the width of the video
     119    $width_pattern = "/width=\"[0-9]*\"/";
     120    //$html = preg_replace($width_pattern, "width='340'", $html);
     121    if (!empty($content_width))
     122    {
     123        $html = preg_replace($width_pattern, "width=\"{$content_width}\"", $html);
     124        $new_width = $content_width;
     125    }
     126
     127    preg_match('/height="([0-9]*)"/', $html, $matches);
     128    if (!empty($matches) AND !empty($matches[1]))
     129    {
     130            $height = (int)$matches[1];
     131            if (!empty($new_width)) $new_height = $new_width * $height / $width; 
     132            // Set the height of the video
     133            $height_pattern = "/height=\"[0-9]*\"/";
     134            $html = preg_replace($height_pattern, "height='{$new_height}'", $html);
     135    }
     136    return $html; // return updated content
     137} // end slideonline_oembed_html
     138add_filter('embed_oembed_html', 'slideonline_oembed_html', 10, 3);
     139
     140//Custom oEmbed Size
     141function slideonline_oembed_defaults($embed_size) {
     142    if(is_front_page()) {
     143        $embed_size['width'] = 640;
     144        $embed_size['height'] = 480;
     145    }
     146    else {
     147        $embed_size['width'] = 640;
     148        $embed_size['height'] = 480;
     149    }
     150    return $embed_size;
     151}
     152add_filter('embed_defaults', 'slideonline_oembed_defaults');
    95153
    96154
Note: See TracChangeset for help on using the changeset viewer.