// PHPMyLinks version 0.1.4, Copyright (C) 2000, Rémi Henriot
// http://rhenriot.free.fr/phpmylinks/ - rhenriot@mail.com
//
// This is free software ; you can redistribute it and/or modify it
// under the terms of the PHPMyLinks License Version 1.0
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY ; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// For more details, see the license.txt file that you should have
// received with this program.
require 'connexion.inc.php3';
require 'links.inc.php3';
// header of the page
include $header;
// get the 'cat_id' and 'sca_id' of the $default_cat, if no sca_id is given
if(! isset($sca_id))
{
if(strpos($default_cat,'/'))
{
$ar = split('/',$default_cat);
$cat_name = trim($ar[0]);
$sca_name = trim($ar[1]);
} else {
$cat_name = $default_cat;
$sca_name = '';
}
$result = mysql_query("select cat_id from categorie ".
"where cat_nom='$cat_name'");
if( $row = mysql_fetch_object($result))
$cat_id = $row->cat_id;
else
$cat_id = -1;
$result = mysql_query("select sca_id from sous_categorie ".
"where sca_nom='$sca_name' and cat_id = '$cat_id'");
if( $row = mysql_fetch_object($result))
$sca_id = $row->sca_id;
}
// get sub-category with 'NULL' name, if no one is given
if(!isset($sca_id))
$sca_id = main_sub_sca($cat_id);
// clean keywords string
$keywords = stripslashes(Chop($keywords));
?>
$keywords = stripslashes(Chop($keywords));
if(strlen($keywords) == 0)
{
// get the name of the category and sub-category selected
$res = mysql_query("select cat.cat_nom, sca.sca_nom ".
"from categorie cat, sous_categorie sca ".
"where cat.cat_id = sca.cat_id and sca.sca_id = $sca_id");
$title = mysql_fetch_row($res);
if($title)
echo "$title[0] / $title[1]";
else
echo "...";
}
else
{
// or get the keyword list
echo "pages associées au mot(s) clé(s) : $keywords";
}
?>
|
if(strlen($keywords) == 0) // there's no keyword, let's display the content of the sub-category selected
{
// construction the query to get URLs linked with "sca_id"
$query = "select url.url_str, url.url_titre, url.url_descr, url.url_id ".
"from classement cla, url ".
"where cla.url_id = url.url_id ".
"and cla.sca_id = ".$sca_id." ".
"order by url.url_titre";
}
else // find the URLs linked with the keywords
{
// first, let's build an array coutaining all keywords like "blabla blabla"
$i = 0;
while(ereg('"([^"]*)"', $keywords, $word))
{
$keywords = ereg_replace("\"$word[1]\"", '', $keywords);
$key[$i] = $word[1];
$i++;
}
// then get the remainig keywords in another array
$simple_key = explode(' ', $keywords);
// and append the second array to the first one
for($j=0; $j < sizeof($simple_key); $j++)
{
if($simple_key[$j] != '')
{
$key[$i] = $simple_key[$j];
$i++;
}
}
// for example, if we have the folowing keywords : "screen saver free",
// we construct a query like this one :
/*
select url.url_str, url.url_titre, url.url_descr, url.url_id
from url,
reference ref0, mot_cle cle0,
reference ref1, mot_cle cle1,
reference ref2, mot_cle cle2
where url.url_id = ref0.url_id and ref0.cle_id = cle0.cle_id and cle0.cle_mot = "screen"
and url.url_id = ref1.url_id and ref1.cle_id = cle1.cle_id and cle1.cle_mot = "saver"
and url.url_id = ref2.url_id and ref2.cle_id = cle2.cle_id and cle2.cle_mot = "free"
order by url.url_titre
*/
// 'select' part
$query = 'select url.url_str, url.url_titre, url.url_descr, url.url_id '.
'from url';
// 'from' part
for($i=0; $i < sizeof($key); $i++)
$query = $query.', reference ref'.$i.', mot_cle cle'.$i;
// 'where' part
$query = $query.' where ';
for($i=0; $i < sizeof($key); $i++)
{
$query = $query.'url.url_id = ref'.$i.'.url_id and ref'.$i.'.cle_id = cle'.$i.'.cle_id '.
'and cle'.$i.'.cle_mot = "'.$key[$i].'"';
if($i+1 < sizeof($key)) $query = $query.' and ';
}
// Clause 'order by'
$query = $query.' order by url.url_titre';
}
// whatever query has been construced : query execution and results
$result = mysql_query($query);
while($row=mysql_fetch_object($result))
{
$not_empty = true;
if(! ereg('http://', $row->url_str)) $row->url_str = 'http://'.$row->url_str;
echo "\n";
echo "\n";
echo "($row->url_str) $row->url_descr
\n";
echo " |
\n";
}
?>
if(! isset($not_empty)): ?>
Aucune page trouvée.
endif; ?>
include $footer; ?>