Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/php8.1 depreciation #1861

Merged
merged 5 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ The format is mostly based on [Keep a Changelog](https://keepachangelog.com/en/1
### Changed

### Fixed
- fix PHP 8.1 deprecations (#1861)
- document api item types (#1861)

# Releases
## [18.1.1] - 2022-08-12
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"phpstan/phpstan-strict-rules": "^1.3.0",
"phpstan/phpstan-phpunit": "^1.0.0",
"phpstan/extension-installer": "^1.1.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"guzzlehttp/guzzle": "^7.3.0",
"doctrine/dbal": "^3.4.1",
"symfony/console": "^4.4.19",
Expand Down
52 changes: 51 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions docs/api/api-v1-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,30 @@ The following attributes are **not sanitized** meaning: including them in your w
* **mediaThumbnail**
* **mediaDescription**

#### Types
| Name | Default | Types |
|------------------|---------|--------------|
| author | null | string\|null |
| body | | string\|null |
| contentHash | | string\|null |
| enclosureLink | | string\|null |
| enclosureMime | | string\|null |
| feedId | | int |
| fingerprint | | string\|null |
| guid | | string |
| guidHash | | string |
| id | | int |
| lastModified | \"0\" | string\|null |
| mediaDescription | | string\|null |
| mediaThumbnail | | string\|null |
| pubDate | | int\|null |
| rtl | false | bool |
| starred | false | bool |
| title | | string\|null |
| unread | false | bool |
| updatedDate | | string\|null |
| url | | string\|null |

#### Get items
* **Status**: Implemented
* **Method**: GET
Expand Down
24 changes: 24 additions & 0 deletions docs/api/api-v1-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,30 @@ The following attributes are **not sanitized** meaning: including them in your w
* **mediaThumbnail**
* **mediaDescription**

#### Types
| Name | Default | Types |
|------------------|---------|--------------|
| author | null | string\|null |
| body | | string\|null |
| contentHash | | string\|null |
| enclosureLink | | string\|null |
| enclosureMime | | string\|null |
| feedId | | int |
| fingerprint | | string\|null |
| guid | | string |
| guidHash | | string |
| id | | int |
| lastModified | \"0\" | string\|null |
| mediaDescription | | string\|null |
| mediaThumbnail | | string\|null |
| pubDate | | int\|null |
| rtl | false | bool |
| starred | false | bool |
| title | | string\|null |
| unread | false | bool |
| updatedDate | | string\|null |
| url | | string\|null |

#### Get items
* **Status**: Implemented
* **Method**: GET
Expand Down
37 changes: 26 additions & 11 deletions lib/Db/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,24 @@ public function generateSearchIndex(): void
? implode('', $this->getCategories())
: '';

$this->setSearchIndex(
mb_strtolower(
html_entity_decode(strip_tags($this->getBody())) .
html_entity_decode($this->getAuthor()) .
html_entity_decode($this->getTitle()) .
html_entity_decode($categoriesString) .
$this->getUrl(),
'UTF-8'
)
);
$stripedBody = "";
if (!is_null($this->getBody())) {
$stripedBody = strip_tags($this->getBody());
}

$input_list = array($stripedBody, $this->getAuthor(), $this->getTitle(), $categoriesString);

$search_string = "";

foreach ($input_list as $value) {
if (!is_null($value)) {
$search_string .= html_entity_decode($value);
}
}

$search_string .= $this->getUrl();

$this->setSearchIndex(mb_strtolower($search_string, 'UTF-8'));
$this->setFingerprint($this->computeFingerprint());
$this->setContentHash($this->computeContentHash());
}
Expand Down Expand Up @@ -346,6 +354,9 @@ public function getCategoriesJson(): ?string
*/
public function getCategories(): ?array
{
if (is_null($this->getCategoriesJson())) {
return null;
}
return json_decode($this->getCategoriesJson());
}

Expand Down Expand Up @@ -594,14 +605,18 @@ public function setUnread(bool $unread): self

public function setUrl(string $url = null): self
{
if (is_null($url)) {
return $this;
}

$url = trim($url);
if ((strpos($url, 'http') === 0 || strpos($url, 'magnet') === 0)
&& $this->url !== $url
) {
$this->url = $url;
$this->markFieldUpdated('url');
}

Grotax marked this conversation as resolved.
Show resolved Hide resolved
return $this;
}

Expand Down
9 changes: 7 additions & 2 deletions lib/Fetcher/FeedFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,14 @@ protected function buildItem(
*/
protected function getFavicon(FeedInterface $feed, string $url)
{
$favicon = null;
// trim the string because authors do funny things
$favicon = trim($feed->getLogo());

$feed_logo = $feed->getLogo();

if (!is_null($feed_logo)) {
$favicon = trim($feed_logo);
}

ini_set('user_agent', 'NextCloud-News/1.0');

$base_url = new Net_URL2($url);
Expand Down
20 changes: 15 additions & 5 deletions lib/Utility/OPMLExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,21 @@ public function build(array $folders, array $feeds)
protected function createFeedOutline(Feed $feed, DOMDocument $document)
{
$feedOutline = $document->createElement('outline');
$feedOutline->setAttribute('title', $feed->getTitle());
$feedOutline->setAttribute('text', $feed->getTitle());
$feedOutline->setAttribute('type', 'rss');
$feedOutline->setAttribute('xmlUrl', $feed->getUrl());
$feedOutline->setAttribute('htmlUrl', $feed->getLink());
$attributes = [
['title', $feed->getTitle()],
['text', $feed->getTitle()],
['type', 'rss'],
['xmlUrl', $feed->getUrl()],
['htmlUrl', $feed->getLink()],
];

foreach ($attributes as $attribute) {
if (is_null($attribute[1])) {
$feedOutline->setAttribute($attribute[0], "");
} else {
$feedOutline->setAttribute($attribute[0], $attribute[1]);
}
}
Grotax marked this conversation as resolved.
Show resolved Hide resolved

return $feedOutline;
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Unit/Db/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,18 @@ public function testSearchIndex()
$this->assertEquals($expected, $item->getSearchIndex());
}

public function testSearchIndexNull()
{
$item = new Item();
$item->setBody('<a>somEth&auml;ng</a>');
$item->setUrl('http://link');
$item->setAuthor(null);
$item->setTitle('<a>t&auml;tle</a>');
$item->setCategories(['food', 'travel']);
$item->generateSearchIndex();
$expected = 'somethängtätlefoodtravelhttp://link';
$this->assertEquals($expected, $item->getSearchIndex());
}

public function testFromImport()
{
Expand Down