relations in xml text

Author Message

Ben Pirt

Friday 20 January 2006 2:39:12 am

Hi there,
Thanks for all of the replies on my last question about creating a new node without a draft. Here's another tricky one I think...

Is it possible to be able to tell which related nodes are used in xml text fields for a node and which ones are ust related.

Why?

I am building a site where the owner is able to link up all kinds of related content to a particular page, which then gets automatically linked up in a list in the right hand column. However, sometimes he uses some of these relations in an xml text field (e.g. embedding images) and so they now show up twice on the page. If I could tell which ones were linked to the xml text area then I could choose not to show them in the RH column.

Any ideas? Short of writing an extension to return an array of related nodes to an xml field.

Cheers,

Ben

Xavier Dutoit

Friday 20 January 2006 1:14:52 pm

I made this extension extactly for the need you discribe.

http://ez.no/community/contribs/template_plugins/getobjects_extension

The name of the tag (object) has changed on 3.6, you'd have to update the code. That's simple, but I don't have the time to do it and test it... but I'd be more than happy to add the modification you're going to do on it ;)

You can find it on pubsvn too.

X+

http://www.sydesy.com

Ben Pirt

Tuesday 24 January 2006 11:18:22 am

Thanks Xavier,
Great extension and absolutely perfect for my needs. Hopefully it will be included in eZ before too long. As suggested I made some changes, which were basically to check for dom elements called "embed" and to also check if they have an attribute of "object_id". So the function "modify" is now as follows:

function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
    {
        if (!isset($namedParameters['xmlattribute']->DataText))
            return "should be an attribute";
         
        $xmldata =& $namedParameters['xmlattribute']->DataText;
        $xml = new eZXML();
        $dom =& $xml->domTree( $xmldata );
        if ( is_object ($dom) )
        {
            $objects =& $dom->elementsByName( "embed" );
            foreach ($objects as $object)
            {
                $attributes=& $object->attributes();
                foreach ($attributes as $attribute)
                {
                    if ($attribute->Name == "object_id")
                        $operatorValue[] = $attribute->content;
                } 
            }
        }
    }

I haven't done a check for the eZ version, but this is working perfectly on my 3.6 installation.

Thanks again,

Ben Pirt

Xavier Dutoit

Wednesday 25 January 2006 12:05:59 am

Thanks for your contrib,

I've modified it so it's compatible both with 3.5 and 3.6.
That's on pubsvn and on the contrib area too;

Could you test with your config and tell me if it's ok ?

X+

http://www.sydesy.com

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

Main resources:

Total runtime0.0173 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0068 587.9141152.6250
Module start 'layout' 0.00680.0030 740.539139.4453
Module start 'content' 0.00980.0053 779.984493.4297
Module end 'content' 0.01510.0022 873.414134.3047
Script end 0.0173  907.7188 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002514.1982140.0002
Check MTime0.00126.6511140.0001
Mysql Total
Database connection0.00137.574710.0013
Mysqli_queries0.002815.894030.0009
Looping result0.00000.093610.0000
Template Total0.001810.410.0018
Template load0.00095.259510.0009
Template processing0.00095.091510.0009
Override
Cache load0.00053.076410.0005
General
dbfile0.00031.761980.0000
String conversion0.00000.039940.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs