<%
ob_start();
include_once( "modules/class.gzip_encode.inc.php" );
Header( "Content-type: text/xml");
# $Id: search-as-xml.php,v 1.1 2005/06/06 23:47:32 hirokai Exp $
$page = "recent-kompact";
include_once( "modules/utils.inc.php" );
$tok = $authenticated = $_COOKIE["c_pass_token"];
$u = $sessionUserId = $_COOKIE["c_uid"];
$MAX_NAME_LENGTH = 128;
$searchTerm = $q ? $q : $searchTerm;
$searchTerm = str_replace( " ", "%", $searchTerm );
$searchTerm = str_replace( "'", "", $searchTerm );
$con = mysql_connect();
mysql_selectdb( getDBName() );
$showInputForm = true;
$search_only = $search_only ? $search_only : "links";
$searchWhat = $search_only;
$qs2 = "SELECT count(*) FROM links;";
$q2 = mysql_query( $qs2 );
if( $q2 ) $totalNumLinks = mysql_result($q2,0);
%>
<<%= "?" %>xml version='1.0' encoding="UTF-8" standalone='yes'?>
<response type="search">
<meta>
Search <%= $my ? "My Links" : "Feed Me Links" %> <%= $q ? "for '$q'" : "" %>
</meta>
<%
if( $searchTerm ) {
if( $search_only == "links" )
$qs = $my ?
"SELECT * from links WHERE lcase(name) LIKE '%$searchTerm%' AND submitter='$sessionUserId' ORDER BY createDate DESC"
# this query needs to pull from the master query, but the column names are different...
: "SELECT * from links WHERE lcase(name) LIKE '%$searchTerm%' AND (isPrivate is NULL OR submitter = '$u') ORDER BY createDate DESC";
else if( $search_only == "users" )
$qs = "SELECT * from linksUsers WHERE lcase(userid) LIKE '%$searchTerm%' ORDER BY userid;";
else if( $search_only == "tags" )
$qs = "SELECT * FROM linksGroups WHERE name LIKE '%$searchTerm%' AND (name like 'p\%2F%' OR userid = '$u') ORDER BY name;";
$q = mysql_query( $qs );
if( $q )
$numRows = mysql_num_rows($q);
%>
<meta><%= $numRows %> matches from <%= number_format( $totalNumLinks ) %> links</meta>
<%
if( $numRows ) {
$i = 0;
if( $search_only == "links" ) {
while ($i < $numRows) {
$id = mysql_result($q,$i,"ID");
$submitter = urldecode( mysql_result($q,$i,"submitter"));
$owned = ( $u == $submitter ) ? 1 : 0;
if( $owned || isInPublicFolder( $id ) ) {
$name = makeSafeName( mysql_result($q,$i,"name"));
if( strlen( $name ) > $MAX_NAME_LENGTH )
$name = substr( $name, 0, $MAX_NAME_LENGTH ) . "...";
$url = urldecode( mysql_result($q,$i,"url"));
%>
<link>
<%
$cats = getCategoriesForLinkAsHTML( $id, $u, "add-trailing-noun=1", 0 );
$name = preg_replace( "/'/", "'", $name );
$url = preg_replace( "/&/", "&", $url );
%>
<url><%= $url %></url>
<name><%= html_entity_decode( $name ) %></name>
<%
$cats = $cats ? "$cats" : "by $submitter";
#echo $cats;
%>
</link>
<%
$i++;
}
}
} else if( $search_only == "users" ) {
while ($i < $numRows) {
$userid = urldecode( mysql_result($q,$i,"userid"));
$email = urldecode( mysql_result($q,$i,"email"));
$name = urldecode( mysql_result($q,$i,"name"));
$qs3 = "SELECT COUNT(*) FROM links WHERE submitter = '$userid';";
$q3 = mysql_query( $qs3 );
$linkCount = mysql_result($q3,0);
%>
<link>
<%= makeUserLink( $userid ) %>
(<%= $linkCount %> links)
</link>
<%
$i++;
}
} else if( $search_only == "tags" ) {
while ($i < $numRows) {
$id = urldecode( mysql_result($q,$i,"id"));
$name = urldecode( mysql_result($q,$i,"name"));
$userid = urldecode( mysql_result($q,$i,"userid"));
$i++;
if( isPublic( $name ) || $u == $userid ) {
$qs3 = "SELECT COUNT(*) FROM linksCategoriesXRef WHERE catID = $id;";
$q3 = mysql_query( $qs3 );
$linkCount = mysql_result($q3,0);
%>
<link>
<%= makeFolderLink( $id, makePrettyFolderName( $name )) %>
(<%= $linkCount %> links, owned by <%= makeUserLink( $userid ) %>)
</link>
<%
}
}
}
} # else no matches.
}
%>
</response>
<%
new gzip_encode();
%>