forked from wallabag/wallabag
Merge pull request #8332 from andreadecorte/fix-reading-time-computation
This commit is contained in:
@ -14,6 +14,7 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Wallabag\AnnotationBundle\Entity\Annotation;
|
||||
use Wallabag\CoreBundle\Helper\EntityTimestampsTrait;
|
||||
use Wallabag\CoreBundle\Helper\UrlHasher;
|
||||
use Wallabag\CoreBundle\Tools\Utils;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
|
||||
/**
|
||||
@ -658,6 +659,14 @@ class Entry
|
||||
$this->readingTime = $readingTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getUserReadingTime()
|
||||
{
|
||||
return round($this->readingTime / $this->getUser()->getConfig()->getReadingSpeed() * Utils::DEFAULT_WORDS_PER_MINUTE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@ -16,6 +16,7 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Wallabag\CoreBundle\Repository\EntryRepository;
|
||||
use Wallabag\CoreBundle\Tools\Utils;
|
||||
use Wallabag\UserBundle\Entity\User;
|
||||
|
||||
class EntryFilterType extends AbstractType
|
||||
@ -57,8 +58,8 @@ class EntryFilterType extends AbstractType
|
||||
return;
|
||||
}
|
||||
|
||||
$min = (int) ($lower * $user->getConfig()->getReadingSpeed() / 200);
|
||||
$max = (int) ($upper * $user->getConfig()->getReadingSpeed() / 200);
|
||||
$min = (int) ($lower * $user->getConfig()->getReadingSpeed() / Utils::DEFAULT_WORDS_PER_MINUTE);
|
||||
$max = (int) ($upper * $user->getConfig()->getReadingSpeed() / Utils::DEFAULT_WORDS_PER_MINUTE);
|
||||
|
||||
if (null === $lower && null !== $upper) {
|
||||
// only lower value is defined: query all entries with reading LOWER THAN this value
|
||||
|
||||
@ -210,7 +210,7 @@ class EntriesExport
|
||||
$publishedDate = $entry->getPublishedAt()->format('Y-m-d');
|
||||
}
|
||||
|
||||
$readingTime = round($entry->getReadingTime() / $user->getConfig()->getReadingSpeed() * 200);
|
||||
$readingTime = $entry->getUserReadingTime();
|
||||
|
||||
$titlepage = $content_start .
|
||||
'<h1>' . $entry->getTitle() . '</h1>' .
|
||||
@ -331,7 +331,7 @@ class EntriesExport
|
||||
$authors = implode(',', $publishedBy);
|
||||
}
|
||||
|
||||
$readingTime = $entry->getReadingTime() / $user->getConfig()->getReadingSpeed() * 200;
|
||||
$readingTime = $entry->getUserReadingTime();
|
||||
|
||||
$pdf->addPage();
|
||||
$html = '<h1>' . $entry->getTitle() . '</h1>' .
|
||||
|
||||
@ -133,7 +133,7 @@ class RuleBasedTagger
|
||||
private function fixEntry(Entry $entry)
|
||||
{
|
||||
$clonedEntry = clone $entry;
|
||||
$clonedEntry->setReadingTime($entry->getReadingTime() / $entry->getUser()->getConfig()->getReadingSpeed() * 200);
|
||||
$clonedEntry->setReadingTime($entry->getUserReadingTime());
|
||||
|
||||
return $clonedEntry;
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{% set reading_time = entry.readingTime / app.user.config.readingSpeed * 200 %}
|
||||
{% set reading_time = entry.userReadingTime %}
|
||||
<i class="material-icons grey-text">timer</i>
|
||||
{% if reading_time > 0 %}
|
||||
<span>{{ 'entry.list.reading_time_minutes_short'|trans({'%readingTime%': reading_time|round}) }}</span>
|
||||
<span>{{ 'entry.list.reading_time_minutes_short'|trans({'%readingTime%': reading_time}) }}</span>
|
||||
{% else %}
|
||||
<span>{{ 'entry.list.reading_time_less_one_minute_short'|trans|raw }}</span>
|
||||
{% endif %}
|
||||
|
||||
@ -4,6 +4,8 @@ namespace Wallabag\CoreBundle\Tools;
|
||||
|
||||
class Utils
|
||||
{
|
||||
public const DEFAULT_WORDS_PER_MINUTE = 200;
|
||||
|
||||
/**
|
||||
* Generate a token used for Feeds.
|
||||
*
|
||||
@ -28,6 +30,6 @@ class Utils
|
||||
*/
|
||||
public static function getReadingTime($text)
|
||||
{
|
||||
return floor(\count(preg_split('~([^\p{L}\p{N}\']+|(\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul}){1,2})~u', strip_tags($text))) / 200);
|
||||
return floor(\count(preg_split('~([^\p{L}\p{N}\']+|(\p{Han}|\p{Hiragana}|\p{Katakana}|\p{Hangul}){1,2})~u', strip_tags($text))) / self::DEFAULT_WORDS_PER_MINUTE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user