Annotation of cdn/www/annotate.html, revision 1.45

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

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