Subversion Repositories Applications.papyrus

Rev

Rev 6 | Rev 78 | Go to most recent revision | 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
// +------------------------------------------------------------------------------------------------------+
65 jpm 22
// CVS : $Id: instal_installation.fonct.php,v 1.2 2004-10-15 18:28:44 jpm 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
65 jpm 36
*@version       $Revision: 1.2 $ $Date: 2004-10-15 18:28:44 $
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
*
65 jpm 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
*/
65 jpm 54
function donnerUrlCourante()
55
{
56
    list($url, ) = explode('?', $_SERVER['REQUEST_URI']);
57
    return $url;
58
}
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($texte, $test, $texte_erreur = '', $stop_erreur = 1, $erreur) {
71
    if ($erreur == 2) {
72
        return 2;
73
    }
74
    global $sortie;
75
    $sortie .= $texte.' ';
76
    if ($test) {
77
        $sortie .= '<span class="ok">OK</span><br />'."\n";
78
        return 0;
79
    } else {
80
        $sortie .= '<span class="failed">ECHEC</span>';
81
        if ($texte_erreur) {
82
            $sortie .= ': '.$texte_erreur;
83
        }
84
        $sortie .= '<br />'."\n" ;
85
        if ($stop_erreur == 1) {
86
            return 2;
87
        } else {
88
            return 1;
89
        }
90
    }
91
}
92
/**
93
 * Removes comment lines and splits up large sql files into individual queries
94
 *
95
 * Last revision: September 23, 2001 - gandon
96
 * Origine : fonction provenant de PhpMyAdmin version 2.6.0-pl1
97
 * Licence : GNU
98
 * Auteurs : voir le fichier Documentation.txt ou Documentation.html de PhpMyAdmin.
99
 *
100
 * @param   array    the splitted sql commands
101
 * @param   string   the sql commands
102
 * @param   integer  the MySQL release number (because certains php3 versions
103
 *                   can't get the value of a constant from within a function)
104
 *
105
 * @return  boolean  always true
106
 *
107
 * @access  public
108
 */
109
function PMA_splitSqlFile(&$ret, $sql, $release)
110
{
111
    // do not trim, see bug #1030644
112
    //$sql          = trim($sql);
113
    $sql          = rtrim($sql, "\n\r");
114
    $sql_len      = strlen($sql);
115
    $char         = '';
116
    $string_start = '';
117
    $in_string    = FALSE;
118
    $nothing      = TRUE;
119
    $time0        = time();
120
 
121
    for ($i = 0; $i < $sql_len; ++$i) {
122
        $char = $sql[$i];
123
 
124
        // We are in a string, check for not escaped end of strings except for
125
        // backquotes that can't be escaped
126
        if ($in_string) {
127
            for (;;) {
128
                $i         = strpos($sql, $string_start, $i);
129
                // No end of string found -> add the current substring to the
130
                // returned array
131
                if (!$i) {
132
                    $tab_info = retournerInfoRequete($sql);
133
                    $ret[] = array('query' => $sql, 'table_nom' => $tab_info['table_nom'], 'type' => $tab_info['type']);
134
                    return TRUE;
135
                }
136
                // Backquotes or no backslashes before quotes: it's indeed the
137
                // end of the string -> exit the loop
138
                else if ($string_start == '`' || $sql[$i-1] != '\\') {
139
                    $string_start      = '';
140
                    $in_string         = FALSE;
141
                    break;
142
                }
143
                // one or more Backslashes before the presumed end of string...
144
                else {
145
                    // ... first checks for escaped backslashes
146
                    $j                     = 2;
147
                    $escaped_backslash     = FALSE;
148
                    while ($i-$j > 0 && $sql[$i-$j] == '\\') {
149
                        $escaped_backslash = !$escaped_backslash;
150
                        $j++;
151
                    }
152
                    // ... if escaped backslashes: it's really the end of the
153
                    // string -> exit the loop
154
                    if ($escaped_backslash) {
155
                        $string_start  = '';
156
                        $in_string     = FALSE;
157
                        break;
158
                    }
159
                    // ... else loop
160
                    else {
161
                        $i++;
162
                    }
163
                } // end if...elseif...else
164
            } // end for
165
        } // end if (in string)
166
 
167
        // lets skip comments (/*, -- and #)
168
        else if (($char == '-' && $sql_len > $i + 2 && $sql[$i + 1] == '-' && $sql[$i + 2] <= ' ') || $char == '#' || ($char == '/' && $sql_len > $i + 1 && $sql[$i + 1] == '*')) {
169
            $i = strpos($sql, $char == '/' ? '*/' : "\n", $i);
170
            // didn't we hit end of string?
171
            if ($i === FALSE) {
172
                break;
173
            }
174
            if ($char == '/') $i++;
175
        }
176
 
177
        // We are not in a string, first check for delimiter...
178
        else if ($char == ';') {
179
            // if delimiter found, add the parsed part to the returned array
180
            $retour_sql = substr($sql, 0, $i);
181
            $tab_info = retournerInfoRequete($retour_sql);
182
            $ret[]      = array('query' => $retour_sql, 'empty' => $nothing, 'table_nom' => $tab_info['table_nom'], 'type' => $tab_info['type']);
183
            $nothing    = TRUE;
184
            $sql        = ltrim(substr($sql, min($i + 1, $sql_len)));
185
            $sql_len    = strlen($sql);
186
            if ($sql_len) {
187
                $i      = -1;
188
            } else {
189
                // The submited statement(s) end(s) here
190
                return TRUE;
191
            }
192
        } // end else if (is delimiter)
193
 
194
        // ... then check for start of a string,...
195
        else if (($char == '"') || ($char == '\'') || ($char == '`')) {
196
            $in_string    = TRUE;
197
            $nothing      = FALSE;
198
            $string_start = $char;
199
        } // end else if (is start of string)
200
 
201
        elseif ($nothing) {
202
            $nothing = FALSE;
203
        }
204
 
205
        // loic1: send a fake header each 30 sec. to bypass browser timeout
206
        $time1     = time();
207
        if ($time1 >= $time0 + 30) {
208
            $time0 = $time1;
209
            header('X-pmaPing: Pong');
210
        } // end if
211
    } // end for
212
 
213
    // add any rest to the returned array
214
    if (!empty($sql) && preg_match('@[^[:space:]]+@', $sql)) {
215
        $tab_info = retournerInfoRequete($sql);
216
        $ret[] = array('query' => $sql, 'empty' => $nothing, 'table_nom' => $tab_info['table_nom'], 'type' => $tab_info['type']);
217
    }
218
 
219
    return TRUE;
220
}
221
 
