Location: PHPKode > projects > FeedMeLinks, Social BookmarkingSince2002 > feedmelinks.com/folder.php
<%
	ob_start();
	include_once( "modules/class.gzip_encode.inc.php" );

	# $Id: folder.php,v 1.58 2005/11/20 05:46:34 hirokai Exp $

	include_once( "modules/utils.inc.php" );
	$site = getSiteUrl();

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

	include_once( "$modules/get-option.inc.php" );

	if( $sidebar ) {
		include_once( "folder-sidebar.php" );
	} else {

	$page = "folder";
	if( ! $sortOrder )
		$sortOrder = "groupid";
		$direction = $sortOrder == name ? "ASC" : "DESC";

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

	$showURLs = false;
	$USE_LONG_URLS = false;
	$errors = 0;
	$condensed = ($condensed || $short) ? 1 : 0;
	if( $folder || $id )
		$folder = $id ? $id : $folder;
	$id = $folder;
	$unfiled = ($folder == "unfiled" ? true : false);
	$fName = getNameForFolder( $id );
	if( $folder != "unfiled" ) {
		$public = isPublic( getNameForFolder( $id )) ? "1" : "0";
		$owner = getOwnerForFolder( $folder );
		if( $_internal == 1 ) {
			$old_u = $u;
			$u = $owner;
		}
		$owned = $owner == $u ? 1 : 0;
	} else {
		$public = 0;
		$owned = 1;
	}

	if( $debug ) {
		echo d( "owned: $owned<br/>"
		.  "getOwnerForFolder($id): " . getOwnerForFolder( $id ) . "<br/>"
		. "id: $id<br/>"
		. "ENV: $env<br />"
		. "db: " . getDBName() );
	}

	$noHead = $noBody = $noMenu = true;
	if( ! $condensed ) { 
		include_once( "$modules/header.inc.php" ); 
	} else {
		include_once( "$modules/header.insecure.inc.php" ); 
	}
	if( $folder || $id ) { 
		$folder = $id ? $id : $folder;
		$con_folder = mysql_connect();
		mysql_selectdb( getDBName() );
		$shouldDump = 1;

		if( $shouldDump ) {
			$columnCount = $showURLs ? 7 : 6;
			$singleGroup = $folder ? true : false;
			$unfiled = ($folder == "unfiled" ? true : false);

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

				if( !$unfiled ) {
					$qs = "SELECT * from linksGroups WHERE id = $folder";
					if( $debug )
						e( "QS: " . $qs);
					$q = mysql_query( $qs );
					$numRows = $q ? mysql_num_rows($q) : 0;
					if( $q && $numRows ) {
						$singleGroupName = makeSafeName( mysql_result($q,$i,"name") );
						$email = getEmailAddressForUser( mysql_result($q,$i,"userid"));
					} else {
						$errors = 1;
%>

<div class="attention">
Sadly, no such folder exists.<br />
Please double-check the URL, or try visiting the list of <a href=\"/list-public\">public <%= getCatsName() %></a>.
</div>

<%
				}
			} else
				$singleGroupName = "unfiled";

				if( $debug ) {
					echo d( "singleGroupName: $singleGroupName");
					if( isPublic( $singleGroupName ))
						echo d( "isPublic( $singleGroupName ) = true" );
					else
						echo d( "isPublic( $singleGroupName ) = FALSE" );
				}

			if( $unfiled || $q ) {
				if( $debug) 
					echo d( "group id $folder (named '$singleGroupName') exists" );	
				if( $numRows )
					$owner = mysql_result($q,$i,"userid");
				if( $unfiled || $u == $owner) {
					$owned = true;
				}
				if( $owned || isPublic( $singleGroupName ))  {
					if( isPublic( $singleGroupName )) {
						$pubFolder = true;
						$singleGroupName = substr( $singleGroupName, 2, strlen( $singleGroupName ) );
					}

					# UNFILED FOLDER:

					if( $unfiled ) {
						$sortOrder= "createDate";
						$direction= "DESC";
						$qs = getQuery( "unfiled" ) .  "AND links.submitter = '$u' ORDER BY $sortOrder $direction";
						if( $debug ) 
							echo "<div class='debug'>using the first query: <br />$qs</div>";

				# NORMAL FOLDER

				} else {
					if( $debug ) 
						echo "<br />using the second query<br />";
					if( $pubFolder )
						$whereClause = " WHERE 
								l.groupid=$folder ";
					else
						$whereClause = " WHERE 
								l.groupid=$folder AND
								l.submitter='$u' ";
								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;";
					if( $debug )
						e( "QS: " . $qs );

					}
			} else { 
				if( $errors != 1 ) {
					$errors = 1;
					echo "<br>Unfortunately, this " . getCatName() . " (ID #$folder) isn't public, bub.<br />
					Try <a href=\"mailto:$email\">emailing the " . getCatName() . " owner ($owner)</a> and asking him to make it public,<br />
				 or check the <a href=\"/list-public\">public " . getCatsName() . " section</a>."; 
			 }
			}
		}
	} 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, linksComments as x $whereClause ORDER BY $sortOrder $direction";
	}
	if( $owned ) {
		$title = "My $singleGroupName " . getCatName();
	} else {
		if( $public ) {
			$title = "$owner's $singleGroupName (a public " . getCatName() . ")";
		} else {
			$title = "a private " . getCatName() . " (owned by $owner)";
	 }
 }
%>
<title> Feed Me Links : <%= $title %> </title>

<style type="text/css">
.r1, .r0 { height: 1.5em; }
</style>
</head>
<% if( ! $condensed ) { %>
<body>
<%
	include_once( "$modules/menu.inc.php" ); 
%>
<br />
<br />
<% } %>

	 <%
				if( $owned ) {
%>
&laquo; <a href="/u/<%= $u %>/tags">back to my list of <%= getCatsName() %></a>
<%
				}
	if( ! $errors ) {

		$q = mysql_query( $qs );
		if( $debug) 
			echo d( "ran \$qs" );
		if( $q ) 
			$numRows = mysql_num_rows($q);
		if( $debug) 
			echo d( "there were [" . $numRows . "] rows" );

		$groupParam = $singleGroup ? "id=$folder&amp;" : "";
		if( $numRows ) {

			if( $owned && !$condensed ) { %>

<script language="javascript">

 var numSelected = 0;
 var numLinks = <%= $numRows %>;

	function updateSelectedTotal( cb ) {
		numSelected = cb.checked ? numSelected + 1 : numSelected - 1;
	}

	function doSelected( arg ) {
		if( numSelected ) {
			document.forms.folderForm.op.value = arg;
			document.forms.folderForm.submit();
		} else 
			alert( "Select some links first, please." );
	}

	function tagSelected() {
		var f = document.forms.folderForm.newFolderID;
		if( f.selectedIndex != 0 )
			doSelected( "tag" );
		else
			alert( "Choose a tag first, please." );
	}

	function untagSelected() {
		doSelected( "untag" );
	}

	function publicizeSelected() {
		doSelected( "makePublic" );
	}

	function privatizeSelected() {
		doSelected( "makePrivate" );
	}

	function deleteSelected() {
		if( numSelected ) {
			if( confirm( "Delete " + ( numSelected == 1 ? "this link" : "these " + numSelected + " links" ) + " permanently?" )) { 
				document.forms.folderForm.op.value = "deleteSelected";
				document.forms.folderForm.submit(); 
			}
		} else 
			alert( "Select some links first, please." );
	}

	function selectAllLinks( argForm ) {
		var f = argForm;
		toggle = f.selectAll.checked;
		for( i=0; i<f.elements.length; i++ ) {
			if( f.elements[i].name && !isNaN( f.elements[i].name ))
				f.elements[i].checked = toggle;
		}
		numSelected = numLinks;
	}

</script>

<form method="post" action="/action" name="folderForm">
&nbsp; (<a href="/edit-folder?op=edit&id=<%= $id %>&name=<%= urlencode( $fName ) %>&options=">click to edit this <%= getCatName() %>'s name</a>)
<p />
		<% } %>

<!-- start block -->
<!-- start row -->
<div class="box">
	<div class="subhead">
<% if( $public && (!$owned)) { %>
	<a class="link" href="/u/<%= $owner %>"><%= $owner %>'s <%= getCatsName() %></a>
<% } else { %>
	<a class="link" href="/index">my <%= getCatsName() %></a> 
<% } %> / <b><%= makePrettyFolderName( getNameForFolder( $folder )) %></b>
<% 
	echo " ($numRows links) &nbsp;";
	if( ! $public && ! $_internal ) { 
	%><img src="/img/lock" /><% 
	} 
	if( $condensed ) { %>
	<a class="link" href="/f/<%= $folder %>">(view expanded)</a>
<% } else { %>
	<a class="link" href="/f/<%= $folder %>/c">(view condensed)</a>
<% } %>

<% if( !$condensed ) { %>

	<% if( $sortOrder != "name" ) { %>
		<a class="link" title="sort by name" href="/f/<%= $folder %>/by-name">(sort by name)</a>
	<% } %>

	<% if( $sortOrder != "createDate" ) { %>
		<a class="link" title="sort by date" href="/f/<%= $folder %>/by-date">(sort by date)</a>
	<% } %>

<% } else { %>

	<% if( $sortOrder != "name" ) { %>
		<a class="link" title="sort by name" href="/f/<%= $folder %>/c/by-name">(sort by name)</a>
	<% } %>

	<% if( $sortOrder != "createDate" ) { %>
		<a class="link" title="sort by date" href="/f/<%= $folder %>/c/by-date">(sort by date)</a>
	<% } %>

<% } %>

<% if( $owned ) { %>
<% if( !$condensed ) { %>
	&nbsp; 
	select
	<input type="checkbox" name="selectAll" onChange="selectAllLinks(document.forms.folderForm);"/>
<% } %>
<% } else if( ! $condensed ) { %>
|
	snatch
<% } %>
	</div>
<!-- end row -->

<%
	$i = 0;
	while ($i < $numRows) {
		$id          = mysql_result($q,$i,"ID");
		$userId      = makeSafeName( mysql_result($q,$i,"submitter"));
		$folderId = mysql_result($q,$i,"groupid");
		$group = $singleGroup ? $singleGroupName : $groups[$folderId];
		$group = $group ? $group : "unfiled";
		if( !$unfiled && $group == "unfiled" )
			break;
		if( $prevGroup != $group && $sortOrder == "groupid" ) {
			$bg = "class='header2'";
			$prevGroup = $group;
%>
<% 
			if( !$owned && !$condensed ) {
%>
<!-- start row -->
<div class="r1">
	(owned by <b><%= makeUserLink( $userId ) %></b>)
</div>
<% 		} %>
<!-- end row -->

<%
		}
		$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");
		$id   = mysql_result($q,$i,"id");

		if( $i % 2 == 0 )
			$bg = "r0";
		else
			$bg = "r1";
%>
<!-- start row -->
<div class="<%= $bg %>">
<%
	if( strlen( $name ) > $MAX_NAME_LENGTH ) {
		$displayName = substr( $name, 0, $MAX_NAME_LENGTH ) . "...";
		$comment = $name;
	} else 
		$displayName = $name;
%>
	<div style="float: left;">
	<%= insertImageLinkIcon( $url ) %>
	<%= makeNamedLinkOut( $id, $displayName) %> <%= makePermaLink( $id ) %>

	</div>
	<div style="float: right;">
		<span class="subtle"><%= $createDate %></span>
<% if( ! $owned ) { 
			if( !$condensed ) { 
%>
		&nbsp;<%= makeStealItLink( $id ) %>
<% }
	} else {
	
		if( !$condensed ) {
%>
		<%= makeEditLink( $id ) %>
		<%= makeDeleteLink( $id ) %>
		<input type="checkbox" name="<%= $id %>" onChange="updateSelectedTotal(this);" />
<% } %>
	<br clear="all">
<% } %>
	</div>

</div>
<!-- end row -->

<% $i++; %>
<%
	}
	conClose( $con_folder );
%>

<% if( $owned && !$condensed) { %>
<!-- start row -->
<div class="r1 last">

	<%= getCatVerb() %> selected links as: 
	<select name="newFolderID">
	<% include( "$modules/folder-menu.inc.php" ); %>
	</select>
	<input type="hidden" name="op" value="tag" />
	<input type="hidden" name="debug" value="<%= $debug %>" />
	<input type="hidden" name="folderID" value="<%= $folder %>" />
	<input class="button" type="button" name="tagButton" value="tag" onClick="tagSelected()"/>
</div>

<div class="r1 last">
	make selected links:
	<input class="button" type="button" name="makePrivateButton" value="private" 
		onClick="privatizeSelected()"/>
	/ 
	<input class="button" type="button" name="makePublicButton" value="public" 
		onClick="publicizeSelected()"/>
	
	&nbsp;<input class="button" type="button" name="deleteButton" value="delete selected" 
		onClick="deleteSelected()"/>

	&nbsp;<input class="button" type="button" name="untagButton" value="untag selected" 
		onClick="untagSelected()"/>
</div>

<br>

<%
	$rss_url = "/f/$folder/rss";
%>
An <a title="subscribe to '<%= $groupName %>'" href="<%= $rss_url %>"><img src="/img/xml" alt="RSS Feed" border="0" /></a> feed of this tag is available.
<span class="subtle">(<a href="http://feedmelinks.com/help/including-feeds">Huh?</a>)</span>
<!-- for clients with auto-discovery -->
<link rel="alternate" type="application/rss+xml" title="RSS Feed of <%= $userId %>'s <%= $singleGroupName %> Links" href="<%= $rss_url %>">

<% if( $debug ) { %>
<input type="hidden" name="debug" value="1" />
<% } %>
<!-- end row -->

<!-- end block -->
</div>

<br />
</form>
<%= getColorKey() %>
<% } else { %>

<!-- end block -->
<% } %>


</div>

<% if( !$condensed && !$owned ) { %>
(the "snatch" button adds a link to your links)
<%
	} 
	} // echo "that group's empty, bucko.<br>";
%>

<%
		}
	} # no folder passed
} else {
	$errors = 1;
%>
<title> Feed Me Links : Error : no <%= getCatName() %> </title>

<div class="attention">
	no <%= getCatName() %> to show.
	<p/>
	[<a href="/">back to the FEED ME LINKS homepage</a>]
</div>

<% } %>

<% if( !$condensed && !$errors && !$i ) { %>
<br />
<div class="welcome">

	<small>(<%= $title %>)</small><br />
	You have no links tagged with: <nobr><u><%= $singleGroupName %></u></nobr>.
</div>
<br />
<br />

view <a href="/list-public">other <%= getCatsName() %></a>.
</form>
<% 
		} 
		if ( ! $condensed ) { 
			echo "<br />\n"; 
		}
		include( "$modules/footer.inc.php" ); 
	}

	$u = $old_u;

	new gzip_encode();
%>
Return current item: FeedMeLinks, Social BookmarkingSince2002