Subversion Repositories Sites.tela-botanica.org

Rev

Rev 267 | Go to most recent revision | Details | Compare with Previous | 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
// +------------------------------------------------------------------------------------------------------+
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);
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)) {
112
				$requete = 	'DELETE FROM '.$table.' '.
113
							'WHERE tag LIKE "Comment%" ';
114
				echo $requete."\n";
115
				$res = $this->connexion->query($requete);
116
				if (PEAR::isError($res)) {
117
					die($res->getMessage());
118
				}
119
			}
120
 
121
			// ACLs : commentaires
122
			if (preg_match('/_acls$/', $table)) {
123
				$requete = 	'DELETE FROM '.$table.' '.
124
							'WHERE page_tag LIKE "Comment%" ';
125
				echo $requete."\n";
126
				$res = $this->connexion->query($requete);
127
				if (PEAR::isError($res)) {
128
					die($res->getMessage());
129
				}
130
 
131
				$requete = 	'UPDATE '.$table.' '.
132
							'SET list = "+" '.
133
							'WHERE privilege = "comment" ';
134
				echo $requete."\n";
135
				$res = $this->connexion->query($requete);
136
				if (PEAR::isError($res)) {
137
					die($res->getMessage());
138
				}
139
			}
140
		}
141
	}
142
 
271 jpm 143
	function parserFichierIni($fichier_ini)
267 jpm 144
	{
145
		if (file_exists($fichier_ini)) {
146
			$aso_ini = parse_ini_file($fichier_ini);
147
	    	foreach ($aso_ini as $cle => $val) {
148
	    		if (preg_match('/^php:(.+)$/', $val, $correspondances)) {
149
					eval('$this->$cle = '.$correspondances[1].';');
150
				} else if (preg_match('/^php-static:(.+)$/', $val, $correspondances)) {
151
					eval('self::$'.$cle.' = '.$correspondances[1].';');
152
				} else {
153
					$this->$cle = $val;
154
				}
155
		   	}
156
		} else {
157
			return false;
158
		}
159
	}
160
}
161
/* +--Fin du code ----------------------------------------------------------------------------------------+
162
*
163
* $Log$
164
*
165
* +-- Fin du code ----------------------------------------------------------------------------------------+
166
*/
167
?>