aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Entry.php
diff options
context:
space:
mode:
authorGravatar Clément <clement@selfhost.fr> 2017-02-15 14:14:03 +0100
committerGravatar Clément <clement@selfhost.fr> 2017-02-15 14:14:03 +0100
commit5a1bb1393b4496eb35a2ffb3cc63d41c9dc1e2e5 (patch)
tree67028e45792c575c25c92616633f64cc7a4a13eb /app/Models/Entry.php
parent7e949d50320317b5c3b5a2da2bdaf324e794b2f7 (diff)
parent5f637bd816b7323885bfe1751a1724ee59a822f6 (diff)
Merge remote-tracking branch 'FreshRSS/master'
Diffstat (limited to 'app/Models/Entry.php')
-rw-r--r--app/Models/Entry.php167
1 files changed, 94 insertions, 73 deletions
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index a6c67221b..a562a963a 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -1,6 +1,11 @@
<?php
class FreshRSS_Entry extends Minz_Model {
+ const STATE_READ = 1;
+ const STATE_NOT_READ = 2;
+ const STATE_ALL = 3;
+ const STATE_FAVORITE = 4;
+ const STATE_NOT_FAVORITE = 8;
private $id = 0;
private $guid;
@@ -9,139 +14,154 @@ class FreshRSS_Entry extends Minz_Model {
private $content;
private $link;
private $date;
- private $is_read;
+ private $hash = null;
+ private $is_read; //Nullable boolean
private $is_favorite;
private $feed;
private $tags;
- public function __construct ($feed = '', $guid = '', $title = '', $author = '', $content = '',
- $link = '', $pubdate = 0, $is_read = false, $is_favorite = false, $tags = '') {
- $this->_guid ($guid);
- $this->_title ($title);
- $this->_author ($author);
- $this->_content ($content);
- $this->_link ($link);
- $this->_date ($pubdate);
- $this->_isRead ($is_read);
- $this->_isFavorite ($is_favorite);
- $this->_feed ($feed);
- $this->_tags (preg_split('/[\s#]/', $tags));
+ public function __construct($feed = '', $guid = '', $title = '', $author = '', $content = '',
+ $link = '', $pubdate = 0, $is_read = false, $is_favorite = false, $tags = '') {
+ $this->_guid($guid);
+ $this->_title($title);
+ $this->_author($author);
+ $this->_content($content);
+ $this->_link($link);
+ $this->_date($pubdate);
+ $this->_isRead($is_read);
+ $this->_isFavorite($is_favorite);
+ $this->_feed($feed);
+ $this->_tags(preg_split('/[\s#]/', $tags));
}
- public function id () {
+ public function id() {
return $this->id;
}
- public function guid () {
+ public function guid() {
return $this->guid;
}
- public function title () {
+ public function title() {
return $this->title;
}
- public function author () {
+ public function author() {
return $this->author === null ? '' : $this->author;
}
- public function content () {
+ public function content() {
return $this->content;
}
- public function link () {
+ public function link() {
return $this->link;
}
- public function date ($raw = false) {
+ public function date($raw = false) {
if ($raw) {
return $this->date;
} else {
- return timestamptodate ($this->date);
+ return timestamptodate($this->date);
}
}
- public function dateAdded ($raw = false) {
+ public function dateAdded($raw = false) {
$date = intval(substr($this->id, 0, -6));
if ($raw) {
return $date;
} else {
- return timestamptodate ($date);
+ return timestamptodate($date);
}
}
- public function isRead () {
+ public function isRead() {
return $this->is_read;
}
- public function isFavorite () {
+ public function isFavorite() {
return $this->is_favorite;
}
- public function feed ($object = false) {
+ public function feed($object = false) {
if ($object) {
- $feedDAO = new FreshRSS_FeedDAO ();
- return $feedDAO->searchById ($this->feed);
+ $feedDAO = FreshRSS_Factory::createFeedDao();
+ return $feedDAO->searchById($this->feed);
} else {
return $this->feed;
}
}
- public function tags ($inString = false) {
+ public function tags($inString = false) {
if ($inString) {
- return empty ($this->tags) ? '' : '#' . implode(' #', $this->tags);
+ return empty($this->tags) ? '' : '#' . implode(' #', $this->tags);
} else {
return $this->tags;
}
}
- public function _id ($value) {
+ public function hash() {
+ if ($this->hash === null) {
+ //Do not include $this->date because it may be automatically generated when lacking
+ $this->hash = md5($this->link . $this->title . $this->author . $this->content . $this->tags(true));
+ }
+ return $this->hash;
+ }
+
+ public function _id($value) {
$this->id = $value;
}
- public function _guid ($value) {
+ public function _guid($value) {
$this->guid = $value;
}
- public function _title ($value) {
+ public function _title($value) {
+ $this->hash = null;
$this->title = $value;
}
- public function _author ($value) {
+ public function _author($value) {
+ $this->hash = null;
$this->author = $value;
}
- public function _content ($value) {
+ public function _content($value) {
+ $this->hash = null;
$this->content = $value;
}
- public function _link ($value) {
+ public function _link($value) {
+ $this->hash = null;
$this->link = $value;
}
- public function _date ($value) {
+ public function _date($value) {
+ $this->hash = null;
$value = intval($value);
$this->date = $value > 1 ? $value : time();
}
- public function _isRead ($value) {
- $this->is_read = $value;
+ public function _isRead($value) {
+ $this->is_read = $value === null ? null : (bool)$value;
}
- public function _isFavorite ($value) {
+ public function _isFavorite($value) {
$this->is_favorite = $value;
}
- public function _feed ($value) {
+ public function _feed($value) {
$this->feed = $value;
}
- public function _tags ($value) {
- if (!is_array ($value)) {
- $value = array ($value);
+ public function _tags($value) {
+ $this->hash = null;
+ if (!is_array($value)) {
+ $value = array($value);
}
foreach ($value as $key => $t) {
if (!$t) {
- unset ($value[$key]);
+ unset($value[$key]);
}
}
$this->tags = $value;
}
- public function isDay ($day, $today) {
+ public function isDay($day, $today) {
$date = $this->dateAdded(true);
switch ($day) {
- case FreshRSS_Days::TODAY:
- $tomorrow = $today + 86400;
- return $date >= $today && $date < $tomorrow;
- case FreshRSS_Days::YESTERDAY:
- $yesterday = $today - 86400;
- return $date >= $yesterday && $date < $today;
- case FreshRSS_Days::BEFORE_YESTERDAY:
- $yesterday = $today - 86400;
- return $date < $yesterday;
- default:
- return false;
+ case FreshRSS_Days::TODAY:
+ $tomorrow = $today + 86400;
+ return $date >= $today && $date < $tomorrow;
+ case FreshRSS_Days::YESTERDAY:
+ $yesterday = $today - 86400;
+ return $date >= $yesterday && $date < $today;
+ case FreshRSS_Days::BEFORE_YESTERDAY:
+ $yesterday = $today - 86400;
+ return $date < $yesterday;
+ default:
+ return false;
}
}
@@ -149,10 +169,10 @@ class FreshRSS_Entry extends Minz_Model {
// Gestion du contenu
// On cherche à récupérer les articles en entier... même si le flux ne le propose pas
if ($pathEntries) {
- $entryDAO = new FreshRSS_EntryDAO();
+ $entryDAO = FreshRSS_Factory::createEntryDao();
$entry = $entryDAO->searchByGuid($this->feed, $this->guid);
- if($entry) {
+ if ($entry) {
// l'article existe déjà en BDD, en se contente de recharger ce contenu
$this->content = $entry->content();
} else {
@@ -162,25 +182,26 @@ class FreshRSS_Entry extends Minz_Model {
htmlspecialchars_decode($this->link(), ENT_QUOTES), $pathEntries
);
} catch (Exception $e) {
- // rien à faire, on garde l'ancien contenu (requête a échoué)
+ // rien à faire, on garde l'ancien contenu(requête a échoué)
}
}
}
}
- public function toArray () {
- return array (
- 'id' => $this->id (),
- 'guid' => $this->guid (),
- 'title' => $this->title (),
- 'author' => $this->author (),
- 'content' => $this->content (),
- 'link' => $this->link (),
- 'date' => $this->date (true),
- 'is_read' => $this->isRead (),
- 'is_favorite' => $this->isFavorite (),
- 'id_feed' => $this->feed (),
- 'tags' => $this->tags (true),
+ public function toArray() {
+ return array(
+ 'id' => $this->id(),
+ 'guid' => $this->guid(),
+ 'title' => $this->title(),
+ 'author' => $this->author(),
+ 'content' => $this->content(),
+ 'link' => $this->link(),
+ 'date' => $this->date(true),
+ 'hash' => $this->hash(),
+ 'is_read' => $this->isRead(),
+ 'is_favorite' => $this->isFavorite(),
+ 'id_feed' => $this->feed(),
+ 'tags' => $this->tags(true),
);
}
}