WordPress Plugin für TED Filme

Sun, 01. Mar 2009

Categories: de sysadmin Tags: Plugin PHP TED

Basierend auf dem Plugin von Robert Anselm experimentiere ich nachdem TED den ‘embed’ Code geändert hat derzeit mit folgendem Plugin Code:

<?php
/*
Plugin Name: TEDTalks for WordPress
Plugin URI: http://www.robertanselm.com/2.0/
Description: A filter for WordPress that displays TED.com videos based on the
Youtube WordPress plugin by Joern Zaefferer. Copy and paste the TEDTalks
"Embed Video" code to a text editor and look for the .flv filename of the
flashvideo. (eg.: JOHNMAEDA-2007_high.flv ).
In WordPress type: [TEDTALKS JOHNMAEDA-2007_high.flv].
Version: 1.0
Author: Robert Anselm
Author URI: http://www.robertanselm.com/2.0/

Instructions

Copy this file you unzipped into the wp-content/plugins folder of WordPress,
then go to Administration > Plugins, it should be in the list. Activtate it
and every occurence of the expression [TEDTALKS file] will as
an embedded flash player. Replace "file" with the TEDTALKS .flv filename.
Copy and paste the TEDTalks "Embed Viedo" code to a text editor and look
for the .flv filename of the flashvideo. (eg.: JOHNMAEDA-2007_high.flv ).
In WordPress type: [TEDTALKS JOHNMAEDA-2007_high.flv].

See also the player embed swap at TED:
 http://blog.TED.com/2009/01/TEDtalks_time_f.php
 http://blog.TED.com/2009/01/TEDtalks_embed_1.php
*/

define("TEDTALKS_REGEXP", "/\[TEDTALKS ([[:print:]]+)[-_: ]([0-9]{4}[GP]?)\]/");
define("TEDTALKS_TARGET", " ");

function TEDtalks_plugin_callback($match)
{
  $output = TEDTALKS_TARGET;
  $speaker = $match[1];
  $year = $match[2];
  $output = str_replace("###TED-###", $speaker.'-'.$year, $output);
  $output = str_replace("###TED_###", $speaker.'_'.$year, $output);
  //if(strlen($year) > 4)
  if('P'==substr($year,4))
    $output = str_replace("-embed_high.flv", "-embed-PARTNER_high.flv", $output);
  return ($output);
}

function TEDtalks_plugin($content)
{
  return (preg_replace_callback(TEDTALKS_REGEXP, 'TEDtalks_plugin_callback', $content));
}

add_filter('the_content', 'TEDtalks_plugin');
add_filter('comment_text', 'TEDtalks_plugin');

?>

Das Plugin ist ein wenig komplizierter zu erklären, aber einfacher zu benutzen (Magic!).