File:  [mozdev] / cdn / www / annotate.html
Revision 1.44: download - view: text, annotated - select for diffs - revision graph
Tue Mar 25 09:52:48 2003 UTC (16 years, 10 months ago) by cdn
Branches: MAIN
CVS tags: HEAD
[\ !]

    1: <?php
    2: 
    3: $post_to_list = 0;
    4: 
    5: // $Id: annotate.html,v 1.44 2003/03/25 09:52:48 cdn Exp $
    6: 
    7: function cleanse ($message, $name = false) {
    8: 
    9: // censor before sending to author/NG
   10: 
   11:    if ( ! $name )
   12:    {
   13:      $message = str_replace("\r\n", "[r[n ", $message); // kludge around
   14:    }
   15: 
   16:    $message = ' ' . $message;
   17:    $replacements = array('"', "'", '*', '#', '&', '$', '', '?', '%', '@', '+', 'X', 'x', );
   18:    srand ((float)microtime()*1000000);
   19:    shuffle($replacements);
   20: 
   21:    $cursed = array("m[0ou]th[3e]r[\ ]?f[cu]+[c]?k[3e]r",
   22:                    "f[\ \.]*[cu]+[\ \.]*[c]?[\ \.]*k",
   23:                    "[4a]+[5s$]+[5s$]hole",
   24:                    "[ck]unt",
   25:                    "pu[5s]+[5s]y",
   26:                    "c[o0]ck",
   27:                    "tw[4a]t",
   28:                    "cl[1i]t",
   29:                    "s[\ \.]*h[\ \.]*[1i]+[\ \.]*t[\ \.]*[e]?",
   30:                    "b[1!i]tch",
   31:                    "cum", // not strictly an obscenity
   32:                   );
   33: 
   34:   // too indiscriminant /Documents goes to /Do*#&amp;$%ents
   35: 
   36:   for ($i=0; $cursed[$i] != ''; $i++) {
   37: 
   38:     if ($name) {
   39:       $cursed[$i] = '[\ !!]?' . $cursed[$i];
   40:     } 
   41:     else {
   42:      // whitespace, however currently turns '\n' to ' '
   43:      $cursed[$i] = '[\ ]+' . $cursed[$i];
   44:     }
   45: 
   46:     shuffle($replacements);
   47:     $repstring = $replacements[0] . $replacements[2] . $replacements[5] .
   48:                  $replacements[1] . $replacements[3];
   49: 
   50:     if ($i == 0)
   51:       // might as well educate the miscreants
   52:       $message = eregi_replace($cursed[0], ' oedipus', $message);
   53:     else if ($i == 1)
   54:       $message = eregi_replace($cursed[1], ' frell', $message);
   55:     else
   56:       $message = eregi_replace($cursed[$i], ' ' . $repstring, $message);
   57:   }
   58: 
   59:   $message = substr($message, 1);
   60: 
   61:   $message = stripslashes($message);
   62: 
   63:   if ( ! $name )
   64:   {
   65: 
   66:     $message = str_replace("[r[n ", "\r\n", $message); // losing \r\n to [\ ] or [[:space:]]
   67: 
   68:   }
   69: 
   70:   return $message;
   71: 
   72: }
   73: 
   74: 
   75: function findBugs($text)
   76: {
   77: 
   78: // find and 'linkify' mozdev bug references in posts
   79: //
   80: // Initial version, only places links into html, mail and NG miss out : )
   81: 
   82: // bug[\ ]?[#%]?[0-9]{1,}
   83: // bug 2345
   84: // bug #2345
   85: // bug %2345 -> http://mozdev.org/bugs/show_bug.cgi?id=2345
   86: 
   87:   $text = eregi_replace("(bug[\ ]+[#%]?[0-9]{1,})",
   88:                               "<a href=\"\\1\">\\1</a>",$text);
   89: 
   90:   $text = eregi_replace('"bug[\ ]+[#%]?', '"http://' . HOST . '/bugs/show_bug.cgi?id=', $text);
   91: 
   92:   return $text;
   93: 
   94: }
   95: 
   96: 
   97: function slash($_page)
   98: {
   99: 
  100: // if no leading slash - add one
  101: 
  102:   if ( !ereg('^/', $_page) )
  103:   {
  104:     return '/';
  105:   }
  106: 
  107: }
  108: 
  109: 
  110: function findComments($text)
  111: {
  112: 
  113: // find and 'linkify' mozdev comment references in posts
  114: //
  115: // Initial version, only places links into html, mail and NG miss out : )
  116: 
  117: // comment[\ ]?[#%]?[0-9]{1,}
  118: // comment 2345
  119: // comment #2345
  120: // comment %2345 -> http://PROJECT.mozdev.org/PAGE#2345
  121: 
  122:   $text = eregi_replace("(comment[\ ]+[#%]?[0-9]{1,})",
  123:                               "<a href=\"\\1\">\\1</a>",$text);
  124: 
  125:   $text = eregi_replace('"comment[\ ]+[#%]?', '"' . THIS_PAGE, $text);
  126: 
  127:   return $text;
  128: 
  129: }
  130: 
  131: 
  132: function findLinks($text)
  133: {
  134: 
  135: // find and 'linkify' links
  136: 
  137:   $text    = eregi_replace("((http|https|ftp):\/\/[^[:space:]<>]{1,})",
  138:                            "<a href=\"\\1\">\\1</a>",$text);
  139: /*
  140: 
  141:   find name@host.tld, where no mailto:
  142: 
  143: $regExp = "^[\+\&_\.0-9a-z-]+@([0-9a-z]+-*[0-9a-z]+[^-]*[.]?)+([a-z]{2,4}[.]?$)";
  144: 
  145:   eregi_replace $regExp, mailto:$regExp
  146: 
  147: */
  148: 
  149:   $text    = eregi_replace("(mailto:[^[:space:]<>]{1,})",
  150:                            "<a href=\"\\1\">\\1</a>",$text);
  151: 
  152: // tidy email references
  153:   $text = str_replace('>mailto:', '>', $text);
  154: 
  155:   return $text;
  156: 
  157: }
  158: 
  159: 
  160: function htmlise($text)
  161: {
  162: 
  163:   $text = htmlspecialchars(str_replace("\\", "", $text));
  164: 
  165:   $text = findLinks($text);
  166: 
  167:   $text = findBugs($text);
  168: 
  169:   $text = findComments($text);
  170: 
  171:   $text = ereg_replace("\r\n\r\n", "\n<p/>", $text);
  172: 
  173:   $text = ereg_replace("\r\n", "\n<br/>", $text);
  174: 
  175: 
  176:   return $text;
  177: }
  178: 
  179: ?><!-- ********************* START NOTES ******************** -->
  180: 
  181: <div id="NOTESheader"><a name="NOTES"><strong>User Notes:</strong></a> <a href="http://<?php echo HOST; ?>/docs/notes.html">[?]</a></div>
  182: 
  183: <div id="NOTESnotes"><acronym class="cdn" title="HyperText Markup Language">HTML</acronym> is not allowed in posts.<br/>
  184: <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>
  185: 
  186: <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;
  187: ?>">mailing list</a> or to the <a href="http://www.<?php echo HOST; ?>/contact.html">project owner</a> directly.</p>
  188: 
  189: <p />
  190: 
  191: <?php
  192: 
  193: $pat            = "^\/";
  194: $target_dir   = ANNOTATE_DIR.PROJECT_DIR."/";
  195: $target_page  = ereg_replace($pat, "", PAGE); // only themes.m.o sets constant PAGE ?
  196: $target_page  = ereg_replace("\/", ".", $target_page);
  197: $readfile     = $target_dir.basename($target_page) . ".comment";
  198: $target_page  = ucwords(ereg_replace("\.html?", "", substr(strrchr($page, "/"), 1)));
  199: 
  200: $_page .= slash(PAGE) . PAGE;
  201: 
  202: define ('THIS_PAGE', 'http://' . PROJECT_DIR . '.' . HOST . $_page . '#');
  203: 
  204: if ( $_POST['message'] && $_POST['name'] && !$hide_text_control )
  205: {
  206: 	// censor name to be on safe side
  207: 	$name = trim( cleanse('!!' . $name), true );
  208: 
  209: 
  210: 	// censor message text
  211: 	$message = cleanse($message);
  212: 
  213: 
  214: 	// 0 has neglible effect ; 1 will split words
  215: 	// $message = wordwrap($message, 100, "\r\n", 1);
  216: 
  217: 
  218: 	// -- make link to this comment
  219: 
  220: 	// make file into variable to play with
  221: 	if ( file_exists($readfile) ) // can't do this if it doesn't exist : )
  222: 	{
  223: 	  $file = implode('', file($readfile));
  224: 	}
  225: 
  226: 	 $_parts = explode('>[', $file);
  227: 
  228: 	 $_strap = array_reverse($_parts);
  229: 
  230: 	 $_parts = explode(']<', $_strap[0]);
  231: 
  232: 	 $NOTE_date =  intval($_parts[0]);
  233: 
  234: 	// increment count
  235: 	 $NOTE_date += 1;
  236: 
  237:          $author_prepend .= THIS_PAGE . $NOTE_date;
  238: 
  239: 	// -- /make link to this comment
  240: 
  241: 
  242: 	if ( $post_to_list )
  243: 	{
  244: 	  $mailto = $project . '@' . HOST;
  245: 
  246: 	  if ( isset($author) )
  247: 	  {
  248: 	    $extra = 'Bcc: ' . base64_decode($_POST['author']) . "\n";
  249: 	  }
  250: 	}
  251: 	elseif ( isset($author) )
  252: 	{
  253: 	  $mailto = base64_decode($_POST['author']);
  254: 	}
  255: 
  256: 
  257: 	if ( $target_page == 'Index' && $page != '/index.html' )
  258: 	{
  259: 	// if [Index] try subdirectory above : e.g. games.m.o/xultris/index.html -> Xultris
  260: 
  261: 	  $target_page = ucwords( substr($page, 0, strrpos($page, "/")) );
  262: 	  $target_page = str_replace('/', '', $target_page);
  263: 	}
  264: 
  265: 
  266: 	if ( isset($target_page_override) )
  267: 	{
  268: 	// if author / developer has something else in mind use that :
  269: 
  270: 	  $target_page = ucwords($target_page_override);
  271: 	}
  272: 
  273: 
  274: 	if ( !empty($target_page) ): $target_page = ' [' . $target_page . ']'; endif;
  275: 
  276: 
  277: 	$name = ereg_replace('^!!', '', $name);
  278: 	$name = ereg_replace('<[^>]+>', '', $name);
  279: 
  280: 	// pre-process name
  281: 	$name_html  = htmlspecialchars($name);
  282: 
  283: 	// pre-process entry
  284: 	$message_html = htmlise($message);
  285: 
  286: 
  287: 	if(!file_exists($target_dir))
  288: 	mkdir($target_dir, 0755);
  289: 
  290: 	// link placement subject to committee
  291: 
  292: 	$c_link     = '<a class="NOTE-date" href="';
  293: 
  294: 	// create name link : PAGE#number
  295: 	$c_link    .= $author_prepend . '">[';
  296: 	$c_link    .= $NOTE_date . ']</a> ';
  297: 
  298: 	// $c_link should be <a class="NOTE-date" href="[/]?PAGE#$NOTE_date">[$NOTE_date]</a>
  299: 
  300: 	// create start of entry
  301: 	$start      = "\n\n" . '<tr><td class="NOTEheader">';
  302: 
  303: // Pointless options if to be globally accepted
  304: 
  305: 	if ( !$hide_c_link )
  306: 	{
  307: 	  $start     .= $c_link . ' ';
  308: 	}
  309: 
  310: 	$start     .= '<a name="';
  311: 	$start     .= $NOTE_date;
  312: 	$start     .= '">' . "\nSubmitted by: ";
  313: 
  314: // Pointless options if to be globally accepted
  315: 
  316: 	$head = "<strong>$name</strong></a>";
  317: 
  318: 	if ( $not_bugzilla_format )
  319: 	{
  320: 	  $head .= '<br/>';
  321: 	}
  322: 	else
  323: 	{
  324: 	  $head .= ' ';
  325: 	}
  326: 
  327: 	$head      .= DATE . "\n</td></tr>\n";
  328: 	$head      .= '<tr class="NOTEbody"><td class="NOTEbodyText">' . "\n";
  329: 
  330: 	// pre-process entry
  331: 
  332: 	// fin
  333: 	$end        = "<br/>\n</td></tr>\n\n";
  334: 
  335: 
  336:         // trying to prevent reload from adding (yet) another post/email/NG post
  337: 	$already_posted = false;
  338: 
  339: 	$already_posted = strstr($file, $head . $message_html . $end);
  340: 
  341: 
  342: 	if( ($post_to_list || isset($author) ) && !empty($name) && !empty($message) && !$already_posted)
  343: 	{
  344: 	  mail($mailto, PROJECT.":$target_page New Feedback from $name",
  345: 		$author_prepend . "\n\n" . $message, "From: notes@mozdev.org\n" . $extra);
  346: 	}
  347: 
  348: 
  349: 	// write to file if fields not left blank
  350: 
  351: 	if(!empty($name) && !empty($message) && !$already_posted) {
  352:         // open file handle to append
  353: 	  $fp       = fopen ($readfile, "a");
  354: 	  fwrite ($fp, $start.$head.$message_html.$end);
  355: 	  fclose ($fp);
  356: 	}
  357: 
  358: }// /if ($_POST['message'])
  359: 
  360: 
  361: function new_notes($file)
  362: {
  363: 
  364:   $start = implode('', file($file));
  365: 
  366:   $start = str_replace("\r\n", "\n", $start); // lineendings fun ? fix
  367:   $start = str_replace("\n\r", "\n", $start); // lineendings fun ? fix
  368: 
  369:   $start = eregi_replace("\n{4,}", "\n\n\n", $start); // may fix the count problem - or not
  370: 
  371:   $start = str_replace("<tr><td class=\"NOTEheader\">\n\n", "<tr><td class=\"NOTEheader\">\n", $start);
  372: 
  373:   if ( ereg("<tr><td class=\"NOTEheader\">\r\n", $start) ||
  374:        ereg("<tr><td class=\"NOTEheader\">\n", $start)
  375:      )
  376:   {
  377: 
  378:     $middle = explode('<tr><td class="NOTEheader"><a', $start);
  379: 
  380:     if (ereg("\r\n\r\n\r\n", $middle[0]))
  381:     $second = explode("\r\n\r\n\r\n", $middle[0]);
  382:     elseif (ereg("\n\n\n", $middle[0]))
  383:     $second = explode("\n\n\n", $middle[0]);
  384: 
  385:     $end = '';
  386: 
  387:     for ( $i = 0; $second[$i] != ''; ++$i )
  388:     {
  389: 
  390:       $j = $i + 1; //echo $j;
  391: 
  392:       $second[$i] = str_replace("<td class=\"NOTEheader\">",
  393:                                 '<td class="NOTEheader"><a class="NOTE_link" href="' . $page_name .
  394:                                 '#' . $j . '">[' . $j . ']</a> <a name="' . $j . '">',
  395:                                 $second[$i]);
  396: 
  397:       $second[$i] = eregi_replace("</b><br[\/]?>", '</b></a> ', $second[$i]);
  398: 
  399:       $end .= $second[$i] . "\n\n\n";
  400: 
  401:     }
  402: 
  403:     for ( $i = 1; $middle[$i] != ''; ++$i )
  404:     {
  405:       $end .= '<tr><td class="NOTEheader"><a' . $middle[$i];
  406:     }
  407: 
  408:     $fw = fwrite(fopen($file, "w"), $end);
  409: 
  410:   }
  411: 
  412: }
  413: 
  414: 
  415: if ( file_exists($readfile) && filesize($readfile) ) {
  416:   echo '<table border="0" cellpadding="3" cellspacing="3" id="NOTES-table" width="90%">' . "\n";
  417: //  new_notes($readfile);
  418:   readfile($readfile);
  419:   echo '<tr id="dummy"><td></td></tr>';
  420:   echo '</table>' . "\n";
  421: 
  422:  if ( !$hide_text_control )
  423:  {
  424:   echo '<div id="NOTESnotes2"><acronym class="cdn" title="HyperText Markup Language">HTML</acronym> is not allowed';
  425:   echo ' in posts.<br/>' . "\n";
  426:   echo '<acronym class="cdn" title="Uniform Resource Locator">URL</acronym>s in the text that use mailto:,';
  427:   echo ' https://, http:// and ftp:// will be converted into hyperlinks.</div>' . "\n";
  428:  }
  429: }
  430: 
  431: 
  432: if (!$hide_text_control)
  433: {
  434: 
  435:   echo '<div id="NOTEStextControl">' . "\n";
  436:   echo '<form action="' . $_page . '" method="post">' . "\n";
  437:   echo '<p>';
  438: 
  439:   if ( isset($author) )
  440:     echo '<input type="hidden" name="author" value="' . base64_encode($author) . '">' . "\n";
  441: 
  442: ?>
  443:   <br/>To add your own comment, fill in the form below. <a href="http://mozdev.org/docs/notes.html">[?]</a><br/>
  444:   <em>(Note: use two carriage returns to start a new paragraph.)</em>
  445: </p>
  446: 
  447: <p>
  448:   <b><label for="mozdevNOTES-name">Your name:</label></b><br/>
  449:   <input id="mozdevNOTES-name" name="name" type="text" size="20" maxlength="20">
  450: </p>
  451: 
  452: <p>
  453:   <b><label for="mozdevNOTES-message">Your comment:</label></b><br/>
  454: 
  455:   <textarea id="mozdevNOTES-message" name="message" rows="6" cols="55" style="white-space: nowrap"></textarea>
  456: </p>
  457: 
  458: <p>
  459:   <input id="NOTESsubmit" name="submit" type="submit" value="Add Note">
  460: </p>
  461: 
  462: </form>
  463: </div>
  464: <?php }
  465: 
  466: clearstatcache();
  467: 
  468: ?>
  469: 
  470: <!-- ********************* END NOTES ******************** -->

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