Location: PHPKode > projects > FeedMeLinks, Social BookmarkingSince2002 > testing/instrumented.php
<%
	# $Id: instrumented.php,v 1.2 2005/01/30 01:47:22 hirokai Exp $

	include_once( "modules/profiler.inc.php" ); #pp
	$prof = new Profiler( true ); #pp

	$prof->startTimer( "include_utils" ); #pp
	include_once( "modules/utils.inc.php" );
	$prof->stopTimer( "include_utils" ); #pp

	$page = "index";
	$magick = "editor";
	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">
<title> INSTRUMENTED <%= $l ? "Feed Me Links: " . getTitleForLink( $l)  : "My Links" %> </title>
<% 
	if( $op != "delete" && $op != "commitEdit" && $u ) {
		$prof->startTimer( "include_header" ); #pp
		include( "$modules/header.inc.php" ); 
		$prof->stopTimer( "include_header" ); #pp
%>

<br />
<br />

<%
	} else {
		include( "$modules/header.insecure.inc.php" );
	}
	$con_index = mysql_connect();
	mysql_selectdb( getDBName() );
	$magick = 1;
	$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;
%>

<% include( "$modules/install-reminder.inc.php" ); %>

<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,'$options', $isPrivate);";
		#echo $qs; #DEBUG
		$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 { echo "oh no! couldn't commit edit!"; }
	
	##############################################################

	} 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 ) {

		$prof->startTimer( "include_install_reminder" ); #pp
%>

<% include( "$modules/install-reminder.inc.php" ); %>

<% 
	$prof->stopTimer( "include_install_reminder" ); #pp
	%>

<!-- dumb container table -->

<table>
<tr>
<td valign="top">


<% if( $debug != "nosubmit" ) { %>
<a href="comments"><span class="head">YOUR COMMENTS</span></a>. (click to view all)

<!-- div class="attention" style="width: 340px">
<% #include( "$modules/cominfo.inc.php" ); %>
</div -->

<br />

	<div id="main">

	<div class="box">
		<div class="subhead"> <%= get_ownoun() %> categories </div>

<%	
	$prof->startTimer( "get_link_counts" ); #pp
	$columnCount = $howURLs ? 7 : 6;
	$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 %> -->
<%
	}
	$numGroups = 0;
	if( $numRows ) {
		$prof->startTimer( "inner_get_link_counts" ); #pp
		$qs2 = "SELECT count(*) FROM links WHERE submitter='$u'";
		$q2 = mysql_query( $qs2 );
		if( $q2 ) $numLinks = mysql_result($q2,0);
%>
	<div class="fr r2">
		<%= printLinkCount( $numLinks ) %> total links
	</div>
<%
	$qs2 = getQuery( "num_unfiled" ) .  "AND links.submitter = '$u' ORDER BY $sortOrder $direction";
	$q2 = mysql_query( $qs2 );
	$numLinks = ( $q2 && mysql_num_rows( $q2 )) ?  mysql_result($q2,0) : 0;
	$bg = "class='r0'";
%>
	<div class="fr r0">
		<%= printLinkCount( $numLinks ) %> links
		remain <a href="f/unfiled"><b><em>unfiled</em></b></a>.
	</div>

	<% $prof->startTimer( "include_folder_list" ); #pp %>
<% include( "$modules/folder-list.inc.php" ); %>
	<% $prof->stopTimer( "include_folder_list" ); #pp %>

<%
		$prof->stopTimer( "inner_get_link_counts" ); #pp
	} else {
%>
<div>
(You do not have any categories yet.<br />
Try adding some, it's much nicer that way!)
</div>

<%
	}
	$prof->stopTimer( "get_link_counts" ); #pp
%>

<p>
	<form action="edit-folder">
	 create new category: <input class="text" name="name" value="<%= $folderToEdit ? $folderToEdit : "TYPE CATEGORY NAME" %>" 
	 onFocus="if( this.value == 'TYPE CATEGORY NAME')this.value='';" 
	 onBlur="if( this.value == '')this.value='TYPE CATEGORY NAME';" 
	 type="text" />
    <input type="hidden" name="op" value="createGroup" />
		<input type="submit" class="button" value="create" />
	</form>
</p>

<% #<p> [or, <a href="expanded">expand all your categories</a>] </p> %>

</td>

<td valign="top">
	<div>
		<% $prof->startTimer( "include_news" ); #pp %>
		<% include( "$modules/news.inc.php" ); %>
		<% $prof->stopTimer( "include_news" ); #pp %>
	</div>
	<div>
		<% $prof->startTimer( "include_my_recent_links" ); #pp %>
		<% include( "$modules/my-recent.inc.php" ); %>
		<% $prof->stopTimer( "include_my_recent_links" ); #pp %>
	</div>
	<div>
		<% $prof->startTimer( "include_their_recent" ); #pp %>
		<% include( "$modules/recent.inc.php" ); %>
		<% $prof->stopTimer( "include_their_recent" ); #pp %>
	</div>
	<div>
		<% $prof->startTimer( "include_random" ); #pp %>
		<% include_once( "$modules/random-links.inc.php" ); %>
		<% $prof->stopTimer( "include_random" ); #pp %>
	</div>
</td>

</tr>
</table>

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

<%
} // end if login

	$prof->printTimers( true );

%>

Return current item: FeedMeLinks, Social BookmarkingSince2002