Import an eZXMLText custom tag with PHP

Author Message

Tom TOMHTML

Thursday 21 August 2008 12:54:49 pm

Hi,
I'm using eZ Publish 4.0 and I've to fill the eZXMLtext attribute of an object with HTML data. But I'm unable to add custom tags.

Example :

$mystring  = "Hello, this is <b>bold</b> and this is <XXX>a factbox</XXX>, ...";

$parser = new eZSimplifiedXMLInputParser( $contentObjectID, false, 0 );

$document = $parser->process( $mystring );

then I got that in the XMLtext attribute :

Hello, this is <strong>bold</strong> and this is a factbox, ...

Well, the parser converts the tag "B" into "STRONG" because of the public variable $InputTags in the class eZSimplifiedXMLInputParser. Take a look :

class eZSimplifiedXMLInputParser extends eZXMLInputParser
{
     var $InputTags = array(
          'b'       => array( 'name' => 'strong' ),
          ....

I've tried to redefine InputTags by adding "XXX" => array("name" => "factbox") but nothing happened.
Who can see a solution ?

And, afterwards, how to handle parameters of custom tags?
Let's say I've a custom tag named "img" with parameters "src" and "alt", my template file is OK and I'm able to create that custom tag in the editor (it appears as a blue rectangle) and when I publish it all is OK, the image is displayed as expected.
However, importing the following code with PHP fails miserably.

$mystring = "This is <b>bold</b> and that is an image : <img src="http://URLofAnImage" alt="alternative text" />";

Any idea?
Thanks in advance.



TOMHTML, French user of eZ Publish.

Tom TOMHTML

Friday 22 August 2008 9:18:59 am

OK, I've found the solution, thank you people :P

==>
The trick is to replace this:

$text = "lorem ipsum <img src='....' alt='...' /> dolor";

by that, with the PHP function or regular expression of your choice:

$text = "lorem ipsum <custom name='img' src='...' alt='...' /> dolor";

I hope this may help some.

PS: be careful with "width" attribute, it is already used by something else and it will be automatically fill with "100%", whatever the content of your attribute.



TOMHTML, French user of eZ Publish.

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 19:05:44
Script start
Timing: Jan 18 2025 19:05:44
Module start 'layout'
Timing: Jan 18 2025 19:05:44
Module start 'content'
Timing: Jan 18 2025 19:05:44
Module end 'content'
Timing: Jan 18 2025 19:05:44
Script end

Main resources:

Total runtime0.7292 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.0167 589.1484152.6406
Module start 'layout' 0.01670.0052 741.789139.4766
Module start 'content' 0.02190.7058 781.2656466.6484
Module end 'content' 0.72770.0015 1,247.91418.1406
Script end 0.7292  1,256.0547 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00490.6669160.0003
Check MTime0.00140.1958160.0001
Mysql Total
Database connection0.00690.946710.0069
Mysqli_queries0.663590.9804520.0128
Looping result0.00050.0698500.0000
Template Total0.677792.920.3388
Template load0.00220.307220.0011
Template processing0.675492.619120.3377
Template load and register function0.00020.029210.0002
states
state_id_array0.00090.117810.0009
state_identifier_array0.00160.223720.0008
Override
Cache load0.00190.2592280.0001
Sytem overhead
Fetch class attribute can translate value0.00100.130710.0010
Fetch class attribute name0.00210.282620.0010
XML
Image XML parsing0.00010.015510.0001
class_abstraction
Instantiating content class attribute0.00000.000920.0000
General
dbfile0.00190.2657100.0002
String conversion0.00000.001840.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
5content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
10content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
6content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs