IM2 | OQP

2008/09/28

Oembed, multimedia, laconica, longurl

Filed under: Français, Standards, communication, french, identica, logiciel-libre, microblogging Robin @ 20:59 (802 lectures)

J’ai hâte de voir oembed supporté nativement par laconica et identica. En attendant, je fais une agrégation de mes dents en filtrant les URL via Long URL qui à son tour fait appel à Ooh Embed pour transformer les URL de certains sites en une représentation visualle appropriée.

Voici comment du côté Wordpress, un bout de code que j’ai tout simplement forcé dans mon fichier de thème sidebar.php :


<?php

// YOUR IDENTICA RSS FEED (or anything you like):
$oembed_feed ‘http://identi.ca/millette/rss’;

function oembed_html($matches) {
    
$x file_get_contents(‘http://api.longurl.org/v1/expand?format=php&url=’ urlencode($matches[1]));
    
$y unserialize($x);
    
$z $y['oembed'];
    if (!empty(
$z['url'])) return “<img src=’{$z['url']}’ /> ”;
    return 
$z['html'] . ‘ ’;
}

function output_oembed_html($txt) {
    
$p ‘/(https?\:\/\/.+\s)/U’;
    
$cbrep ‘oembed_html’;
    
$out preg_replace_callback($p$cbrep$txt ‘ ’);
    return 
$out;
}

require_once(ABSPATH WPINC ‘/rss.php’);
$rss fetch_rss($oembed_feed);
foreach (
$rss->items as $i) {
  echo 
“<p><a href=’{$i['link']}’>{$i['summary']}</a><br />”;
  echo 
output_oembed_html($i['title']);
  echo 
‘</p>’;
}

?>


6 Comments »

  1. Je viens juste d’intégrer ce code à mon blogue, merci!

    Par contre, j’ai mis les 2 fonctions oembed_html et output_oembed_html dans le fichier functions.php de mon thème afin de ne pas encombrer mon fichier sidebar.php pour rien.

    Ensuite, j’ai limité à 3 le nombre de messages en rajoutant “?limit=3″ à la variable $oembed_feed.

    Merci encore! Et j’attends que ce soit implémenté directement dans laconica aussi. :)

    Comment by mdupuis — 2008/09/28 @ 21:31

  2. Ah ouin, c’est libre, hein ;)

    Comment by Robin — 2008/09/28 @ 21:38

  3. Merci pour cette contribution au libre, Robin, je compte bien l’essayer. Mais, juste par curiosité, est-ce que ce bout de code est adapté pour les caractères spéciaux, accents, alouette?

    Comment by Pierre-Luc Daoust — 2008/09/29 @ 18:20

  4. Un p’tit test : http://identi.ca/notice/688764

    Pour le moment, c’est super basique, je ne vais chercher qu’un bout de html (embed) ou bien j’affiche l’image sans aucun égard au texte ni au alt. Ça importe bien en UTF-8, c’est tout ce que j’ai essayé et le bout de code ne gère pas les charset et ne fait aucune conversion.

    Comment by Robin — 2008/09/29 @ 18:30

  5. Hey Robin,

    Nice job here. One suggestion is, because you make an API request for every link every page load, to possibly use something like Wordpress’s caching functions (http://codex.wordpress.org/Function_Reference/WP_Cache) to cut down on the number of requests you have to make.

    You should suggest getting this put in some plugins like http://wordpress.org/extend/plugins/lifestream/ and http://blog.bluefur.com/2008/07/10/wordidentica-a-wordpress-plugin-for-identica/

    Cheers!

    Comment by Sean Murphy — 2008/10/01 @ 15:57

  6. Oh, caching is important, thanks for the reminder. I just assumed it was happening automatically since the rss wasn’t refreshing with every reload. Thanks for the tip!

    I don’t intend to keep this here in the sidebar much longer as it isn’t very pretty nor was it meant to be permanent.

    I just can’t wait to see this feature adopted in the laconica codebase!

    Comment by Robin — 2008/10/01 @ 16:12

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress