A tumblelog CMS built on AJAX, PHP and MySQL.

install.class.php 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. if(!defined('entry') || !entry) die('Not a valid page');
  3. require(Absolute_Path.'/classes/mysql_connection.class.php');
  4. class Install {
  5. var $data = null;
  6. var $errors = null;
  7. var $showForm;
  8. var $errors_d = array();
  9. function Install(){
  10. $this->errors_d[1]='The login field cannot be empty';
  11. $this->errors_d[2]='The password field cannot be empty';
  12. $this->errors_d[3]='Password does not match the confirm password';
  13. $this->errors_d[4]='The e-mail field cannot be empty';
  14. $this->errors_d[5]='The installation URL field cannot be empty';
  15. $this->errors_d[6]='Error establishing a database connection';
  16. $this->errors_d[9]='For security reasons this field is required. It is the same information that in the config.php file';
  17. $this->errors_d[10]='The login field cannot be empty';
  18. }
  19. function run() {
  20. if (empty($this->data)) false;
  21. $this->create_db();
  22. if (!$this->install_db()) return false;
  23. return true;
  24. }
  25. function create_db(){
  26. $link = mysql_connect(DB_Server, DB_User, DB_Password);
  27. if(!$link)
  28. die('Could not connect: '.mysql_error());
  29. $sql = 'CREATE DATABASE '.DB_name;
  30. if(!mysql_query($sql, $link)){
  31. $link = mysql_close($link);
  32. return false;
  33. }
  34. return true;
  35. }
  36. function install_db(){
  37. require_once(Absolute_Path.'config.php');
  38. $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
  39. $sqlStr = array();
  40. $sqlStr[] = "CREATE TABLE `".Table_prefix."data` (
  41. `id_post` int(11) NOT NULL auto_increment,
  42. `title` text NULL,
  43. `url` varchar(250) default NULL,
  44. `description` text NULL,
  45. `type` tinyint(4) NOT NULL default '1',
  46. `date` datetime NOT NULL,
  47. `id_user` int(10) NOT NULL,
  48. PRIMARY KEY (`id_post`)
  49. ) ENGINE = MYISAM ;";
  50. $sqlStr[] = "CREATE TABLE `".Table_prefix."users` (
  51. `id_user` int(10) unsigned NOT NULL auto_increment,
  52. `name` varchar(100) default NULL,
  53. `login` varchar(100) NOT NULL default '',
  54. `password` varchar(64) NOT NULL default '',
  55. `email` varchar(100) default NULL,
  56. `website` varchar(150) default NULL,
  57. `about` text,
  58. PRIMARY KEY (`id_user`)
  59. ) ENGINE = MYISAM;";
  60. $sqlStr[] = "CREATE TABLE `".Table_prefix."config` (
  61. `posts_limit` int(3) NOT NULL,
  62. `title` varchar(250) NOT NULL,
  63. `description` text NOT NULL,
  64. `lang` varchar(10) NOT NULL,
  65. `template` varchar(100) NOT NULL,
  66. `url_installation` varchar(250) NOT NULL,
  67. PRIMARY KEY (`title`)
  68. ) ENGINE = MYISAM ;";
  69. $sqlStr[] = "CREATE TABLE `".Table_prefix."options` (
  70. `name` varchar(100) NOT NULL,
  71. `val` varchar(255) NOT NULL,
  72. PRIMARY KEY (`name`)
  73. ) ENGINE = MYISAM ;";
  74. $sqlStr[] = "CREATE TABLE `".Table_prefix."comments` (
  75. `id_comment` int(11) NOT NULL auto_increment,
  76. `id_post` int(11) NOT NULL,
  77. `username` varchar(50) NOT NULL,
  78. `email` varchar(100) NOT NULL,
  79. `web` varchar(250) default NULL,
  80. `content` text NOT NULL,
  81. `ip_user` varchar(50) NOT NULL,
  82. `comment_date` datetime NOT NULL,
  83. `spam` tinyint(4) NOT NULL,
  84. PRIMARY KEY (`id_comment`)
  85. ) ENGINE = MYISAM ;";
  86. $sqlStr[] = "CREATE TABLE `".Table_prefix."feeds` (
  87. `id_feed` int(11) NOT NULL auto_increment,
  88. `url` varchar(255) NOT NULL,
  89. `title` varchar(255) NOT NULL,
  90. `type` tinyint(4) NOT NULL default '1',
  91. `updated_at` datetime NOT NULL,
  92. `error` tinyint(1) NOT NULL default '0',
  93. `credits` int(1) NOT NULL default '0',
  94. `site_url` varchar(255) NOT NULL,
  95. `id_user` int(10) NOT NULL,
  96. PRIMARY KEY (`id_feed`)
  97. ) ENGINE=MyISAM ;";
  98. $sqlStr[] = "INSERT INTO `".Table_prefix."config` VALUES (". $db->sql_escape($this->data['posts_limit']).", '".$db->sql_escape($this->data['title'])."', '".$db->sql_escape($this->data['description'])."', '".$db->sql_escape($this->data['lang'])."', '".$db->sql_escape($this->data['template'])."', '".$db->sql_escape($this->data['url_installation'])."');";
  99. $sqlStr[] = "INSERT INTO `".Table_prefix."users` VALUES ('', '', '".$db->sql_escape($this->data['login'])."', '".md5($this->data['password'])."', '".$db->sql_escape($this->data['email'])."', '".$db->sql_escape($this->data['website'])."', '".$db->sql_escape($this->data['about'])."');";
  100. $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('url_friendly', '0');";
  101. $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('rich_text', '0');";
  102. $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('allow_comments', '0');";
  103. $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('offset_city', '".$db->sql_escape($this->data['offset_city'])."');";
  104. $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('offset_time', '".$db->sql_escape($this->data['offset_time'])."');";
  105. $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('shorten_links', '0');";
  106. $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('rss_import_frec', '5 minutes');";
  107. $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('check_version', '1');";
  108. $sqlStr[] = "INSERT INTO `".Table_prefix."options` VALUES ('active_plugins', '[{\"total\":0},[]]');";
  109. foreach($sqlStr as $key => $query){
  110. if(!$db->ejecutarConsulta($query)){
  111. return false;
  112. }
  113. }
  114. return true;
  115. }
  116. function inerrors($n) {
  117. if(strpos($this->errors,(string)$n)===false)
  118. return false;
  119. return true;
  120. }
  121. function mostrarerror($n) {
  122. if ($this->inerrors($n)) {
  123. return '<span class="error">'.$this->errors_d[$n].'</span>';
  124. } else {
  125. return "";
  126. }
  127. }
  128. function is_gelato_installed(){
  129. if(file_exists(Absolute_Path.'config.php')) {
  130. include_once(Absolute_Path."config.php");
  131. if (!$this->check_for_config()){
  132. return false;
  133. } else {
  134. if (!$this->is_db_installed()){
  135. return false;
  136. }
  137. }
  138. return true;
  139. }else{
  140. return false;
  141. }
  142. }
  143. function is_db_installed(){
  144. $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
  145. $sqlStr = "SELECT * FROM `".Table_prefix."config`";
  146. if($db->ejecutarConsulta($sqlStr)) {
  147. return ($db->contarRegistros() > 0);
  148. }else{
  149. return false;
  150. }
  151. }
  152. function check_for_config(){
  153. if(!defined('DB_Server')) return false;
  154. if(!defined('DB_name')) return false;
  155. if(!defined('DB_User')) return false;
  156. if(!defined('DB_Password')) return false;
  157. return true;
  158. }
  159. function check_form(){
  160. $action="";
  161. if (isset($this->data['action'])){
  162. $action=$this->data['action'];
  163. }
  164. if (!$this->is_gelato_installed()){
  165. $this->showForm = true;
  166. if ($action=="config") {
  167. $sep_err="";
  168. $this->errors = false;
  169. if (!isset($this->data['db_login']) or $this->data['db_login']!=DB_User) {
  170. $this->errors =$this->errors.$sep_err."9"; //7,8
  171. $sep_err="|";
  172. }
  173. if (!$this->data['login']) {
  174. $this->errors =$this->errors.$sep_err."1";
  175. $sep_err="|";
  176. }
  177. if (!$this->data['password']) {
  178. $this->errors=$this->errors.$sep_err."2";
  179. $sep_err="|";
  180. }
  181. if (!$this->data['email']) {
  182. $this->errors=$this->errors.$sep_err."4";
  183. $sep_err="|";
  184. }
  185. if (!$this->data['url_installation'] ) {
  186. $this->errors=$this->errors.$sep_err."5";
  187. $sep_err="|";
  188. }
  189. if ($this->data['password']!=$_POST['password2']) {
  190. $this->errors=$this->errors.$sep_err."3";
  191. $sep_err="|";
  192. }
  193. $off_r= split("," , $this->data['time_offsets']);
  194. $this->data['offset_time'] = $off_r[0];
  195. $this->data['offset_city'] = $off_r[1];
  196. unset($this->data['time_offsets']);
  197. if(!$this->errors){
  198. if($this->run($this->data))
  199. $this->showForm=false;
  200. else{
  201. $this->errors=$this->errors.$sep_err."6";
  202. $sep_err="|";
  203. $this->showForm=true;
  204. }
  205. }else
  206. $this->showForm=true;
  207. }
  208. }
  209. }
  210. }
  211. ?>