From e5469479c1ee6ddb671659dbb6362eac50f02979 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 6 Mar 2021 11:17:15 +0300 Subject: * don't try to update custom set feed favicons * cleanup update_rss_feed() a bit, use ORM --- classes/pref/feeds.php | 100 +++++++++++++++++++++++-------------------------- 1 file changed, 47 insertions(+), 53 deletions(-) (limited to 'classes/pref') 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 @@ 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() { -- cgit v1.2.3