diff options
Diffstat (limited to 'classes/pref')
| -rwxr-xr-x | classes/pref/feeds.php | 67 | ||||
| -rwxr-xr-x | classes/pref/filters.php | 15 | ||||
| -rw-r--r-- | classes/pref/labels.php | 2 | ||||
| -rw-r--r-- | classes/pref/prefs.php | 48 | ||||
| -rw-r--r-- | classes/pref/users.php | 5 |
5 files changed, 61 insertions, 76 deletions
diff --git a/classes/pref/feeds.php b/classes/pref/feeds.php index 03b70580b..a91d4b1e3 100755 --- a/classes/pref/feeds.php +++ b/classes/pref/feeds.php @@ -172,7 +172,7 @@ class Pref_Feeds extends Handler_Protected { if ($enable_cats) { array_push($root['items'], $cat); } else { - $root['items'] = array_merge($root['items'], $cat['items']); + array_push($root['items'], ...$cat['items']); } $sth = $this->pdo->prepare("SELECT * FROM @@ -202,7 +202,7 @@ class Pref_Feeds extends Handler_Protected { if ($enable_cats) { array_push($root['items'], $cat); } else { - $root['items'] = array_merge($root['items'], $cat['items']); + array_push($root['items'], ...$cat['items']); } } } @@ -373,7 +373,7 @@ class Pref_Feeds extends Handler_Protected { $order_id = 1; - $cat = $data_map[$item_id]; + $cat = ($data_map[$item_id] ?? false); if ($cat && is_array($cat)) { foreach ($cat as $item) { @@ -436,7 +436,7 @@ class Pref_Feeds extends Handler_Protected { foreach ($data['items'] as $item) { # if ($item['id'] != 'root') { - if (is_array($item['items'])) { + if (is_array($item['items'] ?? false)) { if (isset($item['items']['_reference'])) { $data_map[$item['id']] = array($item['items']); } else { @@ -454,14 +454,15 @@ class Pref_Feeds extends Handler_Protected { function removeIcon(): void { $feed_id = (int) $_REQUEST["feed_id"]; - $icon_file = Config::get(Config::ICONS_DIR) . "/$feed_id.ico"; + + $cache = DiskCache::instance('feed-icons'); $feed = ORM::for_table('ttrss_feeds') ->where('owner_uid', $_SESSION['uid']) ->find_one($feed_id); - if ($feed && file_exists($icon_file)) { - if (unlink($icon_file)) { + if ($feed && $cache->exists((string)$feed_id)) { + if ($cache->remove((string)$feed_id)) { $feed->set([ 'favicon_avg_color' => null, 'favicon_last_checked' => '1970-01-01', @@ -486,24 +487,25 @@ class Pref_Feeds extends Handler_Protected { 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)) { - $new_filename = Config::get(Config::ICONS_DIR) . "/$feed_id.ico"; - - if (file_exists($new_filename)) unlink($new_filename); - if (rename($tmp_file, $new_filename)) { - chmod($new_filename, 0644); + $cache = DiskCache::instance('feed-icons'); - $feed->set([ - 'favicon_avg_color' => null, - 'favicon_is_custom' => true, - ]); + if ($cache->put((string)$feed_id, file_get_contents($tmp_file))) { - if ($feed->save()) { - $rc = self::E_ICON_UPLOAD_SUCCESS; - } + $feed->set([ + 'favicon_avg_color' => null, + 'favicon_is_custom' => true, + ]); - } else { - $rc = self::E_ICON_RENAME_FAILED; + if ($feed->save()) { + $rc = self::E_ICON_UPLOAD_SUCCESS; } + + } else { + $rc = self::E_ICON_RENAME_FAILED; + } + + @unlink($tmp_file); + } else { $rc = self::E_ICON_FILE_TOO_LARGE; } @@ -512,7 +514,8 @@ class Pref_Feeds extends Handler_Protected { if (file_exists($tmp_file)) unlink($tmp_file); - print json_encode(['rc' => $rc, 'icon_url' => Feeds::_get_icon($feed_id)]); + print json_encode(['rc' => $rc, 'icon_url' => + Feeds::_get_icon($feed_id) . "?ts=" . time() ]); } function editfeed(): void { @@ -848,7 +851,7 @@ class Pref_Feeds extends Handler_Protected { if ($qpart) { $sth = $this->pdo->prepare("UPDATE ttrss_feeds SET $qpart WHERE id IN ($feed_ids_qmarks) AND owner_uid = ?"); - $sth->execute(array_merge($feed_ids, [$_SESSION['uid']])); + $sth->execute([...$feed_ids, $_SESSION['uid']]); } } @@ -973,16 +976,6 @@ class Pref_Feeds extends Handler_Protected { persist="true" model="feedModel" openOnClick="false"> - <script type="dojo/method" event="onClick" args="item"> - var id = String(item.id); - var bare_id = id.substr(id.indexOf(':')+1); - - if (id.match('FEED:')) { - CommonDialogs.editFeed(bare_id); - } else if (id.match('CAT:')) { - dijit.byId('feedTree').editCategory(bare_id, item); - } - </script> </div> </div> </div> @@ -1161,6 +1154,7 @@ class Pref_Feeds extends Handler_Protected { ->select_many('id', 'title', 'feed_url', 'last_error', 'site_url') ->where_not_equal('last_error', '') ->where('owner_uid', $_SESSION['uid']) + ->where_gte('update_interval', 0) ->find_array()); } @@ -1196,9 +1190,10 @@ class Pref_Feeds extends Handler_Protected { $pdo->commit(); - if (file_exists(Config::get(Config::ICONS_DIR) . "/$id.ico")) { - unlink(Config::get(Config::ICONS_DIR) . "/$id.ico"); - } + $favicon_cache = DiskCache::instance('feed-icons'); + + if ($favicon_cache->exists((string)$id)) + $favicon_cache->remove((string)$id); } else { Labels::remove(Labels::feed_to_label_id($id), $owner_uid); diff --git a/classes/pref/filters.php b/classes/pref/filters.php index 79dd78993..19ec8d39e 100755 --- a/classes/pref/filters.php +++ b/classes/pref/filters.php @@ -115,6 +115,7 @@ class Pref_Filters extends Handler_Protected { $glue = $filter['match_any_rule'] ? " OR " : " AND "; $scope_qpart = join($glue, $scope_qparts); + /** @phpstan-ignore-next-line */ if (!$scope_qpart) $scope_qpart = "true"; $rv = array(); @@ -537,7 +538,7 @@ class Pref_Filters extends Handler_Protected { $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2 WHERE id IN ($ids_qmarks) AND owner_uid = ?"); - $sth->execute(array_merge($ids, [$_SESSION['uid']])); + $sth->execute([...$ids, $_SESSION['uid']]); } private function _save_rules_and_actions(int $filter_id): void { @@ -703,14 +704,6 @@ class Pref_Filters extends Handler_Protected { </div> <div dojoType="fox.PrefFilterTree" id="filterTree" dndController="dijit.tree.dndSource" betweenThreshold="5" model="filterModel" openOnClick="true"> - <script type="dojo/method" event="onClick" args="item"> - var id = String(item.id); - var bare_id = id.substr(id.indexOf(':')+1); - - if (id.match('FILTER:')) { - Filters.edit(bare_id); - } - </script> </div> </div> <?php PluginHost::getInstance()->run_hooks(PluginHost::HOOK_PREFS_TAB, "prefFilters") ?> @@ -788,11 +781,11 @@ class Pref_Filters extends Handler_Protected { $sth = $this->pdo->prepare("UPDATE ttrss_filters2_rules SET filter_id = ? WHERE filter_id IN ($ids_qmarks)"); - $sth->execute(array_merge([$base_id], $ids)); + $sth->execute([$base_id, ...$ids]); $sth = $this->pdo->prepare("UPDATE ttrss_filters2_actions SET filter_id = ? WHERE filter_id IN ($ids_qmarks)"); - $sth->execute(array_merge([$base_id], $ids)); + $sth->execute([$base_id, ...$ids]); $sth = $this->pdo->prepare("DELETE FROM ttrss_filters2 WHERE id IN ($ids_qmarks)"); $sth->execute($ids); diff --git a/classes/pref/labels.php b/classes/pref/labels.php index a50a85a66..2e128691e 100644 --- a/classes/pref/labels.php +++ b/classes/pref/labels.php @@ -61,7 +61,7 @@ class Pref_Labels extends Handler_Protected { if ($kind == "fg" || $kind == "bg") { $sth = $this->pdo->prepare("UPDATE ttrss_labels2 SET - ${kind}_color = ? WHERE id = ? + {$kind}_color = ? WHERE id = ? AND owner_uid = ?"); $sth->execute([$color, $id, $_SESSION['uid']]); diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 8c044b49f..1e02a0508 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -2,18 +2,17 @@ use chillerlan\QRCode; class Pref_Prefs extends Handler_Protected { - // TODO: class properties can be switched to PHP typing if/when the minimum PHP_VERSION is raised to 7.4.0+ /** @var array<Prefs::*, array<int, string>> */ - private $pref_help = []; + private array $pref_help = []; /** @var array<string, array<int, string>> pref items are Prefs::*|Pref_Prefs::BLOCK_SEPARATOR (PHPStan was complaining) */ - private $pref_item_map = []; + private array $pref_item_map = []; /** @var array<string, string> */ - private $pref_help_bottom = []; + private array $pref_help_bottom = []; /** @var array<int, string> */ - private $pref_blacklist = []; + private array $pref_blacklist = []; private const BLOCK_SEPARATOR = 'BLOCK_SEPARATOR'; @@ -26,7 +25,6 @@ class Pref_Prefs extends Handler_Protected { const PI_ERR_PLUGIN_NOT_FOUND = "PI_ERR_PLUGIN_NOT_FOUND"; const PI_ERR_NO_WORKDIR = "PI_ERR_NO_WORKDIR"; - /** @param string $method */ function csrf_ignore(string $method) : bool { $csrf_ignored = array("index", "updateself", "otpqrcode"); @@ -187,7 +185,7 @@ class Pref_Prefs extends Handler_Protected { $boolean_prefs = explode(",", clean($_POST["boolean_prefs"])); foreach ($boolean_prefs as $pref) { - if (!isset($_POST[$pref])) $_POST[$pref] = 'false'; + $_POST[$pref] ??= 'false'; } $need_reload = false; @@ -242,7 +240,7 @@ class Pref_Prefs extends Handler_Protected { $user->full_name = clean($_POST['full_name']); if ($user->email != $new_email) { - Logger::log(E_USER_NOTICE, "Email address of user ".$user->login." has been changed to ${new_email}."); + Logger::log(E_USER_NOTICE, "Email address of user {$user->login} has been changed to {$new_email}."); if ($user->email) { $mailer = new Mailer(); @@ -253,7 +251,7 @@ class Pref_Prefs extends Handler_Protected { $tpl->setVariable('LOGIN', $user->login); $tpl->setVariable('NEWMAIL', $new_email); - $tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH)); + $tpl->setVariable('TTRSS_HOST', Config::get_self_url()); $tpl->addBlock('message'); @@ -633,10 +631,11 @@ class Pref_Prefs extends Handler_Protected { } else if ($pref_name == Prefs::USER_CSS_THEME) { - $theme_files = array_map("basename", - array_merge(glob("themes/*.php"), - glob("themes/*.css"), - glob("themes.local/*.css"))); + $theme_files = array_map("basename", [ + ...glob("themes/*.php") ?: [], + ...glob("themes/*.css") ?: [], + ...glob("themes.local/*.css") ?: [], + ]); asort($theme_files); @@ -869,18 +868,19 @@ class Pref_Prefs extends Handler_Protected { $feed_handler_whitelist = [ "Af_Comics" ]; - $feed_handlers = array_merge( - PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_FETCHED), - PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED), - PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED)); + $feed_handlers = [ + ...PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_FETCHED), + ...PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FEED_PARSED), + ...PluginHost::getInstance()->get_hooks(PluginHost::HOOK_FETCH_FEED), + ]; - $feed_handlers = array_filter($feed_handlers, function($plugin) use ($feed_handler_whitelist) { - return in_array(get_class($plugin), $feed_handler_whitelist) === false; }); + $feed_handlers = array_filter($feed_handlers, + fn($plugin) => in_array(get_class($plugin), $feed_handler_whitelist) === false); if (count($feed_handlers) > 0) { print_error( T_sprintf("The following plugins use per-feed content hooks. This may cause excessive data usage and origin server load resulting in a ban of your instance: <b>%s</b>" , - implode(", ", array_map(function($plugin) { return get_class($plugin); }, $feed_handlers)) + implode(", ", array_map(fn($plugin) => get_class($plugin), $feed_handlers)) ) . " (<a href='https://tt-rss.org/wiki/FeedHandlerPlugins' target='_blank'>".__("More info...")."</a>)" ); } @@ -1002,7 +1002,7 @@ class Pref_Prefs extends Handler_Protected { $tpl->readTemplateFromFile("otp_disabled_template.txt"); $tpl->setVariable('LOGIN', $row["login"]); - $tpl->setVariable('TTRSS_HOST', Config::get(Config::SELF_URL_PATH)); + $tpl->setVariable('TTRSS_HOST', Config::get_self_url()); $tpl->addBlock('message'); @@ -1024,7 +1024,7 @@ class Pref_Prefs extends Handler_Protected { } function setplugins(): void { - $plugins = array_filter($_REQUEST["plugins"], 'clean') ?? []; + $plugins = array_filter($_REQUEST["plugins"] ?? [], 'clean'); set_pref(Prefs::_ENABLED_PLUGINS, implode(",", $plugins)); } @@ -1069,9 +1069,7 @@ class Pref_Prefs extends Handler_Protected { } } - $rv = array_values(array_filter($rv, function ($item) { - return $item["rv"]["need_update"]; - })); + $rv = array_values(array_filter($rv, fn($item) => $item["rv"]["need_update"])); return $rv; } diff --git a/classes/pref/users.php b/classes/pref/users.php index c48619614..78291592d 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -82,11 +82,10 @@ class Pref_Users extends Handler_Administrative { <?php while ($row = $sth->fetch()) { ?> <li> <?php - $icon_file = Config::get(Config::ICONS_URL) . "/" . $row["id"] . ".ico"; - $icon = file_exists($icon_file) ? $icon_file : "images/blank_icon.gif"; + $icon_url = Feeds::_get_icon_url($row['id'], 'images/blank_icon.gif'); ?> - <img class="icon" src="<?= $icon_file ?>"> + <img class="icon" src="<?= htmlspecialchars($icon_url) ?>"> <a target="_blank" href="<?= htmlspecialchars($row["site_url"]) ?>"> <?= htmlspecialchars($row["title"]) ?> |