From d30ac40772ec1b4706922afd8acab8448af39a9e Mon Sep 17 00:00:00 2001 From: Julien-Pierre Avérous Date: Thu, 13 Feb 2020 19:22:35 +0200 Subject: Enhance content path feature (#2778) - Add a maintenance section to be able to clear cache and force reload a feed. - Add an icon next to path field to show a pop-up with the result of the content path. Co-authored-by: Frans de Jonge Co-authored-by: Alexandre Alapetite Co-authored-by: Marien Fressinaud --- app/Controllers/feedController.php | 141 +++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) (limited to 'app/Controllers/feedController.php') diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.php index d395f76d0..38aa09223 100755 --- a/app/Controllers/feedController.php +++ b/app/Controllers/feedController.php @@ -647,6 +647,147 @@ class FreshRSS_feed_Controller extends Minz_ActionController { } } + /** + * This action force clears the cache of a feed. + * + * Parameters are: + * - id (mandatory - no default): Feed ID + * + */ + public function clearCacheAction() { + //Get Feed. + $id = Minz_Request::param('id'); + + $feedDAO = FreshRSS_Factory::createFeedDao(); + $feed = $feedDAO->searchById($id); + + if (!$feed) { + Minz_Request::bad(_t('feedback.sub.feed.not_found'), array()); + return; + } + + $feed->clearCache(); + + Minz_Request::good(_t('feedback.sub.feed.cache_cleared', $feed->name()), array( + 'params' => array('get' => 'f_' . $feed->id()) + )); + } + + /** + * This action forces reloading the articles of a feed. + * + * Parameters are: + * - id (mandatory - no default): Feed ID + * + */ + public function reloadAction() { + @set_time_limit(300); + + //Get Feed ID. + $feed_id = Minz_Request::param('id'); + + $feedDAO = FreshRSS_Factory::createFeedDao(); + $entryDAO = FreshRSS_Factory::createEntryDao(); + + $feed = $feedDAO->searchById($feed_id); + + if (!$feed) { + Minz_Request::bad(_t('feedback.sub.feed.not_found'), array()); + return; + } + + //Re-fetch articles as if the feed was new. + self::actualizeFeed($feed_id, null, false, null, true); + + //Extract all feed entries from database, load complete content and store them back in database. + $entries = $entryDAO->listWhere('f', $feed_id, FreshRSS_Entry::STATE_ALL, 'DESC', 0); + + $entryDAO->beginTransaction(); + + foreach ($entries as $entry) { + $entry->loadCompleteContent(true); + $entryDAO->updateEntry($entry->toArray()); + } + + $entryDAO->commit(); + + //Give feedback to user. + Minz_Request::good(_t('feedback.sub.feed.reloaded', $feed->name()), array( + 'params' => array('get' => 'f_' . $feed->id()) + )); + } + + /** + * This action creates a preview of a content-selector. + * + * Parameters are: + * - id (mandatory - no default): Feed ID + * - selector (mandatory - no default): Selector to preview + * + */ + public function contentSelectorPreviewAction() { + + //Configure. + $this->view->fatalError = ''; + $this->view->selectorSuccess = false; + $this->view->htmlContent = ''; + + $this->view->_layout(false); + + $this->_csp([ + 'default-src' => "'self'", + 'frame-src' => '*', + 'img-src' => '* data:', + 'media-src' => '*', + ]); + + //Get parameters. + $feed_id = Minz_Request::param('id'); + $content_selector = trim(Minz_Request::param('selector')); + + if (!$content_selector) { + $this->view->fatalError = _t('feedback.sub.feed.selector_preview.selector_empty'); + return; + } + + //Check Feed ID validity. + $entryDAO = FreshRSS_Factory::createEntryDao(); + $entries = $entryDAO->listWhere('f', $feed_id); + + if (empty($entries)) { + $this->view->fatalError = _t('feedback.sub.feed.selector_preview.no_entries'); + return; + } + + //Get feed & entry. + $entry = $entries[0]; + $feed = $entry->feed(true); + + if (!$feed) { + $this->view->fatalError = _t('feedback.sub.feed.selector_preview.no_feed'); + return; + } + + //Fetch & select content. + try { + $fullContent = FreshRSS_Entry::getContentByParsing( + htmlspecialchars_decode($entry->link(), ENT_QUOTES), + $content_selector, + $feed->attributes() + ); + + if ($fullContent != '') { + $this->view->selectorSuccess = true; + $this->view->htmlContent = $fullContent; + } else { + $this->view->selectorSuccess = false; + $this->view->htmlContent = $entry->content(); + } + } catch (Exception $e) { + $this->view->fatalError = _t('feedback.sub.feed.selector_preview.http_error'); + } + } + /** * This method update TTL values for feeds if needed. * It changes the old default value (-2) to the new default value (0). -- cgit v1.2.3