username = "hill"; $auth->password = "hill"; $asset = new asset(); $asset->page = new page(); $page = $asset->page; $page->metadataSetPath = "General/Portal"; $page->name = "asdf"; $page->parentFolderPath = "/"; $page->configurationSetPath = "Portal/Standard"; $page->xhtml = "asdf"; $asset->fullXML = "asdf"; print_r($asset->serialize()); $service->create($auth, $asset); print_r($service); /** *//** $prefix = "qwertyytrewqtseu"; $service = new AssetOperationHandlerService(); $auth = new authentication(); $auth->username = "hill"; $auth->password = "hill"; $id = new identifier(); $id->type = "block"; $id->path = "$prefix/$prefix" . 6; // $id->path = "intranet/site-map"; $service->read($auth, $id); // print_r($service); // $service->serialize(); // print_r($service->serialize()); //$service->create($auth, $service->asset); print_r($service); /** $asset->page->metadataSetPath = "Default"; $asset->page->configurationSetPath = "General/Simple XML"; $asset->page->structuredData->definitionPath = "stuff";/***/ /** $service->edit($auth, $asset); $service->create($auth, $asset); print_r($service->serialize()); */ /** * uses reflections to automatically box objects into array, and unbox xml into objects */ class soapSerializer { var $fullXML; /** * Tosses objects into an array for soap */ function serialize() { $result = array(); $reflect = new ReflectionObject($this); $vars = $reflect->getProperties(); for ($i = 0; $i < count($vars); $i++) { $curVar = $reflect->getProperty($vars[$i]->name)->getValue($this); if ($vars[$i]->name != 'fullXML') { if (is_string($curVar)) { global $squelchValue; //if we're on a squelched value (id or path) if (strtolower(substr($vars[$i]->name, 0 - strlen($squelchValue), strlen($squelchValue))) == $squelchValue && ($squelchValue == "id" || $squelchValue == "path")) { if ($squelchValue == "id") { $checkValue = "Path"; } else if ($squelchValue == "path") { $checkValue = "Id"; } $curValue = substr($vars[$i]->name, 0, 0 - strlen($squelchValue)); if (strlen($curValue) == 0) { $checkValue = strtolower($checkValue); } $curValue .= $checkValue; try { $newVar = $reflect->getProperty($curValue)->getValue($this); if (!isset($newVar)) { $result[convertToWSDL($vars[$i]->name, false)] = $curVar; } } catch (Exception $e) { $result[convertToWSDL($vars[$i]->name, false)] = $curVar; } } else/***/ { $result[convertToWSDL($vars[$i]->name, false)] = $curVar; } } else if (is_array($curVar)) { $result[convertToWSDL($vars[$i]->name, false)] = array(); for ($j = 0; $j < count($curVar); $j++) { $result[convertToWSDL($vars[$i]->name, false)][] = $curVar[$j]->serialize(); } } else if (isset($curVar)){ // echo $vars[$i]->name . "@".$curVar->fullXML."\r\n"; $result[convertToWSDL($vars[$i]->name, false)] = $curVar->serialize(); } } } return $result; } /** * Breaks the soap call's resulting XML back into objects */ function deserialize() { $reflect = new ReflectionObject($this); $vars = $reflect->getProperties(); for ($i = 0; $i < count($vars); $i++) { //if we're not on the fullXML var if ($vars[$i]->name != 'fullXML') { if ($vars[$i]->name != 'url') { $reflect->getProperty($vars[$i]->name)->setValue($this, null); } //if the element isn't null if (substr_count($this->fullXML, "<" . convertToWSDL($vars[$i]->name, true) . ">") > 0) { $curXML = getElement($this->fullXML, convertToWSDL($vars[$i]->name, true)); if ($curXML != "") { if (substr_count($curXML, "<") == 0) { $reflect->getProperty($vars[$i]->name)->setValue($this, checkFormat($curXML)); } else { $object = new $vars[$i]->name; $object->fullXML = $curXML; $object->deserialize(); $reflect->getProperty($vars[$i]->name)->setValue($this, $object); } } } } } } } class soapArraySerializer extends soapSerializer { function deserialize() { $reflect = new ReflectionObject($this); $vars = $reflect->getProperties(); $name = $vars[0]->getName(); $temp = array(); $curStr = $this->fullXML; while (substr_count($curStr, "<".convertToWSDL($name, true).">") > 0) { $node = new $name; $node->fullXML = getElement($curStr, convertToWSDL($name, true)); $node->deserialize(); if ($node->fullXML != "") { $temp[] = $node; } $i = 0; $needle = convertToWSDL($name, true); $curStr = substr($curStr, strpos($curStr, "<".$needle.">") + strlen("<".$needle.">")); while ($i >= 0) { if ((strpos($curStr, "<".$needle.">") === false) || strpos($curStr, "") < strpos($curStr, "<".$needle.">")) { $i--; $curStr = substr($curStr, strpos($curStr, "") + strlen("")); } else { $i++; $curStr = substr($curStr, strpos($curStr, "<".$needle.">") + strlen("<".$needle.">")); } } } $this->$name = $temp; } } class children extends soapArraySerializer { var $child;//child } class child extends SoapSerializer { var $type; var $id; var $path; } class baseAsset extends soapSerializer { var $id;//string // var $entityType;//not needed on client end; shouldn't be included in wsdl anyway //as it just breaks stuff } class namedasset extends baseAsset { var $name;//string } class containeredAsset extends namedAsset { var $parentContainerId;//string var $parentContainerPath;//string var $path;//string } class folderContainedAsset extends namedAsset { var $parentFolderId;//string var $parentFolderPath;//string var $path;//string var $lastModifiedDate; var $lastModifiedBy; } class dublinAwareAsset extends folderContainedAsset { var $metadata; var $metadataSetId;//string var $metadataSetPath;//string } class expiringAsset extends dublinAwareAsset { var $expirationFolderId;//string var $expirationFolderPath;//string } class publishableAsset extends expiringAsset { var $shouldBePublished;//string var $shouldBeIndexed;//string var $lastPublishedDate; var $lastPublishedBy; } class target extends namedAsset { var $parentTargetId;//string var $parentTargetPath;//string var $path;//string var $baseFolderId;//string var $baseFolderPath;//string var $outputExtension;//string var $cssClasses;//string var $cssFileId;//string var $cssFilePath;//string var $serializationType; var $includeXMLDeclaration; var $includeTargetPath; var $removeBaseFolder; var $usesScheduledPublishing; var $timeToPublish; var $publishInterval; var $publishIntervalUnits;//string var $children; } class destination extends namedAsset { var $parentTargetId;//string var $parentTargetPath;//string var $transportId;//string var $transportPath;//string var $applicableGroups; var $directory;//string var $enabled;//string var $publishASCII;//string var $usesScheduledPublishing;//string var $timeToPublish;//string var $publishInterval;//string var $publishIntervalUnits;//string } class fileSystemTransport extends namedAsset { var $path; var $directory; var $outputZip; } class ftpTransport extends namedAsset { var $path; var $hostName; var $port; var $username; var $password; var $directory; var $doSFTP; var $doPASV; } class pageRegion extends baseAsset { var $name; var $blockId; var $blockPath; var $noBlock; var $stylesheetId; var $stylesheetPath; var $noStylesheet; } class pageConfiguration extends baseAsset { var $name; var $defaultConfiguration; var $templateId; var $templatePath; var $stylesheetPath; var $stylesheetId; var $pageRegions; } class assetFactory extends containeredAsset { var $applicableGroups; var $assetType; var $baseAssetId; var $baseAssetPath; var $placementFolderId; var $placementFolderPath; var $allowSubfolderPlacement; var $folderPlacementPosition; var $overwrite; var $workflowMode; var $workflowDefinitionId; var $workflowDefinitionPath; } class workflowStepConfiguration { var $stepAssignment; var $stepIdentifier; } class workflowConfiguration { var $workflowName; var $workflowDefinitionId; var $workflowDefinitionPath; var $workflowComments; var $workflowStepConfiguration; } class metadata extends soapSerializer { var $author; var $displayName; var $endDate; var $keywords; var $metaDescription; var $reviewDate; var $startDate; var $summary; var $teaser; var $title; } class entityType extends soapSerializer { var $name; } class file extends publishableAsset { var $data; var $text; } class folder extends publishableAsset { var $children; } class page extends publishableAsset { var $configurationSetId; var $configurationSetPath; var $structuredData; var $xhtml; var $pageConfigurations; } class structuredData extends soapSerializer { var $definitionId; var $definitionPath; var $structuredDataNodes; } class structuredDataNodes extends soapArraySerializer { var $structuredDataNode; } class structuredDataNode extends soapSerializer { var $type; var $identifier; var $text; var $assetType; var $blockId; var $blockPath; var $fileId; var $filePath; var $pageId; var $pagePath; var $structuredDataNodes; var $symlinkId; var $symlinkPath; } class feedBlock extends expiringAsset { var $feedURL; } class indexBlock extends expiringAsset { var $indexedFolderId; var $indexedFolderPath; var $maxRenderedAssets; var $depthOfIndex; var $includePageContent; var $includeCurrentPageXML; var $renderCurrentPageAndHierarchy; var $includeChildrenInHierarchy; var $indexPages; var $indexBlocks; var $indexLinks; var $indexFiles; var $indexRegularContent; var $indexSystemMetadata; var $indexUserMetadata; var $indexAccessRights; var $indexUserInfo; var $indexWorkflowInfo; var $appendCallingPageData; var $sortMethod; } class stylesheet extends folderContainedAsset { var $xml;//string } class reference extends folderContainedAsset { var $referencedAssetId;//string var $referencedAssetPath;//string var $referencedAssetType; } class publishSetContainer extends containeredAsset { var $children;//children } class folders extends soapArraySerializer { var $publishableAssetIdentifier;//fileIdentifier } class pages extends soapArraySerializer { var $publishableAssetIdentifier;//fileIdentifier } class files extends soapArraySerializer { var $publishableAssetIdentifier;//fileIdentifier } class publishableAssetIdentifier extends soapSerializer { var $type; var $id; var $path; } class publishSet extends containeredAsset { var $files; var $folders; var $pages; var $usesScheduledPublishing; var $timeToPublish; var $publishInterval; var $publishIntervalUnits;//string } class workflowDefinition extends containeredAsset { var $applicableGroups; var $copy;//string var $create;//string var $delete;//string var $edit;//string var $namingBehavior; var $xml;//string } class workflowDefinitionContainer extends containeredAsset { var $children; } class symlink extends expiringAsset { var $linkURL;//string } class template extends folderContainedAsset { var $targetId;//string var $targetPath;//string var $stylesheetId; var $stylesheetPath; var $xml;//string var $pageRegions; } class pageRegions extends soapArraySerializer { var $pageRegion; } class textBlock extends expiringAsset { var $text;//string } class xhtmlBlock extends expiringAsset { var $xhtml;//string } class xmlBlock extends expiringAsset { var $xml;//string } class metadataSetContainer extends containeredAsset { var $children; } class metadataSet extends containeredAsset { var $authorFieldRequired;//string var $authorFieldVisibility;//string var $descriptionFieldRequired;//string var $descriptionFieldVisibility;//string var $displayNameFieldRequired;//string var $displayNameFieldVisibility;//string var $endDateFieldRequired;//string var $endDateFieldVisibility;//string var $keywordsFieldRequired;//string var $keywordsFieldVisibility;//string var $reviewDateFieldRequired;//string var $reviewDateFieldVisibility;//string var $startDateFieldRequired;//string var $startDateFieldVisibility;//string var $summaryFieldRequired;//string var $summaryFieldVisibility;//string var $teaserFieldRequired;//string var $teaserFieldVisibility;//string var $titleFieldRequired;//string var $titleFieldVisibility;//string var $dynamicFields; } class dynamicFields extends soapArraySerializer { var $dynamicMetadataFieldDefinition; } class dynamicMetadataFieldDefinition extends soapSerializer { var $name;//string var $fieldType; var $required;//string var $visibility;//string var $configurationXML;//string } class structuredDataDefinitionContainer extends containeredAsset { var $children; } class structuredDataDefinition extends containeredAsset { var $xml;//string } class pageConfigurationSetContainer extends containeredAsset { var $children; } class pageConfigurationSet extends containeredAsset { var $pageConfigurations; } class pageConfigurations extends soapArraySerializer { var $pageConfiguration; } class assetFactoryContainer extends containeredAsset { var $applicableGroups;//string var $children; } class group extends soapSerializer { var $groupName;//string var $groupStartingPageId;//string var $groupStartingPagePath;//string var $groupBaseFolderId;//string var $groupBaseFolderPath;//string var $groupAssetFactoryContainerId;//string var $groupAssetFactoryContainerPath;//string var $cssClasses;//string var $wysiwygAllowFontAssignment;//string var $wysiwygAllowFontFormatting;//string var $wysiwygAllowTextFormatting;//string var $wygiwygAllowViewSource;//string var $wysiwygAllowImageInsertion;//string var $wysiwygAllowTableInsertion;//string var $users;//string var $role; } class user extends soapSerializer { var $username;//string var $fullName;//string var $email;//string var $authType; var $password;//string var $enabled;//string var $groups;//string var $defaultGroup;//string var $role; } class asset extends soapSerializer { var $workflowconfiguration; var $assetFactory; var $assetFactoryContainer; var $destination; var $feedBlock; var $file; var $fileSystemTransport; var $folder; var $ftpTransport; var $group; var $indexBlock; var $metadataSet; var $metadataSetContainer; var $page; var $pageConfigurationSet; var $pageConfigurationSetContainer; var $publishSet; var $publishSetContainer; var $reference; var $structuredDataDefinition; var $structuredDataDefinitionContainer; var $stylesheet; var $symlink; var $target; var $template; var $textBlock; var $user; var $workflowDefinition; var $workflowDefinitionContainer; var $xhtmlBlock; var $xmlBlock; } /** * Handles serialization of the identifier for an asset */ class identifier extends soapSerializer { var $type;//string var $id;//string var $path;//string } /** * Handles serialization of the authentication information */ class authentication extends soapSerializer { var $username;//string var $password;//string } /** * Handles all soap operations for the user */ class AssetOperationHandlerService extends soapSerializer { var $url = "http://localhost:8080/ws/services/AssetOperationService?wsdl";//string var $message;//string var $success;//string var $createdAssetId; var $asset; /* * Deletes the asset with the given identifier * $authentication the authentication--should be an Authentication object * $identifier the identifier--should be an Identifier object * @return the response from the wsdl */ function delete($authentication, $identifier) { $soapClient = new SoapClient($this->url, array('trace' => 1)); $soapClient->delete(array('authentication' => $authentication->serialize(), 'identifier' => $identifier->serialize())); $this->fullXML = $soapClient->__getLastResponse(); $this->deserialize(); } /** * Creates the given asset * $authentication the authentication--should be an Authentication object * $asset the asset--should be an Asset object */ function create($authentication, $asset) { $soapClient = new SoapClient($this->url, array('trace' => 1)); $soapClient->create(array('authentication' => $authentication->serialize(), 'asset' => $asset->serialize())); $this->fullXML = $soapClient->__getLastResponse(); } /** * Publishes the asset with the given identifier * $authentication the authentication--should be an Authentication object * $identifier the identifier--should be an Identifier object */ function publish($authentication, $identifier) { $soapClient = new SoapClient($this->url, array('trace' => 1)); $soapClient->publish(array('authentication' => $authentication->serialize(), 'identifier' => $identifier->serialize())); $this->fullXML = $soapClient->__getLastResponse(); $this->deserialize(); } /** * Edits the given asset * $authentication the authentication--should be an Authentication object * $asset the asset--should be an Asset object */ function edit($authentication, $asset) { $soapClient = new SoapClient($this->url, array('trace' => 1)); $soapClient->edit(array('authentication' => $authentication->serialize(), 'asset' => $asset->serialize())); $this->fullXML = $soapClient->__getLastResponse(); $this->deserialize(); } /** * Reads the asset with the given identifier * $authentication the authentication--should be an Authentication object * $identifier the identifier--should be an Identifier object */ function read ($authentication, $identifier) { $soapClient = new SoapClient($this->url, array('trace' => 1)); $soapClient->read(array('authentication' => $authentication->serialize(), 'identifier' => $identifier->serialize())); $this->fullXML = $soapClient->__getLastResponse(); $this->deserialize(); } } /** * Returns the string between $needle1 and $needle2 in $haystack * $haystack the area being searched * $needle1 where to start parsing * $needle2 where to end */ function subParse($haystack, $needle1, $needle2) { return substr(strstr($haystack, $needle1), strlen($needle1), strpos(substr(strstr($haystack, $needle1), strlen($needle1)), $needle2)); } /** * Returns the first element with the given name * @haystack the are being searched * @needle the element being looked for * @return the element */ function getElement($haystack, $needle) { // echo "$needle//$haystack\r\n"; $i = 0; //if there are multiple of these elements, make sure we're on the outermost one // if (substr_count($haystack, "<$needle>") > 1) { if ($needle == "success" || $needle == "asset" || $needle == "createdAssetId") { $haystack = strstr($haystack, "<".$needle); } else { while (strpos($haystack, "<$needle>") != 0 || $i != 0) { if (strpos($haystack, "") == 0 && strpos($haystack, "/>") !== false) { $i--; } else if (strpos($haystack, "<") == 0 && strpos($haystack, "<") !== false) { $i++; } $haystack = substr($haystack, 1); if (strlen($haystack) == 1) { // echo "@@"; return ""; } if ($i < 0) { return ""; } } } $beginning = substr(strstr($haystack, "<".$needle.">"), strlen("<".$needle.">")); $i = 0; $curResult = ""; while ($i >= 0) { if ((strpos($beginning, "<".$needle.">") === false) || strpos($beginning, "") < strpos($beginning, "<".$needle.">")) { $i--; $curResult .= substr($beginning, 0, strpos($beginning, "") + strlen("")); $beginning = substr($beginning, strpos($beginning, "") + strlen("")); } else { $i++; $curResult .= substr($beginning, 0, strpos($beginning, "<".$needle.">") + strlen("<".$needle.">")); $beginning = substr($beginning, strpos($beginning, "<".$needle.">") + strlen("<".$needle.">")); } } return substr($curResult, 0, 0 - strlen("")); } function convertToWSDL($haystack, $reading) { return $haystack; if ($reading) { return $haystack; if ($haystack == "structuredDataNode") { $haystack = "structuredDataNodes"; } else if ($haystack == "child") { $haystack = "children"; } else if ($haystack == "fileIdentifier") { $haystack = "files"; } else if ($haystack == "folderIdentifier") { $haystack = "folders"; } else if ($haystack == "pageIdentifier") { $haystack = "pages"; } else if ($haystack == "dynamicMetadataFieldDefinition") { $haystack = "dynamicFields"; } else if ($haystack == "pageRegion") { $haystack = "pageRegions"; } else if ($haystack == "pageConfiguration") { $haystack = "pageConfigurations"; } } else { if ($haystack == "fileIdentifier") { $haystack = "file"; } else if ($haystack == "folderIdentifier") { $haystack = "folder"; } else if ($haystack == "pageIdentifier") { $haystack = "page"; } } return $haystack; } function checkFormat($string) { $xml = str_replace(">", ">", str_replace("<", "<", $string)); return $xml; } ?>