Visualisation du fichier liens.php
<?php
// Nouvelle méthode de faire : on vérifie que la catégorie en cours est bien demandée
// par l'URL. Dans ce cas, on gènere tout le bordel relatif à cette catégorie
// sinon, on génère que dalle.
// Attention, mise à jour de la varible globale lorsque l'on voit la balise de fin.
// Je sais, y a mieux que de tester à chaque balise mais je m'en fous.
// Plutôt que de parser 2 fois pour compter le nombre de lien, j'ai mis la hauteur en attributs - je sais c mal mais cf. au-dessus
//--------------------------------------------------------------------------------------------------------------------------------
global $flag_gen;
global $ref_lien;
global $hauteur;
global $liste;
$flag_gen = true;
// Récupération de la liste demandée sous la forme d'une liste de noms de catégories (tous par défaut)
// L'appel est ...?liste=...
//--------------------------
$query_string = getenv("QUERY_STRING");
$query_string = substr($query_string,strpos($query_string, '-')+1,strlen($query_string));
$env_array = split("-", $query_string);
while (list($key, $val) = each($env_array)) {
list($name, $value) = split("=", $val);
global $name;
$name = urldecode($name);
$value = urldecode($value);
$$name = trim($value) ;
}
function startLink ($parser, $name, $attrs){
switch ($name) {
case "CATEGORIE":
// On vérifie que la catégorie est bien demandée.
// Le nom de la catégorie est le premier attirbut (ça pue la bidouille)
// attention à l'opérateur à utiliser ....
//---------------------------------------------------------------------
$nom_cat = array_shift($attrs);
$GLOBALS["hauteur"] = array_shift($attrs);
if (strtolower($GLOBALS["liste"]) == "tous" || strpos(','.strtolower($GLOBALS["liste"]).',',','.strtolower($nom_cat).',') !== false) {
$GLOBALS["flag_gen"] = true;
} else {
$GLOBALS["flag_gen"] = false;
}
// On vérifie si on doit générer
//------------------------------
if ( $GLOBALS["flag_gen"] == true) {
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
echo "\n<tr>";
echo "\n\t <td colspan=\"3\"> \n\t\t <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"> \n\t\t <tr>";
echo "\n\t\t\t <td width=\"11\"><img src=\"img/haut_gauche.jpg\" width=\"11\" height=\"15\" alt=\"\"></td>";
echo "\n\t\t\t <td class=\"big_title_in_the_ass\" align=\"left\">".$nom_cat."</td>";
echo "\n\t\t\t <td width=\"7\" align=\"right\"><img src=\"img/dh_gros.gif\" width=\"7\" height=\"15\" alt=\"\"></td> ";
echo "\n\t\t </tr> \n\t </table> \n\t </td>\n </tr>";
echo "<tr>";
echo "<td width=\"11\" align=\"left\"><img width=\"11\" height=\"".$GLOBALS["hauteur"]."\" src=\"img/bg.jpg\" alt=\"\"></td>";
echo "<td>";
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">";
echo "<tr>";
}
break;
case "SUB_CAT":
if ( $GLOBALS["flag_gen"] == true) {
echo "<tr><td> <br></td></tr><tr>"; // pour espacer un peu sans cellpadding ou cellspacing de merD...
echo "\n\t <td align=\"center\"> \n\t\t <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"> \n\t\t <tr>";
echo "\n\t\t\t <td> \n\t\t\t\t <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"275\">";
echo "\n\t\t\t\t <tr> \n\t\t\t\t <td width=\"8\"><img src=\"img/hg_gris.jpg\" width=\"8\" height=\"15\" alt=\"\"></td>";
echo "\n\t\t\t\t <td width=\"250\" class=\"bgtiny\">".array_shift($attrs)."</td>";
echo "\n\t\t\t\t <td align=\"left\"><img src=\"img/dh_gris.jpg\" width=\"7\" height=\"15\" alt=\"\"/></td>";
echo "\n\t\t\t </tr> \n\t\t\t </table> \n\t\t</td> \n\t\t</tr>";
echo "<tr><td><img width=\"100%\" height=\"1\" src=\"img/bas_gris.jpg\"/></td></tr>";
echo "<tr> <td>";
}
break;
case "LINK":
if ( $GLOBALS["flag_gen"] == true) {
echo "\n\t\t\t <table border=\"0\" width=\"100%\" cellpadding=\"0\" cellspacing=\"0\"> \n\t\t\t <tr>";
echo "<td width=\"15\"><img src=\"img/gauche_gris.jpg\" width=\"4\" height=\"20\" alt=\"\"></td><td>"; // Les éléments du lien
}
break;
case "NOM":
if ( $GLOBALS["flag_gen"] == true) {
$GLOBALS["ref_lien"] = array_shift($attrs);
echo "<img src=\"img/bulle.jpg\" width=\"8\" height=\"8\" alt=\"\"> <a href=\"".$GLOBALS["ref_lien"]."\" target=\"_blank\"><b>";
}
break;
case "RESUME":
if ( $GLOBALS["flag_gen"] == true) {
echo "<tr><td ><img src=\"img/gauche_gris.jpg\" width=\"4\" height=\"20\" alt=\"\"></td><td><i>";
}
break;
}
}
function endLink ($parser, $name){
switch ($name) {
case "CATEGORIE":
// On vérifie si on doit générer et on remet à jour la variable
//-------------------------------------------------------------
if ( $GLOBALS["flag_gen"] == true) {
echo "</td></tr>\n"; // Le titre
echo "</table>";
echo "</td><td width=\"10\" align=\"right\"><img src=\"img/db.gif\" width=\"1\" height=\"".$GLOBALS["hauteur"] ."\" alt=\"\"></td></tr>";
echo "<tr><td><img src=\"img/bas_gauche.jpg\" width=\"11\" height=\"4\" alt=\"\"></td>";
echo "<td colspan=\"2\"><img src=\"img/bas.jpg\" width=\"100%\" height=\"4\" alt=\"\"></td></tr>";
echo "</table><br><br>";
}
$GLOBALS["flag_gen"] = true;
break;
case "SUB_CAT":
if ( $GLOBALS["flag_gen"] == true) {
echo "</td>";
echo "</tr><tr><td><img height=\"4\" width=\"100%\" src=\"img/bas_gris.jpg\"/></td>";
echo "</tr></table>";
}
break;
case "LINK":
if ( $GLOBALS["flag_gen"] == true) {
echo "</table>";
}
break;
case "NOM":
if ( $GLOBALS["flag_gen"] == true) {
echo "</b></a> (".$GLOBALS["ref_lien"].")</td><td align=\"right\"><img src=\"img/droit_gris.gif\" width=\"1\" height=\"20\" alt=\"\"></td></tr>";
}
break;
case "RESUME":
if ( $GLOBALS["flag_gen"] == true) {
echo "</i></td><td align=\"right\"><img src=\"img/droit_gris.gif\" width=\"1\" height=\"20\" alt=\"\"></td></tr>";
}
break;
}
}
function cdataLink ($parser, $data_text){
if ($GLOBALS["flag_gen"] == true) {echo $data_text;}
}
$xmlFile = file($listelink);
$xml_parseur = xml_parser_create();
xml_set_element_handler($xml_parseur, "startLink", "endLink");
xml_set_character_data_handler($xml_parseur, "cdataLink");
foreach($xmlFile as $elem)
{xml_parse($xml_parseur, $elem);}
?>