5 |
david |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/***************************************************************************\
|
|
|
4 |
* SPIP, Systeme de publication pour l'internet *
|
|
|
5 |
* *
|
|
|
6 |
* Copyright (c) 2001-2005 *
|
|
|
7 |
* Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
|
|
|
8 |
* *
|
|
|
9 |
* Ce programme est un logiciel libre distribue sous licence GNU/GPL. *
|
|
|
10 |
* Pour plus de details voir le fichier COPYING.txt ou l'aide en ligne. *
|
|
|
11 |
\***************************************************************************/
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
//
|
|
|
15 |
// Ce fichier ne sera execute qu'une fois
|
|
|
16 |
if (defined("_ECRIRE_INC_BASE")) return;
|
|
|
17 |
define("_ECRIRE_INC_BASE", "1");
|
|
|
18 |
|
|
|
19 |
include_ecrire("inc_acces.php3");
|
|
|
20 |
include_ecrire("inc_serialbase.php3");
|
|
|
21 |
include_ecrire("inc_auxbase.php3");
|
|
|
22 |
include_ecrire("inc_typebase.php3");
|
|
|
23 |
include_ecrire("inc_majbase.php3");
|
|
|
24 |
|
|
|
25 |
// Fonction de creation d'une table SQL nommee $nom
|
|
|
26 |
// a partir de 2 tableaux PHP :
|
|
|
27 |
// champs: champ => type
|
|
|
28 |
// cles: type-de-cle => champ(s)
|
|
|
29 |
// si $autoinc, c'est une auto-increment (i.e. serial) sur la Primary Key
|
|
|
30 |
// Le nom des caches doit etre inferieur a 64 caracteres
|
|
|
31 |
|
|
|
32 |
function spip_create_table($nom, $champs, $cles, $autoinc=false) {
|
|
|
33 |
$query = ''; $keys = ''; $s = '';
|
|
|
34 |
|
|
|
35 |
foreach($cles as $k => $v) {
|
|
|
36 |
$keys .= "$s\n\t\t$k ($v)";
|
|
|
37 |
if ($k == "PRIMARY KEY")
|
|
|
38 |
$p = $v;
|
|
|
39 |
$s = ",";
|
|
|
40 |
}
|
|
|
41 |
$s = '';
|
|
|
42 |
|
|
|
43 |
foreach($champs as $k => $v) {
|
|
|
44 |
$query .= "$s\n\t\t$k $v" .
|
|
|
45 |
(($autoinc && ($p == $k)) ? " auto_increment" : '');
|
|
|
46 |
$s = ",";
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
$query = "CREATE TABLE IF NOT EXISTS $nom ($query" .
|
|
|
50 |
($keys ? ",$keys" : '') .
|
|
|
51 |
")\n";
|
|
|
52 |
spip_query_db($query);
|
|
|
53 |
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
|
|
|
57 |
function creer_base() {
|
|
|
58 |
global $tables_principales, $tables_auxiliaires, $tables_images, $tables_sequences, $tables_documents, $tables_mime;
|
|
|
59 |
|
|
|
60 |
// ne pas revenir plusieurs fois (si, au contraire, il faut pouvoir
|
|
|
61 |
// le faire car certaines mises a jour le demandent explicitement)
|
|
|
62 |
# static $vu = false;
|
|
|
63 |
# if ($vu) return; else $vu = true;
|
|
|
64 |
|
|
|
65 |
foreach($tables_principales as $k => $v)
|
|
|
66 |
spip_create_table($k, $v['field'], $v['key'], true);
|
|
|
67 |
|
|
|
68 |
foreach($tables_auxiliaires as $k => $v)
|
|
|
69 |
spip_create_table($k, $v['field'], $v['key'], false);
|
|
|
70 |
|
|
|
71 |
foreach($tables_images as $k => $v)
|
|
|
72 |
spip_query_db("INSERT IGNORE spip_types_documents (extension, inclus, titre, id_type) VALUES ('$k', 'image', '" .
|
|
|
73 |
(is_numeric($v) ?
|
|
|
74 |
(strtoupper($k) . "', $v") :
|
|
|
75 |
"$v', 0") .
|
|
|
76 |
")");
|
|
|
77 |
|
|
|
78 |
foreach($tables_sequences as $k => $v)
|
|
|
79 |
spip_query_db("INSERT IGNORE spip_types_documents (extension, titre, inclus) VALUES ('$k', '$v', 'embed')");
|
|
|
80 |
|
|
|
81 |
foreach($tables_documents as $k => $v)
|
|
|
82 |
spip_query_db("INSERT IGNORE spip_types_documents (extension, titre, inclus) VALUES ('$k', '$v', 'non')");
|
|
|
83 |
|
|
|
84 |
foreach ($tables_mime as $extension => $type_mime)
|
|
|
85 |
spip_query_db("UPDATE spip_types_documents
|
|
|
86 |
SET mime_type='$type_mime' WHERE extension='$extension'");
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
function stripslashes_base($table, $champs) {
|
|
|
90 |
$modifs = '';
|
|
|
91 |
reset($champs);
|
|
|
92 |
while (list(, $champ) = each($champs)) {
|
|
|
93 |
$modifs[] = $champ . '=REPLACE(REPLACE(' .$champ. ',"\\\\\'", "\'"), \'\\\\"\', \'"\')';
|
|
|
94 |
}
|
|
|
95 |
$query = "UPDATE $table SET ".join(',', $modifs);
|
|
|
96 |
spip_query($query);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
?>
|