Created
December 29, 2011 01:01
-
-
Save kevinclark/1530867 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
include("connectdb.php"); | |
// Show the source if asked | |
if ($HTTP_GET_VARS['src'] == 1) { highlight_file($SCRIPT_FILENAME); return;} | |
if ( ($con = db_connect()) == false ) die ( "SQL connection failed"); | |
//$query = "select top 1 from issues where active = '1' order by issuenum desc"; | |
$query = "select * from issues where active = '1' order by issuenum desc"; | |
$result = mysql_query($query); | |
$row = mysql_fetch_array($result); | |
$issue = $row['issuenum']; | |
$header_img = $row['head_img']; | |
$skycap1 = $row['skycap1']; | |
$skycap2 = $row['skycap2']; | |
$skycap3 = $row['skycap3']; | |
$skycap1_descr = $row['skycap1_descr']; | |
$skycap2_descr = $row['skycap2_descr']; | |
$skycap3_descr = $row['skycap3_descr']; | |
// Code to actually run search | |
if($search_str) | |
{ | |
$search_args = explode(" ", $search_str); | |
$num_args = sizeof($search_args); | |
if ( $search_bound == "TITLE" || $search_bound == "TEXT" ) | |
$query = "select articleid,issue,headline,sub,story from theMQ "; | |
else if ( $search_bound == "BRIEF" ) | |
$query = "select * from newsbriefs "; | |
else if ( $search_bound == "TOP10" ) | |
$query = "select top10index.ttid,top10index.issue,top10index.title,top10index.numitems,top10values.value,top10values.rank,top10values.vid from top10index left join top10values on top10index.ttid=top10values.ttid "; | |
$where_str = "where "; | |
for ( $i = 0 ; $i < $num_args ; $i++ ) | |
{ | |
if ( $search_bound == "TITLE" ) | |
{ | |
$where_str .= "headline LIKE '%$search_args[$i]%' OR "; | |
$where_str .= "sub LIKE '%$search_args[$i]%'"; | |
} | |
else if ( $search_bound == "TEXT" ) | |
$where_str .= "story LIKE '%$search_args[$i]%'"; | |
else if ( $search_bound == "BRIEF" ) | |
{ | |
$where_str .= "title LIKE '%$search_args[$i]%' OR "; | |
$where_str .= "story LIKE '%$search_args[$i]%'"; | |
} | |
else if ( $search_bound == "TOP10" ) | |
{ | |
$where_str .= "title LIKE '%$search_args[$i]%' OR "; | |
$where_str .= "value LIKE '%$search_args[$i]%'"; | |
} | |
if ( $i + 1 < $num_args ) | |
$where_str .= " OR "; | |
} | |
$query = $query . $where_str; | |
$results = mysql_query($query); | |
if ( !$results ) { print $query . "<br />"; die ( mysql_error()); } | |
// FOR EVERY ROW, GET SCORE | |
$num_results = $num_rows = mysql_num_rows($results); | |
for ( $i = 0 ; $i < $num_rows ; $i++ ) | |
{ | |
$row = mysql_fetch_array($results); | |
$score = 0; | |
for ( $j = 0 ; $j < $num_args ; $j++ ) | |
{ | |
if ( $search_bound == "TITLE" ) | |
{ | |
// A point for being there | |
if ( stristr( $row['headline'], $search_args[$j] ) != FALSE || | |
stristr( $row['sub'], $search_args[$j] ) != FALSE ) | |
$score++; | |
// Give an extra point to whole words | |
if ( stristr( $row['headline'], " $search_args[$j] " ) != FALSE || | |
stristr( $row['sub'], " $search_args[$j] " ) != FALSE || | |
eregi( "^$search_args[$j] ", $row['sub'] ) != 0 || | |
eregi( "^$search_args[$j] ", $row['headline'] ) != 0 || | |
eregi( " $search_args[$j]$", $row['sub'] ) != 0 || | |
eregi( " $search_args[$j]$", $row['headline'] ) != 0 ) | |
$score++; | |
// Give an extra point to beginning of words | |
if ( stristr( $row['headline'], " $search_args[$j]" ) != FALSE || | |
stristr( $row['sub'], " $search_args[$j]" ) != FALSE || | |
eregi( "^$search_args[$j]", $row['sub'] ) != 0 || | |
eregi( "^$search_args[$j]", $row['headline'] ) != 0 ) | |
$score++; | |
} | |
else if ( $search_bound == "TEXT" ) | |
{ | |
// A point for being there | |
if ( stristr( $row['story'], $search_args[$j] ) != FALSE ) | |
$score++; | |
// Give an extra point to whole words | |
if ( stristr( $row['story'], " $search_args[$j] ") != FALSE || | |
eregi( "^$search_args[$j] ", $row['story'] ) != 0 || | |
eregi( " $search_args[$j]$", $row['story'] ) != 0 ) | |
$score++; | |
// Extra point to beginning of words | |
if ( stristr( $row['story'], " $search_args[$j]" ) != FALSE || | |
eregi( "^$search_args[$j]", $row['story'] ) != 0 ) | |
$score++; | |
} | |
else if ( $search_bound == "BRIEF" ) | |
{ | |
// A point for being there | |
if ( stristr( $row['title'], $search_args[$j] ) != FALSE || | |
stristr( $row['story'], $search_args[$j] ) != FALSE ) | |
$score++; | |
// Extra point to whole words | |
if ( stristr( $row['title'], " $search_args[$j] " ) != FALSE || | |
stristr( $row['story'], " $search_args[$j] " ) != FALSE || | |
eregi( "^$search_args[$j] ", $row['title'] ) != 0 || | |
eregi( "^$search_args[$j] ", $row['story'] ) != 0 || | |
eregi( " $search_args[$j]$", $row['title'] ) != 0 || | |
eregi( " $search_args[$j]$", $row['story'] ) != 0 ) | |
$score++; | |
// Extra point to beginning of words | |
if ( stristr( $row['story'], " $search_args[$j]" ) != FALSE || | |
stristr( $row['title'], " $search_args[$j]" ) != FALSE || | |
eregi( "^$search_args[$j]", $row['story'] ) != 0 || | |
eregi( "^$search_args[$j]", $row['title'] ) != 0 ) | |
$score++; | |
} | |
else if ( $search_bound == "TOP10" ) | |
{ | |
// A point for being there | |
if ( stristr( $row['title'], $search_args[$j] ) != FALSE || | |
stristr( $row['value'], $search_args[$j] ) != FALSE ) | |
$score++; | |
// Extra point to whole words | |
if ( stristr( $row['title'], " $search_args[$j] " ) != FALSE || | |
stristr( $row['value'], " $search_args[$j] " ) != FALSE || | |
eregi( "^$search_args[$j] ", $row['title'] ) != 0 || | |
eregi( "^$search_args[$j] ", $row['value'] ) != 0 || | |
eregi( " $search_args[$j]$", $row['title'] ) != 0 || | |
eregi( " $search_args[$j]$", $row['value'] ) != 0 ) | |
$score++; | |
// Extra point to beginning of words | |
if ( stristr( $row['title'], " $search_args[$j]" ) != FALSE || | |
stristr( $row['value'], " $search_args[$j]" ) != FALSE || | |
eregi( "^$search_args[$j]", $row['title'] ) != 0 || | |
eregi( "^$search_args[$j]", $row['value'] ) != 0 ) | |
$score++; | |
// If the term is in the title, just show title.. and move on! | |
if ( stristr( $row['title'], $search_args[$j] ) != FALSE ) | |
$TITLE_ONLY[$row['vid']] = true; | |
} | |
} | |
$score = $score / $num_args; | |
if ( $search_bound == "TEXT" || $search_bound == "TITLE" ) | |
{ | |
$content[$row['articleid']] = stripslashes($row['headline']); | |
if ( !empty($row['sub']) ) $content[$row['articleid']] .= ", " . stripslashes($row['sub']); | |
$links[$row['articleid']] = "http://www.themq.com/index.php?issue=" . $row['issue'] . "&articleid=" . $row['articleid']; | |
$scores[$row['articleid']] = $score; | |
} | |
else if ( $search_bound == "BRIEF" ) | |
{ | |
$content[$row['breifid']] = stripslashes($row['title']); | |
$scores[$row['breifid']] = $score; | |
$links[$row['breifid']] = "http://www.themq.com/newsbrief.php?breifid=" . $row['breifid']; | |
} | |
else if ( $search_bound == "TOP10" ) | |
{ | |
$content[$row['vid']] = stripslashes($row['title'] . " #" . $row['rank'] . " " . $row['value']); | |
$scores[$row['vid']] = $score; | |
$links[$row['vid']] = "http://www.themq.com/topten.php?ttid=" . $row['ttid']; | |
if ( $TITLE_ONLY[$row['vid']] == true ) | |
{ | |
$content[$row['vid']] = stripslashes($row['title']); | |
$numitems = $row['numitems']; | |
for ( $k = 0 ; $k < $numitems - 1 ; $k++) | |
{ | |
$row = mysql_fetch_array($results); | |
$num_results--; | |
} | |
} | |
} | |
} | |
arsort($scores); | |
$scoreKeys = array_keys($scores); | |
} | |
?> | |
<!DOCTYPE html | |
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml-strict.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<title>The MQ - So Much Funk, So Little Time</title> | |
<meta http-equiv="Content-type" content="text/html; charset=windows-1250" /> | |
<link href="main.css" rel="stylesheet" type="text/css" /> | |
<script language="Javascript"> | |
function popUp(strURL,strType,strHeight,strWidth) { | |
var strOptions=""; | |
if (strType=="console") strOptions="resizable,height="+strHeight+",width="+strWidth; | |
if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth; | |
if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth; | |
window.open(strURL, 'newWin', strOptions); | |
} | |
</script> | |
</head> | |
<body> | |
<div id="central"> | |
<div id="logotype" style="background-image: url('<?=$header_img;?>');"> | |
<span class="skycap"><img class="skybox" src="<?=$skycap1;?>" alt="<?=$skycap1_descr?>" /></span> | |
<span class="skycap"><img class="skybox" src="<?=$skycap2;?>" alt="<?=$skycap2_descr?>" /></span> | |
<span class="skycap"><img class="skybox" src="<?=$skycap3;?>" alt="<?=$skycap3_descr?>" /></span> | |
<br /> | |
<span class="navi"> | |
<a href="http://www.themq.com/index.php"><img src="images/current.gif" alt="Current" /></a> | |
</span> | |
<span class="navi"> | |
<a href="http://www.themq.com/archives.php"><img src="images/archives.gif" alt="Archives" /></a> | |
</span> | |
<span class="navi"> | |
<a href="http://www.themq.com/about.php"><img src="images/about.gif" alt="About" /></a> | |
</span> | |
<span class="navi"> | |
<a href="http://www.themq.com/contact.php"><img src="images/contact.gif" alt="Contact" /></a> | |
</span> | |
<span class="navi"> | |
<a href="http://www.themq.com/ads.php"><img src="images/ads.gif" alt="Advertising" /></a> | |
</span> | |
<span class="navi"> | |
<a href="http://forums.themq.com/"><img src="images/forums.gif" alt="Forums" /></a> | |
</span> | |
</div> | |
<div id="pad_hack"> | |
<div id="search_result"> | |
<h3><span>Search Results: <?=$num_results?> entries found for "<?=$search_str?>"</span></h3> | |
<p> | |
<? | |
for ( $i = 0 ; $i < $num_results ; $i++ ) | |
{ | |
if ( $search_bound == "TEXT" || $search_bound == "TITLE" ) | |
print "<a href=" . $links[$scoreKeys[$i]] . "'>" | |
. str_replace("&", "&", $content[$scoreKeys[$i]]) . "</a>"; | |
else | |
{ | |
print '<a href="' . $links[$scoreKeys[$i]] . '" onclick="popUp(this.href,\'fixed\',450,400);return false;" target="newWin">' | |
. str_replace("&", "&", $content[$scoreKeys[$i]]) . "</a>"; | |
} | |
print "<br />"; | |
} | |
?> | |
</p> | |
</div> | |
</div> | |
</div> | |
<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"> | |
</script> | |
<script type="text/javascript"> | |
_uacct = "UA-89073-2"; | |
urchinTracker(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Circa '03