From 960ed331c766938f62f5d0534699ed453a21ec7d Mon Sep 17 00:00:00 2001 From: Andy Balaam Date: Fri, 9 Nov 2012 03:08:39 +0000 Subject: [PATCH] Numerous fixes and clean-ups for the web interface. --- playonwii/index.php | 119 ++++++++++++++++++++++++++++++++++++----------- playonwii/play-html5.php | 2 +- playonwii/play.php | 2 +- 3 files changed, 94 insertions(+), 29 deletions(-) diff --git a/playonwii/index.php b/playonwii/index.php index c6b3602..980968a 100644 --- a/playonwii/index.php +++ b/playonwii/index.php @@ -2,8 +2,17 @@ include_once( "functions.php" ); -$extra_path = sanitise_filename( $_GET["path"] ); -$excluded_preprepare = explode( ":", $_GET["exclude"] ); +$extra_path = ""; +if ( array_key_exists( "path", $_GET ) ) +{ + $extra_path = sanitise_filename( $_GET["path"] ); +} + +$excluded_preprepare = array(); +if ( array_key_exists( "exclude", $_GET ) ) +{ + $excluded_preprepare = explode( ":", $_GET["exclude"] ); +} $excluded = array(); @@ -77,15 +86,36 @@ function pretty_date( $date ) { global $num_to_month; - $tm = mktime( - (int)( substr( $date, 11, 2 ) ), - (int)( substr( $date, 14, 2 ) ), - 0, - (int)( substr( $date, 5, 2 ) ), - (int)( substr( $date, 8, 2 ) ), - (int)( substr( $date, 0, 4 ) ) ); - - return date( "D d M, H:i", $tm ); + $hour = substr( $date, 11, 2 ); + $minute = substr( $date, 14, 2 ); + //$second omitted + $month = substr( $date, 5, 2 ); + $day = substr( $date, 8, 2 ) ; + $year = substr( $date, 0, 4 ); + + if( + is_numeric( $hour ) && + is_numeric( $minute ) && + is_numeric( $month ) && + is_numeric( $day ) && + is_numeric( $year ) + ) + { + $tm = mktime( + (int)( $hour ), + (int)( $minute ), + 0, + (int)( $month ), + (int)( $day ), + (int)( $year ) + ); + + return date( "D d M, H:i", $tm ); + } + else + { + return ""; + } } function single_quote_attribute_escape( $value ) @@ -110,8 +140,13 @@ function get_info_from_file( $fn ) $line = fgets( $handle ); $line = substr( $line, 0, -1 ); - list( $k, $v ) = split( "=", $line, 2 ); + $splitline = split( "=", $line, 2 ); + if( count( $splitline ) < 2 ) + { + continue; + } + list( $k, $v ) = $splitline; switch( $k ) { case "title": @@ -150,10 +185,15 @@ function get_info_from_file( $fn ) function get_info_from_filename( $fn ) { - if( preg_match( '/^(.*?)-(.*)\\..*$/', $fn, $matches ) ) + if( preg_match( '/(.*\\/)?([^\\/]*)\\/(.*)-.*$/', $fn, $matches ) ) + { + $title = $matches[2]; + $date = $matches[3]; + } + else if( preg_match( '/(.*\\/)?([^\\/]*)\\/.*$/', $fn, $matches ) ) { - $title = $matches[1]; - $date = $matches[2]; + $title = $matches[2]; + $date = ""; } else { @@ -161,7 +201,16 @@ function get_info_from_filename( $fn ) $date = ""; } - return array( $title, $date ); + if( preg_match( '/.*\\/(.*)\\..*$/', $fn, $matches ) ) + { + $sub_title = $matches[1]; + } + else + { + $sub_title = $fn; + } + + return array( $title, $date, $sub_title ); } function get_info( $filename, $filenames ) @@ -169,6 +218,10 @@ function get_info( $filename, $filenames ) global $full_videos_dir; $title = Null; + $date = Null; + $channel = Null; + $sub_title = Null; + $description = Null; if( preg_match( '/^(.*?)\\.(flv|avi|avi_high\\.mp4|webm|mp4)$/', $filename, $matches ) ) { @@ -182,14 +235,12 @@ function get_info( $filename, $filenames ) } else { - list( $title, $date ) = get_info_from_filename( $filename ); + list( $title, $date, $sub_title ) = + get_info_from_filename( $filename ); + $channel = ""; - $sub_title = ""; $description = ""; } - $titles[$title][] = array( $num, $date, $channel, $sub_title, - $description ); - $num++; } return array( $title, $date, $channel, $sub_title, $description ); @@ -388,7 +439,6 @@ function delete_prog( prog_filename ) $table_counter = 0; foreach( $titles as $title => $arr ) { - list( $num, $date, $channel, $sub_title ) = $arr[0]; print "

$title

\n"; print ""; @@ -399,7 +449,7 @@ function delete_prog( prog_filename ) $dotpos = strrpos( $filename, '.' ); $ext = substr( $filename, $dotpos ); - $play_url = "$videos_uri/$extra_dir$filename"; + $play_url = "$videos_uri/$extra_path$filename"; if( $ext == ".webm" || $ext == ".mp4" ) { $play_url = "play-html5.php?filename=$extra_path$filename"; @@ -418,19 +468,34 @@ function delete_prog( prog_filename ) if( $sub_title ) { - print $sub_title . " ("; + print $sub_title . " "; } - print pretty_date( $date ); + $dtchan = pretty_date( $date ); if( $channel ) { - print " on $channel"; + $dtchan .= " on $channel"; + } + + if( $dtchan ) + { + if( $sub_title ) + { + print "("; + } + + print $dtchan; + + if( $sub_title ) + { + print ")"; + } } if( $sub_title ) { - print ")"; + print ""; } print ""; diff --git a/playonwii/play-html5.php b/playonwii/play-html5.php index 32ec04d..50b0465 100644 --- a/playonwii/play-html5.php +++ b/playonwii/play-html5.php @@ -12,7 +12,7 @@ $extension = substr( $file_path, $dotpos + 1 ); - <?php print "$curfiletitle" ?> + Play file diff --git a/playonwii/play.php b/playonwii/play.php index 74e5cfa..63a4fcf 100644 --- a/playonwii/play.php +++ b/playonwii/play.php @@ -12,7 +12,7 @@ $height = 330; - <?php print "$curfiletitle" ?> + Play file -- 2.11.4.GIT