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.