HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/PvdBoogaard/indoorski.nl/backup/oude-site/cms/lib/simplexml/simplexml.php
<?php


class SimpleXML extends SimpleXMLElement {
/**
	 * Outputs this element as pretty XML to increase readability.
	 *
	 * @param   int     $level      (optional) The number of spaces to use for
	 *                              indentation, defaults to 4
	 * @return  string              The XML output
	 * @access  public
	 */
	public function asFormattedXML($level = 4)
	{
		// get an array containing each XML element
		$xml = explode("\n", preg_replace('/>\s*</', ">\n<", $this->asXML()));

		// hold current indentation level
		$indent = 0;

		// hold the XML segments
		$pretty = array();

		// shift off opening XML tag if present
		if (count($xml) && preg_match('/^<\?\s*xml/', $xml[0])) {
			$pretty[] = array_shift($xml);
		}

		foreach ($xml as $el) {
			if (preg_match('/^<([\w])+[^>\/]*>$/U', $el)) {
				// opening tag, increase indent
				$pretty[] = str_repeat(' ', $indent) . $el;
				$indent += $level;
			} else {
				if (preg_match('/^<\/.+>$/', $el)) {
					// closing tag, decrease indent
					$indent -= $level;
				}
				$pretty[] = str_repeat(' ', $indent) . $el;
			}
		}
		return implode("\n", $pretty);
	}

	public function outputXML($formatted=false){
		header('Content-Type: text/xml; charset=utf-8');
		if($formatted === true){
			echo $this->asFormattedXML();
		}else{
			echo $this->asXML();
		}
	}
	
	public function asFullXml(){
		return parent::asXML();
	}

	public function asXML(){
		$return = parent::asXML();
		$return = str_replace('<?xml version="1.0"?>'."\n", '', $return);
		return $return;
	}

	public function cData($str){
		return "<![CDATA[".$str."]]>";
	}

	function hasChild($MenuItem) {
		var_dump($MenuItem);
		var_dump((array)$MenuItem->children());
			echo "\n\n\n<hr>\n\n\n";
		/*if ( count($MenuItem->children()) >0 ) {
			return true;
		}*/
		return false;
	}

/*
	public function ReplaceContentByClass($class, $changeTo){
		//$result = $this->xpath('//*[child::*[contains(@class,"'.$class.' ") or contains(@class," '.$class.'") or @class="'.$class.'"]]');
		$result = $this->xpath('//*[child::*[contains(@class,"^'.$class.' ") or contains(@class," '.$class.'$") or contains(@class," '.$class.' ") or @class="'.$class.'"]]');
		var_dump(	$this );
		foreach($result as $k=>$element){

			/*while($this->hasChild($element)) {
				$t = $element->children();
				$element = $t[0];
			}* /
			$name = $element->children()->children()->getName();
			$element->$name = $changeTo;
			echo  $class . " - ".$name."\n";
		}
	}
	*/
	
	public function ReplaceContentByClass($class, $changeTo, $obj=null){
		if($obj === null){
			$obj = &$this;
		}
		foreach($obj as $key=>$val){
			$attr = $val->attributes();
			if($this->hasClass($class, $attr)){
				$obj->{$key} = $changeTo;
			}
			if(is_object($val)){
				$this->ReplaceContentByClass($class, $changeTo, $val);
			}
		}
	}
	
	public function hasClass($className, $check){
		if($check['class'] == $className || preg_match('#^'.preg_quote($className, '#').' .*#i', $check) || preg_match('#.* '.preg_quote($className, '#').'$#i', $check)  || preg_match('#.* '.preg_quote($className, '#').' .*#i', $check)){
			return true;
		}
		return false;
	}
	
	
	public function ReplaceAttributeByClass($class, $attr, $changeTo, $obj=null){
		if($obj === null){
			$obj = &$this;
		}
		foreach($obj as $key=>$val){
			$attr = $val->attributes();
			if($this->hasClass($class, $attr)){
				$val[$attr] = $changeTo;
			}
			if(is_object($val)){
				$this->ReplaceAttributeByClass($class, $attr, $changeTo, $val);
			}
		}
	}
	/*
	public function ReplaceAttributeByClass($class, $attr, $changeTo){
		$result = $this->xpath('//*[contains(@class,"'.$class.' ") or contains(@class," '.$class.'") or @class="'.$class.'"]');
		foreach($result as $k=>$element){
			$element[$attr] = $changeTo;
		}
	}*/
	
	public function returnAttributes(){
		$array = '';
		foreach($this->attributes() as $k=>$val){
			$array[(string)$k] = (string)$val;
		}
		return $array;
	}

	public function GetHTMLByClass($class, $htmlEntity = false){
		return $this->GetOuterHTMLByClass($class, $htmlEntity);
	}

	public function GetElementByClass($class){
		$result = $this->xpath('//*[contains(@class,"'.$class.'")]');
		$return = array();
		foreach($result as $k=>$element){
			$return[] = $element;
		}
		return $return;
	}

	public function GetClasses(){
		$attr = $this->attributes();
		return explode(' ', trim((string)$attr['class']));
	}

	public function GetOuterHTMLByClass($class, $htmlEntity = false){
		$result = $this->xpath('//*[contains(@class,"'.$class.' ") or contains(@class," '.$class.'") or @class="'.$class.'"]');
		$return = array();
		foreach($result as $k=>$element){
			if($htmlEntity === true){
				$return[] = htmlspecialchars((string)$element->asXml());
			}else{
				$return[] = (string)$element->asXml();
			}
		}
		return $return;
	}

	public function GetInnerHTMLByClass($class, $htmlEntity = false){
		$result = $this->xpath('//*[contains(@class,"'.$class.' ") or contains(@class," '.$class.'") or @class="'.$class.'"]');
		$return = array();
		foreach($result as $k=>$element){
			$tag = $element->getName();
			$tmp = (string)$element->asXml();
			$tmp = trim($tmp);
			$tmp = preg_replace("#^<".$tag."[^>]*>(.*)</".$tag.">$#is", '$1', $tmp);
			if($htmlEntity === true){
				$tmp = htmlspecialchars($tmp);
			}
			$return[] = $tmp;
		}
		return $return;
	}

	function getChildCData($parent, $name, $value=''){
		$new_child = new SimpleXML("<$name><![CDATA[".$value."]]></$name>");
		$node1 = dom_import_simplexml($parent);
		$dom_sxe = dom_import_simplexml($new_child);
		$node2 = $node1->ownerDocument->importNode($dom_sxe, true);
		$node1->appendChild($node2);
		return simplexml_import_dom($node1, 'SimpleXML');
	}
/*
	public function addChild( $name, $value=''){
		$this->$name = new SimpleXMLElement("<$name>$value</$name>");
		return &$this->$name;
	}

	function addAttribute($name, $value=''){
		$node1 = dom_import_simplexml($this);
		$node1->setAttribute($name,$value);
		$this = simplexml_import_dom($node1);
	}
*/
}