From 5425b0dd82863d548f49dcbd81636ed8dabd7866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20L=C5=93uillet?= Date: Tue, 8 Jul 2014 21:46:32 +0200 Subject: [PATCH] new fields in database, reading time / date and domain name are stored --- inc/poche/Database.class.php | 23 +++++++++++++++++++++-- inc/poche/Poche.class.php | 8 -------- inc/poche/Tools.class.php | 14 -------------- install/poche.sqlite | Bin 393216 -> 393216 bytes themes/baggy/home.twig | 9 +++++---- 5 files changed, 26 insertions(+), 28 deletions(-) mode change 100755 => 100644 install/poche.sqlite diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php index dddb251..a222ed3 100755 --- a/inc/poche/Database.class.php +++ b/inc/poche/Database.class.php @@ -398,6 +398,21 @@ 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 @@ -407,8 +422,12 @@ class Database { * @return integer $id of inserted record */ public function add($url, $title, $content, $user_id, $isFavorite=0, $isRead=0) { - $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); + $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, 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 09a9f5f..e8c3202 100755 --- a/inc/poche/Poche.class.php +++ b/inc/poche/Poche.class.php @@ -232,14 +232,6 @@ 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 1ef875c..13f4890 100755 --- a/inc/poche/Tools.class.php +++ b/inc/poche/Tools.class.php @@ -214,20 +214,6 @@ 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]); diff --git a/install/poche.sqlite b/install/poche.sqlite old mode 100755 new mode 100644 index f2b79b68f2480a6fa0ec923f225b6a24c880ed54..4c0f8139590fb16a67392e0e1f2ccba17baf912c GIT binary patch delta 3209 zcmcImO>7fK6ka>de<`4f280l!MJYwfW@9IqggO=mk~V4xG!3Yi${O#Eok{nPo!$Hp zU<^XsTCt)ks(Q(xQWdz=qUwR38mpJ8hpLCRs(PqEYVRCqZ|$31+ld3AP^q>OkKc~p zy!XEEeQ(O;-R1J`8+&(7N|N*f{MBE3g1*5$lalg#%eLjyQuh**F8_AvJ#O-2%k!7F zR~CP|khoNm4hF%2uB%77+I#lyja?hN`NQ&U-iKrzdqhSjb2DQz6Q{<&pxLHLERV_P z_~hy1U@)mk^4^jI+s@^tPrQ+v2BS-`POVbjgNHJjn3@@TeN5OX%R7F-pjyL-PL7S| z&Q8vt0eGz2CZ<;2!s1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&v)IEOX{$U*#i~s@%AbS}{kN*8Dcj;U(0tg_000IagfB*srAbd{}=|NRaJ;-d&4fB*srAb

{{ entry.title|raw }}

- {% if entry.content| getReadingTime > 0 %} - +
{{ entry.date }}
+ {% if entry.reading_time > 0 %} +
{% else %} - + {% endif %}

{{ entry.content|striptags|slice(0, 300) }}...