Skip to content
This repository has been archived by the owner on Mar 14, 2021. It is now read-only.

Commit

Permalink
changed: file reading functions to use fgets instead of file(), filez…
Browse files Browse the repository at this point in the history
…illa filters.xml output now named correctly
  • Loading branch information
sairuk committed May 1, 2010
1 parent ca64b87 commit a4ba11d
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 193 deletions.
327 changes: 139 additions & 188 deletions php/listgen/includes/functions.php
Expand Up @@ -3,35 +3,133 @@
# Global Variables
global $modname, $fixfile, $ext, $name, $outfile, $xmlhndl, $rompath, $sessionID, $maxviewbytes;

# If page is reloaded from form with ext passed
# populate $ext
if (isset($_POST['rompath']))
{
# Set $ext to combo data
$ext = ".".$_POST['ext'];
} else if ($_POST['ext'] == "custom" ) {

# Set $ext to form data
$ext = ".".$_POST['custext'];
} else {
# Clear $ext
$ext = "";
}
# If page is reloaded from form with ext passed populate $ext
if (isset($_POST['rompath'])) { $ext = ".".$_POST['ext']; #Set $ext to combo data
} else if ($_POST['ext'] == "custom" ) { $ext = ".".$_POST['custext']; #Set $ext to form data
} else { $ext = ""; } #Clear $ext

# Initialise Session Information
session_start();
$sessionID = session_id();
session_start();$sessionID = session_id();


