install.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  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. }
  206. function deleteInstall () {
  207. $res = unlink (PUBLIC_PATH . '/install.php');
  208. if ($res) {
  209. header ('Location: index.php');
  210. }
  211. }
  212. /*** VÉRIFICATIONS ***/
  213. function checkStep () {
  214. $s0 = checkStep0 ();
  215. $s1 = checkStep1 ();
  216. $s2 = checkStep2 ();
  217. $s3 = checkStep3 ();
  218. if (STEP > 0 && $s0['all'] != 'ok') {
  219. header ('Location: index.php?step=0');
  220. } elseif (STEP > 1 && $s1['all'] != 'ok') {
  221. header ('Location: index.php?step=1');
  222. } elseif (STEP > 2 && $s2['all'] != 'ok') {
  223. header ('Location: index.php?step=2');
  224. } elseif (STEP > 3 && $s3['all'] != 'ok') {
  225. header ('Location: index.php?step=3');
  226. }
  227. }
  228. function checkStep0 () {
  229. $languages = availableLanguages ();
  230. $language = isset ($_SESSION['language']) &&
  231. isset ($languages[$_SESSION['language']]);
  232. return array (
  233. 'language' => $language ? 'ok' : 'ko',
  234. 'all' => $language ? 'ok' : 'ko'
  235. );
  236. }
  237. function checkStep1 () {
  238. $php = version_compare (PHP_VERSION, '5.2.0') >= 0;
  239. $minz = file_exists (LIB_PATH . '/minz');
  240. $curl = extension_loaded ('curl');
  241. $pdo = extension_loaded ('pdo_mysql');
  242. $dom = class_exists('DOMDocument');
  243. $data = DATA_PATH && is_writable (DATA_PATH);
  244. $cache = CACHE_PATH && is_writable (CACHE_PATH);
  245. $log = LOG_PATH && is_writable (LOG_PATH);
  246. $favicons = is_writable (PUBLIC_PATH . '/favicons');
  247. return array (
  248. 'php' => $php ? 'ok' : 'ko',
  249. 'minz' => $minz ? 'ok' : 'ko',
  250. 'curl' => $curl ? 'ok' : 'ko',
  251. 'pdo-mysql' => $pdo ? 'ok' : 'ko',
  252. 'dom' => $dom ? 'ok' : 'ko',
  253. 'data' => $data ? 'ok' : 'ko',
  254. 'cache' => $cache ? 'ok' : 'ko',
  255. 'log' => $log ? 'ok' : 'ko',
  256. 'favicons' => $favicons ? 'ok' : 'ko',
  257. 'all' => $php && $minz && $curl && $pdo && $dom && $data && $cache && $log && $favicons ? 'ok' : 'ko'
  258. );
  259. }
  260. function checkStep2 () {
  261. $conf = isset ($_SESSION['sel']) &&
  262. isset ($_SESSION['base_url']) &&
  263. isset ($_SESSION['title']) &&
  264. isset ($_SESSION['old_entries']) &&
  265. isset ($_SESSION['mail_login']) &&
  266. isset ($_SESSION['default_user']);
  267. $defaultUser = empty($_POST['default_user']) ? null : $_POST['default_user'];
  268. if ($defaultUser === null) {
  269. $defaultUser = empty($_SESSION['default_user']) ? '' : $_SESSION['default_user'];
  270. }
  271. $data = file_exists (DATA_PATH . '/' . $defaultUser . '_user.php');
  272. return array (
  273. 'conf' => $conf ? 'ok' : 'ko',
  274. 'data' => $data ? 'ok' : 'ko',
  275. 'all' => $conf && $data ? 'ok' : 'ko'
  276. );
  277. }
  278. function checkStep3 () {
  279. $conf = file_exists (DATA_PATH . '/application.ini');
  280. $bd = isset ($_SESSION['bd_type']) &&
  281. isset ($_SESSION['bd_host']) &&
  282. isset ($_SESSION['bd_user']) &&
  283. isset ($_SESSION['bd_pass']) &&
  284. isset ($_SESSION['bd_name']);
  285. $conn = !isset ($_SESSION['bd_error']) || !$_SESSION['bd_error'];
  286. return array (
  287. 'bd' => $bd ? 'ok' : 'ko',
  288. 'conn' => $conn ? 'ok' : 'ko',
  289. 'conf' => $conf ? 'ok' : 'ko',
  290. 'all' => $bd && $conn && $conf ? 'ok' : 'ko'
  291. );
  292. }
  293. function checkBD () {
  294. $error = false;
  295. try {
  296. $str = '';
  297. $driver_options = null;
  298. if($_SESSION['bd_type'] == 'mysql') {
  299. $driver_options = array(
  300. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  301. );
  302. // on ouvre une connexion juste pour créer la base si elle n'existe pas
  303. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';';
  304. $c = new PDO ($str,
  305. $_SESSION['bd_user'],
  306. $_SESSION['bd_pass'],
  307. $driver_options);
  308. $sql = sprintf (SQL_REQ_CREATE_DB, $_SESSION['bd_name']);
  309. $res = $c->query ($sql);
  310. // on écrase la précédente connexion en sélectionnant la nouvelle BDD
  311. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_name'];
  312. } elseif($_SESSION['bd_type'] == 'sqlite') {
  313. $str = 'sqlite:' . DATA_PATH . $_SESSION['bd_name'] . '.sqlite';
  314. }
  315. $c = new PDO ($str,
  316. $_SESSION['bd_user'],
  317. $_SESSION['bd_pass'],
  318. $driver_options);
  319. $sql = sprintf (SQL_REQ_CAT, $_SESSION['bd_prefix']);
  320. $res = $c->query ($sql);
  321. if (!$res) {
  322. $error = true;
  323. }
  324. $sql = sprintf (SQL_REQ_FEED, $_SESSION['bd_prefix'], $_SESSION['bd_prefix']);
  325. $res = $c->query ($sql);
  326. if (!$res) {
  327. $error = true;
  328. }
  329. $sql = sprintf (SQL_REQ_ENTRY, $_SESSION['bd_prefix'], $_SESSION['bd_prefix']);
  330. $res = $c->query ($sql);
  331. if (!$res) {
  332. $error = true;
  333. }
  334. } catch (PDOException $e) {
  335. $error = true;
  336. }
  337. if ($error && file_exists (DATA_PATH . '/application.ini')) {
  338. unlink (DATA_PATH . '/application.ini');
  339. }
  340. return !$error;
  341. }
  342. /*** AFFICHAGE ***/
  343. function printStep0 () {
  344. global $actual;
  345. ?>
  346. <?php $s0 = checkStep0 (); if ($s0['all'] == 'ok') { ?>
  347. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('language_defined'); ?></p>
  348. <?php } ?>
  349. <form action="index.php?step=0" method="post">
  350. <legend><?php echo _t ('choose_language'); ?></legend>
  351. <div class="form-group">
  352. <label class="group-name" for="language"><?php echo _t ('language'); ?></label>
  353. <div class="group-controls">
  354. <select name="language" id="language">
  355. <?php $languages = availableLanguages (); ?>
  356. <?php foreach ($languages as $short => $lib) { ?>
  357. <option value="<?php echo $short; ?>"<?php echo $actual == $short ? ' selected="selected"' : ''; ?>><?php echo $lib; ?></option>
  358. <?php } ?>
  359. </select>
  360. </div>
  361. </div>
  362. <div class="form-group form-actions">
  363. <div class="group-controls">
  364. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  365. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  366. <?php if ($s0['all'] == 'ok') { ?>
  367. <a class="btn btn-important next-step" href="?step=1"><?php echo _t ('next_step'); ?></a>
  368. <?php } ?>
  369. </div>
  370. </div>
  371. </form>
  372. <?php
  373. }
  374. function printStep1 () {
  375. $res = checkStep1 ();
  376. ?>
  377. <noscript><p class="alert alert-warn"><span class="alert-head"><?php echo _t ('attention'); ?></span> <?php echo _t ('javascript_is_better'); ?></p></noscript>
  378. <?php if ($res['php'] == 'ok') { ?>
  379. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('php_is_ok', PHP_VERSION); ?></p>
  380. <?php } else { ?>
  381. <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>
  382. <?php } ?>
  383. <?php if ($res['minz'] == 'ok') { ?>
  384. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('minz_is_ok'); ?></p>
  385. <?php } else { ?>
  386. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('minz_is_nok', LIB_PATH . '/minz'); ?></p>
  387. <?php } ?>
  388. <?php if ($res['curl'] == 'ok') { ?>
  389. <?php $version = curl_version(); ?>
  390. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('curl_is_ok', $version['version']); ?></p>
  391. <?php } else { ?>
  392. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('curl_is_nok'); ?></p>
  393. <?php } ?>
  394. <?php if ($res['pdo-mysql'] == 'ok') { ?>
  395. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('pdomysql_is_ok'); ?></p>
  396. <?php } else { ?>
  397. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('pdomysql_is_nok'); ?></p>
  398. <?php } ?>
  399. <?php if ($res['dom'] == 'ok') { ?>
  400. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('dom_is_ok'); ?></p>
  401. <?php } else { ?>
  402. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('dom_is_nok'); ?></p>
  403. <?php } ?>
  404. <?php if ($res['data'] == 'ok') { ?>
  405. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('data_is_ok'); ?></p>
  406. <?php } else { ?>
  407. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', DATA_PATH); ?></p>
  408. <?php } ?>
  409. <?php if ($res['cache'] == 'ok') { ?>
  410. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('cache_is_ok'); ?></p>
  411. <?php } else { ?>
  412. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', CACHE_PATH); ?></p>
  413. <?php } ?>
  414. <?php if ($res['log'] == 'ok') { ?>
  415. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('log_is_ok'); ?></p>
  416. <?php } else { ?>
  417. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', LOG_PATH); ?></p>
  418. <?php } ?>
  419. <?php if ($res['favicons'] == 'ok') { ?>
  420. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('favicons_is_ok'); ?></p>
  421. <?php } else { ?>
  422. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', PUBLIC_PATH . '/favicons'); ?></p>
  423. <?php } ?>
  424. <?php if ($res['all'] == 'ok') { ?>
  425. <a class="btn btn-important next-step" href="?step=2"><?php echo _t ('next_step'); ?></a>
  426. <?php } else { ?>
  427. <p class="alert alert-error"><?php echo _t ('fix_errors_before'); ?></p>
  428. <?php } ?>
  429. <?php
  430. }
  431. function printStep2 () {
  432. ?>
  433. <?php $s2 = checkStep2 (); if ($s2['all'] == 'ok') { ?>
  434. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('general_conf_is_ok'); ?></p>
  435. <?php } ?>
  436. <form action="index.php?step=2" method="post">
  437. <legend><?php echo _t ('general_configuration'); ?></legend>
  438. <?php
  439. $url = substr ($_SERVER['PHP_SELF'], 0, -10);
  440. ?>
  441. <div class="form-group" style="display:none">
  442. <!-- TODO: if no problem during version 0.6, remove for version 0.7 -->
  443. <label class="group-name" for="base_url"><?php echo _t ('base_url'); ?></label>
  444. <div class="group-controls">
  445. <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'); ?>
  446. </div>
  447. </div>
  448. <div class="form-group">
  449. <label class="group-name" for="title"><?php echo _t ('title'); ?></label>
  450. <div class="group-controls">
  451. <input type="text" id="title" name="title" value="<?php echo isset ($_SESSION['title']) ? $_SESSION['title'] : _t ('freshrss'); ?>" />
  452. </div>
  453. </div>
  454. <div class="form-group">
  455. <label class="group-name" for="old_entries"><?php echo _t ('delete_articles_every'); ?></label>
  456. <div class="group-controls">
  457. <input type="number" id="old_entries" name="old_entries" value="<?php echo isset ($_SESSION['old_entries']) ? $_SESSION['old_entries'] : '3'; ?>" /> <?php echo _t ('month'); ?>
  458. </div>
  459. </div>
  460. <div class="form-group">
  461. <label class="group-name" for="default_user"><?php echo _t ('default_user'); ?></label>
  462. <div class="group-controls">
  463. <input type="text" id="default_user" name="default_user" maxlength="16" value="<?php echo isset ($_SESSION['default_user']) ? $_SESSION['default_user'] : ''; ?>" placeholder="user1" />
  464. </div>
  465. </div>
  466. <div class="form-group">
  467. <label class="group-name" for="mail_login"><?php echo _t ('persona_connection_email'); ?></label>
  468. <div class="group-controls">
  469. <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'); ?>" />
  470. <noscript><b><?php echo _t ('javascript_should_be_activated'); ?></b></noscript>
  471. </div>
  472. </div>
  473. <div class="form-group form-actions">
  474. <div class="group-controls">
  475. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  476. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  477. <?php if ($s2['all'] == 'ok') { ?>
  478. <a class="btn btn-important next-step" href="?step=3"><?php echo _t ('next_step'); ?></a>
  479. <?php } ?>
  480. </div>
  481. </div>
  482. </form>
  483. <?php
  484. }
  485. function printStep3 () {
  486. ?>
  487. <?php $s3 = checkStep3 (); if ($s3['all'] == 'ok') { ?>
  488. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('bdd_conf_is_ok'); ?></p>
  489. <?php } elseif ($s3['conn'] == 'ko') { ?>
  490. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('bdd_conf_is_ko'); ?></p>
  491. <?php } ?>
  492. <form action="index.php?step=3" method="post">
  493. <legend><?php echo _t ('bdd_configuration'); ?></legend>
  494. <!--
  495. TODO : l'utilisation de SQLite n'est pas encore possible. Pour tester tout de même, décommentez ce bloc
  496. <div class="form-group">
  497. <label class="group-name" for="type"><?php echo _t ('bdd_type'); ?></label>
  498. <div class="group-controls">
  499. <select name="type" id="type">
  500. <option value="mysql"
  501. <?php echo (isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'mysql') ? 'selected="selected"' : ''; ?>>
  502. MySQL
  503. </option>
  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. -->
  512. <div class="form-group">
  513. <label class="group-name" for="host"><?php echo _t ('host'); ?></label>
  514. <div class="group-controls">
  515. <input type="text" id="host" name="host" value="<?php echo isset ($_SESSION['bd_host']) ? $_SESSION['bd_host'] : 'localhost'; ?>" />
  516. </div>
  517. </div>
  518. <div class="form-group">
  519. <label class="group-name" for="user"><?php echo _t ('username'); ?></label>
  520. <div class="group-controls">
  521. <input type="text" id="user" name="user" value="<?php echo isset ($_SESSION['bd_user']) ? $_SESSION['bd_user'] : ''; ?>" />
  522. </div>
  523. </div>
  524. <div class="form-group">
  525. <label class="group-name" for="pass"><?php echo _t ('password'); ?></label>
  526. <div class="group-controls">
  527. <input type="password" id="pass" name="pass" value="<?php echo isset ($_SESSION['bd_pass']) ? $_SESSION['bd_pass'] : ''; ?>" />
  528. </div>
  529. </div>
  530. <div class="form-group">
  531. <label class="group-name" for="base"><?php echo _t ('bdd'); ?></label>
  532. <div class="group-controls">
  533. <input type="text" id="base" name="base" maxlength="64" value="<?php echo isset ($_SESSION['bd_name']) ? $_SESSION['bd_name'] : ''; ?>" />
  534. </div>
  535. </div>
  536. <div class="form-group">
  537. <label class="group-name" for="prefix"><?php echo _t ('prefix'); ?></label>
  538. <div class="group-controls">
  539. <input type="text" id="prefix" name="prefix" maxlength="16" value="<?php echo isset ($_SESSION['bd_prefix']) ? $_SESSION['bd_prefix'] : 'freshrss_'; ?>" />
  540. </div>
  541. </div>
  542. <div class="form-group form-actions">
  543. <div class="group-controls">
  544. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  545. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  546. <?php if ($s3['all'] == 'ok') { ?>
  547. <a class="btn btn-important next-step" href="?step=4"><?php echo _t ('next_step'); ?></a>
  548. <?php } ?>
  549. </div>
  550. </div>
  551. </form>
  552. <?php
  553. }
  554. function printStep4 () {
  555. ?>
  556. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('congratulations'); ?></span> <?php echo _t ('installation_is_ok'); ?></p>
  557. <a class="btn btn-important next-step" href="?step=5"><?php echo _t ('finish_installation'); ?></a>
  558. <?php
  559. }
  560. function printStep5 () {
  561. ?>
  562. <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>
  563. <?php
  564. }
  565. initTranslate ();
  566. checkStep ();
  567. switch (STEP) {
  568. case 0:
  569. default:
  570. saveLanguage ();
  571. break;
  572. case 1:
  573. break;
  574. case 2:
  575. saveStep2 ();
  576. break;
  577. case 3:
  578. saveStep3 ();
  579. break;
  580. case 4:
  581. break;
  582. case 5:
  583. deleteInstall ();
  584. break;
  585. }
  586. ?>
  587. <!DOCTYPE html>
  588. <html lang="fr">
  589. <head>
  590. <meta charset="utf-8">
  591. <meta name="viewport" content="initial-scale=1.0">
  592. <title><?php echo _t ('freshrss_installation'); ?></title>
  593. <link rel="stylesheet" type="text/css" media="all" href="themes/default/global.css" />
  594. <link rel="stylesheet" type="text/css" media="all" href="themes/default/freshrss.css" />
  595. </head>
  596. <body>
  597. <div class="header">
  598. <div class="item title">
  599. <h1><a href="index.php"><?php echo _t ('freshrss'); ?></a></h1>
  600. <h2><?php echo _t ('installation_step', STEP); ?></h2>
  601. </div>
  602. </div>
  603. <div id="global">
  604. <ul class="nav nav-list aside">
  605. <li class="nav-header"><?php echo _t ('steps'); ?></li>
  606. <li class="item<?php echo STEP == 0 ? ' active' : ''; ?>"><a href="?step=0"><?php echo _t ('language'); ?></a></li>
  607. <li class="item<?php echo STEP == 1 ? ' active' : ''; ?>"><a href="?step=1"><?php echo _t ('checks'); ?></a></li>
  608. <li class="item<?php echo STEP == 2 ? ' active' : ''; ?>"><a href="?step=2"><?php echo _t ('general_configuration'); ?></a></li>
  609. <li class="item<?php echo STEP == 3 ? ' active' : ''; ?>"><a href="?step=3"><?php echo _t ('bdd_configuration'); ?></a></li>
  610. <li class="item<?php echo STEP == 4 ? ' active' : ''; ?>"><a href="?step=4"><?php echo _t ('this_is_the_end'); ?></a></li>
  611. </ul>
  612. <div class="post">
  613. <?php
  614. switch (STEP) {
  615. case 0:
  616. default:
  617. printStep0 ();
  618. break;
  619. case 1:
  620. printStep1 ();
  621. break;
  622. case 2:
  623. printStep2 ();
  624. break;
  625. case 3:
  626. printStep3 ();
  627. break;
  628. case 4:
  629. printStep4 ();
  630. break;
  631. case 5:
  632. printStep5 ();
  633. break;
  634. }
  635. ?>
  636. </div>
  637. </div>
  638. </body>
  639. </html>