Location: PHPKode > projects > TVEz - Media Library > tvez-0.2.1/html/shows/include.php
<?php

# ------------------------------------------------------------------------------
#
# This file contains some php helper functions
#
# ------------------------------------------------------------------------------
#
# Copyright (C) 2003 Christian Eheim and Alex Pachikov
#                                                                               
# This file is part of TVEz (tvez.sourceforge.net).
#                                                                               
# TVEz is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#                                                                               
# TVEz is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#                                                                               
# You should have received a copy of the GNU General Public License
# along with TVEz; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#                                                                               
# ------------------------------------------------------------------------------
#
# Created on 02/12/2003 by Alex Pachikov
#
# LAST MODIFIED:
# $Date: 2004/05/18 01:20:55 $
# $Revision: 1.5 $
# $Author: eheim $
#
# ------------------------------------------------------------------------------

function read_dir($dir) {  // reads the directory and returns the content
  if (is_dir($dir)) {
    $handle=opendir($dir);
    while (false !== ($file = readdir($handle))) {
        if ($file != '.' && $file != '..') {
            $retVal[count($retVal)] = $file;
        }
    }
    closedir($handle);
    if(!empty($retVal)) {
        sort($retVal);
        return $retVal;
    }
  }else{
    echo "<span class=\"error\">ERROR:</span><br><b>Can't read dir: $dir</b>";
  }
}

function table_with_header($header,$allseason,$anchors,$randomlink,$content) {
    print '
	<table cellpadding="8" cellspacing="0" border="1" class="showstable">
	';
	if ($header) print '
	 <tr>
	  <td colspan="2" align="center" valign="middle" class="showstableheader">
           '.$header.'
	   </td></tr>';
	   if ($anchors || $allseason) { 
	     print '<tr>';
	     if ($anchors) print '<td>'.$anchors.'</td>';
	     if ($allseason) print '<td align="right"> '.$allseason.'</td>';
	     print '</tr>';
	   }
	print '
	 <tr>
	  <td align="left" colspan="2" valign="top">'.$content.'</td>
	 </tr>
	 ';
	 if ($randomlink)
	 print '
	 <tr>
	  <td align="left" colspan="2" valign="top"><font size=1>'.$randomlink.'</font>
	  </td>
	 </tr>
	 ';
	 print '
	</table>
	';
}

function list_with_links($dir,$links,$what,$url) {
  global $LOGIN_ENABLED;
  $projects = read_dir($dir);
  $content = '';
  if (sizeof($projects) > 0) {
    while (list ($key, $val) = each ($projects)) {
      $newdir = "$dir/$val";
      if ($what != "file") {
        if (is_dir($newdir) && !ereg("^\.",$val)) { 
          if ($links < 1) $content .= "<li>$val";
          else $content .= "<li><a href=\"$newdir\">$val</a>";
        }
      }else{
        if (is_file($newdir) && !ereg("^\.",$val)) { 
          if ($links < 1) $content .= "<li>$val";
          else {
	    $expl = explode(" - ",$val);
	    $name = preg_replace("/\..{3,4}$/","",end($expl));
	    $filesize = round(filesize($newdir)/1024/1024);
		$enum = sizeof($expl)-2;
	    if ($url) {
		  $flink = preg_replace("/XXX/",$expl[1],$url);
		  $epilink = "[<a href=\"$flink\">$expl[$enum]</a>]&nbsp;";
	    }
		else {
		  $epilink = "[$expl[$enum]]&nbsp;";
		}
		$newdir = urlencode($newdir);
	    $content .= "<li type=\"square\">$epilink";
		if ( isset($_SESSION['tvezAccess']) || !$LOGIN_ENABLED )
			$content .= "<a href=\"../html/player/plcontrol.php?tvst=play $newdir\" target=playlist>";
		$content .= $name;
		if ( isset($_SESSION['tvezAccess']) || !$LOGIN_ENABLED )
			$content .= "</a>";
		$content .= "&nbsp;
	    <span class=\"showsize\">(".$filesize."Mb)</span>\n";
	  }
        }
      }
    }
    return $content;
  } else {
    return "No files found in $dir";
  }
}

function table_of_links($dir,$links,$what,$url) {
  global $LOGIN_ENABLED;
  $projects = read_dir($dir);
  $content = '';
  if (sizeof($projects) > 0) {
  $content = "<table width=\"100%\" cellpadding=\"3\" cellspacing=\"0\" border=\"0\">";
    while (list ($key, $val) = each ($projects)) {
      $newdir = "$dir/$val";
        if (is_file($newdir) && !ereg("^\.",$val)) { 
	  if ($key%2 == 0) $altcolor="showstabledark";
	  else $altcolor="showstablelight";
	  $content .= "<tr class=\"$altcolor\">";
#	  $content .= "<td>".($key+1)."</td>";
	  $content .= "<td>";
          if ($links < 1) $content .= "$val";
          else {
	    $expl = explode(" - ",$val);
	    $name = preg_replace("/\..{3,4}$/","",end($expl));
	    $filesize = round(filesize($newdir)/1024/1024);
		$enum = sizeof($expl)-2;
	    if ($url) {
		  $flink = preg_replace("/XXX/",$expl[1],$url);
		  $epilink = "[<a href=\"$flink\">$expl[$enum]</a>]&nbsp;";
	    }
		else {
		  $epilink = "$expl[$enum]&nbsp;";
		}
		$newdir = urlencode($newdir);
	    $content .= "$epilink</td><td>";
		if ( isset($_SESSION['tvezAccess']) || !$LOGIN_ENABLED )
	    	$content .= "<a href=\"../html/player/plcontrol.php?tvst=play $newdir\" target=playlist>";
	    $content .= $name;
		if ( isset($_SESSION['tvezAccess']) || !$LOGIN_ENABLED )
			$content .= "</a>";
		$content .= "</td><td align=\"right\">
	    <span class=\"showsize\">(".$filesize."Mb)</span>\n";
	  }
	  $content .= "</td></tr>";
        }
    }
    $content .= "</table>";
    return $content;
  } else {
    return "No files found in $dir";
  }
}

function build_table($season,$dir,$num,$total,$url,$anc) {
  global $LOGIN_ENABLED;
  print "<a name=$num></a>";
  if ($anc) $anchorhtml = build_anchors($num,$total);
  else $anchorhtml = '';
#  $content = list_with_links($dir,1,file,$url);
  $content = table_of_links($dir,1,file,$url);
  $dir = urlencode($dir);
  if ( isset($_SESSION['tvezAccess']) || !$LOGIN_ENABLED )
	  $allseason = '<a href="../html/player/plcontrol.php?tvst=play '.$dir.'/*" target=playlist>Play All</a>';
  else $allseason = "";
  $randomlink = "";
  table_with_header($season, $allseason, $anchorhtml, $randomlink, $content);
  print '<br>';
}

function build_anchors($on,$total) {
 $anchors = "";
 $g = 0;
 if ($total > 1) {
   for ($g = 1 ; $g <= $total; $g++ ) {
     if ($g != $on)  $anchors .= " <a href=\"#$g\">$g</a> ";
     else $anchors .= " <b>$g</b> ";
   }
 }
 return $anchors;
}

function read_file($show,$type) {
  if (is_file("shows/".$show.".".$type)) {
    @readfile("shows/".$show.".".$type);
  }elseif (is_file("shows/default.".$type)) {
    @readfile("shows/default.".$type);
  }else{
    print "<p class=\"error\">No file: $show.$type or default.$type</p>";
  }
}

?>
Return current item: TVEz - Media Library