Online Editor Extension - internal link list

Author Message

andreas spahr

Friday 28 November 2003 3:55:40 am

Hi all,

I want to improve the OE function "insert link". There should be the possibility to insert an internal link out of the own website. This is a very important feature for customers in general and is until now missing in the OE.
I publish my first draft and I hope, that some of you can help to improve it.

I modified two files: extension/ezdhtml/modules/ezdhtml/insertlink.php
and
extension/ezdhtml/design/standard/templates/ezdhtml/insertlink.tpl

Because of the large modifications in the insertlink.php I make a complete excerpt:
-----------------------------------------
<?php
//
//
// Copyright (C) 1999-2002 eZ systems as. All rights reserved.
//

if ( $VisualViewVersion == 2 )
{
ob_end_clean();
$HelpMode = "enabled";
include_once( "classes/eztemplate.php" );
$t = new eZTemplate( "extension/xmleditor/dhtml/design/standard/templates/ezdhtml/",
"ezarticle/admin/intl/", "en_GB", "medialist.php");

$t->set_file( "popup", "insertlink.tpl" );
$t->pparse( "output", "popup" );
}
else
{
include_once( "kernel/common/template.php" );
include_once( "lib/ezutils/classes/ezini.php" );

$ini =& eZINI::instance( 'content.ini' );
$classList =& $ini->variable( 'link', 'AvailableClasses' );

$Module =& $Params["Module"];

$http =& eZHttpTool::instance();

$Module->setTitle( "Insert Link" );

$tpl =& templateInit();

$tpl->setVariable( "class_list", $classList );
$tpl->setVariable( "module", $Module );

// Here starts internalLinkList
// Fetch the tree node with the root ID
$node = eZContentObjectTreeNode::fetch(1);
$node->dataMap();
// get the children from root
$children = $node->children();
$res = getInternalLinkListInfo($children, $ret);

$erg = array();
$internalLinkListInfo_i = 0;
$my_path_prefix = '/index.php/news/content/view/full/';
$internalLinkList = simplifyInternalLinkListArray($res, &$internalLinkListInfo_i, $erg, $my_path_prefix);


$tpl->setVariable( "internal_Link_List", $internalLinkList );

$Result = array();
$Result['content'] =& $tpl->fetch( "design:ezdhtml/insertlink.tpl" );
$Result['path'] = array( array( 'url' => '/ezdhtml/insertlink/',
'text' => 'Insert link' ) );
}

/*!
Retrieves info from the treenode members
Name, Class ID, Node ID of the object
*/
function getInternalLinkListInfo($children, $ret)
{
$i = 0;

foreach($children as $child)
{
// Get the object ID of the child and fetch it
$objID = $child->attribute("contentobject_id");
$obj = eZContentObject::fetch($objID);

// Load the object's datamap
$obj->dataMap();
$dataMap =& $obj->attribute( "data_map" );

// Get the class id
$clsID = $obj->attribute("contentclass_id");

$ret[$i]["NodeID"] = $child->attribute("node_id");
$ret[$i]["NodeName"] = $obj->attribute( "name" );

// The class ID of Folders == 1
// If the current child is a Folder, loop through its children
// This makes this function recursive. It'll loop through _every_ child of the glossary root
if($clsID == 1)
{
$children2 =& $child->children();
$res = getInternalLinkListInfo($children2);

$ret[$i]["Children"] = $res;
}
else
{
$ret[$i]["Children"] = null;
}

$i++;
}
// Return the result
return $ret;
}


function simplifyInternalLinkListArray( $myArrayTree, &$internalLinkListInfo_i, $erg, $my_path_prefix ) {
foreach ($myArrayTree as $item) {
while (list($key, $value) = each ($item)) {
switch($key) {
case 'ClassID':
break;
case 'NodeID':
$erg[$internalLinkListInfo_i]['NodeID'] = $my_path_prefix . $value;
break;
case 'NodeName':
$erg[$internalLinkListInfo_i++]['NodeName'] = $value;
break;
case 'Children':
if (isset($value)) {
$erg = simplifyInternalLinkListArray($value, &$internalLinkListInfo_i, $erg, $my_path_prefix);
}
break;
}
}
}
return $erg;
}
?>
-----------------------------------------

And this are the changes in the insertlink.tpl file:
-----------------------------------------
<tr>
<td>Internal Links:</td>
<td>
<select name="interneLinkListe" align="left" onchange="javascript:linkUrl.value=this.value">
<option value="">Select an internal link
{section name=internalLinkList loop=$internal_Link_List}
<option value="{$internalLinkList:item.NodeID}">{$internalLinkList:item.NodeName}</option>
{/section}
</select>
</td>
</tr>
-----------------------------------------

As you can see, my programming is not the best eZ-style, please improve it! Also the variable $my_path_prefix in the php-file is unacceptable, but I hope someone can improve it. Small peaces are copied out of the contribution 'glossary'.

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 19 2025 00:21:54
Script start
Timing: Jan 19 2025 00:21:54
Module start 'layout'
Timing: Jan 19 2025 00:21:54
Module start 'content'
Timing: Jan 19 2025 00:21:55
Module end 'content'
Timing: Jan 19 2025 00:21:55
Script end

Main resources:

Total runtime0.9195 sec
Peak memory usage4,096.0000 KB
Database Queries46

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0066 588.0469152.6406
Module start 'layout' 0.00660.0033 740.687539.4766
Module start 'content' 0.01000.9078 780.1641443.5781
Module end 'content' 0.91770.0017 1,223.742212.1250
Script end 0.9194  1,235.8672 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00400.4327160.0002
Check MTime0.00160.1757160.0001
Mysql Total
Database connection0.00080.084610.0008
Mysqli_queries0.850492.4803460.0185
Looping result0.00050.0505440.0000
Template Total0.889096.720.4445
Template load0.00180.191520.0009
Template processing0.887296.483120.4436
Template load and register function0.00020.024810.0002
states
state_id_array0.00070.080610.0007
state_identifier_array0.00090.094020.0004
Override
Cache load0.00170.18731410.0000
Sytem overhead
Fetch class attribute can translate value0.00100.111210.0010
Fetch class attribute name0.00100.111810.0010
XML
Image XML parsing0.00010.013610.0001
class_abstraction
Instantiating content class attribute0.00000.000410.0000
General
dbfile0.00100.1101100.0001
String conversion0.00000.000840.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
1content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
14content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
13content/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: 30
 Number of unique templates used: 5

Time used to render debug report: 0.0002 secs