[cvs-annodex] commit (/annodex): phpannodex/trunk/phpsrc/mod_annodex.php

ctford nobody at lists.annodex.net
Wed Dec 21 17:05:24 EST 2005


Update of /annodex (new revision 1718)

Modified files:
   phpannodex/trunk/phpsrc/mod_annodex.php

Log Message:
Should now be able to look at the accept field of the request and respond with cmml or annodex appropriately. Seems to be outputting the right stuff, but doesn't play in firefox yet. Stay tuned... :)

Modified: phpannodex/trunk/phpsrc/mod_annodex.php
===================================================================
--- phpannodex/trunk/phpsrc/mod_annodex.php	2005-12-21 03:59:15 UTC (rev 1717)
+++ phpannodex/trunk/phpsrc/mod_annodex.php	2005-12-21 06:05:23 UTC (rev 1718)
@@ -1,6 +1,7 @@
+#!/usr/local/bin/php
 <?php
 
-	const BUFFER_SIZE = 1024;
+	define( "BUFFER_SIZE",  1024);
 	
 	/* Attempt to stop browsers caching the output of the script. */
 	header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
@@ -9,39 +10,70 @@
 	/* Break up the accept field of the request so we can parse it. */
 	$accept_array = explode(",",$_SERVER[HTTP_ACCEPT]);
 
+	/*FIXME Need to actually get the filename */
+	$filename_root = "/var/www/phpannodex/php_tests/a_new_computer";
+
 	/* If application/x-cmml is a higher priority than 
 	 * application/x-annodex then we want to output cmml. Otherwise we want
 	 * to output annodex.
 	 */
+	//header('Content-Type: text/html');
+	//echo "\n";
+	
+	//echo $filename_root;
+	
+	if( cmml_prioritised( $accept_array ) ) {
+		output_cmml( $filename_root );
+		//echo "Pretend we outputted cmml";
+	} else {
+		output_annodex( $filename_root );
+		//echo "Pretend we outputted anx";
+	}
+	exit;
+
+/* Check the accept field of the request. If cmml appears before annodex return
+ * true, otherwise return false.
+ */
+function cmml_prioritised( $accept_array ) {
+
 	foreach( $accept_array as $key => $type ) {
 		$accept_array[$key] = explode(";",$type);
 		if( $accept_array[$key][1]=="text/x-cmml" ) {
-			output_cmml();
-			exit;
+			/* Found cmml before annodex. */
+			return true;
 		} else if ( $accept_array[$key][1]=="application/x-annodex" ) {
-			break;
+			/* Found annodex before cmml. */
+			return false;	
 		}
 	}
-
-	/* If we get this far in the script it's because cmml is not preferred
-	 * over annodex.
-	 */
-	output_annodex();
-	exit;
-
+	/* Neither cmml nor annodex found. */
+	return false;
+}
+	
+	
 /* Output the requested .anx file as cmml. */
-function output_cmml( $filename ) {
+function output_cmml( $filename_root ) {
 
 	header('Content-Type: text/x-cmml');
 
+	/* Strip the "anx" off the filename and replace it with "cmml".
+         * This should be done in a more elegant way
+ 	 */
+	$cmml_filename = $filename_root . ".cmml";
+	
+	/* Spit it straight out. */
+	$file_handle = readfile( $cmml_filename );
 
 	return;
 }
 
 /* Output the requested .anx file as proper annodex. */
-function output_annodex( $filename ) {
+function output_annodex( $filename_root ) {
+
+	$filename = $filename_root . ".ogg";
 	
 	header('Content-Type: application/x-annodex');
+	//echo "\n";
 
 	anx_init_importers( "*/*" );
 	$anx = anx_new( ANX_WRITE );
@@ -60,4 +92,4 @@
 
 	return;
 }
-	
+?>	


-- 
ctford



More information about the cvs-annodex mailing list