Location: PHPKode > projects > FeedMeLinks, Social BookmarkingSince2002 > folder-as-rss.php
<%
  Header( "Content-type: text/xml");
	# $Id: folder-as-rss.php,v 1.16 2005/11/20 15:06:50 hirokai Exp $

	include_once( "modules/utils.inc.php" );
	$tok =  $authenticated = $_COOKIE["c_pass_token"];
	$u   =  $sessionUserId = $_COOKIE["c_uid"];

	include_once( "$modules/get-option.inc.php" );
	$MAX = 10;
	$page = "folder-as-rss";
	if( ! $sortOrder )
		$sortOrder = "createDate";
	$direction = $sortOrder == name ? "ASC" : "DESC";


	# first, set up options and defaults.
	$MAX_URL_LENGTH = 40;
	$MAX_NAME_LENGTH = 40;

	$showURLs = false;
	$USE_LONG_URLS = false;
	$errors = 0;

	$con_folderAsRss = mysql_connect();
	mysql_selectdb( getDBName() );
	$magick = 1;
	$shouldDump = 1;
	$hotRow = -1;

	if( $shouldDump ) {
		$columnCount = $showURLs ? 7 : 6;

		$singleGroup = $folder ? true : false;
		$unfiled = ($folder == "unfiled" ? true : false);

		if( $singleGroup ) {
			if( $debug ) {
				echo "singleGroup: $singleGroup<br />";
				}

			if( !$unfiled ) {
				$qs = "SELECT * from linksGroups WHERE id=$folder";
				$q = mysql_query( $qs );
				$singleGroupName = makeSafeName( mysql_result($q,$i,"name") );
				$owner = mysql_result($q,$i,"userid");
			} else
				$singleGroupName = "unfiled";

				if( $debug ) {
					echo "singleGroupName: $singleGroupName<br />";
					if( isPublic( $singleGroupName ))
						echo "isPublic( $singleGroupName ) = true<br />";
					else
						echo "isPublic( $singleGroupName ) = false<br />";
				}

			if( $unfiled || $q ) {
				if( $debug) 
					echo "group id $folder (named $singleGroupName) exists<br>";	
				if( $unfiled || $sessionUserId == mysql_result($q,$i,"userid") ) {
					$owned = true;
				}
				if( $owned || isPublic( $singleGroupName ))  {
					if( $debug && $owned ) echo "owned: TRUE<br />";
					if( isPublic( $singleGroupName )) {
						$pubFolder = true;
						$singleGroupName = substr( $singleGroupName, 2, strlen( $singleGroupName ) );
					}
					if( $pubFolder )
						$whereClause = " WHERE 
								l.groupid=$folder ";
					else
						$whereClause = " WHERE 
								l.groupid=$folder AND
								l.submitter='$sessionUserId' ";
								if( $debug )
									echo "whereClause: $whereClause<br />";

						$qs = "SELECT * FROM links AS l, linksCategoriesXRef AS x WHERE l.ID = x.linkID AND x.catID = $folder ORDER BY $sortOrder $direction;";
				} else {
					$errors = 1;
					$errorMesg = "don't see any public " . getCatsName() . " with that ID number (\"$folder\"), jocko.  try checking the public " . getCatsName() . " section ($site/list-public)."; 
				}
			}
		} else {

			$qs = "SELECT * from linksGroups";
			$q = mysql_query( $qs );

			$numRows = mysql_num_rows($q);
			$whereClause = "WHERE ";
			if( $numRows ) {
				$i = $j = 0;
				while ($i < $numRows) {
					$id = mysql_result($q,$i,"ID");
					$name = makeSafeName( mysql_result($q,$i,"name"));
					if( isPublic( $name ))  {
						$groups[$id] = substr( $name, 2, strlen( $name ) );
						if( $j != 0 ) 
							$whereClause = " $whereClause OR";
						$whereClause = "$whereClause groupid=$id";
						$j++;
					}
					$i++;
				}
			}
			$qs = "SELECT * from links as l $whereClause ORDER BY $sortOrder $direction";
		}

    $title = $owner . "'s " . $singleGroupName . " - a FeedMeLinks public " . getCatName() . "";
%>
<<%= "?" %>xml version="1.0"?>
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">
<rss version="0.91">
  <channel>
    <title><%= $errors ? "private " . getCatName() : $title %></title>
    <description><%= $errors ? "this " . getCatName() . " is not available as RSS" : $title %></description>
    <managingEditor><%= getEmailAddressForUser( $owner ) %></managingEditor>
    <webMaster>hide@address.com</webMaster>
    <link><%= $site %></link>
    <language>en-us</language>
<%
		if( ! $errors ) {

			if( $debug ) 
				echo "$qs<br>";
			$q = mysql_query( $qs );
			if( $debug) echo "ran \$qs<br>";
			if( $q ) 
				$numRows = mysql_num_rows($q);
			if( $debug) echo "there were $numRows rows<br>";

			$groupParam = $singleGroup ? "folder=$folder&" : "";
			if( $numRows ) {
				$bg = "bgcolor='#888888'";
		$i = 0;
		while ($i < $numRows && $i < $MAX) {
			$id          = mysql_result($q,$i,"ID");
			$userId      = makeSafeName( mysql_result($q,$i,"submitter"));
			$groupid = mysql_result($q,$i,"groupid");
			$group = $singleGroup ? $singleGroupName : $groups[$groupid];
			$group = $group ? $group : "unfiled";
			if( !$unfiled && $group == "unfiled" )
				break;
			if( $prevGroup != $group && $sortOrder == "groupid" ) {
				$bg = "bgcolor='white'";
				$prevGroup = $group;
			}
			$group = $group ? $group : "...";
			$url         = makeSafeName( mysql_result($q,$i,"url"));

			$regex = "/(gif|jpg)/";
			$imageLink = "";
			if( preg_match( $regex, $url )) {
				$imageLink = "<b>[<font color=\"#ff0000\">i</font><font color=\"#51A168\">m</font><font color=\"#0000ff\">g</font>]</b> ";
			}

			$name        = makeSafeName( mysql_result($q,$i,"name"));
			$ctime = urldecode( mysql_result($q,$i,"createDate"));
			$createDate  = formatTS( mysql_result($q,$i,"createDate"));
			$lastMod     = formatTS( mysql_result($q,$i,"lastMod"));
			$isPrivate   = mysql_result($q,$i,"isPrivate");

			if( $id == $hotRow ) { $bg = "bgcolor='red'"; } else { 
			if( $i % 2 == 0 )
				$bg = "bgcolor='#eeeeee'";
			else
				$bg = "bgcolor='#ffffff'";
			}
%>
	<%
		if( strlen( $name ) > $MAX_NAME_LENGTH ) 
			$displayName = substr( $name, 0, $MAX_NAME_LENGTH ) . "...";
		else
			$displayName = $name;

		# THIS WILL BREAK : FIXME:
		if( ! preg_match( "/&(amp|apos)/", $displayName ))
			$displayName = htmlentities( $displayName );
		if( ! preg_match( "/&(amp|apos)/", namedisplayName ))
			$name = htmlentities( $name );
		$url = preg_replace( "/&/", "&amp;", $url );
%>
<item>
  <title><%= $displayName %></title>
  <link><%= $url %></link>
  <description><%= $name %></description>
<% if( $showURLs ) {
		$tmpurl = $url;
		if( ! $USE_LONG_URLS ) {
			$tmpurl = str_replace ( "http://", "", $tmpurl);
			$tmpurl = str_replace ( "https://", "[s] ", $tmpurl);
			$tmpurl = str_replace ( "ftp://", "[f] ", $tmpurl);
			$tmpurl = str_replace ( "www.", "", $tmpurl);
		}
		if( strlen( $tmpurl ) > $MAX_URL_LENGTH ) 
			$tmpurl = substr( $tmpurl, 0, $MAX_URL_LENGTH ) . "...";
%>
		<a href="/t/<%= $id %>"><%= $tmpurl %></a>
<% } %>
<% //   <pubDate>%= $createDate %</pubDate> %>
</item>
<% 
	$i++;
		}
		conClose( $con_folderAsRss );
	} // echo "that group's empty, bucko.<br>";
%>

<%
	} else {
%>

<item>
	<title>PRIVATE FOLDER</title>
	<link><%= $site %>/list-public</link>
	<description> <%= $errorMesg %> </description>
</item> 

<% } %>

  </channel>
</rss>
<%
}
%>

<% if( !$errors && !$i ) { %>
this <%= getCatName() %>'s empty.

view <a href="/list-public">other <%= getCatsName() %></a>.
<% } %>



Return current item: FeedMeLinks, Social BookmarkingSince2002