install.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. <?php
  2. require('../constants.php');
  3. include(LIB_PATH . '/lib_rss.php');
  4. session_start ();
  5. if (isset ($_GET['step'])) {
  6. define ('STEP', $_GET['step']);
  7. } else {
  8. define ('STEP', 1);
  9. }
  10. define ('SQL_REQ_CREATE_DB', 'CREATE DATABASE %s DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
  11. define ('SQL_REQ_CAT', 'CREATE TABLE IF NOT EXISTS `%scategory` (
  12. `id` SMALLINT NOT NULL AUTO_INCREMENT, -- v0.7
  13. `name` varchar(255) NOT NULL,
  14. `color` char(7) NOT NULL,
  15. PRIMARY KEY (`id`),
  16. UNIQUE KEY (`name`) -- v0.7
  17. ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
  18. define ('SQL_REQ_FEED', 'CREATE TABLE IF NOT EXISTS `%sfeed` (
  19. `id` SMALLINT NOT NULL AUTO_INCREMENT, -- v0.7
  20. `url` varchar(511) CHARACTER SET latin1 NOT NULL,
  21. `category` SMALLINT DEFAULT 0, -- v0.7
  22. `name` varchar(255) NOT NULL,
  23. `website` varchar(255) CHARACTER SET latin1 NOT NULL,
  24. `description` text NOT NULL,
  25. `lastUpdate` int(11) NOT NULL,
  26. `priority` tinyint(2) NOT NULL DEFAULT 10,
  27. `pathEntries` varchar(511) DEFAULT NULL,
  28. `httpAuth` varchar(511) DEFAULT NULL,
  29. `error` boolean NOT NULL DEFAULT 0,
  30. `keep_history` boolean NOT NULL DEFAULT 0,
  31. `cache_nbEntries` int NOT NULL DEFAULT 0, -- v0.7
  32. `cache_nbUnreads` int NOT NULL DEFAULT 0, -- v0.7
  33. PRIMARY KEY (`id`),
  34. FOREIGN KEY (`category`) REFERENCES `%scategory`(`id`) ON DELETE SET NULL ON UPDATE CASCADE,
  35. UNIQUE KEY (`url`), -- v0.7
  36. INDEX (`name`), -- v0.7
  37. INDEX (`priority`), -- v0.7
  38. INDEX (`keep_history`) -- v0.7
  39. ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
  40. define ('SQL_REQ_ENTRY', 'CREATE TABLE IF NOT EXISTS `%sentry` (
  41. `id` bigint NOT NULL, -- v0.7
  42. `guid` varchar(760) CHARACTER SET latin1 NOT NULL, -- Maximum for UNIQUE is 767B
  43. `title` varchar(255) NOT NULL,
  44. `author` varchar(255) NOT NULL,
  45. `content` text NOT NULL,
  46. `link` varchar(1023) CHARACTER SET latin1 NOT NULL,
  47. `date` int(11) NOT NULL,
  48. `is_read` boolean NOT NULL DEFAULT 0,
  49. `is_favorite` boolean NOT NULL DEFAULT 0,
  50. `id_feed` SMALLINT NOT NULL, -- v0.7
  51. `tags` varchar(1023) NOT NULL,
  52. PRIMARY KEY (`id`),
  53. FOREIGN KEY (`id_feed`) REFERENCES `%sfeed`(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  54. UNIQUE KEY (`id_feed`,`guid`), -- v0.7
  55. INDEX (`is_favorite`), -- v0.7
  56. INDEX (`is_read`) -- v0.7
  57. ) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;');
  58. function writeLine ($f, $line) {
  59. fwrite ($f, $line . "\n");
  60. }
  61. function writeArray ($f, $array) {
  62. foreach ($array as $key => $val) {
  63. if (is_array ($val)) {
  64. writeLine ($f, '\'' . $key . '\' => array (');
  65. writeArray ($f, $val);
  66. writeLine ($f, '),');
  67. } else {
  68. writeLine ($f, '\'' . $key . '\' => \'' . $val . '\',');
  69. }
  70. }
  71. }
  72. // gestion internationalisation
  73. $translates = array ();
  74. $actual = 'en';
  75. function initTranslate () {
  76. global $translates;
  77. global $actual;
  78. $l = getBetterLanguage ('en');
  79. if (isset ($_SESSION['language'])) {
  80. $l = $_SESSION['language'];
  81. }
  82. $actual = $l;
  83. $file = APP_PATH . '/i18n/' . $actual . '.php';
  84. if (file_exists ($file)) {
  85. $translates = include ($file);
  86. }
  87. }
  88. function getBetterLanguage ($fallback) {
  89. $available = availableLanguages ();
  90. $accept = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  91. $language = strtolower (substr ($accept, 0, 2));
  92. if (isset ($available[$language])) {
  93. return $language;
  94. } else {
  95. return $fallback;
  96. }
  97. }
  98. function availableLanguages () {
  99. return array (
  100. 'en' => 'English',
  101. 'fr' => 'Français'
  102. );
  103. }
  104. function _t ($key) {
  105. global $translates;
  106. $translate = $key;
  107. if (isset ($translates[$key])) {
  108. $translate = $translates[$key];
  109. }
  110. $args = func_get_args ();
  111. unset($args[0]);
  112. return vsprintf ($translate, $args);
  113. }
  114. /*** SAUVEGARDES ***/
  115. function saveLanguage () {
  116. if (!empty ($_POST)) {
  117. if (!isset ($_POST['language'])) {
  118. return false;
  119. }
  120. $_SESSION['language'] = $_POST['language'];
  121. header ('Location: index.php?step=1');
  122. }
  123. }
  124. function saveStep2 () {
  125. if (!empty ($_POST)) {
  126. if (empty ($_POST['title']) ||
  127. empty ($_POST['old_entries'])) {
  128. return false;
  129. }
  130. $_SESSION['sel'] = md5 (
  131. uniqid (mt_rand (), true).implode ('', stat (__FILE__))
  132. );
  133. $_SESSION['base_url'] = addslashes ($_POST['base_url']);
  134. $_SESSION['title'] = addslashes ($_POST['title']);
  135. $_SESSION['old_entries'] = $_POST['old_entries'];
  136. if (!is_int (intval ($_SESSION['old_entries'])) ||
  137. $_SESSION['old_entries'] < 1) {
  138. $_SESSION['old_entries'] = 3;
  139. }
  140. $_SESSION['mail_login'] = addslashes ($_POST['mail_login']);
  141. $_SESSION['default_user'] = substr(preg_replace ('/[^a-zA-Z0-9]/', '', $_POST['default_user']), 0, 16);
  142. $token = '';
  143. if ($_SESSION['mail_login']) {
  144. $token = small_hash (time () . $_SESSION['sel'])
  145. . small_hash ($_SESSION['base_url'] . $_SESSION['sel']);
  146. }
  147. $file_data = DATA_PATH . '/' . $_SESSION['default_user'] . '_user.php';
  148. $f = fopen ($file_data, 'w');
  149. writeLine ($f, '<?php');
  150. writeLine ($f, 'return array (');
  151. writeArray ($f, array (
  152. 'language' => $_SESSION['language'],
  153. 'old_entries' => $_SESSION['old_entries'],
  154. 'mail_login' => $_SESSION['mail_login'],
  155. 'token' => $token
  156. ));
  157. writeLine ($f, ');');
  158. fclose ($f);
  159. header ('Location: index.php?step=3');
  160. }
  161. }
  162. function saveStep3 () {
  163. if (!empty ($_POST)) {
  164. if (empty ($_POST['type']) ||
  165. empty ($_POST['host']) ||
  166. empty ($_POST['user']) ||
  167. empty ($_POST['base'])) {
  168. $_SESSION['bd_error'] = true;
  169. }
  170. $_SESSION['bd_type'] = isset ($_POST['type']) ? $_POST['type'] : 'mysql';
  171. $_SESSION['bd_host'] = addslashes ($_POST['host']);
  172. $_SESSION['bd_user'] = addslashes ($_POST['user']);
  173. $_SESSION['bd_pass'] = addslashes ($_POST['pass']);
  174. $_SESSION['bd_name'] = addslashes ($_POST['base']);
  175. $_SESSION['bd_prefix'] = addslashes ($_POST['prefix']);
  176. $file_conf = DATA_PATH . '/application.ini';
  177. $f = fopen ($file_conf, 'w');
  178. writeLine ($f, '[general]');
  179. writeLine ($f, 'environment = "production"');
  180. writeLine ($f, 'use_url_rewriting = false');
  181. writeLine ($f, 'sel_application = "' . $_SESSION['sel'] . '"');
  182. writeLine ($f, 'base_url = "' . $_SESSION['base_url'] . '"');
  183. writeLine ($f, 'title = "' . $_SESSION['title'] . '"');
  184. writeLine ($f, 'default_user = "' . $_SESSION['default_user'] . '"');
  185. writeLine ($f, '[db]');
  186. writeLine ($f, 'type = "' . $_SESSION['bd_type'] . '"');
  187. writeLine ($f, 'host = "' . $_SESSION['bd_host'] . '"');
  188. writeLine ($f, 'user = "' . $_SESSION['bd_user'] . '"');
  189. writeLine ($f, 'password = "' . $_SESSION['bd_pass'] . '"');
  190. writeLine ($f, 'base = "' . $_SESSION['bd_name'] . '"');
  191. writeLine ($f, 'prefix = "' . $_SESSION['bd_prefix'] . '"');
  192. fclose ($f);
  193. $_SESSION['bd_prefix'] .= (empty($_SESSION['default_user']) ? '' : ($_SESSION['default_user'] . '_'));
  194. $res = checkBD ();
  195. if ($res) {
  196. $_SESSION['bd_error'] = false;
  197. header ('Location: index.php?step=4');
  198. } else {
  199. $_SESSION['bd_error'] = true;
  200. }
  201. }
  202. }
  203. function deleteInstall () {
  204. $res = unlink (PUBLIC_PATH . '/install.php');
  205. if ($res) {
  206. header ('Location: index.php');
  207. }
  208. }
  209. /*** VÉRIFICATIONS ***/
  210. function checkStep () {
  211. $s0 = checkStep0 ();
  212. $s1 = checkStep1 ();
  213. $s2 = checkStep2 ();
  214. $s3 = checkStep3 ();
  215. if (STEP > 0 && $s0['all'] != 'ok') {
  216. header ('Location: index.php?step=0');
  217. } elseif (STEP > 1 && $s1['all'] != 'ok') {
  218. header ('Location: index.php?step=1');
  219. } elseif (STEP > 2 && $s2['all'] != 'ok') {
  220. header ('Location: index.php?step=2');
  221. } elseif (STEP > 3 && $s3['all'] != 'ok') {
  222. header ('Location: index.php?step=3');
  223. }
  224. }
  225. function checkStep0 () {
  226. $languages = availableLanguages ();
  227. $language = isset ($_SESSION['language']) &&
  228. isset ($languages[$_SESSION['language']]);
  229. return array (
  230. 'language' => $language ? 'ok' : 'ko',
  231. 'all' => $language ? 'ok' : 'ko'
  232. );
  233. }
  234. function checkStep1 () {
  235. $php = version_compare (PHP_VERSION, '5.2.0') >= 0;
  236. $minz = file_exists (LIB_PATH . '/minz');
  237. $curl = extension_loaded ('curl');
  238. $pdo = extension_loaded ('pdo_mysql');
  239. $dom = class_exists('DOMDocument');
  240. $data = DATA_PATH && is_writable (DATA_PATH);
  241. $cache = CACHE_PATH && is_writable (CACHE_PATH);
  242. $log = LOG_PATH && is_writable (LOG_PATH);
  243. $favicons = is_writable (PUBLIC_PATH . '/favicons');
  244. return array (
  245. 'php' => $php ? 'ok' : 'ko',
  246. 'minz' => $minz ? 'ok' : 'ko',
  247. 'curl' => $curl ? 'ok' : 'ko',
  248. 'pdo-mysql' => $pdo ? 'ok' : 'ko',
  249. 'dom' => $dom ? 'ok' : 'ko',
  250. 'data' => $data ? 'ok' : 'ko',
  251. 'cache' => $cache ? 'ok' : 'ko',
  252. 'log' => $log ? 'ok' : 'ko',
  253. 'favicons' => $favicons ? 'ok' : 'ko',
  254. 'all' => $php && $minz && $curl && $pdo && $dom && $data && $cache && $log && $favicons ? 'ok' : 'ko'
  255. );
  256. }
  257. function checkStep2 () {
  258. $conf = isset ($_SESSION['sel']) &&
  259. isset ($_SESSION['base_url']) &&
  260. isset ($_SESSION['title']) &&
  261. isset ($_SESSION['old_entries']) &&
  262. isset ($_SESSION['mail_login']) &&
  263. isset ($_SESSION['default_user']);
  264. $defaultUser = empty($_POST['default_user']) ? null : $_POST['default_user'];
  265. if ($defaultUser === null) {
  266. $defaultUser = empty($_SESSION['default_user']) ? '' : $_SESSION['default_user'];
  267. }
  268. $data = file_exists (DATA_PATH . '/' . $defaultUser . '_user.php');
  269. return array (
  270. 'conf' => $conf ? 'ok' : 'ko',
  271. 'data' => $data ? 'ok' : 'ko',
  272. 'all' => $conf && $data ? 'ok' : 'ko'
  273. );
  274. }
  275. function checkStep3 () {
  276. $conf = file_exists (DATA_PATH . '/application.ini');
  277. $bd = isset ($_SESSION['bd_type']) &&
  278. isset ($_SESSION['bd_host']) &&
  279. isset ($_SESSION['bd_user']) &&
  280. isset ($_SESSION['bd_pass']) &&
  281. isset ($_SESSION['bd_name']);
  282. $conn = !isset ($_SESSION['bd_error']) || !$_SESSION['bd_error'];
  283. return array (
  284. 'bd' => $bd ? 'ok' : 'ko',
  285. 'conn' => $conn ? 'ok' : 'ko',
  286. 'conf' => $conf ? 'ok' : 'ko',
  287. 'all' => $bd && $conn && $conf ? 'ok' : 'ko'
  288. );
  289. }
  290. function checkBD () {
  291. $error = false;
  292. try {
  293. $str = '';
  294. $driver_options = null;
  295. if($_SESSION['bd_type'] == 'mysql') {
  296. $driver_options = array(
  297. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  298. );
  299. // on ouvre une connexion juste pour créer la base si elle n'existe pas
  300. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';';
  301. $c = new PDO ($str,
  302. $_SESSION['bd_user'],
  303. $_SESSION['bd_pass'],
  304. $driver_options);
  305. $sql = sprintf (SQL_REQ_CREATE_DB, $_SESSION['bd_name']);
  306. $res = $c->query ($sql);
  307. // on écrase la précédente connexion en sélectionnant la nouvelle BDD
  308. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_name'];
  309. } elseif($_SESSION['bd_type'] == 'sqlite') {
  310. $str = 'sqlite:' . DATA_PATH . $_SESSION['bd_name'] . '.sqlite';
  311. }
  312. $c = new PDO ($str,
  313. $_SESSION['bd_user'],
  314. $_SESSION['bd_pass'],
  315. $driver_options);
  316. $sql = sprintf (SQL_REQ_CAT, $_SESSION['bd_prefix']);
  317. $res = $c->query ($sql);
  318. if (!$res) {
  319. $error = true;
  320. }
  321. $sql = sprintf (SQL_REQ_FEED, $_SESSION['bd_prefix'], $_SESSION['bd_prefix']);
  322. $res = $c->query ($sql);
  323. if (!$res) {
  324. $error = true;
  325. }
  326. $sql = sprintf (SQL_REQ_ENTRY, $_SESSION['bd_prefix'], $_SESSION['bd_prefix']);
  327. $res = $c->query ($sql);
  328. if (!$res) {
  329. $error = true;
  330. }
  331. } catch (PDOException $e) {
  332. $error = true;
  333. }
  334. if ($error && file_exists (DATA_PATH . '/application.ini')) {
  335. unlink (DATA_PATH . '/application.ini');
  336. }
  337. return !$error;
  338. }
  339. /*** AFFICHAGE ***/
  340. function printStep0 () {
  341. global $actual;
  342. ?>
  343. <?php $s0 = checkStep0 (); if ($s0['all'] == 'ok') { ?>
  344. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('language_defined'); ?></p>
  345. <?php } ?>
  346. <form action="index.php?step=0" method="post">
  347. <legend><?php echo _t ('choose_language'); ?></legend>
  348. <div class="form-group">
  349. <label class="group-name" for="language"><?php echo _t ('language'); ?></label>
  350. <div class="group-controls">
  351. <select name="language" id="language">
  352. <?php $languages = availableLanguages (); ?>
  353. <?php foreach ($languages as $short => $lib) { ?>
  354. <option value="<?php echo $short; ?>"<?php echo $actual == $short ? ' selected="selected"' : ''; ?>><?php echo $lib; ?></option>
  355. <?php } ?>
  356. </select>
  357. </div>
  358. </div>
  359. <div class="form-group form-actions">
  360. <div class="group-controls">
  361. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  362. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  363. <?php if ($s0['all'] == 'ok') { ?>
  364. <a class="btn btn-important next-step" href="?step=1"><?php echo _t ('next_step'); ?></a>
  365. <?php } ?>
  366. </div>
  367. </div>
  368. </form>
  369. <?php
  370. }
  371. function printStep1 () {
  372. $res = checkStep1 ();
  373. ?>
  374. <noscript><p class="alert alert-warn"><span class="alert-head"><?php echo _t ('attention'); ?></span> <?php echo _t ('javascript_is_better'); ?></p></noscript>
  375. <?php if ($res['php'] == 'ok') { ?>
  376. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('php_is_ok', PHP_VERSION); ?></p>
  377. <?php } else { ?>
  378. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('php_is_nok', PHP_VERSION, '5.1.0'); ?></p>
  379. <?php } ?>
  380. <?php if ($res['minz'] == 'ok') { ?>
  381. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('minz_is_ok'); ?></p>
  382. <?php } else { ?>
  383. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('minz_is_nok', LIB_PATH . '/minz'); ?></p>
  384. <?php } ?>
  385. <?php if ($res['curl'] == 'ok') { ?>
  386. <?php $version = curl_version(); ?>
  387. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('curl_is_ok', $version['version']); ?></p>
  388. <?php } else { ?>
  389. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('curl_is_nok'); ?></p>
  390. <?php } ?>
  391. <?php if ($res['pdo-mysql'] == 'ok') { ?>
  392. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('pdomysql_is_ok'); ?></p>
  393. <?php } else { ?>
  394. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('pdomysql_is_nok'); ?></p>
  395. <?php } ?>
  396. <?php if ($res['dom'] == 'ok') { ?>
  397. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('dom_is_ok'); ?></p>
  398. <?php } else { ?>
  399. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('dom_is_nok'); ?></p>
  400. <?php } ?>
  401. <?php if ($res['data'] == 'ok') { ?>
  402. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('data_is_ok'); ?></p>
  403. <?php } else { ?>
  404. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', DATA_PATH); ?></p>
  405. <?php } ?>
  406. <?php if ($res['cache'] == 'ok') { ?>
  407. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('cache_is_ok'); ?></p>
  408. <?php } else { ?>
  409. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', CACHE_PATH); ?></p>
  410. <?php } ?>
  411. <?php if ($res['log'] == 'ok') { ?>
  412. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('log_is_ok'); ?></p>
  413. <?php } else { ?>
  414. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', LOG_PATH); ?></p>
  415. <?php } ?>
  416. <?php if ($res['favicons'] == 'ok') { ?>
  417. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('favicons_is_ok'); ?></p>
  418. <?php } else { ?>
  419. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', PUBLIC_PATH . '/favicons'); ?></p>
  420. <?php } ?>
  421. <?php if ($res['all'] == 'ok') { ?>
  422. <a class="btn btn-important next-step" href="?step=2"><?php echo _t ('next_step'); ?></a>
  423. <?php } else { ?>
  424. <p class="alert alert-error"><?php echo _t ('fix_errors_before'); ?></p>
  425. <?php } ?>
  426. <?php
  427. }
  428. function printStep2 () {
  429. ?>
  430. <?php $s2 = checkStep2 (); if ($s2['all'] == 'ok') { ?>
  431. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('general_conf_is_ok'); ?></p>
  432. <?php } ?>
  433. <form action="index.php?step=2" method="post">
  434. <legend><?php echo _t ('general_configuration'); ?></legend>
  435. <?php
  436. $url = substr ($_SERVER['PHP_SELF'], 0, -10);
  437. ?>
  438. <div class="form-group" style="display:none">
  439. <!-- TODO: if no problem during version 0.6, remove for version 0.7 -->
  440. <label class="group-name" for="base_url"><?php echo _t ('base_url'); ?></label>
  441. <div class="group-controls">
  442. <input type="text" id="base_url" name="base_url" value="<?php echo isset ($_SESSION['base_url']) ? $_SESSION['base_url'] : $url; ?>" /> <?php echo _t ('do_not_change_if_doubt'); ?>
  443. </div>
  444. </div>
  445. <div class="form-group">
  446. <label class="group-name" for="title"><?php echo _t ('title'); ?></label>
  447. <div class="group-controls">
  448. <input type="text" id="title" name="title" value="<?php echo isset ($_SESSION['title']) ? $_SESSION['title'] : _t ('freshrss'); ?>" />
  449. </div>
  450. </div>
  451. <div class="form-group">
  452. <label class="group-name" for="old_entries"><?php echo _t ('delete_articles_every'); ?></label>
  453. <div class="group-controls">
  454. <input type="number" id="old_entries" name="old_entries" value="<?php echo isset ($_SESSION['old_entries']) ? $_SESSION['old_entries'] : '3'; ?>" /> <?php echo _t ('month'); ?>
  455. </div>
  456. </div>
  457. <div class="form-group">
  458. <label class="group-name" for="default_user"><?php echo _t ('default_user'); ?></label>
  459. <div class="group-controls">
  460. <input type="text" id="default_user" name="default_user" maxlength="16" value="<?php echo isset ($_SESSION['default_user']) ? $_SESSION['default_user'] : ''; ?>" placeholder="user1" />
  461. </div>
  462. </div>
  463. <div class="form-group">
  464. <label class="group-name" for="mail_login"><?php echo _t ('persona_connection_email'); ?></label>
  465. <div class="group-controls">
  466. <input type="email" id="mail_login" name="mail_login" value="<?php echo isset ($_SESSION['mail_login']) ? $_SESSION['mail_login'] : ''; ?>" placeholder="<?php echo _t ('blank_to_disable'); ?>" />
  467. <noscript><b><?php echo _t ('javascript_should_be_activated'); ?></b></noscript>
  468. </div>
  469. </div>
  470. <div class="form-group form-actions">
  471. <div class="group-controls">
  472. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  473. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  474. <?php if ($s2['all'] == 'ok') { ?>
  475. <a class="btn btn-important next-step" href="?step=3"><?php echo _t ('next_step'); ?></a>
  476. <?php } ?>
  477. </div>
  478. </div>
  479. </form>
  480. <?php
  481. }
  482. function printStep3 () {
  483. ?>
  484. <?php $s3 = checkStep3 (); if ($s3['all'] == 'ok') { ?>
  485. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('bdd_conf_is_ok'); ?></p>
  486. <?php } elseif ($s3['conn'] == 'ko') { ?>
  487. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('bdd_conf_is_ko'); ?></p>
  488. <?php } ?>
  489. <form action="index.php?step=3" method="post">
  490. <legend><?php echo _t ('bdd_configuration'); ?></legend>
  491. <!--
  492. TODO : l'utilisation de SQLite n'est pas encore possible. Pour tester tout de même, décommentez ce bloc
  493. <div class="form-group">
  494. <label class="group-name" for="type"><?php echo _t ('bdd_type'); ?></label>
  495. <div class="group-controls">
  496. <select name="type" id="type">
  497. <option value="mysql"
  498. <?php echo (isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'mysql') ? 'selected="selected"' : ''; ?>>
  499. MySQL
  500. </option>
  501. <option value="sqlite"
  502. <?php echo (isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'sqlite') ? 'selected="selected"' : ''; ?>>
  503. SQLite
  504. </option>
  505. </select>
  506. </div>
  507. </div>
  508. -->
  509. <div class="form-group">
  510. <label class="group-name" for="host"><?php echo _t ('host'); ?></label>
  511. <div class="group-controls">
  512. <input type="text" id="host" name="host" value="<?php echo isset ($_SESSION['bd_host']) ? $_SESSION['bd_host'] : 'localhost'; ?>" />
  513. </div>
  514. </div>
  515. <div class="form-group">
  516. <label class="group-name" for="user"><?php echo _t ('username'); ?></label>
  517. <div class="group-controls">
  518. <input type="text" id="user" name="user" value="<?php echo isset ($_SESSION['bd_user']) ? $_SESSION['bd_user'] : ''; ?>" />
  519. </div>
  520. </div>
  521. <div class="form-group">
  522. <label class="group-name" for="pass"><?php echo _t ('password'); ?></label>
  523. <div class="group-controls">
  524. <input type="password" id="pass" name="pass" value="<?php echo isset ($_SESSION['bd_pass']) ? $_SESSION['bd_pass'] : ''; ?>" />
  525. </div>
  526. </div>
  527. <div class="form-group">
  528. <label class="group-name" for="base"><?php echo _t ('bdd'); ?></label>
  529. <div class="group-controls">
  530. <input type="text" id="base" name="base" maxlength="64" value="<?php echo isset ($_SESSION['bd_name']) ? $_SESSION['bd_name'] : ''; ?>" />
  531. </div>
  532. </div>
  533. <div class="form-group">
  534. <label class="group-name" for="prefix"><?php echo _t ('prefix'); ?></label>
  535. <div class="group-controls">
  536. <input type="text" id="prefix" name="prefix" maxlength="16" value="<?php echo isset ($_SESSION['bd_prefix']) ? $_SESSION['bd_prefix'] : 'freshrss_'; ?>" />
  537. </div>
  538. </div>
  539. <div class="form-group form-actions">
  540. <div class="group-controls">
  541. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  542. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  543. <?php if ($s3['all'] == 'ok') { ?>
  544. <a class="btn btn-important next-step" href="?step=4"><?php echo _t ('next_step'); ?></a>
  545. <?php } ?>
  546. </div>
  547. </div>
  548. </form>
  549. <?php
  550. }
  551. function printStep4 () {
  552. ?>
  553. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('congratulations'); ?></span> <?php echo _t ('installation_is_ok'); ?></p>
  554. <a class="btn btn-important next-step" href="?step=5"><?php echo _t ('finish_installation'); ?></a>
  555. <?php
  556. }
  557. function printStep5 () {
  558. ?>
  559. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('oops'); ?></span> <?php echo _t ('install_not_deleted', PUBLIC_PATH . '/install.php'); ?></p>
  560. <?php
  561. }
  562. initTranslate ();
  563. checkStep ();
  564. switch (STEP) {
  565. case 0:
  566. default:
  567. saveLanguage ();
  568. break;
  569. case 1:
  570. break;
  571. case 2:
  572. saveStep2 ();
  573. break;
  574. case 3:
  575. saveStep3 ();
  576. break;
  577. case 4:
  578. break;
  579. case 5:
  580. deleteInstall ();
  581. break;
  582. }
  583. ?>
  584. <!DOCTYPE html>
  585. <html lang="fr">
  586. <head>
  587. <meta charset="utf-8">
  588. <meta name="viewport" content="initial-scale=1.0">
  589. <title><?php echo _t ('freshrss_installation'); ?></title>
  590. <link rel="stylesheet" type="text/css" media="all" href="themes/default/global.css" />
  591. <link rel="stylesheet" type="text/css" media="all" href="themes/default/freshrss.css" />
  592. </head>
  593. <body>
  594. <div class="header">
  595. <div class="item title">
  596. <h1><a href="index.php"><?php echo _t ('freshrss'); ?></a></h1>
  597. <h2><?php echo _t ('installation_step', STEP); ?></h2>
  598. </div>
  599. </div>
  600. <div id="global">
  601. <ul class="nav nav-list aside">
  602. <li class="nav-header"><?php echo _t ('steps'); ?></li>
  603. <li class="item<?php echo STEP == 0 ? ' active' : ''; ?>"><a href="?step=0"><?php echo _t ('language'); ?></a></li>
  604. <li class="item<?php echo STEP == 1 ? ' active' : ''; ?>"><a href="?step=1"><?php echo _t ('checks'); ?></a></li>
  605. <li class="item<?php echo STEP == 2 ? ' active' : ''; ?>"><a href="?step=2"><?php echo _t ('general_configuration'); ?></a></li>
  606. <li class="item<?php echo STEP == 3 ? ' active' : ''; ?>"><a href="?step=3"><?php echo _t ('bdd_configuration'); ?></a></li>
  607. <li class="item<?php echo STEP == 4 ? ' active' : ''; ?>"><a href="?step=4"><?php echo _t ('this_is_the_end'); ?></a></li>
  608. </ul>
  609. <div class="post">
  610. <?php
  611. switch (STEP) {
  612. case 0:
  613. default:
  614. printStep0 ();
  615. break;
  616. case 1:
  617. printStep1 ();
  618. break;
  619. case 2:
  620. printStep2 ();
  621. break;
  622. case 3:
  623. printStep3 ();
  624. break;
  625. case 4:
  626. printStep4 ();
  627. break;
  628. case 5:
  629. printStep5 ();
  630. break;
  631. }
  632. ?>
  633. </div>
  634. </div>
  635. </body>
  636. </html>