Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Petit bout de code, codé avec les pieds, pour générer une liste de tous les
- * topic postés dans un sous-forum précis. C'est bourrin, mais ça marche.
- *
- * Utilisable simplement via la version ligne de commande de php
- * (voir la doc php-cli) :
- *
- * /usr/bin/php sc.php >> listing.txt
- *
- * ------------------------------------------------------------------------------
- *
- * Copyright (C) 2001-2010 Charlie Merland.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * 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. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @author Charlie Merland (charlie.merland@gmail.com)
- * @version 1.0
- * @date 2010/09/14
- */
- // url de base
- $url = "http://onenagros.free.fr/forum/viewforum.php?id=10&p=";
- // tableaux de travail
- $liste = array();
- $liste2 = array();
- // listing final
- $listing = array();
- // On parcours toutes les pages du sous-forum
- for($i=1;$i<=6;$i++)
- {
- // on récupère la page
- $fp = fopen($url.$i, 'r');
- // on la parcours par paquet de 1024 octets
- while($l = fread($fp, 1024))
- // on balance tout dans une chaine, en utf8
- $content .= utf8_encode($l);
- // on ferme le pointer de fichier
- fclose($fp);
- // on cherche tous les <div> contenant un lien intéressant
- preg_match_all('/<div class="tclcon">(.*?)<\/div>/si', $content, $matches);
- // on balance tout dans le tableau
- $liste = array_merge($liste, $matches[1]);
- }
- // on dégage tous les doublons
- $liste = array_unique($liste);
- // pour chaque élément du tableau
- foreach($liste as $sc)
- {
- // on récupère les infos : auteur, lien et titre
- preg_match_all('/<a href="(.*?)">(.*?)<\/a> <span class="byuser">(.*?)<\/span>/si', $sc, $match);
- // on ajoute tout ça dans un autre tableau
- $liste2[] = $match;
- }
- // pour chaque élément de ce nouveau tableau
- foreach($liste2 as $sc2)
- {
- // on récupère le nom de l'auteur
- $author = str_replace("par ","",$sc2[3][0]);
- // on prépare le texte
- $text = "[url=http://onenagros.free.fr/forum/".$sc2[1][0]."]".$sc2[2][0]."[/url]";
- // et on ajoute tout au listing final
- $listing[] = array($author, $text);
- }
- // gadget : le nombre de scénarios traités
- echo count($listing)." scénarios\n\n";
- // on classe le tableau par ordre alphabétique
- sort($listing);
- // et on le parcours
- for($i=0;$i<=count($listing);$i++)
- {
- // si on a un nouvel auteur, on l'affiche, histoire d'éviter
- // d'avoir son nom partout devant chaque lien
- if($listing[$i-1][0] != $listing[$i][0])
- echo " [u][b]".$listing[$i][0]."[/b][/u]\n\n";
- // sinon, on affiche juste le lien
- echo " - ".$listing[$i][1]."\n";
- // et si c'est le dernier scénario de cet auteur, on met un petit retour à la ligne
- if($listing[$i+1][0] != $listing[$i][0])
- echo "\n\n";
- }
- // The End!
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement