define("NB_MESSAGES_PER_PAGE", 15);
define("NB_CHARS_AROUND_KEYWORD", 100);
define("HTTP_ROOT", "http://www.toutjavascript.com/");
$ar_forums = Array(1 => "Javascript",
2 => "Programmation serveur",
3 => "Votre site",
4 => "Débats et réflexions",
5 => "Sur le site",
6 => "Bla bla");
?>
/*foreach($_POST as $key => $value)
{
print $key."=".$value."
\n";
}*/
if (strlen($_POST['btn_submit']))
{
$keywords = trim($_POST['keywords']);
$keywords = ereg_replace(" +", "###", $keywords);
$ar_keywords = explode("###", $keywords);
$id_conn = mysql_connect("sql.beaute-test.com", "frosty", "tyfrosBT");
mysql_select_db("atoutjav");
$req = "SELECT ID, auteur, dtpost, subject, IDforum, nbrep, fin FROM forum_topic"
. " WHERE 0=0";
if (strlen(trim($_POST['author']))) $req .= " AND auteur RLIKE '^".trim($_POST['author'])."$'";
/*if (strlen($keywords) && $_POST['search_into_titles'] == "on")
{
for($i = 0; $i < count($ar_keywords); $i++)
$req .= " AND subject RLIKE '".$ar_keywords[$i]."'";
}*/
if (strlen($keywords))
{
$req_msg = "SELECT M.IDtopic IDtopic, M.body body, M.auteur auteur, M.dtpost dtpost"
. " FROM forum_topic T, forum_msg M"
. " WHERE M.IDtopic = T.ID";
for($i = 0; $i < count($ar_keywords); $i++)
$req_msg .= " AND M.body LIKE '%".$ar_keywords[$i]."%'";
if (strlen(trim($_POST['author']))) $req_msg .= " AND T.auteur LIKE '%".trim($_POST['author'])."%'";
if ($_POST['search_satisfied'] == "on") $req_msg .= " AND T.fin = 1";
if (intval($_POST['forum']) > 0) $req_msg .= " AND T.IDforum = ".$_POST['forum'];
if (is_date($_POST['date_1']))
{
list($d, $m, $y) = explode("/", $_POST['date_1'], 3);
$req_msg .= " AND T.dtpost >= ".mktime(0, 0, 0, $m, $d, $y);
}
if (is_date($_POST['date_2']))
{
list($d, $m, $y) = explode("/", $_POST['date_2'], 3);
$req_msg .= " AND T.dtpost <= ".mktime(24, 59, 59, $m, $d, $y);
}
$req_msg .= " ORDER BY M.dtpost DESC LIMIT 20";
$time_start = getmicrotime();
$res_msg = tjs_query($req_msg) or die(mysql_error());
while($row_msg = mysql_fetch_assoc($res_msg))
{
$ar_messages[intval($row_msg['IDtopic'])][] = $row_msg;
}
$time_end = getmicrotime();
$time = $time_end - $time_start;
print "Temps : ".round($time, 3)." secondes\n";
if (is_array($ar_messages) && count($ar_messages))
{
$req .= " AND ID in (";
$comma = false;
foreach($ar_messages as $key => $value)
{
if ($comma) $req .= ", ";
$req .= $key;
if (!$comma) $comma = true;
for($i = 0; $i < count($value); $i++)
{
$req_page = "SELECT COUNT(*) nb_rep FROM forum_msg "
. " WHERE IDtopic = ".$value[$i]['IDtopic']." AND dtpost < ".$value[$i]['dtpost'];
$res_page = tjs_query($req_page) or die(mysql_error());
$row_page = mysql_fetch_assoc($res_page);
$value[$i]['body'] = preg_replace("/\\[\\/?(A|SCRIPT|B)\\]/", "", $value[$i]['body']);
preg_match("/.{0,".NB_CHARS_AROUND_KEYWORD."}".$ar_keywords[0].".{0,".NB_CHARS_AROUND_KEYWORD."}/is", $value[$i]['body'], $result);
$keywords_regexp = $ar_keywords[0];
for($k = 1; $k < count($ar_keywords); $k++)
$keywords_regexp .= "|".$ar_keywords[$k];
$value[$i]['body'] = preg_replace("/(".$keywords_regexp.")/is", "\\1", htmlspecialchars($result[0]));
$value[$i]['page'] = floor(intval($row_page['nb_rep'])/NB_MESSAGES_PER_PAGE)+1;
//print "(page ".$value[$i]['page']." ".$value[$i]['IDtopic']." ".$value[$i]['auteur'].") ".$value[$i]['body']."
";
}
$ar_messages[$key] = $value;
}
$req .= ")";
}
else
{
$req .= " AND 0=1";
}
}
if ($_POST['search_satisfied'] == "on") $req .= " AND fin = 1";
if (intval($_POST['forum']) > 0) $req .= " AND IDforum = ".$_POST['forum'];
if (is_date($_POST['date_1']))
{
list($d, $m, $y) = explode("/", $_POST['date_1'], 3);
$req .= " AND dtpost >= ".mktime(0, 0, 0, $m, $d, $y);
}
if (is_date($_POST['date_2']))
{
list($d, $m, $y) = explode("/", $_POST['date_2'], 3);
$req .= " AND dtpost <= ".mktime(24, 59, 59, $m, $d, $y);
}
$req .= " ORDER BY dtpost DESC LIMIT 20";
//print $req;
$res = tjs_query($req) or die(mysql_error());
while($row = mysql_fetch_assoc($res))
{
$ar_topics[$row['ID']] = $row;
}
mysql_close($id_conn);
?>
Résultats de la recherche :
if (is_array($ar_topics) && count($ar_topics))
{
foreach($ar_topics as $key=>$value)
{
$ar_temp = $ar_messages[intval($value['ID'])];
$with_messages = (is_array($ar_temp) && count($ar_temp));
?>
créée par
le 01/01/1970 01:00
( réponses)
|
|
if ($with_messages)
{
?>
for($i = 0; $i < count($ar_temp); $i++)
{
?>
......
}
?> |
}
?>
}
}
else
{
?>Aucune discussion trouvée.
}
?>
}
else
{
?>
Rechercher des discussions :
}
?>
/*************
* Functions
**************/
/* function is_date($str)
*
* parameter : $str : any string
* returns : true if the format DD/MM/YYYY is recognized
* false otherwise
*/
function is_date($str)
{
list($day, $month, $year) = explode("/", $str, 3);
$day = (int)$day;
$month = (int)$month;
$year = (int)$year;
return($day > 0 && $month > 0
&& $day <= nb_days_in_month($month, $year)
&& $month <= 12);
}
/*
* function nb_days_in_month($month, $year)
*
* parameters : a month $month, a year $year
* returns : the number of days in the month $month of the year $year
*/
function nb_days_in_month($month, $year)
{
switch($month)
{
case 4 :
case 6 :
case 9 :
case 11 :
$days = 30;
break;
case 2 :
if (leap_year($year))
$days = 29;
else
$days = 28;
break;
default :
$days = 31;
}
return $days;
}
/*
* function leap_year($year)
*
* parameters : a year $year
* returns : true if the year $year is a leap year, otherwise false.
* (eng. leap year = fr. année bissextile)
* thanks to Rodolphe Breton for simplifications.
*/
function leap_year($year)
{
return ((!($year%4) && $year%100) || !($year%400));
}
function getmicrotime()
{
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
?>