install.php 24 KB

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