4
0

javascriptController.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. declare(strict_types=1);
  3. class FreshRSS_javascript_Controller extends FreshRSS_ActionController {
  4. /**
  5. * @var FreshRSS_ViewJavascript
  6. * @phpstan-ignore property.phpDocType
  7. */
  8. protected $view;
  9. public function __construct() {
  10. parent::__construct(FreshRSS_ViewJavascript::class);
  11. }
  12. #[\Override]
  13. public function firstAction(): void {
  14. $this->view->_layout(null);
  15. }
  16. public function actualizeAction(): void {
  17. if (!FreshRSS_Auth::hasAccess() && !FreshRSS_Auth::allowAnonymousRefresh()) {
  18. Minz_Error::error(403);
  19. return;
  20. }
  21. header('Content-Type: application/json; charset=UTF-8');
  22. Minz_Session::_param('actualize_feeds', false);
  23. $databaseDAO = FreshRSS_Factory::createDatabaseDAO();
  24. $databaseDAO->minorDbMaintenance();
  25. Minz_ExtensionManager::callHookVoid(Minz_HookType::FreshrssUserMaintenance);
  26. $catDAO = FreshRSS_Factory::createCategoryDao();
  27. $this->view->categories = $catDAO->listCategoriesOrderUpdate(FreshRSS_Context::userConf()->dynamic_opml_ttl_default);
  28. $feedDAO = FreshRSS_Factory::createFeedDao();
  29. $this->view->feeds = $feedDAO->listFeedsOrderUpdate(FreshRSS_Context::userConf()->ttl_default);
  30. // When the refresh button is used from a feed or category view, limit the
  31. // batch to the feeds visible in that view.
  32. $get = Minz_Request::paramString('get');
  33. if (preg_match('/^c_(\d+)$/', $get, $matches)) {
  34. $category = $this->view->categories[(int)$matches[1]] ?? null;
  35. if ($category !== null) {
  36. $this->view->categories = [$category->id() => $category];
  37. // Filter feeds to keep only those from the selected category, preserving the order
  38. $this->view->feeds = array_filter($this->view->feeds, static fn(FreshRSS_Feed $feed) => $feed->category() === $category->id());
  39. }
  40. } elseif (preg_match('/^f_(\d+)$/', $get, $matches)) {
  41. $feed = $feedDAO->searchById((int)$matches[1]);
  42. $this->view->categories = [];
  43. $this->view->feeds = $feed === null ? [] : [$feed->id() => $feed];
  44. }
  45. }
  46. public function nbUnreadsPerFeedAction(): void {
  47. if (!FreshRSS_Auth::hasAccess() && !FreshRSS_Auth::allowAnonymous()) {
  48. Minz_Error::error(403);
  49. return;
  50. }
  51. header('Content-Type: application/json; charset=UTF-8');
  52. $catDAO = FreshRSS_Factory::createCategoryDao();
  53. $this->view->categories = $catDAO->listCategories(prePopulateFeeds: true, details: false);
  54. $tagDAO = FreshRSS_Factory::createTagDao();
  55. $this->view->tags = $tagDAO->listTags(precounts: true);
  56. }
  57. }