2013-01-22 18:32:17 +00:00
|
|
|
<?php
|
2017-05-04 12:22:57 +00:00
|
|
|
class CCache {
|
|
|
|
static function zero_all($owner_uid) {
|
2017-12-01 15:03:33 +00:00
|
|
|
$pdo = Db::pdo();
|
|
|
|
|
|
|
|
$sth = $pdo->prepare("UPDATE ttrss_counters_cache SET
|
|
|
|
value = 0 WHERE owner_uid = ?");
|
|
|
|
$sth->execute([$owner_uid]);
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
$sth = $pdo->prepare("UPDATE ttrss_cat_counters_cache SET
|
|
|
|
value = 0 WHERE owner_uid = ?");
|
|
|
|
$sth->execute([$owner_uid]);
|
2013-01-22 18:32:17 +00:00
|
|
|
}
|
|
|
|
|
2017-05-04 12:22:57 +00:00
|
|
|
static function remove($feed_id, $owner_uid, $is_cat = false) {
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-03 18:34:57 +00:00
|
|
|
$feed_id = (int) $feed_id;
|
|
|
|
|
2013-01-22 18:32:17 +00:00
|
|
|
if (!$is_cat) {
|
|
|
|
$table = "ttrss_counters_cache";
|
|
|
|
} else {
|
|
|
|
$table = "ttrss_cat_counters_cache";
|
|
|
|
}
|
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
$pdo = Db::pdo();
|
|
|
|
|
|
|
|
$sth = $pdo->prepare("DELETE FROM $table WHERE
|
|
|
|
feed_id = ? AND owner_uid = ?");
|
|
|
|
$sth->execute([$feed_id, $owner_uid]);
|
2013-01-22 18:32:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-05-04 12:22:57 +00:00
|
|
|
static function update_all($owner_uid) {
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
$pdo = Db::pdo();
|
|
|
|
|
2013-04-17 14:34:18 +00:00
|
|
|
if (get_pref('ENABLE_FEED_CATS', $owner_uid)) {
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
$sth = $pdo->prepare("SELECT feed_id FROM ttrss_cat_counters_cache
|
|
|
|
WHERE feed_id > 0 AND owner_uid = ?");
|
|
|
|
$sth->execute([$owner_uid]);
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
while ($line = $sth->fetch()) {
|
2017-05-04 12:22:57 +00:00
|
|
|
CCache::update($line["feed_id"], $owner_uid, true);
|
2013-01-22 18:32:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We have to manually include category 0 */
|
|
|
|
|
2017-05-04 12:22:57 +00:00
|
|
|
CCache::update(0, $owner_uid, true);
|
2013-01-22 18:32:17 +00:00
|
|
|
|
|
|
|
} else {
|
2017-12-01 15:03:33 +00:00
|
|
|
$sth = $pdo->prepare("SELECT feed_id FROM ttrss_counters_cache
|
|
|
|
WHERE feed_id > 0 AND owner_uid = ?");
|
|
|
|
$sth->execute([$owner_uid]);
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
while ($line = $sth->fetch()) {
|
2017-05-04 12:22:57 +00:00
|
|
|
print CCache::update($line["feed_id"], $owner_uid);
|
2013-01-22 18:32:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-04 12:22:57 +00:00
|
|
|
static function find($feed_id, $owner_uid, $is_cat = false,
|
|
|
|
$no_update = false) {
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-03 18:34:57 +00:00
|
|
|
// "" (null) is valid and should be cast to 0 (uncategorized)
|
|
|
|
// everything else i.e. tags are not
|
|
|
|
if (!is_numeric($feed_id) && $feed_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
$feed_id = (int) $feed_id;
|
2013-01-22 18:32:17 +00:00
|
|
|
|
|
|
|
if (!$is_cat) {
|
|
|
|
$table = "ttrss_counters_cache";
|
|
|
|
} else {
|
|
|
|
$table = "ttrss_cat_counters_cache";
|
|
|
|
}
|
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
$pdo = Db::pdo();
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
$sth = $pdo->prepare("SELECT value FROM $table
|
|
|
|
WHERE owner_uid = ? AND feed_id = ?
|
2013-01-22 18:32:17 +00:00
|
|
|
LIMIT 1");
|
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
$sth->execute([$owner_uid, $feed_id]);
|
|
|
|
|
|
|
|
if ($row = $sth->fetch()) {
|
|
|
|
return $row["value"];
|
2013-01-22 18:32:17 +00:00
|
|
|
} else {
|
|
|
|
if ($no_update) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
2017-05-04 12:22:57 +00:00
|
|
|
return CCache::update($feed_id, $owner_uid, $is_cat);
|
2013-01-22 18:32:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-05-04 12:22:57 +00:00
|
|
|
static function update($feed_id, $owner_uid, $is_cat = false,
|
|
|
|
$update_pcat = true, $pcat_fast = false) {
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-03 18:34:57 +00:00
|
|
|
// "" (null) is valid and should be cast to 0 (uncategorized)
|
|
|
|
// everything else i.e. tags are not
|
|
|
|
if (!is_numeric($feed_id) && $feed_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
$feed_id = (int) $feed_id;
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-05-04 12:22:57 +00:00
|
|
|
$prev_unread = CCache::find($feed_id, $owner_uid, $is_cat, true);
|
2013-01-22 18:32:17 +00:00
|
|
|
|
|
|
|
/* When updating a label, all we need to do is recalculate feed counters
|
|
|
|
* because labels are not cached */
|
|
|
|
|
|
|
|
if ($feed_id < 0) {
|
2017-05-04 12:22:57 +00:00
|
|
|
CCache::update_all($owner_uid);
|
2013-01-22 18:32:17 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$is_cat) {
|
|
|
|
$table = "ttrss_counters_cache";
|
|
|
|
} else {
|
|
|
|
$table = "ttrss_cat_counters_cache";
|
|
|
|
}
|
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
$pdo = Db::pdo();
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
if ($is_cat && $feed_id >= 0) {
|
2013-01-22 18:32:17 +00:00
|
|
|
/* Recalculate counters for child feeds */
|
|
|
|
|
2013-10-09 12:58:31 +00:00
|
|
|
if (!$pcat_fast) {
|
2017-12-01 15:03:33 +00:00
|
|
|
$sth = $pdo->prepare("SELECT id FROM ttrss_feeds
|
2017-12-01 16:42:02 +00:00
|
|
|
WHERE owner_uid = :uid AND
|
|
|
|
(cat_id = :cat OR (:cat = 0 AND cat_id IS NULL))");
|
2017-12-01 15:03:33 +00:00
|
|
|
$sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]);
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
while ($line = $sth->fetch()) {
|
2017-12-03 18:34:57 +00:00
|
|
|
CCache::update((int)$line["id"], $owner_uid, false, false);
|
2013-10-09 12:58:31 +00:00
|
|
|
}
|
2013-05-01 22:12:07 +00:00
|
|
|
}
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
$sth = $pdo->prepare("SELECT SUM(value) AS sv
|
2013-01-22 18:32:17 +00:00
|
|
|
FROM ttrss_counters_cache, ttrss_feeds
|
2017-12-01 15:03:33 +00:00
|
|
|
WHERE id = feed_id AND
|
2017-12-01 16:42:02 +00:00
|
|
|
(cat_id = :cat OR (:cat = 0 AND cat_id IS NULL)) AND
|
2017-12-01 15:03:33 +00:00
|
|
|
ttrss_counters_cache.owner_uid = :uid AND
|
|
|
|
ttrss_feeds.owner_uid = :uid");
|
|
|
|
$sth->execute([":uid" => $owner_uid, ":cat" => $feed_id]);
|
|
|
|
$row = $sth->fetch();
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
$unread = (int) $row["sv"];
|
2013-01-22 18:32:17 +00:00
|
|
|
|
|
|
|
} else {
|
move the following to Feeds:
+ static function catchup_feed($feed, $cat_view, $owner_uid = false, $mode = 'all', $search = false) {
+ static function getFeedArticles($feed, $is_cat = false, $unread_only = false,
+ static function subscribe_to_feed($url, $cat_id = 0,
+ static function getFeedIcon($id) {
+ static function getFeedTitle($id, $cat = false) {
+ static function getCategoryUnread($cat, $owner_uid = false) {
+ static function getCategoryChildrenUnread($cat, $owner_uid = false) {
2017-05-04 11:50:56 +00:00
|
|
|
$unread = (int) Feeds::getFeedArticles($feed_id, $is_cat, true, $owner_uid);
|
2013-01-22 18:32:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-02 06:55:53 +00:00
|
|
|
$tr_in_progress = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$pdo->beginTransaction();
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$tr_in_progress = true;
|
|
|
|
}
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
$sth = $pdo->prepare("SELECT feed_id FROM $table
|
|
|
|
WHERE owner_uid = ? AND feed_id = ? LIMIT 1");
|
|
|
|
$sth->execute([$owner_uid, $feed_id]);
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
if ($sth->fetch()) {
|
|
|
|
|
|
|
|
$sth = $pdo->prepare("UPDATE $table SET
|
|
|
|
value = ?, updated = NOW() WHERE
|
|
|
|
feed_id = ? AND owner_uid = ?");
|
|
|
|
|
|
|
|
$sth->execute([$unread, $feed_id, $owner_uid]);
|
2013-01-22 18:32:17 +00:00
|
|
|
|
|
|
|
} else {
|
2017-12-01 15:03:33 +00:00
|
|
|
$sth = $pdo->prepare("INSERT INTO $table
|
2013-01-22 18:32:17 +00:00
|
|
|
(feed_id, value, owner_uid, updated)
|
|
|
|
VALUES
|
2017-12-01 15:03:33 +00:00
|
|
|
(?, ?, ?, NOW())");
|
|
|
|
$sth->execute([$feed_id, $unread, $owner_uid]);
|
2013-01-22 18:32:17 +00:00
|
|
|
}
|
|
|
|
|
2017-12-02 06:55:53 +00:00
|
|
|
if (!$tr_in_progress) $pdo->commit();
|
2013-01-22 18:32:17 +00:00
|
|
|
|
|
|
|
if ($feed_id > 0 && $prev_unread != $unread) {
|
|
|
|
|
|
|
|
if (!$is_cat) {
|
|
|
|
|
|
|
|
/* Update parent category */
|
|
|
|
|
|
|
|
if ($update_pcat) {
|
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
$sth = $pdo->prepare("SELECT cat_id FROM ttrss_feeds
|
|
|
|
WHERE owner_uid = ? AND id = ?");
|
|
|
|
$sth->execute([$owner_uid, $feed_id]);
|
2013-01-22 18:32:17 +00:00
|
|
|
|
2017-12-01 15:03:33 +00:00
|
|
|
if ($row = $sth->fetch()) {
|
2017-12-03 18:34:57 +00:00
|
|
|
CCache::update((int)$row["cat_id"], $owner_uid, true, true, true);
|
2017-12-01 15:03:33 +00:00
|
|
|
}
|
2013-01-22 18:32:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if ($feed_id < 0) {
|
2017-05-04 12:22:57 +00:00
|
|
|
CCache::update_all($owner_uid);
|
2013-01-22 18:32:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $unread;
|
|
|
|
}
|
|
|
|
|
2017-05-04 12:22:57 +00:00
|
|
|
}
|