267 |
jpm |
1 |
<?php
|
|
|
2 |
/*vim: set expandtab tabstop=4 shiftwidth=4: */
|
|
|
3 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
4 |
// | PHP version 5.1 |
|
|
|
5 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
6 |
// | Copyright (C) 1999-2006 Tela Botanica (accueil@tela-botanica.org) |
|
|
|
7 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
8 |
// | This file is part of tela_botanica_v4. |
|
|
|
9 |
// | |
|
|
|
10 |
// | Foobar is free software; you can redistribute it and/or modify |
|
|
|
11 |
// | it under the terms of the GNU General Public License as published by |
|
|
|
12 |
// | the Free Software Foundation; either version 2 of the License, or |
|
|
|
13 |
// | (at your option) any later version. |
|
|
|
14 |
// | |
|
|
|
15 |
// | Foobar is distributed in the hope that it will be useful, |
|
|
|
16 |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
17 |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
18 |
// | GNU General Public License for more details. |
|
|
|
19 |
// | |
|
|
|
20 |
// | You should have received a copy of the GNU General Public License |
|
|
|
21 |
// | along with Foobar; if not, write to the Free Software |
|
|
|
22 |
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
|
|
23 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
24 |
// CVS : $Id$
|
|
|
25 |
/**
|
|
|
26 |
* tela_botanica_v4 - nettoyage_wikini.php
|
|
|
27 |
*
|
|
|
28 |
* Description :
|
|
|
29 |
*
|
|
|
30 |
*@package tela_botanica_v4
|
|
|
31 |
//Auteur original :
|
|
|
32 |
*@author Jean-Pascal MILCENT <jpm@tela-botanica.org>
|
|
|
33 |
//Autres auteurs :
|
|
|
34 |
*@author Aucun
|
|
|
35 |
*@copyright Tela-Botanica 1999-2007
|
|
|
36 |
*@version $Revision$ $Date$
|
|
|
37 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
38 |
*/
|
|
|
39 |
|
|
|
40 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
41 |
// | ENTÊTE du PROGRAMME |
|
|
|
42 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
43 |
define('CHEMIN_PEAR', '../api/pear/');
|
|
|
44 |
$GLOBALS['_NETTOYAGE_']['sites'] = array('http://www.tela-botanica.org', 'http://www.outils-reseaux.org');
|
|
|
45 |
|
|
|
46 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
47 |
// | CORPS du PROGRAMME |
|
|
|
48 |
// +------------------------------------------------------------------------------------------------------+
|
271 |
jpm |
49 |
echo '<h1>'.'Nettoyage des wikini de tela_prod_wikini'.'</h1>';
|
267 |
jpm |
50 |
$Nettoyage = new Nettoyage();
|
271 |
jpm |
51 |
echo '<pre>';
|
267 |
jpm |
52 |
$Nettoyage->nettoyageGlobal();
|
271 |
jpm |
53 |
echo '</pre>';
|
267 |
jpm |
54 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
55 |
// | CLASSES du PROGRAMME |
|
|
|
56 |
// +------------------------------------------------------------------------------------------------------+
|
|
|
57 |
class Nettoyage {
|
271 |
jpm |
58 |
private $bdd_principale = "tela_prod_wikini";
|
|
|
59 |
private $bdd_options = array('debug' => 3);
|
276 |
jpm |
60 |
private $bdd_dsn = "mysql://utilisateur:mdp@localhost/tela_prod_wikini";
|
267 |
jpm |
61 |
|
|
|
62 |
public function __construct()
|
|
|
63 |
{
|
271 |
jpm |
64 |
// $fichier_ini = 'bdd.ini';
|
|
|
65 |
// $ok = $this->parserFichierIni($fichier_ini);
|
|
|
66 |
// if (!$ok) {
|
|
|
67 |
// $e = 'Impossible de parser le fichier : '.$fichier_ini;
|
|
|
68 |
// trigger_error($e, E_USER_ERROR);
|
|
|
69 |
// } else {
|
267 |
jpm |
70 |
require_once CHEMIN_PEAR.'DB.php';
|
|
|
71 |
$this->connexion = DB::connect($this->bdd_dsn, $this->bdd_options);
|
|
|
72 |
if (PEAR::isError($this->connexion)) {
|
|
|
73 |
$e = $this->connexion->getMessage();
|
|
|
74 |
trigger_error($e, E_USER_ERROR);
|
|
|
75 |
}
|
271 |
jpm |
76 |
// }
|
267 |
jpm |
77 |
}
|
|
|
78 |
|
|
|
79 |
public function nettoyageGlobal()
|
|
|
80 |
{
|
|
|
81 |
$res = $this->connexion->query('SHOW TABLES');
|
|
|
82 |
if (PEAR::isError($res)) {
|
|
|
83 |
die($res->getMessage());
|
|
|
84 |
}
|
|
|
85 |
$tab_tables = array();
|
|
|
86 |
$ligne = '';
|
|
|
87 |
while ($res->fetchInto($ligne)) {
|
|
|
88 |
$tab_tables[] = $ligne[0];
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
foreach ($tab_tables as $table) {
|
|
|
92 |
echo "\n".$table."\n";
|
|
|
93 |
|
|
|
94 |
// Referrers
|
|
|
95 |
if (preg_match('/_referrers$/', $table)) {
|
|
|
96 |
$site_nbre = count($GLOBALS['_NETTOYAGE_']['sites']);
|
|
|
97 |
$site_0 = $GLOBALS['_NETTOYAGE_']['sites'][0];
|
|
|
98 |
$requete = 'DELETE FROM '.$table.' '.
|
|
|
99 |
'WHERE referrer NOT LIKE "'.$site_0.'%" ';
|
|
|
100 |
for ($i = 1; $i < $site_nbre; $i++) {
|
|
|
101 |
$requete .= 'AND referrer NOT LIKE "'.$GLOBALS['_NETTOYAGE_']['sites'][$i].'%" ';
|
|
|
102 |
}
|
|
|
103 |
echo $requete."\n";
|
|
|
104 |
$res = $this->connexion->query($requete);
|
|
|
105 |
if (PEAR::isError($res)) {
|
|
|
106 |
die($res->getMessage());
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
// Pages : commentaires
|
|
|
111 |
if (preg_match('/_pages$/', $table)) {
|
275 |
jpm |
112 |
$requete = 'SELECT tag FROM '.$table.' '.
|
267 |
jpm |
113 |
'WHERE tag LIKE "Comment%" ';
|
|
|
114 |
echo $requete."\n";
|
275 |
jpm |
115 |
$aso_pages = $this->connexion->getAll($requete, null, DB_FETCHMODE_ASSOC);
|
|
|
116 |
if (PEAR::isError($aso_pages)) {
|
|
|
117 |
die($aso_pages->getMessage());
|
267 |
jpm |
118 |
}
|
275 |
jpm |
119 |
if (count($aso_pages) > 0) {
|
|
|
120 |
$tab_pages = array();
|
|
|
121 |
foreach ($aso_pages as $page) {
|
|
|
122 |
if (preg_match('/^Comment\d+$/', $page['tag'])){
|
|
|
123 |
$tab_pages[] = $page['tag'];
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
if (count($tab_pages) > 0) {
|
|
|
127 |
$requete = 'DELETE FROM '.$table.' '.
|
|
|
128 |
'WHERE tag IN ("'.implode('","', $tab_pages).'") ';
|
|
|
129 |
echo $requete."\n";
|
|
|
130 |
$res = $this->connexion->query($requete);
|
|
|
131 |
if (PEAR::isError($res)) {
|
|
|
132 |
die($res->getMessage());
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
}
|
267 |
jpm |
136 |
}
|
|
|
137 |
|
|
|
138 |
// ACLs : commentaires
|
|
|
139 |
if (preg_match('/_acls$/', $table)) {
|
|
|
140 |
$requete = 'DELETE FROM '.$table.' '.
|
|
|
141 |
'WHERE page_tag LIKE "Comment%" ';
|
|
|
142 |
echo $requete."\n";
|
|
|
143 |
$res = $this->connexion->query($requete);
|
|
|
144 |
if (PEAR::isError($res)) {
|
|
|
145 |
die($res->getMessage());
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
$requete = 'UPDATE '.$table.' '.
|
|
|
149 |
'SET list = "+" '.
|
|
|
150 |
'WHERE privilege = "comment" ';
|
|
|
151 |
echo $requete."\n";
|
|
|
152 |
$res = $this->connexion->query($requete);
|
|
|
153 |
if (PEAR::isError($res)) {
|
|
|
154 |
die($res->getMessage());
|
|
|
155 |
}
|
|
|
156 |
}
|
|
|
157 |
}
|
|
|
158 |
}
|
|
|
159 |
|
271 |
jpm |
160 |
function parserFichierIni($fichier_ini)
|
267 |
jpm |
161 |
{
|
|
|
162 |
if (file_exists($fichier_ini)) {
|
|
|
163 |
$aso_ini = parse_ini_file($fichier_ini);
|
|
|
164 |
foreach ($aso_ini as $cle => $val) {
|
|
|
165 |
if (preg_match('/^php:(.+)$/', $val, $correspondances)) {
|
|
|
166 |
eval('$this->$cle = '.$correspondances[1].';');
|
|
|
167 |
} else if (preg_match('/^php-static:(.+)$/', $val, $correspondances)) {
|
|
|
168 |
eval('self::$'.$cle.' = '.$correspondances[1].';');
|
|
|
169 |
} else {
|
|
|
170 |
$this->$cle = $val;
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
} else {
|
|
|
174 |
return false;
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
/* +--Fin du code ----------------------------------------------------------------------------------------+
|
|
|
179 |
*
|
|
|
180 |
* $Log$
|
|
|
181 |
*
|
|
|
182 |
* +-- Fin du code ----------------------------------------------------------------------------------------+
|
|
|
183 |
*/
|
|
|
184 |
?>
|