{"cms-login-info"}->server; // The location of the Cascade instance $cascade_user = (string)$xml_config->{"cms-login-info"}->username; // The username to login to the Cascade instance above $cascade_password = (string)$xml_config->{"cms-login-info"}->password; // The username's password $cascade_folder = (string)$xml_config->{"cms-folder"}; // The folder to place the new page in the CMS $cascade_mimic_asset_path = (string)$xml_config->{"cms-mimic-asset-path"}; // The path in the CMS to an asset factory $separator = "_X__"; $checkboxFlag = "__CONTENTXMLCHECKBOX"; $checkboxSeparator = "::CONTENT-XML-CHECKBOX::"; $selectorFlag = "__CONTENTXMLSELECTOR"; $selectorSeparator = "::CONTENT-XML-SELECTOR::"; // Flags whether the web service read call appends unneeded prefixes to certain fields such as "Metadata Sets/" to metadataSetPath // In future versions of Cascade Server this should be changed to FALSE $prefixFlag = false; $contentArray = array(); // Gathers the groups and text fields information into a structured array $currentArray = array(); // This is used as an iterator through the contentArray // Organize the flat POST data into a multi-dimensional array to represent nested groups // and hold text field contents in the array appropriately foreach($_POST as $identifier => $content) { if($identifier != 'data_definition__required_fields') // don't include the hidden field { $temp_array = explode($separator, $identifier); // Begin iterating through the first group names $currentArray = &$contentArray; if(count($temp_array) > 1) { // Don't include the last token in the identifier as that is the node identifier not a identifier for($i = 0; $i < count($temp_array) - 1; $i++) { $group_name = $temp_array[$i]; // Get the group name // If the current group has not been found then add it to the group-array if(!isset($currentArray["$group_name"])) { $currentArray["$group_name"] = array(); } $currentArray = &$currentArray["$group_name"]; } // Add node identifier and content to the $contentArray in the appropriate group array $real_identifier = ""; if(is_array($content)) { $text = ""; $t_identifier = $temp_array[count($temp_array)-1]; if(substr($t_identifier, -1 * strlen($checkboxFlag), strlen($checkboxFlag)) == $checkboxFlag) { $real_identifier = substr($t_identifier, 0, strlen($t_identifier) - strlen($checkboxFlag)); $text = $checkboxSeparator; foreach($content as $index => $checkbox_value) { $text .= $checkbox_value.$checkboxSeparator; } } else { $real_identifier = substr($t_identifier, 0, strlen($t_identifier) - strlen($selectorFlag)); $text = $selectorSeparator; foreach($content as $index => $option_value) { $text .= $option_value.$selectorSeparator; } } $currentArray["$real_identifier"] = $text; } else { $currentArray[$temp_array[count($temp_array)-1]] = $content; } } else { // Add node identifier and content to the $contentArray $currentArray["$identifier"] = $content; } } } // Array to store structuredDataNode parameters needed to create CMS page $structuredDataNode = array(); // Migrate the groups and fields into the structuredDataNodes migrateContent($contentArray, $structuredDataNode); // Instantiate the web service $service = new AssetOperationHandlerService(); $service->url = $cascade_server."/ws/services/AssetOperationService?wsdl"; // Make authentication object for service calls $auth = new authentication(); $auth->username = $cascade_user; $auth->password = $cascade_password; // Make a new identifier to locate the asset in the CMS to mimic when uploading // a new page into the CMS, using most of its characteristics. $id = new identifier(); $id->type = "page"; $id->path = $cascade_mimic_asset_path; $service->read($auth, $id); // Read the asset from the CMS $asset = $service->asset; // Assign $asset to the read mimic asset from the CMS $asset->page->parentFolderPath = $cascade_folder; // Change the parent folder path as indicated by the configuration file // Check if the web service is returning prefixes such as "Configuration Sets" to the configurationSetPath path if($prefixFlag) { // Strip the unneeded prefixes off so that they are the correct path to be submitted to a web service function $asset->page->configurationSetPath = substr($asset->page->configurationSetPath, strlen("Configuration Sets")+1); $asset->page->metadataSetPath = substr($asset->page->metadataSetPath, strlen("Metadata Sets")+1); $asset->page->structuredData->definitionPath = substr($asset->page->structuredData->definitionPath, strlen("Data Definitions")+1); } // Give the asset the structured data created from the POST data submitted to this php script $asset->page->structuredData->structuredDataNodes->structuredDataNode = $structuredDataNode; $service->create($auth, $asset); // Create the asset in the CMS // Output the web service response for the user echo "Web Service Output:
";
print_r($service->serialize());
echo "
"; // Migrate the content stored in a structured array into the structuredDataNodes array function migrateContent(&$contentArray, &$structuredDataNode) { foreach($contentArray as $identifier => $content) { // If the current index in the associative array ($contentArray) points to an array of information, // then the identifier and array represent a group identifier and the group's content if(is_array($content)) { // Create a group structuredDataNode to add to the $structuredDataNode array $tNode = new structuredDataNode; $tNode->type = 'group'; $tNode->identifier = "$identifier"; $tNode->structuredDataNodes = new structuredDataNodes; $tNode->structuredDataNodes->structuredDataNode = array(); $structuredDataNode[] = $tNode; // Migrate the content contained within the current group as well migrateContent($content, $tNode->structuredDataNodes->structuredDataNode); } else { // Create a structuredDataNode containing information drawn from $contentArray $tNode = new structuredDataNode; $tNode->type = 'text'; $tNode->identifier = "$identifier"; $tNode->text = "$content"; $structuredDataNode[] = $tNode; // Add the structuredDataNode the $structuredDataNode array } } } ?>