File:  [mozdev] / cdn / www / annotate.html
Revision 1.45: download - view: text, annotated - select for diffs - revision graph
Tue Mar 25 09:56:17 2003 UTC (14 years, 6 months ago) by cdn
Branches: MAIN
CVS tags: HEAD
!

<?php

$post_to_list = 0;

// $Id: annotate.html,v 1.45 2003/03/25 09:56:17 cdn Exp $

function cleanse ($message, $name = false) {

// censor before sending to author/NG

   if ( ! $name )
   {
     $message = str_replace("\r\n", "[r[n ", $message); // kludge around
   }

   $message = ' ' . $message;
   $replacements = array('"', "'", '*', '#', '&', '$', '', '?', '%', '@', '+', 'X', 'x', );
   srand ((float)microtime()*1000000);
   shuffle($replacements);

   $cursed = array("m[0ou]th[3e]r[\ ]?f[cu]+[c]?k[3e]r",
                   "f[\ \.]*[cu]+[\ \.]*[c]?[\ \.]*k",
                   "[4a]+[5s$]+[5s$]hole",
                   "[ck]unt",
                   "pu[5s]+[5s]y",
                   "c[o0]ck",
                   "tw[4a]t",
                   "cl[1i]t",
                   "s[\ \.]*h[\ \.]*[1i]+[\ \.]*t[\ \.]*[e]?",
                   "b[1!i]tch",
                   "cum", // not strictly an obscenity
                  );

  // too indiscriminant /Documents goes to /Do*#&amp;$%ents

  for ($i=0; $cursed[$i] != ''; $i++) {

    // whitespace, however currently turns '\n' to ' '
    $cursed[$i] = '[\ ]+' . $cursed[$i];

    shuffle($replacements);
    $repstring = $replacements[0] . $replacements[2] . $replacements[5] .
                 $replacements[1] . $replacements[3];

    if ($i == 0)
      // might as well educate the miscreants
      $message = eregi_replace($cursed[0], ' oedipus', $message);
    else if ($i == 1)
      $message = eregi_replace($cursed[1], ' frell', $message);
    else
      $message = eregi_replace($cursed[$i], ' ' . $repstring, $message);
  }

  $message = substr($message, 1);

  $message = stripslashes($message);

  if ( ! $name )
  {

    $message = str_replace("[r[n ", "\r\n", $message); // losing \r\n to [\ ] or [[:space:]]

  }

  return $message;

}


function findBugs($text)
{

// find and 'linkify' mozdev bug references in posts
//
// Initial version, only places links into html, mail and NG miss out : )

// bug[\ ]?[#%]?[0-9]{1,}
// bug 2345
// bug #2345
// bug %2345 -> http://mozdev.org/bugs/show_bug.cgi?id=2345

  $text = eregi_replace("(bug[\ ]+[#%]?[0-9]{1,})",
                              "<a href=\"\\1\">\\1</a>",$text);

  $text = eregi_replace('"bug[\ ]+[#%]?', '"http://' . HOST . '/bugs/show_bug.cgi?id=', $text);

  return $text;

}


function slash($_page)
{

// if no leading slash - add one

  if ( !ereg('^/', $_page) )
  {
    return '/';
  }

}


function findComments($text)
{

// find and 'linkify' mozdev comment references in posts
//
// Initial version, only places links into html, mail and NG miss out : )

// comment[\ ]?[#%]?[0-9]{1,}
// comment 2345
// comment #2345
// comment %2345 -> http://PROJECT.mozdev.org/PAGE#2345

  $text = eregi_replace("(comment[\ ]+[#%]?[0-9]{1,})",
                              "<a href=\"\\1\">\\1</a>",$text);

  $text = eregi_replace('"comment[\ ]+[#%]?', '"' . THIS_PAGE, $text);

  return $text;

}


function findLinks($text)
{

// find and 'linkify' links

  $text    = eregi_replace("((http|https|ftp):\/\/[^[:space:]<>]{1,})",
                           "<a href=\"\\1\">\\1</a>",$text);
/*

  find name@host.tld, where no mailto:

$regExp = "^[\+\&_\.0-9a-z-]+@([0-9a-z]+-*[0-9a-z]+[^-]*[.]?)+([a-z]{2,4}[.]?$)";

  eregi_replace $regExp, mailto:$regExp

*/

  $text    = eregi_replace("(mailto:[^[:space:]<>]{1,})",
                           "<a href=\"\\1\">\\1</a>",$text);

// tidy email references
  $text = str_replace('>mailto:', '>', $text);

  return $text;

}