222
/**Fonction retournerInfoRequete() - Retourne le type de requête sql et le nom de la table touchée.
223
*
224
* Cette fonction retourne un tableau associatif contenant en clé 'table_nom' le nom de la table touchée
225
* et en clé 'type' le type de requête (create, insert, update...).
226
* Licence : la même que celle figurant dans l'entête de ce fichier
227
* Auteurs : Jean-Pascal MILCENT
228
*
229
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
230
* @return string l'url courante.
231
*/
232
function retournerInfoRequete($sql)
233
{
234
    $requete = array();
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:INSERT INTO) +(.+) +(?i:VALUES)/', $sql, $resultat)) {
241
        if (isset($resultat[1])) {
242
            $requete['table_nom'] = $resultat[1];
243
        }
244
        $requete['type'] = 'insert';
245
    }
246
    return $requete;
247
}
248
/**
249
 * Reads (and decompresses) a (compressed) file into a string
250
 *
251
 * Origine : fonction provenant de PhpMyAdmin version 2.6.0-pl1
252
 * Licence : GNU
253
 * Auteurs : voir le fichier Documentation.txt ou Documentation.html de PhpMyAdmin.
254
 *
255
 * @param   string   the path to the file
256
 * @param   string   the MIME type of the file, if empty MIME type is autodetected
257
 *
258
 * @global  array    the phpMyAdmin configuration
259
 *
260
 * @return  string   the content of the file or
261
 *          boolean  FALSE in case of an error.
262
 */
263
function PMA_readFile($path, $mime = '')
264
{
265
    global $cfg;
266
 
267
    if (!file_exists($path)) {
268
        return FALSE;
269
    }
270
    switch ($mime) {
271
        case '':
272
            $file = @fopen($path, 'rb');
273
            if (!$file) {
274
                return FALSE;
275
            }
276
            $test = fread($file, 3);
277
            fclose($file);
278
            if ($test[0] == chr(31) && $test[1] == chr(139)) return PMA_readFile($path, 'application/x-gzip');
279
            if ($test == 'BZh') return PMA_readFile($path, 'application/x-bzip');
280
            return PMA_readFile($path, 'text/plain');
281
        case 'text/plain':
282
            $file = @fopen($path, 'rb');
283
            if (!$file) {
284
                return FALSE;
285
            }
286
            $content = fread($file, filesize($path));
287
            fclose($file);
288
            break;
289
        case 'application/x-gzip':
290
            if ($cfg['GZipDump'] && @function_exists('gzopen')) {
291
                $file = @gzopen($path, 'rb');
292
                if (!$file) {
293
                    return FALSE;
294
                }
295
                $content = '';
296
                while (!gzeof($file)) {
297
                    $content .= gzgetc($file);
298
                }
299
                gzclose($file);
300
            } else {
301
                return FALSE;
302
            }
303
           break;
304
        case 'application/x-bzip':
305
            if ($cfg['BZipDump'] && @function_exists('bzdecompress')) {
306
                $file = @fopen($path, 'rb');
307
                if (!$file) {
308
                    return FALSE;
309
                }
310
                $content = fread($file, filesize($path));
311
                fclose($file);
312
                $content = bzdecompress($content);
313
            } else {
314
                return FALSE;
315
            }
316
           break;
317
        default:
318
           return FALSE;
319
    }
320
    return $content;
6 jpm 321
}
322
/* +--Fin du code ---------------------------------------------------------------------------------------+
65 jpm 323
*
6 jpm 324
* $Log: not supported by cvs2svn $
65 jpm 325
* Revision 1.1  2004/06/16 14:34:12  jpm
326
* Changement de nom de Génésia en Papyrus.
327
* Changement de l'arborescence.
328
*
6 jpm 329
* +--Fin du code ----------------------------------------------------------------------------------------+
330
*/
331
?>