aboutsummaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/Category.php2
-rw-r--r--app/Models/CategoryDAO.php2
-rw-r--r--app/Models/Entry.php5
-rw-r--r--app/Models/EntryDAO.php38
-rw-r--r--app/Models/EntryDAOSQLite.php17
-rw-r--r--app/Models/Feed.php15
-rw-r--r--app/Models/FeedDAO.php4
7 files changed, 48 insertions, 35 deletions
diff --git a/app/Models/Category.php b/app/Models/Category.php
index 9a44a2d09..197faf942 100644
--- a/app/Models/Category.php
+++ b/app/Models/Category.php
@@ -68,7 +68,7 @@ class FreshRSS_Category extends Minz_Model {
$this->id = $value;
}
public function _name($value) {
- $this->name = substr(trim($value), 0, 255);
+ $this->name = mb_strcut(trim($value), 0, 255, 'UTF-8');
}
public function _feeds($values) {
if (!is_array($values)) {
diff --git a/app/Models/CategoryDAO.php b/app/Models/CategoryDAO.php
index ef2c402a0..cf6b3bae3 100644
--- a/app/Models/CategoryDAO.php
+++ b/app/Models/CategoryDAO.php
@@ -9,7 +9,7 @@ class FreshRSS_CategoryDAO extends Minz_ModelPdo implements FreshRSS_Searchable
$stm = $this->bd->prepare($sql);
$values = array(
- substr($valuesTmp['name'], 0, 255),
+ mb_strcut($valuesTmp['name'], 0, 255, 'UTF-8'),
);
if ($stm && $stm->execute($values)) {
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index 2b6059638..ccbad5724 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -31,6 +31,7 @@ class FreshRSS_Entry extends Minz_Model {
$this->_isRead($is_read);
$this->_isFavorite($is_favorite);
$this->_feedId($feedId);
+ $tags = mb_strcut($tags, 0, 1023, 'UTF-8');
$this->_tags(preg_split('/[\s#]/', $tags));
$this->_guid($guid);
}
@@ -123,11 +124,11 @@ class FreshRSS_Entry extends Minz_Model {
}
public function _title($value) {
$this->hash = null;
- $this->title = $value;
+ $this->title = mb_strcut($value, 0, 255, 'UTF-8');
}
public function _author($value) {
$this->hash = null;
- $this->author = $value;
+ $this->author = mb_strcut($value, 0, 255, 'UTF-8');
}
public function _content($value) {
$this->hash = null;
diff --git a/app/Models/EntryDAO.php b/app/Models/EntryDAO.php
index 59f826c3e..f0e164995 100644
--- a/app/Models/EntryDAO.php
+++ b/app/Models/EntryDAO.php
@@ -160,9 +160,9 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$valuesTmp['guid'] = substr($valuesTmp['guid'], 0, 760);
$valuesTmp['guid'] = safe_ascii($valuesTmp['guid']);
$this->addEntryPrepared->bindParam(':guid', $valuesTmp['guid']);
- $valuesTmp['title'] = substr($valuesTmp['title'], 0, 255);
+ $valuesTmp['title'] = mb_strcut($valuesTmp['title'], 0, 255, 'UTF-8');
$this->addEntryPrepared->bindParam(':title', $valuesTmp['title']);
- $valuesTmp['author'] = substr($valuesTmp['author'], 0, 255);
+ $valuesTmp['author'] = mb_strcut($valuesTmp['author'], 0, 255, 'UTF-8');
$this->addEntryPrepared->bindParam(':author', $valuesTmp['author']);
$this->addEntryPrepared->bindParam(':content', $valuesTmp['content']);
$valuesTmp['link'] = substr($valuesTmp['link'], 0, 1023);
@@ -176,7 +176,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$valuesTmp['is_favorite'] = $valuesTmp['is_favorite'] ? 1 : 0;
$this->addEntryPrepared->bindParam(':is_favorite', $valuesTmp['is_favorite'], PDO::PARAM_INT);
$this->addEntryPrepared->bindParam(':id_feed', $valuesTmp['id_feed'], PDO::PARAM_INT);
- $valuesTmp['tags'] = substr($valuesTmp['tags'], 0, 1023);
+ $valuesTmp['tags'] = mb_strcut($valuesTmp['tags'], 0, 1023, 'UTF-8');
$this->addEntryPrepared->bindParam(':tags', $valuesTmp['tags']);
if ($this->hasNativeHex()) {
@@ -243,9 +243,9 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$valuesTmp['guid'] = substr($valuesTmp['guid'], 0, 760);
$this->updateEntryPrepared->bindParam(':guid', $valuesTmp['guid']);
- $valuesTmp['title'] = substr($valuesTmp['title'], 0, 255);
+ $valuesTmp['title'] = mb_strcut($valuesTmp['title'], 0, 255, 'UTF-8');
$this->updateEntryPrepared->bindParam(':title', $valuesTmp['title']);
- $valuesTmp['author'] = substr($valuesTmp['author'], 0, 255);
+ $valuesTmp['author'] = mb_strcut($valuesTmp['author'], 0, 255, 'UTF-8');
$this->updateEntryPrepared->bindParam(':author', $valuesTmp['author']);
$this->updateEntryPrepared->bindParam(':content', $valuesTmp['content']);
$valuesTmp['link'] = substr($valuesTmp['link'], 0, 1023);
@@ -258,7 +258,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$this->updateEntryPrepared->bindValue(':is_read', $valuesTmp['is_read'] ? 1 : 0, PDO::PARAM_INT);
}
$this->updateEntryPrepared->bindParam(':id_feed', $valuesTmp['id_feed'], PDO::PARAM_INT);
- $valuesTmp['tags'] = substr($valuesTmp['tags'], 0, 1023);
+ $valuesTmp['tags'] = mb_strcut($valuesTmp['tags'], 0, 1023, 'UTF-8');
$this->updateEntryPrepared->bindParam(':tags', $valuesTmp['tags']);
if ($this->hasNativeHex()) {
@@ -437,7 +437,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @param integer $priorityMin
* @return integer affected rows
*/
- public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filters = null, $state = 0) {
+ public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filters = null, $state = 0, $is_read = true) {
FreshRSS_UserDAO::touch();
if ($idMax == 0) {
$idMax = time() . '000000';
@@ -445,14 +445,14 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
}
$sql = 'UPDATE `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed=f.id '
- . 'SET e.is_read=1 '
- . 'WHERE e.is_read=0 AND e.id <= ?';
+ . 'SET e.is_read=? '
+ . 'WHERE e.is_read <> ? AND e.id <= ?';
if ($onlyFavorites) {
$sql .= ' AND e.is_favorite=1';
} elseif ($priorityMin >= 0) {
$sql .= ' AND f.priority > ' . intval($priorityMin);
}
- $values = array($idMax);
+ $values = array($is_read ? 1 : 0, $is_read ? 1 : 0, $idMax);
list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filters, $state);
@@ -480,7 +480,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @param integer $idMax fail safe article ID
* @return integer affected rows
*/
- public function markReadCat($id, $idMax = 0, $filters = null, $state = 0) {
+ public function markReadCat($id, $idMax = 0, $filters = null, $state = 0, $is_read = true) {
FreshRSS_UserDAO::touch();
if ($idMax == 0) {
$idMax = time() . '000000';
@@ -488,9 +488,9 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
}
$sql = 'UPDATE `' . $this->prefix . 'entry` e INNER JOIN `' . $this->prefix . 'feed` f ON e.id_feed=f.id '
- . 'SET e.is_read=1 '
- . 'WHERE f.category=? AND e.is_read=0 AND e.id <= ?';
- $values = array($id, $idMax);
+ . 'SET e.is_read=? '
+ . 'WHERE f.category=? AND e.is_read <> ? AND e.id <= ?';
+ $values = array($is_read ? 1 : 0, $id, $is_read ? 1 : 0, $idMax);
list($searchValues, $search) = $this->sqlListEntriesWhere('e.', $filters, $state);
@@ -518,7 +518,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
* @param integer $idMax fail safe article ID
* @return integer affected rows
*/
- public function markReadFeed($id_feed, $idMax = 0, $filters = null, $state = 0) {
+ public function markReadFeed($id_feed, $idMax = 0, $filters = null, $state = 0, $is_read = true) {
FreshRSS_UserDAO::touch();
if ($idMax == 0) {
$idMax = time() . '000000';
@@ -527,9 +527,9 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$this->bd->beginTransaction();
$sql = 'UPDATE `' . $this->prefix . 'entry` '
- . 'SET is_read=1 '
- . 'WHERE id_feed=? AND is_read=0 AND id <= ?';
- $values = array($id_feed, $idMax);
+ . 'SET is_read=? '
+ . 'WHERE id_feed=? AND is_read <> ? AND id <= ?';
+ $values = array($is_read ? 1 : 0, $id_feed, $is_read ? 1 : 0, $idMax);
list($searchValues, $search) = $this->sqlListEntriesWhere('', $filters, $state);
@@ -909,6 +909,7 @@ class FreshRSS_EntryDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$stm = $this->bd->prepare($sql);
$stm->execute();
$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
+ rsort($res);
$all = empty($res[0]) ? 0 : $res[0];
$unread = empty($res[1]) ? 0 : $res[1];
return array('all' => $all, 'unread' => $unread, 'read' => $all - $unread);
@@ -963,6 +964,7 @@ SQL;
$stm = $this->bd->prepare($sql);
$stm->execute(array(':priority_normal' => FreshRSS_Feed::PRIORITY_NORMAL));
$res = $stm->fetchAll(PDO::FETCH_COLUMN, 0);
+ rsort($res);
$all = empty($res[0]) ? 0 : $res[0];
$unread = empty($res[1]) ? 0 : $res[1];
return array('all' => $all, 'unread' => $unread, 'read' => $all - $unread);
diff --git a/app/Models/EntryDAOSQLite.php b/app/Models/EntryDAOSQLite.php
index cca970e36..944de8470 100644
--- a/app/Models/EntryDAOSQLite.php
+++ b/app/Models/EntryDAOSQLite.php
@@ -101,6 +101,7 @@ DROP TABLE IF EXISTS `tmp`;
* @return integer affected rows
*/
public function markRead($ids, $is_read = true) {
+ FreshRSS_UserDAO::touch();
if (is_array($ids)) { //Many IDs at once (used by API)
if (true) { //Speed heuristics //TODO: Not implemented yet for SQLite (so always call IDs one by one)
$affected = 0;
@@ -159,19 +160,20 @@ DROP TABLE IF EXISTS `tmp`;
* @param integer $priorityMin
* @return integer affected rows
*/
- public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filters = null, $state = 0) {
+ public function markReadEntries($idMax = 0, $onlyFavorites = false, $priorityMin = 0, $filters = null, $state = 0, $is_read = true) {
+ FreshRSS_UserDAO::touch();
if ($idMax == 0) {
$idMax = time() . '000000';
Minz_Log::debug('Calling markReadEntries(0) is deprecated!');
}
- $sql = 'UPDATE `' . $this->prefix . 'entry` SET is_read=1 WHERE is_read=0 AND id <= ?';
+ $sql = 'UPDATE `' . $this->prefix . 'entry` SET is_read = ? WHERE is_read <> ? AND id <= ?';
if ($onlyFavorites) {
$sql .= ' AND is_favorite=1';
} elseif ($priorityMin >= 0) {
$sql .= ' AND id_feed IN (SELECT f.id FROM `' . $this->prefix . 'feed` f WHERE f.priority > ' . intval($priorityMin) . ')';
}
- $values = array($idMax);
+ $values = array($is_read ? 1 : 0, $is_read ? 1 : 0, $idMax);
list($searchValues, $search) = $this->sqlListEntriesWhere('', $filters, $state);
@@ -199,17 +201,18 @@ DROP TABLE IF EXISTS `tmp`;
* @param integer $idMax fail safe article ID
* @return integer affected rows
*/
- public function markReadCat($id, $idMax = 0, $filters = null, $state = 0) {
+ public function markReadCat($id, $idMax = 0, $filters = null, $state = 0, $is_read = true) {
+ FreshRSS_UserDAO::touch();
if ($idMax == 0) {
$idMax = time() . '000000';
Minz_Log::debug('Calling markReadCat(0) is deprecated!');
}
$sql = 'UPDATE `' . $this->prefix . 'entry` '
- . 'SET is_read=1 '
- . 'WHERE is_read=0 AND id <= ? AND '
+ . 'SET is_read = ? '
+ . 'WHERE is_read <> ? AND id <= ? AND '
. 'id_feed IN (SELECT f.id FROM `' . $this->prefix . 'feed` f WHERE f.category=?)';
- $values = array($idMax, $id);
+ $values = array($is_read ? 1 : 0, $is_read ? 1 : 0, $idMax, $id);
list($searchValues, $search) = $this->sqlListEntriesWhere('', $filters, $state);
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 89eb0a53c..ed381a867 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -59,8 +59,8 @@ class FreshRSS_Feed extends Minz_Model {
return $this->hash;
}
- public function url() {
- return $this->url;
+ public function url($includeCredentials = true) {
+ return $includeCredentials ? $this->url : SimplePie_Misc::url_remove_credentials($this->url);
}
public function selfUrl() {
return $this->selfUrl;
@@ -341,7 +341,7 @@ class FreshRSS_Feed extends Minz_Model {
foreach ($feed->get_items() as $item) {
$title = html_only_entity_decode(strip_tags($item->get_title()));
- $author = $item->get_author();
+ $authors = $item->get_authors();
$link = $item->get_permalink();
$date = @strtotime($item->get_date());
@@ -409,12 +409,19 @@ class FreshRSS_Feed extends Minz_Model {
$guid = $item->get_id(false, false);
$hasUniqueGuids &= empty($guids['_' . $guid]);
$guids['_' . $guid] = true;
+ $author_names = '';
+ if (is_array($authors)) {
+ foreach ($authors as $author) {
+ $author_names .= html_only_entity_decode(strip_tags($author->name == '' ? $author->email : $author->name)) . ', ';
+ }
+ }
+ $author_names = substr($author_names, 0, -2);
$entry = new FreshRSS_Entry(
$this->id(),
$guid,
$title === null ? '' : $title,
- $author === null ? '' : html_only_entity_decode(strip_tags($author->name == null ? $author->email : $author->name)),
+ $author_names,
$content === null ? '' : $content,
$link === null ? '' : $link,
$date ? $date : time()
diff --git a/app/Models/FeedDAO.php b/app/Models/FeedDAO.php
index 9d980c139..285f17193 100644
--- a/app/Models/FeedDAO.php
+++ b/app/Models/FeedDAO.php
@@ -55,9 +55,9 @@ class FreshRSS_FeedDAO extends Minz_ModelPdo implements FreshRSS_Searchable {
$values = array(
substr($valuesTmp['url'], 0, 511),
$valuesTmp['category'],
- substr($valuesTmp['name'], 0, 255),
+ mb_strcut($valuesTmp['name'], 0, 255, 'UTF-8'),
substr($valuesTmp['website'], 0, 255),
- substr($valuesTmp['description'], 0, 1023),
+ mb_strcut($valuesTmp['description'], 0, 1023, 'UTF-8'),
$valuesTmp['lastUpdate'],
base64_encode($valuesTmp['httpAuth']),
FreshRSS_Feed::KEEP_HISTORY_DEFAULT,