Skip to content

Commit d92f59a

Browse files
authored
Merge pull request #657 from ivanhrytsaim/12976-Blog-meta-description-fix
12976-Blog-meta-description-fix
2 parents ca7051e + 6f4dd83 commit d92f59a

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

Model/Author.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,17 @@ public function getMetaDescription()
114114
$desc = $this->getShortContentExtractor()->execute($this->getData('content'), 500);
115115
}
116116

117-
$stylePattern = "~\<style(.*)\>(.*)\<\/style\>~";
117+
$stylePattern = "~<style\b[^>]*>.*?</style>~is";
118118
$desc = preg_replace($stylePattern, '', $desc);
119119
$desc = trim(strip_tags((string)$desc));
120120
$desc = str_replace(["\r\n", "\n\r", "\r", "\n"], ' ', $desc);
121121

122-
if (mb_strlen($desc) > 200) {
123-
$desc = mb_substr($desc, 0, 200);
122+
if (mb_strlen($desc) > 160) {
123+
$desc = mb_substr($desc, 0, 160);
124+
$lastSpace = mb_strrpos($desc, ' ');
125+
if ($lastSpace !== false) {
126+
$desc = mb_substr($desc, 0, $lastSpace) . '...';
127+
}
124128
}
125129

126130
return trim($desc);

Model/Category.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,17 @@ public function getMetaDescription()
398398
$desc = $this->getShortContentExtractor()->execute($this->getData('content'), 500);
399399
}
400400

401-
$stylePattern = "~\<style(.*)\>(.*)\<\/style\>~";
401+
$stylePattern = "~<style\b[^>]*>.*?</style>~is";
402402
$desc = preg_replace($stylePattern, '', $desc);
403403
$desc = trim(strip_tags((string)$desc));
404404
$desc = str_replace(["\r\n", "\n\r", "\r", "\n"], ' ', $desc);
405405

406-
if (mb_strlen($desc) > 200) {
407-
$desc = mb_substr($desc, 0, 200);
406+
if (mb_strlen($desc) > 160) {
407+
$desc = mb_substr($desc, 0, 160);
408+
$lastSpace = mb_strrpos($desc, ' ');
409+
if ($lastSpace !== false) {
410+
$desc = mb_substr($desc, 0, $lastSpace);
411+
}
408412
}
409413

410414
return trim($desc);

Model/Post.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -584,13 +584,17 @@ public function getMetaDescription()
584584
$desc = $this->getShortFilteredContent(500);
585585
}
586586

587-
$stylePattern = "~\<style(.*)\>(.*)\<\/style\>~";
587+
$stylePattern = "~<style\b[^>]*>.*?</style>~is";
588588
$desc = preg_replace($stylePattern, '', $desc);
589589
$desc = trim(strip_tags((string)$desc));
590590
$desc = str_replace(["\r\n", "\n\r", "\r", "\n"], ' ', $desc);
591591

592-
if (mb_strlen($desc) > 200) {
593-
$desc = mb_substr($desc, 0, 200);
592+
if (mb_strlen($desc) > 160) {
593+
$desc = mb_substr($desc, 0, 160);
594+
$lastSpace = mb_strrpos($desc, ' ');
595+
if ($lastSpace !== false) {
596+
$desc = mb_substr($desc, 0, $lastSpace) . '...';
597+
}
594598
}
595599

596600
$desc = trim($desc);

Model/Tag.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,17 @@ public function getMetaDescription()
187187
$desc = $this->getShortContentExtractor()->execute($this->getData('content'), 500);
188188
}
189189

190-
$stylePattern = "~\<style(.*)\>(.*)\<\/style\>~";
190+
$stylePattern = "~<style\b[^>]*>.*?</style>~is";
191191
$desc = preg_replace($stylePattern, '', $desc);
192192
$desc = trim(strip_tags((string)$desc));
193193
$desc = str_replace(["\r\n", "\n\r", "\r", "\n"], ' ', $desc);
194194

195-
if (mb_strlen($desc) > 200) {
196-
$desc = mb_substr($desc, 0, 200);
195+
if (mb_strlen($desc) > 160) {
196+
$desc = mb_substr($desc, 0, 160);
197+
$lastSpace = mb_strrpos($desc, ' ');
198+
if ($lastSpace !== false) {
199+
$desc = mb_substr($desc, 0, $lastSpace) . '...';
200+
}
197201
}
198202

199203
return trim($desc);

0 commit comments

Comments
 (0)