CMSURL; $cmsdirectory = $config->cmsdirectory; $user = "".$config->username; $pass = "".$config->password; $metadata = "".$config->metadataset; $configset = "".$config->configset; $datadefinition = "".$config->datadefinition; $oldimagefolder = "".$config->oldimagefolder; $newimagefodler = "".$config->newimagefolder; $timestamp = $_SERVER['REQUEST_TIME']; //supplies WSDL $client = new SoapClient($CMSURL . "/ws/services/AssetOperationService?wsdl", array('trace' => 1)); directoryXML($xmldirectory); fwrite($log,"TOTAL EXECUTION TIME: ".(time() - $timestamp)." seconds\n"); fclose($log); } else { echo "You may import one of the following directories:

"; foreach ($config->import as $e) { $directory = str_replace('/','%2f',$e->xmldirectory); $logf = str_replace('.','%2e',$e->logfile); echo "".$e->xmldirectory."
"; } } //Reset timeout set_time_limit(30); //Recurs through the folder structure containing the XML to import. Mimics the XML folder structure for the CMS function directoryXML($dir) { global $log; global $timestamp; $contents = scandir($dir); foreach($contents as $item) { //It's an XML file if(substr_count(strtolower("".$item),".xml") > 0) { if($temp = simplexml_load_file($dir."/".$item)) { outputToCMS($temp, $dir); } else { fwrite($log,"FAILED XML LOAD: ".$dir."/".$item." TIME: ".(time() - $timestamp)." seconds\n"); } } //It's a directory else if (substr_count($item,".") == 0) { directoryXML($dir."/".$item); } } } //Sets up parameters and then writes to CMS function outputToCMS($page, $dir) { global $in; global $client; global $cmsdirectory; global $user; global $pass; global $metadata; global $configset; global $datadefinition; global $log; global $timestamp; global $oldimagefolder; global $newimagefolder; $dmeta; $pagepath; $data = $page->NewsItem->NewsComponent->NewsComponent; $xhtml = $data->ContentItem->DataContent->html->body->asXML(); //Create folder page goes in if ($dir[0] == '/') { $pagepath = $cmsdirectory.$dir; make_folder($pagepath,basename($dir)); } else { $pagepath = $cmsdirectory."/".$dir; make_folder($pagepath,basename($dir)); } //Full path to the page in the cms $pagepath = $pagepath."/".str_replace(" ","-",strtolower(substr($data->NewsLines->HeadLine, 0, 100))); //Build array of descriptive metadata //Push OfInterestTo fields foreach($data->DescriptiveMetadata->OfInterestTo as $i) { foreach($i->attributes() as $a) { if ($a->getName() == 'FormalName') { $dmeta[] = array('type' => 'text','identifier' => 'OfInterestTo','text' => "".$a); break; } } } //Push TopicOccurrences foreach($data->DescriptiveMetadata->TopicOccurrence as $t) { foreach($t->attributes() as $a) { if ($a->getName() == 'Topic') { $dmeta[] = array('type' => 'text','identifier' => 'TopicOccurrence','text' => "".$a); break; } } } //Push Language foreach($data->DescriptiveMetadata->Language->attributes() as $a) { if ($a->getName() == 'FormalName') { $dmeta[] = array('type' => 'text','identifier' => 'Language','text' => $a); } } $newslinetype; //Create NewsLineType foreach($data->NewsLines->NewsLine->NewsLineType->attributes() as $a) { if ($a->getName() == 'FormalName') { $newslinetype = $a; break; } } //Set up edit parameters. Content uses structured data definition $create_params = array ( 'authentication' => array( 'password' => $pass, 'username' => $user ), 'asset' => array( 'page' => array( 'name' => basename($pagepath), 'parentFolderPath' => dirname($pagepath), 'path' => '', 'metadataSetPath' => $metadata, 'configurationSetPath' => $configset, 'structuredData' => array( 'definitionPath' => "".$datadefinition, 'structuredDataNodes' => array( 'structuredDataNode' => array( array('type' => 'group', 'identifier' => 'NewsComponent', 'structuredDataNodes' => array( 'structuredDataNode' => array( array('type' => 'group', 'identifier' => 'NewsLines', 'structuredDataNodes' => array( 'structuredDataNode' => array( array('type' => 'text', 'identifier' => 'HeadLine', 'text' => "".$data->NewsLines->HeadLine ), array('type' => 'text', 'identifier' => 'ByLine', 'text' => "".$data->NewsLines->ByLine ), array('type' => 'text', 'identifier' => 'DateLine', 'text' => "".$data->NewsLines->DateLine ), array('type' => 'text', 'identifier' => 'CreditLine', 'text' => "".$data->NewsLines->CreditLine ), array('type' => 'text', 'identifier' => 'CopyrightLine', 'text' => "".$data->NewsLines->CopyrightLine ), array('type' => 'text', 'identifier' => 'SlugLine', 'text' => "".$data->NewsLines->SlugLine ), array('type' => 'group', 'identifier' => 'NewsLine', 'structuredDataNodes' => array( 'structuredDataNode' => array( array('type' => 'text', 'identifier' => 'NewsLineType', 'text' => "".$newslinetype ), array('type' => 'text', 'identifier' => 'NewsLineText', 'text' => "".$data->NewsLines->NewsLine->NewsLineText ))) ) ) )), array('type' => 'group', 'identifier' => 'DescriptiveMetadata', 'structuredDataNodes' => array( 'structuredDataNode' => $dmeta )), array('type' => 'group', 'identifier' => 'ContentItem', 'structuredDataNodes' => array( 'structuredDataNode' => array( array('type' => 'text', 'identifier' => 'DataContent', 'text' => str_replace("src=\"".$oldimagefolder,"src=\"".$newimagefolder,str_replace("&","&",str_replace("&","&","".$data->ContentItem->DataContent->html->body->asXML())))."" ) ) )) ) )) ) ) ), 'metadata' => array( 'displayName' => substr("".$data->NewsLines->HeadLine, 0, 200) ) ))); try { $reply = $client->create($create_params); if ( $reply->createReturn->success != 'true' ) { $response = $client->__getLastResponse(); $start = strpos($response,"") + strlen(""); $response = substr($response,$start,strpos($response,"") - $start); if (substr_count($response,"deadlock") > 0) { outputToCMS($page); //SQL deadlocked...try again } else { fwrite($log,"CREATE FAILED: ".$pagepath." ERROR: ".$response." TIME: ".(time() - $timestamp)." seconds\n"); } } else { fwrite($log,"CREATE SUCCEEDED: ".$pagepath." TIME: ".(time() - $timestamp)." seconds\n"); } } catch (Exception $e) { print("Page creation/edit request failed to conform to the WSDL.\n"); print($client->__getLastResponse()); } } //Creates the library and group folders for the imported file function make_folder($path,$display) { global $user; global $pass; global $client; global $log; global $timestamp; //Set up folder params $edit_params = array ( 'authentication' => array( 'password' => $pass, 'username' => $user ), 'asset' => array( 'folder' => array( 'parentFolderPath' => dirname($path), 'path' => $path, 'metadataSetPath' => "/Default", 'name' => basename($path), 'metadata' => array( 'displayName' => "".$display ) ))); try { $client->edit($edit_params); //if edit fails, then folder did not exist, so create it if ( $reply->editReturn->success != 'true' ) { $edit_params['asset']['folder']['path'] = ""; //does not exist yet, so 'path' should be empty $client->create($edit_params); if ( $reply->createReturn->success != 'true' ) { $response = $client->__getLastResponse(); $start = strpos($response,"") + strlen(""); $response = substr($response,$start,strpos($response,"") - $start); if (substr_count($response,"deadlock") > 0) { outputToCMS($page); //SQL deadlocked...try again } else { fwrite($log,"CREATE FAILED: ".$path." ERROR: ".$response." TIME: ".(time() - $timestamp)." seconds\n"); } } else { fwrite($log,"CREATE SUCCEEDED: ".$path." TIME: ".(time() - $timestamp)." seconds\n"); } } } catch (Exception $e) { print("Folder creation/edit request failed to conform to the WSDL.\n"); print($client->__getLastResponse()); } } ?>