New file |
0,0 → 1,161 |
<?php |
/*vim: set expandtab tabstop=4 shiftwidth=4: */ |
// +------------------------------------------------------------------------------------------------------+ |
// | PHP version 5.1 | |
// +------------------------------------------------------------------------------------------------------+ |
// | Copyright (C) 1999-2006 Tela Botanica (accueil@tela-botanica.org) | |
// +------------------------------------------------------------------------------------------------------+ |
// | This file is part of tela_botanica_v4. | |
// | | |
// | Foobar 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. | |
// | | |
// | Foobar 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 Foobar; if not, write to the Free Software | |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
// +------------------------------------------------------------------------------------------------------+ |
// CVS : $Id$ |
/** |
* tela_botanica_v4 - nettoyage_wikini.php |
* |
* Description : |
* |
*@package tela_botanica_v4 |
//Auteur original : |
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org> |
//Autres auteurs : |
*@author Aucun |
*@copyright Tela-Botanica 1999-2007 |
*@version $Revision$ $Date$ |
// +------------------------------------------------------------------------------------------------------+ |
*/ |
|
// +------------------------------------------------------------------------------------------------------+ |
// | ENTÊTE du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
define('CHEMIN_PEAR', '../api/pear/'); |
$GLOBALS['_NETTOYAGE_']['sites'] = array('http://www.tela-botanica.org', 'http://www.outils-reseaux.org'); |
|
// +------------------------------------------------------------------------------------------------------+ |
// | CORPS du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
$Nettoyage = new Nettoyage(); |
$Nettoyage->nettoyageGlobal(); |
|
// +------------------------------------------------------------------------------------------------------+ |
// | CLASSES du PROGRAMME | |
// +------------------------------------------------------------------------------------------------------+ |
class Nettoyage { |
|
public function __construct() |
{ |
$fichier_ini = 'bdd.ini'; |
if (file_exists($fichier_ini)) { |
$this->parserFichierIni($fichier_ini); |
require_once CHEMIN_PEAR.'DB.php'; |
$this->connexion = DB::connect($this->bdd_dsn, $this->bdd_options); |
if (PEAR::isError($this->connexion)) { |
$e = $this->connexion->getMessage(); |
trigger_error($e, E_USER_ERROR); |
} |
} |
} |
|
public function nettoyageGlobal() |
{ |
$res = $this->connexion->query('SHOW TABLES'); |
if (PEAR::isError($res)) { |
die($res->getMessage()); |
} |
$tab_tables = array(); |
$ligne = ''; |
while ($res->fetchInto($ligne)) { |
$tab_tables[] = $ligne[0]; |
} |
|
echo '<pre>'; |
foreach ($tab_tables as $table) { |
echo "\n".$table."\n"; |
|
// Referrers |
if (preg_match('/_referrers$/', $table)) { |
$site_nbre = count($GLOBALS['_NETTOYAGE_']['sites']); |
$site_0 = $GLOBALS['_NETTOYAGE_']['sites'][0]; |
$requete = 'DELETE FROM '.$table.' '. |
'WHERE referrer NOT LIKE "'.$site_0.'%" '; |
for ($i = 1; $i < $site_nbre; $i++) { |
$requete .= 'AND referrer NOT LIKE "'.$GLOBALS['_NETTOYAGE_']['sites'][$i].'%" '; |
} |
echo $requete."\n"; |
$res = $this->connexion->query($requete); |
if (PEAR::isError($res)) { |
die($res->getMessage()); |
} |
} |
|
// Pages : commentaires |
if (preg_match('/_pages$/', $table)) { |
$requete = 'DELETE FROM '.$table.' '. |
'WHERE tag LIKE "Comment%" '; |
echo $requete."\n"; |
$res = $this->connexion->query($requete); |
if (PEAR::isError($res)) { |
die($res->getMessage()); |
} |
} |
|
// ACLs : commentaires |
if (preg_match('/_acls$/', $table)) { |
$requete = 'DELETE FROM '.$table.' '. |
'WHERE page_tag LIKE "Comment%" '; |
echo $requete."\n"; |
$res = $this->connexion->query($requete); |
if (PEAR::isError($res)) { |
die($res->getMessage()); |
} |
|
$requete = 'UPDATE '.$table.' '. |
'SET list = "+" '. |
'WHERE privilege = "comment" '; |
echo $requete."\n"; |
$res = $this->connexion->query($requete); |
if (PEAR::isError($res)) { |
die($res->getMessage()); |
} |
} |
} |
echo '</pre>'; |
} |
|
private function parserFichierIni($fichier_ini) |
{ |
if (file_exists($fichier_ini)) { |
$aso_ini = parse_ini_file($fichier_ini); |
foreach ($aso_ini as $cle => $val) { |
if (preg_match('/^php:(.+)$/', $val, $correspondances)) { |
eval('$this->$cle = '.$correspondances[1].';'); |
} else if (preg_match('/^php-static:(.+)$/', $val, $correspondances)) { |
eval('self::$'.$cle.' = '.$correspondances[1].';'); |
} else { |
$this->$cle = $val; |
} |
} |
} else { |
return false; |
} |
} |
} |
/* +--Fin du code ----------------------------------------------------------------------------------------+ |
* |
* $Log$ |
* |
* +-- Fin du code ----------------------------------------------------------------------------------------+ |
*/ |
?> |