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

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

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