Elxis CMS Forum
Support => Technical support => Topic started 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 ??? ??? ??? ???
-
I miss understand the question sorry.
-
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;
-
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 ;)
-
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)
<?php
$param1 = $params->get('first_parameter', '');
$param2 = $params->get('second_parameter', '');
$param3 = $params->get('third_parameter', '');
//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):
<?php
if (version_compare(PHP_VERSION, '5.1.0') >= 0) { libxml_use_internal_errors(true); }
$xmlDoc = simplexml_load_file('path_to_xml_file', 'SimpleXMLElement');
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
<?php
require_once($mainframe->getCfg('absolute_path').'/administrator/includes/softdisk.class.php');
$row = new softdiskdb($database);
$row->sdsection = 'CORE';
$row->valuetype = 'STRING';
$row->sdname = 'MYMODULE_MD5';
$row->sdvalue = $md5sum;
$row->sdsystem = '0';
$row->lastmodified = time();
$row->sdhidden = '0';
$row->store();
?>
Read the value from softdisk
<?php
require_once($mainframe->getCfg('absolute_path').'/administrator/includes/softdisk.class.php');
$softdisk = new softDisk();
$previous_md5 = $softdisk->getValue('MYMODULE_MD5');
?>
Update value in softdisk
<?php
require_once($mainframe->getCfg('absolute_path').'/administrator/includes/softdisk.class.php');
$softdisk = new softDisk();
$softdisk->update('MYMODULE_MD5', $md5sum);
?>
-
Thanks datahell.
A new module powered FLASH/XML/SOFTDISK will be ready at soon... :)
-
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. ;)