From 7e2a08c7bce16ff7b36ede087cd13809262f2d61 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 1 Jan 2018 17:43:03 -0500 Subject: [PATCH] Review changes - Add file comment in Content\OEmbed - Add self where relevant - Remove useless spaces from the XPath expression --- src/Content/OEmbed.php | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index db2c130eaf..020d3b9b76 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -1,9 +1,7 @@ */ class OEmbed { public static function replaceCallback($matches) { $embedurl = $matches[1]; - $j = OEmbed::fetchURL($embedurl); - $s = OEmbed::formatObject($j); + $j = self::fetchURL($embedurl); + $s = self::formatObject($j); return $s; } @@ -157,7 +160,7 @@ class OEmbed public static function formatObject($j) { $embedurl = $j->embedurl; - $jhtml = OEmbed::iframe($j->embedurl, (isset($j->width) ? $j->width : null), (isset($j->height) ? $j->height : null)); + $jhtml = self::iframe($j->embedurl, (isset($j->width) ? $j->width : null), (isset($j->height) ? $j->height : null)); $ret = ""; switch ($j->type) { case "video": @@ -268,7 +271,7 @@ class OEmbed } $xpath = new DOMXPath($dom); - $xattr = OEmbed::buildXPath("class", "oembed"); + $xattr = self::buildXPath("class", "oembed"); $entries = $xpath->query("//span[$xattr]"); $xattr = "@rel='oembed'"; //oe_build_xpath("rel","oembed"); @@ -278,7 +281,7 @@ class OEmbed $e->parentNode->replaceChild(new DOMText("[embed]" . $href . "[/embed]"), $e); } } - return OEmbed::getInnerHTML($dom->getElementsByTagName("body")->item(0)); + return self::getInnerHTML($dom->getElementsByTagName("body")->item(0)); } else { return $text; } @@ -329,7 +332,7 @@ class OEmbed private static function buildXPath($attr, $value) { // https://www.westhoffswelt.de/blog/2009/6/9/select-html-elements-with-more-than-one-css-class-using-xpath - return "contains( normalize-space( @$attr ), ' $value ' ) or substring( normalize-space( @$attr ), 1, string-length( '$value' ) + 1 ) = '$value ' or substring( normalize-space( @$attr ), string-length( @$attr ) - string-length( '$value' ) ) = ' $value' or @$attr = '$value'"; + return "contains(normalize-space(@$attr), ' $value ') or substring(normalize-space(@$attr), 1, string-length('$value') + 1) = '$value ' or substring(normalize-space(@$attr), string-length(@$attr) - string-length('$value')) = ' $value' or @$attr = '$value'"; } /** -- 2.39.5