function htmlise($text)
{

  $text = htmlspecialchars(str_replace("\\", "", $text));

  $text = findLinks($text);

  $text = findBugs($text);

  $text = findComments($text);

  $text = ereg_replace("\r\n\r\n", "\n<p/>", $text);

  $text = ereg_replace("\r\n", "\n<br/>", $text);


  return $text;
}

?><!-- ********************* START NOTES ******************** -->

<div id="NOTESheader"><a name="NOTES"><strong>User Notes:</strong></a> <a href="http://<?php echo HOST; ?>/docs/notes.html">[?]</a></div>

<div id="NOTESnotes"><acronym class="cdn" title="HyperText Markup Language">HTML</acronym> is not allowed in posts.<br/>
<acronym class="cdn" title="Uniform Resource Locator">URL</acronym>s in the text that use mailto:, https://, http:// and ftp:// will be converted into hyperlinks.</div>

<p id="NOTESdisclaimer">If you do not get a response to a question posted in this forum, please try sending a message to the project's <a href="http://www.<?php echo HOST; ?>/mailman/listinfo/<?php echo PROJECT_DIR;
?>">mailing list</a> or to the <a href="http://www.<?php echo HOST; ?>/contact.html">project owner</a> directly.</p>

<p />

<?php

$pat            = "^\/";
$target_dir   = ANNOTATE_DIR.PROJECT_DIR."/";
$target_page  = ereg_replace($pat, "", PAGE); // only themes.m.o sets constant PAGE ?
$target_page  = ereg_replace("\/", ".", $target_page);
$readfile     = $target_dir.basename($target_page) . ".comment";
$target_page  = ucwords(ereg_replace("\.html?", "", substr(strrchr($page, "/"), 1)));

$_page .= slash(PAGE) . PAGE;

define ('THIS_PAGE', 'http://' . PROJECT_DIR . '.' . HOST . $_page . '#');

if ( $_POST['message'] && $_POST['name'] && !$hide_text_control )
{
	// censor name to be on safe side
	$name = trim( cleanse(' ' . $name), true );


	// censor message text
	$message = cleanse($message);


	// 0 has neglible effect ; 1 will split words
	// $message = wordwrap($message, 100, "\r\n", 1);


	// -- make link to this comment

	// make file into variable to play with
	if ( file_exists($readfile) ) // can't do this if it doesn't exist : )
	{
	  $file = implode('', file($readfile));
	}

	 $_parts = explode('>[', $file);

	 $_strap = array_reverse($_parts);

	 $_parts = explode(']<', $_strap[0]);

	 $NOTE_date =  intval($_parts[0]);

	// increment count
	 $NOTE_date += 1;

         $author_prepend .= THIS_PAGE . $NOTE_date;

	// -- /make link to this comment


	if ( $post_to_list )
	{
	  $mailto = $project . '@' . HOST;

	  if ( isset($author) )
	  {
	    $extra = 'Bcc: ' . base64_decode($_POST['author']) . "\n";
	  }
	}
	elseif ( isset($author) )
	{
	  $mailto = base64_decode($_POST['author']);
	}


	if ( $target_page == 'Index' && $page != '/index.html' )
	{
	// if [Index] try subdirectory above : e.g. games.m.o/xultris/index.html -> Xultris

	  $target_page = ucwords( substr($page, 0, strrpos($page, "/")) );
	  $target_page = str_replace('/', '', $target_page);
	}


	if ( isset($target_page_override) )
	{
	// if author / developer has something else in mind use that :

	  $target_page = ucwords($target_page_override);
	}


	if ( !empty($target_page) ): $target_page = ' [' . $target_page . ']'; endif;


//	$name = ereg_replace('^\ ', '', $name);
	$name = ereg_replace('<[^>]+>', '', $name);

	// pre-process name
	$name_html  = htmlspecialchars($name);

	// pre-process entry
	$message_html = htmlise($message);


	if(!file_exists($target_dir))
	mkdir($target_dir, 0755);

	// link placement subject to committee

	$c_link     = '<a class="NOTE-date" href="';

	// create name link : PAGE#number
	$c_link    .= $author_prepend . '">[';
	$c_link    .= $NOTE_date . ']</a> ';

	// $c_link should be <a class="NOTE-date" href="[/]?PAGE#$NOTE_date">[$NOTE_date]</a>

	// create start of entry
	$start      = "\n\n" . '<tr><td class="NOTEheader">';

// Pointless options if to be globally accepted

	if ( !$hide_c_link )
	{
	  $start     .= $c_link . ' ';
	}

	$start     .= '<a name="';
	$start     .= $NOTE_date;
	$start     .= '">' . "\nSubmitted by: ";

// Pointless options if to be globally accepted

	$head = "<strong>$name</strong></a>";

	if ( $not_bugzilla_format )
	{
	  $head .= '<br/>';
	}
	else
	{
	  $head .= ' ';
	}

	$head      .= DATE . "\n</td></tr>\n";
	$head      .= '<tr class="NOTEbody"><td class="NOTEbodyText">' . "\n";

	// pre-process entry

	// fin
	$end        = "<br/>\n</td></tr>\n\n";


        // trying to prevent reload from adding (yet) another post/email/NG post
	$already_posted = false;

	$already_posted = strstr($file, $head . $message_html . $end);


	if( ($post_to_list || isset($author) ) && !empty($name) && !empty($message) && !$already_posted)
	{
	  mail($mailto, PROJECT.":$target_page New Feedback from $name",
		$author_prepend . "\n\n" . $message, "From: notes@mozdev.org\n" . $extra);
	}


	// write to file if fields not left blank

	if(!empty($name) && !empty($message) && !$already_posted) {
        // open file handle to append
	  $fp       = fopen ($readfile, "a");
	  fwrite ($fp, $start.$head.$message_html.$end);
	  fclose ($fp);
	}

}// /if ($_POST['message'])


