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

	# $Id: index.php,v 1.77 2005/11/20 15:23:21 hirokai Exp $

	include_once( "modules/utils.inc.php" );
	$page = "index";

	if( ! $sortOrder )
		$sortOrder = "groupid";
	$direction = "ASC";

	$tok =  $_COOKIE["c_pass_token"];
	$u   =  $sessionUserId = $_COOKIE["c_uid"];
	
	if( (! $tok || $tok != md5( getPasswdForUser( $u )) ) && ! $l ) {
		$op = "login";
		if( $name && $url && $from ) {
			echo bounceTo( $site . "/login?name=" . urlencode( $name ) . "&url=" . urlencode( $url ) . "&from=" . urlencode( $from ));
		} else {
			if( isADevice( $HTTP_USER_AGENT )) {
				echo jsWrap( "window.location = 'http://feedmelinks.com/portal';" );
			} else {
				echo bounceTo( $site . urldecode( "/portal" ) );
			}
		} 
	} else {

		# first, set up options and defaults.
		$MAX_URL_LENGTH = 40;
		$MAX_NAME_LENGTH = 40;
		$USE_LONG_URLS = 0;
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<link rel="alternate" type="application/rss+xml" title="RSS Feed for Feed Me Links" href="http://feedmelinks.com/rss">
<title> <%= $l ? "Feed Me Links: " . getTitleForLink( $l)  : "Feed Me Links!" %> </title>
<% 
	if( $op != "delete" && $op != "commitEdit" && $u ) {
		include( "$modules/header.inc.php" ); 
%>

<br />

<%
	} else {
		include( "$modules/header.insecure.inc.php" );
	}
	$con_index = mysql_connect();
	mysql_selectdb( getDBName() );
	$showLinks = 1;
	$hotRow = -1;

	##############################################################

	if( $op == "add_comment" ) {
		addCommentToLink( $l, $comment, $u, $debug );

		if( !$debug ) {
%>
<script language="javascript"> history.go( -1 ); </script>
<%
		}
	}

	if( $l ) {
		include_once( "$modules/view-link.inc.php" );
	} else if( $mesg ) {
%>
<div class="attention">
	<b><%= $mesg %></b><br />
	<img src="img/dk-gray.gif" height="1" width="250" /><br />
</div>
<br />
<%
	}

	##############################################################
	
	if( $op == "input" ) {
		$showLinks = 0;
%>

<form>
<div class="attention">
	<b>add a link</b><br />
	<img src="img/dk-gray.gif" height="1" width="250" /><br />
  <input name="op" value="submit" type="hidden" />
<% if( $from == "toolbar" ) { %>
  return to URL after saving to my links? <input class="light" name="bounce" checked type="checkbox" />
<% } %>
<% include( "$modules/addLinkForm.inc.php" ); %>
</div>
</form>
<%

	##############################################################

	} else if( $op == "makeNewFolderAndSubmit" ) {
		if( $debug )
			echo "DEBUG: ADDING <b>$linkName</b> ($url)TO NEW FOLDER $newFolderName<br />\n";
		if( $url && $linkName ) {
			if( $newFolderName ) {
				echo "adding <b>$linkName</b> to <b>$newFolderName</b>...<br />\n";
				$url = prepURLforSubmit( $url );
				$name = urlencode( $linkName );
				$submitter = urlencode( $u );
				$isPrivate = $isPrivate ? 1 : "NULL";

				# first we create the new category
				$folderId = addFolder( $newFolderName, $u );

				# make sure the category is public, because we want new categories created public by default:
				if( $folderId ) {
					echo "created <b>$newFolderName</b>.<br />\n";
				} 

				# then we add the link:
				$q = addLink( $url, $name, $submitter, $folderId, $isPrivate, $options );
				if( $q ) {
					echo "link added!<br />\n"; 

					if( $loggedIn == "wasnt" || $newFolderName  ) {
%>
	<script language="javascript"> history.go( -3 ); </script>
<%
					} else {
%>
	<script language="javascript"> history.go( -2 ); </script>
<%
					}
				} else { # link add failed
					echo "sorry, something bad happened and your new link wasn't added.";
					echo "please click your back button and try again, or email hide@address.com<br />\n";
				}

			} else {
				echo "no new folder to create, try again."; 
			}

		} else {
			echo "no url to add, try again."; 
		}

	} else if( $op == "submit" ) {
		if( $url && $name ) {
			echo "submitting link...";
			$url = prepURLforSubmit( $url );
			$name = urlencode( $name );
			if( !$groupid || $from == "toolbar" ) {
				$groupid = "NULL";
			} else { 
				$groupid = $groupid;
			}
			$submitter = urlencode( $u );
			$isPrivate = $isPrivate ? 1 : "NULL";
			$options = ""; # not yet implemented

%>
<!-- 
	calling: _dLink( <%= $url %>, <%= $name %>, <%= $submitter %>, <%= $groupid %>, <%= $isPrivate %> );
-->
<%
			$q = addLink( $url, $name, $submitter, $groupid, $isPrivate, $options );
			if( $q ) {
				echo "link added!<br />\n"; 

				if( $from == "toolbar" || $from == "funnel" ) {
					$showLinks = 0;

					if( $loggedIn == "wasnt" ) {
					   if( preg_match( "/MSIE.*Mac/", $HTTP_USER_AGENT )) {
						 	echo "ahh, THE DREADED MAC IE.";
%>
					<script language="javascript"> history.go( -5 ); </script>
<%
						 } else {
%>
					<script language="javascript"> history.go( -3 ); </script>
<%
						 }
						 	
					} else {
%>
					<script language="javascript"> history.go( -2 ); </script>
<%
					}

				} else {
					$showLinks = 0;
					echo bounceWithDelay( urldecode( "/index" ), 1 );
				}
			} else { 
				echo "failed!"; 
			}
		} else {
			echo "no url to add, try again."; 
		}

	##############################################################

	} else if( $op == "edit" ) {
		$hotRow = $id;
%>
<form>
<input type="hidden" name="folder" value="<%= $folder %>" />
<div class="attention">
editing link '<%= $name %>':<br />
  <input class="light" name="op" value="commitEdit" type="hidden" />
<% include( "$modules/addLinkForm.inc.php" ); %>
</div>
</form>
<%

	##############################################################

	} else if( $op == "commitEdit" ) {
		if( strlen( $name ) > $MAX_NAME_LENGTH )
			$displayName = substr( $name, 0, $MAX_NAME_LENGTH ) . "...";
		else
			$displayName = $name;
%>
		<div class="small attention">
		saving <b><%= $name %></b>...
<%
			$url = urlencode( $url );
			$name = urlencode( $name );
			$groupid = ($groupid && $groupid != "unfiled") ? $groupid : "NULL";
			$createDate = urlencode( $createDate );
			$submitter = urlencode( $u );
			$options = ""; # not yet implemented
			$isPrivate = $isPrivate ? 1 : "NULL";

    $qs = "REPLACE into links values($id, '$url', '$name', '$createDate', NULL, '$submitter', $groupid, $isPrivate);";
		$q = mysql_query( $qs );
		if( $q ) { 
			$showLinks = 0;
%>
	<b>saved</b>. (window will close in 2 seconds)
		</div>
<%
			if( $from == "popup" ) {
%>

<script language="javascript">
	var timer = setTimeout( "window.close()", 2 * 1000 );
	window.resizeTo(437,146);
</script>

<%
			}
		} else { 
%>
<div class="attention">
<%= $qs %>
oh no! couldn't commit edit!
</div>
<%
		}
	
	##############################################################

	} else if( $op == "confirmDelete" ) {
		$hotRow = $id;
%>
<div class="attention">
	<b>delete link:</b>
	<br />
	<img src="img/dk-gray.gif" height="1" width="250" />
	<br />
	<br />
	are you sure you want to delete the link '<%= $name %>'?
	<p style="text-align:right;">
	<a href="<%= $page %>?op=delete&id=<%= $id %>&folder=<%= urlencode( $folder ) %>">yes</a> / <a href="<%= $page %>">no</a>
	</p>
</div>
<br />
<%

	##############################################################

	} else if( $op = "delete" ) {
		$q = deleteLink( $id, $u );
		if( $q ) {
			$showLinks = 0;
%>

<div class="small attention">
		<b>link deleted</b>. (window will close in 2 seconds)
</div>
	<script language="javascript"> 
		var timer = setTimeout( "window.close()", 2 * 1000 );
		window.resizeTo(437,146);
	</script>

<%
		} else {
			$_x = 1;
		}
	} # end if delete 
	if( $showLinks ) {
%>

<% if( $debug != "nosubmit" ) { %>

	<!-- start left -->
	<div id="leftColumn">

		<div class="box">
			<div class="subhead"> 
				<%= get_ownoun() %> <%= getCatsName() %> 
				(Sort by:

				<% if( $taglist_sort_order == "alphabetic" ) { %>
				<a href="<%= $page %>?taglist_sort_order=popularity">Popularity</a>
				<% } else { %>
				Popularity
				<% } %>
				|
				<% if( $taglist_sort_order == "alphabetic" ) { %>
				A-Z<% 
					} else { %>
				<a href="<%= $page %>?taglist_sort_order=alphabetic">A-Z</a><% 
					} %>)
			</div>

<%	
	$qs = "SELECT * from linksGroups where userid = '$u' ORDER BY name";
	$q = mysql_query( $qs );
	if( $q )
		$numRows = mysql_num_rows($q);
	else {
%>
<!-- ERROR: running <%= $qs %> -->
<%
	}
	if( $numRows ) {
		$qs2 = "SELECT count(*) FROM links WHERE submitter='$u'";
		$q2 = mysql_query( $qs2 );
		if( $q2 ) {
			$numLinks = mysql_result($q2,0);
%>
	<div class="">
		<%= printLinkCount( $numLinks ) %> total links,
<%
	$qs3 = getQuery( "num_unfiled" ) .  "AND links.submitter = '$u' ORDER BY $sortOrder $direction";

	if( $debug ) {
		e( "<br>" );
		e( $qs );
	}

	$q3 = mysql_query( $qs3 );
	$numLinks = ( $q3 && mysql_num_rows( $q3 )) ?  mysql_result($q3,0) : 0;
	$bg = "class='r0'";
%>
		<%= printLinkCount( $numLinks ) %> 
		<a href="/f/unfiled"><b><em><%= getUnCattedName() %></em></b></a>.
	</div>

<% include( "$modules/folder-list.inc.php" ); %>

<%
}
	} else {
%>
	<div>
		(You do not have any <%= getCatsName() %> yet.<br />
		Try adding some, it's much nicer that way!)
	</div>

<%
	}
%>

	<p>
		<form action="edit-folder">
		 Add <%= getCatName() %>: 
		 <input class="text" name="name" value="<%= $folderToEdit ? $folderToEdit : "Type the tag name..." %>" 
		 onFocus="if( this.value == 'Type the tag name...')this.value='';" 
		 onBlur="if( this.value == '')this.value='Type the tag name...';" 
		 type="text" 
		 size="18"
		 maxlength="36"
		 />
			<input type="hidden" name="op" value="createGroup" />
			<input type="submit" class="button" value="create" />
		</form>
	</p>
	<p>
	You can also <big><a href="/delete-unused-tags">Delete any unused tags</a></big>.
	</p>
	</div>
</div>

<div id="rightColumn">
	<div id="news" class="box">
		<% include_once( "$modules/news-divs.inc.php" ); %>
	</div>

	<% include( "$modules/recent.inc.php" ); %>
	
	<% include( "$modules/my-recent.inc.php" ); %>

	<% include_once( "$modules/random-links.inc.php" ); %>
</div>

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

<%
} // end if login
 new gzip_encode();
%>
Return current item: FeedMeLinks, Social BookmarkingSince2002