Thumbnail programmes as we convert them
[recordtv.git] / playonwii / index.php
blobfbfba1bb943ecc5c3bf65b4785f0bcfad4657cc0
1 <?php
3 include_once( "functions.php" );
5 $extra_path = "";
6 if ( array_key_exists( "path", $_GET ) )
8 $extra_path = sanitise_filename( $_GET["path"] );
11 $excluded_preprepare = array();
12 if ( array_key_exists( "exclude", $_GET ) )
14 $excluded_preprepare = explode( ":", $_GET["exclude"] );
17 $excluded = array();
19 foreach( $excluded_preprepare as $ex )
21 $excluded[] = sanitise_filename( $ex );
24 $full_videos_dir = $videos_dir;
26 if( $extra_path )
28 $full_videos_dir .= "/$extra_path";
29 if( !ends_with( $extra_path, "/" ) )
31 $extra_path .= "/";
34 else
36 $extra_path = "";
39 function is_video_dir( $full_path )
41 if( substr_compare( $full_path, "/.", -2 ) == 0 or
42 substr_compare( $full_path, "/..", -3 ) == 0 or
43 substr_compare( $full_path, "/deleted", -8 ) == 0 or
44 substr_compare( $full_path, "/tvguide", -8 ) == 0 )
46 return false;
49 return is_dir( $full_path );
52 function is_not_excluded( $filename )
54 global $excluded;
56 return !in_array( $filename, $excluded );
59 function get_filenames_recursive( &$filenames, $top_dir, $sub_dir = "" )
61 $handle = opendir( "$top_dir/$sub_dir" );
62 if( $handle )
64 while( ( $filename = readdir( $handle ) ) )
66 if( strlen( $sub_dir ) > 0 )
68 $filepath = "$sub_dir/$filename";
70 else
72 $filepath = $filename;
74 if( is_not_excluded( $filename ) &&
75 is_video_dir( "$top_dir/$sub_dir/$filename" ) )
77 get_filenames_recursive( $filenames, $top_dir, $filepath );
79 else
81 $filenames[$filepath] = '';
84 closedir($handle);
88 function pretty_date( $date )
90 global $num_to_month;
92 $hour = substr( $date, 11, 2 );
93 $minute = substr( $date, 14, 2 );
94 //$second omitted
95 $month = substr( $date, 5, 2 );
96 $day = substr( $date, 8, 2 ) ;
97 $year = substr( $date, 0, 4 );
99 if(
100 is_numeric( $hour ) &&
101 is_numeric( $minute ) &&
102 is_numeric( $month ) &&
103 is_numeric( $day ) &&
104 is_numeric( $year )
107 $tm = mktime(
108 (int)( $hour ),
109 (int)( $minute ),
111 (int)( $month ),
112 (int)( $day ),
113 (int)( $year )
116 return date( "D d M, H:i", $tm );
118 else
120 return "";
124 function single_quote_attribute_escape( $value )
126 return str_replace( "'", "&apos;", $value );
129 function get_info_from_file( $fn )
131 $title = "";
132 $sub_title = "";
133 $description = "";
134 $date = "";
135 $channel = "";
137 $handle = fopen( $fn, "r" );
139 if( $handle )
141 while ( !feof( $handle ) )
143 $line = fgets( $handle );
144 $line = substr( $line, 0, -1 );
146 $splitline = split( "=", $line, 2 );
147 if( count( $splitline ) < 2 )
149 continue;
152 list( $k, $v ) = $splitline;
153 switch( $k )
155 case "title":
157 $title = $v;
158 break;
160 case "sub_title":
162 $sub_title = $v;
163 break;
165 case "description":
167 $description = $v;
168 break;
170 case "startTime":
172 $date = $v;
173 break;
175 case "channel_pretty":
177 $channel = $v;
178 break;
183 fclose( $handle );
186 return array( $title, $date, $channel, $sub_title, $description );
189 function get_info_from_filename( $fn )
191 if( preg_match( '/(.*\\/)?([^\\/]*)\\/(.*)-.*$/', $fn, $matches ) )
193 $title = $matches[2];
194 $date = $matches[3];
196 else if( preg_match( '/(.*\\/)?([^\\/]*)\\/.*$/', $fn, $matches ) )
198 $title = $matches[2];
199 $date = "";
201 else
203 $title = substr( $fn, 0, strlen( $fn ) - 4 );
204 $date = "";
207 if( preg_match( '/.*\\/(.*)\\..*$/', $fn, $matches ) )
209 $sub_title = $matches[1];
211 else
213 $sub_title = $fn;
216 return array( $title, $date, $sub_title );
219 function get_info( $filename, $filenames )
221 global $full_videos_dir;
223 $title = Null;
224 $date = Null;
225 $channel = Null;
226 $sub_title = Null;
227 $description = Null;
229 if( preg_match( '/^(.*?)\\.(flv|avi|avi_high\\.mp4|webm|mp4)$/', $filename, $matches ) )
232 $infofn = $matches[1] . ".rtvinfo";
234 if( array_key_exists( $infofn, $filenames ) )
236 list( $title, $date, $channel, $sub_title, $description ) =
237 get_info_from_file( $full_videos_dir . "/" . $infofn );
239 else
241 list( $title, $date, $sub_title ) =
242 get_info_from_filename( $filename );
244 $channel = "";
245 $description = "";
249 return array( $title, $date, $channel, $sub_title, $description );
252 // This is a hash filename -> nothing of all files in the videos directory
253 // and subdirectories
254 $filenames = array();
255 get_filenames_recursive( $filenames, $full_videos_dir );
257 // This is a hash filename -> nothing of all files in the deleted directory
258 $deleted_filenames = array();
259 $handle = opendir( $deleted_dir );
260 if( $handle )
262 while( ( $filename = readdir( $handle ) ) )
264 $deleted_filenames[$filename] = '';
267 closedir($handle);
271 // This is a hash title->array( array( filenumber, date, filename, channel ) )
272 $titles = array();
273 $num = 0;
275 $nondeleted_filenames = array();
277 foreach ( $filenames as $fn => $blank )
279 $modified_fn = str_replace( "/", "_", "$extra_path$fn" );
280 if( !array_key_exists( $modified_fn, $deleted_filenames ) )
282 $nondeleted_filenames[$fn] = '';
285 #array_diff_key( $filenames, $deleted_filenames );
287 $sorted_fns = array_keys( $nondeleted_filenames );
288 sort( $sorted_fns );
290 foreach( $sorted_fns as $filename )
292 list( $title, $date, $channel, $sub_title, $description ) = get_info(
293 $filename, $nondeleted_filenames );
295 if( $title != Null )
297 $titles[$title][] = array( $num, $date, $channel, $sub_title,
298 $description, $filename );
299 $num++;
305 <html>
307 <head>
308 <title>Recorded programmes</title>
309 <style type="text/css">
310 body {
311 font-family: verdana, sans-serif;
312 text-align: center;
315 text-decoration: none;
316 color: black;
318 a:hover {
319 color: red;
321 a.deletelink {
322 color:red;
323 font-size: xx-small;
325 a.title {
326 color: blue;
328 span.smalltime {
329 font-size: smaller;
330 color: gray;
332 span.smalltime:hover {
333 color: red;
335 h2 {
336 font-size: x-large;
337 font-weight: normal;
338 color: blue;
339 margin: 2px;
341 td.dates {
342 font-size: small;
344 </style>
345 <script language="JavaScript">
347 function makeRequest( url, arg )
349 var httpRequest;
351 if( window.XMLHttpRequest ) // Mozilla, Safari etc.
353 httpRequest = new XMLHttpRequest();
355 else if( window.ActiveXObject ) // IE
359 httpRequest = new ActiveXObject( "Msxml2.XMLHTTP" );
361 catch( e )
365 httpRequest = new ActiveXObject( "Microsoft.XMLHTTP" );
367 catch( e )
373 if( !httpRequest )
375 return false;
378 httpRequest.onreadystatechange = function()
380 receiveAnswer( httpRequest, arg );
383 httpRequest.open('GET', url, true);
384 httpRequest.send('');
387 function receiveAnswer( httpRequest, prog_filename )
389 if( httpRequest.readyState == 4 )
391 if( httpRequest.status != 200 )
393 document.location = "delete_error.php?filename=" + prog_filename
399 function mouse_over( tr_id )
401 tr_el = document.getElementById( tr_id );
402 tr_el.style.backgroundColor = '#ffaaaa';
405 function mouse_out( tr_id )
407 tr_el = document.getElementById( tr_id );
408 tr_el.style.backgroundColor = 'transparent';
411 function title_click( table_id )
413 table_el = document.getElementById( table_id );
414 if( table_el.style.display == 'inline' )
416 table_el.style.display = 'none';
418 else
420 table_el.style.display = 'inline';
425 function delete_prog( prog_filename )
427 makeRequest( 'delete.php?filename=' + prog_filename,
428 prog_filename );
429 tr_el = document.getElementById( 'tr_' + prog_filename );
430 tr_el.style.display = 'none';
433 </script>
434 </head>
436 <body>
437 <h1>Recorded programmes</h1>
439 <center>
440 <?php
441 ksort( $titles );
442 $table_counter = 0;
443 foreach( $titles as $title => $arr )
445 print "<h2><a class='title' href='javascript: title_click( \"table_$table_counter\" )'>$title</a></h2>\n";
447 print "<table id='table_$table_counter' style='display: none' width='90%' cellpadding='0' cellspacing='0' border='0'>";
448 foreach( $arr as $lst )
450 list( $num, $date, $channel, $sub_title, $description,
451 $filename ) = $lst;
453 $dotpos = strrpos( $filename, '.' );
454 $ext = substr( $filename, $dotpos );
455 $play_url = "$videos_uri/$extra_path$filename";
456 if( $ext == ".webm" || $ext == ".mp4" )
458 $play_url = "play-html5.php?filename=$extra_path$filename";
460 else if( $ext == ".flv" )
462 $play_url = "play.php?filename=$extra_path$filename";
465 print "<tr id='tr_$extra_path$filename'><td><a href='$play_url' style='padding-right: 10px'";
467 print " title='".single_quote_attribute_escape( $description )
468 ."'";
470 print ">";
472 if( $sub_title )
474 print $sub_title . " <span class='smalltime'>";
477 $dtchan = pretty_date( $date );
479 if( $channel )
481 $dtchan .= " on $channel";
484 if( $dtchan )
486 if( $sub_title )
488 print "(";
491 print $dtchan;
493 if( $sub_title )
495 print ")";
499 if( $sub_title )
501 print "</span>";
504 print "</a></td>";
505 print "<td><a class='deletelink' onmouseover='mouse_over(\"tr_$extra_path$filename\")' onmouseout='mouse_out(\"tr_$extra_path$filename\")' href='javascript: delete_prog( \"$extra_path$filename\" )'>[DELETE]</a></td></tr>\n";
507 print "</table>\n";
508 $table_counter += 1;
511 </center>
513 </body>
515 </html>