]> git.immae.eu Git - github/wallabag/wallabag.git/blame - install/install_functions.php
improvements for the installer
[github/wallabag/wallabag.git] / install / install_functions.php
CommitLineData
6fa7d088 1<?php
3602405e
NL
2/**
3 * wallabag, self hostable application allowing you to not miss any content anymore
4 *
5 * @category wallabag
6 * @author Nicolas Lœuillet <nicolas@loeuillet.org>
7 * @copyright 2013
8 * @license http://opensource.org/licenses/MIT see COPYING file
9 */
10
444f1406 11function status() {
d6073305 12$app_name = 'wallabag';
6fa7d088 13
35252364 14$php_ok = (function_exists('version_compare') && version_compare(phpversion(), '5.3.3', '>='));
444f1406 15$pdo_ok = class_exists('PDO');
6fa7d088
NL
16$pcre_ok = extension_loaded('pcre');
17$zlib_ok = extension_loaded('zlib');
18$mbstring_ok = extension_loaded('mbstring');
ace42866 19$dom_ok = extension_loaded('DOM');
6fa7d088
NL
20$iconv_ok = extension_loaded('iconv');
21$tidy_ok = function_exists('tidy_parse_string');
22$curl_ok = function_exists('curl_exec');
becc5bfb 23$parse_ini_ok = function_exists('parse_ini_file');
6fa7d088
NL
24$parallel_ok = ((extension_loaded('http') && class_exists('HttpRequestPool')) || ($curl_ok && function_exists('curl_multi_init')));
25$allow_url_fopen_ok = (bool)ini_get('allow_url_fopen');
26$filter_ok = extension_loaded('filter');
d6073305 27$gettext_ok = function_exists("gettext");
bbfe6fa5 28$gd_ok = extension_loaded('gd');
8d7ec546
TC
29$pdo_drivers = pdoDrivers();
30$pdo_drivers_passing = $pdo_drivers['sqlite'] || $pdo_drivers['mysql'] || $pdo_drivers['postgres'];
31
32
6fa7d088
NL
33
34if (extension_loaded('xmlreader')) {
35 $xml_ok = true;
36} elseif (extension_loaded('xml')) {
37 $parser_check = xml_parser_create();
38 xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
39 xml_parser_free($parser_check);
40 $xml_ok = isset($values[0]['value']);
41} else {
42 $xml_ok = false;
43}
44
8d7ec546
TC
45$status = array('app_name' => $app_name, 'php' => $php_ok, 'pdo' => $pdo_ok,
46 'pdo_drivers_passing' => $pdo_drivers_passing, 'xml' => $xml_ok, 'pcre' => $pcre_ok,
47 'zlib' => $zlib_ok, 'mbstring' => $mbstring_ok, 'dom' => $dom_ok, 'iconv' => $iconv_ok, 'tidy' => $tidy_ok, 'curl' => $curl_ok,
48 'parse_ini' => $parse_ini_ok, 'parallel' => $parallel_ok, 'allow_url_fopen' => $allow_url_fopen_ok, 'filter' => $filter_ok,
49 'gettext' => $gettext_ok, 'gd' => $gd_ok);
6fa7d088 50
444f1406 51return $status;
6fa7d088 52}
444f1406
TC
53function isOkay() {
54 return !in_array(false, status());
6fa7d088 55}
d6073305 56
444f1406
TC
57function isPassing() {
58 $status = status();
59 unset($status['curl'], $status['parallel'], $status['tidy'], $status['gd'], $status['filter']);
60 return !in_array(false, $status);
d6073305 61}
6fa7d088 62
8d7ec546
TC
63function pdoDrivers() {
64 $pdo_driver_sqlite = extension_loaded('pdo_sqlite');
65 $pdo_driver_mysql = extension_loaded('pdo_mysql');
66 $pdo_driver_postgres = extension_loaded('pdo_pgsql');
67
68 $pdo_drivers = array('sqlite' => $pdo_driver_sqlite, 'mysql' => $pdo_driver_mysql,
69 'postgres' => $pdo_driver_postgres);
70
71 return $pdo_drivers;
72}
73
ca056e7f
TC
74/* Function taken from at http://php.net/manual/en/function.rmdir.php#110489
75 * Idea : nbari at dalmp dot com
76 * Rights unknown
77 * Here in case of .gitignore files
78 */
79
80function delTree($dir) {
81 $files = array_diff(scandir($dir), array('.','..'));
82 foreach ($files as $file) {
83 (is_dir("$dir/$file")) ? delTree("$dir/$file") : unlink("$dir/$file");
84 }
85 return rmdir($dir);
86 }
87
88function generate_salt() {
89 mt_srand(microtime(true)*100000 + memory_get_usage(true));
90 return md5(uniqid(mt_rand(), true));
91}
92
93function executeQuery($handle, $sql, $params) {
94 try
95 {
96 $query = $handle->prepare($sql);
97 $query->execute($params);
98 return $query->fetchAll();
99 }
100 catch (Exception $e)
101 {
102 return FALSE;
103 }
104}
105
444f1406 106?>