Subversion Repositories Applications.papyrus

Rev

Rev 1192 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 jpm 1
<?php
2
/*vim: set expandtab tabstop=4 shiftwidth=4: */
3
// +------------------------------------------------------------------------------------------------------+
4
// | PHP version 4.1                                                                                      |
5
// +------------------------------------------------------------------------------------------------------+
6
// | Copyright (C) 2004 Tela Botanica (accueil@tela-botanica.org)                                         |
7
// +------------------------------------------------------------------------------------------------------+
8
// | This library is free software; you can redistribute it and/or                                        |
9
// | modify it under the terms of the GNU Lesser General Public                                           |
10
// | License as published by the Free Software Foundation; either                                         |
11
// | version 2.1 of the License, or (at your option) any later version.                                   |
12
// |                                                                                                      |
13
// | This library is distributed in the hope that it will be useful,                                      |
14
// | but WITHOUT ANY WARRANTY; without even the implied warranty of                                       |
15
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                                    |
16
// | Lesser General Public License for more details.                                                      |
17
// |                                                                                                      |
18
// | You should have received a copy of the GNU Lesser General Public                                     |
19
// | License along with this library; if not, write to the Free Software                                  |
20
// | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                            |
21
// +------------------------------------------------------------------------------------------------------+
1192 alexandre_ 22
// CVS : $Id: instal_installation.fonct.php,v 1.7 2007-01-04 17:06:03 alexandre_tb Exp $
6 jpm 23
/**
65 jpm 24
* Bibliothèque des fonctions de l'application Installateur de Papyrus.
6 jpm 25
*
65 jpm 26
* Ce sous-paquetage contient les fonctions de l'application Installateur de Papyrus. Cette application gère
27
* l'installation de Papyrus (base de données).
6 jpm 28
*
29
*@package Installateur
30
*@subpackage Fonctions
31
//Auteur original :
65 jpm 32
*@author        Jean-Pascal MILCENT <jpm@tela-botanica.org>
6 jpm 33
//Autres auteurs :
65 jpm 34
*@author        aucun
6 jpm 35
*@copyright     Tela-Botanica 2000-2004
1192 alexandre_ 36
*@version       $Revision: 1.7 $ $Date: 2007-01-04 17:06:03 $
6 jpm 37
*/
38
 
39
// +------------------------------------------------------------------------------------------------------+
40
// |                                           LISTE de FONCTIONS                                         |
41
// +------------------------------------------------------------------------------------------------------+
42
 
43
 
65 jpm 44
/**Fonction donnerUrlCourante() - Retourne la base de l'url courante.
6 jpm 45
*
458 florian 46
* Cette fonction renvoie la base de l'url courante.
47
* Origine : fonction provenant du fichier header.php de Wikini version 0.4.1
48
* Licence : la même que celle figurant dans l'entête du fichier header.php de Wikini version 0.4.1
49
* ou le fichier install_defaut.inc.php de cette application.
50
* Auteurs : Hendrik MANS, David DELON, Patrick PAUL, Jean-Pascal MILCENT
6 jpm 51
*
65 jpm 52
* @return string l'url courante.
6 jpm 53
*/
458 florian 54
function donnerUrlCourante()
55
{
56
    list($url, ) = explode('?', $_SERVER['REQUEST_URI']);
57
    return $url;
6 jpm 58
}
458 florian 59
 
