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

	# $Id: submit-link.php,v 1.18 2005/11/20 01:58:49 hirokai Exp $
	include_once( "modules/utils.inc.php" );
	$tok =  $authenticated = $_COOKIE["c_pass_token"];
	$u   =  $sessionUserId = $_COOKIE["c_uid"];

	$folder = $folderID ? $folderID : $folder;
	$catNums = Array();

	if( $debug )
		echo "<pre>";

	foreach( $_POST as $catName=>$catValue ) {
		if( $debug )
			echo "DEBUG: POST: $catName : &gt;<span style=\"color: red\">$catValue</span>&lt;\n";
		if( $catValue == "on" && substr( $catName, 0, 2 ) == "cb" ) {
			array_push( $catNums, substr( $catName, 2 ) );
		}
	}

	foreach( $_GET as $catName=>$catValue ) {
		if( $debug )
			echo "DEBUG: GET: $catName : &gt;<span style=\"color: red\">$catValue</span>&lt;\n";
		if( $catValue == "on" && substr( $catName, 0, 2 ) == "cb" ) {
			array_push( $catNums, substr( $catName, 2 ) );
		}
	}

	if( $debug )
		echo "</pre>";

		if( $debug ) {
			echo "DEBUG: operation: $op<br/>";
			echo "DEBUG: current " . getCatName() . " is: $folder<br/>";
			echo "<br />";
			echo "DEBUG: url: $url<br />";
			echo "DEBUG: name: $name<br />";
			echo "DEBUG: submitter: $u<br />";
			echo "<br />";
		}
		if( $tok && $tok == md5( getPasswdForUser( $u ))) {
			$con_submit = mysql_connect( );
			mysql_selectdb( getDBName() );
			if( $op == "submit" ) {
%>

tagging link "<a href="<%= $url %>"><%= $name %></a>"...<br />

<%
			if( $debug ) {
				echo "<br />";
				echo "DEBUG: \$url : $url<br />";
				echo "DEBUG: \$name : $name<br />";
				echo "DEBUG: \$u : $u<br />";
				echo "DEBUG: \$is_private : $is_private<br />";
				echo "<br />";
			}

			# first we add the link and save the ID num:
			$q = $newLinkID = addLinkSimple( $url, $name, $u, ($is_private != "" ? 1 : "NULL"), $debug );
			if( $q ) {

				# then add any new tags, and tag this link with them:
				$q = add_tags_from_request( $u, $newLinkID, $catNums, $con_submit );

				if( $q ) {
					if( $debug )
						echo "<p>ALL CATEGORY ADDS WERE SUCCESSFUL!</p>";

					# handle comments:
					addCommentToLink( $newLinkID, $comments, $u, $func_debug = 0 );
					if( $debug ) {
						e( "<b>DEBUGGING ON - TAKING YOU NOWHERE, FAST!</b>" );
						return;
					}

					if( $from == "mobile_bitch" ) {
%>
<div class="attention">
link added, mobile bitch
</div>
<%
	echo bounceTo( "/add/success?link_name=" . urlencode( $name ) . "&link_num=$newLinkID" );

					} else if( $from == "right-click" ) {
%>
<script language="javascript"> 
	window.close();
</script>
<%
					} else if( $from == "xulbar" || $from == "xulbutton" ) {
%>

<script language="javascript"> 
	var bounceCount = <%= $from == "xulbutton" ? 2 : 1 %>;
	var loggedIn = "<%= $loggedIn %>";
	if( loggedIn == "wasnt" )
		bounceCount++;
	if( loggedIn == "someone-else" )
		bounceCount += 2;
	history.go( -bounceCount ); 
</script>

<%
					} else 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"> 
		if( history.length == 2 )
			window.close(); // we were spawned in a separate window (eg. bloglines...)
		else
			history.go( -2 ); 
	</script>
<%
						}
					# end from = toolbar/funnel
					} else {
						$showLinks = 0;
						bounceWithDelay( urldecode( "/index" ), 1 );
					}

				} else {
%>
<div class="attention warning">
adding the link <a href="<%= $url %>"><%= $name %></a> to some or all of the <%= getCatsName() %> failed...<br />
</div>
<%
				}
			} else {
%>
<div class="attention warning">
adding the link <a href="<%= $url %>"><%= $name %></a> failed<br />
<% if( $debug ) { %>
<br />
result was: <pre><%= $q %></pre>
<% } %>
</div>
<%
			}
		} else {
			warn( "Uh oh, looks like you may have bookmarked the wrong page.[unknown op: should be 'submit']" );
			include_once( "500.php" );
		}
	} else {
%>
<div class="attention">
it looks like you have not logged in. please <a href="/login">log in</a> first.
</div>
<%
			# not logged in
	}
	if( $q ) {
		if( $debug ) {
%>
	<div class="attention">
		<%= $qs %> worked!
	</div>
<%
		}
		if( !$debug && $from != "xulbar" && $from != "toolbar" ) {
			if( $folder ) {
%>

		 <script language="javascript"> location.replace( "/f/<%= $folder %>" ); </script>
<%
		} else {
%>

<div class="attention">
	no folder to bounce you to!
</div>

<%
			}
		}
	} else {
%>
			<div class="attention">
				failed!
			</div>
<%
	}
	conClose( $con_submit );
	new gzip_encode();
%>
Return current item: FeedMeLinks, Social BookmarkingSince2002