Forums / Developer / Import an eZXMLText custom tag with PHP

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.