From 56e38dd6bd404c8c98c9dbda87769887e567048f Mon Sep 17 00:00:00 2001
From: rabuzarus <rabuzarus@t-online.de>
Date: Sun, 27 Nov 2016 20:19:43 +0100
Subject: [PATCH] move function deletenode() to the xml class

---
 include/ParseUrl.php    | 31 ++++++++++++-------------------
 include/html2bbcode.php | 40 +++++++++++++++++-----------------------
 include/xml.php         | 18 ++++++++++++++++--
 3 files changed, 45 insertions(+), 44 deletions(-)

diff --git a/include/ParseUrl.php b/include/ParseUrl.php
index 8a3392e73b..834c644757 100644
--- a/include/ParseUrl.php
+++ b/include/ParseUrl.php
@@ -12,6 +12,7 @@ use \Friendica\Core\Config;
 require_once("include/network.php");
 require_once("include/Photo.php");
 require_once("include/oembed.php");
+require_once("include/xml.php");
 
 /**
  * @brief Class with methods for extracting certain content from an url
@@ -184,17 +185,17 @@ class ParseUrl {
 		$doc = new \DOMDocument();
 		@$doc->loadHTML($body);
 
-		self::deleteNode($doc, "style");
-		self::deleteNode($doc, "script");
-		self::deleteNode($doc, "option");
-		self::deleteNode($doc, "h1");
-		self::deleteNode($doc, "h2");
-		self::deleteNode($doc, "h3");
-		self::deleteNode($doc, "h4");
-		self::deleteNode($doc, "h5");
-		self::deleteNode($doc, "h6");
-		self::deleteNode($doc, "ol");
-		self::deleteNode($doc, "ul");
+		\xml::deleteNode($doc, "style");
+		\xml::deleteNode($doc, "script");
+		\xml::deleteNode($doc, "option");
+		\xml::deleteNode($doc, "h1");
+		\xml::deleteNode($doc, "h2");
+		\xml::deleteNode($doc, "h3");
+		\xml::deleteNode($doc, "h4");
+		\xml::deleteNode($doc, "h5");
+		\xml::deleteNode($doc, "h6");
+		\xml::deleteNode($doc, "ol");
+		\xml::deleteNode($doc, "ul");
 
 		$xpath = new \DomXPath($doc);
 
@@ -440,14 +441,6 @@ class ParseUrl {
 		$tag = "#" . $tag;
 	}
 
-	private static function deleteNode(&$doc, $node) {
-		$xpath = new \DomXPath($doc);
-		$list = $xpath->query("//".$node);
-		foreach ($list as $child) {
-			$child->parentNode->removeChild($child);
-		}
-	}
-
 	private static function completeUrl($url, $scheme) {
 		$urlarr = parse_url($url);
 
diff --git a/include/html2bbcode.php b/include/html2bbcode.php
index 28e251aee4..189ba91f19 100644
--- a/include/html2bbcode.php
+++ b/include/html2bbcode.php
@@ -1,11 +1,14 @@
 <?php
-/*
-html2bbcode.php
-Converter for HTML to BBCode
-Made by: ike@piratenpartei.de
-Originally made for the syncom project: http://wiki.piratenpartei.de/Syncom
-					https://github.com/annando/Syncom
-*/
+/**
+ * @file include/html2bbcode.php
+ * @brief Converter for HTML to BBCode
+ * 
+ * Made by: ike@piratenpartei.de
+ * Originally made for the syncom project: http://wiki.piratenpartei.de/Syncom
+ * 					https://github.com/annando/Syncom
+ */
+
+require_once("include/xml.php");
 
 function node2bbcode(&$doc, $oldnode, $attributes, $startbb, $endbb)
 {
@@ -76,15 +79,6 @@ function node2bbcodesub(&$doc, $oldnode, $attributes, $startbb, $endbb)
 	return($replace);
 }
 
-if(!function_exists('deletenode')) {
-function deletenode(&$doc, $node)
-{
-	$xpath = new DomXPath($doc);
-	$list = $xpath->query("//".$node);
-	foreach ($list as $child)
-		$child->parentNode->removeChild($child);
-}}
-
 function _replace_code_cb($m){
 	return "<code>".str_replace("\n","<br>\n",$m[1]). "</code>";
 }
@@ -117,12 +111,12 @@ function html2bbcode($message)
 
 	@$doc->loadHTML($message);
 
-	deletenode($doc, 'style');
-	deletenode($doc, 'head');
-	deletenode($doc, 'title');
-	deletenode($doc, 'meta');
-	deletenode($doc, 'xml');
-	deletenode($doc, 'removeme');
+	xml::deleteNode($doc, 'style');
+	xml::deleteNode($doc, 'head');
+	xml::deleteNode($doc, 'title');
+	xml::deleteNode($doc, 'meta');
+	xml::deleteNode($doc, 'xml');
+	xml::deleteNode($doc, 'removeme');
 
 	$xpath = new DomXPath($doc);
 	$list = $xpath->query("//pre");
@@ -239,7 +233,7 @@ function html2bbcode($message)
 	node2bbcode($doc, 'iframe', array('src'=>'/(.+)/'), '[iframe]$1', '[/iframe]');
 
 	node2bbcode($doc, 'code', array(), '[code]', '[/code]');
-    node2bbcode($doc, 'key', array(), '[code]', '[/code]');
+	node2bbcode($doc, 'key', array(), '[code]', '[/code]');
 
 	$message = $doc->saveHTML();
 
diff --git a/include/xml.php b/include/xml.php
index 3bb376abaf..fd04ed1dfd 100644
--- a/include/xml.php
+++ b/include/xml.php
@@ -1,11 +1,12 @@
 <?php
+
 /**
  * @file include/xml.php
  */
 
 
 /**
- * @brief This class contain functions to work with XML data
+ * @brief This class contain methods to work with XML data
  *
  */
 class xml {
@@ -372,5 +373,18 @@ class xml {
 
 		return($xml_array);
 	}
+
+	/**
+	 * @brief Delete a node in a XML object
+	 * 
+	 * @param object $doc XML document
+	 * @param string $node Node name
+	 */
+	public static function deleteNode(&$doc, $node) {
+		$xpath = new \DomXPath($doc);
+		$list = $xpath->query("//".$node);
+		foreach ($list as $child) {
+			$child->parentNode->removeChild($child);
+		}
+	}
 }
-?>