Skip to content

Commit

Permalink
Empty title guid or first words (FreshRSS#6240)
Browse files Browse the repository at this point in the history
* settings

* add comments for better understanding

* Update reading.phtml

* overhaul the code

* i18n

* typo

* add a constant to configure the amount of chars

* fix

* simplify

* Update Entry.php

* clean

* Update Entry.php

* Update app/Models/Entry.php

Co-authored-by: Alexandre Alapetite <[email protected]>

* Update constants.php

* Update app/Models/Entry.php

---------

Co-authored-by: Alexandre Alapetite <[email protected]>
  • Loading branch information
math-GH and Alkarex authored Jun 5, 2024
1 parent 99b1d55 commit fec9e53
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
22 changes: 21 additions & 1 deletion app/Models/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,27 @@ public function guid(): string {
return $this->guid;
}
public function title(): string {
return $this->title == '' ? $this->guid() : $this->title;
$title = '';

if ($this->title === '') {
// used while fetching the article from feed and store it in the database
$title = $this->guid();
} else {
// used while fetching from the database
if ($this->title !== $this->guid) {
$title = $this->title;
} else {
$content = trim(strip_tags($this->content(false)));
$title = trim(mb_substr($content, 0, MAX_CHARS_EMPTY_FEED_TITLE, 'UTF-8'));

if ($title === '') {
$title = $this->guid();
} elseif (strlen($content) > strlen($title)) {
$title .= '';
}
}
}
return $title;
}
/** @deprecated */
public function author(): string {
Expand Down
1 change: 1 addition & 0 deletions app/views/configure/reading.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
</select>
</div>
</div>

<div class="form-group">
<label class="group-name" for="show_author_date"><?= _t('conf.reading.article.authors_date') ?></label>
<div class="group-controls">
Expand Down
3 changes: 3 additions & 0 deletions constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
// Maximum log file size in Bytes, before it will be divided by two
defined('MAX_LOG_SIZE') or define('MAX_LOG_SIZE', 1048576);

// Amount of characters of text shown if feed has no title
defined('MAX_CHARS_EMPTY_FEED_TITLE') or define('MAX_CHARS_EMPTY_FEED_TITLE', 75);

//This directory must be writable
$dataPath = getenv('DATA_PATH');
if (is_string($dataPath) && $dataPath !== '') {
Expand Down

0 comments on commit fec9e53

Please sign in to comment.