diff options
| author | 2020-02-13 19:22:35 +0200 | |
|---|---|---|
| committer | 2020-02-13 18:22:35 +0100 | |
| commit | d30ac40772ec1b4706922afd8acab8448af39a9e (patch) | |
| tree | 6b7cec8455a542875959a09f7bdcc7a2af285fa1 /app/Controllers | |
| parent | 4ddd1821bb0fc1186937551d59100294b8833727 (diff) | |
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 <fransdejonge@gmail.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Co-authored-by: Marien Fressinaud <dev@marienfressinaud.fr>
Diffstat (limited to 'app/Controllers')
| -rwxr-xr-x | app/Controllers/feedController.php | 141 |
1 files changed, 141 insertions, 0 deletions
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 @@ -648,6 +648,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). * It changes the old disabled value (-1) to the default disabled value. |
