aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Feed.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Models/Feed.php')
-rw-r--r--app/Models/Feed.php74
1 files changed, 41 insertions, 33 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index dbe6aaa73..024a7841a 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -82,7 +82,7 @@ class FreshRSS_Feed extends Minz_Model {
public function hash(): string {
if ($this->hash == '') {
- $salt = FreshRSS_Context::$system_conf->salt;
+ $salt = FreshRSS_Context::systemConf()->salt;
$this->hash = hash('crc32b', $salt . $this->url);
}
return $this->hash;
@@ -126,7 +126,7 @@ class FreshRSS_Feed extends Minz_Model {
return $simplePie == null ? [] : iterator_to_array($this->loadEntries($simplePie));
}
public function name(bool $raw = false): string {
- return $raw || $this->name != '' ? $this->name : preg_replace('%^https?://(www[.])?%i', '', $this->url);
+ return $raw || $this->name != '' ? $this->name : (preg_replace('%^https?://(www[.])?%i', '', $this->url) ?? '');
}
/** @return string HTML-encoded URL of the Web site of the feed */
public function website(): string {
@@ -179,7 +179,7 @@ class FreshRSS_Feed extends Minz_Model {
if ($raw) {
$ttl = $this->ttl;
if ($this->mute && FreshRSS_Feed::TTL_DEFAULT === $ttl) {
- $ttl = FreshRSS_Context::$user_conf ? FreshRSS_Context::$user_conf->ttl_default : 3600;
+ $ttl = FreshRSS_Context::userConf()->ttl_default;
}
return $ttl * ($this->mute ? -1 : 1);
}
@@ -331,7 +331,7 @@ class FreshRSS_Feed extends Minz_Model {
} else {
$url = htmlspecialchars_decode($this->url, ENT_QUOTES);
if ($this->httpAuth != '') {
- $url = preg_replace('#((.+)://)(.+)#', '${1}' . $this->httpAuth . '@${3}', $url);
+ $url = preg_replace('#((.+)://)(.+)#', '${1}' . $this->httpAuth . '@${3}', $url) ?? '';
}
$simplePie = customSimplePie($this->attributes());
if (substr($url, -11) === '#force_feed') {
@@ -342,7 +342,7 @@ class FreshRSS_Feed extends Minz_Model {
if (!$loadDetails) { //Only activates auto-discovery when adding a new feed
$simplePie->set_autodiscovery_level(SIMPLEPIE_LOCATOR_NONE);
}
- if ($this->attributes('clear_cache')) {
+ if ($this->attributeBoolean('clear_cache')) {
// Do not use `$simplePie->enable_cache(false);` as it would prevent caching in multiuser context
$this->clearCache();
}
@@ -370,7 +370,7 @@ class FreshRSS_Feed extends Minz_Model {
if ($loadDetails) {
// si on a utilisé l’auto-discover, notre url va avoir changé
- $subscribe_url = $simplePie->subscribe_url(false);
+ $subscribe_url = $simplePie->subscribe_url(false) ?? '';
if ($this->name(true) === '') {
//HTML to HTML-PRE //ENT_COMPAT except '&'
@@ -385,11 +385,11 @@ class FreshRSS_Feed extends Minz_Model {
}
} else {
//The case of HTTP 301 Moved Permanently
- $subscribe_url = $simplePie->subscribe_url(true);
+ $subscribe_url = $simplePie->subscribe_url(true) ?? '';
}
$clean_url = SimplePie_Misc::url_remove_credentials($subscribe_url);
- if ($subscribe_url !== null && $subscribe_url !== $url) {
+ if ($subscribe_url !== '' && $subscribe_url !== $url) {
$this->_url($clean_url);
}
@@ -411,7 +411,7 @@ class FreshRSS_Feed extends Minz_Model {
$testGuids = [];
$guids = [];
$links = [];
- $hadBadGuids = $this->attributes('hasBadGuids');
+ $hadBadGuids = $this->attributeBoolean('hasBadGuids');
$items = $simplePie->get_items();
if (empty($items)) {
@@ -426,7 +426,10 @@ class FreshRSS_Feed extends Minz_Model {
$hasUniqueGuids &= empty($testGuids['_' . $guid]);
$testGuids['_' . $guid] = true;
$guids[] = $guid;
- $links[] = $item->get_permalink();
+ $permalink = $item->get_permalink();
+ if ($permalink != null) {
+ $links[] = $permalink;
+ }
}
if ($hadBadGuids != !$hasUniqueGuids) {
@@ -444,7 +447,7 @@ class FreshRSS_Feed extends Minz_Model {
/** @return Traversable<FreshRSS_Entry> */
public function loadEntries(SimplePie $simplePie): Traversable {
- $hasBadGuids = $this->attributes('hasBadGuids');
+ $hasBadGuids = $this->attributeBoolean('hasBadGuids');
$items = $simplePie->get_items();
if (empty($items)) {
@@ -560,15 +563,15 @@ class FreshRSS_Feed extends Minz_Model {
$title == '' ? '' : $title,
$authorNames,
$content == '' ? '' : $content,
- $link == '' ? '' : $link,
+ $link == null ? '' : $link,
$date ?: time()
);
$entry->_tags($tags);
$entry->_feed($this);
if (!empty($attributeThumbnail['url'])) {
- $entry->_attributes('thumbnail', $attributeThumbnail);
+ $entry->_attribute('thumbnail', $attributeThumbnail);
}
- $entry->_attributes('enclosures', $attributeEnclosures);
+ $entry->_attribute('enclosures', $attributeEnclosures);
$entry->hash(); //Must be computed before loading full content
$entry->loadCompleteContent(); // Optionally load full content for truncated feeds
@@ -587,11 +590,14 @@ class FreshRSS_Feed extends Minz_Model {
if ($this->httpAuth != '') {
$feedSourceUrl = preg_replace('#((.+)://)(.+)#', '${1}' . $this->httpAuth . '@${3}', $feedSourceUrl);
}
+ if ($feedSourceUrl == null) {
+ return null;
+ }
// Same naming conventions than https://rss-bridge.github.io/rss-bridge/Bridge_API/XPathAbstract.html
// https://rss-bridge.github.io/rss-bridge/Bridge_API/BridgeAbstract.html#collectdata
/** @var array<string,string> $xPathSettings */
- $xPathSettings = $this->attributes('xpath');
+ $xPathSettings = $this->attributeArray('xpath');
$xPathFeedTitle = $xPathSettings['feedTitle'] ?? '';
$xPathItem = $xPathSettings['item'] ?? '';
$xPathItemTitle = $xPathSettings['itemTitle'] ?? '';
@@ -725,9 +731,9 @@ class FreshRSS_Feed extends Minz_Model {
* @throws JsonException
*/
public function keepMaxUnread() {
- $keepMaxUnread = $this->attributes('keep_max_n_unread');
+ $keepMaxUnread = $this->attributeInt('keep_max_n_unread');
if ($keepMaxUnread === null) {
- $keepMaxUnread = FreshRSS_Context::$user_conf->mark_when['max_n_unread'];
+ $keepMaxUnread = FreshRSS_Context::userConf()->mark_when['max_n_unread'];
}
return is_int($keepMaxUnread) && $keepMaxUnread >= 0 ? $keepMaxUnread : null;
}
@@ -754,9 +760,9 @@ class FreshRSS_Feed extends Minz_Model {
* @return int|false the number of lines affected, or false if not applicable
*/
public function markAsReadUponGone(bool $upstreamIsEmpty, int $maxTimestamp = 0) {
- $readUponGone = $this->attributes('read_upon_gone');
+ $readUponGone = $this->attributeBoolean('read_upon_gone');
if ($readUponGone === null) {
- $readUponGone = FreshRSS_Context::$user_conf->mark_when['gone'];
+ $readUponGone = FreshRSS_Context::userConf()->mark_when['gone'];
}
if (!$readUponGone) {
return false;
@@ -782,13 +788,15 @@ class FreshRSS_Feed extends Minz_Model {
* @return int|false
*/
public function cleanOldEntries() {
- $archiving = $this->attributes('archiving');
- if ($archiving == null) {
+ /** @var array<string,bool|int|string>|null $archiving */
+ $archiving = $this->attributeArray('archiving');
+ if ($archiving === null) {
$catDAO = FreshRSS_Factory::createCategoryDao();
$category = $catDAO->searchById($this->categoryId);
- $archiving = $category == null ? null : $category->attributes('archiving');
- if ($archiving == null) {
- $archiving = FreshRSS_Context::$user_conf->archiving;
+ $archiving = $category === null ? null : $category->attributeArray('archiving');
+ /** @var array<string,bool|int|string>|null $archiving */
+ if ($archiving === null) {
+ $archiving = FreshRSS_Context::userConf()->archiving;
}
}
if (is_array($archiving)) {
@@ -850,7 +858,7 @@ class FreshRSS_Feed extends Minz_Model {
$hubFilename = PSHB_PATH . '/feeds/' . sha1($url) . '/!hub.json';
if ($hubFile = @file_get_contents($hubFilename)) {
$hubJson = json_decode($hubFile, true);
- if ($hubJson && empty($hubJson['error']) &&
+ if (is_array($hubJson) && empty($hubJson['error']) &&
(empty($hubJson['lease_end']) || $hubJson['lease_end'] > time())) {
return true;
}
@@ -862,8 +870,8 @@ class FreshRSS_Feed extends Minz_Model {
$url = $this->selfUrl ?: $this->url;
$hubFilename = PSHB_PATH . '/feeds/' . sha1($url) . '/!hub.json';
$hubFile = @file_get_contents($hubFilename);
- $hubJson = $hubFile ? json_decode($hubFile, true) : [];
- if (!isset($hubJson['error']) || $hubJson['error'] !== $error) {
+ $hubJson = is_string($hubFile) ? json_decode($hubFile, true) : null;
+ if (is_array($hubJson) && !isset($hubJson['error']) || $hubJson['error'] !== $error) {
$hubJson['error'] = $error;
file_put_contents($hubFilename, json_encode($hubJson));
Minz_Log::warning('Set error to ' . ($error ? 1 : 0) . ' for ' . $url, PSHB_LOG);
@@ -876,13 +884,13 @@ class FreshRSS_Feed extends Minz_Model {
*/
public function pubSubHubbubPrepare() {
$key = '';
- if (Minz_Request::serverIsPublic(FreshRSS_Context::$system_conf->base_url) &&
+ if (Minz_Request::serverIsPublic(FreshRSS_Context::systemConf()->base_url) &&
$this->hubUrl && $this->selfUrl && @is_dir(PSHB_PATH)) {
$path = PSHB_PATH . '/feeds/' . sha1($this->selfUrl);
$hubFilename = $path . '/!hub.json';
if ($hubFile = @file_get_contents($hubFilename)) {
$hubJson = json_decode($hubFile, true);
- if (!$hubJson || empty($hubJson['key']) || !ctype_xdigit($hubJson['key'])) {
+ if (!is_array($hubJson) || empty($hubJson['key']) || !ctype_xdigit($hubJson['key'])) {
$text = 'Invalid JSON for WebSub: ' . $this->url;
Minz_Log::warning($text);
Minz_Log::warning($text, PSHB_LOG);
@@ -901,7 +909,7 @@ class FreshRSS_Feed extends Minz_Model {
}
} else {
@mkdir($path, 0770, true);
- $key = sha1($path . FreshRSS_Context::$system_conf->salt);
+ $key = sha1($path . FreshRSS_Context::systemConf()->salt);
$hubJson = [
'hub' => $this->hubUrl,
'key' => $key,
@@ -913,7 +921,7 @@ class FreshRSS_Feed extends Minz_Model {
Minz_Log::debug($text);
Minz_Log::debug($text, PSHB_LOG);
}
- $currentUser = Minz_User::name();
+ $currentUser = Minz_User::name() ?? '';
if (FreshRSS_user_Controller::checkUsername($currentUser) && !file_exists($path . '/' . $currentUser . '.txt')) {
touch($path . '/' . $currentUser . '.txt');
}
@@ -928,7 +936,7 @@ class FreshRSS_Feed extends Minz_Model {
} else {
$url = $this->url; //Always use current URL during unsubscribe
}
- if ($url && (Minz_Request::serverIsPublic(FreshRSS_Context::$system_conf->base_url) || !$state)) {
+ if ($url && (Minz_Request::serverIsPublic(FreshRSS_Context::systemConf()->base_url) || !$state)) {
$hubFilename = PSHB_PATH . '/feeds/' . sha1($url) . '/!hub.json';
$hubFile = @file_get_contents($hubFilename);
if ($hubFile === false) {
@@ -936,7 +944,7 @@ class FreshRSS_Feed extends Minz_Model {
return false;
}
$hubJson = json_decode($hubFile, true);
- if (!$hubJson || empty($hubJson['key']) || !ctype_xdigit($hubJson['key']) || empty($hubJson['hub'])) {
+ if (!is_array($hubJson) || empty($hubJson['key']) || !ctype_xdigit($hubJson['key']) || empty($hubJson['hub'])) {
Minz_Log::warning('Invalid JSON for WebSub: ' . $this->url);
return false;
}