Saturday 27 March 2004 11:08:53 pm
Hi, One of the tasks that must be carried out on our website is the publishing of a monthly magazine. Each article for the monthly is generated by the print-layout software (pagemaker I think). When copying and pasting that html into the appropriate field (body) ezpublish of course stripped out all the html tags but <a href (which is transformed to <link>). The staff are not technically orientated at all, and have found moving through the heirarchial structure of ezpublish annoying and complex compared to their old system (a straight and simple php powered form... a one page script essentially). So when the problem hit that html tags (specifically important were img and font tags) were stripped out of each article of the magazine upon posting it was ridiculous to tell them they would have to modify the html code to conform with ezpublish xml format and upload each image needed for the article into the ezpublish system it would not have gone down well. So I made a quick hack for the XMLTextField that I think is quite good.... it ensures that html after submission will conform to the ezpublish xml format, but that important tags such as font and img will be kept, albeit as <custom name=$htmlTagName> etc. Inside ezsimplifiedxmlinput.php in the method validateInput($http, $base, $contentObjectAttribute) at about line 150 I added this:
function &validateInput( &$http, $base, &$contentObjectAttribute )
{
$contentObjectID = $contentObjectAttribute->attribute( "contentobject_id" );
$contentObjectAttributeID = $contentObjectAttribute->attribute( "id" );
$contentObjectAttributeVersion = $contentObjectAttribute->attribute('version');
if ( $http->hasPostVariable( $base . "_data_text_" . $contentObjectAttributeID ) )
{
$data =& $http->postVariable( $base . "_data_text_" . $contentObjectAttributeID );
/*MYCODE*/
include_once( "lib/ezutils/classes/ezini.php" );
$ini =& eZINI::instance( 'content.ini' );
$customTagList =& $ini->variable( 'CustomTagSettings', 'AvailableCustomTags' );
foreach($customTagList as $customTag) {
//If there is a custom tag with the same name as the input htmt tag
//then copy it to custom form
$pattern = "#<(/)?$customTag?((\s+.*?(\s*=\s*\".*?|.*?))*\s*)?(>|/>)#ie";
$replace = "replaceCustomTags('\\1', '\\2', '\\5', '$customTag')";
$data = preg_replace($pattern, $replace, $data);
$data = stripslashes($data);
}
/*END MYCODE*/
and at the start of that file I added the function (not method):
function replaceCustomTags($one, $two, $five, $tagName) {
//If its an end tag, only replace with the tag name
if($one != '' && $one != null && $one != false) {
return "</custom>";
}
//Its a start tag and we need to include attributes also.
else {
return "<custom name=\"".$tagName."\"".$two."".$five."";
}
}
Now to support a regular html tag is simple... simply add the respective entries to content.ini and the templates. It works for both block and inline tags. The regex appears to work very well although I'm sure someone can find something to mess it up.
[CustomTagSettings]
AvailableCustomTags[]=img
AvailableCustomTags[]=font IsInline[img]=true Now added img.tpl: <img src="{$src}" border="{$border}"/> And font.tpl:
<font color="{$color}" size="{$size}">
{$content} </font> When the raw html is submitted. Any html tags that you have specified inside content.ini[.append] is converted to the correct <custom name="whatever"></custom> Any thoughts?
Regards, Willie
|