1
0
Fork 0
mirror of https://github.com/wallabag/wallabag.git synced 2025-09-15 18:57:05 +00:00

new fields in database, reading time / date and domain name are stored

This commit is contained in:
Nicolas Lœuillet 2014-07-08 21:46:32 +02:00
parent 4247b37551
commit 5425b0dd82
5 changed files with 26 additions and 28 deletions

View file

@ -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;
}

View file

@ -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() {

View file

@ -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]);