A tumblelog CMS built on AJAX, PHP and MySQL.

install.php 9.2KB

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