aboutsummaryrefslogtreecommitdiffstats
path: root/include/oembed.php
diff options
context:
space:
mode:
authorFabio Comuni <fabrix.xm@gmail.com>2011-02-16 09:22:32 +0100
committerFabio Comuni <fabrix.xm@gmail.com>2011-02-16 09:22:32 +0100
commitc8116932c286f04bbaf121f75053dfde0fb7d571 (patch)
treec8a50d9b39beeae4efb8368cfb240423af9f7904 /include/oembed.php
parentc5f5102396cee8ec691fd22d486070ec3d5f243d (diff)
downloadvolse-hubzilla-c8116932c286f04bbaf121f75053dfde0fb7d571.tar.gz
volse-hubzilla-c8116932c286f04bbaf121f75053dfde0fb7d571.tar.bz2
volse-hubzilla-c8116932c286f04bbaf121f75053dfde0fb7d571.zip
Fix #8 \"recycle symbol getting mangled from status.net retweets\"
Diffstat (limited to 'include/oembed.php')
-rw-r--r--include/oembed.php39
1 files changed, 24 insertions, 15 deletions
diff --git a/include/oembed.php b/include/oembed.php
index 4d6b0af16..4d2b7185e 100644
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -79,22 +79,31 @@ function oe_get_inner_html( $node ) {
* and replace it with [embed]url[/embed]
*/
function oembed_html2bbcode($text) {
- // If it doesn't parse at all, just return the text.
- $dom = @DOMDocument::loadHTML($text);
- if(! $dom)
+ // start parser only if 'oembed' is in text
+ if (strpos($text, "oembed")){
+
+ // convert non ascii chars to html entities
+ $html_text = mb_convert_encoding($text, 'HTML-ENTITIES', mb_detect_encoding($text));
+
+ // If it doesn't parse at all, just return the text.
+ $dom = @DOMDocument::loadHTML($html_text);
+ if(! $dom)
+ return $text;
+ $xpath = new DOMXPath($dom);
+ $attr = "oembed";
+
+ $xattr = oe_build_xpath("class","oembed");
+ $entries = $xpath->query("//span[$xattr]");
+
+ $xattr = oe_build_xpath("rel","oembed");
+ foreach($entries as $e) {
+ $href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue;
+ if(!is_null($href)) $e->parentNode->replaceChild(new DOMText("[embed]".$href."[embed]"), $e);
+ }
+ return oe_get_inner_html( $dom->getElementsByTagName("body")->item(0) );
+ } else {
return $text;
- $xpath = new DOMXPath($dom);
- $attr = "oembed";
-
- $xattr = oe_build_xpath("class","oembed");
- $entries = $xpath->query("//span[$xattr]");
-
- $xattr = oe_build_xpath("rel","oembed");
- foreach($entries as $e) {
- $href = $xpath->evaluate("a[$xattr]/@href", $e)->item(0)->nodeValue;
- if(!is_null($href)) $e->parentNode->replaceChild(new DOMText("[embed]".$href."[embed]"), $e);
- }
- return oe_get_inner_html( $dom->getElementsByTagName("body")->item(0) );
+ }
}
?> \ No newline at end of file