00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 include_once( 'kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php' );
00035
00036
00037 class eZXHTMLXMLOutput extends eZXMLOutputHandler
00038 {
00039
00040 var $OutputTags = array(
00041
00042 'section' => array( 'quickRender' => true,
00043 'initHandler' => 'initHandlerSection',
00044 'renderHandler' => 'renderChildrenOnly' ),
00045
00046 'embed' => array( 'initHandler' => 'initHandlerEmbed',
00047 'renderHandler' => 'renderAll',
00048 'attrNamesTemplate' => array( 'class' => 'classification',
00049 'xhtml:id' => 'id',
00050 'object_id' => false,
00051 'node_id' => false,
00052 'show_path' => false ),
00053 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00054
00055 'embed-inline' => array( 'initHandler' => 'initHandlerEmbed',
00056 'renderHandler' => 'renderInline',
00057 'attrNamesTemplate' => array( 'class' => 'classification',
00058 'xhtml:id' => 'id',
00059 'object_id' => false,
00060 'node_id' => false,
00061 'show_path' => false ),
00062 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00063
00064 'table' => array( 'initHandler' => 'initHandlerTable',
00065 'renderHandler' => 'renderAll',
00066 'contentVarName' => 'rows',
00067 'attrNamesTemplate' => array( 'class' => 'classification',
00068 'width' => 'width' ),
00069 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00070
00071 'tr' => array(
00072 'initHandler' => 'initHandlerTr',
00073 'renderHandler' => 'renderAll',
00074 'attrNamesTemplate' => array( 'class' => 'classification' ),
00075 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00076
00077 'td' => array( 'initHandler' => 'initHandlerTd',
00078 'renderHandler' => 'renderAll',
00079 'attrNamesTemplate' => array( 'xhtml:width' => 'width',
00080 'xhtml:colspan' => 'colspan',
00081 'xhtml:rowspan' => 'rowspan',
00082 'class' => 'classification' ),
00083 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00084
00085 'th' => array( 'initHandler' => 'initHandlerTd',
00086 'renderHandler' => 'renderAll',
00087 'attrNamesTemplate' => array( 'xhtml:width' => 'width',
00088 'xhtml:colspan' => 'colspan',
00089 'xhtml:rowspan' => 'rowspan',
00090 'class' => 'classification' ),
00091 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00092
00093 'ol' => array( 'renderHandler' => 'renderAll',
00094 'attrNamesTemplate' => array( 'class' => 'classification' ),
00095 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00096
00097 'ul' => array( 'renderHandler' => 'renderAll',
00098 'attrNamesTemplate' => array( 'class' => 'classification' ),
00099 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00100
00101 'li' => array( 'renderHandler' => 'renderAll',
00102 'attrNamesTemplate' => array( 'class' => 'classification' ),
00103 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00104
00105 'header' => array( 'initHandler' => 'initHandlerHeader',
00106 'renderHandler' => 'renderAll',
00107 'attrNamesTemplate' => array( 'class' => 'classification' ),
00108 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00109
00110 'paragraph' => array(
00111 'renderHandler' => 'renderParagraph',
00112 'attrNamesTemplate' => array( 'class' => 'classification' ),
00113 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00114
00115 'line' => array(
00116 'renderHandler' => 'renderLine' ),
00117
00118 'literal' => array( 'renderHandler' => 'renderAll',
00119 'attrNamesTemplate' => array( 'class' => 'classification' ),
00120 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00121
00122 'strong' => array( 'renderHandler' => 'renderInline',
00123 'attrNamesTemplate' => array( 'class' => 'classification' ),
00124 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00125
00126 'emphasize' => array( 'renderHandler' => 'renderInline',
00127 'attrNamesTemplate' => array( 'class' => 'classification' ),
00128 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00129
00130 'link' => array( 'initHandler' => 'initHandlerLink',
00131 'renderHandler' => 'renderInline',
00132 'attrNamesTemplate' => array( 'xhtml:id' => 'id',
00133 'xhtml:title' => 'title',
00134 'url_id' => false,
00135 'object_id' => false,
00136 'node_id' => false,
00137 'show_path' => false,
00138 'ezurl_id' => false,
00139 'anchor_name' => false,
00140 'class' => 'classification' ),
00141 'attrDesignKeys' => array( 'class' => 'classification' ) ),
00142
00143 'anchor' => array( 'renderHandler' => 'renderInline' ),
00144
00145 'custom' => array( 'initHandler' => 'initHandlerCustom',
00146 'renderHandler' => 'renderCustom',
00147 'attrNamesTemplate' => array( 'name' => false ) ),
00148
00149 '#text' => array( 'quickRender' => true,
00150 'renderHandler' => 'renderText' )
00151 );
00152
00153 function eZXHTMLXMLOutput( &$xmlData, $aliasedType, $contentObjectAttribute = null )
00154 {
00155 $this->eZXMLOutputHandler( $xmlData, $aliasedType, $contentObjectAttribute );
00156
00157 $ini =& eZINI::instance('ezxml.ini');
00158 if ( $ini->variable( 'ezxhtml', 'RenderParagraphInTableCells' ) == 'disabled' )
00159 $this->RenderParagraphInTableCells = false;
00160 }
00161
00162 function initHandlerSection( &$element, &$attributes, &$sibilingParams, &$parentParams )
00163 {
00164 $ret = array();
00165 if( !isset( $parentParams['section_level'] ) )
00166 $parentParams['section_level'] = 0;
00167 else
00168 $parentParams['section_level']++;
00169
00170
00171 $level = $parentParams['section_level'];
00172 if ( $level != 0 )
00173 {
00174 if ( !isset( $this->HeaderCount[$level] ) )
00175 $this->HeaderCount[$level] = 0;
00176
00177 $this->HeaderCount[$level + 1] = 0;
00178 }
00179
00180 return $ret;
00181 }
00182
00183 function initHandlerHeader( &$element, &$attributes, &$sibilingParams, &$parentParams )
00184 {
00185 $level = $parentParams['section_level'];
00186 $this->HeaderCount[$level]++;
00187
00188
00189 $i = 1;
00190 $headerAutoName = '';
00191 while ( $i <= $level )
00192 {
00193 if ( $i > 1 )
00194 $headerAutoName .= "_";
00195
00196 $headerAutoName .= $this->HeaderCount[$i];
00197 $i++;
00198 }
00199 $levelNumber = str_replace( "_", ".", $headerAutoName );
00200
00201 if ( $this->ObjectAttributeID )
00202 $headerAutoName = $this->ObjectAttributeID . '_' . $headerAutoName;
00203
00204 $ret = array( 'tpl_vars' => array( 'level' => $level,
00205 'header_number' => $levelNumber,
00206 'toc_anchor_name' => $headerAutoName ) );
00207
00208 return $ret;
00209 }
00210
00211 function initHandlerLink( &$element, &$attributes, &$sibilingParams, &$parentParams )
00212 {
00213 $ret = array();
00214
00215
00216 $href='';
00217 if ( $element->getAttribute( 'url_id' ) != null )
00218 {
00219 $linkID = $element->getAttribute( 'url_id' );
00220 $href = $this->LinkArray[$linkID];
00221 }
00222 elseif ( $element->getAttribute( 'node_id' ) != null )
00223 {
00224 $nodeID = $element->getAttribute( 'node_id' );
00225 $node =& $this->NodeArray[$nodeID];
00226
00227 if ( $node != null )
00228 {
00229 $view = $element->getAttribute( 'view' );
00230 if ( $view )
00231 $href = 'content/view/' . $view . '/' . $nodeID;
00232 else
00233 $href = $node->attribute( 'url_alias' );
00234 }
00235 else
00236 eZDebug::writeWarning( "Node #$nodeID doesn't exist", "XML output handler: link" );
00237 }
00238 elseif ( $element->getAttribute( 'object_id' ) != null )
00239 {
00240 $objectID = $element->getAttribute( 'object_id' );
00241 $object =& $this->ObjectArray["$objectID"];
00242 if ( $object )
00243 {
00244 $node =& $object->attribute( 'main_node' );
00245 if ( $node )
00246 {
00247 $nodeID = $node->attribute( 'node_id' );
00248
00249 $view = $element->getAttribute( 'view' );
00250 if ( $view )
00251 $href = 'content/view/' . $view . '/' . $nodeID;
00252 else
00253 $href = $node->attribute( 'url_alias' );
00254 }
00255 else
00256 eZDebug::writeWarning( "Object #$objectID doesn't have assigned nodes", "XML output handler: link" );
00257 }
00258 else
00259 {
00260 eZDebug::writeWarning( "Object #$objectID doesn't exist", "XML output handler: link" );
00261 }
00262 }
00263 elseif ( $element->getAttribute( 'href' ) != null )
00264 {
00265 $href = $element->getAttribute( 'href' );
00266 }
00267
00268 if ( $element->getAttribute( 'anchor_name' ) != null )
00269 {
00270 $href .= '#' . $element->getAttribute( 'anchor_name' );
00271 }
00272
00273 if ( $href !== false )
00274 {
00275 $attributes['href'] = $href;
00276 $parentParams['link_parameters'] = $attributes;
00277 }
00278
00279 return $ret;
00280 }
00281
00282 function initHandlerEmbed( &$element, &$attributes, &$sibilingParams, &$parentParams )
00283 {
00284
00285 $ret = array( 'no_render' => true );
00286
00287 $tplSuffix = '';
00288 $objectID = $element->getAttribute( 'object_id' );
00289 if ( $objectID )
00290 {
00291 $object =& $this->ObjectArray["$objectID"];
00292 }
00293 else
00294 {
00295 $nodeID = $element->getAttribute( 'node_id' );
00296 if ( $nodeID )
00297 {
00298 if ( isset( $this->NodeArray[$nodeID] ) )
00299 {
00300 $node =& $this->NodeArray[$nodeID];
00301 $objectID = $node->attribute( 'contentobject_id' );
00302 $object =& $node->object();
00303 $tplSuffix = '_node';
00304 }
00305 else
00306 {
00307 eZDebug::writeWarning( "Node #$nodeID doesn't exist", "XML output handler: embed" );
00308 return $ret;
00309 }
00310 }
00311 }
00312
00313 if ( !isset( $object ) || !$object || get_class( $object ) != "ezcontentobject" )
00314 {
00315 eZDebug::writeWarning( "Can't fetch object #$objectID", "XML output handler: embed" );
00316 return $ret;
00317 }
00318 if ( $object->attribute( 'status' ) != EZ_CONTENT_OBJECT_STATUS_PUBLISHED )
00319 {
00320 eZDebug::writeWarning( "Object #$objectID is not published", "XML output handler: embed" );
00321 return $ret;
00322 }
00323
00324 if ( $object->attribute( 'can_read' ) ||
00325 $object->attribute( 'can_view_embed' ) )
00326 {
00327 $templateName = $element->nodeName . $tplSuffix;
00328 }
00329 else
00330 {
00331 $templateName = $element->nodeName . '_denied';
00332 }
00333
00334 $objectParameters = array();
00335 $excludeAttrs = array( 'view', 'class', 'node_id', 'object_id' );
00336
00337 foreach ( array_keys( $attributes ) as $attrName )
00338 {
00339 $value = $attributes[$attrName];
00340 if ( !in_array( $attrName, $excludeAttrs ) )
00341 {
00342 if ( strpos( $attrName, ':' ) !== false )
00343 $attrName = substr( $attrName, strpos( $attrName, ':' ) + 1 );
00344
00345 $objectParameters[$attrName] = $value;
00346 unset( $attributes[$attrName] );
00347 }
00348 }
00349
00350 if ( isset( $parentParams['link_parameters'] ) )
00351 $linkParameters = $parentParams['link_parameters'];
00352 else
00353 $linkParameters = array();
00354
00355 $ret = array( 'template_name' => $templateName,
00356 'tpl_vars' => array( 'object' => $object,
00357 'link_parameters' => $linkParameters,
00358 'object_parameters' => $objectParameters ),
00359 'design_keys' => array( 'class_identifier', $object->attribute( 'class_identifier' ) ) );
00360
00361 if ( $tplSuffix == '_node')
00362 $ret['tpl_vars']['node'] = $node;
00363
00364 return $ret;
00365 }
00366
00367 function initHandlerTable( &$element, &$attributes, &$sibilingParams, &$parentParams )
00368 {
00369
00370 $rows =& $element->children();
00371 $rowCount = count( $rows );
00372 $rowCount--;
00373 $lastRow =& $element->lastChild();
00374 $cols =& $lastRow->children();
00375 $colCount = count( $cols );
00376 if ( $colCount )
00377 $colCount--;
00378
00379 $ret = array( 'tpl_vars' => array( 'col_count' => $colCount,
00380 'row_count' => $rowCount ) );
00381 return $ret;
00382 }
00383
00384 function initHandlerTr( &$element, &$attributes, &$sibilingParams, &$parentParams )
00385 {
00386 $ret = array();
00387 if( !isset( $sibilingParams['table_row_count'] ) )
00388 $sibilingParams['table_row_count'] = 0;
00389 else
00390 $sibilingParams['table_row_count']++;
00391
00392 $parentParams['table_row_count'] = $sibilingParams['table_row_count'];
00393
00394
00395 $cols =& $element->children();
00396 $colCount = count( $cols );
00397 if ( $colCount )
00398 $colCount--;
00399
00400 $ret = array( 'tpl_vars' => array( 'row_count' => $parentParams['table_row_count'],
00401 'col_count' => $colCount ) );
00402 return $ret;
00403 }
00404
00405 function initHandlerTd( &$element, &$attributes, &$sibilingParams, &$parentParams )
00406 {
00407 if( !isset( $sibilingParams['table_col_count'] ) )
00408 $sibilingParams['table_col_count'] = 0;
00409 else
00410 $sibilingParams['table_col_count']++;
00411
00412 $ret = array( 'tpl_vars' => array( 'col_count' => $sibilingParams['table_col_count'],
00413 'row_count' => $parentParams['table_row_count'] ) );
00414 return $ret;
00415 }
00416
00417 function initHandlerCustom( &$element, &$attributes, &$sibilingParams, &$parentParams )
00418 {
00419 $ret = array( 'template_name' => $attributes['name'] );
00420 return $ret;
00421 }
00422
00423
00424
00425 function renderParagraph( &$element, $childrenOutput, $vars )
00426 {
00427
00428 $parent =& $element->parentNode;
00429
00430 if ( ( $parent->nodeName == 'li' && count( $parent->Children ) == 1 ) ||
00431 ( $parent->nodeName == 'td' && count( $parent->Children ) == 1 && !$this->RenderParagraphInTableCells ) )
00432 {
00433 return $childrenOutput;
00434 }
00435
00436
00437 $tagText = '';
00438 $lastTagInline = null;
00439 $inlineContent = '';
00440 foreach( $childrenOutput as $key=>$childOutput )
00441 {
00442 if ( $childOutput[0] === true )
00443 $inlineContent .= $childOutput[1];
00444
00445 if ( ( $childOutput[0] === false && $lastTagInline === true ) ||
00446 ( $childOutput[0] === true && !array_key_exists( $key + 1, $childrenOutput ) ) )
00447 {
00448 $tagText .= $this->renderTag( $element, $inlineContent, $vars );
00449 $inlineContent = '';
00450 }
00451
00452 if ( $childOutput[0] === false )
00453 $tagText .= $childOutput[1];
00454
00455 $lastTagInline = $childOutput[0];
00456 }
00457 return array( false, $tagText );
00458 }
00459
00460 function renderInline( &$element, $childrenOutput, $vars )
00461 {
00462 $renderedArray = array();
00463 $lastTagInline = null;
00464 $inlineContent = '';
00465
00466 foreach( $childrenOutput as $key=>$childOutput )
00467 {
00468 if ( $childOutput[0] === true )
00469 $inlineContent .= $childOutput[1];
00470
00471
00472 if ( ( $childOutput[0] === false && $lastTagInline === true ) ||
00473 ( $childOutput[0] === true && !array_key_exists( $key + 1, $childrenOutput ) ) )
00474 {
00475 $tagText = $this->renderTag( $element, $inlineContent, $vars );
00476 $renderedArray[] = array( true, $tagText );
00477 $inlineContent = '';
00478 }
00479
00480 if ( $childOutput[0] === false )
00481 $renderedArray[] = array( false, $childOutput[1] );
00482
00483 $lastTagInline = $childOutput[0];
00484
00485 }
00486 return $renderedArray;
00487 }
00488
00489 function renderLine( &$element, $childrenOutput, $vars )
00490 {
00491 $renderedArray = array();
00492 $lastTagInline = null;
00493 $inlineContent = '';
00494
00495 foreach( $childrenOutput as $key=>$childOutput )
00496 {
00497 if ( $childOutput[0] === true )
00498 $inlineContent .= $childOutput[1];
00499
00500
00501
00502
00503 if ( $childOutput[0] === false && $lastTagInline === true )
00504 {
00505 $renderedArray[] = array( true, $inlineContent );
00506 $inlineContent = '';
00507 }
00508 elseif ( $childOutput[0] === true && !array_key_exists( $key + 1, $childrenOutput ) )
00509 {
00510 $next =& $element->nextSibling();
00511 if ( $next && $next->nodeName == 'line' )
00512 {
00513 $tagText = $this->renderTag( $element, $inlineContent, $vars );
00514 $renderedArray[] = array( true, $tagText );
00515 }
00516 else
00517 $renderedArray[] = array( true, $inlineContent );
00518 }
00519
00520 if ( $childOutput[0] === false )
00521 $renderedArray[] = array( false, $childOutput[1] );
00522
00523 $lastTagInline = $childOutput[0];
00524 }
00525 return $renderedArray;
00526 }
00527
00528 function renderCustom( &$element, $childrenOutput, $vars )
00529 {
00530 if ( $this->XMLSchema->isInline( $element ) )
00531 {
00532 $ret = $this->renderInline( $element, $childrenOutput, $vars );
00533 }
00534 else
00535 {
00536 $ret = $this->renderAll( $element, $childrenOutput, $vars );
00537 }
00538 return $ret;
00539 }
00540
00541 function renderChildrenOnly( &$element, $childrenOutput, $vars )
00542 {
00543 $tagText = '';
00544 foreach( $childrenOutput as $childOutput )
00545 {
00546 $tagText .= $childOutput[1];
00547 }
00548
00549 return array( false, $tagText );
00550 }
00551
00552 function renderText( &$element, $childrenOutput, $vars )
00553 {
00554 if ( $element->parentNode->nodeName != 'literal' )
00555 {
00556 $text = htmlspecialchars( $element->Content );
00557
00558 $text = preg_replace( "#[\n]+#", "", $text );
00559
00560 if ( $this->AllowMultipleSpaces )
00561 $text = preg_replace( "# #", " ", $text );
00562 else
00563 $text = preg_replace( "# +#", " ", $text );
00564
00565 if ( $this->AllowNumericEntities )
00566 $text = preg_replace( '/&#([0-9]+);/', '&#\1;', $text );
00567 }
00568 else
00569 {
00570 $text = $element->Content;
00571 }
00572
00573 return array( true, $text );
00574 }
00575
00576
00577
00578 var $LinkParameters = array();
00579
00580 var $HeaderCount = array();
00581
00582 var $RenderParagraphInTableCells = true;
00583 }
00584
00585 ?>