Преглед на файлове

* Repaired installation script.

Victor De la Rocha преди 16 години
родител
ревизия
02407f90f3
променени са 6 файла, в които са добавени 235 реда и са изтрити 258 реда
  1. 51 86
      classes/install.class.php
  2. 109 109
      classes/mysql_connection.class.php
  3. 11 12
      classes/user.class.php
  4. 2 3
      config-sample.php
  5. 31 22
      entry.php
  6. 31 26
      install.php

+ 51 - 86
classes/install.class.php Целия файл

@@ -1,13 +1,13 @@
1 1
 <?php
2
-if(!defined('entry') || !entry) die('Not a valid page'); 
3
-require('classes/mysql_connection.class.php');
2
+if(!defined('entry') || !entry) die('Not a valid page');
3
+require(Absolute_Path.'/classes/mysql_connection.class.php');
4 4
 
5 5
 class Install {
6 6
 	var $data = null;
7 7
 	var $errors = null;
8 8
 	var $showForm;
9 9
 	var $errors_d = array();
10
-	
10
+
11 11
 	function Install(){
12 12
 		$this->errors_d[1]="The login field cannot be empty";
13 13
 		$this->errors_d[2]="The password field cannot be empty";
@@ -20,41 +20,39 @@ class Install {
20 20
 		$this->errors_d[9]="Password does not match the confirm password";
21 21
 		$this->errors_d[10]="The login field cannot be empty";
22 22
 	}
23
-	
23
+
24 24
     function run() {
25
-    	
25
+
26 26
     	if (empty($this->data)) false;
27
-    	
28
-    	if (!$this->create_config()) return false;
29
-    	
27
+
30 28
     	$this->create_db();
31
-    	
29
+
32 30
     	if (!$this->install_db()) return false;
33
-		
31
+
34 32
 		return true;
35 33
     }
36
-    
34
+
37 35
     function create_db(){
38
-		
36
+
39 37
 	    $link =  mysql_connect($this->data['db_host'], $this->data['db_login'], $this->data['db_password']);
40 38
 		if (!$link) {
41 39
 		    die('Could not connect: ' . mysql_error());
42 40
 		}
43
-		
41
+
44 42
 		$sql = 'CREATE DATABASE ' . $this->data['db_name'];
45 43
 		if (!mysql_query($sql, $link)) {
46 44
 			$link = mysql_close($link);
47 45
 			return false;
48
-		} 
49
-		
50
-		return true;    	
46
+		}
47
+
48
+		return true;
51 49
     }
52
-    
50
+
53 51
 	function install_db(){
54 52
 		require('config.php');
55
-		$db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);	
53
+		$db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
56 54
 		$sqlStr = array();
57
-		
55
+
58 56
 		$sqlStr[] = "CREATE TABLE `".Table_prefix."data` (
59 57
 			  `id_post` int(11) NOT NULL auto_increment,
60 58
 			  `title` text NULL,
@@ -86,16 +84,16 @@ class Install {
86 84
 			  `url_installation` varchar(250) NOT NULL,
87 85
 			  PRIMARY KEY  (`title`)
88 86
 			) ENGINE = MYISAM ;";
89
-			
90 87
 
91
-		
88
+
89
+
92 90
 		$sqlStr[] = "CREATE TABLE `".Table_prefix."options` (
93 91
 		  `name` varchar(100) NOT NULL,
94 92
 		  `val` varchar(255) NOT NULL,
95 93
 		  PRIMARY KEY  (`name`)
96 94
 		) ENGINE = MYISAM ;";
97 95
 
98
-		
96
+
99 97
 		$sqlStr[] = "CREATE TABLE `".Table_prefix."comments` (
100 98
 		  `id_comment` int(11) NOT NULL auto_increment,
101 99
 		  `id_post` int(11) NOT NULL,
@@ -108,7 +106,7 @@ class Install {
108 106
 		  `spam` tinyint(4) NOT NULL,
109 107
 		  PRIMARY KEY  (`id_comment`)
110 108
 		) ENGINE = MYISAM ;";
111
-		
109
+
112 110
 		$sqlStr[] = "CREATE TABLE `".Table_prefix."feeds` (
113 111
 			`id_feed` int(11) NOT NULL auto_increment,
114 112
 			`url` varchar(255) NOT NULL,
@@ -122,13 +120,13 @@ class Install {
122 120
 			PRIMARY KEY  (`id_feed`)
123 121
 			) ENGINE=MyISAM ;";
124 122
 
125
-					
126
-		$sqlStr[] = "INSERT INTO `".Table_prefix."config` VALUES (". $this->data['posts_limit'] .", '".$this->data['title']."', '".$this->data['description']."', '".$this->data['lang']."', '".$this->data['template']."', '".$this->data['url_installation']."');";		
123
+
124
+		$sqlStr[] = "INSERT INTO `".Table_prefix."config` VALUES (". $this->data['posts_limit'] .", '".$this->data['title']."', '".$this->data['description']."', '".$this->data['lang']."', '".$this->data['template']."', '".$this->data['url_installation']."');";
127 125
 		$sqlStr[] = "INSERT INTO `".Table_prefix."users` VALUES ('', '', '".$this->data['login']."', '".md5($this->data['password'])."', '".$this->data['email']."', '".$this->data['website']."', '".$this->data['about']."');";
