Location: PHPKode > projects > FeedMeLinks, Social BookmarkingSince2002 > comments.php
<%
	# $Id: comments.php,v 1.9 2004/10/31 21:41:19 hirokai Exp $
	include_once( "modules/utils.inc.php" );
	$site = getSiteUrl();

	$tok =  $_COOKIE["c_pass_token"];
	$u   =  $_COOKIE["c_uid"];
	$sessionUserId = $u;

	if( ($tok && $tok == md5( getPasswdForUser( $u ))) || $who ) { 
		$authenticated = 1;
		$user = $who ? $who : $sessionUserId;
%>

<title> Feed me comments </title>

<% 
	include( "$modules/header.inc.php" ); 
%>

<h3>
<% 
	if( $who ) 
		echo "Comments by and about $who";
	else
		echo "My Comments";
%>
</h3>

<div style="width: 630px; height: 400px;">

<div class="column" style="float: left;">
	<span style="font-weight: bold; text-transform: uppercase">others' comments on <%= $who ? $who . "'s" : "YOUR" %> links:</span>
	<div class="onepxlline">&nbsp;</div>
	<br />

<%
	chdir( getHomeDir() );
	$cmd = "find _comments/$user -type f | xargs -n1 grep -H -v $user | sort -rk 2";
	if( $debug )
		echo "$cmd<br />";
	$n = exec( "$cmd | wc -l" );
	$o = exec( $cmd, $oba, $r );
	$c = 1; # counter
	if( $debug )
		echo "\$r: $r<br />";
	
	
	if( $r == 0 || $r == 1 ) {
		if( $debug )
			echo "got here<br />";
%>
		<b><%= $n %> <%= $n == 1 ? "comment" : "comments" %></b>:<br />
<%
		
		foreach ($oba as $line) {
	
			preg_match("/comments\/$user\/(\d+).*:([^,]+), ([^,]+), (.*)$/", $line, $matches );
			$linkId = $matches[1];
			$commentor = $matches[2];
			$date = $matches[3];
			$comment = $matches[4];
	
			echo "$c)  by ";
			echo makeUserLink( $commentor ) . " on ";
			echo formatTS( $date ) . " :\n";
			echo "<br />\n";
			echo "&nbsp; &nbsp; ";
			echo makeLinkOut( $linkId ) . " ";
			echo makePermaLink( $linkId );
			echo "<br />\n";
			echo "&nbsp; &nbsp; <em>$comment</em>\n";
			echo "<br />\n";
			echo "<br />\n";
			$c++;
		}
	} else {
%>
<!-- DEBUG:
$o: <%= $o %>
<%= $cmd %> failed with code <%= $r %>!
-->

<center>(nobody's added comments to <%= $who ? "$user's" : "your" %> links yet)</center>
<br />
<%
	}
%>

	<br />
	<span style="font-weight: bold; text-transform: uppercase">
	<%= $who ? ($who . "'s comments on his own links") : "Your comments on your own links" %>:</span>
	<div class="onepxlline">&nbsp;</div>
	<br />

<%
	$c = 1; #counter
	$the_dir = getHomeDir() . '/_comments/' . $user;
	if( is_dir( $the_dir )) {
	chdir( $the_dir );
	$cmd = "grep -l '^$user' * | sort -rn";
	$n = exec( "$cmd | wc -l" );
	exec( $cmd, $oa, $r );
	
	echo "<b>$n comments</b><br />\n";
	foreach ($oa as $commentFile) {
		$id = substr( $commentFile, 0, -4 ); # trim the ".txt" extension
		
		$cmd = "cat $commentFile | grep '^$user' | wc -l";
		$yrComments = exec( $cmd );

		if( $yrComments != 0 ) {
	
			$cmd = "wc -l $commentFile | awk '{print $1}'";
			$totalComments = exec( $cmd );
			
			echo "$c : <a href=\"/$id\">$yrComments comment" . ($yrComments == 1 ? "" : "s" ) . "</a> on ";

			echo makeLinkOut( $id ) . " ";
			echo makePermaLink( $id );
			if( $yrComments != $totalComments ) {
				echo " ($totalComments total)\n";
			}
			echo "<br />\n";
				$c++;
			}
		}
	} else {
%>
<!--
DEBUG: 
<%= $cmd %> failed with code <%= $r%> !
-->
<center>
(<%= $who ? "$who hasn't" : "you haven't" %> any comments to your links)
</center>
<br />
<%
	} # end if dir exists:
%>

</div>

<div class="column" style="float: right;">
	<span style="font-weight: bold; text-transform: uppercase"><%= $who ? $who . "'s" : "" %> comments on others' links:</span>
	<div class="onepxlline">&nbsp;</div>
	<br />

<%
	chdir( getHomeDir() );
	$cmd = "find _comments/ -type f | sort -r | xargs -n1 grep -H $user, | grep -v comments/$user | sort -r -k 2";
	if( $debug )
		echo "$cmd<p />";
	$n = exec( "$cmd | wc -l" );
	$o = exec( $cmd, $oca, $r );
	$c = 1; # counter
	
	if( $n != 0 ) {
		echo "<b>$n comments</b><br />\n";
		foreach ($oca as $line) {
	
			preg_match("/comments\/(\w+)\/(\d+).*:([^,]+), ([^,]+), (.*)$/", $line, $matches );
			$linkId = $matches[2];
			$commentor = $matches[1];
			$date = $matches[4];
			$comment = $matches[5];
	
			echo "$c : on ";
			echo formatTS( $date ) . " :\n";
			echo makeUserLink( $commentor ) . "'s\n";
			echo makeLinkOut( $linkId ) . " ";
			echo makePermaLink( $linkId );
			echo "<br />\n";
			echo "&nbsp; &nbsp; <em>$comment</em>\n";
			echo "<br />\n";
			echo "<br />\n";

			$c++;
		}
	} else {
%>
<center>(<%= $who ? "$user has" : "you've" %> made no comments here yet)</center>
<br />
<!-- DEBUG:
$o: <%= $o %>
<%= $cmd %> failed with code <%= $r %>!
-->
<%
	}
%>

</div>

</div>

<br />
<br />
<div width="650">
<% include( "$modules/footer.inc.php" ); %>
</div>

<% } else {  %>
<%= bounceTo( $site . "/login?bounceToPage=" . urlencode( "comments" )) %>
<% } %>

Return current item: FeedMeLinks, Social BookmarkingSince2002