Location: PHPKode > projects > TVEz - Media Library > tvez-0.2.1/demo/socket.php
<?php

# ------------------------------------------------------------------------------
#
# This file contains the _FAKE_ socket php code
# to be used for the online demo
#
# ------------------------------------------------------------------------------
#
# 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 12/07/2003 by Christian Eheim
#
# LAST MODIFIED:
# $Date: 2004/01/11 23:20:27 $
# $Revision: 1.1.1.1 $
# $Author: eheim $
#
# ------------------------------------------------------------------------------

function send_command($command) {
	require "../config/config_file.php";

	$fakePlaylist = "mypl.inc";
	require $fakePlaylist;

	$command = chop($command);
	list($cmd,$what) = split(" ",$command,2);

	$lines = "";
	$out = "";
	$count = 0;
	$fcount = 0;
	if (isset($mfile) )
	# Create the playlist list from the files in the fake playlist file
	foreach ($mfile as $value) {
		if ($cmd == "delete" && $what == $count) ;
		# If we have a delete don't add this file to the new playlist
		else {
			$lines .= "$value\n";
			$out .= "\$mfile[$fcount] = \"$value\";\n";
			$fcount++;
		}
		$count++;
	}
	else $lines = "empty playlist";

	# Play command
	if ($cmd == "play") {
		# Play the entire season
		if ( preg_match("/\*$/", $what) ) {
			$dir = preg_replace("/\*$/", "", $what);
			// Open the directory, and proceed to read its contents
			if (is_dir($dir)) {
				if ($dh = opendir($dir)) {
				while (($file = readdir($dh)) !== false) {
					if (!preg_match("/^\./", $file)) {
						$out .= "\$mfile[$fcount] = \"$file\";\n";
						$fcount++;
					}
				}
				closedir($dh);
				}
			}
		}
		# Play just one file
		else {
			$out .= "\$mfile[$fcount] = \"$what\";\n";
		}
	}
	# Clear the playlist
	else if ($cmd == "clear") {
		$out = "";
	}

	# If we had a delete, clear, or play command, write the playlist file
	if ($cmd == "delete" || $cmd == "play" || $cmd == "clear") {
		$fp = fopen($fakePlaylist, "w");
			if ($fp) {
				fwrite($fp, "<?php\n");
				fwrite($fp, $out);
				fwrite($fp, "?>");
				fclose($fp);
		}
	}
	return array($errno,$lines);

}

?>
Return current item: TVEz - Media Library