" . $lastID . "") <= 0) {
;
}
} else {
fgets($fp);
}
while ($next = array_pop($ids)) {
fwrite($fp, "\t" . $next . "\r\n");
}
fwrite($fp, "");
}
/* This function will be called by the XML parser when it
* finds an opening tag */
function start_element($parser, $elementName, $attrs) {
global $tagstack;
global $template_xml;
global $processed_xml;
global $skip;
global $complexType;
global $complexLoc;
global $template_params;
global $xhtmlBlock;
if (isset($attrs['id'])) {
if (isset($processed_xml['event'][$attrs['id']])) {
$skip = true;
} else {
global $pass;
global $name;
global $path;
global $fullPath;
global $metaPath;
global $configPath;
global $dataPath;
global $newEvents;
$skip = false;
$processed_xml['event'][$attrs['id']] = $attrs['id'];
$newEvents['event'][$attrs['id']] = $attrs['id'];
$template_params = array (
'authentication' => array(
'password' => $pass,
'username' => $name),
'asset' => array(
'page' => array(
'name' => $attrs['id'],
'parentFolderPath' => $fullPath,
'path' => $fullPath . "/" . $attrs['id'],
'metadataSetPath' => $metaPath,
'configurationSetPath' => $configPath,
'structuredData' => array(
'definitionPath' => $dataPath,
'structuredDataNodes' => array(
'structuredDataNode' => array(
))))));
}
}
if (!$skip) {
if (count($tagstack) >= 2) {
if ($complexType == "xhtml") {
$xhtmlBlock .= "<" . $elementName;
$keys = array_keys($attrs);
$vars = array_values($attrs);
for ($i = 0; $i < count($attrs); $i++) {
$xhtmlBlock .= " " . $keys[$i] . "=" . $vars[$i];
}
$xhtmlBlock .= ">";
}
if (!$complexType) {
add_to_end($template_params['asset']['page']['structuredData']['structuredDataNodes']['structuredDataNode'], 2, $elementName);
}
if (isset($attrs['complexType'])) {
if ($attrs['complexType'] == "checkbox"
| $attrs['complexType'] == "selector"
| $attrs['complexType'] == "xhtml"
| $attrs['complexType'] == "asset") {
$complexType = $attrs['complexType'];
$complexLoc = count($tagstack);
if ($attrs['complexType'] == "xhtml") {
$xhtmlBlock = "";
}
} else {
echo "Error: complexType can not be of type \"" . $attrs['complexType'] . "\".";
$skip = true;
}
}
}
}
/* Push the current tag name onto our tag stack */
array_unshift($tagstack, $elementName);
}
/**
* Adds a new group onto the current one. If this turns out to not be a group, we can later change it
* to whatever it is by stepping back through the array once we have the data
* @&$curArray The current array. & makes it a funky php pseudo-fake-reference thingy.
* that references the original instead of a duplicate of it
* @i the index
* @name the name of the new element
*/
function add_to_end(&$curArray, $i, $name) {
global $tagstack;
global $host;
global $complexType;
global $complexLoc;
global $template_params;
if (count($tagstack) > $i) {
add_to_end($curArray[count($curArray) - 1]['structuredDataNodes']['structuredDataNode'], $i + 1, $name);
} else {
$newArray = array(
'type' => "group",
'identifier' => $name,
'structuredDataNodes' => array()
);
$curArray[] = $newArray;
}
}
/* This function will be called by the XML parser when it
* finds a closing tag */
function end_element($parser, $name) {
global $tagstack;
global $skip;
global $template_params;
global $complexLoc;
global $complexType;
global $host;
global $xhtmlBlock;
/**
* If we're processing an event and we're at the end of said event
*/
if (!$skip && $name == "event" && count($tagstack) == 2) {
$client = new SoapClient($host . "/ws/services/AssetOperationService?wsdl",
array('trace' => 1));
/** Try to edit */
$client->edit($template_params);
$result = $client->__getLastResponse();
/** If we can't, create it */
if (substr_count($client->__getLastResponse(), "false") > 0) {
$template_params['asset']['page']['path'] = "";
$client->create($template_params);
}
//echo "exiting";
}
/* We are exiting a tag, so we want to pop it off of our
* tag stack */
array_shift($tagstack);
if ($complexType) {
if ($complexType == "xhtml" && $complexLoc != count($tagstack)) {
$xhtmlBlock .= "" . $name;
$xhtmlBlock .= ">";
}
if ($complexLoc == count($tagstack)) {
if ($complexType == "xhtml") {
//put it all in the block
setData($template_params['asset']['page']['structuredData']['structuredDataNodes']['structuredDataNode'], 2, $xhtmlBlock);
}
$complexType = false;
}
}
}
/* This function will be called by the XML parser when it
* finds character data between the opening and the closing
* of a tag */
function character_data($parser, $data) {
/**
* If we're not on a real character_data node, run away. This is basically to
* ignore all whitespace nodes, because no one likes them anyway
*/
if (trim($data) == "") {
return;
}
global $xhtmlBlock;
global $complexType;
global $tagstack;
global $template_xml;
global $skip;
global $processed_xml;
global $template_params;
if ($complexType == "xhtml") {
$xhtmlBlock .= $data;
return;
}
/* If we aren't deep enough, don't do anything */
if (count($tagstack) < 2)
return;
/** here's where we traverse everything */
switch ($tagstack[count($tagstack) - 1]) {
/** If we're on the config file: */
case "system-data-structure":
switch ($tagstack[count($tagstack) - 2]) {
case "server":
global $host;
$host = $data;
break;
case "username":
global $name;
$name = $data;
break;
case "password":
global $pass;
$pass = $data;
break;
case "log":
global $logFile;
$logFile = $data;
break;
case "xml":
global $newFile;
$newFile = $data;
break;
case "base":
global $fullPath;
$fullPath = $data;
break;
case "config":
global $configPath;
$configPath = $data;
break;
case "meta":
global $metaPath;
$metaPath = $data;
break;
case "data":
global $dataPath;
$dataPath = $data;
break;
}
break;
/** If we're on the list of already-processed events: */
case "eventList":
switch ($tagstack[count($tagstack) - 2]) {
/** Add the eventID to our list */
case "eventID":
$template_xml['event'][$data] .= $data;
break;
}
break;
break;
/**If we're in the xml file that contains all of the events */
case "events":
switch ($tagstack[count($tagstack) - 2]) {
case "event":
/** If the eventID isn't already in our list of processed IDs: */
if (!$skip) {
setData($template_params['asset']['page']['structuredData']['structuredDataNodes']['structuredDataNode'], 2, $data);
// }
}
break;
default:
/** This should never get called */
echo "error position" . $data . ".." . $tagstack[count($tagstack) - 2];
break;
}
break;
}
}
/**
* Sets the current node's type to text, and text to the given data
* @&$curArray The current array. & makes it a funky php pseudo-fake-reference thingy.
* that references the original instead of a duplicate of it
* @i the index
* @data the data to add
*/
function setData(&$curArray, $i, $data) {
global $tagstack;
global $complexType;
global $complexLoc;
global $template_params;
global $CHECKBOX_DELIMITER;
global $SELECTOR_DELIMITER;
if ($complexType) {
$testI = $i + count($tagstack) - $complexLoc - 1;
} else {
$testI = $i;
}
if (count($tagstack) > $testI + 1) {
setData($curArray[count($curArray) - 1]['structuredDataNodes']['structuredDataNode'], $i + 1, $data);
} else if (count($tagstack) > $testI) {
setData($curArray[count($curArray) - 1], $i + 1, $data);
} else {
if ($complexType) {
if ($complexType == "checkbox") {
if (isset($curArray['text'])) {
$curArray['text'] .= $CHECKBOX_DELIMITER . $data;
} else {
$curArray['type'] = "text";
$curArray['text'] = $data;
}
} else if ($complexType == "selector") {
if (isset($curArray['text'])) {
$curArray['text'] .= $SELECTOR_DELIMITER . $data;
} else {
$curArray['type'] = "text";
$curArray['text'] = $data;
}
} else if ($complexType == "xhtml") {
$curArray['type'] = "text";
$curArray['text'] = $data;
} else {
echo "@@@@@@@" . $complexType . "$@@@@@@@";
}
} else {
$curArray['type'] = "text";
$curArray['text'] = $data;
}
}/***/
}
function parse_xml($file) {
global $template_xml;
global $tagstack;
global $checkLog;
/* Initialize our template data structure */
$template_xml = array();
/* Initialize the tag stack. This will be a stack of the tag
* structure we are currently in */
$tagstack = array();
/* Create an XML Parser object */
$xml_parser = xml_parser_create();
/* Turn off case folding on the XML Parser object, this
* will ensure that the parser will be case sensitive */
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 0);
/* Set the callback functions for the XML Parser object. The object
* will call these functions when various actions happen */
xml_set_element_handler($xml_parser, "start_element", "end_element");
xml_set_character_data_handler($xml_parser, "character_data");
/* Try to open the XML file */
if (file_exists($file)) {
$fp = fopen($file, "r");
} else {
if ($checkLog) {
echo "creating";
$fp = fopen($file, "w");
fwrite($fp, "\r\n");
fclose($fp);
$fp = fopen($file, "r");
} else {
die ("Cannot find: " . $file);
}
}
/* Read the data a bit at a a time */
while ($data = fread($fp, 4096)) {
/* Try to parse that bit */
if (!xml_parse($xml_parser, $data, feof($fp))) {
/* Give and error and quit if the parsing fails */
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
/* Free the parser data */
xml_parser_free($xml_parser);
}
?>