60
/**Fonction testerConfig() - Retourne un message en fonction du résultat du test.
61
*
62
* Cette fonction retourne un message en fonction du résultat du test.
63
* Origine : fonction provenant du fichier header.php de Wikini version 0.4.1
64
* Licence : la même que celle figurant dans l'entête du fichier header.php de Wikini version 0.4.1
65
* ou le fichier install_defaut.inc.php de cette application.
66
* Auteurs : Hendrik MANS, David DELON, Patrick PAUL, Jean-Pascal MILCENT
67
*
68
* @return string l'url courante.
69
*/
70
function testerConfig(&$sortie, $texte, $test, $texte_erreur = '', $stop_erreur = 1, $erreur) {
71
    if ($erreur == 2) {
72
        return 2;
73
    }
74
    $sortie .= $texte.' ';
75
    if ($test) {
76
        $sortie .= '<span class="ok">&nbsp;OK&nbsp;</span><br />'."\n";
77
        return 0;
78
    } else {
79
        $sortie .= '<span class="failed">&nbsp;ECHEC&nbsp;</span>';
80
        if ($texte_erreur) {
1192 alexandre_ 81
            $sortie .= '<p class="erreur">'.$texte_erreur.'</p>';
458 florian 82
        }
83
        $sortie .= '<br />'."\n" ;
84
        if ($stop_erreur == 1) {
85
            return 2;
86
        } else {
87
            return 1;
88
        }
89
    }
90
}
91
/**
92
 * Removes comment lines and splits up large sql files into individual queries
93
 *
94
 * Last revision: September 23, 2001 - gandon
95
 * Origine : fonction provenant de PhpMyAdmin version 2.6.0-pl1
96
 * Licence : GNU
97
 * Auteurs : voir le fichier Documentation.txt ou Documentation.html de PhpMyAdmin.
98
 *
99
 * @param   array    the splitted sql commands
100
 * @param   string   the sql commands
101
 * @param   integer  the MySQL release number (because certains php3 versions
102
 *                   can't get the value of a constant from within a function)
103
 *
104
 * @return  boolean  always true
105
 *
106
 * @access  public
107
 */
108
function PMA_splitSqlFile(&$ret, $sql, $release)
109
{
110
    // do not trim, see bug #1030644
111
    //$sql          = trim($sql);
112
    $sql          = rtrim($sql, "\n\r");
113
    $sql_len      = strlen($sql);
114
    $char         = '';
115
    $string_start = '';
116
    $in_string    = FALSE;
117
    $nothing      = TRUE;
118
    $time0        = time();
119
 
120
    for ($i = 0; $i < $sql_len; ++$i) {
121
        $char = $sql[$i];
122
 
123
        // We are in a string, check for not escaped end of strings except for
124
        // backquotes that can't be escaped
125
        if ($in_string) {
126
            for (;;) {
127
                $i         = strpos($sql, $string_start, $i);
128
                // No end of string found -> add the current substring to the
129
                // returned array
130
                if (!$i) {
131
                    $tab_info = retournerInfoRequete($sql);
132
                    $ret[] = array('query' => $sql, 'table_nom' => $tab_info['table_nom'], 'type' => $tab_info['type']);
133
                    return TRUE;
134
                }
135
                // Backquotes or no backslashes before quotes: it's indeed the
136
                // end of the string -> exit the loop
137
                else if ($string_start == '`' || $sql[$i-1] != '\\') {
138
                    $string_start      = '';
139
                    $in_string         = FALSE;
140
                    break;
141
                }
142
                // one or more Backslashes before the presumed end of string...
143
                else {
144
                    // ... first checks for escaped backslashes
145
                    $j                     = 2;
146
                    $escaped_backslash     = FALSE;
147
                    while ($i-$j > 0 && $sql[$i-$j] == '\\') {
148
                        $escaped_backslash = !$escaped_backslash;
149
                        $j++;
150
                    }
151
                    // ... if escaped backslashes: it's really the end of the
152
                    // string -> exit the loop
153
                    if ($escaped_backslash) {
154
                        $string_start  = '';
155
                        $in_string     = FALSE;
156
                        break;
157
                    }
158
                    // ... else loop
159
                    else {
160
                        $i++;
161
                    }
162
                } // end if...elseif...else
163
            } // end for
164
        } // end if (in string)
165
 
166
        // lets skip comments (/*, -- and #)
167
        else if (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) {
168
            $i = strpos($sql, $char == '/' ? '*/' : "\n", $i);
169
            // didn't we hit end of string?
170
            if ($i === FALSE) {
171
                break;
172
            }
173
            if ($char == '/') $i++;
174
        }
175
 
176
        // We are not in a string, first check for delimiter...
177
        else if ($char == ';') {
178
            // if delimiter found, add the parsed part to the returned array
179
            $retour_sql = substr($sql, 0, $i);
180
            $tab_info = retournerInfoRequete($retour_sql);
181
            $ret[]      = array('query' => $retour_sql, 'empty' => $nothing, 'table_nom' => $tab_info['table_nom'], 'type' => $tab_info['type']);
182
            $nothing    = TRUE;
183
            $sql        = ltrim(substr($sql, min($i + 1, $sql_len)));
184
            $sql_len    = strlen($sql);
185
            if ($sql_len) {
186
                $i      = -1;
187
            } else {
188
                // The submited statement(s) end(s) here
189
                return TRUE;
190
            }
191
        } // end else if (is delimiter)
192
 
193
        // ... then check for start of a string,...
194
        else if (($char == '"') || ($char == '\'') || ($char == '`')) {
195
            $in_string    = TRUE;
196
            $nothing      = FALSE;
197
            $string_start = $char;
198
        } // end else if (is start of string)
199
 
200
        elseif ($nothing) {
201
            $nothing = FALSE;
202
        }
203
 
204
        // loic1: send a fake header each 30 sec. to bypass browser timeout
205
        $time1     = time();
206
        if ($time1 >= $time0 + 30) {
207
            $time0 = $time1;
208
            header('X-pmaPing: Pong');
209
        } // end if
210
    } // end for
211
 
212
    // add any rest to the returned array
213
    if (!empty($sql) && preg_match('@[^[:space:]]+@', $sql)) {
214
        $tab_info = retournerInfoRequete($sql);
215
        $ret[] = array('query' => $sql, 'empty' => $nothing, 'table_nom' => $tab_info['table_nom'], 'type' => $tab_info['type']);
216
    }
217
 
218
    return TRUE;
219
}
220
 
