Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
authorDan
Wed, 26 Mar 2008 11:10:20 -0400
changeset 13 b5db2345c397
parent 12 b3fcc21e557f
child 14 7a1573676cc4
Added PHP feature check to prevent script from throwing unneeded exceptions on unsupported PHP configurations
functions.php
greyhound.php
scripts/ajax.js
webserver.php
--- a/functions.php	Wed Mar 26 10:24:20 2008 -0400
+++ b/functions.php	Wed Mar 26 11:10:20 2008 -0400
@@ -44,6 +44,18 @@
 }
 
 /**
+ * Print a stylized warning message, compatible with Linux consoles
+ * @param string message message
+ */
+
+function warning($msg)
+{
+  $h = @fopen('php://stderr', 'w');
+  fwrite($h, "\x1B[33;1m[Greyhound] \x1B[0m\x1B[33mWarning:\x1B[0m $msg\n");
+  fclose($h);
+}
+
+/**
  * Performs an action with DCOP.
  * @param string DCOP component, e.g. player, playlist, playlistbrowser, ...
  * @param string Action to perform, e.g. stop, play, ...
--- a/greyhound.php	Wed Mar 26 10:24:20 2008 -0400
+++ b/greyhound.php	Wed Mar 26 11:10:20 2008 -0400
@@ -85,6 +85,11 @@
 try
 {
   status('starting PhpHttpd');
+  status('doing PHP capabilities check');
+  if ( !function_exists('pcntl_signal') )
+  {
+    warning('System does not support POSIX functions. Termination signals will result in unclean shutdown.');
+  }
   $httpd = new WebServer($ip, $port);
   
   // setup handlers
--- a/scripts/ajax.js	Wed Mar 26 10:24:20 2008 -0400
+++ b/scripts/ajax.js	Wed Mar 26 11:10:20 2008 -0400
@@ -293,6 +293,10 @@
 {
   var count_seconds = time % 60;
   var count_minutes = ( time - count_seconds ) / 60;
+  if ( isNaN(count_seconds) )
+    count_seconds = 0;
+  if ( isNaN(count_minutes) )
+    count_minutes = 0;
   return fill_zeroes(count_minutes) + ':' + fill_zeroes(count_seconds);
 }
 
@@ -335,13 +339,16 @@
       $(booby).rmClass(match[2]);
     }
   }
+  // recalculate list of rows that should pulse
   var tdlist_new = document.getElementsByClassName('current', 'tr');
   if ( pulsar_current == 0 && tdlist_new == pulsar_tdlist )
   {
     return true;
   }
+  // reset everything to 0
   pulsar_tdlist = tdlist_new;
   pulsar_current = 0;
+  pulsar_direction = 1;
   for ( var i = 0; i < pulsar_tdlist.length; i++ )
   {
     var td = pulsar_reset[i];
@@ -361,6 +368,10 @@
 
 var pulsar_advance = function()
 {
+  // this should be as optimized as possible, it should use a precalculated
+  // list of elements to pulse and whatnot... heck even right now it's not
+  // really as optimized as it should be due to the logic, but a lot of it's
+  // kinda more or less necessary.
   if ( !is_playing )
     return true;
   if ( pulsar_current + pulsar_direction == 10 )
--- a/webserver.php	Wed Mar 26 10:24:20 2008 -0400
+++ b/webserver.php	Wed Mar 26 11:10:20 2008 -0400
@@ -105,6 +105,12 @@
     @set_time_limit(0);
     @ini_set('memory_limit', '256M');
     
+    // do we have socket functions?
+    if ( !function_exists('socket_create') )
+    {
+      burnout('System does not support socket functions. Please rebuild your PHP or install an appropriate extension.');
+    }
+    
     $this->sock = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp'));
     if ( !$this->sock )
       throw new Exception('Could not create socket');