query($q); $db->next_record(); $topic_image_name = $db->Record["image"]; $topic_image_width = $db->Record["width"]; $topic_image_height = $db->Record["height"]; return ""; } else { /* no id, WITH name, we set the image stuff and return the ID */ $name = clean($name); $q = "SELECT topic_id, topic_name, image, width, height FROM psl_topic WHERE topic_name = '$name'"; $db->query($q); $db->next_record(); $topic_image_name = $db->Record["image"]; $topic_image_width = $db->Record["width"]; $topic_image_height = $db->Record["height"]; return $db->Record["topic_id"]; } } else { /* we HAVE an ID so we'll just set the topic image stuff and move on */ $q = "SELECT topic_id, image, width, height FROM psl_topic WHERE topic_id = '$id'"; $db->query($q); $db->next_record(); $topic_image_name = $db->Record["image"]; $topic_image_width = $db->Record["width"]; $topic_image_height = $db->Record["height"]; return $db->Record["topic_id"]; } } function getSectionID ($id, $name) { if ($id == "") { if ($name == "") { return ""; } else { $name = clean($name); $db = new slashDB; $q = "SELECT section_id from psl_section WHERE section_name = '$name'"; $db->query($q); $db->next_record(); return $db->Record["section_id"]; } } else { return clean($id); } } function getAuthorID ($id, $name) { if ($id == "") { if ($name == "") { return ""; } else { $name = clean($name); $db = new slashDB; $q = "SELECT author_id from psl_author WHERE author_name = '$name'"; $db->query($q); $db->next_record(); return $db->Record["author_id"]; } } else { return clean($id); } } $search_topic_id = getTopicID($topic_id, $topic_name); $search_section_id = getSectionID($section_id, $section_name); $search_author_id = getAuthorID($author_id, $author_name); /*** DEBUG ***/ debug("HTTP_POST_VARS", $HTTP_POST_VARS); debug("HTTP_GET_VARS", $HTTP_GET_VARS); /*************/ $sl_q = new slashDB; $sl_q->debug = false; /*************PAGE START*******************/ slashhead($pagetitle,$xsiteobject); /* Templates */ $templ = new Template ("$templatedir"); $templ->debug = false; $templ->set_file (searchpage, "searchPage.tpl"); /**** [ Begin Modif for DigitalSook ] ****/ // titlebar("100%","Searching $query"); /**** [ end Modif for DigitalSook ] ****/ // Required to clean the QUERY_STRING field in the template if (!isset ($query)) { $query = ""; } $templ->set_var (array ( TOPIC_IMAGE_SRC => "$imagedir/topics/$topic_image_name", TOPIC_WIDTH => $topic_image_width, TOPIC_HEIGHT => $topic_image_height, TOPIC_ALT_TEXT => $topic_alttext, QUERY_STRING => $query, ACTION_URL => $PHP_SELF )); /* print the topic select box */ $templ->set_block ("searchpage", "each_topic", "topic_block"); $templ->set_var (array ( TOPIC_VALUE => "", TOPIC_TEXT => "All Topics" )); if ($search_topic_id == "") { $templ->set_var (TOPIC_SELECTED, "selected"); } else { $templ->set_var (TOPIC_SELECTED, ""); } $templ->parse ("topic_block", "each_topic", true); $sl_q->query ("SELECT topic_id, topic_name FROM psl_topic ORDER BY topic_name"); while ($sl_q->next_record()) { $templ->set_var (array ( TOPIC_VALUE => $sl_q->Record[topic_id], TOPIC_TEXT => $sl_q->Record[topic_name] )); if ($search_topic_id == $sl_q->Record[topic_id]) { $templ->set_var (TOPIC_SELECTED, "selected"); } else { $templ->set_var (TOPIC_SELECTED, ""); } $templ->parse( "topic_block", "each_topic", true); } /* print the section select box */ $templ->set_block ("searchpage", "each_section", "section_block"); $templ->set_var (array ( SECTION_VALUE => "", SECTION_TEXT => "All Sections" )); if ($search_section_id == "") { $templ->set_var (SECTION_SELECTED, "selected"); } else { $templ->set_var (SECTION_SELECTED, ""); } $templ->parse ("section_block", "each_section", true); $sl_q->query ("SELECT section_id, section_name FROM psl_section ORDER BY section_name"); while ($sl_q->next_record()) { $templ->set_var (array ( SECTION_VALUE => $sl_q->Record[section_id], SECTION_TEXT => $sl_q->Record[section_name] )); if ($search_section_id == $sl_q->Record[section_id]) { $templ->set_var (SECTION_SELECTED, "selected"); } else { $templ->set_var (SECTION_SELECTED, ""); } $templ->parse ("section_block", "each_section", true); } /* print out the authors select box */ $templ->set_block ("searchpage", "each_author", "author_block"); $templ->set_var (array ( AUTHOR_VALUE => "", AUTHOR_TEXT => "All Authors" )); if ($search_author_id == "") { $templ->set_var (AUTHOR_SELECTED, "selected"); } else { $templ->set_var (AUTHOR_SELECTED, ""); } $templ->parse ("author_block", "each_author", true); $sl_q->query ("SELECT author_id, author_name FROM psl_author WHERE seclev > 0 ORDER BY author_id"); while ($sl_q->next_record()) { $templ->set_var (array ( AUTHOR_VALUE => $sl_q->Record[author_id], AUTHOR_TEXT => $sl_q->Record[author_name] )); if ($search_author_id == $sl_q->Record[author_id]) { $templ->set_var (AUTHOR_SELECTED, "selected"); } else { $templ->set_var (AUTHOR_SELECTED, ""); } $templ->parse( "author_block", "each_author", true ); } /* print matches */ if ($min == "") { $min = 0; } $prev = $min - $maxsearchresults; if ($prev >= 0) { $templ->set_file (previous_matches_file, "searchPrevMatches.tpl"); $templ->parse (previous_matches, previous_matches_file); $prev_matches_url = "$PHP_SELF?min=" . ($min - $maxsearchresults); /* Only put the necessary stuff on the query URL */ if ($query != "") $prev_matches_url .= "&query=$query"; if ($topic_id != "") $prev_matches_url .= "&topic_id=$topic"; if ($section_id != "") $prev_matches_url .= "&section_id=$section"; if ($author_id != "") $prev_matches_url .= "&author_id=$author"; $templ->set_var (array ( PREV_MATCHES_URL => $prev_matches_url, PREV_COUNT => $min )); $templ->parse (MATCHES, previous_matches, true); } $q = "SELECT DISTINCT story.story_id, psl_author.author_id, story.title, psl_author.author_name, date_format(story.time,\"%W, %M %d \@%h:%m\") AS dateformat, commentcount.count AS commentcount, psl_author.url \n"; if ($search_section_id != "") { $q .= ",sections.section_id ,sections.story_id"; } if ($search_topic_id != "") { $q .= ",topics.topic_id ,topics.story_id "; } $q .=" FROM psl_story story, psl_author, psl_commentcount commentcount"; if ($search_section_id != "") { $q .= ",psl_section_lut sections "; } if ($search_topic_id != "") { $q .= ",psl_topic_lut topics "; } $q .="\n WHERE story.user_id = psl_author.author_id AND story.story_id = commentcount.count_id "; if ($query != "") $q .= " AND (story.title LIKE \"%$query%\" OR story.intro_text LIKE \"%$query%\" ) "; if ($search_author_id != "") $q .= " AND psl_author.author_id = \"$search_author_id\" "; /* section and topic search are re-enabled --Daniel Serodio */ if ($search_section_id != "") $q .= " AND sections.section_id = \"$search_section_id\" AND sections.story_id = story.story_id"; if ($search_topic_id != "") $q .= " AND topics.topic_id=\"$search_topic_id\" AND topics.story_id=story.story_id"; $q .= "\n ORDER BY story.time DESC LIMIT $min,$maxsearchresults"; # echo "
$q

