#!/usr/bin/perl

# THIS IS A SCRIPT I WROTE TO TAKE THE OLD PERL FILE AND CONVERT MOST OF IT
# TO PHP FORMAT

$file = $ARGV[0];
$newfile = $ARGV[1];

  open(PHP, ">$newfile");
  print PHP "<?
// ------------------------------------------------------------------------
// WWWThreads - PHP
// Wired Community Software
// Rick Baker (rbaker\@wcsoft.net)
// (c) Copyright 1999-2000
// ------------------------------------------------------------------------

// Require the library
   require (\"../main.inc.php\");

// -----------------
// Get the user info
   \$Username = \$w3t_myname;
   \$Password = \$w3t_mypass;
   \$userob = new user;
   \$user = \$userob -> authenticate(\"\$Username\",\"\$Password\",\"U_Username, U_Password\");
   \$html = new html;

// -----------------------------
// Make sure they should be here
   if ( (\$user[U_Status] != 'Moderator') && (\$user[U_Status] != 'Administrator')){
      \$html -> not_right (\"You must be logged in, and be a valid administrator or moderator to access this.\",\$Cat);
   }

";
 
  open(FILE,"$file");
  while (<FILE>) {
    if ($_ =~/^1/) { next; }
    $_ =~s/{'/\[/igs;
    $_ =~s/'}/\]/igs;
    $_ =~s/cgiurl/phpurl/igs;
    $_ =~s/\.pl/\.php/igs;
    $_ =~s/#/\/\//igs;
    $_ =~s/w3t::/\$html -> /igs;
    $_ =~s/\$dbh -> quote/addslashes/igs;
    $_ =~s/print/echo/igs;
    $_ =~s/user\[/user\[U_/igs;
    $_ =~s/my / /igs;
    $_ =~s/\$sth -> fetchrow_array/\$dbh -> fetch_array(\$sth)/igs;
    $_ =~s/qq!/"/igs;
    $_ =~s/!;/";/igs;
    $_ =~s/qq\~/"/igs;
    $_ =~s/\~;/";/igs;
    $_ =~s/\%user/\$user/igs;


    print PHP "$_";
  }
  print PHP "\n?>";
  close(FILE);
  close(PHP);