RSS

Website Build With Flash/HTML Integration

0 Comments | This entry was posted on Dec 15 2009

Last week, we at Sputnik Agency pushed live the site we had been building for our parent company Kit Digital. What I like most about this website is that it required us to include dynamic Flash navigation that had little overhead and to have the flash headers and html update seamlessly without reloading the page.

Project platform

We decided to go with WordPress as the project required a good CMS that was easy for the client to use and was quick and easy to develop.

Flash navigation with little overhead

There are two main flash headers that include navigation. This navigation needed to be dynamic in the way that if new pages were created in WordPress, the flash navigation needed to include these also. Having the navigation work dynamically this way can create an undesirable overhead as generally this would require mulitple calls to the database.

I overcame this by creating WordPress plugins that used hooks to create XML files when pages were added, updated or removed. These XML files included hierarchical page information required by the navigation. Therefore when a page is loaded in the front-end, the Flash would just read the XML file rather than force PHP to make database query requests. This resulted in the pages loading faster and reducing server overhead.

One other benefit of using SWFAddress is that although page loading does not occur, you can still click back through the pages of content you have loaded. The browser will not behave this way with standard content replacement using AJAX.

Seamlessly update flash header and update content

The next task was to allow links (whether clicked from the Flash navigation or HTML navigation) to update the Flash navigation and HTML without reloading the page. This seemed like a very difficult task and something I had not seen before but we managed this using SWFAddress.

Using the SWFAddress Javascript library we could update the URL in the address bar which would trigger both the HTML and Flash to change their behaviour. Once the the change was caught I used jQuery to make a request to another custom WordPress plugin that would pull page content from the database and then update the HTML without needing to reload the page. Clicking on the Flash links did the same.

The end result is a very sleek and fast loading website where the content is completely CMS driven.

To see these pages in action, visit these links: VX Platform, Global.

Quick Tutorial On Getting Started With SOAP In PHP.

1 Comment | This entry was posted on Jul 07 2009

Understanding what SOAP is and learning how to use it can be very confusing. There is much talk of SOAP on the Internet but finding an easy to understand tutorial on how to get started with it are hard to find. Therefore I have written this article for those new to SOAP.

This article assumes you have a good understanding of PHP and XML.

You use SOAP just the same way that you would any PHP class. However, in this case the class does not exist in the local applications file system, but at a remote site accessed over http.

A SOAP service is expressed as a URL. For this example I am using one I found with Google: terraservice.net/TerraService.asmx?WSDL. If we think of using a SOAP service as just another PHP class then the WSDL document is a list of all the available class methods and properties. If you open that URL in your browser you will see an XML document that lists these methods (also known as operations) and properties. If you load the page without the WSDL in the URL you will generally just get a list of the available methods: terraservice.net/TerraService.asmx. Clicking one of the operations will show the XML the service expects and the response a successful response will return. This is a typical example of how I would learn about how to use the SOAP service.

For this example I will use the GetPlaceFacts operation.This can be down by the following code:

$wsdl = 'http://terraservice.net/TerraService.asmx?WSDL';

$trace = true;
$exceptions = true;

$client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));

The new object is created with the PHP5 function SoapClient(). When first testing a service it’s best to set trace and exceptions to true so that any errors can be discovered more easily. We should now have created an object of the service and are ready to send a request. For this example we will use the GetPlaceList operation. In this case we need to send data along with the request.

$xml_array['placeName'] = 'Pomona';
$xml_array['MaxItems'] = 3;
$xml_array['imagePresence'] = true;

The data here is supplied in an array rather than XML like the service expects. This is automatically converted by SoapClient.

To better understand where how to determine how these values should be entered into the array, we should check with the request format:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetPlaceList xmlns="http://terraserver-usa.com/terraserver/">
      <placeName>string</placeName>
      <MaxItems>int</MaxItems>
      <imagePresence>boolean</imagePresence>
    </GetPlaceList>
  </soap:Body>
</soap:Envelope>

You can see the first element after the body element is the operation that we want to use. Following is the data that we need to send. If there were nested elements then we would need to use nested arrays to match.

Now that we have set the data we can make our request which follows:

$wsdl = 'http://terraservice.net/TerraService.asmx?WSDL';

$trace = true;
$exceptions = false;

$xml_array['placeName'] = 'Pomona';
$xml_array['MaxItems'] = 3;
$xml_array['imagePresence'] = true;

try
{
   $client = new SoapClient($wsdl, array('trace' => $trace, 'exceptions' => $exceptions));
   $response = $client->GetPlaceList($xml_array);
}

catch (Exception $e)
{
   echo "Error!";
   echo $e -> getMessage ();
   echo 'Last response: '. $client->__getLastResponse();
}

var_dump($response);

I also wrap the request in a try/catch pair to prevent any fatal errors. Also, from habit I dump the response with var_dump() so I can inspect the response in detail.

Sometimes you will find that the response values are quite nested. In this case I can trim back the response like this:

$response = $response->GetPlaceListResult->PlaceFacts;

Then we can loop through the results:

foreach($response as $key => $value)
{
   echo '<br />Place: '. $key .'<br />';
   echo 'City: '. $value->Place->City .'<br />';
   echo 'State: '. $value->Place->State .'<br />';
   echo 'Country: '. $value->Place->Country .'<br />';
}

This is a basic example of how to get started using SOAP. There is much more to it. By looking closely at the WSDL you will find which data must be supplied. This is shown by an attribute of minOccurs where equal to at least one.

For a definitive guide on SOAP I suggest going to www.w3schools.com/soap/default.asp.