summaryrefslogtreecommitdiff
path: root/classes/pref/feeds.php
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-03-06 11:17:15 +0300
committerAndrew Dolgov <[email protected]>2021-03-06 11:17:15 +0300
commite5469479c1ee6ddb671659dbb6362eac50f02979 (patch)
tree42fac045821e3111fc07c8dd21f287a546edcd29 /classes/pref/feeds.php
parent42e057c8088070f9afd417d92cf6a0ebc9fdd01f (diff)
* don't try to update custom set feed favicons
* cleanup update_rss_feed() a bit, use ORM
Diffstat (limited to 'classes/pref/feeds.php')
-rwxr-xr-xclasses/pref/feeds.php100
1 files changed, 47 insertions, 53 deletions
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php
index 340f6515d..c763a254a 100755
--- a/classes/pref/feeds.php
+++ b/classes/pref/feeds.php
@@ -1,5 +1,10 @@
<?php
class Pref_Feeds extends Handler_Protected {
+ const E_ICON_FILE_TOO_LARGE = 'E_ICON_FILE_TOO_LARGE';
+ const E_ICON_RENAME_FAILED = 'E_ICON_RENAME_FAILED';
+ const E_ICON_UPLOAD_FAILED = 'E_ICON_UPLOAD_FAILED';
+ const E_ICON_UPLOAD_SUCCESS = 'E_ICON_UPLOAD_SUCCESS';
+
function csrf_ignore($method) {
$csrf_ignored = array("index", "getfeedtree", "savefeedorder");
@@ -435,78 +440,67 @@ class Pref_Feeds extends Handler_Protected {
}
}
- function removeicon() {
- $feed_id = clean($_REQUEST["feed_id"]);
-
- $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
- WHERE id = ? AND owner_uid = ?");
- $sth->execute([$feed_id, $_SESSION['uid']]);
+ function removeIcon() {
+ $feed_id = (int) $_REQUEST["feed_id"];
+ $icon_file = Config::get(Config::ICONS_DIR) . "/$feed_id.ico";
- if ($row = $sth->fetch()) {
- @unlink(Config::get(Config::ICONS_DIR) . "/$feed_id.ico");
+ $feed = ORM::for_table('ttrss_feeds')
+ ->where('owner_uid', $_SESSION['uid'])
+ ->find_one($feed_id);
- $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET favicon_avg_color = NULL, favicon_last_checked = '1970-01-01'
- where id = ?");
- $sth->execute([$feed_id]);
+ if ($feed && file_exists($icon_file)) {
+ if (unlink($icon_file)) {
+ $feed->set([
+ 'favicon_avg_color' => null,
+ 'favicon_last_checked' => '1970-01-01',
+ 'favicon_is_custom' => false,
+ ]);
+ $feed->save();
+ }
}
}
- function uploadicon() {
- header("Content-type: text/html");
-
- if (is_uploaded_file($_FILES['icon_file']['tmp_name'])) {
- $tmp_file = tempnam(Config::get(Config::CACHE_DIR) . '/upload', 'icon');
-
- if (!$tmp_file)
- return;
-
- $result = move_uploaded_file($_FILES['icon_file']['tmp_name'], $tmp_file);
+ function uploadIcon() {
+ $feed_id = (int) $_REQUEST['feed_id'];
+ $tmp_file = tempnam(Config::get(Config::CACHE_DIR) . '/upload', 'icon');
- if (!$result) {
- return;
- }
- } else {
- return;
- }
-
- $icon_file = $tmp_file;
- $feed_id = clean($_REQUEST["feed_id"]);
- $rc = 2; // failed
+ // default value
+ $rc = self::E_ICON_UPLOAD_FAILED;
- if ($icon_file && is_file($icon_file) && $feed_id) {
- if (filesize($icon_file) < 65535) {
+ $feed = ORM::for_table('ttrss_feeds')
+ ->where('owner_uid', $_SESSION['uid'])
+ ->find_one($feed_id);
- $sth = $this->pdo->prepare("SELECT id FROM ttrss_feeds
- WHERE id = ? AND owner_uid = ?");
- $sth->execute([$feed_id, $_SESSION['uid']]);
+ if ($feed && $tmp_file && move_uploaded_file($_FILES['icon_file']['tmp_name'], $tmp_file)) {
+ if (filesize($tmp_file) < Config::get(Config::MAX_FAVICON_FILE_SIZE)) {
- if ($row = $sth->fetch()) {
- $new_filename = Config::get(Config::ICONS_DIR) . "/$feed_id.ico";
+ $new_filename = Config::get(Config::ICONS_DIR) . "/$feed_id.ico";
- if (file_exists($new_filename)) unlink($new_filename);
+ if (file_exists($new_filename)) unlink($new_filename);
+ if (rename($tmp_file, $new_filename)) {
+ chmod($new_filename, 0644);
- if (rename($icon_file, $new_filename)) {
- chmod($new_filename, 644);
+ $feed->set([
+ 'favicon_avg_color' => null,
+ 'favicon_is_custom' => true,
+ ]);
- $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET
- favicon_avg_color = ''
- WHERE id = ?");
- $sth->execute([$feed_id]);
+ if ($feed->save()) {
+ $rc = self::E_ICON_UPLOAD_SUCCESS;
+ }
- $rc = Feeds::_get_icon($feed_id);
+ } else {
+ $rc = self::E_ICON_RENAME_FAILED;
}
- }
} else {
- $rc = 1;
+ $rc = self::E_ICON_FILE_TOO_LARGE;
}
}
- if ($icon_file && is_file($icon_file)) {
- unlink($icon_file);
- }
+ if (file_exists($tmp_file))
+ unlink($tmp_file);
- print $rc;
- return;
+ print json_encode(['rc' => $rc, 'icon_url' => Feeds::_get_icon($feed_id)]);
}
function editfeed() {