# If page is reloaded from form with rompath passed
# strip slashes from the path and print path to the
# screen
if (isset($_POST['rompath']))
{
$rompath = stripslashes($_POST['rompath']);
print $rompath;
if (isset($_POST['rompath'])) { $rompath = stripslashes($_POST['rompath']); }

/*
* switchOutput
*
* adds in output format data
*/
function switchOutput($pstQueue) {

global $fixfile, $name, $modname, $outurl;

$name = substr($fixfile,0,strlen($fixfile)-4);

# For Debugging
#$pstQueue = "test";

# Outputs
switch ($pstQueue) {
case filezilla:
require(DOCROOT.'/outputs/filezilla.php');break;
case wget:
require(DOCROOT.'/outputs/wget.php');break;
case msbat:
require(DOCROOT.'/outputs/msbat.php');break;
case CRCmsbat:
require(DOCROOT.'/outputs/msbat-crc.php');break;
case msbatnumbered:
require(DOCROOT.'/outputs/msbat-numbered.php');break;
case bash:
require(DOCROOT.'/outputs/bash.php');break;
case google:
$modname = 'Google Search';
$outurl = "http://www.google.com.au/search?q=";
require(DOCROOT.'/outputs/html_generic.php');break;
case ebay:
$modname = 'Ebay Search';
$outurl = "http://shop.ebay.com/?_nkw=";
require(DOCROOT.'/outputs/html_generic.php');break;
case ebayau:
$modname = "Ebay Australia Search";
$outurl = "http://shop.ebay.com.au/?_nkw=";
require(DOCROOT.'/outputs/html_generic.php');break;
case binsearch:
$modname = "binsearch.info";
$outurl = "http://www.binsearch.info/?q=";
require(DOCROOT.'/outputs/html_generic.php');
case easynews:
$modname = "EasyNews Global Search";
$outurl = "http://members.easynews.com/global4/search.html?gps=";
require(DOCROOT.'/outputs/html_generic.php');break;
case htmlall:
require(DOCROOT.'/outputs/html_all.php');break;
case mamewah:
require(DOCROOT.'/outputs/mamewah.php');break;
case mamewah168:
require(DOCROOT.'/outputs/mamewah168.php');break;
case mGalaxy:
require(DOCROOT.'/outputs/mgalaxy.php');break;
case xbmclauncher:
require(DOCROOT.'/outputs/xbmc-launcher.php');break;
case test:
require(DOCROOT.'/outputs/test_mamewah168.php');break;
default:
echo "Nothing to do here either jim";
}

}

/*
* Process all files after upload
* Checks type of file then calls genFunction()
*/
function process_upload($tmpfile) {

global $fixfile, $sessionID;
$uploaddir = UPLOADPATH .'/'. $sessionID .'/' ;

# Make the users upload path if it doesnt exist
if (!is_dir($uploaddir)) {mkdir($uploaddir);chmod($uploaddir, 0777);}

# Set upload information and move uploaded file
$uploadfname = basename($_FILES['fixfile']['name']);
$uploadfile = $uploaddir . $uploadfname;
if (move_uploaded_file($_FILES['fixfile']['tmp_name'], $uploadfile)) {
$fixfile = $uploaddir . $uploadfname;

# Read in 4 lines from file to establish type
$handle = @fopen($fixfile, "r");
if ($handle) {
$HDR0 = fread($handle, 512);
fclose($handle);
}
# Check if it is a binary file
if (substr_count($HDR0, "\x00") > 0 ) {
echo "<b>You uploaded a binary file!</b><br /> Please only upload ascii files.";
exit;
}
if ( preg_match('/You are Missing|You Have/i',$HDR0) ) { #Valid GoodTools File
genFunction("goodtxt","2","Recognised GoodTools style Miss/Have Text");exit;
} elseif ( preg_match('/clrmamepro \(/i',$HDR0 )) { #Valid CMPRO DAT File
genFunction("cmprodat","2","Recognised CMPro DAT");exit;
} elseif ( preg_match('/DOCTYPE mame/',$HDR0) ) { #Valid MAME XML
if ( ! ini_get('memory_limit') < 256 ) {
genFunction("mamexml","85","Recognised MAME XML");
} else { echo "<b><i> - (Not Support on this Server)</i></b>";break; }
$exit;
} elseif ( preg_match('/CREDITS/',$HDR0) ) { #Valid Rommanger
genFunction("rommanager","9","Recognised Rommanager Dat");exit;
} elseif ( preg_match('/datafile/',$HDR0) ) { #Valid CMPRO XML Fixdat
genFunction("cmproxml","0","Recognised CMPro/RC3 XML");exit;
} else { #File Not Recognised, treating as generic listing
genFunction("generic","0","File Not Recognised, treating as generic listing");exit;
}
}
}

/*
* General Function, used to process all files
Expand All @@ -49,30 +147,35 @@ function genFunction($inType,$skiplines,$fTypeTitle) {

$build = "Current";
$i = "0";

# Clean up the name of the file
cleanSessionID($outfile);
$name = $csIDstr;

if (file_exists($fixfile) && is_readable ($fixfile)) {

$outfile = UPLOADPATH .'/'. $sessionID .'/'. $outfile;

print $fTypeTitle."<br />";

# File write header, open file for writing
@unlink($outfile);
$xmlhndl = @fopen($outfile,"w");
writeout_header();

$lines = file($fixfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ( $lines as $line ) {
$line = trim($line,"\r\n");
$i++;
$xmlhndl = @fopen($outfile,"a");
# File write content, open file for append
$xmlhndl = @fopen($outfile,"a");

#$lines = file($fixfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$handle = @fopen($fixfile, "r");
if ($handle) {
while(!feof($handle)) {
$line = fgets($handle);
$line = trim($line,"\r\n");
$i++;

# Custom Items Start Here
switch ($inType) {
# Cowering's Goodtools Have/Miss Text Format
case goodtxt:
# Get version number of set
# Get version number of set for $build
if (preg_match('/ROMS \(V.*\)/',$line)) {
$stringlen = strrpos($line,")");
$stringpos = strpos($line,"(")+1;
Expand Down Expand Up @@ -150,17 +253,17 @@ function genFunction($inType,$skiplines,$fTypeTitle) {
default:
echo "Nothing to do here either jim";
}

}

}
fclose($handle);
}

# File write footer, open file for append
$xmlhndl = @fopen($outfile,"a");
#$xmlhndl = @fopen($outfile,"a");
writeout_footer();
}
}

if (file_exists($fixfile)) {
unlink($fixfile);
}
if (file_exists($fixfile)) { unlink($fixfile); }
}

function build_itemArray($type = "0",$condition = "1",$value,$cloneof,$romof,$ext,$description,$manufucturer,$rom,$size,$crc32,$md5,$sha1,$build) {
Expand Down Expand Up @@ -229,82 +332,6 @@ function read_mamexml($skiplines)
}
}

/*
* Process all files after upload
* Checks type of file then calls genFunction()
*/
function process_upload($tmpfile) {

global $fixfile, $sessionID;

$uploaddir = UPLOADPATH .'/'. $sessionID .'/' ;

if (!is_dir($uploaddir)) {
mkdir($uploaddir);
chmod($uploaddir, 0777);
}

$uploadfname = basename($_FILES['fixfile']['name']);
$uploadfile = $uploaddir . $uploadfname;
if (move_uploaded_file($_FILES['fixfile']['tmp_name'], $uploadfile)) {
$fixfile = $uploaddir . $uploadfname;

# Check if it is a binary file
$testBIN = fopen($fixfile, "r");
$blk = fread($testBIN, 512);
fclose($testBIN);
if (substr_count($blk, "\x00") > 0 ) {
echo "<b>You uploaded a binary file!</b><br /> Please only upload ascii files.";
exit;
}

$i = 0;
$lines = file($fixfile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ( $lines as $line ) {
$i++;
# Use first 4 lines to determine filetype
if ($i <= "4") {
if ($i == "1") { $HDR1 = $line; }
if ($i == "2") { $HDR2 = $line; }
if ($i == "3") { $HDR3 = $line; }
if ($i == "4") { $HDR4 = $line; }
} else {
$HDR0 = $HDR1.$HDR2.$HDR3.$HDR4;
if ( preg_match('/You are Missing|You Have/i',$HDR0) ) {
# Valid GoodTools File
genFunction("goodtxt","2","Recognised GoodTools style Miss/Have Text");
exit;
} elseif ( preg_match('/clrmamepro \(/i',$HDR0 )) {
# Valid CMPRO DAT File
genFunction("cmprodat","2","Recognised CMPro DAT");
exit;
} elseif ( preg_match('/DOCTYPE mame/',$HDR0) ) {
# Valid MAME XML
if ( ! ini_get('memory_limit') < 128 ) {
genFunction("mamexml","85","Recognised MAME XML");
} else {
echo "<b><i> - (Not Support on this Server)</i></b>";
break;
}
exit;
} elseif ( preg_match('/CREDITS/',$HDR0) ) {
# Valid Rommanger
genFunction("rommanager","9","Recognised Rommanager Dat");
exit;
} elseif ( preg_match('/datafile/',$HDR0) ) {
# Valid CMPRO XML Fixdat
genFunction("cmproxml","0","Recognised CMPro/RC3 XML");
exit;
} else {
# File Not Recognised, treating as generic listing
genFunction("generic","0","File Not Recognised, treating as generic listing");
exit;
}
}
}

}
}
/*
* create_link()
*
Expand Down Expand Up @@ -337,83 +364,7 @@ function create_link($zipfile) {
}
}

function switchOutput($pstQueue) {

global $fixfile, $name, $modname, $outurl;

$name = substr($fixfile,0,strlen($fixfile)-4);

# For Debugging
#$pstQueue = "test";

# Outputs
switch ($pstQueue) {
case filezilla:
require(DOCROOT.'/outputs/filezilla.php');
break;
case wget:
require(DOCROOT.'/outputs/wget.php');
break;
case msbat:
require(DOCROOT.'/outputs/msbat.php');
break;
case CRCmsbat:
require(DOCROOT.'/outputs/msbat-crc.php');
break;
case msbatnumbered:
require(DOCROOT.'/outputs/msbat-numbered.php');
break;
case bash:
require(DOCROOT.'/outputs/bash.php');
break;
case google:
$modname = 'Google Search';
$outurl = "http://www.google.com.au/search?q=";
require(DOCROOT.'/outputs/html_generic.php');
break;
case ebay:
$modname = 'Ebay Search';
$outurl = "http://shop.ebay.com/?_nkw=";
require(DOCROOT.'/outputs/html_generic.php');
break;
case ebayau:
$modname = "Ebay Australia Search";
$outurl = "http://shop.ebay.com.au/?_nkw=";
require(DOCROOT.'/outputs/html_generic.php');
break;
case binsearch:
$modname = "binsearch.info";
$outurl = "http://www.binsearch.info/?q=";
require(DOCROOT.'/outputs/html_generic.php');
break;
case easynews:
$modname = "EasyNews Global Search";
$outurl = "http://members.easynews.com/global4/search.html?gps=";
require(DOCROOT.'/outputs/html_generic.php');
break;
case htmlall:
require(DOCROOT.'/outputs/html_all.php');
break;
case mamewah:
require(DOCROOT.'/outputs/mamewah.php');
break;
case mamewah168:
require(DOCROOT.'/outputs/mamewah168.php');
break;
case mGalaxy:
require(DOCROOT.'/outputs/mgalaxy.php');
break;
case xbmclauncher:
require(DOCROOT.'/outputs/xbmc-launcher.php');
break;
case test:
require(DOCROOT.'/outputs/test_mamewah168.php');
break;
default:
echo "Nothing to do here either jim";
}

}

function cleanSessionID($string) {
global $sessionID, $csIDstr;
Expand Down

0 comments on commit a4ba11d

Please sign in to comment.