|
|
@@ -1,4 +1,5 @@
|
|
1
|
1
|
<?php
|
|
|
2
|
+if(!defined('entry'))define('entry', true);
|
|
2
|
3
|
/* ===========================
|
|
3
|
4
|
|
|
4
|
5
|
gelato CMS - A PHP based tumblelog CMS
|
|
|
@@ -9,84 +10,15 @@
|
|
9
|
10
|
Copyright (C) 2007 by Pedro Santana <pecesama at gmail dot com>
|
|
10
|
11
|
|
|
11
|
12
|
=========================== */
|
|
12
|
|
-?>
|
|
13
|
|
-<?php
|
|
14
|
13
|
|
|
15
|
14
|
$configFile = dirname(__FILE__).DIRECTORY_SEPARATOR."config.php";
|
|
16
|
|
-
|
|
17
|
|
-if (!file_exists($configFile)) {
|
|
18
|
|
- $mensaje = "
|
|
19
|
|
- <h3 class=\"important\">Error reading configuration file</h3>
|
|
20
|
|
- <p>There doesn't seem to be a <code>config.php</code> file. I need this before we can get started.</p>
|
|
21
|
|
- <p>This either means that you did not rename the <code>config-sample.php</code> file to <code>config.php</code>.</p>";
|
|
22
|
|
- die($mensaje);
|
|
23
|
|
-} else {
|
|
24
|
|
- require(dirname(__FILE__).DIRECTORY_SEPARATOR."config.php");
|
|
25
|
|
- $showForm = true;
|
|
26
|
|
-}
|
|
27
|
15
|
|
|
28
|
|
-
|
|
29
|
|
-include("classes/functions.php");
|
|
|
16
|
+include('classes/functions.php');
|
|
|
17
|
+include('classes/install.class.php');
|
|
30
|
18
|
|
|
31
|
|
-$errors_d=array();
|
|
32
|
|
-$errors_d[1]="The login field cannot be empty";
|
|
33
|
|
-$errors_d[2]="The password field cannot be empty";
|
|
34
|
|
-$errors_d[3]="Password does not match the confirm password";
|
|
35
|
|
-$errors_d[4]="The e-mail field cannot be empty";
|
|
36
|
|
-$errors_d[5]="The installation URL field cannot be empty";
|
|
37
|
|
-$errors_d[6]="Error establishing a database connection";
|
|
38
|
|
-
|
|
39
|
|
-$action="";
|
|
40
|
|
-$errors="";
|
|
41
|
|
-
|
|
42
|
|
-if (isset($_POST['action'])){
|
|
43
|
|
- $action=$_POST['action'];
|
|
44
|
|
-}
|
|
45
|
|
-
|
|
46
|
|
-if ($action=="config" && !is_db_installed()) {
|
|
47
|
|
-
|
|
48
|
|
- $sep_err="";
|
|
49
|
|
-
|
|
50
|
|
- if (!$_POST['login']) {
|
|
51
|
|
- $errors=$errors.$sep_err."1";
|
|
52
|
|
- $sep_err="|";
|
|
53
|
|
- }
|
|
54
|
|
- if (!$_POST['password']) {
|
|
55
|
|
- $errors=$errors.$sep_err."2";
|
|
56
|
|
- $sep_err="|";
|
|
57
|
|
- }
|
|
58
|
|
- if (!$_POST['email']) {
|
|
59
|
|
- $errors=$errors.$sep_err."4";
|
|
60
|
|
- $sep_err="|";
|
|
61
|
|
- }
|
|
62
|
|
- if (!$_POST['url_installation']) {
|
|
63
|
|
- $errors=$errors.$sep_err."5";
|
|
64
|
|
- $sep_err="|";
|
|
65
|
|
- }
|
|
66
|
|
- if ($_POST['password']!=$_POST['password2']) {
|
|
67
|
|
- $errors=$errors.$sep_err."3";
|
|
68
|
|
- $sep_err="|";
|
|
69
|
|
- }
|
|
70
|
|
- $off_r= split("," , $_POST['time_offsets']);
|
|
71
|
|
- $_POST['offset_time'] = $off_r[0];
|
|
72
|
|
- $_POST['offset_city'] = $off_r[1];
|
|
73
|
|
- unset($_POST['time_offsets']);
|
|
74
|
|
-
|
|
75
|
|
- if (!$errors) {
|
|
76
|
|
- if (install_db($_POST['login'], $_POST['password'], $_POST['email'], $_POST['title'], $_POST['description'], $_POST['url_installation'], $_POST['posts_limit'], $_POST['lang'], $_POST['template'], $_POST['website'], $_POST['about'], $_POST['offset_city'], $_POST['offset_time'])) {
|
|
77
|
|
- $showForm=false;
|
|
78
|
|
- } else {
|
|
79
|
|
- $errors=$errors.$sep_err."6";
|
|
80
|
|
- $sep_err="|";
|
|
81
|
|
- $showForm=true;
|
|
82
|
|
- }
|
|
83
|
|
- } else {
|
|
84
|
|
- $showForm=true;
|
|
85
|
|
- }
|
|
86
|
|
-}
|
|
87
|
|
-
|
|
88
|
|
-
|
|
89
|
|
- $showForm = (!is_db_installed());
|
|
|
19
|
+$install = new Install();
|
|
|
20
|
+$install->data = $_POST;
|
|
|
21
|
+$install->check_form();
|
|
90
|
22
|
|
|
91
|
23
|
?>
|
|
92
|
24
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
@@ -110,7 +42,7 @@ if ($action=="config" && !is_db_installed()) {
|
|
110
|
42
|
|
|
111
|
43
|
<?php
|
|
112
|
44
|
|
|
113
|
|
- if ($showForm) {
|
|
|
45
|
+ if ($install->showForm) {
|
|
114
|
46
|
?>
|
|
115
|
47
|
|
|
116
|
48
|
<div class="box">
|
|
|
@@ -122,17 +54,32 @@ if ($action=="config" && !is_db_installed()) {
|
|
122
|
54
|
|
|
123
|
55
|
<div class="tabla">
|
|
124
|
56
|
<form action="install.php" method="post" id="config_form" autocomplete="off" class="newpost">
|
|
|
57
|
+ <fieldset>
|
|
|
58
|
+ <legend class="install">Database Settings</legend>
|
|
|
59
|
+ <ul>
|
|
|
60
|
+ <li><label for="login">User:</label>
|
|
|
61
|
+ <input type="text" name="db_login" id="db_login" value="" class="txt"/><?php echo $install->mostrarerror("1")?></li>
|
|
|
62
|
+ <li><label for="password">Password:</label>
|
|
|
63
|
+ <input type="password" name="db_password" id="db_password" value="" class="txt"/><?php echo $install->mostrarerror("2")?></li>
|
|
|
64
|
+ <li><label for="password2">Re-type password:</label>
|
|
|
65
|
+ <input type="password" name="db_password2" id="db_password2" value="" class="txt"/><?php echo $install->mostrarerror("3")?></li>
|
|
|
66
|
+ <li><label for="email">Database Host:</label>
|
|
|
67
|
+ <input type="text" name="db_host" id="db_host" value="localhost" class="txt"/><?php echo $install->mostrarerror("7")?></li>
|
|
|
68
|
+ <li><label for="email">Database Name:</label>
|
|
|
69
|
+ <input type="text" name="db_name" id="db_name" value="gelatocms" class="txt"/><?php echo $install->mostrarerror("8")?></li>
|
|
|
70
|
+ </ul>
|
|
|
71
|
+ </fieldset><br />
|
|
125
|
72
|
<fieldset>
|
|
126
|
73
|
<legend class="install">Admin user</legend>
|
|
127
|
74
|
<ul>
|
|
128
|
75
|
<li><label for="login">User:</label>
|
|
129
|
|
- <input type="text" name="login" id="login" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"1")?></li>
|
|
|
76
|
+ <input type="text" name="login" id="login" value="" class="txt"/><?php echo $install->mostrarerror("1")?></li>
|
|
130
|
77
|
<li><label for="password">Password:</label>
|
|
131
|
|
- <input type="password" name="password" id="password" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"2")?></li>
|
|
|
78
|
+ <input type="password" name="password" id="password" value="" class="txt"/><?php echo $install->mostrarerror("2")?></li>
|
|
132
|
79
|
<li><label for="password2">Re-type password:</label>
|
|
133
|
|
- <input type="password" name="password2" id="password2" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"3")?></li>
|
|
|
80
|
+ <input type="password" name="password2" id="password2" value="" class="txt"/><?php echo $install->mostrarerror("3")?></li>
|
|
134
|
81
|
<li><label for="email">E-mail:</label>
|
|
135
|
|
- <input type="text" name="email" id="email" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"4")?></li>
|
|
|
82
|
+ <input type="text" name="email" id="email" value="" class="txt"/><?php echo $install->mostrarerror("4")?></li>
|
|
136
|
83
|
</ul>
|
|
137
|
84
|
</fieldset><br />
|
|
138
|
85
|
<fieldset>
|
|
|
@@ -143,7 +90,7 @@ if ($action=="config" && !is_db_installed()) {
|
|
143
|
90
|
<li><label for="description">Description:</label>
|
|
144
|
91
|
<input type="text" name="description" id="description" value="" class="txt"/></li>
|
|
145
|
92
|
<li><label for="url_installation">Installation URL</label>
|
|
146
|
|
- <input type="text" name="url_installation" id="url_installation" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"5")?></li>
|
|
|
93
|
+ <input type="text" name="url_installation" id="url_installation" value="<?php print substr($_SERVER["SCRIPT_URI"], '0', '-12'); ?>" class="txt"/><?php echo $install->mostrarerror("5")?></li>
|
|
147
|
94
|
<li><label for="posts_limit">Post limit:</label>
|
|
148
|
95
|
<input type="text" name="posts_limit" id="posts_limit" value="10" class="txt"/></li>
|
|
149
|
96
|
<li><label for="lang">Language:</label>
|
|
|
@@ -254,131 +201,3 @@ if ($action=="config" && !is_db_installed()) {
|
|
254
|
201
|
</div>
|
|
255
|
202
|
</body>
|
|
256
|
203
|
</html>
|
|
257
|
|
-
|
|
258
|
|
-<?php
|
|
259
|
|
-function install_db($login, $password, $email, $title, $description, $url_installation, $posts_limit, $lang, $template, $website, $about, $offset_city, $offset_time){
|
|
260
|
|
-
|
|
261
|
|
- $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
|
|
262
|
|
-
|
|
263
|
|
- $sqlStr = "CREATE TABLE `".Table_prefix."data` (
|
|
264
|
|
- `id_post` int(11) NOT NULL auto_increment,
|
|
265
|
|
- `title` text NULL,
|
|
266
|
|
- `url` varchar(250) default NULL,
|
|
267
|
|
- `description` text NULL,
|
|
268
|
|
- `type` tinyint(4) NOT NULL default '1',
|
|
269
|
|
- `date` datetime NOT NULL,
|
|
270
|
|
- `id_user` int(10) NOT NULL,
|
|
271
|
|
- PRIMARY KEY (`id_post`)
|
|
272
|
|
- ) ENGINE = MYISAM ;";
|
|
273
|
|
-
|
|
274
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
275
|
|
-
|
|
276
|
|
- $sqlStr = "CREATE TABLE `".Table_prefix."users` (
|
|
277
|
|
- `id_user` int(10) unsigned NOT NULL auto_increment,
|
|
278
|
|
- `name` varchar(100) default NULL,
|
|
279
|
|
- `login` varchar(100) NOT NULL default '',
|
|
280
|
|
- `password` varchar(64) NOT NULL default '',
|
|
281
|
|
- `email` varchar(100) default NULL,
|
|
282
|
|
- `website` varchar(150) default NULL,
|
|
283
|
|
- `about` text,
|
|
284
|
|
- PRIMARY KEY (`id_user`)
|
|
285
|
|
- ) ENGINE = MYISAM;";
|
|
286
|
|
-
|
|
287
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
288
|
|
-
|
|
289
|
|
- $sqlStr = "CREATE TABLE `".Table_prefix."config` (
|
|
290
|
|
- `posts_limit` int(3) NOT NULL,
|
|
291
|
|
- `title` varchar(250) NOT NULL,
|
|
292
|
|
- `description` text NOT NULL,
|
|
293
|
|
- `lang` varchar(10) NOT NULL,
|
|
294
|
|
- `template` varchar(100) NOT NULL,
|
|
295
|
|
- `url_installation` varchar(250) NOT NULL,
|
|
296
|
|
- PRIMARY KEY (`title`)
|
|
297
|
|
- ) ENGINE = MYISAM ;";
|
|
298
|
|
-
|
|
299
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
300
|
|
-
|
|
301
|
|
- $sqlStr = "CREATE TABLE `".Table_prefix."options` (
|
|
302
|
|
- `name` varchar(100) NOT NULL,
|
|
303
|
|
- `val` varchar(255) NOT NULL,
|
|
304
|
|
- PRIMARY KEY (`name`)
|
|
305
|
|
- ) ENGINE = MYISAM ;";
|
|
306
|
|
-
|
|
307
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
308
|
|
-
|
|
309
|
|
- $sqlStr = "CREATE TABLE `".Table_prefix."comments` (
|
|
310
|
|
- `id_comment` int(11) NOT NULL auto_increment,
|
|
311
|
|
- `id_post` int(11) NOT NULL,
|
|
312
|
|
- `username` varchar(50) NOT NULL,
|
|
313
|
|
- `email` varchar(100) NOT NULL,
|
|
314
|
|
- `web` varchar(250) default NULL,
|
|
315
|
|
- `content` text NOT NULL,
|
|
316
|
|
- `ip_user` varchar(50) NOT NULL,
|
|
317
|
|
- `comment_date` datetime NOT NULL,
|
|
318
|
|
- `spam` tinyint(4) NOT NULL,
|
|
319
|
|
- PRIMARY KEY (`id_comment`)
|
|
320
|
|
- ) ENGINE = MYISAM ;";
|
|
321
|
|
-
|
|
322
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
323
|
|
-
|
|
324
|
|
- $url_installation = (endsWith($url_installation, "/")) ? substr($url_installation, 0, strlen($url_installation)-1) : $url_installation ;
|
|
325
|
|
-
|
|
326
|
|
- $sqlStr = "INSERT INTO `".Table_prefix."config` VALUES (".$posts_limit.", '".$title."', '".$description."', '".$lang."', '".$template."', '".$url_installation."');";
|
|
327
|
|
-
|
|
328
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
329
|
|
-
|
|
330
|
|
- $sqlStr = "INSERT INTO `".Table_prefix."users` VALUES ('', '', '".$login."', '".md5($password)."', '".$email."', '".$website."', '".$about."');";
|
|
331
|
|
-
|
|
332
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
333
|
|
-
|
|
334
|
|
- $sqlStr = "INSERT INTO `".Table_prefix."options` VALUES ('url_friendly', '1');";
|
|
335
|
|
-
|
|
336
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
337
|
|
-
|
|
338
|
|
- $sqlStr = "INSERT INTO `".Table_prefix."options` VALUES ('rich_text', '0');";
|
|
339
|
|
-
|
|
340
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
341
|
|
-
|
|
342
|
|
- $sqlStr = "INSERT INTO `".Table_prefix."options` VALUES ('allow_comments', '0');";
|
|
343
|
|
-
|
|
344
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
345
|
|
-
|
|
346
|
|
- $sqlStr = "INSERT INTO `".Table_prefix."options` VALUES ('offset_city', '".$offset_city."');";
|
|
347
|
|
-
|
|
348
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
349
|
|
-
|
|
350
|
|
- $sqlStr = "INSERT INTO `".Table_prefix."options` VALUES ('offset_time', '".$offset_time."');";
|
|
351
|
|
-
|
|
352
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
353
|
|
-
|
|
354
|
|
- $db->cierraConexion();
|
|
355
|
|
- return true;
|
|
356
|
|
-}
|
|
357
|
|
-
|
|
358
|
|
-function inerrors($errors,$n) {
|
|
359
|
|
- if (strpos($errors,$n)===false) {
|
|
360
|
|
- return false;
|
|
361
|
|
- } else {
|
|
362
|
|
- return true;
|
|
363
|
|
- }
|
|
364
|
|
-}
|
|
365
|
|
-
|
|
366
|
|
-function mostrarerror($errors,$errors_d,$n) {
|
|
367
|
|
- if (inerrors($errors,$n)) {
|
|
368
|
|
- return '<span class="error">'.$errors_d[$n].'</span>';
|
|
369
|
|
- } else {
|
|
370
|
|
- return "";
|
|
371
|
|
- }
|
|
372
|
|
-}
|
|
373
|
|
-
|
|
374
|
|
-function is_db_installed(){
|
|
375
|
|
-
|
|
376
|
|
- $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
|
|
377
|
|
-
|
|
378
|
|
- $sqlStr = "SELECT * FROM `".Table_prefix."config`";
|
|
379
|
|
-
|
|
380
|
|
- $db->ejecutarConsulta($sqlStr);
|
|
381
|
|
-
|
|
382
|
|
- return ($db->contarRegistros() > 0);
|
|
383
|
|
-}
|
|
384
|
|
-?>
|