                                                                                    

<?php
//-->-->-->-->-->-->-->-->-->-->-->-->-->-->
//--Description:
//--  The purpose of this script is to return the 'source' of a file, and
//--  in particular, PHP files or any other file which would otherwise be
//--  pre-processed by the web-server. This current script is important
//--  because I am envisioning an 'across-the-web' or internet-oriented
//--  system installation proceedure. This proceedure would involve a set-up
//--  or installation script querying another installation for all the 
//--  required files to set up a new installation of this system.
//--
//--  This would involve first obtaining a list of files in each of the 
//--  main areas of the system, such as; library functions, management scripts,
//--  the notepad files, and the webpad files, and also system documentation
//--  and configuration files.
//--
//--  Once these lists were obtained then this 'get-source.php' script would
//--  be able to be employed to serve each of the required files, one at
//--  a time. This proceedure obviates the need to have unzipping software
//--  available on the server, even if this software is quite common.
//--
//--See Also:
//--  
//--
//--
  include "/home/waggacwc/public_html/refurb/RETRO-GLOBALS.php";

  include "$LIBRARYPATH/RETROVOX-CONSTANT-VARIABLES.php";
  include "$LIBRARYPATH/fnRetrovoxStartHtml.php";
  include "$LIBRARYPATH/fnRetrovoxEndHtml.php";
  include "$LIBRARYPATH/fnRetrovoxDirectoryListing.php";

  include "$LIBRARYPATH/fnFillWebTemplate.php";
  include "$LIBRARYPATH/fnMessageToHtml.php";
  include "$LIBRARYPATH/fnCodeBlockToHtml.php";
  include "$LIBRARYPATH/fnCodeBlockFromHtml.php";
  include "$LIBRARYPATH/fnListBlockToHtml.php";

  include "$LIBRARYPATH/fnHyperlinkPlainText.php";

  $sWebDocumentRoot = "$WEBROOT";
  $sFilePath = '';

  $sFilePath = stripslashes($_GET['file']);
  $sFilePathEncoded = htmlspecialchars($sFilePath);

  
  if ($sFilePath == '')
  {

    $sPageTitle = "Get File Source: no file name specified";
    $sPageContent = "
          = Get File Source: No File Name Specified

      You did not specify any files


      ";

    $sPageContent = fnMessageToHtml($sPageContent);
    $sErrorPage = fnFillWebTemplate(
      $sErrorTemplateContents, $sPageContent, $sPageTitle);   
    echo $sErrorPage;

    exit; 

  } //-- if no file specified
 
  
  
  if (!file_exists($sFilePath))
  {
    if (file_exists($WEBROOT.$sFilePath))
    {
      $sFilePath = $WEBROOT.$sFilePath;
    }
    elseif (file_exists($WEBROOT."/".$sFilePath))
    {
      $sFilePath = $WEBROOT."/".$sFilePath;
    }
    else
    {
      $sPageTitle = "Get File Source: the file doesn't exist";
      $sPageContent = "
            = Get File Source: the file doesn't exist

        The file-name [$sFilePathEncoded] which you just specified does
        not exist.
           ";

      $sPageContent = fnMessageToHtml($sPageContent);
      $sErrorPage = fnFillWebTemplate(
        $sErrorTemplateContents, $sPageContent, $sPageTitle);   
      echo $sErrorPage;

      exit; 
    }	  
  } //-- if file doesnt exist

  if (is_dir($sFilePath))
  {
    if (substr($sFilePath, -1) != "/")
    {
      $sFilePath = "$sFilePath/";
    }
    
    $sPageTitle = "the file is a directory";
    $sPageContent = "
           = the file is a directory

      The file-name [$sFilePathEncoded] which you just specified is a 
      directory (folder). 

       ";

    $sPageContent = 
      fnMessageToHtml($sPageContent).fnDirectoryListing($sFilePath, true);

    $sErrorPage = fnFillWebTemplate(
      $sErrorTemplateContents, $sPageContent, $sPageTitle);   
    echo $sErrorPage;
      
    exit;
  } //-- if file is a directory


  $sWebFilePathEncoded = 
    htmlspecialchars(
      str_replace("$sWebDocumentRoot", "", $sFilePath));


//--<--<--<--<--<--<--<--<--<--<--<--<--<--<
?>


<?php
//-->-->-->-->-->-->-->-->-->-->-->-->-->-->
  $ii = 0;
  $aaFileLines = file($sFilePath);
  echo "<pre>";
  foreach ($aaFileLines as $sLine)
  {
    echo "$ii: ".htmlspecialchars($sLine);
    $ii++;
  }
  echo "</pre>";
//--<--<--<--<--<--<--<--<--<--<--<--<--<--<
?>



                                                                                    