Elxis CMS Forum

Support => Technical support => Topic started by: speck on March 29, 2010, 10:45:44

Title: [SOLVED] where is better to save a file .xml
Post by: speck on March 29, 2010, 10:45:44
I need an advice  :)
I finished a flash module, but i don't where is better to save a file xml that the module create and the flash movie read and dispolay.
Is better to save the file .xml in the elxis cache folder or in the same folder (or his subdirectory) of the module ??? ??? ??? ???
Title: Re: where is better to save a file .xml
Post by: CREATIVE Options on March 29, 2010, 11:57:35
I miss understand the question sorry.
Title: Re: where is better to save a file .xml
Post by: datahell on March 29, 2010, 13:38:12
For consistency all modules files should be kept under the same directory. So, you should save the XML file under modules/mymodule/

BUT at it is a file that the web server needs to write often then it might be better to place it inside the cache folder. Make sure that your module is able to create that file if does not exist. If you place it inside cache folder then there are 2 options:
1. Dont include that file in module's package. The module itself will generate that file during the first run.
2. Include the file is module's package and during the first run your module should copy that file inside the cache folder.

Note
Elxis file manager provides you with some very cool methods to handle files.

Create a file: $fmanager->createFile('path_to_file', 'data');

Write data to a file:  $fmanager->writeFile('path_to_file', 'data');

If you inteed to use $fmanager inside a function dont forget to call it via global before you use it:
global $fmanager;
Title: Re: where is better to save a file .xml
Post by: speck on March 29, 2010, 14:52:34
BUT at it is a file that the web server needs to write often then it might be better to place it inside the cache folder. Make sure that your module is able to create that file if does not exist. If you place it inside cache folder then there are 2 options:

Thanks datahell, you're always a great teacher!! and your advices are always precious for me
The cache is the best solution for me because the module write the xml everytime is loaded.
I don't know if is possible to insert a button in the control panel of the module to create manually the xml everytime when I change the parameters in the module. I have intention to make a check too when the module is loaded (example if $check = 1 create a xml ) but i don't know to do rewrite the check variable in the parameters (ex: $check=0) when the xml file has been created from the front end, i don't know how to do  :( or if is possible to do this from a module ;)
Title: Re: where is better to save a file .xml
Post by: datahell on March 29, 2010, 18:19:57
Here is an idea on how to do it. There might be a better way but this is the first that came into my mind.

Calculate the md5 checksum of all the parameter's values and write these values inside the XML file or in a separate text file.
When ever the module runs calculate this md5 checksum and compare it with the value from the xml/txt file. If the 2 md5 strings varie you should re-generate the XML file.

You can alternatively save the md5 check sum in database (table elx_softdisk is a good choice).

Example of MD5 calculation (you should validate params, not just parse them)
Code: [Select]
<?php 
$param1 
$params->get(&#39;first_parameter&#39;, &#39;&#39;);
$param2 $params->get(&#39;second_parameter&#39;, &#39;&#39;);
$param3 $params->get(&#39;third_parameter&#39;, &#39;&#39;);
//continue for all parameters....
$md5sum md5($param1.$param2.$param3);
?>

Your XML file:

<myxml>
    <md5>previous_value_of_md5sum</md5>
    <more>rest of your xml file</more>
</myxml>

Read XML file (you should check if file exists first):

Code: [Select]
<?php 
if (version_compare(PHP_VERSION, &#39;5.1.0&#39;) >= 0) { libxml_use_internal_errors(true); }
$xmlDoc simplexml_load_file(&#39;path_to_xml_file&#39;, &#39;SimpleXMLElement&#39;);
if ($xmlDoc) { 
     
$previous_md5 = (string)$xmlDoc->md5;
     if (
$previous_md5 != $md5sum) {
          
//parameters changed! We must recreate the XML file
     
} else {
          
//parameters are the same as before.
     
}
}
?>

Example of saving the md5 checksum in database instead of the XML file.

Create the softdisk entry
Code: [Select]
<?php 
require_once($mainframe->getCfg(&#39;absolute_path&#39;).&#39;/administrator/includes/softdisk.class.php&#39;);
$row = new softdiskdb($database);
$row->sdsection = &#39;CORE&#39;;
$row->valuetype = &#39;STRING&#39;;
$row->sdname = &#39;MYMODULE_MD5&#39;;
$row->sdvalue $md5sum;
$row->sdsystem = &#39;0&#39;;
$row->lastmodified time();
$row->sdhidden = &#39;0&#39;;
$row->store();
?>

Read the value from softdisk
Code: [Select]
<?php 
require_once($mainframe->getCfg(&#39;absolute_path&#39;).&#39;/administrator/includes/softdisk.class.php&#39;);
$softdisk = new softDisk();
$previous_md5 $softdisk->getValue(&#39;MYMODULE_MD5&#39;);
?>

Update value in softdisk
Code: [Select]
<?php 
require_once($mainframe->getCfg(&#39;absolute_path&#39;).&#39;/administrator/includes/softdisk.class.php&#39;);
$softdisk = new softDisk();
$softdisk->update(&#39;MYMODULE_MD5&#39;, $md5sum);
?>
Title: Re: where is better to save a file .xml
Post by: speck on April 05, 2010, 21:40:46
Thanks datahell.
A new module powered FLASH/XML/SOFTDISK will be ready at soon... :)
Title: Re: [SOLVED] where is better to save a file .xml
Post by: webgift on April 06, 2010, 15:48:45
My opinion is :

I don't know but i don't like this method.
Too many requests from XML file ...
Every time that change the image (e.g from 1st to 2nd) then we have a request from server to load the next image (2nd) and again and again.
Too many bandwidth resources from server.!

I have installed a script working with the same philosophy and i have had problems with bandwidth before 1 year ago.

I say again that is my opinion ... i hope to be acceptable. ;)