install.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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. $actual = isset($_SESSION['language']) ? $_SESSION['language'] : getBetterLanguage('en');
  82. $file = APP_PATH . '/i18n/' . $actual . '.php';
  83. if (file_exists ($file)) {
  84. $translates = include ($file);
  85. }
  86. }
  87. function getBetterLanguage ($fallback) {
  88. $available = availableLanguages ();
  89. $accept = $_SERVER['HTTP_ACCEPT_LANGUAGE'];
  90. $language = strtolower (substr ($accept, 0, 2));
  91. if (isset ($available[$language])) {
  92. return $language;
  93. } else {
  94. return $fallback;
  95. }
  96. }
  97. function availableLanguages () {
  98. return array (
  99. 'en' => 'English',
  100. 'fr' => 'Français'
  101. );
  102. }
  103. function _t ($key) {
  104. global $translates;
  105. $translate = $key;
  106. if (isset ($translates[$key])) {
  107. $translate = $translates[$key];
  108. }
  109. $args = func_get_args ();
  110. unset($args[0]);
  111. return vsprintf ($translate, $args);
  112. }
  113. /*** SAUVEGARDES ***/
  114. function saveLanguage () {
  115. if (!empty ($_POST)) {
  116. if (!isset ($_POST['language'])) {
  117. return false;
  118. }
  119. $_SESSION['language'] = $_POST['language'];
  120. header ('Location: index.php?step=1');
  121. }
  122. }
  123. function saveStep2 () {
  124. if (!empty ($_POST)) {
  125. if (empty ($_POST['title']) ||
  126. empty ($_POST['old_entries'])) {
  127. return false;
  128. }
  129. $_SESSION['sel_application'] = sha1(uniqid(mt_rand(), true).implode('', stat(__FILE__)));
  130. $_SESSION['title'] = addslashes ($_POST['title']);
  131. $_SESSION['old_entries'] = $_POST['old_entries'];
  132. if (!is_int (intval ($_SESSION['old_entries'])) ||
  133. $_SESSION['old_entries'] < 1) {
  134. $_SESSION['old_entries'] = 3;
  135. }
  136. $_SESSION['mail_login'] = addslashes ($_POST['mail_login']);
  137. $_SESSION['default_user'] = substr(preg_replace ('/[^a-zA-Z0-9]/', '', $_POST['default_user']), 0, 16);
  138. $token = '';
  139. if ($_SESSION['mail_login']) {
  140. $token = sha1($_SESSION['sel_application'] . $_SESSION['mail_login']);
  141. }
  142. $file_data = DATA_PATH . '/' . $_SESSION['default_user'] . '_user.php';
  143. $f = fopen ($file_data, 'w');
  144. writeLine ($f, '<?php');
  145. writeLine ($f, 'return array (');
  146. writeArray ($f, array (
  147. 'language' => $_SESSION['language'],
  148. 'old_entries' => $_SESSION['old_entries'],
  149. 'mail_login' => $_SESSION['mail_login'],
  150. 'token' => $token
  151. ));
  152. writeLine ($f, ');');
  153. fclose ($f);
  154. header ('Location: index.php?step=3');
  155. }
  156. }
  157. function saveStep3 () {
  158. if (!empty ($_POST)) {
  159. if (empty ($_POST['type']) ||
  160. empty ($_POST['host']) ||
  161. empty ($_POST['user']) ||
  162. empty ($_POST['base'])) {
  163. $_SESSION['bd_error'] = true;
  164. }
  165. $_SESSION['bd_type'] = isset ($_POST['type']) ? $_POST['type'] : 'mysql';
  166. $_SESSION['bd_host'] = addslashes ($_POST['host']);
  167. $_SESSION['bd_user'] = addslashes ($_POST['user']);
  168. $_SESSION['bd_password'] = addslashes ($_POST['pass']);
  169. $_SESSION['bd_base'] = addslashes ($_POST['base']);
  170. $_SESSION['bd_prefix'] = addslashes ($_POST['prefix']);
  171. $file_conf = DATA_PATH . '/application.ini';
  172. $f = fopen ($file_conf, 'w');
  173. writeLine ($f, '[general]');
  174. writeLine ($f, 'environment = "' . empty($_SESSION['environment']) ? 'production' : $_SESSION['environment'] . '"');
  175. writeLine ($f, 'use_url_rewriting = false');
  176. writeLine ($f, 'sel_application = "' . $_SESSION['sel_application'] . '"');
  177. writeLine ($f, 'base_url = ""');
  178. writeLine ($f, 'title = "' . $_SESSION['title'] . '"');
  179. writeLine ($f, 'default_user = "' . $_SESSION['default_user'] . '"');
  180. writeLine ($f, '[db]');
  181. writeLine ($f, 'type = "' . $_SESSION['bd_type'] . '"');
  182. writeLine ($f, 'host = "' . $_SESSION['bd_host'] . '"');
  183. writeLine ($f, 'user = "' . $_SESSION['bd_user'] . '"');
  184. writeLine ($f, 'password = "' . $_SESSION['bd_password'] . '"');
  185. writeLine ($f, 'base = "' . $_SESSION['bd_base'] . '"');
  186. writeLine ($f, 'prefix = "' . $_SESSION['bd_prefix'] . '"');
  187. fclose ($f);
  188. $_SESSION['bd_prefix_user'] = $_SESSION['bd_prefix'] . (empty($_SESSION['default_user']) ? '' : ($_SESSION['default_user'] . '_'));
  189. $res = checkBD ();
  190. if ($res) {
  191. $_SESSION['bd_error'] = false;
  192. header ('Location: index.php?step=4');
  193. } else {
  194. $_SESSION['bd_error'] = true;
  195. }
  196. }
  197. invalidateHttpCache();
  198. }
  199. function deleteInstall () {
  200. $res = unlink (PUBLIC_PATH . '/install.php');
  201. if ($res) {
  202. header ('Location: index.php');
  203. }
  204. }
  205. function moveOldFiles() {
  206. $mvs = array(
  207. '/app/configuration/application.ini' => '/data/application.ini', //v0.6
  208. '/public/data/Configuration.array.php' => '/data/Configuration.array.php', //v0.6
  209. );
  210. $ok = true;
  211. foreach ($mvs as $fFrom => $fTo) {
  212. if (file_exists(FRESHRSS_PATH . $fFrom)) {
  213. if (copy(FRESHRSS_PATH . $fFrom, FRESHRSS_PATH . $fTo)) {
  214. @unlink(FRESHRSS_PATH . $fFrom);
  215. } else {
  216. $ok = false;
  217. }
  218. }
  219. }
  220. return $ok;
  221. }
  222. function delTree($dir) { //http://php.net/rmdir#110489
  223. if (!is_dir($dir)) {
  224. return true;
  225. }
  226. $files = array_diff(scandir($dir), array('.', '..'));
  227. foreach ($files as $file) {
  228. $f = $dir . '/' . $file;
  229. if (is_dir($f)) {
  230. @chmod($f, 0777);
  231. delTree($f);
  232. }
  233. else unlink($f);
  234. }
  235. return rmdir($dir);
  236. }
  237. function removeOldFiles() {
  238. $oldDirs = array('/app/configuration/', '/cache/', '/log/', '/public/data/', '/public/themes/printer/'); //v0.6
  239. $ok = true;
  240. foreach ($oldDirs as $oldDir) {
  241. $ok &= delTree(FRESHRSS_PATH . $oldDir);
  242. }
  243. return $ok;
  244. }
  245. /*** VÉRIFICATIONS ***/
  246. function checkStep () {
  247. $s0 = checkStep0 ();
  248. $s1 = checkStep1 ();
  249. $s2 = checkStep2 ();
  250. $s3 = checkStep3 ();
  251. if (STEP > 0 && $s0['all'] != 'ok') {
  252. header ('Location: index.php?step=0');
  253. } elseif (STEP > 1 && $s1['all'] != 'ok') {
  254. header ('Location: index.php?step=1');
  255. } elseif (STEP > 2 && $s2['all'] != 'ok') {
  256. header ('Location: index.php?step=2');
  257. } elseif (STEP > 3 && $s3['all'] != 'ok') {
  258. header ('Location: index.php?step=3');
  259. }
  260. }
  261. function checkStep0 () {
  262. moveOldFiles() && removeOldFiles();
  263. if (file_exists(DATA_PATH . '/application.ini')) {
  264. $ini_array = parse_ini_file(DATA_PATH . '/application.ini', true);
  265. if ($ini_array) {
  266. $ini_general = isset($ini_array['general']) ? $ini_array['general'] : null;
  267. if ($ini_general) {
  268. $keys = array('environment', 'sel_application', 'title', 'default_user');
  269. foreach ($keys as $key) {
  270. if ((empty($_SESSION[$key])) && isset($ini_general[$key])) {
  271. $_SESSION[$key] = $ini_general[$key];
  272. }
  273. }
  274. }
  275. $ini_db = isset($ini_array['db']) ? $ini_array['db'] : null;
  276. if ($ini_db) {
  277. $keys = array('type', 'host', 'user', 'password', 'base', 'prefix');
  278. foreach ($keys as $key) {
  279. if ((!isset($_SESSION['bd_' . $key])) && isset($ini_db[$key])) {
  280. $_SESSION['bd_' . $key] = $ini_db[$key];
  281. }
  282. }
  283. }
  284. }
  285. }
  286. if (isset($_SESSION['default_user']) && file_exists(DATA_PATH . '/' . $_SESSION['default_user'] . '_user.php')) {
  287. $userConfig = include(DATA_PATH . '/' . $_SESSION['default_user'] . '_user.php');
  288. } elseif (file_exists(DATA_PATH . '/Configuration.array.php')) {
  289. $userConfig = include(DATA_PATH . '/Configuration.array.php'); //v0.6
  290. } else {
  291. $userConfig = array();
  292. }
  293. $keys = array('language', 'old_entries', 'mail_login');
  294. foreach ($keys as $key) {
  295. if ((!isset($_SESSION[$key])) && isset($userConfig[$key])) {
  296. $_SESSION[$key] = $userConfig[$key];
  297. }
  298. }
  299. $languages = availableLanguages ();
  300. $language = isset ($_SESSION['language']) &&
  301. isset ($languages[$_SESSION['language']]);
  302. return array (
  303. 'language' => $language ? 'ok' : 'ko',
  304. 'all' => $language ? 'ok' : 'ko'
  305. );
  306. }
  307. function checkStep1 () {
  308. $php = version_compare (PHP_VERSION, '5.2.0') >= 0;
  309. $minz = file_exists (LIB_PATH . '/Minz');
  310. $curl = extension_loaded ('curl');
  311. $pdo = extension_loaded ('pdo_mysql');
  312. $dom = class_exists('DOMDocument');
  313. $data = DATA_PATH && is_writable (DATA_PATH);
  314. $cache = CACHE_PATH && is_writable (CACHE_PATH);
  315. $log = LOG_PATH && is_writable (LOG_PATH);
  316. $favicons = is_writable (DATA_PATH . '/favicons');
  317. return array (
  318. 'php' => $php ? 'ok' : 'ko',
  319. 'minz' => $minz ? 'ok' : 'ko',
  320. 'curl' => $curl ? 'ok' : 'ko',
  321. 'pdo-mysql' => $pdo ? 'ok' : 'ko',
  322. 'dom' => $dom ? 'ok' : 'ko',
  323. 'data' => $data ? 'ok' : 'ko',
  324. 'cache' => $cache ? 'ok' : 'ko',
  325. 'log' => $log ? 'ok' : 'ko',
  326. 'favicons' => $favicons ? 'ok' : 'ko',
  327. 'all' => $php && $minz && $curl && $pdo && $dom && $data && $cache && $log && $favicons ? 'ok' : 'ko'
  328. );
  329. }
  330. function checkStep2 () {
  331. $conf = isset ($_SESSION['sel_application']) &&
  332. isset ($_SESSION['title']) &&
  333. isset ($_SESSION['old_entries']) &&
  334. isset ($_SESSION['mail_login']) &&
  335. isset ($_SESSION['default_user']);
  336. $defaultUser = empty($_POST['default_user']) ? null : $_POST['default_user'];
  337. if ($defaultUser === null) {
  338. $defaultUser = empty($_SESSION['default_user']) ? '' : $_SESSION['default_user'];
  339. }
  340. $data = file_exists (DATA_PATH . '/' . $defaultUser . '_user.php');
  341. if ($data) {
  342. @unlink(DATA_PATH . '/Configuration.array.php'); //v0.6
  343. }
  344. return array (
  345. 'conf' => $conf ? 'ok' : 'ko',
  346. 'data' => $data ? 'ok' : 'ko',
  347. 'all' => $conf && $data ? 'ok' : 'ko'
  348. );
  349. }
  350. function checkStep3 () {
  351. $conf = file_exists (DATA_PATH . '/application.ini');
  352. $bd = isset ($_SESSION['bd_type']) &&
  353. isset ($_SESSION['bd_host']) &&
  354. isset ($_SESSION['bd_user']) &&
  355. isset ($_SESSION['bd_password']) &&
  356. isset ($_SESSION['bd_base']) &&
  357. isset ($_SESSION['bd_prefix']);
  358. $conn = !isset ($_SESSION['bd_error']) || !$_SESSION['bd_error'];
  359. return array (
  360. 'bd' => $bd ? 'ok' : 'ko',
  361. 'conn' => $conn ? 'ok' : 'ko',
  362. 'conf' => $conf ? 'ok' : 'ko',
  363. 'all' => $bd && $conn && $conf ? 'ok' : 'ko'
  364. );
  365. }
  366. function checkBD () {
  367. $error = false;
  368. try {
  369. $str = '';
  370. $driver_options = null;
  371. if($_SESSION['bd_type'] == 'mysql') {
  372. $driver_options = array(
  373. PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
  374. );
  375. // on ouvre une connexion juste pour créer la base si elle n'existe pas
  376. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';';
  377. $c = new PDO ($str,
  378. $_SESSION['bd_user'],
  379. $_SESSION['bd_password'],
  380. $driver_options);
  381. $sql = sprintf (SQL_REQ_CREATE_DB, $_SESSION['bd_base']);
  382. $res = $c->query ($sql);
  383. // on écrase la précédente connexion en sélectionnant la nouvelle BDD
  384. $str = 'mysql:host=' . $_SESSION['bd_host'] . ';dbname=' . $_SESSION['bd_base'];
  385. } elseif($_SESSION['bd_type'] == 'sqlite') {
  386. $str = 'sqlite:' . DATA_PATH . $_SESSION['bd_base'] . '.sqlite';
  387. }
  388. $c = new PDO ($str,
  389. $_SESSION['bd_user'],
  390. $_SESSION['bd_password'],
  391. $driver_options);
  392. $sql = sprintf (SQL_REQ_CAT, $_SESSION['bd_prefix_user']);
  393. $res = $c->query ($sql);
  394. if (!$res) {
  395. $error = true;
  396. }
  397. $sql = sprintf (SQL_REQ_FEED, $_SESSION['bd_prefix_user'], $_SESSION['bd_prefix_user']);
  398. $res = $c->query ($sql);
  399. if (!$res) {
  400. $error = true;
  401. }
  402. $sql = sprintf (SQL_REQ_ENTRY, $_SESSION['bd_prefix_user'], $_SESSION['bd_prefix_user']);
  403. $res = $c->query ($sql);
  404. if (!$res) {
  405. $error = true;
  406. }
  407. } catch (PDOException $e) {
  408. $error = true;
  409. }
  410. if ($error && file_exists (DATA_PATH . '/application.ini')) {
  411. unlink (DATA_PATH . '/application.ini');
  412. }
  413. return !$error;
  414. }
  415. /*** AFFICHAGE ***/
  416. function printStep0 () {
  417. global $actual;
  418. ?>
  419. <?php $s0 = checkStep0 (); if ($s0['all'] == 'ok') { ?>
  420. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('language_defined'); ?></p>
  421. <?php } ?>
  422. <form action="index.php?step=0" method="post">
  423. <legend><?php echo _t ('choose_language'); ?></legend>
  424. <div class="form-group">
  425. <label class="group-name" for="language"><?php echo _t ('language'); ?></label>
  426. <div class="group-controls">
  427. <select name="language" id="language">
  428. <?php $languages = availableLanguages (); ?>
  429. <?php foreach ($languages as $short => $lib) { ?>
  430. <option value="<?php echo $short; ?>"<?php echo $actual == $short ? ' selected="selected"' : ''; ?>><?php echo $lib; ?></option>
  431. <?php } ?>
  432. </select>
  433. </div>
  434. </div>
  435. <div class="form-group form-actions">
  436. <div class="group-controls">
  437. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  438. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  439. <?php if ($s0['all'] == 'ok') { ?>
  440. <a class="btn btn-important next-step" href="?step=1"><?php echo _t ('next_step'); ?></a>
  441. <?php } ?>
  442. </div>
  443. </div>
  444. </form>
  445. <?php
  446. }
  447. function printStep1 () {
  448. $res = checkStep1 ();
  449. ?>
  450. <noscript><p class="alert alert-warn"><span class="alert-head"><?php echo _t ('attention'); ?></span> <?php echo _t ('javascript_is_better'); ?></p></noscript>
  451. <?php if ($res['php'] == 'ok') { ?>
  452. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('php_is_ok', PHP_VERSION); ?></p>
  453. <?php } else { ?>
  454. <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>
  455. <?php } ?>
  456. <?php if ($res['minz'] == 'ok') { ?>
  457. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('minz_is_ok'); ?></p>
  458. <?php } else { ?>
  459. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('minz_is_nok', LIB_PATH . '/Minz'); ?></p>
  460. <?php } ?>
  461. <?php if ($res['curl'] == 'ok') { ?>
  462. <?php $version = curl_version(); ?>
  463. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('curl_is_ok', $version['version']); ?></p>
  464. <?php } else { ?>
  465. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('curl_is_nok'); ?></p>
  466. <?php } ?>
  467. <?php if ($res['pdo-mysql'] == 'ok') { ?>
  468. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('pdomysql_is_ok'); ?></p>
  469. <?php } else { ?>
  470. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('pdomysql_is_nok'); ?></p>
  471. <?php } ?>
  472. <?php if ($res['dom'] == 'ok') { ?>
  473. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('dom_is_ok'); ?></p>
  474. <?php } else { ?>
  475. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('dom_is_nok'); ?></p>
  476. <?php } ?>
  477. <?php if ($res['data'] == 'ok') { ?>
  478. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('data_is_ok'); ?></p>
  479. <?php } else { ?>
  480. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', DATA_PATH); ?></p>
  481. <?php } ?>
  482. <?php if ($res['cache'] == 'ok') { ?>
  483. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('cache_is_ok'); ?></p>
  484. <?php } else { ?>
  485. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', CACHE_PATH); ?></p>
  486. <?php } ?>
  487. <?php if ($res['log'] == 'ok') { ?>
  488. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('log_is_ok'); ?></p>
  489. <?php } else { ?>
  490. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', LOG_PATH); ?></p>
  491. <?php } ?>
  492. <?php if ($res['favicons'] == 'ok') { ?>
  493. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('favicons_is_ok'); ?></p>
  494. <?php } else { ?>
  495. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('file_is_nok', DATA_PATH . '/favicons'); ?></p>
  496. <?php } ?>
  497. <?php if ($res['all'] == 'ok') { ?>
  498. <a class="btn btn-important next-step" href="?step=2"><?php echo _t ('next_step'); ?></a>
  499. <?php } else { ?>
  500. <p class="alert alert-error"><?php echo _t ('fix_errors_before'); ?></p>
  501. <?php } ?>
  502. <?php
  503. }
  504. function printStep2 () {
  505. ?>
  506. <?php $s2 = checkStep2 (); if ($s2['all'] == 'ok') { ?>
  507. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('general_conf_is_ok'); ?></p>
  508. <?php } ?>
  509. <form action="index.php?step=2" method="post">
  510. <legend><?php echo _t ('general_configuration'); ?></legend>
  511. <?php
  512. $url = substr ($_SERVER['PHP_SELF'], 0, -10);
  513. ?>
  514. <div class="form-group">
  515. <label class="group-name" for="title"><?php echo _t ('title'); ?></label>
  516. <div class="group-controls">
  517. <input type="text" id="title" name="title" value="<?php echo isset ($_SESSION['title']) ? $_SESSION['title'] : _t ('freshrss'); ?>" />
  518. </div>
  519. </div>
  520. <div class="form-group">
  521. <label class="group-name" for="old_entries"><?php echo _t ('delete_articles_every'); ?></label>
  522. <div class="group-controls">
  523. <input type="number" id="old_entries" name="old_entries" value="<?php echo isset ($_SESSION['old_entries']) ? $_SESSION['old_entries'] : '3'; ?>" /> <?php echo _t ('month'); ?>
  524. </div>
  525. </div>
  526. <div class="form-group">
  527. <label class="group-name" for="default_user"><?php echo _t ('default_user'); ?></label>
  528. <div class="group-controls">
  529. <input type="text" id="default_user" name="default_user" maxlength="16" value="<?php echo isset ($_SESSION['default_user']) ? $_SESSION['default_user'] : ''; ?>" placeholder="user1" />
  530. </div>
  531. </div>
  532. <div class="form-group">
  533. <label class="group-name" for="mail_login"><?php echo _t ('persona_connection_email'); ?></label>
  534. <div class="group-controls">
  535. <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'); ?>" />
  536. <noscript><b><?php echo _t ('javascript_should_be_activated'); ?></b></noscript>
  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 ($s2['all'] == 'ok') { ?>
  544. <a class="btn btn-important next-step" href="?step=3"><?php echo _t ('next_step'); ?></a>
  545. <?php } ?>
  546. </div>
  547. </div>
  548. </form>
  549. <?php
  550. }
  551. function printStep3 () {
  552. ?>
  553. <?php $s3 = checkStep3 (); if ($s3['all'] == 'ok') { ?>
  554. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('ok'); ?></span> <?php echo _t ('bdd_conf_is_ok'); ?></p>
  555. <?php } elseif ($s3['conn'] == 'ko') { ?>
  556. <p class="alert alert-error"><span class="alert-head"><?php echo _t ('damn'); ?></span> <?php echo _t ('bdd_conf_is_ko'); ?></p>
  557. <?php } ?>
  558. <form action="index.php?step=3" method="post">
  559. <legend><?php echo _t ('bdd_configuration'); ?></legend>
  560. <div class="form-group">
  561. <label class="group-name" for="type"><?php echo _t ('bdd_type'); ?></label>
  562. <div class="group-controls">
  563. <select name="type" id="type">
  564. <option value="mysql"
  565. <?php echo (isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'mysql') ? 'selected="selected"' : ''; ?>>
  566. MySQL
  567. </option>
  568. <!-- TODO : l'utilisation de SQLite n'est pas encore possible. Pour tester tout de même, décommentez ce bloc
  569. <option value="sqlite"
  570. <?php echo (isset($_SESSION['bd_type']) && $_SESSION['bd_type'] === 'sqlite') ? 'selected="selected"' : ''; ?>>
  571. SQLite
  572. </option>-->
  573. </select>
  574. </div>
  575. </div>
  576. <div class="form-group">
  577. <label class="group-name" for="host"><?php echo _t ('host'); ?></label>
  578. <div class="group-controls">
  579. <input type="text" id="host" name="host" value="<?php echo isset ($_SESSION['bd_host']) ? $_SESSION['bd_host'] : 'localhost'; ?>" />
  580. </div>
  581. </div>
  582. <div class="form-group">
  583. <label class="group-name" for="user"><?php echo _t ('username'); ?></label>
  584. <div class="group-controls">
  585. <input type="text" id="user" name="user" value="<?php echo isset ($_SESSION['bd_user']) ? $_SESSION['bd_user'] : ''; ?>" />
  586. </div>
  587. </div>
  588. <div class="form-group">
  589. <label class="group-name" for="pass"><?php echo _t ('password'); ?></label>
  590. <div class="group-controls">
  591. <input type="password" id="pass" name="pass" value="<?php echo isset ($_SESSION['bd_password']) ? $_SESSION['bd_password'] : ''; ?>" />
  592. </div>
  593. </div>
  594. <div class="form-group">
  595. <label class="group-name" for="base"><?php echo _t ('bdd'); ?></label>
  596. <div class="group-controls">
  597. <input type="text" id="base" name="base" maxlength="64" value="<?php echo isset ($_SESSION['bd_base']) ? $_SESSION['bd_base'] : ''; ?>" placeholder="freshrss" />
  598. </div>
  599. </div>
  600. <div class="form-group">
  601. <label class="group-name" for="prefix"><?php echo _t ('prefix'); ?></label>
  602. <div class="group-controls">
  603. <input type="text" id="prefix" name="prefix" maxlength="16" value="<?php echo isset ($_SESSION['bd_prefix']) ? $_SESSION['bd_prefix'] : 'freshrss_'; ?>" />
  604. </div>
  605. </div>
  606. <div class="form-group form-actions">
  607. <div class="group-controls">
  608. <button type="submit" class="btn btn-important"><?php echo _t ('save'); ?></button>
  609. <button type="reset" class="btn"><?php echo _t ('cancel'); ?></button>
  610. <?php if ($s3['all'] == 'ok') { ?>
  611. <a class="btn btn-important next-step" href="?step=4"><?php echo _t ('next_step'); ?></a>
  612. <?php } ?>
  613. </div>
  614. </div>
  615. </form>
  616. <?php
  617. }
  618. function printStep4 () {
  619. ?>
  620. <p class="alert alert-success"><span class="alert-head"><?php echo _t ('congratulations'); ?></span> <?php echo _t ('installation_is_ok'); ?></p>
  621. <a class="btn btn-important next-step" href="?step=5"><?php echo _t ('finish_installation'); ?></a>
  622. <?php
  623. }
  624. function printStep5 () {
  625. ?>
  626. <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>
  627. <?php
  628. }
  629. checkStep ();
  630. initTranslate ();
  631. switch (STEP) {
  632. case 0:
  633. default:
  634. saveLanguage ();
  635. break;
  636. case 1:
  637. break;
  638. case 2:
  639. saveStep2 ();
  640. break;
  641. case 3:
  642. saveStep3 ();
  643. break;
  644. case 4:
  645. break;
  646. case 5:
  647. deleteInstall ();
  648. break;
  649. }
  650. ?>
  651. <!DOCTYPE html>
  652. <html lang="fr">
  653. <head>
  654. <meta charset="utf-8">
  655. <meta name="viewport" content="initial-scale=1.0">
  656. <title><?php echo _t ('freshrss_installation'); ?></title>
  657. <link rel="stylesheet" type="text/css" media="all" href="themes/default/global.css" />
  658. <link rel="stylesheet" type="text/css" media="all" href="themes/default/freshrss.css" />
  659. </head>
  660. <body>
  661. <div class="header">
  662. <div class="item title">
  663. <h1><a href="index.php"><?php echo _t ('freshrss'); ?></a></h1>
  664. <h2><?php echo _t ('installation_step', STEP); ?></h2>
  665. </div>
  666. </div>
  667. <div id="global">
  668. <ul class="nav nav-list aside">
  669. <li class="nav-header"><?php echo _t ('steps'); ?></li>
  670. <li class="item<?php echo STEP == 0 ? ' active' : ''; ?>"><a href="?step=0"><?php echo _t ('language'); ?></a></li>
  671. <li class="item<?php echo STEP == 1 ? ' active' : ''; ?>"><a href="?step=1"><?php echo _t ('checks'); ?></a></li>
  672. <li class="item<?php echo STEP == 2 ? ' active' : ''; ?>"><a href="?step=2"><?php echo _t ('general_configuration'); ?></a></li>
  673. <li class="item<?php echo STEP == 3 ? ' active' : ''; ?>"><a href="?step=3"><?php echo _t ('bdd_configuration'); ?></a></li>
  674. <li class="item<?php echo STEP == 4 ? ' active' : ''; ?>"><a href="?step=4"><?php echo _t ('this_is_the_end'); ?></a></li>
  675. </ul>
  676. <div class="post">
  677. <?php
  678. switch (STEP) {
  679. case 0:
  680. default:
  681. printStep0 ();
  682. break;
  683. case 1:
  684. printStep1 ();
  685. break;
  686. case 2:
  687. printStep2 ();
  688. break;
  689. case 3:
  690. printStep3 ();
  691. break;
  692. case 4:
  693. printStep4 ();
  694. break;
  695. case 5:
  696. printStep5 ();
  697. break;
  698. }
  699. ?>
  700. </div>
  701. </div>
  702. </body>
  703. </html>