Tim Heuer released a silverlight plugin for wordpress.

In the never ending process of setting up my blog I added his plug-in.

When playing with it and trying to write a post I had a problem adding multiple embeds, so I took the liberty to poke through the code.

I was quite impressed with simplicity of the plug in management in Word Press.

WP has an easy to change and quick to deploy development story , that interpreter based languages has – It’s a joy.

But back to SL plug in , i tinkered with it and found out that Tim already had 99.9% of the way.

what basically the plug in does is parse the post code and replace a some special markers with silverlight embed code.

the function that does the work has a stop condition on line 4, and to enable multiple embeds I changed the return value to be recursive (line 29)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
function silverlight_the_content($content)
{
	$found_pos = strpos($content, SILVERLIGHT_META_START);
	if(!$found_pos) return ($content);
 
	$embedded = substr($content, 0, $found_pos);
	$meta = explode(",", trim(substr($content, $found_pos+strlen(SILVERLIGHT_META_START), (strpos($content, SILVERLIGHT_META_END, $found_pos) - ($found_pos+strlen(SILVERLIGHT_META_START))))));
 
	$output = $embedded . SILVERLIGHT_TARGET;
	$paramHolder = SILVERLIGHT_INITPARAMS;
	$url = trim($meta[0]);
	$width = trim($meta[1]);
	$height = trim($meta[2]);
	$initparams = trim($meta[3]);
  $minver = trim($meta[4]);
	if(!strpos($url, "http://")) $url = get_option('silverlight_standard_location') . $url;
	if(strlen($width) <= 0) $width = get_option('silverlight_standard_width');
	if(strlen($height) <= 0) $height = get_option('silverlight_standard_height');
  if(strlen($minver) <= 0) $minver = get_option('silverlight_standard_version'); 	$output = str_replace("###URL###",  $url, $output); 	$output = str_replace("###WIDTH###", $width, $output); 	$output = str_replace("###HEIGHT###", $height, $output);   $output = str_replace("###MINVER###", $minver, $output); 	if(strlen($initparams) > 0) {
    $initparams_parsed = str_replace("#", ",", $initparams);
    $paramHolder = str_replace("###INITPARAMS###", $initparams_parsed, $paramHolder);
    $output = str_replace("###PARAMHOLDER###", $paramHolder, $output);
  }
  else {
    $output = str_replace("###PARAMHOLDER###", "", $output);
  }
	$output .= "
" . substr($content, strpos($content, SILVERLIGHT_META_END, $found_pos)+1);
  return silverlight_the_content($output);
//return ($output);
}