@@ -518,7 +518,7 @@ function get_posts($posts, $page = 1, $perpage = 0)
518
518
519
519
// Get the contents and convert it to HTML
520
520
$ post ->body = MarkdownExtra::defaultTransform (remove_html_comments ($ content ));
521
-
521
+
522
522
$ post ->description = get_content_tag ("d " , $ content , get_description ($ post ->body ));
523
523
524
524
$ word_count = str_word_count (strip_tags ($ post ->body ));
@@ -592,7 +592,7 @@ function get_pages($pages, $page = 1, $perpage = 0)
592
592
593
593
// Get the contents and convert it to HTML
594
594
$ post ->body = MarkdownExtra::defaultTransform (remove_html_comments ($ content ));
595
-
595
+
596
596
$ post ->description = get_content_tag ("d " , $ content , get_description ($ post ->body ));
597
597
598
598
$ word_count = str_word_count (strip_tags ($ post ->body ));
@@ -672,13 +672,12 @@ function get_subpages($sub_pages, $page = 1, $perpage = 0)
672
672
673
673
// Get the contents and convert it to HTML
674
674
$ post ->body = MarkdownExtra::defaultTransform (remove_html_comments ($ content ));
675
-
675
+
676
676
$ post ->description = get_content_tag ("d " , $ content , get_description ($ post ->body ));
677
677
678
678
$ word_count = str_word_count (strip_tags ($ post ->body ));
679
679
$ post ->readTime = ceil ($ word_count / 200 );
680
680
681
-
682
681
$ toc = explode ('<!--toc--> ' , $ post ->body );
683
682
if (isset ($ toc ['1 ' ])) {
684
683
$ post ->body = insert_toc ('subpage- ' . $ post ->slug , $ toc ['0 ' ], $ toc ['1 ' ]);
@@ -960,9 +959,9 @@ function read_category_info($category)
960
959
961
960
// Get the contents and convert it to HTML
962
961
$ desc ->body = MarkdownExtra::defaultTransform (remove_html_comments ($ content ));
963
-
962
+
964
963
$ desc ->description = get_content_tag ("d " , $ content , get_description ($ desc ->body ));
965
-
964
+
966
965
$ toc = explode ('<!--toc--> ' , $ desc ->body );
967
966
if (isset ($ toc ['1 ' ])) {
968
967
$ desc ->body = insert_toc ('taxonomy- ' . $ desc ->slug , $ toc ['0 ' ], $ toc ['1 ' ]);
@@ -1192,18 +1191,17 @@ function get_author($name)
1192
1191
1193
1192
// Get the contents and convert it to HTML
1194
1193
$ author ->about = MarkdownExtra::defaultTransform (remove_html_comments ($ content ));
1195
-
1194
+
1196
1195
$ author ->description = strip_tags ($ author ->about );
1197
-
1196
+
1198
1197
$ toc = explode ('<!--toc--> ' , $ author ->about );
1199
1198
if (isset ($ toc ['1 ' ])) {
1200
1199
$ author ->about = insert_toc ('profile- ' . $ author ->slug , $ toc ['0 ' ], $ toc ['1 ' ]);
1201
1200
}
1202
-
1201
+
1203
1202
$ author ->body = $ author ->about ;
1204
-
1205
1203
$ author ->title = $ author ->name ;
1206
-
1204
+
1207
1205
$ tmp [] = $ author ;
1208
1206
}
1209
1207
}
@@ -2212,15 +2210,21 @@ function get_teaser($string, $url = null, $char = null)
2212
2210
return $ string ;
2213
2211
}
2214
2212
} 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
+ }
2217
2221
}
2218
2222
}
2219
2223
2220
2224
// Shorten the string
2221
2225
function shorten ($ string = null , $ char = null )
2222
2226
{
2223
- if (empty ($ char ) || empty ( $ string )) {
2227
+ if (empty ($ string )) {
2224
2228
return ;
2225
2229
}
2226
2230
@@ -2230,16 +2234,18 @@ function shorten($string = null, $char = null)
2230
2234
$ tags_to_remove = array ('script ' , 'style ' );
2231
2235
foreach ($ tags_to_remove as $ tag ){
2232
2236
$ element = $ dom ->getElementsByTagName ($ tag );
2233
- foreach ($ element as $ item ){
2237
+ foreach ($ element as $ item ){
2234
2238
$ item ->parentNode ->removeChild ($ item );
2235
2239
}
2236
2240
}
2237
2241
$ string = preg_replace ('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i ' , '' , mb_convert_encoding ($ dom ->saveHTML ($ dom ->documentElement ), 'UTF-8 ' ));
2238
2242
$ string = preg_replace ('/\s\s+/ ' , ' ' , strip_tags ($ string ));
2239
2243
$ 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
+ }
2243
2249
}
2244
2250
return $ string ;
2245
2251
@@ -2510,7 +2516,7 @@ function analytics()
2510
2516
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
2511
2517
ga('create', ' {$ analytics }', 'auto');
2512
2518
ga('send', 'pageview');
2513
- </script>
2519
+ </script>
2514
2520
EOF ;
2515
2521
$ gtagScript = <<<EOF
2516
2522
<!-- Global site tag (gtag.js) - Google Analytics -->
0 commit comments