Advertisement
Guest User

sc.php

a guest
Sep 14th, 2010
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.40 KB | None | 0 0
  1. <?php
  2. /**
  3.  *  Petit bout de code, codé avec les pieds, pour générer une liste de tous les
  4.  *  topic postés dans un sous-forum précis. C'est bourrin, mais ça marche.
  5.  *
  6.  *  Utilisable simplement via la version ligne de commande de php
  7.  *  (voir la doc php-cli) :
  8.  *
  9.  *        /usr/bin/php sc.php >> listing.txt
  10.  *
  11.  * ------------------------------------------------------------------------------
  12.  *
  13.  * Copyright (C) 2001-2010 Charlie Merland.
  14.  *
  15.  * This program is free software; you can redistribute it and/or modify
  16.  * it under the terms of the GNU General Public License as published by
  17.  * the Free Software Foundation; either version 2 of the License, or
  18.  * (at your option) any later version.
  19.  *
  20.  * This program is distributed in the hope that it will be useful,
  21.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23.  * GNU General Public License for more details.
  24.  *
  25.  * You should have received a copy of the GNU General Public License along
  26.  * with this program; if not, write to the Free Software Foundation, Inc.,
  27.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  28.  * http://www.gnu.org/copyleft/gpl.html
  29.  *
  30.  * @author Charlie Merland (charlie.merland@gmail.com)
  31.  * @version 1.0
  32.  * @date 2010/09/14
  33.  */
  34.  
  35. // url de base
  36. $url = "http://onenagros.free.fr/forum/viewforum.php?id=10&p=";
  37.  
  38. // tableaux de travail
  39. $liste = array();
  40. $liste2 = array();
  41.  
  42. // listing final
  43. $listing = array();
  44.  
  45. // On parcours toutes les pages du sous-forum
  46. for($i=1;$i<=6;$i++)
  47. {
  48.     // on récupère la page
  49.     $fp = fopen($url.$i, 'r');
  50.     // on la parcours par paquet de 1024 octets
  51.     while($l = fread($fp, 1024))
  52.         // on balance tout dans une chaine, en utf8
  53.         $content .= utf8_encode($l);
  54.     // on ferme le pointer de fichier
  55.     fclose($fp);
  56.  
  57.     // on cherche tous les <div> contenant un lien intéressant
  58.     preg_match_all('/<div class="tclcon">(.*?)<\/div>/si', $content, $matches);
  59.     // on balance tout dans le tableau
  60.     $liste = array_merge($liste, $matches[1]);
  61. }
  62.  
  63. // on dégage tous les doublons
  64. $liste = array_unique($liste);
  65.  
  66. // pour chaque élément du tableau
  67. foreach($liste as $sc)
  68. {
  69.     // on récupère les infos : auteur, lien et titre
  70.     preg_match_all('/<a href="(.*?)">(.*?)<\/a> <span class="byuser">(.*?)<\/span>/si', $sc, $match);
  71.     // on ajoute tout ça dans un autre tableau
  72.     $liste2[] = $match;
  73. }
  74.  
  75. // pour chaque élément de ce nouveau tableau
  76. foreach($liste2 as $sc2)
  77. {
  78.     // on récupère le nom de l'auteur
  79.     $author = str_replace("par&nbsp;","",$sc2[3][0]);
  80.     // on prépare le texte
  81.     $text = "[url=http://onenagros.free.fr/forum/".$sc2[1][0]."]".$sc2[2][0]."[/url]";
  82.     // et on ajoute tout au listing final
  83.     $listing[] = array($author, $text);
  84. }
  85.  
  86. // gadget : le nombre de scénarios traités
  87. echo count($listing)." scénarios\n\n";
  88.  
  89. // on classe le tableau par ordre alphabétique
  90. sort($listing);
  91. // et on le parcours
  92. for($i=0;$i<=count($listing);$i++)
  93. {
  94.     // si on a un nouvel auteur, on l'affiche, histoire d'éviter
  95.     // d'avoir son nom partout devant chaque lien
  96.     if($listing[$i-1][0] != $listing[$i][0])
  97.         echo "    [u][b]".$listing[$i][0]."[/b][/u]\n\n";
  98.  
  99.     // sinon, on affiche juste le lien
  100.     echo " - ".$listing[$i][1]."\n";
  101.     // et si c'est le dernier scénario de cet auteur, on met un petit retour à la ligne
  102.     if($listing[$i+1][0] != $listing[$i][0])
  103.         echo "\n\n";
  104. }
  105.  
  106. // The End!
  107. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement