|
|
@@ -2,13 +2,15 @@
|
|
|
|
|
|
class Feed extends Model {
|
|
|
private $url;
|
|
|
- private $categories;
|
|
|
- private $entries_list;
|
|
|
+ private $category = '';
|
|
|
+ private $entries_list = array ();
|
|
|
+ private $entries = null;
|
|
|
+ private $name = '';
|
|
|
+ private $website = '';
|
|
|
+ private $description = '';
|
|
|
|
|
|
- public function __construct ($url = null) {
|
|
|
+ public function __construct ($url) {
|
|
|
$this->_url ($url);
|
|
|
- $this->_categories (array ());
|
|
|
- $this->_entries (array ());
|
|
|
}
|
|
|
|
|
|
public function id () {
|
|
|
@@ -17,11 +19,26 @@ class Feed extends Model {
|
|
|
public function url () {
|
|
|
return $this->url;
|
|
|
}
|
|
|
- public function categories () {
|
|
|
- return $this->categories;
|
|
|
+ public function category () {
|
|
|
+ return $this->category;
|
|
|
}
|
|
|
- public function entries () {
|
|
|
- return $this->entries_list;
|
|
|
+ public function entries ($list = true) {
|
|
|
+ if ($list) {
|
|
|
+ return $this->entries_list;
|
|
|
+ } elseif (!is_null ($this->entries)) {
|
|
|
+ return $this->entries;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function name () {
|
|
|
+ return $this->name;
|
|
|
+ }
|
|
|
+ public function website () {
|
|
|
+ return $this->website;
|
|
|
+ }
|
|
|
+ public function description () {
|
|
|
+ return $this->description;
|
|
|
}
|
|
|
|
|
|
public function _url ($value) {
|
|
|
@@ -31,12 +48,8 @@ class Feed extends Model {
|
|
|
throw new Exception ();
|
|
|
}
|
|
|
}
|
|
|
- public function _categories ($value) {
|
|
|
- if (!is_array ($value)) {
|
|
|
- $value = array ($value);
|
|
|
- }
|
|
|
-
|
|
|
- $this->categories = $value;
|
|
|
+ public function _category ($value) {
|
|
|
+ $this->category = $value;
|
|
|
}
|
|
|
public function _entries ($value) {
|
|
|
if (!is_array ($value)) {
|
|
|
@@ -45,42 +58,54 @@ class Feed extends Model {
|
|
|
|
|
|
$this->entries_list = $value;
|
|
|
}
|
|
|
+ public function _name ($value) {
|
|
|
+ $this->name = $value;
|
|
|
+ }
|
|
|
+ public function _website ($value) {
|
|
|
+ $this->website = $value;
|
|
|
+ }
|
|
|
+ public function _description ($value) {
|
|
|
+ $this->description = $value;
|
|
|
+ }
|
|
|
|
|
|
- public function loadEntries () {
|
|
|
+ public function load () {
|
|
|
if (!is_null ($this->url)) {
|
|
|
$feed = new SimplePie ();
|
|
|
$feed->set_feed_url ($this->url);
|
|
|
$feed->set_cache_location (CACHE_PATH);
|
|
|
$feed->init ();
|
|
|
|
|
|
- $entries = array ();
|
|
|
- if ($feed->data) {
|
|
|
- foreach ($feed->get_items () as $item) {
|
|
|
- $title = $item->get_title ();
|
|
|
- $author = $item->get_author ();
|
|
|
- $content = $item->get_content ();
|
|
|
- $link = $item->get_permalink ();
|
|
|
- $date = strtotime ($item->get_date ());
|
|
|
-
|
|
|
- $entry = new Entry (
|
|
|
- $item->get_id (),
|
|
|
- !is_null ($title) ? $title : '',
|
|
|
- !is_null ($author) ? $author->name : '',
|
|
|
- !is_null ($content) ? $content : '',
|
|
|
- !is_null ($link) ? $link : '',
|
|
|
- $date ? $date : time ()
|
|
|
- );
|
|
|
-
|
|
|
- $entries[$entry->id ()] = $entry;
|
|
|
- }
|
|
|
-
|
|
|
- return $entries;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- } else {
|
|
|
- return false;
|
|
|
+ $title = $feed->get_title ();
|
|
|
+ $this->loadEntries ($feed);
|
|
|
+ $this->_name (!is_null ($title) ? $title : $this->url);
|
|
|
+ $this->_website ($feed->get_link ());
|
|
|
+ $this->_description ($feed->get_description ());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private function loadEntries ($feed) {
|
|
|
+ $entries = array ();
|
|
|
+
|
|
|
+ foreach ($feed->get_items () as $item) {
|
|
|
+ $title = $item->get_title ();
|
|
|
+ $author = $item->get_author ();
|
|
|
+ $content = $item->get_content ();
|
|
|
+ $link = $item->get_permalink ();
|
|
|
+ $date = strtotime ($item->get_date ());
|
|
|
+
|
|
|
+ $entry = new Entry (
|
|
|
+ $this->id (),
|
|
|
+ $item->get_id (),
|
|
|
+ !is_null ($title) ? $title : '',
|
|
|
+ !is_null ($author) ? $author->name : '',
|
|
|
+ !is_null ($content) ? $content : '',
|
|
|
+ !is_null ($link) ? $link : '',
|
|
|
+ $date ? $date : time ()
|
|
|
+ );
|
|
|
+
|
|
|
+ $entries[$entry->id ()] = $entry;
|
|
|
}
|
|
|
+
|
|
|
+ $this->entries = $entries;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -114,6 +139,16 @@ class FeedDAO extends Model_array {
|
|
|
$this->writeFile($this->array);
|
|
|
}
|
|
|
|
|
|
+ public function searchById ($id) {
|
|
|
+ $list = HelperFeed::daoToFeed ($this->array);
|
|
|
+
|
|
|
+ if (isset ($list[$id])) {
|
|
|
+ return $list[$id];
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public function listFeeds () {
|
|
|
$list = $this->array;
|
|
|
|
|
|
@@ -139,8 +174,11 @@ class HelperFeed {
|
|
|
|
|
|
foreach ($listDAO as $key => $dao) {
|
|
|
$list[$key] = new Feed ($dao['url']);
|
|
|
- $list[$key]->_categories ($dao['categories']);
|
|
|
+ $list[$key]->_category ($dao['category']);
|
|
|
$list[$key]->_entries ($dao['entries']);
|
|
|
+ $list[$key]->_name ($dao['name']);
|
|
|
+ $list[$key]->_website ($dao['website']);
|
|
|
+ $list[$key]->_description ($dao['description']);
|
|
|
}
|
|
|
|
|
|
return $list;
|