Change add feed action (#3027)

* Docker Alpine 3.12 (#3025)

https://alpinelinux.org/posts/Alpine-3.12.0-released.html
With PHP 7.3.18 (from 7.3.17) (and Apache 2.4.43 unchanged).
No other significant change spotted

* Ensure feed attributes are used before load

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
This commit is contained in:
Alexis Degrugillier
2020-06-05 10:09:31 +02:00
committed by GitHub
parent 27f0b61418
commit d4554fa087
49 changed files with 247 additions and 109 deletions

View File

@@ -39,7 +39,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
* @throws FreshRSS_Feed_Exception
* @throws Minz_FileNotExistException
*/
public static function addFeed($url, $title = '', $cat_id = 0, $new_cat_name = '', $http_auth = '') {
public static function addFeed($url, $title = '', $cat_id = 0, $new_cat_name = '', $http_auth = '', $attributes = array()) {
FreshRSS_UserDAO::touch();
@set_time_limit(300);
@@ -67,6 +67,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$cat_id = $cat == null ? FreshRSS_CategoryDAO::DEFAULTCATEGORYID : $cat->id();
$feed = new FreshRSS_Feed($url); //Throws FreshRSS_BadUrl_Exception
$feed->_attributes('', $attributes);
$feed->_httpAuth($http_auth);
$feed->load(true); //Throws FreshRSS_Feed_Exception, Minz_FileNotExistException
$feed->_category($cat_id);
@@ -90,7 +91,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
'description' => $feed->description(),
'lastUpdate' => time(),
'httpAuth' => $feed->httpAuth(),
'attributes' => array(),
'attributes' => $feed->attributes(),
);
$id = $feedDAO->addFeed($values);
@@ -141,7 +142,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$feedDAO = FreshRSS_Factory::createFeedDao();
$url_redirect = array(
'c' => 'subscription',
'a' => 'index',
'a' => 'add',
'params' => array(),
);
@@ -154,13 +155,6 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
if (Minz_Request::isPost()) {
$cat = Minz_Request::param('category');
$new_cat_name = '';
if ($cat === 'nc') {
// User want to create a new category, new_category parameter
// must exist
$new_cat = Minz_Request::param('new_category');
$new_cat_name = isset($new_cat['name']) ? trim($new_cat['name']) : '';
}
// HTTP information are useful if feed is protected behind a
// HTTP authentication
@@ -171,8 +165,18 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$http_auth = $user . ':' . $pass;
}
$attributes = array(
'ssl_verify' => null,
'timeout' => null,
);
if (FreshRSS_Auth::hasAccess('admin')) {
$attributes['ssl_verify'] = Minz_Request::paramTernary('ssl_verify');
$timeout = intval(Minz_Request::param('timeout', 0));
$attributes['timeout'] = $timeout > 0 ? $timeout : null;
}
try {
$feed = self::addFeed($url, '', $cat, $new_cat_name, $http_auth);
$feed = self::addFeed($url, '', $cat, null, $http_auth, $attributes);
} catch (FreshRSS_BadUrl_Exception $e) {
// Given url was not a valid url!
Minz_Log::warning($e->getMessage());
@@ -192,6 +196,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
}
// Entries are in DB, we redirect to feed configuration page.
$url_redirect['a'] = 'index';
$url_redirect['params']['id'] = $feed->id();
Minz_Request::good(_t('feedback.sub.feed.added', $feed->name()), $url_redirect);
} else {
@@ -212,6 +217,7 @@ class FreshRSS_feed_Controller extends Minz_ActionController {
$feed = $feedDAO->searchByUrl($this->view->feed->url());
if ($feed) {
// Already subscribe so we redirect to the feed configuration page.
$url_redirect['a'] = 'index';
$url_redirect['params']['id'] = $feed->id();
Minz_Request::good(_t('feedback.sub.feed.already_subscribed', $feed->name()), $url_redirect);
}