aboutsummaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rwxr-xr-xapp/models/Category.php20
-rwxr-xr-xapp/models/Entry.php89
-rw-r--r--app/models/Exception/FeedException.php7
-rw-r--r--app/models/Feed.php57
-rwxr-xr-xapp/models/RSSConfiguration.php19
5 files changed, 161 insertions, 31 deletions
diff --git a/app/models/Category.php b/app/models/Category.php
index d7db8ee65..7ce572e71 100755
--- a/app/models/Category.php
+++ b/app/models/Category.php
@@ -77,6 +77,8 @@ class CategoryDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
@@ -94,6 +96,8 @@ class CategoryDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
@@ -107,6 +111,8 @@ class CategoryDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
@@ -152,6 +158,20 @@ class CategoryDAO extends Model_pdo {
return HelperCategory::daoToCategory ($stm->fetchAll (PDO::FETCH_ASSOC));
}
+ public function getDefault () {
+ $sql = 'SELECT * FROM category WHERE id="000000"';
+ $stm = $this->bd->prepare ($sql);
+
+ $stm->execute ();
+ $res = $stm->fetchAll (PDO::FETCH_ASSOC);
+ $cat = HelperCategory::daoToCategory ($res);
+
+ if (isset ($cat[0])) {
+ return $cat[0];
+ } else {
+ return false;
+ }
+ }
public function checkDefault () {
$def_cat = $this->searchById ('000000');
diff --git a/app/models/Entry.php b/app/models/Entry.php
index 3e90db289..230b457bf 100755
--- a/app/models/Entry.php
+++ b/app/models/Entry.php
@@ -49,7 +49,11 @@ class Entry extends Model {
return $this->title;
}
public function author () {
- return $this->author;
+ if (is_null ($this->author)) {
+ return '';
+ } else {
+ return $this->author;
+ }
}
public function content () {
return $this->content;
@@ -212,7 +216,7 @@ class Entry extends Model {
class EntryDAO extends Model_pdo {
public function addEntry ($valuesTmp) {
- $sql = 'INSERT INTO entry(id, guid, title, author, content, link, date, is_read, is_favorite, is_public, id_feed, annotation, tags, lastUpdate) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
+ $sql = 'INSERT INTO entry(id, guid, title, author, content, link, date, is_read, is_favorite, is_public, id_feed, lastUpdate) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
$stm = $this->bd->prepare ($sql);
$values = array (
@@ -227,14 +231,14 @@ class EntryDAO extends Model_pdo {
$valuesTmp['is_favorite'],
$valuesTmp['is_public'],
$valuesTmp['id_feed'],
- $valuesTmp['annotation'],
- $valuesTmp['tags'],
$valuesTmp['lastUpdate'],
);
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
@@ -261,12 +265,14 @@ class EntryDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
public function markReadEntries ($read, $dateMax) {
- $sql = 'UPDATE entry SET is_read = ? WHERE date < ?';
+ $sql = 'UPDATE entry e INNER JOIN feed f ON e.id_feed = f.id SET is_read = ? WHERE date < ? AND priority > 0';
$stm = $this->bd->prepare ($sql);
$values = array ($read, $dateMax);
@@ -274,6 +280,8 @@ class EntryDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
@@ -286,6 +294,8 @@ class EntryDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
@@ -298,6 +308,8 @@ class EntryDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
@@ -323,13 +335,15 @@ class EntryDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
public function cleanOldEntries ($nb_month) {
$date = 60 * 60 * 24 * 30 * $nb_month;
- $sql = 'DELETE FROM entry WHERE date <= ? AND is_favorite = 0 AND notes != ""';
+ $sql = 'DELETE FROM entry WHERE date <= ? AND is_favorite = 0 AND annotation = ""';
$stm = $this->bd->prepare ($sql);
$values = array (
@@ -339,6 +353,8 @@ class EntryDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
@@ -361,19 +377,15 @@ class EntryDAO extends Model_pdo {
}
public function listEntries ($mode, $search = false, $order = 'high_to_low') {
- $where = '';
+ $where = ' WHERE priority > 0';
if ($mode == 'not_read') {
- $where = ' WHERE is_read=0';
+ $where .= ' AND is_read=0';
}
$values = array();
if ($search) {
$values[] = '%'.$search.'%';
- if ($mode == 'not_read') {
- $where = ' AND title LIKE ?';
- } else {
- $where = ' WHERE title LIKE ?';
- }
+ $where .= ' AND title LIKE ?';
}
if ($order == 'low_to_high') {
@@ -382,7 +394,7 @@ class EntryDAO extends Model_pdo {
$order = '';
}
- $sql = 'SELECT COUNT(*) AS count FROM entry' . $where;
+ $sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id' . $where;
$stm = $this->bd->prepare ($sql);
$stm->execute ($values);
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
@@ -391,7 +403,8 @@ class EntryDAO extends Model_pdo {
$deb = ($this->currentPage () - 1) * $this->nbItemsPerPage;
$fin = $this->nbItemsPerPage;
- $sql = 'SELECT * FROM entry' . $where
+ $sql = 'SELECT e.* FROM entry e'
+ . ' INNER JOIN feed f ON e.id_feed = f.id' . $where
. ' ORDER BY date' . $order
. ' LIMIT ' . $deb . ', ' . $fin;
$stm = $this->bd->prepare ($sql);
@@ -409,7 +422,7 @@ class EntryDAO extends Model_pdo {
$values = array();
if ($search) {
$values[] = '%'.$search.'%';
- $where = ' AND title LIKE ?';
+ $where .= ' AND title LIKE ?';
}
if ($order == 'low_to_high') {
@@ -442,8 +455,17 @@ class EntryDAO extends Model_pdo {
return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
}
- public function listPublic ($order = 'high_to_low') {
+ public function listPublic ($mode, $search = false, $order = 'high_to_low') {
$where = ' WHERE is_public=1';
+ if ($mode == 'not_read') {
+ $where .= ' AND is_read=0';
+ }
+
+ $values = array();
+ if ($search) {
+ $values[] = '%'.$search.'%';
+ $where .= ' AND title LIKE ?';
+ }
if ($order == 'low_to_high') {
$order = ' DESC';
@@ -451,10 +473,26 @@ class EntryDAO extends Model_pdo {
$order = '';
}
- $sql = 'SELECT * FROM entry' . $where . ' ORDER BY date' . $order;
+ $sql = 'SELECT COUNT(*) AS count FROM entry' . $where;
+ $stm = $this->bd->prepare ($sql);
+ $stm->execute ($values);
+ $res = $stm->fetchAll (PDO::FETCH_ASSOC);
+ $this->nbItems = $res[0]['count'];
+
+ if($this->nbItemsPerPage < 0) {
+ $sql = 'SELECT * FROM entry' . $where
+ . ' ORDER BY date' . $order;
+ } else {
+ $deb = ($this->currentPage () - 1) * $this->nbItemsPerPage;
+ $fin = $this->nbItemsPerPage;
+ $sql = 'SELECT * FROM entry' . $where
+ . ' ORDER BY date' . $order
+ . ' LIMIT ' . $deb . ', ' . $fin;
+ }
$stm = $this->bd->prepare ($sql);
- $stm->execute ();
+
+ $stm->execute ($values);
return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
}
@@ -468,7 +506,7 @@ class EntryDAO extends Model_pdo {
$values = array ($cat);
if ($search) {
$values[] = '%'.$search.'%';
- $where = ' AND title LIKE ?';
+ $where .= ' AND title LIKE ?';
}
if ($order == 'low_to_high') {
@@ -502,10 +540,10 @@ class EntryDAO extends Model_pdo {
$where .= ' AND is_read=0';
}
- $values = array();
+ $values = array($feed);
if ($search) {
$values[] = '%'.$search.'%';
- $where = ' AND title LIKE ?';
+ $where .= ' AND title LIKE ?';
}
if ($order == 'low_to_high') {
@@ -516,7 +554,6 @@ class EntryDAO extends Model_pdo {
$sql = 'SELECT COUNT(*) AS count FROM entry' . $where;
$stm = $this->bd->prepare ($sql);
- $values = array ($feed);
$stm->execute ($values);
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
$this->nbItems = $res[0]['count'];
@@ -529,15 +566,13 @@ class EntryDAO extends Model_pdo {
$stm = $this->bd->prepare ($sql);
- $values = array ($feed);
-
$stm->execute ($values);
return HelperEntry::daoToEntry ($stm->fetchAll (PDO::FETCH_ASSOC));
}
public function count () {
- $sql = 'SELECT COUNT(*) AS count FROM entry';
+ $sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id WHERE priority > 0';
$stm = $this->bd->prepare ($sql);
$stm->execute ();
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
@@ -546,7 +581,7 @@ class EntryDAO extends Model_pdo {
}
public function countNotRead () {
- $sql = 'SELECT COUNT(*) AS count FROM entry WHERE is_read=0';
+ $sql = 'SELECT COUNT(*) AS count FROM entry e INNER JOIN feed f ON e.id_feed = f.id WHERE is_read=0 AND priority > 0';
$stm = $this->bd->prepare ($sql);
$stm->execute ();
$res = $stm->fetchAll (PDO::FETCH_ASSOC);
diff --git a/app/models/Exception/FeedException.php b/app/models/Exception/FeedException.php
new file mode 100644
index 000000000..3fe0f4ea0
--- /dev/null
+++ b/app/models/Exception/FeedException.php
@@ -0,0 +1,7 @@
+<?php
+
+class FeedException extends Exception {
+ public function __construct ($message) {
+ parent::__construct ($message);
+ }
+}
diff --git a/app/models/Feed.php b/app/models/Feed.php
index 91c8d8022..222e22256 100644
--- a/app/models/Feed.php
+++ b/app/models/Feed.php
@@ -9,6 +9,7 @@ class Feed extends Model {
private $website = '';
private $description = '';
private $lastUpdate = 0;
+ private $priority = 10;
private $pathEntries = '';
private $httpAuth = '';
@@ -48,6 +49,9 @@ class Feed extends Model {
public function lastUpdate () {
return $this->lastUpdate;
}
+ public function priority () {
+ return $this->priority;
+ }
public function pathEntries () {
return $this->pathEntries;
}
@@ -108,6 +112,12 @@ class Feed extends Model {
public function _lastUpdate ($value) {
$this->lastUpdate = $value;
}
+ public function _priority ($value) {
+ if (!is_int (intval ($value))) {
+ $value = 10;
+ }
+ $this->priority = $value;
+ }
public function _pathEntries ($value) {
$this->pathEntries = $value;
}
@@ -124,10 +134,14 @@ class Feed extends Model {
);
} else {
$feed = new SimplePie ();
- $feed->set_feed_url ($this->url);
+ $feed->set_feed_url (preg_replace ('/&amp;/', '&', $this->url));
$feed->set_cache_location (CACHE_PATH);
$feed->init ();
+ if ($feed->error()) {
+ throw new FeedException ($feed->error);
+ }
+
$subscribe_url = $feed->subscribe_url ();
if (!is_null ($subscribe_url) && $subscribe_url != $this->url) {
$this->_url ($subscribe_url);
@@ -191,7 +205,7 @@ class Feed extends Model {
class FeedDAO extends Model_pdo {
public function addFeed ($valuesTmp) {
- $sql = 'INSERT INTO feed (id, url, category, name, website, description, lastUpdate) VALUES(?, ?, ?, ?, ?, ?, ?)';
+ $sql = 'INSERT INTO feed (id, url, category, name, website, description, lastUpdate, priority, error) VALUES(?, ?, ?, ?, ?, ?, ?, 10, 0)';
$stm = $this->bd->prepare ($sql);
$values = array (
@@ -207,6 +221,8 @@ class FeedDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
@@ -229,6 +245,8 @@ class FeedDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
@@ -245,6 +263,8 @@ class FeedDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
@@ -258,6 +278,22 @@ class FeedDAO extends Model_pdo {
if ($stm && $stm->execute ($values)) {
return true;
} else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
+ return false;
+ }
+ }
+ public function deleteFeedByCategory ($id) {
+ $sql = 'DELETE FROM feed WHERE category=?';
+ $stm = $this->bd->prepare ($sql);
+
+ $values = array ($id);
+
+ if ($stm && $stm->execute ($values)) {
+ return true;
+ } else {
+ $info = $stm->errorInfo();
+ Log::record ('SQL error : ' . $info[2], Log::ERROR);
return false;
}
}
@@ -278,6 +314,22 @@ class FeedDAO extends Model_pdo {
return false;
}
}
+ public function searchByUrl ($url) {
+ $sql = 'SELECT * FROM feed WHERE url=?';
+ $stm = $this->bd->prepare ($sql);
+
+ $values = array ($url);
+
+ $stm->execute ($values);
+ $res = $stm->fetchAll (PDO::FETCH_ASSOC);
+ $feed = current (HelperFeed::daoToFeed ($res));
+
+ if (isset ($feed)) {
+ return $feed;
+ } else {
+ return false;
+ }
+ }
public function listFeeds () {
$sql = 'SELECT * FROM feed ORDER BY name';
@@ -354,6 +406,7 @@ class HelperFeed {
$list[$key]->_website ($dao['website']);
$list[$key]->_description ($dao['description']);
$list[$key]->_lastUpdate ($dao['lastUpdate']);
+ $list[$key]->_priority ($dao['priority']);
$list[$key]->_pathEntries ($dao['pathEntries']);
$list[$key]->_httpAuth ($dao['httpAuth']);
diff --git a/app/models/RSSConfiguration.php b/app/models/RSSConfiguration.php
index 270ec2ce1..ca56ec3a8 100755
--- a/app/models/RSSConfiguration.php
+++ b/app/models/RSSConfiguration.php
@@ -9,6 +9,7 @@ class RSSConfiguration extends Model {
private $shortcuts = array ();
private $mail_login = '';
private $mark_when = array ();
+ private $url_shaarli = '';
public function __construct () {
$confDAO = new RSSConfigurationDAO ();
@@ -20,6 +21,7 @@ class RSSConfiguration extends Model {
$this->_shortcuts ($confDAO->shortcuts);
$this->_mailLogin ($confDAO->mail_login);
$this->_markWhen ($confDAO->mark_when);
+ $this->_urlShaarli ($confDAO->url_shaarli);
}
public function postsPerPage () {
@@ -55,6 +57,9 @@ class RSSConfiguration extends Model {
public function markWhenPage () {
return $this->mark_when['page'];
}
+ public function urlShaarli () {
+ return $this->url_shaarli;
+ }
public function _postsPerPage ($value) {
if (is_int (intval ($value))) {
@@ -108,11 +113,17 @@ class RSSConfiguration extends Model {
$this->mark_when['site'] = $values['site'];
$this->mark_when['page'] = $values['page'];
}
+ public function _urlShaarli ($value) {
+ $this->url_shaarli = '';
+ if (filter_var ($value, FILTER_VALIDATE_URL)) {
+ $this->url_shaarli = $value;
+ }
+ }
}
class RSSConfigurationDAO extends Model_array {
- public $posts_per_page = 10;
- public $default_view = 'all';
+ public $posts_per_page = 20;
+ public $default_view = 'not_read';
public $display_posts = 'no';
public $sort_order = 'low_to_high';
public $old_entries = 3;
@@ -131,6 +142,7 @@ class RSSConfigurationDAO extends Model_array {
'site' => 'yes',
'page' => 'no'
);
+ public $url_shaarli = '';
public function __construct () {
parent::__construct (PUBLIC_PATH . '/data/Configuration.array.php');
@@ -159,6 +171,9 @@ class RSSConfigurationDAO extends Model_array {
if (isset ($this->array['mark_when'])) {
$this->mark_when = $this->array['mark_when'];
}
+ if (isset ($this->array['url_shaarli'])) {
+ $this->url_shaarli = $this->array['url_shaarli'];
+ }
}
public function update ($values) {