aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/functions.php17
-rw-r--r--core/include/page/main.php2
-rw-r--r--core/include/post/main.php2
-rw-r--r--core/include/user/main.php2
-rw-r--r--template/standard/html/feed/item_page.php2
-rw-r--r--template/standard/html/feed/item_post.php2
6 files changed, 19 insertions, 8 deletions
diff --git a/core/functions.php b/core/functions.php
index 471c14f..c6bdb1e 100644
--- a/core/functions.php
+++ b/core/functions.php
@@ -272,10 +272,10 @@ function removeDoubleLineBreaks($string): string {
}
#===============================================================================
-# Remove line breaks and tabs from a string
+# Remove all multiple whitespace characters
#===============================================================================
-function removeLineBreaksAndTabs($string, $replace = ''): string {
- return str_replace(["\r\n", "\r", "\n", "\t"], $replace, $string);
+function removeWhitespace($string): string {
+ return preg_replace('/\s+/S', ' ', trim($string));
}
#===============================================================================
@@ -309,6 +309,17 @@ function excerpt($string, $length = 500, $replace = ' […]') {
}
#===============================================================================
+# Return content for meta description
+#===============================================================================
+function description($string, $length = 200, $replace = ' […]') {
+ $string = removeHTML($string);
+ $string = removeWhitespace($string);
+ $string = cut($string, $length, $replace);
+
+ return $string;
+}
+
+#===============================================================================
# Generate a valid slug URL part from a string
#===============================================================================
function makeSlugURL($string) {
diff --git a/core/include/page/main.php b/core/include/page/main.php
index 925d5d9..bf3e03e 100644
--- a/core/include/page/main.php
+++ b/core/include/page/main.php
@@ -47,7 +47,7 @@ try {
$MainTemplate->set('HTML', $PageTemplate);
$MainTemplate->set('HEAD', [
'NAME' => $page_data['ATTR']['NAME'],
- 'DESC' => cut(removeLineBreaksAndTabs(removeHTML($page_data['BODY']['HTML']), ' '), Application::get('PAGE.DESCRIPTION_SIZE')),
+ 'DESC' => description($page_data['BODY']['HTML'], Application::get('PAGE.DESCRIPTION_SIZE')),
'PERM' => $page_data['URL'],
'OG_IMAGES' => $page_data['FILE']['LIST']
]);
diff --git a/core/include/post/main.php b/core/include/post/main.php
index 46937f3..dc3cbdc 100644
--- a/core/include/post/main.php
+++ b/core/include/post/main.php
@@ -47,7 +47,7 @@ try {
$MainTemplate->set('HTML', $PostTemplate);
$MainTemplate->set('HEAD', [
'NAME' => $post_data['ATTR']['NAME'],
- 'DESC' => cut(removeLineBreaksAndTabs(removeHTML($post_data['BODY']['HTML']), ' '), Application::get('POST.DESCRIPTION_SIZE')),
+ 'DESC' => description($post_data['BODY']['HTML'], Application::get('POST.DESCRIPTION_SIZE')),
'PERM' => $post_data['URL'],
'OG_IMAGES' => $post_data['FILE']['LIST']
]);
diff --git a/core/include/user/main.php b/core/include/user/main.php
index 7944f1f..79e0ea9 100644
--- a/core/include/user/main.php
+++ b/core/include/user/main.php
@@ -62,7 +62,7 @@ try {
$MainTemplate->set('HTML', $UserTemplate);
$MainTemplate->set('HEAD', [
'NAME' => $user_data['ATTR']['FULLNAME'],
- 'DESC' => cut(removeLineBreaksAndTabs(removeHTML($user_data['BODY']['HTML']), ' '), Application::get('USER.DESCRIPTION_SIZE')),
+ 'DESC' => description($user_data['BODY']['HTML'], Application::get('USER.DESCRIPTION_SIZE')),
'PERM' => $User->getURL(),
'OG_IMAGES' => $User->getFiles()
]);
diff --git a/template/standard/html/feed/item_page.php b/template/standard/html/feed/item_page.php
index 9defc25..ac3d197 100644
--- a/template/standard/html/feed/item_page.php
+++ b/template/standard/html/feed/item_page.php
@@ -13,7 +13,7 @@
<guid isPermaLink="false"><?=$PAGE['GUID']?></guid>
<pubDate><?=parseDatetime($PAGE['ATTR']['TIME_INSERT'], '[RFC2822]')?></pubDate>
<dc:creator><?=escapeHTML($USER['ATTR']['FULLNAME'])?></dc:creator>
- <description><?=escapeHTML(cut(removeLineBreaksAndTabs(removeHTML($PAGE['BODY']['HTML'])), 400))?></description>
+ <description><?=description($PAGE['BODY']['HTML'], 400)?></description>
<content:encoded>
<![CDATA[
<?=$PAGE['BODY']['HTML']?>
diff --git a/template/standard/html/feed/item_post.php b/template/standard/html/feed/item_post.php
index f004316..fe59060 100644
--- a/template/standard/html/feed/item_post.php
+++ b/template/standard/html/feed/item_post.php
@@ -13,7 +13,7 @@
<guid isPermaLink="false"><?=$POST['GUID']?></guid>
<pubDate><?=parseDatetime($POST['ATTR']['TIME_INSERT'], '[RFC2822]')?></pubDate>
<dc:creator><?=escapeHTML($USER['ATTR']['FULLNAME'])?></dc:creator>
- <description><?=escapeHTML(cut(removeLineBreaksAndTabs(removeHTML($POST['BODY']['HTML'])), 400))?></description>
+ <description><?=description($POST['BODY']['HTML'], 400)?></description>
<content:encoded>
<![CDATA[
<?=$POST['BODY']['HTML']?>