                    
<?php
//-->-->-->-->-->-->-->-->
//-- Description:
//--   The purpose of this function is to transform a 'string' of text
//--   into some kind of meaningful HTML. The 'string' is considered to
//--   be a 'message' which one of the PHP scripts is echo-ing to the 
//--   requesting client. The text may contain special codes or 'structures'
//--   which indicate to this transformation script the way in which the
//--   text should be formatted in the HTML result. For example if a word
//--   begins with the text 'http://' then it will be made into an HTML
//--   hyperlink, which will transport the clicker to the target URL or 
//--   web-page. Or, if the line begins with an equals sign '=' then that
//--   line will be made into an HTML level 1 heading, which will appear
//--   very large and bold in the resulting web-page.
//--
//--
//-- Notes:
//--   I created this function by basically copying the function
//--   fnDocumentToHtml. fnFaqToHtml, fnJournalToHtml are also very 
//--   similar to the present function.
//--
//-- History:
//--
//-- Dependencies:
//--   This dependency list is not particularly reliable. It should be
//--   generated automatically I suppose. At the moment, it is maintained
//--   by hand.
//--
//--   fnHyperlinkPlainText
//--   fnReduplicateCharacters
//--   fnUnduplicateCharacters
//--   fnCodeBlockToHtml
//--   fnCodeBlockFromHtml
//--   fnListBlockToHtml
//--
//-- See Also:
//--
//--   fnHyperlinkPlainText.php 
//--     has explanations as to what sort of 
//--     plain text structures will be hyperlinked. 
//--
//-- 
//--   retrovox-notepad.php    
//--     A script to allow editing of files located on a server using a web
//--     browser.
//--   webpad.php
//--     A script to allow editing of 'documents' which are located on 
//--     a server running PHP and probably the Apache web-server. While
//--     the 'retrovox-notepad.php' script is designed to edit any file on
//--     the server, the 'webpad.php' script is only able to edit a small
//--     subsection of the files on the server, namely, those files which
//--     are considered to be 'documents' or 'webpages'.
//--
//-- Author:
//--   matth3wbishop@yahoo.com
//--   http://www.geocities.com/matth3wbishop/
//--

include_once "fnHtmlCommonTransforms.php";
include_once "fnHtmlCommonTransformsMore.php";
include_once "fnSpecialLinkPlainText.php";

function fnMessageToHtml($sPlainText, $sFilePath = '')
{
  $sReturn = $sPlainText;

  $sReturn = fnHtmlCommonTransforms($sReturn);

  //-- Make the title into a first level heading  
  $sReturn = 
    preg_replace("#^[ ]*=(.*)#m", "<center><h1>$1</h1></center><dl>", $sReturn);

  $sHeadings = $sReturn;

  $sHeadings = 
     preg_replace("#^[ \t]*#m", "", $sHeadings);

  $sHeadings = 
     preg_replace('#^[^\*].*$#im', '', $sHeadings);

  $sHeadings = 
     preg_replace("#\n\s*\n#m", "\n", $sHeadings);

  //-- Get rid of the leading 'star' characters for each of the questions
  $sHeadings = 
     preg_replace("#^\s*\*\s*#m", "", $sHeadings);

  $sHeadings = 
     preg_replace("#\s*$#m", "", $sHeadings);

  if ($sHeadings != "")
  {
    $sHeadings = 
      preg_replace("#^(.*)$#m", "<li><a href = '#$1'>$1</a>" , $sHeadings);

    $sHeadings = 
      "<a name = 'toc'></a><br><ol type = '1'>".$sHeadings."</ol>";
  }
  //echo "<pre>[$sHeadings]</pre>";
  //echo $sHeadings;
  $sReturn = preg_replace(
      "#^\s*\*\s*([^\n\r]*)#m", 
      "<dt><h4><a name = '$1'>$1</a>&nbsp;<a href = '#toc'>[toc]</a></h4></dt><dd>", 
      $sReturn);

  $sReturn = $sHeadings."\n".$sReturn;

  $sReturn = fnHyperlinkPlainText($sReturn);
  $sReturn = fnSpeciallinkPlainText($sReturn, $sFilePath);


  /*
  //-- Make a tab into 2 HTML spaces
  $sReturn = preg_replace("#\t#im", "&nbsp;&nbsp;", $sReturn);


  //-- get rid of the [*faq*] meta-tag which is used to tell the transformation
  //-- system that the current document should be transformed according to the 
  //-- rules for a journal for an faq style document.

  //-- This </dl> rubbish is a terrible hack. It is assuming that 
  //-- the faq flag occurs right at the end of the document and that
  //-- there is some kind of definition list in the doc. Very ugly.
  $sReturn = preg_replace("#^\s*\[\*faq\*\]\s*$#im", "</dl>", $sReturn);

  */
  
  $sReturn = fnHtmlCommonTransformsMore($sReturn);

  $sReturn = 
    preg_replace(
         "#<pre>((.|\n)*?)</pre>#ime", 
         "'<pre>'.fnCodeBlockFromHtml('$1').'</pre>'", $sReturn);

  return $sReturn;
} //-- function fnDocumentToHtml 
     

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