aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/poche/Database.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/poche/Database.class.php')
-rwxr-xr-xinc/poche/Database.class.php23
1 files changed, 21 insertions, 2 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 }