Elxis CMS Forum

Extensions => Modules => Topic started by: gsot on September 17, 2009, 15:55:39

Title: Xml settings
Post by: gsot on September 17, 2009, 15:55:39
I would like to have an .swf object in my site, specifically a flash map. The map is distributed in javascript, so i just had to copy that in a php file and import it in elxis with a simple xml file with no params in it. Everything has worked just fine and at the moment,i have the flash map in the proper div!

My problem is though, that the only way i can change the settings of the map, is via its settings file which is an xml file and is loaded in the javascript code. What i am trying now to achieve is to be able to modify the map through elxis control panel. To simplify the problem: Elxis modules read settings from the database, but my module reads from its own xml file.

What are your suggestions? Shall I build a script that reads the params from the database and writes them in the map's settings file? I am confused..  ???

php file
Code: [Select]
( &#39;_VALID_MOS&#39; ) or die( &#39;Direct Access to this location is not allowed.&#39; );

<script type="text/javascript" src="ammap/swfobject.js"></script>
<div id="flashcontent">
<strong>You need to upgrade your Flash Player</strong>

<script type="text/javascript">

var so = new SWFObject("ammap/ammap.swf", "ammap", "150", "100", "8", "#444444");
so.addVariable("path", "ammap/");
so.addVariable("settings_file", escape("ammap/ammap_settings.xml"));                   
so.addVariable("data_file", escape("ammap/ammap_data.xml"));


part of xml map settings
Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>
Title: Re: Xml settings
Post by: datahell on September 17, 2009, 18:13:02
Elxis read the XML files (not the database), finds the parameters default values, types, etc, and afterwards BINDS to that parameters the saved values from the database.

If you wish to modify the XML file then you must have a script that will be able to read/write on that file. Domit or simple pie (both integrated into elxis) can help you read any XML file. In order to create such a script and be able to use it via elxis interface you should either create a small component or an elxis tool. Both of these scripts must be able to perform the following tasks:

1. Read the XML file (via Domit, Simple pie or standard php).
2. Display a form which will have as fields the parameters read in the XML file and their values.
3. Save the form and update the XML file (re-create the XML file).

The easiest method is by creating an Elxis tool. Elxis tools are very easy to be build. They do not have installers. You just copy-paste them into "tools" directory and they work!

Reading your XML file

Code: (php) [Select]
$xmlDoc = new DOMIT_Lite_Document();
$rows = array();
$q 0;
if (
$xmlDoc->loadXML($this->xmlfilefalsetrue)) {
$element $xmlDoc->documentElement;
       if (
$element->getTagName() == &#39;settings&#39;) {
if ($element->hasChildNodes()) {
$myChildNodes $element->childNodes;
$numChildren $element->childCount;
                  for (
$i 0$i $numChildren$i++) {
$currentNode $myChildNodes[$i];
$childElement $currentNode->getElementsByPath(&#39;width&#39;, 1);
$rows[$q][&#39;width&#39;] = $childElement->getText();

Save/update XML file

Code: (php) [Select]
= &#39;xxxxx&#39;; //contains the whole data of the new XML file
Title: Re: Xml settings
Post by: gsot on September 18, 2009, 12:50:12
Thanks a lot! That was very helpful! It is beginning to become clear to me now.  :)

Your recommendation is to avoid building a module and do the same work with an elxis tool! Am I right?
Title: Re: Xml settings
Post by: datahell on September 18, 2009, 19:35:46
You asked me how to handle (edit) an XML file from elxis back-end and I answered you to that question. To display the map you can built a module, a bot or even a component. It depends on what you want to do.