\n"; $sl_q->query ($q); /* Should we use num_rows() or sql COUNT? --Daniel Serodio */ if ($sl_q->num_rows() != 0) { $templ->set_file (listed_matches, "searchMatch.tpl"); $templ->set_block ("listed_matches", "each_match", "match_block"); $shown_matches = 0; while ($sl_q->next_record ()) { $templ->set_var (array ( STORY_URL => "$rootdir/article.php3?story_id=".$sl_q->Record[story_id], STORY_TITLE => $sl_q->Record[title], AUTHOR_URL => $sl_q->Record[url], AUTHOR_NAME => $sl_q->Record[author_name], DATE => $sl_q->Record[dateformat], COMMENTCOUNT => $sl_q->Record[commentcount] )); $templ->parse ("match_block", "each_match", true); $shown_matches ++; } if ($shown_matches >= ($maxsearchresults - 1)) { $min += $maxsearchresults; $templ->set_file (more_matches_file, "searchMoreMatches.tpl"); $templ->parse (more_matches, more_matches_file); $more_matches_url = "$PHP_SELF?min=$min"; /* Only put the necessary stuff on the query URL */ if ($query != "") $more_matches_url .= "&query=$query"; if ($topic_id != "") $more_matches_url .= "&topic_id=$topic_id"; if ($section_id != "") $more_matches_url .= "&section_id=$section_id"; if ($author_id != "") $more_matches_url .= "&author_id=$author_id"; $templ->set_var (MORE_MATCHES_URL, $more_matches_url); $templ->parse (MATCHES, listed_matches, true); $templ->parse (MATCHES, more_matches, true); } else { $templ->parse (MATCHES, listed_matches, true); } } else { // num_rows == 0 $templ->set_file (no_matches, "searchNoMatch.tpl"); $templ->parse (MATCHES, no_matches); } $templ->pparse ("OUT", "searchpage"); slashfoot(); ?>