function new_notes($file)
{

  $start = implode('', file($file));

  $start = str_replace("\r\n", "\n", $start); // lineendings fun ? fix
  $start = str_replace("\n\r", "\n", $start); // lineendings fun ? fix

  $start = eregi_replace("\n{4,}", "\n\n\n", $start); // may fix the count problem - or not

  $start = str_replace("<tr><td class=\"NOTEheader\">\n\n", "<tr><td class=\"NOTEheader\">\n", $start);

  if ( ereg("<tr><td class=\"NOTEheader\">\r\n", $start) ||
       ereg("<tr><td class=\"NOTEheader\">\n", $start)
     )
  {

    $middle = explode('<tr><td class="NOTEheader"><a', $start);

    if (ereg("\r\n\r\n\r\n", $middle[0]))
    $second = explode("\r\n\r\n\r\n", $middle[0]);
    elseif (ereg("\n\n\n", $middle[0]))
    $second = explode("\n\n\n", $middle[0]);

    $end = '';

    for ( $i = 0; $second[$i] != ''; ++$i )
    {

      $j = $i + 1; //echo $j;

      $second[$i] = str_replace("<td class=\"NOTEheader\">",
                                '<td class="NOTEheader"><a class="NOTE_link" href="' . $page_name .
                                '#' . $j . '">[' . $j . ']</a> <a name="' . $j . '">',
                                $second[$i]);

      $second[$i] = eregi_replace("</b><br[\/]?>", '</b></a> ', $second[$i]);

      $end .= $second[$i] . "\n\n\n";

    }

    for ( $i = 1; $middle[$i] != ''; ++$i )
    {
      $end .= '<tr><td class="NOTEheader"><a' . $middle[$i];
    }

    $fw = fwrite(fopen($file, "w"), $end);

  }

}


if ( file_exists($readfile) && filesize($readfile) ) {
  echo '<table border="0" cellpadding="3" cellspacing="3" id="NOTES-table" width="90%">' . "\n";
//  new_notes($readfile);
  readfile($readfile);
  echo '<tr id="dummy"><td></td></tr>';
  echo '</table>' . "\n";

 if ( !$hide_text_control )
 {
  echo '<div id="NOTESnotes2"><acronym class="cdn" title="HyperText Markup Language">HTML</acronym> is not allowed';
  echo ' in posts.<br/>' . "\n";
  echo '<acronym class="cdn" title="Uniform Resource Locator">URL</acronym>s in the text that use mailto:,';
  echo ' https://, http:// and ftp:// will be converted into hyperlinks.</div>' . "\n";
 }
}


if (!$hide_text_control)
{

  echo '<div id="NOTEStextControl">' . "\n";
  echo '<form action="' . $_page . '" method="post">' . "\n";
  echo '<p>';

  if ( isset($author) )
    echo '<input type="hidden" name="author" value="' . base64_encode($author) . '">' . "\n";

?>
  <br/>To add your own comment, fill in the form below. <a href="http://mozdev.org/docs/notes.html">[?]</a><br/>
  <em>(Note: use two carriage returns to start a new paragraph.)</em>
</p>

<p>
  <b><label for="mozdevNOTES-name">Your name:</label></b><br/>
  <input id="mozdevNOTES-name" name="name" type="text" size="20" maxlength="20">
</p>

<p>
  <b><label for="mozdevNOTES-message">Your comment:</label></b><br/>

  <textarea id="mozdevNOTES-message" name="message" rows="6" cols="55" style="white-space: nowrap"></textarea>
</p>

<p>
  <input id="NOTESsubmit" name="submit" type="submit" value="Add Note">
</p>

</form>
</div>
<?php }

clearstatcache();

?>

<!-- ********************* END NOTES ******************** -->

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>