X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=inc%2Fpoche%2FTools.class.php;h=3a792d43acbaf85bdcb45c737953c17e5eab34eb;hb=d5ce28df67fcddfb957ce28424f3e5751f433695;hp=1ff4ba55c90680790d9b9819e9d7dee23d672476;hpb=63c35580c7d60e2278ee6fe9ba2d4440ff0308d6;p=github%2Fwallabag%2Fwallabag.git diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 1ff4ba55..3a792d43 100644 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -77,6 +77,7 @@ class Tools $url = $ref; } } + self::logm('redirect to ' . $url); header('Location: '.$url); exit(); } @@ -169,6 +170,7 @@ class Tools preg_match('#charset="?(.*)"#si', $meta[0], $encoding); # if charset is found set it otherwise, set it to utf-8 $html_charset = (!empty($encoding[1])) ? strtolower($encoding[1]) : 'utf-8'; + if (empty($encoding[1])) $encoding[1] = 'utf-8'; } else { $html_charset = 'utf-8'; $encoding[1] = ''; @@ -197,7 +199,8 @@ class Tools { if (DEBUG_POCHE) { $t = strval(date('Y/m/d_H:i:s')) . ' - ' . $_SERVER["REMOTE_ADDR"] . ' - ' . strval($message) . "\n"; - file_put_contents('./log.txt', $t, FILE_APPEND); + file_put_contents(CACHE . '/log.txt', $t, FILE_APPEND); + error_log('DEBUG POCHE : ' . $message); } } @@ -206,8 +209,43 @@ class Tools return sha1($string . SALT); } - public static function checkVar($var) + public static function checkVar($var, $default = '') { - return ((isset ($_REQUEST["$var"])) ? htmlentities($_REQUEST["$var"]) : ''); + return ((isset ($_REQUEST["$var"])) ? htmlentities($_REQUEST["$var"]) : $default); + } + + public static function getDomain($url) + { + return parse_url($url, PHP_URL_HOST); + } + + public static function getReadingTime($text) { + $word = str_word_count(strip_tags($text)); + $minutes = floor($word / 200); + $seconds = floor($word % 200 / (200 / 60)); + $time = array('minutes' => $minutes, 'seconds' => $seconds); + + return $minutes; + } + + + public static function createMyConfig() + { + $myconfig_file = './inc/poche/myconfig.inc.php'; + + if (!is_writable('./inc/poche/')) { + self::logm('you don\'t have write access to create ./inc/poche/myconfig.inc.php'); + die('You don\'t have write access to create ./inc/poche/myconfig.inc.php.'); + } + + if (!file_exists($myconfig_file)) + { + $fp = fopen($myconfig_file, 'w'); + fwrite($fp, '