diff --git a/classes/install.class.php b/classes/install.class.php
index 6e4cb80..79dfb97 100644
--- a/classes/install.class.php
+++ b/classes/install.class.php
@@ -1,13 +1,13 @@
errors_d[1]="The login field cannot be empty";
$this->errors_d[2]="The password field cannot be empty";
@@ -20,41 +20,39 @@ class Install {
$this->errors_d[9]="Password does not match the confirm password";
$this->errors_d[10]="The login field cannot be empty";
}
-
+
function run() {
-
+
if (empty($this->data)) false;
-
- if (!$this->create_config()) return false;
-
+
$this->create_db();
-
+
if (!$this->install_db()) return false;
-
+
return true;
}
-
+
function create_db(){
-
+
$link = mysql_connect($this->data['db_host'], $this->data['db_login'], $this->data['db_password']);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
-
+
$sql = 'CREATE DATABASE ' . $this->data['db_name'];
if (!mysql_query($sql, $link)) {
$link = mysql_close($link);
return false;
- }
-
- return true;
+ }
+
+ return true;
}
-
+
function install_db(){
require('config.php');
- $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
+ $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
$sqlStr = array();
-
+
$sqlStr[] = "CREATE TABLE `".Table_prefix."data` (
`id_post` int(11) NOT NULL auto_increment,
`title` text NULL,
@@ -86,16 +84,16 @@ class Install {
`url_installation` varchar(250) NOT NULL,
PRIMARY KEY (`title`)
) ENGINE = MYISAM ;";
-
-
+
+
$sqlStr[] = "CREATE TABLE `".Table_prefix."options` (
`name` varchar(100) NOT NULL,
`val` varchar(255) NOT NULL,
PRIMARY KEY (`name`)
) ENGINE = MYISAM ;";
-
+
$sqlStr[] = "CREATE TABLE `".Table_prefix."comments` (
`id_comment` int(11) NOT NULL auto_increment,
`id_post` int(11) NOT NULL,
@@ -108,7 +106,7 @@ class Install {
`spam` tinyint(4) NOT NULL,
PRIMARY KEY (`id_comment`)
) ENGINE = MYISAM ;";
-
+
$sqlStr[] = "CREATE TABLE `".Table_prefix."feeds` (
`id_feed` int(11) NOT NULL auto_increment,
`url` varchar(255) NOT NULL,
@@ -122,13 +120,13 @@ class Install {
PRIMARY KEY (`id_feed`)
) ENGINE=MyISAM ;";
-
- $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']."');";
+
+ $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']."');";
$sqlStr[] = "INSERT INTO `".Table_prefix."users` VALUES ('', '', '".$this->data['login']."', '".md5($this->data['password'])."', '".$this->data['email']."', '".$this->data['website']."', '".$this->data['about']."');";
$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('url_friendly', '0');";
- $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('rich_text', '0');";
+ $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('rich_text', '0');";
$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('allow_comments', '0');";
- $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('offset_city', '".$this->data['offset_city']."');";
+ $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('offset_city', '".$this->data['offset_city']."');";
$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('offset_time', '".$this->data['offset_time']."');";
$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('shorten_links', '0');";
$sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('rss_import_frec', '5 minutes');";
@@ -141,7 +139,7 @@ class Install {
return true;
}
-
+
function inerrors($n) {
if ( strpos($this->errors,$n)===false) {
return false;
@@ -149,7 +147,7 @@ class Install {
return true;
}
}
-
+
function mostrarerror($n) {
if ($this->inerrors($n)) {
return ''.$this->errors_d[$n].'';
@@ -157,12 +155,12 @@ class Install {
return "";
}
}
-
+
function is_gelato_installed(){
- if(file_exists('config.php')) {
- @include("config.php");
- if (!$this->check_for_config()){
- return false;
+ if(file_exists(Absolute_Path.'config.php')) {
+ @include(Absolute_Path."config.php");
+ if (!$this->check_for_config()){
+ return false;
} else {
if (!$this->is_db_installed()){
return false;
@@ -173,18 +171,18 @@ class Install {
return false;
}
}
-
+
function is_db_installed(){
- $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
+ $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
$sqlStr = "SELECT * FROM `".Table_prefix."config`";
if($db->ejecutarConsulta($sqlStr)) {
return ($db->contarRegistros() > 0);
}else{
return false;
}
-
+
}
-
+
function check_for_config(){
if(!defined('DB_Server')) return false;
if(!defined('DB_name')) return false;
@@ -192,57 +190,24 @@ class Install {
if(!defined('DB_Password')) return false;
return true;
}
-
- function create_config(){
- $config = fopen("config.php", 'w+');
- $contents = '
-
- =========================== */
-
-define(\'DB_Server\', \''. $this->data['db_host'] . '\');
-define(\'DB_name\', \''. $this->data['db_name'] . '\');
-define(\'DB_User\', \''. $this->data['db_login'] . '\');
-define(\'DB_Password\', \''. $this->data['db_password'] . '\');
-define(\'Table_prefix\', \'gel_\');
-define(\'Absolute_Path\', dirname(__FILE__).DIRECTORY_SEPARATOR);
-
-?>';
-
- if (fwrite($config, $contents) === FALSE) {
- $this->errors = "Could not write config file to directory";
- return false;
- }
- fclose($config);
- return true;
- }
-
function check_form(){
$action="";
-
+
if (isset($this->data['action'])){
$action=$this->data['action'];
}
-
+
if (!$this->is_gelato_installed()){
-
+
$this->showForm = true;
-
-
+
if ($action=="config") {
-
+
$sep_err="";
$this->errors = false;
-
+
if (!$this->data['login']) {
$this->errors =$this->errors.$sep_err."1";
$sep_err="|";
@@ -274,31 +239,31 @@ define(\'Absolute_Path\', dirname(__FILE__).DIRECTORY_SEPARATOR);
if ($this->data['password']!=$_POST['password2']) {
$this->errors=$this->errors.$sep_err."3";
$sep_err="|";
- }
+ }
if ( $_POST['db_password']!=$_POST['db_password2']) {
$this->errors=$this->errors.$sep_err."9";
$sep_err="|";
- }
-
+ }
+
$off_r= split("," , $this->data['time_offsets']);
$this->data['offset_time'] = $off_r[0];
$this->data['offset_city'] = $off_r[1];
unset($this->data['time_offsets']);
-
+
if (!$this->errors) {
-
+
if ($this->run($this->data)) {
$this->showForm=false;
} else {
$this->errors=$this->errors.$sep_err."6";
$sep_err="|";
$this->showForm=true;
- }
+ }
} else {
$this->showForm=true;
}
}
- }
- }
+ }
+ }
}
?>
\ No newline at end of file
diff --git a/classes/mysql_connection.class.php b/classes/mysql_connection.class.php
index 9def573..f94efa6 100644
--- a/classes/mysql_connection.class.php
+++ b/classes/mysql_connection.class.php
@@ -15,26 +15,26 @@
// constantes
define('MYSQL_TYPES_NUMERIC', 'int real ');
define('MYSQL_TYPES_DATE', 'datetime timestamp year date time ');
-define('MYSQL_TYPES_STRING', 'string blob ');
+define('MYSQL_TYPES_STRING', 'string blob ');
class Conexion_Mysql {
- var $mbase_datos;
- var $mservidor;
- var $musuario;
- var $mclave;
- var $mid_conexion = 0; // Identificador de conexión
+ var $mbase_datos;
+ var $mservidor;
+ var $musuario;
+ var $mclave;
+ var $mid_conexion = 0; // Identificador de conexi�n
var $mid_consulta = 0; // Identificador de consulta
- var $merror_numero = 0; // Número de error
- var $merror = ""; // Descripción del error.
-
- /** Al crear una instancia de clase, se ejecutará esta función */
- function Conexion_Mysql($bd="", $host="localhost", $user="", $pass="") {
- $this->mbase_datos = $bd;
- $this->mservidor = $host;
- $this->musuario = $user;
+ var $merror_numero = 0; // N�mero de error
+ var $merror = ""; // Descripci�n del error.
+
+ /** Al crear una instancia de clase, se ejecutara esta funcion */
+ function Conexion_Mysql($bd="", $host="localhost", $user="", $pass="") {
+ $this->mbase_datos = $bd;
+ $this->mservidor = $host;
+ $this->musuario = $user;
$this->mclave = $pass;
-
+
if (!$this->conectar()) {
$mensaje = "
Error establishing a database connection
@@ -44,42 +44,42 @@ class Conexion_Mysql {
Are you sure that you have typed the correct hostname?
Are you sure that the database server is running?
";
- die($mensaje);
+ die($mensaje);
}
}
-
- /** Conectar a la base de datos */
- function conectar() {
- // Conectamos al servidor
- $this->mid_conexion = @mysql_connect($this->mservidor, $this->musuario, $this->mclave);
- if (!$this->mid_conexion) {
- $this->merror = "No se logró realizar la conexión.";
+
+ /** Conectar a la base de datos */
+ function conectar() {
+ // Conectamos al servidor
+ $this->mid_conexion = @mysql_connect($this->mservidor, $this->musuario, $this->mclave);
+ if (!$this->mid_conexion) {
+ $this->merror = "No se logr� realizar la conexi�n.";
return false;
- }
- //seleccionamos la base de datos
- if (!@mysql_select_db($this->mbase_datos, $this->mid_conexion)) {
- $this->merror = "No se puede abrir la base ".$this->mbase_datos ;
- return false;
- }
- return $this->mid_conexion; // Si todo salio bien regresa el id de la conexión
- }
-
- /** Para ejecutar consultas en la conexión abierta */
+ }
+ //seleccionamos la base de datos
+ if (!@mysql_select_db($this->mbase_datos, $this->mid_conexion)) {
+ $this->merror = "No se puede abrir la base ".$this->mbase_datos ;
+ return false;
+ }
+ return $this->mid_conexion; // Si todo salio bien regresa el id de la conexi�n
+ }
+
+ /** Para ejecutar consultas en la conexi�n abierta */
function ejecutarConsulta($msql = "") {
- if ($msql == "") {
- $this->merror = "No introdujo la sentencia SQL";
- return false;
- }
- //ejecutamos la consulta
- $this->mid_consulta = mysql_query($msql, $this->mid_conexion);
- if (!$this->mid_consulta) {
- $this->merror_numero = mysql_errno();
+ if ($msql == "") {
+ $this->merror = "No introdujo la sentencia SQL";
+ return false;
+ }
+ //ejecutamos la consulta
+ $this->mid_consulta = mysql_query($msql, $this->mid_conexion);
+ if (!$this->mid_consulta) {
+ $this->merror_numero = mysql_errno();
$this->merror = mysql_error()." error";
- return false;
- }
- return $this->mid_consulta; // Si todo salio bien regresa el id de la consulta
- }
-
+ return false;
+ }
+ return $this->mid_consulta; // Si todo salio bien regresa el id de la consulta
+ }
+
/**
* Inserta un registro en la DB por cada llave->valor en un arreglo.
* No se debe usar sentencias SQL con esta funcion.
@@ -90,26 +90,26 @@ class Conexion_Mysql {
* @return string El ID del insert, verdadero si la tabla no tiene un campo auto_increment o false si ocurre un error.
*/
function insertarDeFormulario($tabla, $datos) {
-
+
if (empty($datos)) {
$this->merror = "Debes de pasar un arreglo como parametro.";
return false;
}
-
+
$cols = '(';
$sqlValues = '(';
-
+
foreach ($datos as $llave=>$valor) {
-
- $cols .= "$llave,";
-
+
+ $cols .= "$llave,";
+
$tipo_col = $this->obtenerTipoCampo($tabla, $llave); // obtiene el tipo de campo
if (!$tipo_col) return false; // error!
-
+
// determina si se necesita poner comillas al valor.
if (is_null($valor)) {
- $sqlValues .= "NULL,";
- }
+ $sqlValues .= "NULL,";
+ }
elseif (substr_count(MYSQL_TYPES_NUMERIC, "$tipo_col ")) {
$sqlValues .= "$valor,";
}
@@ -119,17 +119,17 @@ class Conexion_Mysql {
}
elseif (substr_count(MYSQL_TYPES_STRING, "$tipo_col ")) {
$valor = $this->sql_escape($valor);
- $sqlValues .= "'$valor',";
+ $sqlValues .= "'$valor',";
}
}
$cols = rtrim($cols, ',').')';
- $sqlValues = rtrim($sqlValues, ',').')';
-
- // inserta los valores en la DB
+ $sqlValues = rtrim($sqlValues, ',').')';
+
+ // inserta los valores en la DB
$sql = "INSERT INTO $tabla $cols VALUES $sqlValues";
- return $this->ejecutarConsulta($sql);
+ return $this->ejecutarConsulta($sql);
}
-
+
/**
* Modifica un registro en la DB por cada llave->valor en un arreglo.
* No se debe usar sentencias SQL con esta funcion.
@@ -143,7 +143,7 @@ class Conexion_Mysql {
* Falso si ocurrio algun error.
*/
function modificarDeFormulario($tabla, $datos, $condicion="") {
-
+
if (empty($datos)) {
$this->merror = "Debes de pasar un arreglo como parametro.";
return false;
@@ -152,14 +152,14 @@ class Conexion_Mysql {
$sql = "UPDATE $tabla SET";
foreach ($datos as $llave=>$valor) {
$sql .= " $llave=";
-
+
$tipo_col = $this->obtenerTipoCampo($tabla, $llave); // obtiene el tipo de campo
if (!$tipo_col) return false; // error!
-
+
// determina si se necesita poner comillas al valor.
if (is_null($valor)) {
- $sql .= "NULL,";
- }
+ $sql .= "NULL,";
+ }
elseif (substr_count(MYSQL_TYPES_NUMERIC, "$tipo_col ")) {
$sql .= "$valor,";
}
@@ -169,25 +169,25 @@ class Conexion_Mysql {
}
elseif (substr_count(MYSQL_TYPES_STRING, "$tipo_col ")) {
$valor = $this->sql_escape($valor);
- $sql .= "'$valor',";
- }
+ $sql .= "'$valor',";
+ }
}
$sql = rtrim($sql, ','); // elimina la ultima coma
if (!empty($condicion)) $sql .= " WHERE $condicion";
-
+
// modifica los valores
return $this->ejecutarConsulta($sql);
}
-
+
/**
- * Obtiene la informacion sobre un campo usando la funcion mysql_fetch_field.
+ * Obtiene la informacion sobre un campo usando la funcion mysql_fetch_field.
*
* @param mixed $tabla El nombre de la tabla en la BD.
* @param string $campo El campo del que se desea la informacion.
* @return array Un arreglo con la informacion del campo o false si hay algun error.
*/
function obtenerTipoCampo($tabla, $campo) {
-
+
$r = mysql_query("SELECT $campo FROM $tabla");
if (!$r) {
$this->merror = mysql_error();
@@ -200,9 +200,9 @@ class Conexion_Mysql {
return false;
}
mysql_free_result($r);
- return $ret;
+ return $ret;
}
-
+
/**
* Convierte una fecha en formato para DB.
*
@@ -214,7 +214,7 @@ class Conexion_Mysql {
if(eregi("^([0-9]+)$",$valor)){
$valor = date("Y-m-d H:i:s",$valor);
}else{
- // Estariá en el formato strtotime()
+ // Estari� en el formato strtotime()
$valor = date("Y-m-d H:i:s",strtotime($valor));
}
}
@@ -222,56 +222,56 @@ class Conexion_Mysql {
/* if (gettype($valor) == 'string') $valor = strtotime($valor);
return date('Y-m-d H:i:s', $valor);
*/
- }
+ }
/**
* Obtiene el registro obtenido de una consulta.
*/
- function obtenerRegistro() {
- return mysql_fetch_assoc($this->mid_consulta);
- }
-
+ function obtenerRegistro() {
+ return mysql_fetch_assoc($this->mid_consulta);
+ }
+
/**
- * Devuelve el número de campos de una consulta.
+ * Devuelve el n�mero de campos de una consulta.
*/
- function contarCampos() {
- return mysql_num_fields($this->mid_consulta);
- }
-
+ function contarCampos() {
+ return mysql_num_fields($this->mid_consulta);
+ }
+
/**
- * Devuelve el número de registros de una consulta.
+ * Devuelve el n�mero de registros de una consulta.
*/
- function contarRegistros() {
- return @mysql_num_rows($this->mid_consulta);
- }
-
+ function contarRegistros() {
+ return @mysql_num_rows($this->mid_consulta);
+ }
+
/**
* Devuelve el nombre de un campo de una consulta.
*/
- function obtenerNombreCampo($numero_campo) {
- return mysql_field_name($this->mid_consulta, $numero_campo);
- }
-
+ function obtenerNombreCampo($numero_campo) {
+ return mysql_field_name($this->mid_consulta, $numero_campo);
+ }
+
/**
* Muestra los datos de una consulta (para debug).
*/
function verConsulta() {
- echo "
\n";
- // mostramos los nombres de los campos
- for ($i = 0; $i < $this->contarCampos(); $i++) {
- echo "
".$this->obtenerNombreCampo($i)."
\n";
- }
- echo "\n";
+ echo "
\n";
+ // mostramos los nombres de los campos
+ for ($i = 0; $i < $this->contarCampos(); $i++) {
+ echo "
".$this->obtenerNombreCampo($i)."
\n";
+ }
+ echo "\n";
// mostrarmos los registros
- while ($row = mysql_fetch_row($this->mid_consulta)) {
- echo "