File:  [mozdev] / cdn / www / annotate.html
Revision 1.1: download - view: text, annotated - select for diffs - revision graph
Sun Mar 23 17:28:02 2003 UTC (16 years, 10 months ago) by cdn
Branches: MAIN
CVS tags: HEAD
*** empty log message ***

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

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