Refactor OPML export categories (#4356)

* Refactor OPML export categories
Simplify code to comply with types hints.
And renamed a property to plural.

* Link to OPML namespace
pull/4357/head^2
Alexandre Alapetite 2 years ago committed by GitHub
parent 4a87206f28
commit da0a333b94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      app/Models/Category.php
  2. 1
      app/Models/View.php
  3. 9
      app/Services/ExportService.php
  4. 5
      app/views/helpers/export/opml.phtml
  5. 4
      docs/en/developers/01_Index.md

@ -6,7 +6,7 @@ class FreshRSS_Category extends Minz_Model {
*/
private $id = 0;
private $name;
private $nbFeed = -1;
private $nbFeeds = -1;
private $nbNotRead = -1;
private $feeds = null;
private $hasFeedsWithError = false;
@ -17,10 +17,10 @@ class FreshRSS_Category extends Minz_Model {
$this->_name($name);
if (isset($feeds)) {
$this->_feeds($feeds);
$this->nbFeed = 0;
$this->nbFeeds = 0;
$this->nbNotRead = 0;
foreach ($feeds as $feed) {
$this->nbFeed++;
$this->nbFeeds++;
$this->nbNotRead += $feed->nbNotRead();
$this->hasFeedsWithError |= $feed->inError();
}
@ -36,13 +36,13 @@ class FreshRSS_Category extends Minz_Model {
public function isDefault(): bool {
return $this->isDefault;
}
public function nbFeed(): int {
if ($this->nbFeed < 0) {
public function nbFeeds(): int {
if ($this->nbFeeds < 0) {
$catDAO = FreshRSS_Factory::createCategoryDao();
$this->nbFeed = $catDAO->countFeed($this->id());
$this->nbFeeds = $catDAO->countFeed($this->id());
}
return $this->nbFeed;
return $this->nbFeeds;
}
public function nbNotRead(): int {
if ($this->nbNotRead < 0) {
@ -56,18 +56,18 @@ class FreshRSS_Category extends Minz_Model {
if ($this->feeds === null) {
$feedDAO = FreshRSS_Factory::createFeedDao();
$this->feeds = $feedDAO->listByCategory($this->id());
$this->nbFeed = 0;
$this->nbFeeds = 0;
$this->nbNotRead = 0;
foreach ($this->feeds as $feed) {
$this->nbFeed++;
$this->nbFeeds++;
$this->nbNotRead += $feed->nbNotRead();
$this->hasFeedsWithError |= $feed->inError();
}
}
usort($this->feeds, function ($a, $b) {
return strnatcasecmp($a->name(), $b->name());
});
usort($this->feeds, function ($a, $b) {
return strnatcasecmp($a->name(), $b->name());
});
}
return $this->feeds;
}

@ -6,6 +6,7 @@ class FreshRSS_View extends Minz_View {
public $callbackBeforeEntries;
public $callbackBeforeFeeds;
public $callbackBeforePagination;
/** @var array<FreshRSS_Category> */
public $categories;
/** @var FreshRSS_Category|null */
public $category;

@ -47,14 +47,7 @@ class FreshRSS_Export_Service {
$view = new FreshRSS_View();
$day = date('Y-m-d');
$categories = [];
foreach ($this->category_dao->listCategories() as $key => $category) {
$categories[$key]['name'] = $category->name();
$categories[$key]['feeds'] = $this->feed_dao->listByCategory($category->id());
}
$view->categories = $categories;
$view->categories = $this->category_dao->listCategories(true);
return [
"feeds_{$day}.opml.xml",

@ -11,12 +11,11 @@ $opml_array = array(
foreach ($this->categories as $key => $cat) {
$opml_array['body'][$key] = array(
'text' => $cat['name'],
'text' => $cat->name(),
'@outlines' => array()
);
/** @var FreshRSS_Feed $feed */
foreach ($cat['feeds'] as $feed) {
foreach ($cat->feeds() as $feed) {
$outline = [
'text' => htmlspecialchars_decode($feed->name(), ENT_QUOTES),
'type' => FreshRSS_Export_Service::TYPE_RSS_ATOM,

@ -26,6 +26,10 @@ Start by creating your development environment. A guide to setting up FreshRSS
* [View files](04_Frontend/01_View_files.md)
* [Design (Themes/Theming)](04_Frontend/02_Design.md)
## Namespaces
* [OPML FreshRSS namespace](OPML.md)
## Minz
Minz is the homemade PHP framework used by FreshRSS. More information can be found [here](Minz/index.md).

Loading…
Cancel
Save