Skip to content

Commit 95f7afe

Browse files
committedMar 2, 2024
Teaser break handling. See danpros#693
1 parent 3125dc0 commit 95f7afe

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed
 

‎system/includes/functions.php

+25-19
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ function get_posts($posts, $page = 1, $perpage = 0)
518518

519519
// Get the contents and convert it to HTML
520520
$post->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
521-
521+
522522
$post->description = get_content_tag("d", $content, get_description($post->body));
523523

524524
$word_count = str_word_count(strip_tags($post->body));
@@ -592,7 +592,7 @@ function get_pages($pages, $page = 1, $perpage = 0)
592592

593593
// Get the contents and convert it to HTML
594594
$post->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
595-
595+
596596
$post->description = get_content_tag("d", $content, get_description($post->body));
597597

598598
$word_count = str_word_count(strip_tags($post->body));
@@ -672,13 +672,12 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0)
672672

673673
// Get the contents and convert it to HTML
674674
$post->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
675-
675+
676676
$post->description = get_content_tag("d", $content, get_description($post->body));
677677

678678
$word_count = str_word_count(strip_tags($post->body));
679679
$post->readTime = ceil($word_count / 200);
680680

681-
682681
$toc = explode('<!--toc-->', $post->body);
683682
if (isset($toc['1'])) {
684683
$post->body = insert_toc('subpage-' . $post->slug, $toc['0'], $toc['1']);
@@ -960,9 +959,9 @@ function read_category_info($category)
960959

961960
// Get the contents and convert it to HTML
962961
$desc->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
963-
962+
964963
$desc->description = get_content_tag("d", $content, get_description($desc->body));
965-
964+
966965
$toc = explode('<!--toc-->', $desc->body);
967966
if (isset($toc['1'])) {
968967
$desc->body = insert_toc('taxonomy-' . $desc->slug, $toc['0'], $toc['1']);
@@ -1192,18 +1191,17 @@ function get_author($name)
11921191

11931192
// Get the contents and convert it to HTML
11941193
$author->about = MarkdownExtra::defaultTransform(remove_html_comments($content));
1195-
1194+
11961195
$author->description = strip_tags($author->about);
1197-
1196+
11981197
$toc = explode('<!--toc-->', $author->about);
11991198
if (isset($toc['1'])) {
12001199
$author->about = insert_toc('profile-' . $author->slug, $toc['0'], $toc['1']);
12011200
}
1202-
1201+
12031202
$author->body = $author->about;
1204-
12051203
$author->title = $author->name;
1206-
1204+
12071205
$tmp[] = $author;
12081206
}
12091207
}
@@ -2212,15 +2210,21 @@ function get_teaser($string, $url = null, $char = null)
22122210
return $string;
22132211
}
22142212
} else {
2215-
$string = shorten($string, $char);
2216-
return $string;
2213+
$readMore = explode('<!--more-->', $string);
2214+
if (isset($readMore['1'])) {
2215+
$string = shorten($readMore[0]);
2216+
return $string;
2217+
} else {
2218+
$string = shorten($string, $char);
2219+
return $string;
2220+
}
22172221
}
22182222
}
22192223

22202224
// Shorten the string
22212225
function shorten($string = null, $char = null)
22222226
{
2223-
if(empty($char) || empty($string)) {
2227+
if(empty($string)) {
22242228
return;
22252229
}
22262230

@@ -2230,16 +2234,18 @@ function shorten($string = null, $char = null)
22302234
$tags_to_remove = array('script', 'style');
22312235
foreach($tags_to_remove as $tag){
22322236
$element = $dom->getElementsByTagName($tag);
2233-
foreach($element as $item){
2237+
foreach($element as $item){
22342238
$item->parentNode->removeChild($item);
22352239
}
22362240
}
22372241
$string = preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', mb_convert_encoding($dom->saveHTML($dom->documentElement), 'UTF-8'));
22382242
$string = preg_replace('/\s\s+/', ' ', strip_tags($string));
22392243
$string = ltrim(rtrim($string));
2240-
if (strlen($string) > $char) {
2241-
$string = substr($string, 0, $char);
2242-
$string = substr($string, 0, strrpos($string, ' '));
2244+
if (!empty($char)) {
2245+
if (strlen($string) > $char) {
2246+
$string = substr($string, 0, $char);
2247+
$string = substr($string, 0, strrpos($string, ' '));
2248+
}
22432249
}
22442250
return $string;
22452251

@@ -2510,7 +2516,7 @@ function analytics()
25102516
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
25112517
ga('create', '{$analytics}', 'auto');
25122518
ga('send', 'pageview');
2513-
</script>
2519+
</script>
25142520
EOF;
25152521
$gtagScript = <<<EOF
25162522
<!-- Global site tag (gtag.js) - Google Analytics -->

0 commit comments

Comments
 (0)
Please sign in to comment.