use orm for feed access keys

This commit is contained in:
Andrew Dolgov 2021-03-02 08:26:37 +03:00
parent 70adfd4a74
commit 84d8b08d1f
2 changed files with 23 additions and 22 deletions

View File

@ -1946,9 +1946,23 @@ class Feeds extends Handler_Protected {
return false; return false;
} }
static function _get_access_key($feed_id, bool $is_cat, int $owner_uid = 0) { static function _clear_access_keys(int $owner_uid) {
if (!$owner_uid) $owner_uid = $_SESSION["uid"]; $key = ORM::for_table('ttrss_access_keys')
->where('owner_uid', $owner_uid)
->delete_many();
}
static function _update_access_key(string $feed_id, bool $is_cat, int $owner_uid) {
$key = ORM::for_table('ttrss_access_keys')
->where('owner_uid', $owner_uid)
->where('feed_id', $feed_id)
->where('is_cat', $is_cat)
->delete_many();
return self::_get_access_key($feed_id, $is_cat, $owner_uid);
}
static function _get_access_key(string $feed_id, bool $is_cat, int $owner_uid) {
$key = ORM::for_table('ttrss_access_keys') $key = ORM::for_table('ttrss_access_keys')
->where('owner_uid', $owner_uid) ->where('owner_uid', $owner_uid)
->where('feed_id', $feed_id) ->where('feed_id', $feed_id)

View File

@ -1253,12 +1253,16 @@ class Pref_Feeds extends Handler_Protected {
} }
} }
function clearKeys() {
return Feeds::_clear_access_keys($_SESSION['uid']);
}
function getOPMLKey() { function getOPMLKey() {
print json_encode(["link" => OPML::get_publish_url()]); print json_encode(["link" => OPML::get_publish_url()]);
} }
function regenOPMLKey() { function regenOPMLKey() {
$this->update_feed_access_key('OPML:Publish', Feeds::_update_access_key('OPML:Publish',
false, $_SESSION["uid"]); false, $_SESSION["uid"]);
print json_encode(["link" => OPML::get_publish_url()]); print json_encode(["link" => OPML::get_publish_url()]);
@ -1268,12 +1272,12 @@ class Pref_Feeds extends Handler_Protected {
$feed_id = clean($_REQUEST['id']); $feed_id = clean($_REQUEST['id']);
$is_cat = clean($_REQUEST['is_cat']); $is_cat = clean($_REQUEST['is_cat']);
$new_key = $this->update_feed_access_key($feed_id, $is_cat, $_SESSION["uid"]); $new_key = Feeds::_update_access_key($feed_id, $is_cat, $_SESSION["uid"]);
print json_encode(["link" => $new_key]); print json_encode(["link" => $new_key]);
} }
function getsharedurl() { function getSharedURL() {
$feed_id = clean($_REQUEST['id']); $feed_id = clean($_REQUEST['id']);
$is_cat = clean($_REQUEST['is_cat']) == "true"; $is_cat = clean($_REQUEST['is_cat']) == "true";
$search = clean($_REQUEST['search']); $search = clean($_REQUEST['search']);
@ -1292,23 +1296,6 @@ class Pref_Feeds extends Handler_Protected {
]); ]);
} }
private function update_feed_access_key($feed_id, $is_cat, $owner_uid) {
// clear old value and generate new one
$sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys
WHERE feed_id = ? AND is_cat = ? AND owner_uid = ?");
$sth->execute([$feed_id, bool_to_sql_bool($is_cat), $owner_uid]);
return Feeds::_get_access_key($feed_id, $is_cat, $owner_uid);
}
// Silent
function clearKeys() {
$sth = $this->pdo->prepare("DELETE FROM ttrss_access_keys WHERE
owner_uid = ?");
$sth->execute([$_SESSION['uid']]);
}
private function calculate_children_count($cat) { private function calculate_children_count($cat) {
$c = 0; $c = 0;