INT, 'cpage' => INT));
typecast($_POST, array('low' => STRING, 'high' => STRING, 'radius' => INT, 'dist' => STRING, 'final' => STRING, 'what' => STRING, 'name' => STRING, 'preview' => STRING,
'condition' => STRING, 'keywords' => STRING, 'whenterm' => STRING, 'when' => INT));
list($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
authenticate();
if ( $Globals['ppboards'] == "closed" && $User['adminedit'] != 1 )
{
diewell( $Globals['closedmsg'] );
}
topmenu();
if ( empty($final) )
{
$seltext = "selected=\"selected\"";
if ( $cat > 0 )
{
$seltext = null;
$selected = $cat;
}
quickcats(0);
printheader( 0, $Globals['pp_lang']['search'] );
include( "{$Globals['TMPL_PATH']}/menubar.tmpl" );
if ( $Globals['sidebar_global'] == "yes" )
{
if ( $Globals['statspal'] == "yes" )
{
get_statscache();
}
if ( $Globals['topposterspal'] == "yes" )
{
get_posterscache();
}
if ( $Globals['ratingspal'] == "yes" )
{
get_ratingcache();
}
}
if ( $Globals['sidebar'] == "left" && $Globals['sidebar_global'] == "yes" ) {
include( "{$Globals['TMPL_PATH']}/sidebar_leftopen.tmpl" );
}
if ( $Globals['sidebar'] == "right" && $Globals['sidebar_global'] == "yes" ) {
include( "{$Globals['TMPL_PATH']}/sidebar_rightopen.tmpl" );
}
include( "{$Globals['TMPL_PATH']}/search.tmpl" );
if ( $Globals['undercat'] == "yes" && $Globals['sidebar_global'] == "yes" ) {
include( "{$Globals['TMPL_PATH']}/undercat-sidebar.tmpl" );
}
if ( $Globals['sidebar'] == "left" && $Globals['sidebar_global'] == "yes" ) {
include( "{$Globals['TMPL_PATH']}/sidebar_leftclose.tmpl" );
}
if ( $Globals['sidebar'] == "right" && $Globals['sidebar_global'] == "yes" ) {
include( "{$Globals['TMPL_PATH']}/sidebar_rightclose.tmpl" );
}
printfooter();
}
else
{
if ( !isset($what) )
{
$what = "all";
}
if ( !isset($name) )
{
$name = null;
}
if ( !isset($cats) )
{
$cats = null;
}
$scats = null;
if ( @is_array( $_POST['cats'] ) )
{
$scats = addslashes(join( ",", $_POST['cats'] ));
$mcats = $scats;
}
elseif ( @is_array( $_GET['cats'] ) )
{
$scats = addslashes(join( ",", $_GET['cats'] ));
$mcats = $scats;
}
elseif ( !empty($cats) )
{
$scats = addslashes(join( ",", $cats ));
$mcats = $scats;
}
if ( $what == "comments" )
{
// multiple cats
if ( $mcats && $mcats != "all" )
{
$catcheck = " AND r.cat IN ($mcats)";
}
// for this we need to be explicit
$exclude_cat = str_replace( "cat", "c.cat", $exclude_cat );
if ( isset($preview) )
{
$query = "SELECT c.id,c.username,c.userid,c.date,c.comment,c.cat,c.product,p.bigimage,p.cat,p.userid FROM {$Globals['pp_db_prefix']}comments c
LEFT JOIN {$Globals['pp_db_prefix']}products p ON p.id=c.product WHERE c.comment != '' $catcheck $exclude_cat";
}
else
{
$query = "SELECT c.id,c.username,c.userid,c.date,c.comment,c.cat,c.product,c.approved FROM {$Globals['pp_db_prefix']}comments c WHERE c.comment != '' $catcheck $exclude_cat";
}
if ( $Globals['moderatecoms'] == "no" )
{
$query .= " AND c.approved=1";
}
// search terms
$searchterms = explode(" ", trim($keywords));
$keyphrase = null;
if ( !isset($condition) )
{
$condition = "AND";
}
if ( $condition == "or" )
{
$scond = "OR";
}
else
{
$scond = "AND";
}
foreach( $searchterms as $key )
{
$key = trim(addslashes($key));
if ( $key )
{
$keyphrase .= " $scond ((c.comment LIKE \"% $key%\") OR (c.comment LIKE \"$key%\"))";
}
}
if ( $name )
{
$keyphrase .= " AND (c.username LIKE '%".addslashes($name)."%')";
}
// time frame (days is default)
if ( $when )
{
if ( !isset($whenterm) ) $whenterm = "d";
if ( $whenterm == "w" )
{
$days = ($when * 7);
}
elseif ( $whenterm == "m" )
{
$days = ($when * 30);
}
elseif ( $whenterm == "y" )
{
$days = ($when * 365);
}
else {
$days = $when;
}
list($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
$mon = $mon + 1;
$year = $year + 1900;
$hour = $hour - ($days * 24);
$searchdate = mktime($hour,$min,$sec,$mon,$mday,$year);
$keyphrase .= " AND c.date > $searchdate";
}
$query .= $keyphrase;
$queryv = ppmysql_query($query,$link);
$comcount = mysql_num_rows($queryv);
if ( $comcount == 0 )
{
$compages = 0;
}
else {
if ($pperpage > 0)
{
$compages=($comcount/$pperpage);
}
else
{
$pperpage = $Globals['defaultposts'];
$compages = ($comcount/$pperpage);
}
}
if ( intval($compages) < $compages )
{
$compages = intval($compages)+1;
}
else
{
$compages = intval($compages);
}
if ( isset($cpage) )
{
$cstartnumb=($cpage*$pperpage)-$pperpage+1;
}
else
{
$cpage=1;
$cstartnumb=1;
}
$itemnum = 0;
$results = array();
$ckcolor = 0;
while ( list( $cid, $cusername, $cuserid, $cdate, $ccomment, $comcat, $comphoto, $bigimage, $pcat, $puserid ) = mysql_fetch_row($queryv) )
{
$cc++;
if ($cc >= $cstartnumb)
{
if ($cc < ($cstartnumb+$pperpage))
{
$results['cid'][$itemnum] = $cid;
$ucuser[$itemnum] = "$cusername";
$cuserid[$itemnum] = $cuserid;
$imgtime[$itemnum] = formatpptime( $cdate );
$imgdate[$itemnum] = formatppdate( $cdate );
$ccomment = substr($ccomment,0,256);
reset($searchterms);
foreach($searchterms as $key)
{
$key = trim(addslashes($key));
if ( $key )
{
$ccomment = preg_replace( "/$key/i", "[i]{$key}[/i]", $ccomment );
}
}
$commenttextline = convert_markups($ccomment);
$commenttext[$itemnum] = convert_returns($commenttextline);
$ccat[$itemnum] = $comcat;
$cphoto[$itemnum] = $comphoto;
$thumbrc[$itemnum] = null;
if ( isset($preview) )
{
$thisthumb = get_imagethumb( $bigimage, $pcat, $puserid, 1 );
$thumbrc[$itemnum] = "$thisthumb
";
}
if ($ckcolor == 1)
{
$fillcolor[$itemnum] = "{$Style['alternatetable']}";
$ckcolor = 0;
}
else
{
$fillcolor[$itemnum] = "{$Style['tddetails']}";
$ckcolor = 1;
}
$itemnum++;
}
}
}
$more = " ";
$less = " ";
if ( $cpage != $compages && $compages > 1 )
{
$nextpage = $cpage+1;
$keywords = urlencode($keywords);
$name = urlencode($name);
$more = "
";
}
printheader( 0, $Globals['pp_lang']['search'] );
include( "{$Globals['TMPL_PATH']}/menubar.tmpl" );
if ( $Globals['sidebar_global'] == "yes" )
{
if ( $Globals['statspal'] == "yes" )
{
get_statscache();
}
if ( $Globals['topposterspal'] == "yes" )
{
get_posterscache();
}
if ( $Globals['ratingspal'] == "yes" )
{
get_ratingcache();
}
}
if ( $Globals['onlinepal'] == "yes" && $Globals['sidebar_global'] == "yes" ) {
// Lets get Who is Online
$whoonline = get_whoonline();
}
if ( $Globals['sidebar'] == "left" && $Globals['sidebar_global'] == "yes" ) {
include( "{$Globals['TMPL_PATH']}/sidebar_leftopen.tmpl" );
}
if ( $Globals['sidebar'] == "right" && $Globals['sidebar_global'] == "yes" ) {
include( "{$Globals['TMPL_PATH']}/sidebar_rightopen.tmpl" );
}
include( "{$Globals['TMPL_PATH']}/search-r.tmpl" );
if ( $Globals['undercat'] == "yes" && $Globals['sidebar_global'] == "yes" ) {
include( "{$Globals['TMPL_PATH']}/undercat-sidebar.tmpl" );
}
if ( $Globals['sidebar'] == "left" && $Globals['sidebar_global'] == "yes" ) {
include( "{$Globals['TMPL_PATH']}/sidebar_leftclose.tmpl" );
}
if ( $Globals['sidebar'] == "right" && $Globals['sidebar_global'] == "yes" ) {
include( "{$Globals['TMPL_PATH']}/sidebar_rightclose.tmpl" );
}
printfooter();
}
else
{
$keywords = urlencode($keywords);
$condition = rawurlencode($condition);
$what = rawurlencode($what);
forward( "showcat.php?mcats=$scats&si=$keywords&what=$what&name=$name&when=$when&whenterm=$whenterm&dist=$dist&radius=$radius&low=$low&high=$high", $Globals['pp_lang']['searching'] );
}
}
?>