public function test_convertRelToAbs() { $GLOBALS["location"] = "http://www.someweb.com"; $test_url = "/something/image.jpg"; $correct_result = "http://www.someweb.com/something/image.jpg"; $result = convertRelToAbs($test_url); echo "Final url was: " . $result . "\n"; echo "Expected url was: " . $correct_result . "\n"; $this->assertEquals($correct_result, $result); }
function getParagraphs($DOMNode) { $currentTag = $DOMNode->tagName; $content = ""; //whitelist if ($currentTag == "p") { $content = "<p>"; // this loop here check for any other inline formating within the paragraph foreach ($DOMNode->childNodes as $node) { if (isset($node->tagName) && $node->tagName == "a") { $content .= "<a href='" . convertRelToAbs($node->attributes->getNamedItem("href")->nodeValue) . "'>" . $node->nodeValue . "</a>"; } else { $content .= $node->nodeValue; } } $content .= "</p>"; } if ($currentTag == "img") { $content = "<div class='img_container'><img src='" . convertRelToAbs($DOMNode->attributes->getNamedItem("src")->nodeValue) . "' style='vertical-align:middle'></img></div>"; } //blacklist, if one of these elements are found, stop here as any further processing is a waste of time if ($currentTag == "aside") { //echo "<p>Aside Detected and removed</p>"; return ""; } if ($currentTag == "noscript") { // should remove many kinds of browser plugin warnings return ""; } if ($DOMNode->hasChildNodes()) { if ($currentTag == "blockquote") { $content .= "<blockquote>"; } $childNodes = $DOMNode->childNodes; for ($i = 0; $i < $childNodes->length; $i++) { $childNode = $childNodes->item($i); if (isset($childNode->tagName)) { $content = $content . getParagraphs($childNode); } } if ($currentTag == "blockquote") { $content .= "</blockquote>"; } } else { // if there is a blockquote but it does not contain any further nodes, then do this simply if ($currentTag == "blockquote") { $content .= "<blockquote>"; $content .= $DOMNode->nodeValue; $content .= "</blockquote>"; } } return $content; }