<%
ob_start();
include_once( "modules/class.gzip_encode.inc.php" );
# $Id: categorize.php,v 1.34 2005/11/20 01:58:49 hirokai Exp $
$page = $debug ? "categorize?debug=y" : "categorize";
$errorPage = "index";
$shouldShowCreateEditForm = 1;
$hotRow = -1;
$shouldDump = 1;
include_once( "modules/utils.inc.php" );
$site = getSiteUrl();
$tok = $authenticated = $_COOKIE["c_pass_token"];
$u = $sessionUserId = $_COOKIE["c_uid"];
$MAX_COLS = 5;
$BIG_FOLDER_LAYOUT_THRESH = 10;
$bigLayout = 1;
$rowsPerSmallColumn = 25;
$hiddenColor = "#bcbcbc";
%>
<base href="<%= $site %>/funnel.php" />
<title> Feed Me Links : <%= $op == "Change" ? getCatVerb() : "Save" %> This Link </title>
<div style="text-align: right; margin-bottom: 2em;">
<%
if( $u ) {
$change_user_url = urlencode( "categorize?from=$from&loggedIn=someone-else&op=submit&name=$name&url=$url&ref=$ref&version=$version" );
$change_user_mesg = urlencode( "Login to save the link '<u>$name</u>'..." );
%>
Not <a href="/"><%= $u %></a>?
<a href="/login?mesg=<%= $change_user_mesg %>&bounceToPage=<%= $change_user_url %>">Log in</a>.
<% } %>
</div>
<% if( $debug ) { %>
user is "<%= $u %>"<br />
<%
}
if( $tok && $tok == md5( getPasswdForUser( $u ))) {
$noMenu = true;
$noBody = true;
include( "$modules/header.inc.php" );
%>
<body onLoad="document.forms['funnelForm'].name.select()">
<%
if( $debug )
dumpParams();
if( $l || ($id || ( $url && $name != "null" ))) {
if( !$name )
$name = "Please type a name for this link.";
if( $op == "change" && $id ) {
$opVerb = "Tagging";
$li = getLinkInfo( $id );
$name = urldecode( $li['name'] );
$url = $li['url'];
$rawCats = getCategoriesForLink( $id, $u );
if( $debug ) {
print "rawCats:<br />";
print_r( $rawCats);
}
$hashcats = Array();
if( $debug )
echo "<br/> current " . getCatsName() . ":<br />";
if( $rawCats && count( $rawCats ) ) {
foreach( $rawCats as $cat ) {
$hashcats[ $cat ] = 1;
if( $debug )
echo "DEBUG: adding existing " . getCatName() . " $cat to \$hashcats[]<br />";
}
} else {
if( $debug )
echo "no existing " . getCatsName() . " for link $id<br />";
}
} else {
if( $l ) {
$con_getLinkInfo = mysql_connect();
mysql_selectdb( getDBName() );
$qs = "SELECT * FROM links WHERE ID = $l";
$q = mysql_query( $qs );
if( $q && mysql_num_rows($q) ) {
$row = mysql_fetch_assoc( $q );
$url = urldecode( $row["url"] );
$name = urldecode( $row["name"] ) . " (thanks, " . urldecode( $row["submitter"] ) . ")";
}
conClose( $con_getLinkInfo );
}
$opVerb = "Name this link:";
# cruft from the old jm3.net redirect...
$regex = "/^http%3A/";
if( preg_match( $regex, $url )) {
$url = urldecode( $url );
$name = urldecode( $name );
}
}
$con_categorize = mysql_connect();
mysql_selectdb( getDBName() );
$qs = "SELECT * FROM linksGroups WHERE userId = '$u' ORDER BY name ASC;";
if( $debug )
echo "\$qs: $qs<br />";
$q = mysql_query( $qs );
if( $q )
$numRows = mysql_num_rows($q);
else if( $debug )
echo "warning: DB query failed or no " . getCatsName() . " found in DB!<br />";
%>
<center>
<form style="margin: 0px;" action="<%= $op == "change" ? "/action" : "/submit-link" %>" name="funnelForm" method="post">
<script type="javascript">
var f = document.forms['funnelForm'];
var i = new Image();
i.src = "/img/save.png";
var io = new Image();
io.src = "/img/save-off.png";
</script>
<div style="border-bottom: 1px solid #dddddd; margin-bottom: 1px; padding: 0px;">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top">
<h2><%= $opVerb %> <input type="text" size="64" maxlength="127" name="name" value="<%= $from == "toolbar" ? $name : o( $name ) %>">
<%
if( $debug ) {
%>
$name: <%= $name %><br />
$from: <%= $from %><br />
o( $name ): <%= o( $name ) %><br />
<%
}
%>
<br />
<br />
<a href="javascript:setPrivate();">Save as private</a>?
<input type="checkbox" name="is_private" />
</h2>
<br />
</td>
<td valign="top">
<a href="javascript:submitLink();"
onMouseOver="document.images.save.src='/img/save.png';"
onMouseOut="document.images.save.src='/img/save-off.png';"
><img name="save" src="/img/save-off.png" alt="Save It!" border="0" /></a>
<br />
</td>
</tr>
</table>
<input type="hidden" name="op" value="<%= $op == "change" ? "changeCategories" : "submit" %>" />
<input type="hidden" name="debug" value="<%= $debug %>" />
<input type="hidden" name="version" value="<%= $version ? $version : "pre_version" %>" />
<% if( $op == "change" ) { %>
<input type="hidden" name="id" value="<%= $id %>" />
<% } else { %>
<input type="hidden" name="from" value="<%= $from ? $from : "funnel" %>" />
<input type="hidden" name="url" value="<%= $url %>" />
<input type="hidden" name="ref" value="<%= $ref %>" />
<input type="hidden" name="loggedIn" value="<%= $loggedIn %>" />
<% } %>
</div>
<%
if( $numRows ) {
$catsRendered = 0;
%>
<table cellspacing="0" cellpadding="8" border="0" width="650">
<tr>
<%
$categories = array();
$count = 0;
if( $debug ) echo "<p>($numRows " . getCatsName() . ")</p>";
while( $count < $numRows ) {
$idx = $catsRendered; # $i*$rows+$j;
$id = mysql_result($q, $idx, "ID");
$options = mysql_result($q, $idx, "options");
$catName = makeSafeName( mysql_result($q, $idx, "name"));
$public = 0;
if( isPublic( $catName )) {
$catName = makePrettyFolderName( $catName );
++$public;
}
$categories[$count] = array( $catName, $options, $id, $public );
$catsRendered++;
$count++;
}
conClose( $con_categorize );
$catsRendered = 0;
$i = 0;
sort( $categories );
if( $numRows > $BIG_FOLDER_LAYOUT_THRESH ) {
$bigLayout = 0;
$rowsPerSmallColumn = ($numRows / 3) + 1;
}
if( !$bigLayout ) { %>
<style type="text/css">
/* momentarily override the visited colorizing so as not to confuse the user... */
a:visited { color: #ff6600; }
.l { height: 1.6em; }
</style>
<%
}
foreach( $categories as $key=>$category ) {
if( $bigLayout ) {
# calculate how the rows should be set up
$rows = $cols = round( sqrt($numRows + 1) );
if( $cols != sqrt($numRows + 1) )
$cols++;
if( $rows > $MAX_COLS )
$rows = $cols = 5;
if( $catsRendered % $rows == 0)
echo "</tr><tr>";
} else {
if( $catsRendered % $rowsPerSmallColumn == 0 )
echo "</td><td class='funnelTD' valign='top'>";
}
if( $catsRendered < $numRows ) {
$idx = $catsRendered; # $i*$rows+$j;
$id = $category[2];
$options = $category[1];
$catName = $category[0];
$public = $category[3];
$alreadySelected = $hashcats[$id];
# orig url:
#
# from=toolbar
# op=submit
# groupid=XXXX
# name=asd
# url=http%3A//feedmelinks.com/testing/categories.php%3Furl%3Dfoo
# ref=
# loggedIn=(wasnt ? or "")
$cb = "<input type=\"checkbox\" name=\"cb$id\" onChange=\"cbpc($id)\" " . ($alreadySelected ? "checked" : "" ) . "/>"; #checkbox
if( $bigLayout ) {
%>
<td class="funnelTD" height="45" align="center" valign="bottom">
<%= $cb %>
<a <%= $alreadySelected ? "class=\"hot\" " : "" %>href="javascript:pc(<%= $id %>);"><img src="<%= $public ? "img/big-tag-bice" : "img/big-tag-private-bice" %>.gif" border="0" /><br />
<b><%= $catName %><%= $debug ? " ($id)" : "" %></b></a><br />
</td>
<%
} else {
%>
<div class="l">
<%= $cb %>
<a href="javascript:pc(<%= $id %>);"><img src="img/lil-tag<%= !$public ? "-private" : "" %>-bice.gif" align="absmiddle" border="0" /></a>
<a <%= !$public ? "style='color: $hiddenColor;'" : "" %> <%= $alreadySelected ? "class=\"hot\" " : "" %>href="javascript:pc(<%= $id %>);"><%=
$catName %></a>
</div>
<%
}
$catsRendered++;
} else if ( $catsRendered == $numRows ) {
$catsRendered++;
%>
<%
} else {
echo " ";
} # end if( we should draw another link )
} # end foreach
if( $bigLayout ) {
%>
</td>
</tr>
<tr>
<td class="funnelTD" height="45" align="center" valign="bottom">
<a href="/?op=submit&from=funnel&name=<%= urlencode( $name )
%>&url=<%= urlencode( $url ) %><%= $loggedIn == "wasnt" ? "&loggedIn=wasnt" : "" %>"><img
src="img/big-tag-private-bice" border="0" /></a><br />
leave <a href="/?op=submit&from=funnel&name=<%= urlencode( $name )
%>&url=<%= urlencode( $url ) %><%= $loggedIn == "wasnt" ? "&loggedIn=wasnt" : "" %>"> <b><%= getUnCattedName() %></b></a><br />
</td>
<%
} else {
%>
<div class="l">
<br />
or, leave this link <a href="/?op=submit&name=<%=
urlencode( $name ) %>&url=<%= urlencode( $url ) %>&from=funnel<%= $loggedIn == "wasnt" ? "&loggedIn=wasnt" : "" %>"><%= getUnCattedName() %></a>.
</div>
<%
}
%>
</tr>
</table>
<br />
or, <b>Add new <%= getCatsName() %></b>:
<input name="new_tag_1" size="14" maxlength="48" />,
<input name="new_tag_2" size="14" maxlength="48" />,
<input name="new_tag_3" size="14" maxlength="48" />
<br /><br />
<% if( $ref != "" ) {
preg_match("/http:\/\/([^\/]+)\//", $ref, $matches );
$domain = $matches[1];
%>
<div class="head" style="margin-bottom: 0.5em;">
(Linked from: <a href="<%= $ref %>"><%= $domain %></a> / Edit: <input name="referrer" value="<%= $domain %>" />)
</div>
<% } %>
<br />
<input type="button" class="default button" style="padding: 3px;" value="Save It!" onClick="submitLink();" />
<input type="button" onClick="deselectAllCategories();" value="De-Select All <%= getCatsName() %>" class="button" />
</form>
<% if( !$bigLayout ) { %>
<p>
(private <%= getCatsName() %> are light gray)
</p>
<% } %>
</center>
<%
} else {
%>
<div class="attention warning">
You appear to have no <%= getCatsName() %>.
</div>
<%
}
} else {
%>
<style type="text/css">
/* momentarily override the visited colorizing so as not to confuse the user... */
a:visited { color: #ff6600; }
table, tr, td { background-color: #E5E5E5 }
</style>
<%
echo $_GET["link_name"];
$link_name = urldecode( preg_replace( ":^.*link_name=(.*)&link_num=(.+):", "\\1", $REQUEST_URI ));
$link_num = urldecode( preg_replace( ":^.*link_num=(.+):", "\\1", $REQUEST_URI ));
if( preg_match( ":/add/success:", $REQUEST_URI )) {
$op = "mobile_bitch";
%>
<div class="attention">
Added <b><%= $link_name %></b> as <%= getPermaLink( $link_num ) %>!
<br />
Add 'nother link?
<br />
</div>
<%
} else if( preg_match( ":add:", $REQUEST_URI )) {
$op = "mobile_bitch";
} else {
%>
<h2>This page is usually used with the <u>Feed Me Links</u> Button (or "Bookmarklet") to add links</h2>
(go <a href="/install">here</a> to get the <a href="/install">Bookmarklet</a>)
<p />
<%
}
%>
<br />
<form action="categorize" method="post">
<% if( $op == "mobile_bitch" ) {
startTell( "<img src='/img/mobile-header.gif' alt='for our nomadic users...'/>", "600");
%>
<input type="hidden" name="from" value="mobile_bitch" />
<% } %>
<div class="attention" style="width: 50em;">
<table width="550" border="0" style="background-color: #E5E5E5;" cellpadding="0" cellspacing="0">
<tr>
<td>
<table border="0" style="background-color: #E5E5E5;" cellpadding="0" cellspacing="0">
<tr>
<td align="right">url: </td>
<td><input name="url" value="<%= $url %>" size="40" maxlength="254" /></td>
<td> </td>
</tr>
<tr>
<td align="right">name: </td>
<td><input name="name" value="<%= $name %>" size="40" maxlength="127" /></td>
</tr>
</table>
</td>
<td>
<input type="submit" class="default button" value="Save It!" />
<p />
<input type="button" class="button" value="Cancel" onClick="history.go( -1 );" />
</td>
</tr>
</table>
</div>
</form>
<%
if( $op == "mobile_bitch" ) {
endTell();
}
}
include( "$modules/footer.inc.php" );
} else { #end auth
# need to pack this as one param so the param chain doesnt get unrolled on the next page
if( preg_match( "/^\/g\//", $page )) {
$bounce = urlencode( "categorize?l=$l&loggedIn=wasnt" );
} else {
# Nb. this is the 'not logged in and clicked the bookmarklet / XUL button' case
if( $from ) {
$qs = $_SERVER['QUERY_STRING'];
$bounce = urlencode( "$page&loggedIn=wasnt&$qs" );
} else {
# this is the ..logged in, clicked a shortcut link.. case
$bounce = preg_replace( "/^\//", "", $page );
}
}
if( $debug )
e( "bounce: $bounce" );
else
echo bounceTo( $site . "/login?bounceToPage=$bounce" );
%>
<% }
new gzip_encode();
%>