Răsfoiți Sursa

Allow selecting a category in feed add URLs (#9047)

* Support categories in feed add URLs

## Summary

- Honour the `category` query parameter when opening the add-feed form.
- Keep the existing `cat_id` parameter as a backwards-compatible fallback.
- Use `category` for the add-feed links in the subscription view.

This makes the URL proposed in #4160 select the intended category:
`?c=feed&a=add&category=1&url_rss=https://example.com/feed.xml`.

## Validation

- PHP syntax checks for the changed controller and templates.
- Focused request-parameter checks for explicit `category`, legacy `cat_id`, and the default category.

Fixes #4160


* Simplify and small fixes

---------

Co-authored-by: Gerard Alvear <gerard.alvear@logiqd.me>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Gerard Alvear Porras 1 săptămână în urmă
părinte
comite
6996447d54

+ 1 - 0
app/Controllers/feedController.php

@@ -124,6 +124,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {
 	 * GET request displays a form to add and configure a feed.
 	 * Request parameter is:
 	 *   - url_rss (default: false)
+	 *   - cat_id (default: 1)
 	 *
 	 * POST request adds a feed in database.
 	 * Parameters are:

+ 1 - 1
app/views/feed/add.phtml

@@ -58,7 +58,7 @@
 				<div class="group-controls">
 					<select name="category" id="category">
 						<?php foreach ($this->categories as $cat) { ?>
-						<option value="<?= $cat->id() ?>"<?= $cat->id() == 1 ? ' selected="selected"' : '' ?>>
+						<option value="<?= $cat->id() ?>"<?= $cat->id() === (Minz_Request::paramInt('cat_id') ?: 1) ? ' selected="selected"' : '' ?>>
 							<?= $cat->name() ?>
 						</option>
 						<?php } ?>

+ 2 - 2
app/views/subscription/bookmarklet.phtml

@@ -8,10 +8,10 @@
 	<h2><?= _t('sub.bookmarklet.title') ?></h2>
 	<p><a class="btn btn-important"
 		href="javascript:(function(){var%20url%20=%20location.href;var%20otherWindow=window.open('about:blank','_blank');otherWindow.opener=null;otherWindow.location='<?=
-		Minz_Url::display(['c' => 'feed', 'a' => 'add'], 'html', true) ?>&amp;url_rss='+encodeURIComponent(url);})();"><?= _t('sub.bookmarklet.label') ?></a></p>
+		Minz_Url::display(['c' => 'feed', 'a' => 'add'], 'html', true) ?>&amp;cat_id=1&amp;url_rss='+encodeURIComponent(url);})();"><?= _t('sub.bookmarklet.label') ?></a></p>
 	<?= _t('sub.bookmarklet.documentation') ?>
 
 	<h2><?= _t('sub.api.title') ?></h2>
 	<p><?= _t('sub.api.documentation') ?></p>
-	<kbd><?= Minz_Url::display(['c' => 'feed', 'a' => 'add'], 'html', true) ?>&amp;url_rss=%s</kbd>
+	<kbd><?= Minz_Url::display(['c' => 'feed', 'a' => 'add'], 'html', true) ?>&amp;cat_id=1&amp;url_rss=%s</kbd>
 </main>