// HELPER FUNCTIONS
///////////////////////////////
+// Adapted from WordPress\r
+// http://core.trac.wordpress.org/browser/tags/3.5.1/wp-includes/formatting.php#L2173\r
+function get_excerpt($text, $num_words=55, $more=null) {\r
+ if (null === $more) $more = '…';\r
+ $text = strip_tags($text);\r
+ //TODO: Check if word count is based on single characters (East Asian characters)\r
+ /*\r
+ if (1==2) {\r
+ $text = trim(preg_replace("/[\n\r\t ]+/", ' ', $text), ' ');\r
+ preg_match_all('/./u', $text, $words_array);\r
+ $words_array = array_slice($words_array[0], 0, $num_words + 1);\r
+ $sep = '';\r
+ } else {\r
+ $words_array = preg_split("/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY);\r
+ $sep = ' ';\r
+ }\r
+ */\r
+ $words_array = preg_split("/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY);\r
+ $sep = ' ';\r
+ if (count($words_array) > $num_words) {\r
+ array_pop($words_array);\r
+ $text = implode($sep, $words_array);\r
+ $text = $text.$more;\r
+ } else {\r
+ $text = implode($sep, $words_array);\r
+ }\r
+ // trim whitespace at beginning or end of string\r
+ // See: http://stackoverflow.com/questions/4166896/trim-unicode-whitespace-in-php-5-2\r
+ $text = preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $text);\r
+ return $text;\r
+}\r
+\r
function url_allowed($url) {
global $options;
if (!empty($options->allowed_urls)) {
if (strtolower($encoding) != 'utf-8') {
debug('Converting to UTF-8');
$html = SimplePie_Misc::change_encoding($html, $encoding, 'utf-8');
- /*
- if (function_exists('iconv')) {
- // iconv appears to handle certain character encodings better than mb_convert_encoding
- $html = iconv($encoding, 'utf-8', $html);
- } else {
- $html = mb_convert_encoding($html, 'utf-8', $encoding);
- }
- */
}
}
}
}
function makeAbsoluteAttr($base, $e, $attr) {
if ($e->hasAttribute($attr)) {
- // Trim leading and trailing white space. I don't really like this but
+ // Trim leading and trailing white space. I don't really like this but
// unfortunately it does appear on some sites. e.g. <img src=" /path/to/image.jpg" />
$url = trim(str_replace('%20', ' ', $e->getAttribute($attr)));
$url = str_replace(' ', '%20', $url);
flush();
}
}
+
+function get_base_url($dom) {\r
+ $xpath = new DOMXPath($dom);\r
+ $base_url = @$xpath->evaluate('string(//head/base/@href)', $dom);\r
+ if ($base_url !== '') {\r
+ return $base_url;\r
+ } else {\r
+ return false;\r
+ }\r
+}