Changeset 1278

Show
Ignore:
Timestamp:
12/30/06 11:24:00 (2 years ago)
Author:
jm3
Message:

* implemented comment deletion
* implemented beginnings of undo (just caching of the queue of actions)
* cleaned up css files a bit
* added optional message to view-link page

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • feedmelinks/.htaccess-global

    r1226 r1278  
    2626RewriteRule    ^([0-9]+)$ /?l=$1 [L] 
    2727RewriteRule    ^([0-9]+)/d$ /?l=$1&debug=1 [L] 
     28RewriteRule    ^([0-9]+)/m/(.*)$ /?l=$1&mesg=$2 [L] 
    2829 
    2930# grab links 
  • feedmelinks/FAQ/index.php

    r1082 r1278  
    151151                <div class="q">Can I have the source code to Feed Me Links?</div> 
    152152                <div class="a"> 
    153                         Of course! We're all about sharing. <a href="/code">Download the source to Feed Me Links at <u>feedmelinks.com/code</u></a> 
     153                        Of course! We're all about sharing. The code is a total mess, so, you know -- be forewarned.<p/> 
     154                         
     155                        if you just want to <b>read</b> the source code, you can browse it online at: <a href="/code">Download the source to Feed Me Links at <u>feedmelinks.com/code</u></a> 
     156                        <p/> 
     157                        if you want to check-out / download it, you'll need <a href="http://subversion.tigris.org/">Subversion</a>. From a command-line, type: <p/> 
     158                        <code> 
     159                        svn co http://toolstomaketools.svnrepository.com/svn/codepot/feedmelinks/ 
     160                        </code> 
     161 
    154162                </div> 
    155163                <a href="#top">back to top</a> 
  • feedmelinks/action.php

    r1178 r1278  
    250250<% } else { %> 
    251251 
    252 <link rel="stylesheet" type="text/css" href="/new-portal.css" title="default stylings"> 
     252<link rel="stylesheet" type="text/css" href="/style/main.css" title="default stylings"> 
    253253<div class='welcome'> 
    254254        no links selected;<br/> 
  • feedmelinks/comments.php

    r961 r1278  
    1 <% 
     1<?php 
    22        # $Id$ 
    33        include_once( "modules/utils.inc.php" ); 
     
    1111                $authenticated = 1; 
    1212                $user = $who ? $who : $sessionUserId; 
    13 %
     13?
    1414 
    1515<title> Feed me comments </title> 
    1616 
    17 <%  
    18         include( "$modules/header.inc.php" );  
    19 %> 
     17<?php  
     18                include( "$modules/header.inc.php" );  
     19                $show_comments = true; 
     20 
     21                if( $op == "delete" ) 
     22                        $show_comments = false; 
     23?> 
    2024 
    2125<h3> 
    22 <%  
    23         if( $who )  
    24                 echo "Comments by and about $who"; 
    25         else 
    26                 echo "My Comments"; 
    27 %> 
     26<?php  
     27                if( $who )  
     28                        echo "Comments by and about $who"; 
     29                else if( $op == "delete" ) 
     30                        echo "Delete comment:"; 
     31                else 
     32                        echo "My Comments"; 
     33?> 
    2834</h3> 
     35<?php 
     36                if( $op == "delete" && getOwnerForLink( $link ) == $u ) { 
     37 
     38                        $comments = get_file_safe( get_comments_file( $link, $u )); 
     39                        if( ! array_key_exists( $comment, $comments )) 
     40                                bounceBack(); 
     41 
     42                        # cache it for displaying in any error messages 
     43                        $c = parse_comment( $comments[ $comment ]); 
     44                        echo '"' . $c["comment"] . '"' . " by " . getUserLink( $c["user"] ) . " from " . formatAsSimpleDate( $c["date"]) . " on " . getLink( $link ) . "</p>"; 
     45 
     46                        if( $debug ) 
     47                                echo "<p>comment #$comment</p>"; 
     48 
     49                        # back up the comment file so the deletion can be un-done if necessary 
     50                        $undo_file = get_undo_file( $u, "comment", "delete" ); 
     51                        file_append_contents( $undo_file, $link . ":" . $comments[ $comment ]); 
     52 
     53                        # remove the comment line from the array 
     54                        $new_comments = $comments; 
     55                        unset( $new_comments[ $comment ]); 
     56                        if( $debug ) { 
     57                                echo "<pre>post deletion"; 
     58                                print_r( $new_comments ); 
     59                        } 
     60                         
     61                        # write the modified array back into the comment file 
     62                        file_put_contents( get_comments_file($link, $u), implode( "", $new_comments )); 
     63 
     64                        # send the user back to the link page with a note that the comment was deleted 
     65                        echo bounceTo( "/$link/m/Comment+deleted.", 1 ); 
     66 
     67                } 
     68                if( $show_comments ) { 
     69?> 
    2970 
    3071<div style="width: 630px; height: 400px;"> 
    3172 
    3273<div class="column" style="float: left;"> 
    33         <span style="font-weight: bold; text-transform: uppercase">others' comments on <%= $who ? $who . "'s" : "YOUR" %> links:</span> 
     74        <span style="font-weight: bold; text-transform: uppercase">others' comments on <?= $who ? $who . "'s" : "YOUR" ?> links:</span> 
    3475        <div class="onepxlline">&nbsp;</div> 
    3576        <br /> 
    3677 
    37 <% 
     78<?php 
    3879        chdir( get_webserver_root() ); 
    3980        $cmd = "find _comments/$user -type f | xargs -n1 grep -H -v $user | sort -rk 2"; 
     
    5091                if( $debug ) 
    5192                        echo "got here<br />"; 
    52 %
    53                 <b><%= $n %> <%= $n == 1 ? "comment" : "comments" %></b>:<br /> 
    54 <% 
     93?
     94                <b><?= $n ?> <?= $n == 1 ? "comment" : "comments" ?>b>:<br /> 
     95<?php 
    5596                 
    5697                foreach ($oba as $line) { 
     
    76117                } 
    77118        } else { 
    78 %
     119?
    79120<!-- DEBUG: 
    80 $o: <%= $o %
    81 <%= $cmd %> failed with code <%= $r %>! 
     121$o: <?= $o ?
     122<?= $cmd ?> failed with code <?= $r ?> 
    82123--> 
    83124 
    84 <center>(nobody's added comments to <%= $who ? "$user's" : "your" %> links yet)</center> 
    85 <br /> 
    86 <% 
     125<center>(nobody's added comments to <?= $who ? "$user's" : "your" ?> links yet)</center> 
     126<br /> 
     127<?php 
    87128        } 
    88 %
     129?
    89130 
    90131        <br /> 
    91132        <span style="font-weight: bold; text-transform: uppercase"> 
    92         <%= $who ? ($who . "'s comments on his own links") : "Your comments on your own links" %>:</span> 
     133        <?= $who ? ($who . "'s comments on his own links") : "Your comments on your own links" ?>span> 
    93134        <div class="onepxlline">&nbsp;</div> 
    94135        <br /> 
    95136 
    96 <% 
     137<?php 
    97138        $c = 1; #counter 
    98139        $the_dir = get_webserver_root() . '/_comments/' . $user; 
     
    127168                } 
    128169        } else { 
    129 %
     170?
    130171<!-- 
    131172DEBUG:  
    132 <%= $cmd %> failed with code <%= $r%> ! 
     173<?= $cmd ?> failed with code <?= $r?> ! 
    133174--> 
    134175<center> 
    135 (<%= $who ? "$who hasn't" : "you haven't" %> any comments to your links) 
     176(<?= $who ? "$who hasn't" : "you haven't" ?> any comments to your links) 
    136177</center> 
    137178<br /> 
    138 <% 
     179<?php 
    139180        } # end if dir exists: 
    140 %
     181?
    141182 
    142183</div> 
    143184 
    144185<div class="column" style="float: right;"> 
    145         <span style="font-weight: bold; text-transform: uppercase"><%= $who ? $who . "'s" : "" %> comments on others' links:</span> 
     186        <span style="font-weight: bold; text-transform: uppercase"><?= $who ? $who . "'s" : "" ?> comments on others' links:</span> 
    146187        <div class="onepxlline">&nbsp;</div> 
    147188        <br /> 
    148189 
    149 <% 
     190<?php 
    150191        chdir( get_webserver_root() ); 
    151192        $cmd = "find _comments/ -type f | sort -r | xargs -n1 grep -H $user, | grep -v comments/$user | sort -r -k 2"; 
     
    179220                } 
    180221        } else { 
    181 %
    182 <center>(<%= $who ? "$user has" : "you've" %> made no comments here yet)</center> 
     222?
     223<center>(<?= $who ? "$user has" : "you've" ?> made no comments here yet)</center> 
    183224<br /> 
    184225<!-- DEBUG: 
    185 $o: <%= $o %
    186 <%= $cmd %> failed with code <%= $r %>! 
     226$o: <?= $o ?
     227<?= $cmd ?> failed with code <?= $r ?> 
    187228--> 
    188 <% 
     229<?php 
    189230        } 
    190 %
     231?
    191232 
    192233</div> 
     
    197238<br /> 
    198239<div width="650"> 
    199 <% include( "$modules/footer.inc.php" ); %> 
    200 </div> 
    201  
    202 <% } else {  %> 
    203 <%= bounceTo( $site . "/login?bounceToPage=" . urlencode( "comments" )) %> 
    204 <% } %> 
    205  
     240<?php include( "$modules/footer.inc.php" ); ?> 
     241</div> 
     242 
     243<?php  
     244                } 
     245        } else {  ?> 
     246<?= bounceTo( $site . "/login?bounceToPage=" . urlencode( "comments" )) ?> 
     247<?php } ?> 
     248 
  • feedmelinks/contacts/add.php

    r1276 r1278  
    66        $u = $_COOKIE["c_uid"]; 
    77%> 
    8 <link rel="stylesheet" type="text/css" href="/new-portal.css" title="default stylings"> 
     8<link rel="stylesheet" type="text/css" href="/style/main.css" title="default stylings"> 
    99<% 
    1010 
  • feedmelinks/contacts/remove.php

    r427 r1278  
    66        $u = $_COOKIE["c_uid"]; 
    77%> 
    8 <link rel="stylesheet" type="text/css" href="/new-portal.css" title="default stylings"> 
     8<link rel="stylesheet" type="text/css" href="/style/main.css" title="default stylings"> 
    99<% 
    1010 
  • feedmelinks/contacts/testing.php

    r427 r1278  
    66        $u = $_COOKIE["c_uid"]; 
    77%> 
    8 <link rel="stylesheet" type="text/css" href="/new-portal.css" title="default stylings"> 
     8<link rel="stylesheet" type="text/css" href="/style/main.css" title="default stylings"> 
    99<% 
    1010 
  • feedmelinks/diespammersdie/index.php

    r1248 r1278  
    99        </title> 
    1010 
    11         <link href="/style/new-portal.css" rel="stylesheet" type="text/css">   
     11        <link href="/style/main.css" rel="stylesheet" type="text/css">   
    1212        <link href="/style/one-page.css" rel="stylesheet" type="text/css">   
    1313 
  • feedmelinks/diespammersdie/report.php

    r1177 r1278  
    99        </title> 
    1010 
    11         <link href="/style/new-portal.css" rel="stylesheet" type="text/css">   
     11        <link href="/style/main.css" rel="stylesheet" type="text/css">   
    1212        <link href="/style/one-page.css" rel="stylesheet" type="text/css">   
    1313 
  • feedmelinks/modules/header.inc.php

    r1272 r1278  
    2121        <link rel="shortcut icon" href="/img/favicon.png" type="image/png"> 
    2222        <% if( $css ) { %><link rel="stylesheet" type="text/css" href="<%= $css %>"><% } %> 
    23         <link rel="stylesheet" type="text/css" href="/style/new-portal.css"> 
    24         <link rel="stylesheet" type="text/css" href="/style/notebox.css"> 
     23        <link rel="stylesheet" type="text/css" href="/style/main.css"> 
    2524        <link rel="alternate" type="application/rss+xml" title="Feed Me Links" href="<?= $site ?>/rss"> 
    2625 
     
    5655  if( ! $noBody ) 
    5756    echo "<body>"; 
     57?> 
     58 
     59<script type='text/javascript' src='http://track3.mybloglog.com/js/jsserv.php?mblID=2006121201422511'></script> 
     60 
     61<?php 
    5862        if( ! $noMenu ) 
    5963                include( "$modules/menu.inc.php" );  
  • feedmelinks/modules/utils.inc.php

    r1272 r1278  
    169169    fclose( $f ); 
    170170  } 
     171} 
     172 
     173# convenience function, now part of php5 
     174function file_put_contents( $filename, $data ) { 
     175        return file_put_contents_driver( $filename, $data, "w+" ); 
     176} 
     177 
     178function file_append_contents( $filename, $data ) { 
     179        return file_put_contents_driver( $filename, $data, "a+" ); 
     180} 
     181 
     182function file_put_contents_driver( $filename, $data, $mode ) { 
     183        if( !$f = fopen($filename, $mode)) { 
     184                echo "Cannot open file ($filename)"; 
     185                exit; 
     186        } 
     187        if( fwrite($f, $data) === FALSE) { 
     188                echo "Cannot write to file ($filename)"; 
     189                exit; 
     190        } 
     191        fclose($f); 
     192        return "Success, wrote ($data) to file ($filename)"; 
    171193} 
    172194 
     
    562584    $pi["samanthers"] = true; 
    563585    $pi["r34l"] = true; 
     586    $pi["chrishaney"] = true; 
     587    $pi["troubledyouth"] = true; 
    564588 
    565589    #$pi["rrhobbs"] = true; 
     
    582606  $config = new Config; 
    583607 
     608        function mk_folder( $f ) { 
     609                if( !$f || is_dir( $f )) 
     610                        return; 
     611                $old_umask = umask(0); 
     612                mkdir( $f ); 
     613                umask($old_umask); 
     614        } 
     615 
    584616  function make_user_dir( $u ) { 
    585617    chdir( get_root() ); 
    586618    $u_dir = get_user_folder( $u ? $u : get_user() ); 
    587619    if( ! is_dir( $u_dir )) { 
    588       $old_umask = umask(0); 
    589       mkdir( $u_dir ); 
    590       umask($old_umask); 
     620                        mk_folder( $u_dir ); 
    591621    } 
    592622    if( !is_dir( $u_dir ))  
     
    663693  } 
    664694 
    665  
    666695  function startTell( $t = "", $wide = false ) { 
    667696%> 
     697<link rel="stylesheet" type="text/css" href="/style/notebox.css"> 
    668698<div class="notebox" <%= $wide ? 'style="width: 600px; margin-left: auto; margin-right: auto;"' : ""%>> 
    669699  <div class="noteboxHead" <%= $wide ? 'style="font-size: 140%;"' : ""%>><h2><%= $t %></h2></div> 
     
    716746    $linkfolder = $COMMENT_DIR . $folder; 
    717747    return( get_root() ."/" . $COMMENT_DIR . $folder . escapeshellcmd( $l ) . $COMMENT_EXT ); 
     748  } 
     749 
     750  function get_undo_file( $u, $noun, $verb ) { 
     751    if( ! $u ) 
     752      return;  
     753    $u = escapeshellcmd( $u ); 
     754    $f = get_root() ."/" . get_user_folder( $u ) . "/undo"; 
     755    if( ! is_dir( $f )) 
     756      mk_folder( $f ); 
     757                if( $noun ) 
     758      mk_folder( "$f/$noun" ); 
     759    $noun = $noun ? $noun : "last";  
     760    return "$f/$noun" . ($verb ? "/$verb" : ""); 
    718761  } 
    719762 
     
    14751518      if( $debug ) 
    14761519        echo "<br><b>making usr dir..</b><br>"; 
    1477       $old_umask = umask(0); 
    1478       mkdir( $u_dir ); 
    1479       umask($old_umask); 
     1520                        mk_folder( $u_dir ); 
    14801521    } 
    14811522    if( is_writable( $argCacheFile )) { 
     
    24002441} 
    24012442 
     2443function parse_comment( $c ) { 
     2444        if( ! $c ) 
     2445                return ; 
     2446        $pieces = explode(", ", $c); 
     2447        return array( "user" => $pieces[0], "date" => $pieces[1], "comment" => $pieces[2]); 
     2448} 
     2449 
    24022450function getCommentCSS() { 
    24032451      return ' 
     
    24522500  } 
    24532501 
     2502# flock a file and read into an array 
     2503function get_file_safe( $fname ) { 
     2504        if( !$fname ) 
     2505                return; 
     2506        ignore_user_abort(true); 
     2507        $f = fopen( $fname, 'r' ); 
     2508        flock( $f, LOCK_SH ); 
     2509        $lines = file( $fname ); 
     2510        flock( $f, LOCK_UN ); 
     2511        fclose( $f ); 
     2512        return $lines; 
     2513} 
     2514 
    24542515function getCommentsForLink() { 
    24552516    $args = func_get_args(); 
     
    24572518    $argUser = $args[1]; 
    24582519    $debug = 0; 
    2459     #$debug = $args[2]
     2520               $u = get_user()
    24602521 
    24612522    $link = $argId; 
     
    24642525 
    24652526      $owner = getOwnerForLink( $link ); 
     2527                        $yours = ($u == $owner) ? true : false; 
    24662528      $linkfile = get_comments_file( $link, $owner ); 
    24672529       
     
    24692531          if( $debug ) 
    24702532            echo "(COMMENTS FILE $link$COMMENT_EXT  EXISTS AND IS READABLE)<br /><br />";  
    2471      
    2472           # flock comments file and read into an array 
    2473           ignore_user_abort(true); 
    2474           $f = fopen( $linkfile, 'r' ); 
    2475           flock( $f, LOCK_SH ); 
    2476           $lines = file( $linkfile ); 
    2477           flock( $f, LOCK_UN ); 
    2478           fclose( $f ); 
     2533 
     2534                                        # flock comments file and read into an array 
     2535                                        $lines = get_file_safe( $linkfile ); 
    24792536 
    24802537  %> 
     
    25092566            } 
    25102567 
    2511             echo "<div class=\"$class\" style=\"width: 40em;\">$comment</div><br />"; 
     2568            echo "<div class=\"$class\" id=\"comment_" . $argId . "_" . $line_num . "\" style=\"width: 40em;\">$comment"; 
     2569                                                echo "<p/>"; 
     2570                                                if( $yours ) 
     2571                                                        echo "[<a href='/comments?op=delete&link=$argId&comment=$line_num'>delete</a>]"; 
     2572                                                echo "</div><br />"; 
    25122573          } 
    25132574      } else { 
     
    25212582      echo "NO LINK or INVALID LINK ID ($argID)<br />"; 
    25222583    } 
    2523     #if( ! $comments ) 
    2524       #echo "&#160;NO COMMENTS FOR THIS LINK EXIST (YET)<br />"; 
    25252584    if( $argUser && $argUser != "nobody") 
    25262585      echo getAddCommentForm( $argId, $comments, $debug ); 
     
    27612820 
    27622821      if( !is_dir( $linkfolder ) || !is_writable( $linkfolder )) { 
    2763         $old_umask = umask(0); 
    2764         mkdir( $linkfolder ); 
    2765         umask($old_umask); 
     2822        mk_folder( $linkfolder ); 
    27662823      } else 
    27672824        if( $debug ) 
     
    33613418 
    33623419function getLink( $id, $url, $text, $title, $class, $target ) { 
     3420        ob_start(); 
    33633421  if( $url && $text) { 
    3364     ob_start(); 
    33653422    $url = encodeAmps( $url ); 
    33663423    $title = $title ? "title=\"" . encodeAmps( $title ) . "\"" : ""; 
     
    33683425    $target = $target ? "target=\"$target\"" : ""; 
    33693426%><a <%= $title ? $title : "" %> href="<%= $url %>" <%= $class %> <%= $target %>><%= $text %></a><%= isPrivate( $id ) ? "&#160;" . getLinkLock( $id ) : "" %><% 
    3370     $out = ob_get_clean(); 
    3371     return $out; 
    3372   } 
     3427  } else if( $id ) { 
     3428                %><a href="/<%= $id %>"><%= getTitleForLink( $id ) %></a><%  
     3429        } 
     3430        $out = ob_get_clean(); 
     3431        return $out; 
    33733432} 
    33743433 
     
    36103669    return $txt; 
    36113670  } 
     3671 
     3672function formatAsSimpleDate( $ts ) { 
     3673  return preg_replace( "/T.*$/", "", formatAsDCDate( $ts )); 
     3674} 
    36123675 
    36133676function formatAsDCDate( $ts ) { 
  • feedmelinks/modules/view-link.inc.php

    r1188 r1278  
    2626                        $owned = ( $user == $u ) ? 1 : 0; 
    2727 
     28                        if( $mesg ) { 
    2829%> 
    2930 
    30 <div class="attention" style="width: 45em;"> 
     31<div class="warning"> 
     32        <?= $mesg ?> 
    3133</div> 
    3234<% 
     35 
     36                        } 
    3337                        if( $owned ) { 
    3438%> 
  • feedmelinks/portal-uncached.php

    r1184 r1278  
    2626                <meta name="ICBM" content="42.544396, -83.213255"> 
    2727                <meta name="DC.title" content="Feed Me Links!"> 
    28                 <link rel="stylesheet" type="text/css" href="style/new-portal.css" title="default stylings"> 
     28                <link rel="stylesheet" type="text/css" href="style/main.css" title="default stylings"> 
    2929        </head> 
    3030 
     
    6464                </div> 
    6565                 
    66 <link rel="stylesheet" type="text/css" href="/style/new-portal.css"> 
     66<link rel="stylesheet" type="text/css" href="/style/main.css"> 
    6767<style type="text/css"> 
    6868        .peepBox { 
  • feedmelinks/testing/contacts.php

    r475 r1278  
    1111 
    1212%> 
    13         <link rel="stylesheet" type="text/css" href="/new-portal.css" title="default stylings"> 
     13        <link rel="stylesheet" type="text/css" href="/style/main.css" title="default stylings"> 
    1414 
    1515<pre>