Not signed in ( Sign In)

Categories

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

Vanilla 1.1.10 is a product of Lussumo. More Information: Documentation, Community Support.

    •  
      CommentAuthorNoWhereMan
    • CommentTimeDec 5th 2009 edited
     permalink
    I have implemented a very quick oEmbed plugin

    oEmbed

    needs php5 and the json extension to work (because I'm lazy), bbcode (with inline html enabled) and extendedimg bbcode plugin (here on this forum)
    you can customize it by hand by the way, since it's very simple

    supports photo, video (and probably should work with rich and link as well). For more info... search for oEmbed wordpress 2.9 online and you should see how it works, or see the home page of oEmbed. Supported params for the [oembed] tag are those defined there for requests

    code:
    <?php
    /*
    Plugin Name: oembed
    Version: 1.0
    Plugin URI: http://www.example.com
    Description: Description for oembed
    Author: $AUTHOR$
    Author URI: http://www.example.com
    */

    /*
    * Code goes here
    *
    */

    function plugin_oembed_callback($action, $attr, $content, $params, $node_object) {
    $provider = 'http://oohembed.com/oohembed/?';
    $attr['url'] = $attr['default'];
    unset($attr['default']);

    $query = http_build_query($attr);
    $json = file_get_contents('http://oohembed.com/oohembed/?'.$query);


    $out = '';

    $obj = json_decode($json);
    switch ($obj->type) {

    case 'photo':
    $out = "[img={$obj->url}]"
    ."\"{$obj->title}\" by [url={$obj->author_url}]{$obj->author_url}[/url] "
    ."([url={$obj->provider_url}]{$obj->provider_name}[/url])[/img]";
    break;

    case 'video':
    case 'rich':
    case 'link':
    $out = $obj->html; break;

    default: if ($action=='validate') return false;
    }

    return $out;

    }


    function plugin_oembed_parse($text) {
    global $OEMBED_BBCODE;
    return $OEMBED_BBCODE->parse($text);
    }

    function plugin_oembed_init() {
    global $OEMBED_BBCODE;
    $OEMBED_BBCODE = new StringParser_BBcode;
    $OEMBED_BBCODE->addCode(
    'oembed',
    'callback_replace_single',
    'plugin_oembed_callback',
    array(),
    'inline',
    array('inline', 'block'),
    array()
    );
    $OEMBED_BBCODE->setCodeFlag('oembed', 'closetag', BBCODE_CLOSETAG_FORBIDDEN);
    }




    add_filter('init', 'plugin_oembed_init');
    add_filter('content_save_pre', 'plugin_oembed_parse');