From 6400371ff93782d25cdbd50aa224c70145b3890a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Thu, 10 Jul 2014 13:17:04 +0200 Subject: I removed my previous commit. We have to create a new branch for that. --- inc/poche/Database.class.php | 22 ++-------------------- inc/poche/Poche.class.php | 8 ++++++++ inc/poche/Tools.class.php | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 20 deletions(-) (limited to 'inc/poche') diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index a222ed39..11cccb72 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -398,21 +398,6 @@ class Database { return $query; } - - private function _getDomain($url) - { - return parse_url($url, PHP_URL_HOST); - } - - private 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; - } - /** * * @param string $url @@ -422,12 +407,9 @@ class Database { * @return integer $id of inserted record */ public function add($url, $title, $content, $user_id, $isFavorite=0, $isRead=0) { - $readingTime = $this->_getReadingTime($content); - $domainName = $this->_getDomain($url); - $date = date('Y-m-d H:i:s'); + $sql_action = 'INSERT INTO entries ( url, title, content, user_id, is_fav, is_read ) VALUES (?, ?, ?, ?, ?, ?)'; + $params_action = array($url, $title, $content, $user_id, $isFavorite, $isRead); - $sql_action = 'INSERT INTO entries ( url, title, content, user_id, is_fav, is_read, date, reading_time, domain_name ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)'; - $params_action = array($url, $title, $content, $user_id, $isFavorite, $isRead, $date, $readingTime, $domainName); if ( !$this->executeQuery($sql_action, $params_action) ) { $id = null; } diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php index e8c32024..09a9f5ff 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -232,6 +232,14 @@ class Poche $this->tpl = new Twig_Environment($loaderChain, $twigParams); $this->tpl->addExtension(new Twig_Extensions_Extension_I18n()); + + # filter to display domain name of an url + $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain'); + $this->tpl->addFilter($filter); + + # filter for reading time + $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime'); + $this->tpl->addFilter($filter); } public function createNewUser() { diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php index 13f48903..cc01f403 100755 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -214,6 +214,20 @@ class Tools 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 getDocLanguage($userlanguage) { $lang = explode('.', $userlanguage); return str_replace('_', '-', $lang[0]); -- cgit v1.2.3