Location: PHPKode > projects > FeedMeLinks, Social BookmarkingSince2002 > feedmelinks.com/modules/recent-with-times.inc.php
<%
	include_once( "$modules/utils.inc.php" );

	$limit = $links_per_page ? $links_per_page : $limit;
	$limit = $limit ? $limit : 7;
	$limit = $limit > 40 ? 40 : $limit;
	$limit = 2 * $limit;
	$start = $start ? $start : 0;

	if( $user ) {
		$pass = $PHP_AUTH_PW ? $PHP_AUTH_PW : $password;
		$u    = $PHP_AUTH_USER ? $PHP_AUTH_USER : ( $user ? $user : $_COOKIE["c_uid"] );
		$tok =  $authenticated = $_COOKIE["c_pass_token"];

		if( $u && ($pass && $pass == getPasswdForUser( $u ) || ($tok && $tok == md5( getPasswdForUser( $u ))))) {
			$qs = getQuery( "recent_for_user_pageable", $user, $start, $limit );
		} else {
			echo "log in first\n";
			return;
			exit;
		}

	} else {
		if( $go == "back" ) {
			$start = (!$start) ? 0 : $start - ($links_per_page * 3);
			$start = ($start < 0) ? 0 : $start;
			echo "\nbackpedalling; start: $start\n\n";
			$limit = $links_per_page * 3;
			}
		$qs = getMasterQuery() . "ORDER BY ID DESC LIMIT $start, $limit;";
	}

	if( $interactive ) {
%>
<p>
	<script language="javascript">
	var start = <%= $start %>;
	var limit = <%= $limit %>;
	function go( argNum ) {
		var f = document.forms.cruiser_form;
		var x = (limit * argNum ) + start;
		x = (x>0) ? x : 0;
		f.start.value = x;
		f.submit();
	}
	</script>
	<form name="cruiser_form">
		<input type="hidden" name="start" value="<%= $start %>">
		<input type="button" value="&laquo; BACKWARD!" onClick="go( -1 );">
		<select name="links_per_page" onChange="document.forms.cruiser_form.submit();">
			<option value="10" <%= $links_per_page == 10 ? "selected" : "" %>> 10 </option>
			<option value="20" <%= $links_per_page == 20 ? "selected" : "" %>> 20 </option>
			<option value="30" <%= $links_per_page == 30 ? "selected" : "" %>> 30 </option>
			<option value="40" <%= $links_per_page == 40 ? "selected" : "" %>> 40 </option>
		</select>
		<input type="button" value="FORWARD! &raquo;" onClick="go( 1 );">
	</form>
		<center><small>links per page</small></center>
</p>
<%
	}

	if( $format == "nvp" ) {
		echo "&numLinks=" . ($limit / 2 ) . "&\n";
		echo "&site=http://feedmelinks.com&\n";
		echo "\n";
		$cached_links = array();
	}

	$con = mysql_connect();
	mysql_selectdb( getDBName() );
	$q = mysql_query( $qs );
	$numRows = $q ? mysql_num_rows( $q ) : 0;
	$format = $format ? $format : "1-per-line";
	$lastID = "";
	$realCount = 0;
	for( $i = 0; ($i < $numRows && $realCount < $limit / 2 ); $i++ ) {

		$id = mysql_result($q,$i,"ID");
		$user = urldecode( mysql_result($q,$i,"u"));
		$name = urldecode( mysql_result($q,$i,"name"));
		$time = mysql_result($q,$i,"time_ago");
		$tag = mysql_result($q,$i,"tag");
		$tagID = mysql_result($q,$i,"tagID");

		if( $format == "1-per-line" ) {
			if( $id == $lastID ) {
				echo ", " . getTagLink( $tagID, $tag );
			} else {
				if( $i != 0 ) {
%>
</div>
<% 			} %>
<div class="r<%= $realCount % 2 == 0 ? 1 : 0 %><%= $realCount == $limit - 1 ? " last" : "" %>">
	<%= makeNamedLinkOut( $id, getCompactString( urldecode( $name ) ) ) %> <%= makePermaLink( $id ) %> - <%= makeUserLink( $user ) %>
	<% if( !$hideTimes ) { %><span class="subtle">(<%= $time %>&nbsp;ago)</span><% } %>
	in <%= getTagLink( $tagID, $tag ) %>
<%
			if( $debug )
				echo "\$i: $i, \$realCount: $realCount, \$limit: $limit ";
			if($i == $numRows - 1 || $realCount + 1 == $limit / 2 ) {
				echo "\n</div>\n";
			}
    ++ $realCount;
		}
		$lastID = $id;

	} else if( $format == "nvp" ) {
		$link = array();

		$link["id"]    = mysql_result($q,$i,"ID");
		$link["user"]  = urldecode( mysql_result($q,$i,"u"));
		$link["tagID"] = mysql_result($q,$i,"tagID");
		$link["tag"]   = mysql_result($q,$i,"tag");
		$link["time"]  = mysql_result($q,$i,"time_ago");
		$link["name"]  = urldecode( mysql_result($q,$i,"name"));

		array_push( $cached_links, $link );

	# TODO

	} else if( $format == "rss" ) {
		$user = makeSafeName( $user );
		$infoURL = get_site() . "/u/" . $submitter;
		$fURL = get_site() . "/f/" . $f;
		$url = urldecode( mysql_result($q,$i,"url"));
		$dcDate = formatAsDCDate( mysql_result($q,$i,"createDate") );
		$uDate  = formatTS( mysql_result($q,$i,"createDate") );
		$name = str_replace ( "&", "&amp;", $name);
			
		if( $id != $lastID ) {
%>
<item>
  <title><%= $user . " : " . $name %></title>
	<link><%= get_site() %>/<%= $id %></link>
	<description>added by: <%= $user %></description>
	<guid isPermaLink="true"><%= get_site() %>/<%= $id %></guid>
	<content:encoded><![CDATA[
		<p>
			<a href="<%= $url %>"><%= $url %></a> - <%= $uDate %><br />
			<small><a href="<%= get_site() . "/$id" %>">view link info</a> [link no. <%= $id %>]</small>
			<p>
				<a href="/g/<%= ( $id ) %>">
				grab this link <img src="<%= get_site() . '/img/plus.gif' %>" border="0" /></a>
			</p>
		</p>
		<%= $i == 0 ? getCommentCSS() : "" %>
		<%= getCommentsForLink( $id, "nobody", $debug ) %>
		<% $cats = getCategoriesForLinkAsRss( $id, "nobody", "add-trailing-noun=1", 0 ); %>
	]]></content:encoded>
	<dc:subject><%= $cats ? "$cats" : "(" . getUnCattedName() . ")" %></dc:subject>
	<dc:date><%= $dcDate %></dc:date>

</item>
<%
	}
	$lastID = $id;
	} else {
		# sidebar
		if( $id == $lastID ) {
			echo ", " . getTagLink( $tagID, $tag );
		} else {
		++ $realCount;

		$url = urldecode( mysql_result($q,$i,"url"));
%>
</div>
<div class="r<%= $realCount % 2 == 0 ? 1 : 0 %><%= $i == $limit - 1 ? " last" : "" %>">
	<%= makeNamedLinkOut( $id, getCompactString( urldecode( $name ) ) ) %>
	<%= makePermaLink( $id ) %> 
	<%= getStealItLink( $id ) %>
	added by <%= makeUserLink( $user ) %>
	in <%= getTagLink( $tagID, $tag ) %><% if( !$hideTimes ) { %><span class="subtle">(<%= $time %>&nbsp;ago)</span><% } %><%
	}
	if( $i == $numRows - 1 )
		echo "</div>";
	}
	$lastID = $id;
	} # end for

	if( $format == "nvp" ) {

		if( $go == "back" ) {
			for( $j = 0; $j < sizeof( $cached_links ); $j++ ) {
				$l = $cached_links[$j];
				if( $l["id"] == $first_id ) {
					$list_end = $j;
					$found = true;
					echo "we found the starting link $first_id (" .  $l["name"] . ") at position $j\n\n";
					echo "hence, this list ends at index $list_end\n";
					break;
				}
			}
			if( ! $found )
				echo "we could not find link $first_id in the back list\n\n";
			else {
				$num_links = 0;
				for( $j = $list_end; ($j > 0 && $num_links <= $links_per_page); $j-- ) {
					$l = $cached_links[$j];
					if( $l["id"] != $last_id )
						$num_links++;
					$last_id = $l["id"];
				}
				$list_start = $j + 1;
				echo "and this list starts at index $list_start\n";
				if( $num_links >= $links_per_page )
					echo "(and we have enough ($links_per_page) links)\n";
				else
					$list_end = sizeof( $cached_links );
			}
		}

		$list_start = $list_start ? $list_start : 0;
		$list_end = $list_end ? $list_end : sizeof( $cached_links ); 

		for( $j = $list_start; ($j < $list_end && $realCount < $links_per_page); $j++ ) {

			$l = $cached_links[$j];
			if( $j == $list_start )
				$new_first_id = $l["id"];

				if( $l["id"] == $lastID ) {
					$tagCount++;
					echo "&tagName_" . $realCount . "_$tagCount=" . $l["tag"] . "&tagID_" . $realCount . "_$tagCount=" . $l["tagID"] . "&\n";
				} else {
					echo "&tagCount_$realCount=$tagCount&\n";
					$tagCount=1;
					$realCount++;
					echo "&name_$realCount=" . urlencode( $l["name"] ) . "&\n";
					echo "&id_$realCount=" . $l["id"] . "&\n";
					echo "&submitter_$realCount=" . $l["user"] . "&\n";
					$has_comments = has_comments( $l["id"], $l["user"] );
					if( $has_comments ) {
						echo "&hasComments_$realCount=" . num_comments( $l["id"], $l["user"] ) . "&\n";
					}
					echo "&tagName_" . $realCount . "_1=" . $l["tag"] . "&\n";
					echo "&tagID_" . $realCount . "_1=" . $l["tagID"] . "&\n";
				}
				$lastID = $l["id"];
			}

		echo "&num_db_rows=$j&\n";
		echo "&meta_info=you told us your first id was: $first_id&\n";
		echo "&meta_info=your new first id is: $new_first_id&\n";
		echo "&meta_info=we started at: $start&\n";
		echo "&meta_info=we showed you: $j rows and $realCount links&\n";
		$next_start = $start + $j;
		echo "&meta_info=next start should be: $next_start&\n";
		$prev_start = (!$prev_start && !start) ? 0 : $start;
		echo "&meta_info=you told us your previous start was: $prev_start&\n";

		$p_url = "$site/recent?go=back&start=$prev_start&first_id=$new_first_id";
		$n_url = "$site/recent?start=$next_start";
		$p_url = str_replace ( "&", "&amp;", $p_url);
		$n_url = str_replace ( "&", "&amp;", $n_url);

		echo "&prev_url=$p_url&\n";
		echo "&next_url=$n_url&\n";
		echo "&prev_start=$prev_start&\n";
		echo "&first_id=$first_id&\n";
		echo "\n\n";


		}

	conClose( $con );
%>
Return current item: FeedMeLinks, Social BookmarkingSince2002