false, 'output-xhtml' => true, 'show-body-only' => true, 'numeric-entities' => true); $tidy = new tidy; /* Initialize some arrays to hold all the pages and paths we've * seen. In this case the path of each web page is stored in the * database. */ $paths = array(); /* Here we iterate over each line of the table that this query returns. * Each line will be an associative array which has keys equal to the * field names and value equal to the field values */ foreach ($pages as $key => $page) { /* Now we use the Tidy object to clean up the "content" field * which contains the content for the main block of each page. * We save this cleaned content back into the content field. */ $tidy->parseString($page["content"], $tidy_config, 'utf8'); $tidy->cleanRepair(); $page["content"] = tidy_get_output($tidy); /* Cascade requires that the content we use be well-formed XML, * thus we need to wrap the XML in a single root tag before * delivering it to the CMS */ $line["content"] = '' . $line["content"] . ""; /* Finally we want to end the HTML tag to complete the markup */ $page["content"] . ''; /* The old CMS had a field named "path" which stored the complete * path of the page, including directory structure and filename. * We want to separate this path out into these two parts, so * that we can add the pages to Cascade */ /* We want to find the string length of the path */ $pathlen = strlen($page["path"]); /* Next we find the position of the last (notice the use of strrpos) * directory seperator (the old CMS used a "/"). */ $filename_loc = strrpos($page["path"], "/"); /* Now we grab the part of the string after this last "/" so we can use * that as the page's system name */ $system_name = substr($page["path"], $filename_loc + 1, $pathlen - $filename_loc - 1); /* Because Cascade does not use page extensions in the CMS, we * want to remove the extension from the system name. In this case, * the old CMS used the ".htm" extension */ $system_name = str_replace(".htm", "", $system_name); /* We store the system name in the associative array, so that we * can use it later. */ $page["__system_name"] = $system_name; /* Now we want to transform the path into the part before the * page name */ $page["path"] = substr($page["path"], 0, $filename_loc); /* We are going to have to add all the paths we've seen on-the-fly, * so we add them to an associative array (the paths are the keys) */ $paths[$page["path"]] = true; if (!isset($page["metaDesc"])) $page["metaDesc"] = ""; if (!isset($page["keywords"])) $page["keywords"] = ""; if (!isset($page["title"])) $page["title"] = ""; /* Replace the old element in the array with this new one. * This is a safer method than doing foreach with references */ $pages[$key] = $page; } /* We want to add parent paths before children, so we sort them by * their string length. We use uksort, because we are using the array * like a hash table and we want to sort on the keys */ uksort($paths, "comp_length"); /* Open up a SOAP client to the Cascade server. We give the URI of * the WSDL document describing Cascade Web Services */ $client = new SoapClient("http://localhost:8080/ws/services/AssetOperationService?wsdl", array('trace' => 1)); /* Iterate through the keys (each one is a single, unique path) of * $paths and add it to Cascade */ foreach ($paths as $path => $i) add_folder($path, $client); /* Iterate through the elements of $pages (each one is a an associative * array containing the page data) and add it to Cascade */ foreach ($pages as $page) add_page($page, $client); } function add_folder($path, $client) { /* We need to find the last element on the path, which will * be the directory we want to create. We do this similarly to * the way we separated the page name from the path */ /* Find the string length of the path */ $pathlen = strlen($path); /* Find the position of the last path separator */ $folder_loc = strrpos($path, "/"); /* The folder name will be the substring after this separator */ $folder_name = substr($path, $folder_loc + 1, $pathlen - $folder_loc - 1); /* The parent folder for our new folder will be the parent directory */ $path = substr($path, 0, $folder_loc + 1); /* Now we fill an associative array that we will pass to the PHP * SOAP functions. The structure of this array will be determined * by the WSDL specification. PHP will interpret the structure * and create appropriate XML to pass to the Web Services */ $create_params = array ( 'authentication' => array( 'password' => "admin", 'username' => "admin" ), 'asset' => array( 'folder' => array( 'name' => $folder_name, 'metadataSetPath' => "/Default", 'parentFolderPath' => $path))); try { /* Pass the create parameters through the PHP SOAP client. */ $response = $client->create($create_params); /* If something goes wrong, it will be reported with * __getLastResponse, so be sure to take a look at the * message it returns. */ //print($client->__getLastResponse() . "\n"); } catch (Exception $e) { /* The request will throw an exception when parameters do * not conform to the WSDL. This will *not* catch errors * in the parameters themselves */ print("Folder creation request failed to conform to the WSDL.\n"); } } /* This function adds a page to the Cascade server with web * services. The page information should be stored in an * associative array, $pdata. */ function add_page($pdata, $client) { /* Ensure that all the metadata is encoded in UTF-8 */ $pdata["title"] = utf8_encode($pdata["title"]); $pdata["keywords"] = utf8_encode($pdata["keywords"]); $pdata["metaDesc"] = utf8_encode($pdata["metaDesc"]); /* Costruct the parameters in the same way that we * constructucted them for the folder, though creating * a page requires a bit more information */ $create_params = array ( 'authentication' => array( 'password' => "admin", 'username' => "admin" ), 'asset' => array( 'page' => array( 'name' => $pdata["__system_name"], 'parentFolderPath' => $pdata["path"], 'metadataSetPath' => "/Default", 'configurationSetPath' => "/General/Simple Full HTML", 'xhtml' => $pdata["content"], 'metadata' => array( 'title' => $pdata["title"], 'keywords' => $pdata["keywords"], 'metaDescription' =>$pdata["metaDesc"])))); try { $response = $client->create($create_params); /* If something goes wrong, uncomment this line to read * the server's response to your SOAP request */ //print($client->__getLastResponse()); } catch (Exception $e) { print("Page creation request failed to conform to the WSDL.\n"); } } /* Compare the string lengths of two strings. This is * used by the uksort above */ function comp_length($astring, $bstring) { if (strlen($astring) == strlen($bstring)) return 0; if (strlen($astring) > strlen($bstring)) return 1; else return -1; } function import_quotes($quotes) { /* Construct a SOAP client connecting to Cascade instance */ $client = new SoapClient("http://localhost:8080/ws/services/AssetOperationService?wsdl", array('trace' => 1)); /* Create a folder to hold our quotes */ add_folder("//quotes", $client); /* Iterate thruogh each quote */ foreach ($quotes as $quote) { /* Convert the quote body to UTF-8 encoding */ $quote["body"] = utf8_encode($quote["body"]); $quote["type"] = utf8_encode($quote["type"]); $quote["source"] = utf8_encode($quote["source"]); /* construct the parameters to create pages that use * data definitions. Notice the structure of the * structuredDataNodes. Each node is an array of the * elements of each data defintion */ $create_params = array ( 'authentication' => array( 'password' => "admin", 'username' => "admin" ), 'asset' => array( 'page' => array( 'name' => $quote["id"], 'parentFolderPath' => "/quotes", 'metadataSetPath' => "/Default", 'configurationSetPath' => "/General/Simple XML", 'structuredData' => array( 'definitionPath' => "/Quote", 'structuredDataNodes' => array( 'structuredDataNode' => array( array( 'type' => "text", 'identifier' => "type", 'text' => $quote["type"]), array( 'type' => "text", 'identifier' => "source", 'text' => $quote["source"]), array( 'type' => "text", 'identifier' => "body", 'text' => $quote["body"]) ))) ) )); try { /* Pass this request to Web Services */ $response = $client->create($create_params); /* If something goes wrong check the value of * __getLastResponse() */ print("\n". $client->__getLastResponse() . "\n"); } catch (Exception $e) { /* The request will throw an exception when parameters do * not conform to the WSDL. This will *not* catch errors * in the parameters themselves */ print("Page creation request failed to conform to the WSDL.\n"); } } } ?>