KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.62
System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64
User : www ( 80)
PHP Version : 8.3.8
Disable Function : NONE
Directory :  /domains/simes/unused/fCMSBackend/includes/fcmsdb/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /domains/simes/unused/fCMSBackend/includes/fcmsdb/fcms_xml.php
<?php

require_once "./includes/xpath/xpath.php";

$XML_ATTRLIST_PAGE = array ("url", "cprops", "iprops");

class FCMS_XML {

	var $xp;
	var $initOK;
	

	# ----- Init

	function FCMS_XML () {
		$path = "./xmlContent.xml";

		$this->xp = new FCMSXPath ();
		
		if (filesize ($path) > 0) {
			$ok = $this->xp->parse ($path);
		}
		else {
			$def_content = '<?xml version="1.0" encoding="utf-8"?><content/>';
			$ok = $this->xp->parse ($def_content, False);
		}

		$this->initOK = $ok;
	}

	# ----- Communication methods
	# They should be moved to a separate base class !

	function WGet ($paths, $request) {
		if ($paths == "") $this->fcmsResponseAll ($request);
			// Export the whole tree

		$patharr = explode ("|-|", $paths );
		$types_arr = array ();
		
		foreach ($patharr as $path) {
			$nval = $this->getNodeValueAsXML ($path);

			$value = $nval ['value'];
			$type = $nval ['type'];

			if (empty ($types_arr [$type])) $types_arr [$type ] = array();
			array_push ($types_arr [$type], $value);
		}

		$ret = "";
		foreach ($types_arr as $type => $val) {
			$ret .= '<' . $type . '>';
			foreach ($val as $content ) {
				$ret .= $content;
			}
			$ret .= '</' . $type . '>';
		}

		$ret = "<content>\n" . $ret . "\n</content>";

		$this->fcmsResponse ($ret, $request);
	}

	function WEdit ($xmltext, $request) {
		$xp =& $this->xp;
		$xpreq = new FCMSXPath ();
		$xpreq->parse ($xmltext, False);

		$ctypes = array ();
		$type_nodes = $xpreq->match ('/*/*');
		
		foreach ($type_nodes as $typenode) {
			$tname = $xpreq->getNodeName ($typenode);
			array_push ($ctypes, $tname);
		}

		foreach ($ctypes as $type) {
			$xp->createSingleChildNodeOf ('/content', $type);

			$pxpath ='/content/' . $type;
			$fxpath_base = $pxpath . '/field';
			$field_nodes = $xpreq->match ($fxpath_base);
			
			foreach ($field_nodes as $fnode) {
				$fpath = $xpreq->getAttribute ($fnode, 'path');

				$fxpath = $fxpath_base .  '[@path="' . $fpath .'"]';
				$fnode_dest = $xp->matchNode ($fxpath);
				
				if (! $fnode_dest) {
					$fnode_dest = $xp->appendChildNodeOf ($pxpath, "field");
					$xp->setAttribute ($fnode_dest, 'path', $fpath);
				}
					
				$page_nodes = $xpreq->match ($fxpath . '/page');
				foreach ($page_nodes as $pnode) {
					$page_num = $xpreq->getAttribute ($pnode, 'n');
					$page_xpath_base = $fxpath . '/page';
					$page_xpath = $page_xpath_base . '[@n="' . $page_num .'"]';

					$page_dest = $xp->matchNode ($page_xpath);
					if (! $page_dest) {
						$page_dest = $xp->appendChildNodeOf ($fxpath, 'page');
						$xp->setAttribute ($page_dest, 'n', $page_num);
					}

					//$xp->importNode ($fxpath, $pnode, $xpreq);
					$this->updatePageElement ($xp, $page_dest, $xpreq, $pnode);
				}
				
			}
		}

		if (! $xp->exportToFile ('xmlContent.xml')) {
			$request->error ('AccessDenied');
		}
		else {
			$rarr = array ();
			$rarr ['status'] = "ok";
			$request->response ($rarr, "", True);
		}
	}

	function fcmsResponse ($xml, $request) {
		$xml = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . $xml;
		$request->responseXML ($xml);
	}

	function fcmsResponseAll ($request) {
		$res = $this->xp->exportNodeAsXML ("/content");
		$this->fcmsResponse ($res, $request);
	}

	# ----- DB Access methods

	// This method takes the path (passed by flash) and 
	// returns the array ['type', 'value'].
	
	function getNodeValueAsXML ($path) {
		$res = array ();
		$xpath = '/content/*/field[@path="' . $path . '"]';

		$value = $this->xp->exportNodeAsXML ($xpath);
		
		if ($value) {		
			$pnode_xpath = $xpath . '/..';
			$type = $this->xp->getNodeName ($pnode_xpath);
		}
		else {
			$type = "type";
			$value = '<field path="' . $path . '" />';
		}

		$res ['type'] = $type;
		$res ['value'] = $value;

		return $res;
	}

	# ----- Utility methods

	function updatePageElement (&$xp1, $page1, &$xp2, $page2) {
		global $XML_ATTRLIST_PAGE;
		
		$n = $xp2->getAttribute ($page2, 'n');
		$value = $xp2->getNodeValue ($page2);

		$xp1->setAttribute ($page1, 'n', $n);
		$xp1->setNodeValue ($page1, $value);

		// Copy all other possible attributes
		foreach ($XML_ATTRLIST_PAGE as $attr) {
			$av = $xp2->getAttribute ($page2, $attr);
			if ($av) {
				$xp1->setAttribute ($page1, $attr, $av);
			}
		}
	}
}

?>

Anon7 - 2021