A tumblelog CMS built on AJAX, PHP and MySQL.

install.php 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <?php
  2. /* ===========================
  3. gelato CMS - A PHP based tumblelog CMS
  4. development version
  5. http://www.gelatocms.com/
  6. gelato CMS is a free software licensed under GPL (General public license)
  7. =========================== */
  8. ?>
  9. <?php
  10. $configFile = dirname(__FILE__).DIRECTORY_SEPARATOR."config.php";
  11. if (!file_exists($configFile)) {
  12. $mensaje = "
  13. <h3 class=\"important\">Error reading configuration file</h3>
  14. <p>There doesn't seem to be a <code>config.php</code> file. I need this before we can get started.</p>
  15. <p>This either means that you did not rename the <code>config-sample.php</code> file to <code>config.php</code>.</p>";
  16. die($mensaje);
  17. } else {
  18. require(dirname(__FILE__).DIRECTORY_SEPARATOR."config.php");
  19. $showForm = true;
  20. }
  21. include("classes/functions.php");
  22. $errors_d=array();
  23. $errors_d[1]="The login field cannot be empty";
  24. $errors_d[2]="The password field cannot be empty";
  25. $errors_d[3]="Password does not match the confirm password";
  26. $errors_d[4]="The e-mail field cannot be empty";
  27. $errors_d[5]="The installation URL field cannot be empty";
  28. $errors_d[6]="Error establishing a database connection";
  29. $action="";
  30. $errors="";
  31. if (isset($_POST['action'])){
  32. $action=$_POST['action'];
  33. }
  34. if ($action=="config") {
  35. $sep_err="";
  36. if (!$_POST['login']) {
  37. $errors=$errors.$sep_err."1";
  38. $sep_err="|";
  39. }
  40. if (!$_POST['password']) {
  41. $errors=$errors.$sep_err."2";
  42. $sep_err="|";
  43. }
  44. if (!$_POST['email']) {
  45. $errors=$errors.$sep_err."4";
  46. $sep_err="|";
  47. }
  48. if (!$_POST['url_installation']) {
  49. $errors=$errors.$sep_err."5";
  50. $sep_err="|";
  51. }
  52. if ($_POST['password']!=$_POST['password2']) {
  53. $errors=$errors.$sep_err."3";
  54. $sep_err="|";
  55. }
  56. if (!$errors) {
  57. 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'])) {
  58. $showForm=false;
  59. } else {
  60. $errors=$errors.$sep_err."6";
  61. $sep_err="|";
  62. $showForm=true;
  63. }
  64. } else {
  65. $showForm=true;
  66. }
  67. }
  68. ?>
  69. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  70. <html xmlns="http://www.w3.org/1999/xhtml">
  71. <head>
  72. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  73. <meta name="generator" content="gelato cms <?php echo version();?>" />
  74. <title>gelato :: installation</title>
  75. <link rel="shortcut icon" href="images/favicon.ico" />
  76. <style type="text/css" media="screen">
  77. @import "admin/css/style.css";
  78. </style>
  79. </head>
  80. <body>
  81. <div id="cont">
  82. <div id="head">
  83. <h1><a href="index.php" title="gelato :: home">gelato cms</a></h1>
  84. </div>
  85. <div id="main">
  86. <?
  87. if ($showForm) {
  88. ?>
  89. <div class="box">
  90. <ul class="menu manage">
  91. <h3>gelato :: installation</h3>
  92. <li class="selected"><a>Install</a></li>
  93. </ul>
  94. <div class="tabla">
  95. <form action="install.php" method="post" id="config_form" autocomplete="off" class="newpost">
  96. <fieldset>
  97. <legend class="install">Admin user</legend>
  98. <ul>
  99. <li><label for="login">User:</label>
  100. <input type="text" name="login" id="login" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"1")?></li>
  101. <li><label for="password">Password:</label>
  102. <input type="password" name="password" id="password" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"2")?></li>
  103. <li><label for="password2">Re-type password:</label>
  104. <input type="password" name="password2" id="password2" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"3")?></li>
  105. <li><label for="email">E-mail:</label>
  106. <input type="text" name="email" id="email" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"4")?></li>
  107. </ul>
  108. </fieldset><br />
  109. <fieldset>
  110. <legend class="install">Tumblelog configuration</legend>
  111. <ul>
  112. <li><label for="title">Title:</label>
  113. <input type="text" name="title" id="title" value="" class="txt"/></li>
  114. <li><label for="description">Description:</label>
  115. <input type="text" name="description" id="description" value="" class="txt"/></li>
  116. <li><label for="url_installation">Installation URL</label>
  117. <input type="text" name="url_installation" id="url_installation" value="" class="txt"/><?php echo mostrarerror($errors,$errors_d,"5")?></li>
  118. <li><label for="posts_limit">Post limit:</label>
  119. <input type="text" name="posts_limit" id="posts_limit" value="10" class="txt"/></li>
  120. <li><label for="lang">Language:</label>
  121. <select id="lang" name="lang">
  122. <option value="en" selected="selected">english</option>
  123. </select>
  124. </li>
  125. <li><label for="template">Template:</label>
  126. <select id="template" name="template">
  127. <?php
  128. $themes = getThemes();
  129. foreach ($themes as $theme) {
  130. echo "<option value=\"".$theme."\" selected=\"true\">".$theme."</option>\n";
  131. }
  132. ?>
  133. </select>
  134. </li>
  135. </ul>
  136. </fieldset>
  137. <p>
  138. <input type="hidden" name="website" id="website" value="" />
  139. <input type="hidden" name="about" id="about" value="" />
  140. <input type="hidden" name="action" id="action" value="config" />
  141. <input type="submit" name="btnsubmit" id="btnsubmit" value="<< Install >>" class="submit"/>
  142. </p>
  143. </form>
  144. </div>
  145. <div class="footer-box">&nbsp;</div>
  146. </div>
  147. <?php
  148. } else {
  149. echo "<p><em>Finished!</em></p>";
  150. echo "<p>Now you can <a href=\"login.php\" class=\"inslnl\">log in</a> with your <strong>username</strong> and <strong>password</strong></p>";
  151. }
  152. ?>
  153. </div>
  154. <div id="foot">
  155. <a href="http://www.gelatocms.com/" title="gelato CMS">gelato CMS</a> :: PHP/MySQL Tumblelog Content Management System.
  156. </div>
  157. </div>
  158. </body>
  159. </html>
  160. <?php
  161. function install_db($login, $password, $email, $title, $description, $url_installation, $posts_limit, $lang, $template, $website, $about){
  162. $db = new Conexion_Mysql(DB_name, DB_Server, DB_User, DB_Password);
  163. $sqlStr = "CREATE TABLE `".Table_prefix."data` (
  164. `id_post` int(11) NOT NULL auto_increment,
  165. `title` text NULL,
  166. `url` varchar(250) default NULL,
  167. `description` text NULL,
  168. `type` tinyint(4) NOT NULL default '1',
  169. `date` datetime NOT NULL,
  170. `id_user` int(10) NOT NULL,
  171. PRIMARY KEY (`id_post`)
  172. ) ENGINE = MYISAM ;";
  173. $db->ejecutarConsulta($sqlStr);
  174. $sqlStr = "CREATE TABLE `".Table_prefix."users` (
  175. `id_user` int(10) unsigned NOT NULL auto_increment,
  176. `name` varchar(100) default NULL,
  177. `login` varchar(100) NOT NULL default '',
  178. `password` varchar(64) NOT NULL default '',
  179. `email` varchar(100) default NULL,
  180. `website` varchar(150) default NULL,
  181. `about` text,
  182. PRIMARY KEY (`id_user`)
  183. ) ENGINE = MYISAM;";
  184. $db->ejecutarConsulta($sqlStr);
  185. $sqlStr = "CREATE TABLE `".Table_prefix."config` (
  186. `posts_limit` int(3) NOT NULL,
  187. `title` varchar(250) NOT NULL,
  188. `description` text NOT NULL,
  189. `lang` varchar(10) NOT NULL,
  190. `template` varchar(100) NOT NULL,
  191. `url_installation` varchar(250) NOT NULL,
  192. PRIMARY KEY (`title`)
  193. ) ENGINE = MYISAM ;";
  194. $db->ejecutarConsulta($sqlStr);
  195. $sqlStr = "CREATE TABLE `".Table_prefix."options` (
  196. `name` varchar(100) NOT NULL,
  197. `val` varchar(255) NOT NULL,
  198. PRIMARY KEY (`name`)
  199. ) ENGINE = MYISAM ;";
  200. $db->ejecutarConsulta($sqlStr);
  201. $sqlStr = "CREATE TABLE `".Table_prefix."comments` (
  202. `id_comment` int(11) NOT NULL auto_increment,
  203. `id_post` int(11) NOT NULL,
  204. `username` varchar(50) NOT NULL,
  205. `email` varchar(100) NOT NULL,
  206. `web` varchar(250) default NULL,
  207. `content` text NOT NULL,
  208. `ip_user` varchar(50) NOT NULL,
  209. `comment_date` datetime NOT NULL,
  210. `spam` tinyint(4) NOT NULL,
  211. PRIMARY KEY (`id_comment`)
  212. ) ENGINE = MYISAM ;";
  213. $db->ejecutarConsulta($sqlStr);
  214. $url_installation = (endsWith($url_installation, "/")) ? substr($url_installation, 0, strlen($url_installation)-1) : $url_installation ;
  215. $sqlStr = "INSERT INTO `".Table_prefix."config` VALUES (".$posts_limit.", '".$title."', '".$description."', '".$lang."', '".$template."', '".$url_installation."');";
  216. $db->ejecutarConsulta($sqlStr);
  217. $sqlStr = "INSERT INTO `".Table_prefix."users` VALUES ('', '', '".$login."', '".md5($password)."', '".$email."', '".$website."', '".$about."');";
  218. $db->ejecutarConsulta($sqlStr);
  219. $sqlStr = "INSERT INTO `".Table_prefix."options` VALUES ('url_friendly', '1');";
  220. $db->ejecutarConsulta($sqlStr);
  221. $sqlStr = "INSERT INTO `".Table_prefix."options` VALUES ('rich_text', '0');";
  222. $db->ejecutarConsulta($sqlStr);
  223. return true;
  224. }
  225. function inerrors($errors,$n) {
  226. if (strpos($errors,$n)===false) {
  227. return false;
  228. } else {
  229. return true;
  230. }
  231. }
  232. function mostrarerror($errors,$errors_d,$n) {
  233. if (inerrors($errors,$n)) {
  234. return '<span class="error">'.$errors_d[$n].'</span>';
  235. } else {
  236. return "";
  237. }
  238. }
  239. ?>