Subversion Repositories Sites.tela-botanica.org

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
// +------------------------------------------------------------------------------------------------------+
49
$Nettoyage = new Nettoyage();
50
$Nettoyage->nettoyageGlobal();
51
 
52
// +------------------------------------------------------------------------------------------------------+
53
// |                                           CLASSES du PROGRAMME                                       |
54
// +------------------------------------------------------------------------------------------------------+
55
class Nettoyage {
56
 
57
	public function __construct()
58
	{
59
		$fichier_ini = 'bdd.ini';
60
		if (file_exists($fichier_ini)) {
61
			$this->parserFichierIni($fichier_ini);
62
			require_once CHEMIN_PEAR.'DB.php';
63
			$this->connexion = DB::connect($this->bdd_dsn, $this->bdd_options);
64
			if (PEAR::isError($this->connexion)) {
65
				$e = $this->connexion->getMessage();
66
				trigger_error($e, E_USER_ERROR);
67
			}
68
		}
69
	}
70
 
71
	public function nettoyageGlobal()
72
	{
73
		$res = $this->connexion->query('SHOW TABLES');
74
		if (PEAR::isError($res)) {
75
			die($res->getMessage());
76
		}
77
		$tab_tables = array();
78
		$ligne = '';
79
		while ($res->fetchInto($ligne)) {
80
			$tab_tables[] = $ligne[0];
81
		}
82
 
83
		echo '<pre>';
84
		foreach ($tab_tables as $table) {
85
			echo "\n".$table."\n";
86
 
87
			// Referrers
88
			if (preg_match('/_referrers$/', $table)) {
89
				$site_nbre = count($GLOBALS['_NETTOYAGE_']['sites']);
90
				$site_0 = $GLOBALS['_NETTOYAGE_']['sites'][0];
91
				$requete = 	'DELETE FROM '.$table.' '.
92
							'WHERE referrer NOT LIKE "'.$site_0.'%" ';
93
				for ($i = 1; $i < $site_nbre; $i++) {
94
					$requete .= 'AND referrer NOT LIKE "'.$GLOBALS['_NETTOYAGE_']['sites'][$i].'%" ';
95
				}
96
				echo $requete."\n";
97
				$res = $this->connexion->query($requete);
98
				if (PEAR::isError($res)) {
99
					die($res->getMessage());
100
				}
101
			}
102
 
103
			// Pages : commentaires
104
			if (preg_match('/_pages$/', $table)) {
105
				$requete = 	'DELETE FROM '.$table.' '.
106
							'WHERE tag LIKE "Comment%" ';
107
				echo $requete."\n";
108
				$res = $this->connexion->query($requete);
109
				if (PEAR::isError($res)) {
110
					die($res->getMessage());
111
				}
112
			}
113
 
114
			// ACLs : commentaires
115
			if (preg_match('/_acls$/', $table)) {
116
				$requete = 	'DELETE FROM '.$table.' '.
117
							'WHERE page_tag LIKE "Comment%" ';
118
				echo $requete."\n";
119
				$res = $this->connexion->query($requete);
120
				if (PEAR::isError($res)) {
121
					die($res->getMessage());
122
				}
123
 
124
				$requete = 	'UPDATE '.$table.' '.
125
							'SET list = "+" '.
126
							'WHERE privilege = "comment" ';
127
				echo $requete."\n";
128
				$res = $this->connexion->query($requete);
129
				if (PEAR::isError($res)) {
130
					die($res->getMessage());
131
				}
132
			}
133
		}
134
		echo '</pre>';
135
	}
136
 
137
	private function parserFichierIni($fichier_ini)
138
	{
139
		if (file_exists($fichier_ini)) {
140
			$aso_ini = parse_ini_file($fichier_ini);
141
	    	foreach ($aso_ini as $cle => $val) {
142
	    		if (preg_match('/^php:(.+)$/', $val, $correspondances)) {
143
					eval('$this->$cle = '.$correspondances[1].';');
144
				} else if (preg_match('/^php-static:(.+)$/', $val, $correspondances)) {
145
					eval('self::$'.$cle.' = '.$correspondances[1].';');
146
				} else {
147
					$this->$cle = $val;
148
				}
149
		   	}
150
		} else {
151
			return false;
152
		}
153
	}
154
}
155
/* +--Fin du code ----------------------------------------------------------------------------------------+
156
*
157
* $Log$
158
*
159
* +-- Fin du code ----------------------------------------------------------------------------------------+
160
*/
161
?>