221
/**Fonction retournerInfoRequete() - Retourne le type de requête sql et le nom de la table touchée.
222
*
223
* Cette fonction retourne un tableau associatif contenant en clé 'table_nom' le nom de la table touchée
224
* et en clé 'type' le type de requête (create, alter, insert, update...).
225
* Licence : la même que celle figurant dans l'entête de ce fichier
226
* Auteurs : Jean-Pascal MILCENT
227
*
228
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
229
* @return string l'url courante.
230
*/
231
function retournerInfoRequete($sql)
232
{
233
    $requete = array();
832 florian 234
    $resultat='';
458 florian 235
    if (preg_match('/(?i:CREATE TABLE) +(.+) +\(/', $sql, $resultat)) {
236
        if (isset($resultat[1])) {
237
            $requete['table_nom'] = $resultat[1];
238
        }
239
        $requete['type'] = 'create';
240
    } else if (preg_match('/(?i:ALTER TABLE) +(.+) +/', $sql, $resultat)) {
241
        if (isset($resultat[1])) {
242
            $requete['table_nom'] = $resultat[1];
243
        }
244
        $requete['type'] = 'alter';
245
    } else if (preg_match('/(?i:INSERT INTO) +(.+) +(?i:\(|VALUES +\()/', $sql, $resultat)) {
246
        if (isset($resultat[1])) {
247
            $requete['table_nom'] = $resultat[1];
248
        }
249
        $requete['type'] = 'insert';
250
    } else if (preg_match('/(?i:UPDATE) +(.+) +(?i:SET)/', $sql, $resultat)) {
251
        if (isset($resultat[1])) {
252
            $requete['table_nom'] = $resultat[1];
253
        }
254
        $requete['type'] = 'update';
255
    }
256
    return $requete;
257
}
258
/**
259
 * Reads (and decompresses) a (compressed) file into a string
260
 *
261
 * Origine : fonction provenant de PhpMyAdmin version 2.6.0-pl1
262
 * Licence : GNU
263
 * Auteurs : voir le fichier Documentation.txt ou Documentation.html de PhpMyAdmin.
264
 *
265
 * @param   string   the path to the file
266
 * @param   string   the MIME type of the file, if empty MIME type is autodetected
267
 *
268
 * @global  array    the phpMyAdmin configuration
269
 *
270
 * @return  string   the content of the file or
271
 *          boolean  FALSE in case of an error.
272
 */
