summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/wordpress-mobile-pack/inc/class-wmp-formatter.php')
-rwxr-xr-xplugins/wordpress-mobile-pack/inc/class-wmp-formatter.php22
1 files changed, 19 insertions, 3 deletions
diff --git a/plugins/wordpress-mobile-pack/inc/class-wmp-formatter.php b/plugins/wordpress-mobile-pack/inc/class-wmp-formatter.php
index b1d12aa5..c611befd 100755
--- a/plugins/wordpress-mobile-pack/inc/class-wmp-formatter.php
+++ b/plugins/wordpress-mobile-pack/inc/class-wmp-formatter.php
@@ -36,7 +36,7 @@ if ( ! class_exists( 'WMobilePack_Formatter' ) ) {
$config->set('URI.AllowedSchemes', array('http' => true, 'https' => true, 'mailto' => true, 'news' => true, 'tel' => true, 'callto' => true, 'skype' => true, 'sms' => true, 'whatsapp' => true));
$config->set('HTML.SafeIframe', 1);
- $config->set('URI.SafeIframeRegexp', "%^(https?:)?(http?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player.vimeo.com|www\.dailymotion.com|w.soundcloud.com|fast.wistia.net|fast.wistia.com|wi.st|flickrit.com|www.spreaker.com|spreaker.com|instagram.com|www.instagram.com|embed.spotify.com|play.spotify.com|spotify.com)%");
+ $config->set('URI.SafeIframeRegexp', "%^(https?:)?(http?:)?//(www\.youtube(?:-nocookie)?\.com/embed/|player.vimeo.com|www\.dailymotion.com|w.soundcloud.com|fast.wistia.net|fast.wistia.com|wi.st|flickrit.com|www.spreaker.com|spreaker.com|instagram.com|www.instagram.com|embed.spotify.com|play.spotify.com|spotify.com|player.youku.com|youku.com)%");
// extend purifier
$Html5Purifier = new WMPHtmlPurifier();
@@ -91,6 +91,7 @@ if ( ! class_exists( 'WMobilePack_Formatter' ) ) {
if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
return $text;
}
+
// splits all html-tags to scanable lines
preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER);
$total_length = strlen($ending);
@@ -98,18 +99,24 @@ if ( ! class_exists( 'WMobilePack_Formatter' ) ) {
$truncate = '';
foreach ($lines as $line_matchings) {
+
// if there is any html-tag in this line, handle it and add it (uncounted) to the output
if (!empty($line_matchings[1])) {
+
// if it's an "empty element" with or without xhtml-conform closing slash
if (preg_match('/^<(\s*.+?\/\s*|\s*(img|br|input|hr|area|base|basefont|col|frame|isindex|link|meta|param)(\s.+?)?)>$/is', $line_matchings[1])) {
+
// do nothing
// if tag is a closing tag
+
} else if (preg_match('/^<\s*\/([^\s]+?)\s*>$/s', $line_matchings[1], $tag_matchings)) {
+
// delete tag from $open_tags list
$pos = array_search($tag_matchings[1], $open_tags);
if ($pos !== false) {
unset($open_tags[$pos]);
}
+
// if tag is an opening tag
} else if (preg_match('/^<\s*([^\s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) {
// add tag to the beginning of $open_tags list
@@ -118,12 +125,16 @@ if ( ! class_exists( 'WMobilePack_Formatter' ) ) {
// add html-tag to $truncate'd text
$truncate .= $line_matchings[1];
}
+
// calculate the length of the plain text part of the line; handle entities as one character
$content_length = strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', ' ', $line_matchings[2]));
+
if ($total_length + $content_length > $length) {
+
// the number of characters which are left
$left = $length - $total_length;
$entities_length = 0;
+
// search for html entities
if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) {
// calculate the real length of all entities in the legal range
@@ -137,6 +148,7 @@ if ( ! class_exists( 'WMobilePack_Formatter' ) ) {
}
}
}
+
$truncate .= substr($line_matchings[2], 0, $left + $entities_length);
// maximum length is reached, so get off the loop
break;
@@ -156,15 +168,19 @@ if ( ! class_exists( 'WMobilePack_Formatter' ) ) {
$truncate = substr($text, 0, $length - strlen($ending));
}
}
+
// if the words shouldn't be cut in the middle...
if (!$exact) {
- // ...search the last occurance of a space...
+
+ // ...search the last occurrence of a space...
$spacepos = strrpos($truncate, ' ');
- if (isset($spacepos)) {
+
+ if ($spacepos !== false) {
// ...and cut the text in this position
$truncate = substr($truncate, 0, $spacepos);
}
}
+
// add the defined ending to the text
$truncate .= $ending;
if ($considerHtml) {