\n"; foreach ($shows as $show => $seasons) { echo '
' . htmlspecialchars($show) . "
\n"; foreach ($seasons as $season => $monitored) { echo '
Season ' . htmlspecialchars($season); if ($monitored) { echo ' (monitored)'; } echo "
\n"; } } echo "\n"; } function findWebloc($path) { $retval = false; $dir = opendir($path); if ($dir === FALSE) { die('Unable to opendir(): ' . htmlspecialchars($path) . "\n"); } while (false !== ($name = readdir($dir))) { # Skip junk if (isJunk($name)) { continue; } # We only care about *.webloc files if (!preg_match('/\.webloc$/', $name)) { continue; } # The file must be readable to be useful $file = $path . '/' . $name; if (is_readable($file)) { $retval = $file; last; } } closedir($dir); return $retval; } function readWebloc($file) { global $TVDB_URL; $retval = array( 'tvdb-id' => false, 'tvdb-lid' => false, 'url' => false, ); # Read and parse the file $str = trim(file_get_contents($file)); if (preg_match('/[\?\&]id=(\d+)/', $str, $matches)) { $retval['tvdb-id'] = $matches[1]; } if (preg_match('/[\?\&]lid=(\d+)/', $str, $matches)) { $retval['tvdb-lid'] = $matches[1]; } # Construct a URL if ($retval['tvdb-id'] !== false) { $retval['url'] = $TVDB_URL . '&id=' . $retval['tvdb-id']; if ($retval['tvdb-lid'] !== false) { $retval['url'] .= '&lid=' . $retval['tvdb-lid']; } } return $retval; } function readFlags($path) { global $EXISTS_FILES; global $CONTENT_FILES; $flags = array(); # Look for all the exists files foreach ($EXISTS_FILES as $name) { $flags[ $name ] = false; if (file_exists($path . '/' . $name)) { $flags[ $name ] = true; } } # Read all the content files foreach ($CONTENT_FILES as $name) { $flags[ $name ] = false; $file = $path . '/' . $name; if (is_readable($file)) { $flags[ $name ] = trim(file_get_contents($file)); } } # Read the TVDB IDs from the *.webloc file $webloc = findWebloc($path); if ($webloc !== false) { $flags = array_merge($flags, readWebloc($webloc)); } return $flags; } function printShow($show) { global $TV_PATH; global $EXISTS_FILES; global $CONTENT_FILES; # Construct our show path and make sure it's reasonable $path = $TV_PATH . '/' . $show; if (!is_dir($path)) { die('Unknown show: ' . htmlspecialchars($show)); } # Check the flags $flags = readFlags($path); # Check the seasons $seasons = findSeasons($path); # Header echo '

' . htmlspecialchars($show) . '

'; echo '
'; # Exists and content flags echo '

Search Parameters

'; echo '

'; foreach ($EXISTS_FILES as $file) { echo '
'; } foreach ($CONTENT_FILES as $file) { echo '
'; } echo '

'; # TVDB URL echo '

The TVDB

'; echo '

' . htmlspecialchars($flags['url']) . '

'; # Seasons echo '

Seasons

'; echo '

'; foreach ($seasons as $season => $monitored) { echo '
'; } echo '

'; # Footer echo '
'; } #========================================================================================= # Send our headers early header('Content-type: text/html; charset=utf-8'); # Did the user request a specific show? $show = false; if (isset($_REQUEST['show'])) { # This is not a great filter, but it should make the string safe for use as a quoted path $show = preg_replace('/[\0\n\r]/', '', $_REQUEST['show']); $show = basename($show); } #========================================================================================= # Generic XHTML 1.1 header print << UberZach TV ENDOLA; if ($show === false) { printAllShows(); } else { printShow($show); } # Generic XHTML 1.1 footer print << ENDOLA; ?>