Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read/write to XML file in data folder
#1
Hi All,

I know this forum is not for learning PHP programming but I need help about specific GS PHP<=>XML connection.
Generally I looking for solution how to write data from form into XML files in data folder.
Next step I will looking how to read this data.

All I need is simple instruction like have in Joomla documentation here:
http://docs.joomla.org/Accessing_the_dat..._JDatabase

Just few lines of code how to write/read data in Get-Simple CMS.
Can anybody spend some time just to point me where to start. It is easy find information how read/write in SQL but not in XML way how it is in GS CMS.

Thank you in advance.
ArekS
Reply
#2
A good program you should check out which is ready for experimentation is the matrix, an XML database plug-in for GetSimple 3.1:
https://github.com/n00dles/DM_Matrix

A current plug-in for reference would be:
http://get-simple.info/extend/plugin/get...table/290/

GetSimple users the 'simpleXML' php function for reading and writing to file. For a good overview of that function go to:
http://us2.php.net/manual/en/book.simplexml.php

Reply
#3
Really thank you for information. This day I found some solutions in web and make my first attempt to read/write XML.
I created simple XML test file and create PHP file.
In PHP file I wrote (just important part of code):

$doc = new DOMDocument();
$doc->load( 'nameofmyxmlfile.xml' );
echo $doc->childNodes->length;

After that I can access to my XML file, (I made tests and success I can read data form XML) but when I move it to GS folders it stopping working.
How I move it to GS:
In my custom template folder create xyz.php file and put all my php code here (of coures use this file as template for page in GS admin). To the same folder copied my sample XML file.
Everytime I refresh site echo function show 0 (zero) so not loading XML file (see line 3 of my code). Strange, outside of GS it working OK. I suppose some framework of GS block it, maybe I should put it in different folders.
Can you point me what I'm doing wrong?

Best wishes
ArekS
Reply
#4
Look at our source code, its on github linked from download page.

We use simplexml, with extended cdata support.

Look at changedata.php for how we save page files.
Or settings for saving website.xml

PHP Code:
$getdata getXml(GSDATAOTHERPATH$file '.xml');
echo 
$getdata->node;

$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><item></item>');
$node $xml->addChild('node');
$node->addCData("blahblah");
XMLsave($xmlGSDATAOTHERPATH.$file.'.xml'); 
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#5
Thank you, I found it last night but one problem freeze me in place and I can't go forward.
My main goal is to create form where data are saved and read to/from XML. This form will be on one page, so I do not need plugin (because as I understand from Wiki plugin is displayed on every page). I created in my template folder somefile.php and create in it typical template (all working OK). Assign this template in Admin->Pages with one page.
Now if I put in this file code bellow (of course have correct xml file and so on) it read nothing.
Code:
$getdata = getXml(GSDATAOTHERPATH. $file . '.xml');
echo $getdata->node;
It point me to conclusion maybe it working only in plugin not in template files?
And second consideration: I'm still not sure where to put my XML file (but I was trying every place :-) ).
If using plugin and GSDATAOTHERPATH it is clear (in data/other/myxmlfile.xml) but if using template is it the same or GSDATAOTHERPATH point to different place?

Again thank you for your time :-)

Best wishes
ArekS
Reply
#6
Its the same, are you talking about a public form?
Your understanding of a plugin is wrong. A plugin is very well suited or this.

But template should work.

As far your problem i am not sure, you will need errors or something
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#7
Yes I'm talking about public form but have success - it now working OK in my template :-)
I was made all the time so simple error it is shame to write about this.
Again thank you for your patience. Big Grin

Back for moment to plugin. Reading Wiki I hope I understand hooks (can decide to what part of page plugin code will be added but can't understand filters (as I understand using filters I can decide on what pages plugin will be displayed).
I can't understand how to use filters to put plugin code only on one particular site.

Best
ArekS
Reply
#8
My understanding may be limited, but hooks are about adding content to the page where it otherwise wouldn't be (e.g. in the header or footer), whereas filters are about modifying existing content on the page (e.g. parsing the content field and replacing portions of the string). A clear example of this is when plugin developers allow users to put placeholders on their page content and still use a plugin, like RobA's External Commenting plugin or mvlcek's i18n Search.

I would look at External Comments for an easier to understand example. He returns the $content variable, searches it for the string that he wants to replace, replaces it with a function that calls the comments (in a return, not an echo) and concatenates it all together back into the $content variable to be returned at the end. That way, when the page content is called, the comments are shown wherever the user has declared the placeholder. This method either requires using explode(), str_replace() or preg_replace() to isolate the desired string (the last one requiring knowledge of regular expressions to get working, but ultimately being more flexible - though others might object that regex should be avoided).

(Also as a sidenote: my personal endorsement for creating XML files without having to worry about coding them is just to use DM Matrix. It exists for that very reason: easy plugin development Smile)
Reply
#9
Or you can just replace an entire page using a pre-template hook and modify global $content. Use an empty slug as a placehoder.
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#10
Thank you shawn_a and Angryboy, now I can see where to go further :-)

Best wishes
ArekS
Reply




Users browsing this thread: 1 Guest(s)