Enable Flash Support

From Snapp CMS Developer Documentation

Jump to: navigation, search

This page describes the traditional method of communicating between SnappCMS and Flash applets using XML. In v2.10, SnappCMS introduced support for the AMF object serialization format, which is a more efficient method of communications.

For an idea of how to use AMF support in SnappCMS, read AMF_Protocol_handling. Otherwise, the text below describes the still-supported old way of transferring data.


Contents

Step 1 - Add Flash Params to Configuration

To enable the flash functionality in the the following lines need to be added to the config.ini file

[Flash]
baseURL="load.php"
redirect=1


baseURL: provides a basis for all for all urls generated with in the menu xml.

redirect: Forces site redirected from form posts to use the base url instead of the index.php

Step 2 - Reading Sitemap XML

To read the xml site structure, simply make a get request to

load.php?menu=0

The menu param tells the cms which part of the sitemap to load the xml from

Step 3 - Configure Pages to Use with Flash

Depending to the type of module the page is using, there will need to be a template created that can generate the XML Output,

In most cases if you are using a template built for use with flash these will be already installed

Example

The example below is from the gallery module

 	$xmlDOM = new DOMDocument('1.0','UTF-8');
 	$root = $xmlDOM->createElement('gallery');
 	// Gallery ID
 	$node = $root->appendChild($xmlDOM->createElement('id'));
 	$node->appendChild($xmlDOM->createTextNode($gallery->id));
 
 	// Gallery Title
 	$node = $root->appendChild($xmlDOM->createElement('title'));
 	$node->appendChild($xmlDOM->createTextNode($gallery->title));
 
 	// Gallery Content
 	$node = $root->appendChild($xmlDOM->createElement('content'));
 	$node->appendChild($xmlDOM->createCDATASection('<body>'.str_replace(' ', ' ', $gallery->content).'</body>'));
 
 	// Gallery Images
 	$images = $root->appendChild($xmlDOM->createElement('images'));
 	foreach ($gallery->images AS $image) {
 		
 		$parts = pathinfo($image->src);
 		switch ($parts['extension']) {
 			case 'flv':
 				$imageNode = $xmlDOM->createElement('video');
 				foreach ($image AS $name=>$value) {
 					switch ($name) {
 						case 'src':
 							$node = $imageNode->appendChild($xmlDOM->createElement('file'));
 							$node->appendChild($xmlDOM->createTextNode($cms->config->Paths->relativeMedia.$value));
 							break;
 						default:
 						if (!is_object($value)) {
 							$node = $imageNode->appendChild($xmlDOM->createElement($name));
 							switch ($name) {
 								case 'url':
 								case 'description':
 									$node->appendChild($xmlDOM->createCDATASection($value));
 									break;
 								default:
 									$node->appendChild($xmlDOM->createTextNode($value));		
 							}
 						}
 						
 					}
 				}
 				$images->appendChild($imageNode);				
 				break;
 			case 'swf':
 				$imageNode = $xmlDOM->createElement('flash');
 				foreach ($image AS $name=>$value) {
 					switch ($name) {
 						case 'src':
 							$node = $imageNode->appendChild($xmlDOM->createElement('file'));
 							$node->appendChild($xmlDOM->createTextNode($cms->config->Paths->relativeMedia.$value));
 							break;
 						default:
 						if (!is_object($value)) {
 							$node = $imageNode->appendChild($xmlDOM->createElement($name));
 							switch ($name) {
 								case 'url':
 								case 'description':
 									$node->appendChild($xmlDOM->createCDATASection($value));
 									break;
 								default:
 									$node->appendChild($xmlDOM->createTextNode($value));		
 							}
 						}
 						
 					}
 				}
 				$images->appendChild($imageNode);				
 				break;
 			case 'mp3':
 				$imageNode = $xmlDOM->createElement('sound');
 				foreach ($image AS $name=>$value) {
 					switch ($name) {
 						case 'src':
 							$node = $imageNode->appendChild($xmlDOM->createElement('file'));
 							$node->appendChild($xmlDOM->createTextNode($cms->config->Paths->relativeMedia.$value));
 							break;
 						default:
 						if (!is_object($value)) {
 							$node = $imageNode->appendChild($xmlDOM->createElement($name));
 							switch ($name) {
 								case 'url':
 								case 'description':
 									$node->appendChild($xmlDOM->createCDATASection($value));
 									break;
 								default:
 									$node->appendChild($xmlDOM->createTextNode($value));		
 							}
 						}
 						
 					}
 				}
 				$images->appendChild($imageNode);				
 				break;
 			default:
 				$imageNode = $xmlDOM->createElement('image');
 				foreach ($image AS $name=>$value) {
 					switch ($name) {
 						case 'src':
 							$node = $imageNode->appendChild($xmlDOM->createElement('thumbnail'));
 							$node->appendChild($xmlDOM->createTextNode('/cms/image.php?f='.$value.'&s='.$gallery->thumbSize));
 							$node->setAttribute('width', $image->thumbSize->width);
 							$node->setAttribute('height', $image->thumbSize->height);
 							$node = $imageNode->appendChild($xmlDOM->createElement('preview'));
 							$node->appendChild($xmlDOM->createTextNode('/cms/image.php?f='.$value.'&s='.$gallery->largeSize));
 							$node->setAttribute('width', $image->largeSize->width);
 							$node->setAttribute('height', $image->largeSize->height);
 							$node = $imageNode->appendChild($xmlDOM->createElement('original'));
 							$node->appendChild($xmlDOM->createTextNode($cms->config->Paths->relativeMedia.$value));
 							$node->setAttribute('width', $image->originalSize->width);
 							$node->setAttribute('height', $image->originalSize->height);
 							break;
 						default:
 						if (!is_object($value)) {
 							$node = $imageNode->appendChild($xmlDOM->createElement($name));
 							switch ($name) {
 								case 'url':
 								case 'description':
 									$node->appendChild($xmlDOM->createCDATASection($value));
 									break;
 								default:
 									$node->appendChild($xmlDOM->createTextNode($value));		
 							}
 						}
 						
 					}
 				}
 				$images->appendChild($imageNode);		
 		}
 	}
 	$root->appendChild($images);
 	$xmlDOM->appendChild($root);
 	echo $xmlDOM->saveXML();
 

Step 4 - Reading Page Data XML

To read a pages xml data

load.php?page=10

The page param is the page id from the sitemap tree and can be retrieved from the Sitemap Menu XML

Personal tools
Core Components
Standalone Installs