273
function PMA_readFile($path, $mime = '')
274
{
275
    global $cfg;
276
 
277
    if (!file_exists($path)) {
278
        return FALSE;
279
    }
280
    switch ($mime) {
281
        case '':
282
            $file = @fopen($path, 'rb');
283
            if (!$file) {
284
                return FALSE;
285
            }
286
            $test = fread($file, 3);
287
            fclose($file);
288
            if ($test[0] == chr(31) && $test[1] == chr(139)) return PMA_readFile($path, 'application/x-gzip');
289
            if ($test == 'BZh') return PMA_readFile($path, 'application/x-bzip');
290
            return PMA_readFile($path, 'text/plain');
291
        case 'text/plain':
292
            $file = @fopen($path, 'rb');
293
            if (!$file) {
294
                return FALSE;
295
            }
296
            $content = fread($file, filesize($path));
297
            fclose($file);
298
            break;
299
        case 'application/x-gzip':
300
            if ($cfg['GZipDump'] && @function_exists('gzopen')) {
301
                $file = @gzopen($path, 'rb');
302
                if (!$file) {
303
                    return FALSE;
304
                }
305
                $content = '';
306
                while (!gzeof($file)) {
307
                    $content .= gzgetc($file);
308
                }
309
                gzclose($file);
310
            } else {
311
                return FALSE;
312
            }
313
           break;
314
        case 'application/x-bzip':
315
            if ($cfg['BZipDump'] && @function_exists('bzdecompress')) {
316
                $file = @fopen($path, 'rb');
317
                if (!$file) {
318
                    return FALSE;
319
                }
320
                $content = fread($file, filesize($path));
321
                fclose($file);
322
                $content = bzdecompress($content);
323
            } else {
324
                return FALSE;
325
            }
326
           break;
327
        default:
328
           return FALSE;
329
    }
330
    return $content;
331
}
6 jpm 332
/* +--Fin du code ---------------------------------------------------------------------------------------+
458 florian 333
*
2150 mathias 334
* $Log: instal_installation.fonct.php,v $
335
* Revision 1.7  2007-01-04 17:06:03  alexandre_tb
336
* modif mineure
337
*
1192 alexandre_ 338
* Revision 1.6  2006/04/28 12:41:49  florian
339
* corrections erreurs chemin
340
*
832 florian 341
* Revision 1.5  2005/09/23 14:20:23  florian
342
* nouvel habillage installateur, plus correction de quelques bugs
343
*
458 florian 344
* Revision 1.4  2004/10/25 16:26:56  jpm
345
* Ajout de la gestion des requêtes de type alter et update.
346
*
347
* Revision 1.3  2004/10/19 16:47:06  jpm
348
* Modification de la gestion du texte de sortie dans la fonction testerConfig().
349
*
350
* Revision 1.2  2004/10/15 18:28:44  jpm
351
* Ajout de fonction utilisée pour l'installation de Papyrus.
352
*
353
* Revision 1.1  2004/06/16 14:34:12  jpm
354
* Changement de nom de Génésia en Papyrus.
355
* Changement de l'arborescence.
356
*
6 jpm 357
* +--Fin du code ----------------------------------------------------------------------------------------+
358
*/
359
?>