Flash Player version in AWStats – Revised

My first implementation of this idea may have been sufficient for general use. For inclusion in WordPress however it was problematic at best.
Now that I have revised (and tested) it, I thought I’d share this updated WordPress plugin.

<?php
/*
Plugin Name: Flash version Detection
Plugin URI: http://www.dirty-motherfucker.org/
Description: Detects flash version
Version: 0.1
Author: gencha
Author URI: http://www.dirty-motherfucker.org
*/

$plugin_root = get_settings('siteurl') . '/wp-content/plugins/'.dirname(plugin_basename(__FILE__));

if( preg_match("/(\/\?feed=|\/feed)/i",$_SERVER['REQUEST_URI']) ) {
        // RSS Feeds
        // do nothing
} else {
        add_action('wp_head', 'add_head');
}

function add_head() {
	global $plugin_root;
	echo '
	<!-- Flash player version detection -->
	<script src="' . $plugin_root . '/swfobject.js" type="text/javascript"></script>
	<script type="text/javascript">
		window.onload = function() {
			var version = deconcept.SWFObjectUtil.getPlayerVersion();
			if( document.getElementById && version["major"]> 0 ) {
				var flash_version = version["major"] +"."+ version["minor"] +"."+ version["rev"];
				document.getElementById("flashversion").innerHTML = "<iframe src=\"' . get_settings("siteurl") . '/flash_player_version.php?version=" + flash_version + "\" style=\"display: none;\"></iframe>";
			}
		}
	</script>
	';
}
?>

In this version I put the JavaScript code inline. Although I’m not a big fan of that, it’s reasonable in this case and I have all the code in one place. This made it easier to fix the second bug. Which was that the whole concept only worked on the main page. On other pages the browser couldn’t find the flash_version.php file. Which resulted in nasty 404 errors. Now I can simply put the blogs base path into the JavaScript code and everything is well.

One Response to “Flash Player version in AWStats – Revised”

  1. arT2 Says:

    i’ll test it as soon as the project i’m workin’ on goes beta ;)

Leave a Reply

You must be logged in to post a comment.