aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2014-07-08 21:46:32 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2014-07-08 21:46:32 +0200
commit5425b0dd82863d548f49dcbd81636ed8dabd7866 (patch)
treedb5631725be9be0fc1a179af414041a09de05032 /inc/poche
parent4247b37551ae8aa35840ddadcec1c781a8e56d4b (diff)
downloadwallabag-5425b0dd82863d548f49dcbd81636ed8dabd7866.tar.gz
wallabag-5425b0dd82863d548f49dcbd81636ed8dabd7866.tar.zst
wallabag-5425b0dd82863d548f49dcbd81636ed8dabd7866.zip
new fields in database, reading time / date and domain name are stored
Diffstat (limited to 'inc/poche')
-rwxr-xr-xinc/poche/Database.class.php23
-rwxr-xr-xinc/poche/Poche.class.php8
-rwxr-xr-xinc/poche/Tools.class.php14
3 files changed, 21 insertions, 24 deletions
diff --git a/inc/poche/Database.class.php b/inc/poche/Database.class.php
index dddb2512..a222ed39 100755
--- a/inc/poche/Database.class.php
+++ b/inc/poche/Database.class.php
@@ -398,6 +398,21 @@ class Database {
398 return $query; 398 return $query;
399 } 399 }
400 400
401
402 private function _getDomain($url)
403 {
404 return parse_url($url, PHP_URL_HOST);
405 }
406
407 private function _getReadingTime($text) {
408 $word = str_word_count(strip_tags($text));
409 $minutes = floor($word / 200);
410 $seconds = floor($word % 200 / (200 / 60));
411 $time = array('minutes' => $minutes, 'seconds' => $seconds);
412
413 return $minutes;
414 }
415
401 /** 416 /**
402 * 417 *
403 * @param string $url 418 * @param string $url
@@ -407,8 +422,12 @@ class Database {
407 * @return integer $id of inserted record 422 * @return integer $id of inserted record
408 */ 423 */
409 public function add($url, $title, $content, $user_id, $isFavorite=0, $isRead=0) { 424 public function add($url, $title, $content, $user_id, $isFavorite=0, $isRead=0) {
410 $sql_action = 'INSERT INTO entries ( url, title, content, user_id, is_fav, is_read ) VALUES (?, ?, ?, ?, ?, ?)'; 425 $readingTime = $this->_getReadingTime($content);
411 $params_action = array($url, $title, $content, $user_id, $isFavorite, $isRead); 426 $domainName = $this->_getDomain($url);
427 $date = date('Y-m-d H:i:s');
428
429 $sql_action = 'INSERT INTO entries ( url, title, content, user_id, is_fav, is_read, date, reading_time, domain_name ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)';
430 $params_action = array($url, $title, $content, $user_id, $isFavorite, $isRead, $date, $readingTime, $domainName);
412 if ( !$this->executeQuery($sql_action, $params_action) ) { 431 if ( !$this->executeQuery($sql_action, $params_action) ) {
413 $id = null; 432 $id = null;
414 } 433 }
diff --git a/inc/poche/Poche.class.php b/inc/poche/Poche.class.php
index 09a9f5ff..e8c32024 100755
--- a/inc/poche/Poche.class.php
+++ b/inc/poche/Poche.class.php
@@ -232,14 +232,6 @@ class Poche
232 232
233 $this->tpl = new Twig_Environment($loaderChain, $twigParams); 233 $this->tpl = new Twig_Environment($loaderChain, $twigParams);
234 $this->tpl->addExtension(new Twig_Extensions_Extension_I18n()); 234 $this->tpl->addExtension(new Twig_Extensions_Extension_I18n());
235
236 # filter to display domain name of an url
237 $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain');
238 $this->tpl->addFilter($filter);
239
240 # filter for reading time
241 $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime');
242 $this->tpl->addFilter($filter);
243 } 235 }
244 236
245 public function createNewUser() { 237 public function createNewUser() {
diff --git a/inc/poche/Tools.class.php b/inc/poche/Tools.class.php
index 1ef875c9..13f48903 100755
--- a/inc/poche/Tools.class.php
+++ b/inc/poche/Tools.class.php
@@ -214,20 +214,6 @@ class Tools
214 return ((isset ($_REQUEST["$var"])) ? htmlentities($_REQUEST["$var"]) : $default); 214 return ((isset ($_REQUEST["$var"])) ? htmlentities($_REQUEST["$var"]) : $default);
215 } 215 }
216 216
217 public static function getDomain($url)
218 {
219 return parse_url($url, PHP_URL_HOST);
220 }
221
222 public static function getReadingTime($text) {
223 $word = str_word_count(strip_tags($text));
224 $minutes = floor($word / 200);
225 $seconds = floor($word % 200 / (200 / 60));
226 $time = array('minutes' => $minutes, 'seconds' => $seconds);
227
228 return $minutes;
229 }
230
231 public static function getDocLanguage($userlanguage) { 217 public static function getDocLanguage($userlanguage) {
232 $lang = explode('.', $userlanguage); 218 $lang = explode('.', $userlanguage);
233 return str_replace('_', '-', $lang[0]); 219 return str_replace('_', '-', $lang[0]);