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

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

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