128 126
 		$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('url_friendly', '0');";
129
-		$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('rich_text', '0');";		
127
+		$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('rich_text', '0');";
130 128
 		$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('allow_comments', '0');";
131
-		$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('offset_city', '".$this->data['offset_city']."');";		
129
+		$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('offset_city', '".$this->data['offset_city']."');";
132 130
 		$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('offset_time', '".$this->data['offset_time']."');";
133 131
 		$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('shorten_links', '0');";
134 132
 		$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('rss_import_frec', '5 minutes');";
@@ -141,7 +139,7 @@ class Install {
141 139
 
142 140
 		return true;
143 141
 	}
144
-	
142
+
145 143
 	function inerrors($n) {
146 144
 		if ( strpos($this->errors,$n)===false) {
147 145
 			return false;
@@ -149,7 +147,7 @@ class Install {
149 147
 			return true;
150 148
 		}
151 149
 	}
152
-	
150
+
153 151
 	function mostrarerror($n) {
154 152
 		if ($this->inerrors($n)) {
155 153
 			return '<span class="error">'.$this->errors_d[$n].'</span>';
@@ -157,12 +155,12 @@ class Install {
157 155
 			return "";
158 156
 		}
159 157
 	}
160
-	
158
+
161 159
 	function is_gelato_installed(){
162
-		if(file_exists('config.php')) {
163
-			@include("config.php");
164
-			if (!$this->check_for_config()){ 
165
-				return false; 
160
+		if(file_exists(Absolute_Path.'config.php')) {
161
+			@include(Absolute_Path."config.php");
162
+			if (!$this->check_for_config()){
163
+				return false;
166 164
 			} else {
167 165
 				if (!$this->is_db_installed()){
168 166
 					return false;
@@ -173,18 +171,18 @@ class Install {
173 171
 			return false;
174 172
 		}
175 173
 	}
176
-	
174
+
177 175
 	function is_db_installed(){
178
-			$db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);	
176
+			$db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
179 177
 				$sqlStr = "SELECT * FROM `".Table_prefix."config`";
180 178
 				if($db->ejecutarConsulta($sqlStr)) {
181 179
 					return ($db->contarRegistros() > 0);
182 180
 			}else{
183 181
 			return false;
184 182
 			}
185
-	
183
+
186 184
 	}
187
-	
185
+
188 186
 	function check_for_config(){
189 187
 		if(!defined('DB_Server')) return false;
190 188
 		if(!defined('DB_name')) return false;
@@ -192,57 +190,24 @@ class Install {
192 190
 		if(!defined('DB_Password')) return false;
193 191
 		return true;
194 192
 	}
195
-	
196
-	function create_config(){
197
-		$config = fopen("config.php", 'w+');
198
-		$contents = '<?php
199
-if(!defined(\'entry\') || !entry) die(\'Not a valid page\'); 
200
-/* ===========================
201
-
202
-  gelato CMS - A PHP based tumblelog CMS
203
-  development version
204
-  http://www.gelatocms.com/
205
-
206
-  gelato CMS is a free software licensed under the GPL 2.0
207
-  Copyright (C) 2007 by Pedro Santana <pecesama at gmail dot com>
208
-
209
-  =========================== */
210
-
211
-define(\'DB_Server\', \''. $this->data['db_host'] . '\');
212
-define(\'DB_name\', \''. $this->data['db_name'] . '\');
213
-define(\'DB_User\', \''. $this->data['db_login'] . '\');
214
-define(\'DB_Password\', \''. $this->data['db_password'] . '\'); 
215
-define(\'Table_prefix\', \'gel_\');
216
-define(\'Absolute_Path\', dirname(__FILE__).DIRECTORY_SEPARATOR);
217
-
218
-?>';
219
-
220
-	    if (fwrite($config, $contents) === FALSE) {
221
-	        $this->errors = "Could not write config file to directory";
222
-	        return false;
223
-	    } 
224
-	    fclose($config);
225
-	    return true;		
226
-	}
227
-	
193
+
228 194
 	function check_form(){
229 195
 
230 196
 		$action="";
231
-		
197
+
232 198
 		if (isset($this->data['action'])){
233 199
 			$action=$this->data['action'];
234 200
 		}
235
-		
201
+
236 202
 		if (!$this->is_gelato_installed()){
237
-			
203
+
238 204
 		$this->showForm = true;
239
-			
240
-		
205
+
241 206
 			if ($action=="config") {
242
-				
207
+
243 208
 				$sep_err="";
244 209
 				$this->errors = false;
245
-				
210
+
246 211
 				if (!$this->data['login']) {
247 212
 					$this->errors =$this->errors.$sep_err."1";
248 213
 					$sep_err="|";
@@ -274,31 +239,31 @@ define(\'Absolute_Path\', dirname(__FILE__).DIRECTORY_SEPARATOR);
274 239
 				if ($this->data['password']!=$_POST['password2']) {
275 240
 					$this->errors=$this->errors.$sep_err."3";
276 241
 					$sep_err="|";
277
-				}				
242
+				}
278 243
 				if ( $_POST['db_password']!=$_POST['db_password2']) {
279 244
 					$this->errors=$this->errors.$sep_err."9";
280 245
 					$sep_err="|";
281
-				}				
282
-				
246
+				}
247
+
283 248
 				$off_r= split("," , $this->data['time_offsets']);
284 249
 				$this->data['offset_time'] = $off_r[0];
285 250
 				$this->data['offset_city'] = $off_r[1];
286 251
 				unset($this->data['time_offsets']);
287
-				
252
+
288 253
 				if (!$this->errors) {
289
-							
254
+
290 255
 					if ($this->run($this->data)) {
291 256
 						$this->showForm=false;
292 257
 					} else {
293 258
 						$this->errors=$this->errors.$sep_err."6";
294 259
 						$sep_err="|";
295 260
 						$this->showForm=true;
296
-					}		
261
+					}
297 262
 				} else {
298 263
 					$this->showForm=true;
299 264
 				}
300 265
 			}
301
-		}	
302
-	}	
266
+		}
267
+	}
303 268
 }
304 269
 ?>

+ 109 - 109
classes/mysql_connection.class.php Целия файл

@@ -15,26 +15,26 @@
15 15
 // constantes
16 16
 define('MYSQL_TYPES_NUMERIC', 'int real ');
17 17
 define('MYSQL_TYPES_DATE', 'datetime timestamp year date time ');
18
-define('MYSQL_TYPES_STRING', 'string blob '); 
18
+define('MYSQL_TYPES_STRING', 'string blob ');
19 19
 
20 20
 class Conexion_Mysql {
21 21
 
22
-	var $mbase_datos;	
23
-	var $mservidor;	
24
-	var $musuario;	
25
-	var $mclave; 
26
-	var $mid_conexion = 0; 	// Identificador de conexión	
22
+	var $mbase_datos;
23
+	var $mservidor;
24
+	var $musuario;
25
+	var $mclave;
26
+	var $mid_conexion = 0; 	// Identificador de conexi�n
27 27
 	var $mid_consulta = 0; 	// Identificador de consulta
28
-	var $merror_numero = 0;		// Número de error			
29
-	var $merror = "";		// Descripción del error.
30
-	
31
-	/** Al crear una instancia de clase, se ejecutará esta función */	
32
-	function Conexion_Mysql($bd="", $host="localhost", $user="", $pass="") {	
33
-		$this->mbase_datos = $bd;	
34
-		$this->mservidor = $host;	
35
-		$this->musuario = $user;	
28
+	var $merror_numero = 0;		// N�mero de error
29
+	var $merror = "";		// Descripci�n del error.
30
+
31
+	/** Al crear una instancia de clase, se ejecutara esta funcion */
32
+	function Conexion_Mysql($bd="", $host="localhost", $user="", $pass="") {
33
+		$this->mbase_datos = $bd;
34
+		$this->mservidor = $host;
35
+		$this->musuario = $user;
36 36
 		$this->mclave = $pass;
37
-		
37
+
38 38
 		if (!$this->conectar()) {
39 39
 			$mensaje = "
40 40
 				<h3 class=\"important\">Error establishing a database connection</h3>
@@ -44,42 +44,42 @@ class Conexion_Mysql {
44 44
 					<li>Are you sure that you have typed the correct hostname?</li>
45 45
 					<li>Are you sure that the database server is running?</li>
46 46
 				</ul>";
47
-			die($mensaje);			
47
+			die($mensaje);
48 48
 		}
49 49
 	}
50
-	
51
-	/** Conectar a la base de datos */	
52
-	function conectar() {		
53
-		// Conectamos al servidor		
54
-		$this->mid_conexion = @mysql_connect($this->mservidor, $this->musuario, $this->mclave);		
55
-		if (!$this->mid_conexion) {		
56
-			$this->merror = "No se logró realizar la conexión.";		
50
+
51
+	/** Conectar a la base de datos */
52
+	function conectar() {
53
+		// Conectamos al servidor
54
+		$this->mid_conexion = @mysql_connect($this->mservidor, $this->musuario, $this->mclave);
55
+		if (!$this->mid_conexion) {
56
+			$this->merror = "No se logr� realizar la conexi�n.";
57 57
 			return false;
58
-		}	 
59
-		//seleccionamos la base de datos		
60
-		if (!@mysql_select_db($this->mbase_datos, $this->mid_conexion)) {		
61
-			$this->merror = "No se puede abrir la base ".$this->mbase_datos ;		
62
-			return false;		
63
-		}	 
64
-		return $this->mid_conexion;	// Si todo salio bien regresa el id de la conexión
65
-	}	
66
-	
67
-	/** Para ejecutar consultas en la conexión abierta */	
58
+		}
59
+		//seleccionamos la base de datos
60
+		if (!@mysql_select_db($this->mbase_datos, $this->mid_conexion)) {
61
+			$this->merror = "No se puede abrir la base ".$this->mbase_datos ;
62
+			return false;
63
+		}
64
+		return $this->mid_conexion;	// Si todo salio bien regresa el id de la conexi�n
65
+	}
66
+
67
+	/** Para ejecutar consultas en la conexi�n abierta */
68 68
 	function ejecutarConsulta($msql = "") {
69
-		if ($msql == "") {	
70
-			$this->merror = "No introdujo la sentencia SQL";	
71
-			return false;	
72
-		}		
73
-		//ejecutamos la consulta		
74
-		$this->mid_consulta = mysql_query($msql, $this->mid_conexion);		
75
-		if (!$this->mid_consulta) {		
76
-			$this->merror_numero = mysql_errno();		
69
+		if ($msql == "") {
70
+			$this->merror = "No introdujo la sentencia SQL";
71
+			return false;
72
+		}
73
+		//ejecutamos la consulta
74
+		$this->mid_consulta = mysql_query($msql, $this->mid_conexion);
75
+		if (!$this->mid_consulta) {
76
+			$this->merror_numero = mysql_errno();
77 77
 			$this->merror = mysql_error()." error";
78
-			return false;		
79
-		}				
80
-		return $this->mid_consulta; // Si todo salio bien regresa el id de la consulta	
81
-	}	
82
-	
78
+			return false;
79
+		}
80
+		return $this->mid_consulta; // Si todo salio bien regresa el id de la consulta
81
+	}
82
+
83 83
 	/**
84 84
 	 * Inserta un registro en la DB por cada llave->valor en un arreglo.
85 85
 	 * No se debe usar sentencias SQL con esta funcion.
@@ -90,26 +90,26 @@ class Conexion_Mysql {
90 90
 	 * @return string El ID del insert, verdadero si la tabla no tiene un campo auto_increment o false si ocurre un error.
91 91
 	 */
92 92
 	function insertarDeFormulario($tabla, $datos) {
93
-	  	  
93
+
94 94
 	  if (empty($datos)) {
95 95
 		 $this->merror = "Debes de pasar un arreglo como parametro.";
96 96
 		 return false;
97 97
 	  }
98
-	  
98
+
99 99
 	  $cols = '(';
100 100
 	  $sqlValues = '(';
101
-	  
101
+
102 102
 	  foreach ($datos as $llave=>$valor) {
103
-		  
104
-		 $cols .= "$llave,"; 
105
-		 
103
+
104
+		 $cols .= "$llave,";
105
+
106 106
 		 $tipo_col = $this->obtenerTipoCampo($tabla, $llave);  // obtiene el tipo de campo
107 107
 		 if (!$tipo_col) return false;  // error!
108
-		 
108
+
109 109
 		 // determina si se necesita poner comillas al valor.
110 110
 		 if (is_null($valor)) {
111
-			$sqlValues .= "NULL,";   
112
-		 } 
111
+			$sqlValues .= "NULL,";
112
+		 }
113 113
 		 elseif (substr_count(MYSQL_TYPES_NUMERIC, "$tipo_col ")) {
114 114
 			$sqlValues .= "$valor,";
115 115
 		 }
@@ -119,17 +119,17 @@ class Conexion_Mysql {
119 119
 		 }
120 120
 		 elseif (substr_count(MYSQL_TYPES_STRING, "$tipo_col ")) {
121 121
 			$valor = $this->sql_escape($valor);
122
-			$sqlValues .= "'$valor',";  
122
+			$sqlValues .= "'$valor',";
123 123
 		 }
124 124
 	  }
125 125
 	  $cols = rtrim($cols, ',').')';
126
-	  $sqlValues = rtrim($sqlValues, ',').')';     
127
-	  
128
-	  // inserta los valores en la DB	  
126
+	  $sqlValues = rtrim($sqlValues, ',').')';
127
+
128
+	  // inserta los valores en la DB
129 129
 	  $sql = "INSERT INTO $tabla $cols VALUES $sqlValues";
130
-	  return $this->ejecutarConsulta($sql);	  
130
+	  return $this->ejecutarConsulta($sql);
131 131
 	}
132
-	
132
+
133 133
 	/**
134 134
 	 * Modifica un registro en la DB por cada llave->valor en un arreglo.
135 135
 	 * No se debe usar sentencias SQL con esta funcion.
@@ -143,7 +143,7 @@ class Conexion_Mysql {
143 143
 	 * 		Falso si ocurrio algun error.
144 144
 	 */
145 145
 	function modificarDeFormulario($tabla, $datos, $condicion="") {
146
-      
146
+
147 147
 		if (empty($datos)) {
148 148
 			$this->merror = "Debes de pasar un arreglo como parametro.";
149 149
 			return false;
@@ -152,14 +152,14 @@ class Conexion_Mysql {
152 152
 		$sql = "UPDATE $tabla SET";
153 153
 		foreach ($datos as $llave=>$valor) {
154 154
 			$sql .= " $llave=";
155
-			
155
+
156 156
 			$tipo_col = $this->obtenerTipoCampo($tabla, $llave);  // obtiene el tipo de campo
157 157
 			if (!$tipo_col) return false;  // error!
158
-			
158
+
159 159
 			// determina si se necesita poner comillas al valor.
160 160
 			if (is_null($valor)) {
161
-			$sql .= "NULL,";   
162
-			} 
161
+			$sql .= "NULL,";
162
+			}
163 163
 			elseif (substr_count(MYSQL_TYPES_NUMERIC, "$tipo_col ")) {
164 164
 			$sql .= "$valor,";
165 165
 			}
@@ -169,25 +169,25 @@ class Conexion_Mysql {
169 169
 			}
170 170
 			elseif (substr_count(MYSQL_TYPES_STRING, "$tipo_col ")) {
171 171
 			$valor = $this->sql_escape($valor);
172
-			$sql .= "'$valor',";  
173
-			}	
172
+			$sql .= "'$valor',";
173
+			}
174 174
 		}
175 175
 		$sql = rtrim($sql, ','); // elimina la ultima coma
176 176
 		if (!empty($condicion)) $sql .= " WHERE $condicion";
177
-		
177
+
178 178
 		// modifica los valores
179 179
 		return $this->ejecutarConsulta($sql);
180 180
 	}
181
-	
181
+
182 182
 	/**
183
-	 * Obtiene la informacion sobre un campo usando la funcion mysql_fetch_field.	 
183
+	 * Obtiene la informacion sobre un campo usando la funcion mysql_fetch_field.
184 184
 	 *
185 185
 	 * @param mixed $tabla El nombre de la tabla en la BD.
186 186
 	 * @param string $campo El campo del que se desea la informacion.
187 187
 	 * @return array Un arreglo con la informacion del campo o false si hay algun error.
188 188
 	 */
189 189
 	function obtenerTipoCampo($tabla, $campo) {
190
-	
190
+
191 191
 	  $r = mysql_query("SELECT $campo FROM $tabla");
192 192
 	  if (!$r) {
193 193
 		 $this->merror = mysql_error();
@@ -200,9 +200,9 @@ class Conexion_Mysql {
200 200
 		 return false;
201 201
 	  }
202 202
 	  mysql_free_result($r);
203
-	  return $ret;	  
203
+	  return $ret;
204 204
 	}
205
-   
205
+
206 206
 	/**
207 207
 	 * Convierte una fecha en formato para DB.
208 208
 	 *
@@ -214,7 +214,7 @@ class Conexion_Mysql {
214 214
 			if(eregi("^([0-9]+)$",$valor)){
215 215
 				$valor = date("Y-m-d H:i:s",$valor);
216 216
 			}else{
217
-				// Estariá en el formato strtotime()
217
+				// Estari� en el formato strtotime()
218 218
 				$valor = date("Y-m-d H:i:s",strtotime($valor));
219 219
 			}
220 220
 		}
@@ -222,56 +222,56 @@ class Conexion_Mysql {
222 222
 	/*  if (gettype($valor) == 'string') $valor = strtotime($valor);
223 223
 	  return date('Y-m-d H:i:s', $valor);
224 224
 	*/
225
-	}	
225
+	}
226 226
 
227 227
 	/**
228 228
 	 * Obtiene el registro obtenido de una consulta.
229 229
 	 */
230
-	function obtenerRegistro() {				
231
-		return mysql_fetch_assoc($this->mid_consulta);	  	
232
-	}	
233
-	
230
+	function obtenerRegistro() {
231
+		return mysql_fetch_assoc($this->mid_consulta);
232
+	}
233
+
234 234
 	/**
235
-	 * Devuelve el número de campos de una consulta.
235
+	 * Devuelve el n�mero de campos de una consulta.
236 236
 	 */
237
-	function contarCampos() {	
238
-		return mysql_num_fields($this->mid_consulta);	
239
-	}	
240
-	
237
+	function contarCampos() {
238
+		return mysql_num_fields($this->mid_consulta);
239
+	}
240
+
241 241
 	/**
242
-	 * Devuelve el número de registros de una consulta.
242
+	 * Devuelve el n�mero de registros de una consulta.
243 243
 	 */
244
-	function contarRegistros() {	
245
-		return @mysql_num_rows($this->mid_consulta);	
246
-	}	
247
-	
244
+	function contarRegistros() {
245
+		return @mysql_num_rows($this->mid_consulta);
246
+	}
247
+
248 248
 	/**
249 249
 	 * Devuelve el nombre de un campo de una consulta.
250 250
 	 */
251
-	function obtenerNombreCampo($numero_campo) {	
252
-		return mysql_field_name($this->mid_consulta, $numero_campo);	
253
-	}	
254
-	
251
+	function obtenerNombreCampo($numero_campo) {
252
+		return mysql_field_name($this->mid_consulta, $numero_campo);
253
+	}
254
+
255 255
 	/**
256 256
 	 * Muestra los datos de una consulta (para debug).
257 257
 	 */
258 258
 	function verConsulta() {
259
-		echo "<table border=1>\n";	 	
260
-		// mostramos los nombres de los campos		
261
-		for ($i = 0; $i < $this->contarCampos(); $i++) {		
262
-			echo "<td><b>".$this->obtenerNombreCampo($i)."</b></td>\n";		
263
-		}		
264
-		echo "</tr>\n";		
259
+		echo "<table border=1>\n";
260
+		// mostramos los nombres de los campos
261
+		for ($i = 0; $i < $this->contarCampos(); $i++) {
262
+			echo "<td><b>".$this->obtenerNombreCampo($i)."</b></td>\n";
263
+		}
264
+		echo "</tr>\n";
265 265
 		// mostrarmos los registros
266
-		while ($row = mysql_fetch_row($this->mid_consulta)) {		
267
-			echo "<tr> \n";		
268
-			for ($i = 0; $i < $this->contarCampos(); $i++) {		
269
-				echo "<td>".$row[$i]."</td>\n";		
270
-			}		
271
-			echo "</tr>\n";		
272
-		}	
266
+		while ($row = mysql_fetch_row($this->mid_consulta)) {
267
+			echo "<tr> \n";
268
+			for ($i = 0; $i < $this->contarCampos(); $i++) {
269
+				echo "<td>".$row[$i]."</td>\n";
270
+			}
271
+			echo "</tr>\n";
272
+		}
273 273
 	}
274
-	
274
+
275 275
 	/**
276 276
 	 * Cierra la conexion a la BD.
277 277
 	 */
@@ -289,6 +289,6 @@ class Conexion_Mysql {
289 289
 	          $value = addslashes($value);
290 290
 	    }
291 291
 	    return $value;
292
-	}	
292
+	}
293 293
 } //fin de la Clase conexion_mysql
294 294
 ?>

+ 11 - 12
classes/user.class.php Целия файл

@@ -1,5 +1,5 @@
1 1
 <?php
2
-if(!defined('entry') || !entry) die('Not a valid page'); 
2
+if(!defined('entry') || !entry) die('Not a valid page');
3 3
 /* ===========================
4 4
 
5 5
   gelato CMS - A PHP based tumblelog CMS
@@ -20,7 +20,6 @@ class user extends Conexion_Mysql {
20 20
 	var $cookieTime;
21 21
 	var $persist = false;
22 22
 
23
-
24 23
 	function user() {
25 24
 		parent::Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
26 25
 		$this->cookie_life = 60*24*3600;
@@ -29,19 +28,19 @@ class user extends Conexion_Mysql {
29 28
 	}
30 29
 
31 30
 	function isAdmin() {
32
-		
31
+
33 32
 		if ((!empty($_SESSION["user_id"]) && !empty($_SESSION["user_login"]))  && (isset($_SESSION['authenticated'])  && $_SESSION['authenticated']==true)) {
34 33
 			return true;
35 34
 		}
36
-		
35
+
37 36
 		if(isset($_COOKIE["PHPSESSID"]) && $_COOKIE["PHPSESSID"]!="") {
38 37
 			if ((!empty($_SESSION["user_id"]) && !empty($_SESSION["user_login"]))  && (isset($_SESSION['authenticated'])  && $_SESSION['authenticated']==true)) {
39 38
 				return true;
40
-			} 
39
+			}
41 40
 		}
42
-		
41
+
43 42
 		return false;
44
-		
43
+
45 44
 	}
46 45
 
47 46
 	function validateUser($username="", $password="") {
@@ -55,7 +54,7 @@ class user extends Conexion_Mysql {
55 54
 				if (isset($_POST["save_pass"])) {
56 55
 					$this->persist = true;
57 56
 					setcookie("PHPSESSID",session_id(),$this->cookieTime+$this->cookie_life);
58
-				} 
57
+				}
59 58
 				return true;
60 59
 			} else {
61 60
 				return false;
@@ -65,9 +64,9 @@ class user extends Conexion_Mysql {
65 64
 		}
66 65
 	}
67 66
 
68
-	function closeSession() {	
67
+	function closeSession() {
69 68
 		if (!$this->persist) session_destroy();
70
-		return true;	
69
+		return true;
71 70
 	}
72 71
 
73 72
 	function userExist($user="") {
@@ -79,7 +78,7 @@ class user extends Conexion_Mysql {
79 78
 			}
80 79
 		}
81 80
 	}
82
-	
81
+
83 82
 	function isAuthenticated(){
84 83
 		return $this->isAdmin();
85 84
 	}
@@ -133,7 +132,7 @@ class user extends Conexion_Mysql {
133 132
 				return false;
134 133
 			}
135 134
 		}
136
-	}	
135
+	}
137 136
 
138 137
 	function confirmationEmail($email="", $user="", $password="") {
139 138
 		$msg =  "<font face=verdana><em><font size=2>Account information on <strong>gelato CMS</strong></font></em><br/><br/>";

+ 2 - 3
config-sample.php Целия файл

@@ -1,5 +1,5 @@
1 1
 <?php
2
-if(!defined('entry') || !entry) die('Not a valid page'); 
2
+if(!defined('entry') || !entry) die('Not a valid page');
3 3
 /* ===========================
4 4
 
5 5
   gelato CMS - A PHP based tumblelog CMS
@@ -14,8 +14,7 @@ if(!defined('entry') || !entry) die('Not a valid page');
14 14
 define('DB_Server', '[server]');
15 15
 define('DB_name', '[database]');
16 16
 define('DB_User', '[userdb]');
17
-define('DB_Password', '[dbpass]'); 
17
+define('DB_Password', '[dbpass]');
18 18
 define('Table_prefix', 'gel_');
19
-define('Absolute_Path', dirname(__FILE__).DIRECTORY_SEPARATOR);
20 19
 
21 20
 ?>

+ 31 - 22
entry.php Целия файл

@@ -20,26 +20,35 @@
20 20
  * admin/admin.php
21 21
  * admin/comments.php
22 22
  * admin/user.php
23
- * admin/feeds.php 
23
+ * admin/feeds.php
24 24
  * classes/imgsize.php
25 25
  */
26 26
 
27
- 
28 27
 // PHP settings specific to Gelato
29 28
 ini_set('pcre.backtrack_limit', '10000');
29
+// Globals to be used throughout the application
30
+define('Absolute_Path', dirname(__FILE__).DIRECTORY_SEPARATOR);
31
+$installed = true;
32
+$configFile = Absolute_Path.'config.php';
30 33
 
31
-// Globals to be used throughout the application        
32
-$configFile = dirname(__FILE__).DIRECTORY_SEPARATOR."config.php";
33
-
34
-if (!file_exists($configFile)) {
35
-	header("Location: install.php");  
36
-} else {
37
-        require(dirname(__FILE__).DIRECTORY_SEPARATOR."config.php");
38
-}       
34
+if(strpos($_SERVER['REQUEST_URI'],'/admin'))$dir = "../"; else $dir = "";
35
+if (!file_exists($configFile) and basename($_SERVER['PHP_SELF'])!='install.php'){
36
+	header("Location: {$dir}install.php");exit;
37
+}else{
38
+	include(Absolute_Path.'classes/install.class.php');
39
+	$install = new Install();
40
+	if(!$install->is_gelato_installed()){
41
+		if(basename($_SERVER['PHP_SELF'])!='install.php'){
42
+				header("Location: {$dir}install.php");exit;
43
+			}
44
+		$installed = false;
45
+	}
46
+}
39 47
 
48
+require($configFile);
40 49
 require_once("classes/configuration.class.php");
41 50
 require_once("classes/textile.class.php");
42
-require_once("classes/gelato.class.php");    
51
+require_once("classes/gelato.class.php");
43 52
 require_once("classes/templates.class.php");
44 53
 require_once("classes/pagination.class.php");
45 54
 require_once("classes/user.class.php");
@@ -50,17 +59,17 @@ require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'streams.class.php');
50 59
 require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'gettext.class.php');
51 60
 require_once(Absolute_Path.'classes'.DIRECTORY_SEPARATOR.'lang.functions.php');
52 61
 
53
-// Globals to be used throughout the application
54
-$user = new user();
55
-$tumble = new gelato();
56
-$conf = new configuration();
57
-$db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
58
-
59
-
60
-session_start();
62
+if($installed){
63
+	// Globals to be used throughout the application
64
+	$user = new user();
65
+	$tumble = new gelato();
66
+	$conf = new configuration();
67
+	$db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
61 68
 
62
-$feeds = new feeds();
63
-$feeds->updateFeeds();
64
-unset($feeds);
69
+	session_start();
65 70
 
71
+	$feeds = new feeds();
72
+	$feeds->updateFeeds();
73
+	unset($feeds);
74
+}
66 75
 ?>

+ 31 - 26
install.php Целия файл

@@ -1,5 +1,5 @@
1 1
 <?php
2
-if(!defined('entry'))define('entry', true);
2
+if(!defined('entry') || !entry) define('entry',true);
3 3
 /* ===========================
4 4
 
5 5
   gelato CMS - A PHP based tumblelog CMS
@@ -11,47 +11,52 @@ if(!defined('entry'))define('entry', true);
11 11
 
12 12
   =========================== */
13 13
 
14
-require('entry.php');
15
-global $user, $conf, $tumble;
14
+// Received a valid request, better start setting globals we'll need throughout the app in entry.php
15
+require_once('entry.php');
16 16
 
17
-include('classes/install.class.php'); 
18
-$install = new Install(); 
17
+$configFile = Absolute_Path."config.php";
18
+if(file_exists($configFile)){
19
+	require($configFile);
20
+}else{
21
+	exit("You need to rename config-sample.php to config.php and fill out the required details.");
22
+}
19 23
 
24
+global $user, $conf, $tumble;
25
+$install = new Install();
20 26
 $install->data = $_POST;
21 27
 $install->check_form();
22
-
23 28
 ?>
24 29
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
25 30
 <html xmlns="http://www.w3.org/1999/xhtml">
26 31
 <head>
27 32
 	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
28 33
 	<meta name="generator" content="gelato cms <?php echo version();?>" />
29
-	<title>gelato :: installation</title>	
34
+	<title>gelato :: installation</title>
30 35
 	<link rel="shortcut icon" href="images/favicon.ico" />
31
-	<style type="text/css" media="screen">	
32
-		@import "admin/css/style.css";		
33
-	</style>		
36
+	<style type="text/css" media="screen">
37
+		@import "admin/css/style.css";
38
+	</style>
34 39
 </head>
35 40
 <body>
36 41
 <div id="cont">
37 42
 	<div id="head">
38 43
 		<h1><a href="index.php" title="gelato :: home">gelato cms</a></h1>
39 44
 	</div>
40
-	
45
+
41 46
 	<div id="main">
42
-	
47
+
43 48
 <?php
44 49
 
45 50
 	if ($install->showForm) {
46 51
 ?>
47
-	
52
+
48 53
 	<div class="box">
49 54
 		<ul class="menu manage">
50 55
 		<h3>gelato :: installation</h3>
51 56
 
52 57
 		<li class="selected"><a>Install</a></li>
53 58
 		</ul>
54
-	
59
+
55 60
 		<div class="tabla">
56 61
 			<form action="install.php" method="post" id="config_form" autocomplete="off" class="newpost">
57 62
 				<fieldset class="install">
@@ -62,11 +67,11 @@ $install->check_form();
62 67
 						<li><label for="password">Password:</label>
63 68
 							<input type="password" name="db_password" id="db_password" value="" class="txt"/></li>
64 69
 						<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("9")?></li>						
70
+							<input type="password" name="db_password2" id="db_password2" value="" class="txt"/><?php echo $install->mostrarerror("9")?></li>
66 71
 						<li><label for="email">Database Host:</label>
67
-							<input type="text" name="db_host" id="db_host" value="<?php echo (!empty($install->data['db_host']))?  $install->data['db_host'] : 'localhost'?>" class="txt"/><?php echo $install->mostrarerror("7")?></li>	
72
+							<input type="text" name="db_host" id="db_host" value="<?php echo (!empty($install->data['db_host']))?  $install->data['db_host'] : 'localhost'?>" class="txt"/><?php echo $install->mostrarerror("7")?></li>
68 73
 						<li><label for="email">Database Name:</label>
69
-							<input type="text" name="db_name" id="db_name" value="<?php echo (!empty($install->data['db_name']))?  $install->data['db_name'] : 'gelatocms'?>" class="txt"/><?php echo $install->mostrarerror("8")?></li>											
74
+							<input type="text" name="db_name" id="db_name" value="<?php echo (!empty($install->data['db_name']))?  $install->data['db_name'] : 'gelatocms'?>" class="txt"/><?php echo $install->mostrarerror("8")?></li>
70 75
 					</ul>
71 76
 				</fieldset><br  />
72 77
 				<fieldset class="install">
@@ -77,14 +82,14 @@ $install->check_form();
77 82
 						<li><label for="password">Password:</label>
78 83
 							<input type="password" name="password" id="password" value="" class="txt"/><?php echo $install->mostrarerror("2")?></li>
79 84
 						<li><label for="password2">Re-type password:</label>
80
-							<input type="password" name="password2" id="password2" value="" class="txt"/><?php echo $install->mostrarerror("3")?></li>						
85
+							<input type="password" name="password2" id="password2" value="" class="txt"/><?php echo $install->mostrarerror("3")?></li>
81 86
 						<li><label for="email">E-mail:</label>
82
-							<input type="text" name="email" id="email" value="<?php echo $install->data['email']?>" class="txt"/><?php echo $install->mostrarerror("4")?></li>						
87
+							<input type="text" name="email" id="email" value="<?php echo $install->data['email']?>" class="txt"/><?php echo $install->mostrarerror("4")?></li>
83 88
 					</ul>
84 89
 				</fieldset><br  />
85 90
 				<fieldset class="install">
86 91
 					<legend class="install">Tumblelog configuration</legend>
87
-					<ul>							
92
+					<ul>
88 93
 						<li><label for="title">Title:</label>
89 94
 							<input type="text" name="title" id="title" value="<?php echo $install->data['title']?>" class="txt"/></li>
90 95
 						<li><label for="description">Description:</label>
@@ -102,9 +107,9 @@ $install->check_form();
102 107
 							<select id="template" name="template">
103 108
 <?php
104 109
 							$themes = getThemes();
105
-							foreach ($themes as $theme) {									
110
+							foreach ($themes as $theme) {
106 111
 								echo "<option value=\"".$theme."\" selected=\"true\">".$theme."</option>\n";
107
-								
112
+
108 113
 							}
109 114
 ?>							</select>
110 115
 						<li>
@@ -175,17 +180,17 @@ $install->check_form();
175 180
 						</li>
176 181
 					</ul>
177 182
 				</fieldset>
178
-				<p>	
183
+				<p>
179 184
 					<input type="hidden" name="website" id="website" value="" />
180 185
 					<input type="hidden" name="about" id="about" value="" />
181 186
 					<input type="hidden" name="action" id="action" value="config" />
182 187
 					<input type="submit" name="btnsubmit" id="btnsubmit" value="<< Install >>" class="submit"/>
183 188
 				</p>
184
-			</form>		
189
+			</form>
185 190
 		</div>
186 191
 		<div class="footer-box">&nbsp;</div>
187 192
 	</div>
188
-	
193
+
189 194
 <?php
190 195
 	} else {
191 196
 		echo "<p><em>Finished!</em></p>";
@@ -197,7 +202,7 @@ $install->check_form();
197 202
 	<div id="foot">
198 203
 		<a href="http://www.gelatocms.com/" title="gelato CMS">gelato CMS</a> :: PHP/MySQL Tumblelog Content Management System.
199 204
 	</div>
200
-	
205
+
201 206
 </div>
202 207
 </body>
203 208
 </html>