From e931413d2d66140162d018947c453c7478834c49 Mon Sep 17 00:00:00 2001 From: danpros Date: Sun, 18 Apr 2021 11:07:44 +0700 Subject: [PATCH] Add read time --- system/includes/functions.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/system/includes/functions.php b/system/includes/functions.php index a719b2e..1f75e9b 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -375,6 +375,9 @@ function get_posts($posts, $page = 1, $perpage = 0) } $post->description = get_content_tag("d", $content, get_description($post->body)); + + $word_count = str_word_count(strip_tags($post->body)); + $post->readTime = ceil($word_count / 200); $tmp[] = $post; } @@ -856,6 +859,9 @@ function get_static_post($static) } $post->description = get_content_tag("d", $content, get_description($post->body)); + + $word_count = str_word_count(strip_tags($post->body)); + $post->readTime = ceil($word_count / 200); $tmp[] = $post; } @@ -900,6 +906,9 @@ function get_static_sub_post($static, $sub_static) $post->views = get_views($post->file); $post->description = get_content_tag("d", $content, get_description($post->body)); + + $word_count = str_word_count(strip_tags($post->body)); + $post->readTime = ceil($word_count / 200); $tmp[] = $post; } @@ -1521,7 +1530,9 @@ function has_prev($prev) 'video' => $prev->video, 'audio' => $prev->audio, 'quote' => $prev->quote, - 'link' => $prev->link + 'link' => $prev->link, + 'categoryUrl' => $prev->categoryUrl, + 'readTime' => $prev->readTime ); } } @@ -1549,7 +1560,9 @@ function has_next($next) 'video' => $next->video, 'audio' => $next->audio, 'quote' => $next->quote, - 'link' => $next->link + 'link' => $next->link, + 'categoryUrl' => $next->categoryUrl, + 'readTime' => $next->readTime ); } }