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

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

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