3 include_once( "functions.php" );
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"] );
19 foreach( $excluded_preprepare as $ex )
21 $excluded[] = sanitise_filename( $ex );
24 $full_videos_dir = $videos_dir;
28 $full_videos_dir .= "/$extra_path";
29 if( !ends_with( $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 )
49 return is_dir( $full_path );
52 function is_not_excluded( $filename )
56 return !in_array( $filename, $excluded );
59 function get_filenames_recursive( &$filenames, $top_dir, $sub_dir = "" )
61 $handle = opendir( "$top_dir/$sub_dir" );
64 while( ( $filename = readdir( $handle ) ) )
66 if( strlen( $sub_dir ) > 0 )
68 $filepath = "$sub_dir/$filename";
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 );
81 $filenames[$filepath] = '';
88 function pretty_date( $date )
92 $hour = substr( $date, 11, 2 );
93 $minute = substr( $date, 14, 2 );
95 $month = substr( $date, 5, 2 );
96 $day = substr( $date, 8, 2 ) ;
97 $year = substr( $date, 0, 4 );
100 is_numeric( $hour ) &&
101 is_numeric( $minute ) &&
102 is_numeric( $month ) &&
103 is_numeric( $day ) &&
116 return date( "D d M, H:i", $tm );
124 function single_quote_attribute_escape( $value )
126 return str_replace( "'", "'", $value );
129 function get_info_from_file( $fn )
137 $handle = fopen( $fn, "r" );
141 while ( !feof( $handle ) )
143 $line = fgets( $handle );
144 $line = substr( $line, 0, -1 );
146 $splitline = split( "=", $line, 2 );
147 if( count( $splitline ) < 2 )
152 list( $k, $v ) = $splitline;
175 case "channel_pretty":
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];
196 else if( preg_match( '/(.*\\/)?([^\\/]*)\\/.*$/', $fn, $matches ) )
198 $title = $matches[2];
203 $title = substr( $fn, 0, strlen( $fn ) - 4 );
207 if( preg_match( '/.*\\/(.*)\\..*$/', $fn, $matches ) )
209 $sub_title = $matches[1];
216 return array( $title, $date, $sub_title );
219 function get_info( $filename, $filenames )
221 global $full_videos_dir;
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 );
241 list( $title, $date, $sub_title ) =
242 get_info_from_filename( $filename );
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 );
262 while( ( $filename = readdir( $handle ) ) )
264 $deleted_filenames[$filename] = '';
271 // This is a hash title->array( array( filenumber, date, filename, channel ) )
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 );
290 foreach( $sorted_fns as $filename )
292 list( $title, $date, $channel, $sub_title, $description ) = get_info(
293 $filename, $nondeleted_filenames );
297 $titles[$title][] = array( $num, $date, $channel, $sub_title,
298 $description, $filename );
308 <title
>Recorded programmes
</title
>
309 <style type
="text/css">
311 font
-family
: verdana
, sans
-serif
;
315 text
-decoration
: none
;
332 span
.smalltime
:hover
{
345 <script language
="JavaScript">
347 function makeRequest( url
, arg
)
351 if( window
.XMLHttpRequest
) // Mozilla, Safari etc.
353 httpRequest
= new XMLHttpRequest();
355 else if( window
.ActiveXObject
) // IE
359 httpRequest
= new ActiveXObject( "Msxml2.XMLHTTP" );
365 httpRequest
= new ActiveXObject( "Microsoft.XMLHTTP" );
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';
420 table_el
.style
.display
= 'inline';
425 function delete_prog( prog_filename
)
427 makeRequest( 'delete.php?filename=' + prog_filename
,
429 tr_el
= document
.getElementById( 'tr_' + prog_filename
);
430 tr_el
.style
.display
= 'none';
437 <h1
>Recorded programmes
</h1
>
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,
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 )
474 print $sub_title . " <span class='smalltime'>";
477 $dtchan = pretty_date( $date );
481 $dtchan .= " on $channel";
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";