[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/classes/datatypes/ezxmltext/handlers/output/ -> ezxhtmlxmloutput.php (source)

   1  <?php
   2  //
   3  // Definition of eZXHTMLXMLOutput class
   4  //
   5  // Created on: <18-Aug-2006 15:05:00 ks>
   6  //
   7  // SOFTWARE NAME: eZ publish
   8  // SOFTWARE RELEASE: 3.9.0
   9  // BUILD VERSION: 17785
  10  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
  11  // SOFTWARE LICENSE: GNU General Public License v2.0
  12  // NOTICE: >
  13  //   This program is free software; you can redistribute it and/or
  14  //   modify it under the terms of version 2.0  of the GNU General
  15  //   Public License as published by the Free Software Foundation.
  16  //
  17  //   This program is distributed in the hope that it will be useful,
  18  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  19  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20  //   GNU General Public License for more details.
  21  //
  22  //   You should have received a copy of version 2.0 of the GNU General
  23  //   Public License along with this program; if not, write to the Free
  24  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  25  //   MA 02110-1301, USA.
  26  //
  27  //
  28  
  29  /*!
  30  */
  31  
  32  include_once ( 'kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php' );
  33  //include_once( 'lib/eztemplate/classes/eztemplateincludefunction.php' );
  34  
  35  class eZXHTMLXMLOutput extends eZXMLOutputHandler
  36  {
  37  
  38      var $OutputTags = array(
  39  
  40      'section'      => array( 'quickRender' => true,
  41                               'initHandler' => 'initHandlerSection',
  42                               'renderHandler' => 'renderChildrenOnly' ),
  43  
  44      'embed'        => array( 'initHandler' => 'initHandlerEmbed',
  45                               'renderHandler' => 'renderAll',
  46                               'attrNamesTemplate' => array( 'class' => 'classification',
  47                                                             'xhtml:id' => 'id',
  48                                                             'object_id' => false,
  49                                                             'node_id' => false,
  50                                                             'show_path' => false ),
  51                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
  52  
  53      'embed-inline' => array( 'initHandler' => 'initHandlerEmbed',
  54                               'renderHandler' => 'renderInline',
  55                               'attrNamesTemplate' => array( 'class' => 'classification',
  56                                                             'xhtml:id' => 'id',
  57                                                             'object_id' => false,
  58                                                             'node_id' => false,
  59                                                             'show_path' => false ),
  60                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
  61  
  62      'table'        => array( 'renderHandler' => 'renderAll',
  63                               'contentVarName' => 'rows',
  64                               'attrNamesTemplate' => array( 'class' => 'classification' ),
  65                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
  66  
  67      'tr'           => array( //'quickRender' => array( 'tr', "\n" ),
  68                               'initHandler' => 'initHandlerTr',
  69                               'renderHandler' => 'renderAll',
  70                               'attrNamesTemplate' => array( 'class' => 'classification' ),
  71                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
  72  
  73      'td'           => array( 'initHandler' => 'initHandlerTd',
  74                               'renderHandler' => 'renderAll',
  75                               'attrNamesTemplate' => array( 'xhtml:width' => 'width',
  76                                                             'xhtml:colspan' => 'colspan',
  77                                                             'xhtml:rowspan' => 'rowspan',
  78                                                             'class' => 'classification' ),
  79                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
  80  
  81      'th'           => array( 'initHandler' => 'initHandlerTd',
  82                               'renderHandler' => 'renderAll',
  83                               'attrNamesTemplate' => array( 'xhtml:width' => 'width',
  84                                                             'xhtml:colspan' => 'colspan',
  85                                                             'xhtml:rowspan' => 'rowspan',
  86                                                             'class' => 'classification' ),
  87                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
  88  
  89      'ol'           => array( 'renderHandler' => 'renderAll',
  90                               'attrNamesTemplate' => array( 'class' => 'classification' ),
  91                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
  92  
  93      'ul'           => array( 'renderHandler' => 'renderAll',
  94                               'attrNamesTemplate' => array( 'class' => 'classification' ),
  95                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
  96  
  97      'li'           => array( 'renderHandler' => 'renderAll',
  98                               'attrNamesTemplate' => array( 'class' => 'classification' ),
  99                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
 100  
 101      'header'       => array( 'initHandler' => 'initHandlerHeader',
 102                               'renderHandler' => 'renderAll',
 103                               'attrNamesTemplate' => array( 'class' => 'classification' ),
 104                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
 105  
 106      'paragraph'    => array( //'quickRender' => array( 'p', "\n" ),
 107                               'renderHandler' => 'renderParagraph',
 108                               'attrNamesTemplate' => array( 'class' => 'classification' ),
 109                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
 110  
 111      'line'         => array( //'quickRender' => array( '', "<br/>" ),
 112                               'renderHandler' => 'renderLine' ),
 113  
 114      'literal'      => array( 'renderHandler' => 'renderAll',
 115                               'attrNamesTemplate' => array( 'class' => 'classification' ),
 116                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
 117  
 118      'strong'       => array( 'renderHandler' => 'renderInline',
 119                               'attrNamesTemplate' => array( 'class' => 'classification' ),
 120                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
 121  
 122      'emphasize'    => array( 'renderHandler' => 'renderInline',
 123                               'attrNamesTemplate' => array( 'class' => 'classification' ),
 124                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
 125  
 126      'link'         => array( 'initHandler' => 'initHandlerLink',
 127                               'renderHandler' => 'renderInline',
 128                               'attrNamesTemplate' => array( 'xhtml:id' => 'id',
 129                                                             'xhtml:title' => 'title',
 130                                                             'url_id' => false,
 131                                                             'object_id' => false,
 132                                                             'node_id' => false,
 133                                                             'show_path' => false,
 134                                                             'ezurl_id' => false,
 135                                                             'anchor_name' => false,
 136                                                             'class' => 'classification' ),
 137                               'attrDesignKeys' => array( 'class' => 'classification' ) ),
 138  
 139      'anchor'       => array( 'renderHandler' => 'renderInline' ),
 140  
 141      'custom'       => array( 'initHandler' => 'initHandlerCustom',
 142                               'renderHandler' => 'renderCustom',
 143                               'attrNamesTemplate' => array( 'name' => false ) ),
 144  
 145      '#text'        => array( 'quickRender' => true,
 146                               'renderHandler' => 'renderText' )
 147      );
 148  
 149      function eZXHTMLXMLOutput( &$xmlData, $aliasedType, $contentObjectAttribute = null )
 150      {
 151          $this->eZXMLOutputHandler( $xmlData, $aliasedType, $contentObjectAttribute );
 152  
 153          $ini =& eZINI::instance('ezxml.ini');
 154          if ( $ini->variable( 'ezxhtml', 'RenderParagraphInTableCells' ) == 'disabled' )
 155              $this->RenderParagraphInTableCells = false;
 156      }
 157  
 158      function initHandlerSection( &$element, &$attributes, &$sibilingParams, &$parentParams )
 159      {
 160          $ret = array();
 161          if( !isset( $parentParams['section_level'] ) )
 162              $parentParams['section_level'] = 0;
 163          else
 164              $parentParams['section_level']++;
 165  
 166          // init header counter for current level and resert it for the next level
 167          $level = $parentParams['section_level'];
 168          if ( $level != 0 )
 169          {
 170              if ( !isset( $this->HeaderCount[$level] ) )
 171                  $this->HeaderCount[$level] = 0;
 172  
 173              $this->HeaderCount[$level + 1] = 0;
 174          }
 175  
 176          return $ret;
 177      }
 178  
 179      function initHandlerHeader( &$element, &$attributes, &$sibilingParams, &$parentParams )
 180      {
 181          $level = $parentParams['section_level'];
 182          $this->HeaderCount[$level]++;
 183  
 184          // headers auto-numbering
 185          $i = 1;
 186          $headerAutoName = '';
 187          while ( $i <= $level )
 188          {
 189              if ( $i > 1 )
 190                  $headerAutoName .= "_";
 191              
 192              $headerAutoName .= $this->HeaderCount[$i];
 193              $i++;
 194          }
 195          $levelNumber = str_replace( "_", ".", $headerAutoName );
 196  
 197          if ( $this->ObjectAttributeID )
 198              $headerAutoName = $this->ObjectAttributeID . '_' . $headerAutoName;
 199  
 200          $ret = array( 'tpl_vars' => array( 'level' => $level,
 201                                             'header_number' => $levelNumber,
 202                                             'toc_anchor_name' => $headerAutoName ) );
 203  
 204          return $ret;
 205      }
 206  
 207      function initHandlerLink( &$element, &$attributes, &$sibilingParams, &$parentParams )
 208      {
 209          $ret = array();
 210  
 211          // Set link parameters for rendering children of link tag
 212          $href='';
 213          if ( $element->getAttribute( 'url_id' ) != null )
 214          {
 215              $linkID = $element->getAttribute( 'url_id' );
 216              $href = $this->LinkArray[$linkID];
 217          }
 218          elseif ( $element->getAttribute( 'node_id' ) != null )
 219          {
 220              $nodeID = $element->getAttribute( 'node_id' );
 221              $node =& $this->NodeArray[$nodeID];
 222  
 223              if ( $node != null )
 224              {
 225                  $view = $element->getAttribute( 'view' );
 226                  if ( $view )
 227                      $href = 'content/view/' . $view . '/' . $nodeID;
 228                  else
 229                      $href = $node->attribute( 'url_alias' );
 230              }
 231              else
 232                  eZDebug::writeWarning( "Node #$nodeID doesn't exist", "XML output handler: link" );
 233          }
 234          elseif ( $element->getAttribute( 'object_id' ) != null )
 235          {
 236              $objectID = $element->getAttribute( 'object_id' );
 237              $object =& $this->ObjectArray["$objectID"];
 238              if ( $object )
 239              {
 240                  $node =& $object->attribute( 'main_node' );
 241                  $nodeID = $node->attribute( 'node_id' );
 242                  if ( $node )
 243                  {
 244                      $view = $element->getAttribute( 'view' );
 245                      if ( $view )
 246                          $href = 'content/view/' . $view . '/' . $nodeID;
 247                      else
 248                          $href = $node->attribute( 'url_alias' );
 249                  }
 250                  else
 251                      $href = 'content/view/full/' . $nodeID;
 252              }
 253              else
 254              {
 255                  eZDebug::writeWarning( "Object #$objectID doesn't exist", "XML output handler: link" );
 256              }
 257          }
 258          elseif ( $element->getAttribute( 'href' ) != null )
 259          {
 260              $href = $element->getAttribute( 'href' );
 261          }
 262  
 263          if ( $element->getAttribute( 'anchor_name' ) != null )
 264          {
 265              $href .= '#' . $element->getAttribute( 'anchor_name' );
 266          }
 267  
 268          if ( $href !== false )
 269          {
 270              $attributes['href'] = $href;
 271              $parentParams['link_parameters'] = $attributes;
 272          }
 273  
 274          return $ret;
 275      }
 276  
 277      function initHandlerEmbed( &$element, &$attributes, &$sibilingParams, &$parentParams )
 278      {
 279      // default return value in case of errors
 280          $ret = array( 'no_render' => true );
 281  
 282          $objectID = $element->getAttribute( 'object_id' );
 283          if ( $objectID )
 284          {
 285              $object =& $this->ObjectArray["$objectID"];
 286          }
 287          else
 288          {
 289              $nodeID = $element->getAttribute( 'node_id' );
 290              if ( $nodeID )
 291              {
 292                  if ( isset( $this->NodeArray[$nodeID] ) )
 293                  {
 294                      $node =& $this->NodeArray[$nodeID];
 295                      $objectID = $node->attribute( 'contentobject_id' );
 296                      $object =& $node->object();
 297                  }
 298                  else
 299                  {
 300                      eZDebug::writeWarning( "Node #$nodeID doesn't exist", "XML output handler: embed" );
 301                      return $ret;
 302                  }
 303              }
 304          }
 305  
 306          if ( !isset( $object ) || !$object || get_class( $object ) != "ezcontentobject" )
 307          {
 308              eZDebug::writeWarning( "Can't fetch object #$objectID", "XML output handler: embed" );
 309              return $ret;
 310          }
 311          if ( $object->attribute( 'status' ) != EZ_CONTENT_OBJECT_STATUS_PUBLISHED )
 312          {
 313              eZDebug::writeWarning( "Object #$objectID is not published", "XML output handler: embed" );
 314              return $ret;
 315          }
 316  
 317          if ( $object->attribute( 'can_read' ) ||
 318               $object->attribute( 'can_view_embed' ) )
 319          {
 320              $templateName = $element->nodeName;
 321          }
 322          else
 323          {
 324              $templateName = $element->nodeName . '_denied';
 325          }
 326  
 327          $objectParameters = array();
 328          $excludeAttrs = array( 'view', 'class', 'node_id', 'object_id' );
 329          foreach ( $attributes as $attrName=>$value )
 330          {
 331             if ( !in_array( $attrName, $excludeAttrs ) )
 332             {
 333                 if ( substr( $attrName, 0, 6 ) == 'custom:' )
 334                     $attrName = substr( $attrName, strpos( $attrName, ':' ) + 1 );
 335  
 336                 $objectParameters[$attrName] = $value;
 337             }
 338          }
 339  
 340          if ( isset( $parentParams['link_parameters'] ) )
 341              $linkParameters = $parentParams['link_parameters'];
 342          else
 343              $linkParameters = array();
 344  
 345          $ret = array( 'tpl_vars' => array( 'object' => $object,
 346                                             'template_name' => $templateName,
 347                                             'link_parameters' => $linkParameters,
 348                                             'object_parameters' => $objectParameters ),
 349                        'design_keys' => array( 'class_identifier', $object->attribute( 'class_identifier' ) ) );
 350          return $ret;
 351      }
 352  
 353      function initHandlerTr( &$element, &$attributes, &$sibilingParams, &$parentParams )
 354      {
 355          $ret = array();
 356          if( !isset( $sibilingParams['table_row_count'] ) )
 357              $sibilingParams['table_row_count'] = 0;
 358          else
 359              $sibilingParams['table_row_count']++;
 360  
 361          $parentParams['table_row_count'] = $sibilingParams['table_row_count'];
 362  
 363          return $ret;
 364      }
 365  
 366      function initHandlerTd( &$element, &$attributes, &$sibilingParams, &$parentParams )
 367      {
 368          if( !isset( $sibilingParams['table_col_count'] ) )
 369              $sibilingParams['table_col_count'] = 0;
 370          else
 371              $sibilingParams['table_col_count']++;
 372  
 373          $ret = array( 'tpl_vars' => array( 'col_count' => $sibilingParams['table_col_count'],
 374                                             'row_count' => $parentParams['table_row_count'] ) );
 375          return $ret;
 376      }
 377  
 378      function initHandlerCustom( &$element, &$attributes, &$sibilingParams, &$parentParams )
 379      {
 380          $ret = array( 'template_name' => $attributes['name'] );
 381          return $ret;
 382      }
 383  
 384      // Render handlers
 385  
 386      function renderParagraph( &$element, $childrenOutput, $vars )
 387      {
 388          // don't render if inside 'li' or inside 'td' (by option)
 389          $parent =& $element->parentNode;
 390  
 391          if ( $parent->nodeName == 'li' ||
 392               ( $parent->nodeName == 'td' && !$this->RenderParagraphInTableCells ) )
 393          {
 394              return $childrenOutput;
 395          }
 396  
 397          // break paragraph by block tags
 398          $tagText = '';
 399          $lastTagInline = null;
 400          $inlineContent = '';
 401          foreach( $childrenOutput as $key=>$childOutput )
 402          {
 403              if ( $childOutput[0] === true )
 404                  $inlineContent .= $childOutput[1];
 405  
 406              if ( ( $childOutput[0] === false && $lastTagInline === true ) ||
 407                   ( $childOutput[0] === true && !array_key_exists( $key + 1, $childrenOutput ) ) )
 408              {
 409                  $tagText .= $this->renderTag( $element, $inlineContent, $vars );
 410                  $inlineContent = '';
 411              }
 412  
 413              if ( $childOutput[0] === false )
 414                  $tagText .= $childOutput[1];
 415  
 416              $lastTagInline = $childOutput[0];
 417          }
 418          return array( false, $tagText );
 419      }
 420  
 421      function renderInline( &$element, $childrenOutput, $vars )
 422      {
 423          $renderedArray = array();
 424          $lastTagInline = null;
 425          $inlineContent = '';
 426  
 427          foreach( $childrenOutput as $key=>$childOutput )
 428          {
 429              if ( $childOutput[0] === true )
 430                  $inlineContent .= $childOutput[1];
 431  
 432              // Render only inline parts, block parts just passed to parent
 433              if ( ( $childOutput[0] === false && $lastTagInline === true ) ||
 434                   ( $childOutput[0] === true && !array_key_exists( $key + 1, $childrenOutput ) ) )
 435              {
 436                  $tagText = $this->renderTag( $element, $inlineContent, $vars );
 437                  $renderedArray[] = array( true, $tagText );
 438                  $inlineContent = '';
 439              }
 440  
 441              if ( $childOutput[0] === false )
 442                  $renderedArray[] = array( false, $childOutput[1] );
 443  
 444              $lastTagInline = $childOutput[0];
 445  
 446          }
 447          return $renderedArray;
 448      }
 449  
 450      function renderLine( &$element, $childrenOutput, $vars )
 451      {
 452          $renderedArray = array();
 453          $lastTagInline = null;
 454          $inlineContent = '';
 455  
 456          foreach( $childrenOutput as $key=>$childOutput )
 457          {
 458              if ( $childOutput[0] === true )
 459                  $inlineContent .= $childOutput[1];
 460  
 461              // Render line tag only if the last part of childrenOutput is inline and the next tag
 462              // within the same paragraph is 'line' too.
 463  
 464              if ( $childOutput[0] === false && $lastTagInline === true )
 465              {
 466                  $renderedArray[] = array( true, $inlineContent );
 467                  $inlineContent = '';
 468              }
 469              elseif ( $childOutput[0] === true && !array_key_exists( $key + 1, $childrenOutput ) )
 470              {
 471                  $next =& $element->nextSibling();
 472                  if ( $next && $next->nodeName == 'line' )
 473                  {
 474                      $tagText = $this->renderTag( $element, $inlineContent, $vars );
 475                      $renderedArray[] = array( true, $tagText );
 476                  }
 477                  else
 478                      $renderedArray[] = array( true, $inlineContent );
 479              }
 480  
 481              if ( $childOutput[0] === false )
 482                  $renderedArray[] = array( false, $childOutput[1] );
 483  
 484              $lastTagInline = $childOutput[0];
 485          }
 486          return $renderedArray;
 487      }
 488  
 489      function renderCustom( &$element, $childrenOutput, $vars )
 490      {
 491          if ( $this->XMLSchema->isInline( $element ) )
 492          {
 493              $ret = $this->renderInline( $element, $childrenOutput, $vars );
 494          }
 495          else
 496          {
 497              $ret = $this->renderAll( $element, $childrenOutput, $vars );
 498          }
 499          return $ret;
 500      }
 501  
 502      function renderChildrenOnly( &$element, $childrenOutput, $vars )
 503      {
 504          $tagText = '';
 505          foreach( $childrenOutput as $childOutput )
 506          {
 507              $tagText .= $childOutput[1];
 508          }
 509          
 510          return array( false, $tagText );
 511      }
 512  
 513      function renderText( &$element, $childrenOutput, $vars )
 514      {
 515          if ( $element->parentNode->nodeName != 'literal' )
 516          {
 517              $text = htmlspecialchars( $element->Content );
 518              // Get rid of linebreak and spaces stored in xml file
 519              $text = preg_replace( "#[\n]+#", "", $text );
 520      
 521              if ( $this->AllowMultipleSpaces )
 522                  $text = preg_replace( "#  #", " &nbsp;", $text );
 523              else
 524                  $text = preg_replace( "# +#", " ", $text );
 525  
 526              if ( $this->AllowNumericEntities )
 527                  $text = preg_replace( '/&amp;#([0-9]+);/', '&#\1;', $text );
 528          }
 529          else
 530          {
 531              $text = $element->Content;
 532          }
 533  
 534          return array( true, $text );
 535      }
 536  
 537  
 538      /// Array of parameters for rendering tags that are children of 'link' tag
 539      var $LinkParameters = array();
 540  
 541      var $HeaderCount = array();
 542  
 543      var $RenderParagraphInTableCells = true;
 544  }
 545  
 546  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7