<%
# $Id: public.inc.php,v 1.18 2004/11/07 10:55:08 hirokai Exp $
include_once( "modules/utils.inc.php" );
$tok = $authenticated = $_COOKIE["c_pass_token"];
$u = $sessionUserId = $_COOKIE["c_uid"];
$page = "portal";
if( ! $sortOrder )
$sortOrder = "groupid DESC, createDate";
$direction = $sortOrder == name ? "ASC" : "DESC";
# first, set up options and defaults.
$MAX_URL_LENGTH = 40;
$MAX_NAME_LENGTH = 33;
$MAX_LINKS = 3;
$MAX_FOLDERS = 8;
$showURLs = false;
$USE_LONG_URLS = false;
$max = 4;
$foldersRendered = 0;
%>
<big><b>NEW FOLDERS:</b></big> (or <a href="/list-public">view all folders</a>)
<br />
<%
$con = mysql_connect();
mysql_selectdb( getDBName() );
$magick = 1;
$shouldDump = 1;
if( $shouldDump ) {
$columnCount = $showURLs ? 7 : 6;
$singleGroup = $folder ? true : false;
if( $singleGroup ) {
$qs = "SELECT * from linksGroups WHERE id=$folder";
$q = mysql_query( $qs );
if( $q ) {
$singleGroupName = urldecode( mysql_result($q,$i,"name") );
if( $debug)
echo "group id $folder (named $singleGroupName) exists<br>";
if( isPublic( $singleGroupName )) {
$singleGroupName = substr( $singleGroupName, 2, strlen( $singleGroupName ) );
$qs = "SELECT * FROM links WHERE groupid=$folder
ORDER BY $sortOrder $direction LIMIT $MAX_FOLDERS";
} else {
echo "<br>don't see any public folders with that ID number (\"$folder\"), jocko.\
try checking <a href=\"/public\">the public folders section</a>.<br>";
}
}
} 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 = urldecode( 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 $whereClause ORDER BY $sortOrder $direction LIMIT 8;";
}
if( $debug )
echo "$qs<br>";
$q = mysql_query( $qs );
if( $debug) echo "ran \$qs<br>";
if( $q )
$numRows = mysql_num_rows($q);
if( $debug) echo "there were $numRows rows<br>";
$groupParam = $singleGroup ? "folder=$folder&" : "";
if( $numRows ) {
$bg = "class='header'";
%>
<table cellpadding="1" cellspacing="0">
<tr>
<td class="boxBorder">
<table cellspacing="0" cellpadding="1" border="0">
<tr>
<td colspan="2" class="header" width="120">
folder/link name
</td>
<% if( $showURLs ) { %>
<td <%= $bg %> width="250"><a class="header" href="<%= $page %>?sortOrder=url">url</a></td>
<% } %>
<td class="header" <%= $bg %> width="100">added on</td>
<% if( $magick ) { %>
<td class="header" width="10">grab </td>
<% } %>
<% if( $magick ) { %>
<td class="header"width="10"> </td>
<% } %>
</tr>
<%
$i = 0;
#echo "NUM: $numRows\n";
$linksInThisGroup = 0;
while ($i < $numRows ) {
$id = mysql_result($q,$i,"ID");
$userId = urldecode( mysql_result($q,$i,"submitter"));
$folderId = mysql_result($q,$i,"groupid");
$group = $singleGroup ? $singleGroupName : $groups[$folderId];
$group = $group ? $group : "unfiled";
if( $group == "unfiled" )
break;
if( $prevGroup != $group && $sortOrder == "groupid DESC, createDate" ) {
if( $foldersRendered < $MAX_FOLDERS ) {
$foldersRendered++;
$linksInThisGroup = 1;
$shownContinue = false;
$prevGroup = $group;
$groupName = ( $group == "public" ) ? $userId ."'s public folder" : $group;
%>
<tr><td colspan="<%= $columnCount + 1%>" class="header" height="1"><img src="/img/spacer.gif" height="1" width="1" alt="" /></td></tr>
<tr><td colspan="<%= $columnCount + 1 %>" class="r1">
<span style="font-size: 110%"><b><%= makeFolderLink( $folderId, $groupName ) %></b> folder </span>
(owned by <b><%= makeUserLink( $userId ) %></a></b>)
</td></tr>
<tr><td colspan="<%= $columnCount + 1%>" class="header" height="1"><img src="/img/spacer.gif" height="1" width="1" alt="" /></td></tr>
<%
}
} else {
$linksInThisGroup++;
}
if( $linksInThisGroup - 1 < $MAX_LINKS ) {
if( $foldersRendered < $MAX_FOLDERS ) {
$group = $group ? $group : "...";
$url = urldecode( mysql_result($q,$i,"url"));
$name = urldecode( mysql_result($q,$i,"name"));
$rawCreateDate = urldecode( mysql_result($q,$i,"createDate"));
$createDate = formatTS( mysql_result($q,$i,"createDate"));
if( $i % 2 == 0 )
$bg = "class='r0a'";
else
$bg = "class='r1a'";
%>
<tr>
<td <%= $bg %>>
</td>
<td <%= $bg %>>
<%
if( strlen( $name ) > $MAX_NAME_LENGTH ) {
$comment = $name;
$displayName = substr( $name, 0, $MAX_NAME_LENGTH ) . "...";
} else {
$comment = "";
$displayName = $name;
}
%>
<%= makeNewWindowLink( $url ) %>
<%= makeNamedLinkOut( $id, $displayName ) %>
</td>
<% if( $showURLs ) { %>
<td <%= $bg %>>
<%
$tmpurl = $url;
if( ! $USE_LONG_URLS ) {
$tmpurl = str_replace ( "http://", "", $tmpurl);
$tmpurl = str_replace ( "https://", "[s] ", $tmpurl);
$tmpurl = str_replace ( "ftp://", "[f] ", $tmpurl);
$tmpurl = str_replace ( "www.", "", $tmpurl);
}
if( strlen( $tmpurl ) > $MAX_URL_LENGTH )
$tmpurl = substr( $tmpurl, 0, $MAX_URL_LENGTH ) . "...";
%>
<%= makeNamedLinkOut( $id, $tmpurl ) %>
</td>
<% } %>
<td <%= $bg %>>
<span class="subtle"><%= $createDate %></span>
</td>
<td colspan="2" <%= $bg %>> <%= makeStealItLink( $id ) %></td>
</tr>
<% }
} else {
if( !$shownContinue ) {
$shownContinue = true;
%>
<tr>
<td colspan="5" align="right" <%= $bg %>><%= makeFolderLink( $folderId, "view this <b>entire</b> folder" ) %>...</td>
</tr>
<%
}
}
%>
<% $i++; %>
<%
}
mysql_close( $con );
%>
</table>
</td>
</tr>
</table>
<br />
the plus button (<img src="/img/plus.gif" />) adds a link to your collection.<br />
<%
} // echo "that group's empty, bucko.<br>";
%>
<%
}
%>