Saving ezxmltext through ajax

Author Message

Sao Tavi

Thursday 16 June 2011 12:37:16 pm

I tried to create something like an autosave feature for an ezxmltext, but I soon found out that it is not that easy to save the new data into the db in the correct format. I tried looking at ezxmltext datatype for getting help, but after several hours I gave up.

So... if I have in php the contents from a tiny mce editor and the contentObjectAttribute, how can I save them into the database in the right format?

What I did was either stripping the images or a lot of other things that were not right.

 

Oh, and just as a note: something strange happened, when trying to add images to the xml text I was getting some errors (like 'ez publish "A file is required for upload, no file were found.  No HTTP file found, cannot fetch uploaded file.') . Trying to find out the problems origins, without changing anything, it magically solved by itself after several tries and checking this on another ez publish install on the same server... Unfortunately, I cannot reproduce it.

PS: The redirection system is not good when using multiple tabs on the same ez publish installation. Maybe it should use post variables instead of cookies? I believe I should post this in the issues tracker.

Sao Tavi

Thursday 16 June 2011 2:54:24 pm

With a little bit of help, I found the answer eventually. It seems that I needed to use the parser from ezoe, it works with no problems now.

Here is the code used:

 

                $parser = new eZOEInputParser( );
                $parser->setParseLineBreaks( true );
                 
                if (!$document = $parser->process( $http->postVariable('val') ))
                    return 'failed to parse';
                 
                // Create XML structure
                $xmlString = eZXMLTextType::domString( $document );              

                $options['description']->setAttribute('data_text', $xmlString);
                $options['description']->store();

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 01:55:53
Script start
Timing: Jan 18 2025 01:55:53
Module start 'layout'
Timing: Jan 18 2025 01:55:53
Module start 'content'
Timing: Jan 18 2025 01:55:54
Module end 'content'
Timing: Jan 18 2025 01:55:54
Script end

Main resources:

Total runtime1.1345 sec
Peak memory usage4,096.0000 KB
Database Queries52

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0058 587.9141152.6250
Module start 'layout' 0.00580.0034 740.539139.4531
Module start 'content' 0.00931.1235 779.9922428.9844
Module end 'content' 1.13280.0016 1,208.97668.1641
Script end 1.1344  1,217.1406 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.2815160.0002
Check MTime0.00140.1209160.0001
Mysql Total
Database connection0.00070.058510.0007
Mysqli_queries1.090196.0917520.0210
Looping result0.00050.0424500.0000
Template Total1.103197.220.5515
Template load0.00210.186320.0011
Template processing1.101097.045720.5505
Template load and register function0.00050.048110.0005
states
state_id_array0.00130.113310.0013
state_identifier_array0.00140.127520.0007
Override
Cache load0.00160.1431230.0001
Sytem overhead
Fetch class attribute can translate value0.00070.063610.0007
Fetch class attribute name0.00110.099520.0006
XML
Image XML parsing0.00010.011610.0001
class_abstraction
Instantiating content class attribute0.00000.000520.0000
General
dbfile0.00230.2012100.0002
String conversion0.00000.001040.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
4content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 10
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs