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
00035
00036
00037
00038
00039
00040 class eZTOCOperator
00041 {
00042
00043
00044
00045 function eZTOCOperator()
00046 {
00047 }
00048
00049
00050
00051
00052 function operatorList()
00053 {
00054 return array( 'eztoc' );
00055 }
00056
00057
00058
00059
00060
00061 function namedParameterPerOperator()
00062 {
00063 return true;
00064 }
00065
00066
00067
00068
00069 function namedParameterList()
00070 {
00071 return array( 'eztoc' => array( 'dom' => array( 'type' => 'object',
00072 'required' => true,
00073 'default' => 0 ) ) );
00074 }
00075
00076
00077
00078 function modify( &$tpl, &$operatorName, &$operatorParameters, &$rootNamespace, &$currentNamespace, &$operatorValue, &$namedParameters )
00079 {
00080 $dom = $namedParameters['dom'];
00081 if ( get_class( $dom ) == 'ezcontentobjectattribute' )
00082 {
00083 $this->ObjectAttributeId = $dom->attribute( 'id' );
00084 $content = $dom->attribute( 'content' );
00085 $xmlData = $content->attribute( 'xml_data' );
00086
00087 $xml = new eZXML();
00088 $domTree =& $xml->domTree( $xmlData );
00089
00090 $tocText = '';
00091 if ( is_object( $domTree ) )
00092 {
00093 $this->HeaderCounter = array();
00094 $this->LastHeaderLevel = 0;
00095
00096 $rootNode = $domTree->root();
00097 $tocText .= $this->handleSection( $rootNode );
00098
00099 while ( $this->LastHeaderLevel > 0 )
00100 {
00101 $tocText .= "</li>\n</ul>\n";
00102 $this->LastHeaderLevel--;
00103 }
00104 }
00105 }
00106 $operatorValue = $tocText;
00107 }
00108
00109 function handleSection( $sectionNode, $level = 0 )
00110 {
00111
00112 $this->HeaderCounter[$level + 1] = 0;
00113
00114 $tocText = '';
00115 $children =& $sectionNode->Children;
00116 foreach ( array_keys( $children ) as $key )
00117 {
00118 $child =& $children[$key];
00119 if ( $child->nodeName == 'section' )
00120 {
00121 $tocText .= $this->handleSection( $child, $level + 1 );
00122 }
00123
00124 if ( $child->nodeName == 'header' )
00125 {
00126 if ( $level > $this->LastHeaderLevel )
00127 {
00128 while ( $level > $this->LastHeaderLevel )
00129 {
00130 $tocText .= "\n<ul><li>";
00131 $this->LastHeaderLevel++;
00132 }
00133 }
00134 elseif ( $level == $this->LastHeaderLevel )
00135 {
00136 $tocText .= "</li>\n<li>";
00137 }
00138 else
00139 {
00140 $tocText .= "</li>\n";
00141 while ( $level < $this->LastHeaderLevel )
00142 {
00143 $tocText .= "</ul></li>\n";
00144 $this->LastHeaderLevel--;
00145 }
00146 $tocText .= "<li>";
00147 }
00148 $this->LastHeaderLevel = $level;
00149
00150 $this->HeaderCounter[$level] += 1;
00151 $i = 1;
00152 $headerAutoName = "";
00153 while ( $i <= $level )
00154 {
00155 if ( $i > 1 )
00156 $headerAutoName .= "_";
00157
00158 $headerAutoName .= $this->HeaderCounter[$i];
00159 $i++;
00160 }
00161 $tocText .= '<a href="#eztoc' . $this->ObjectAttributeId . '_' . $headerAutoName . '">' . $child->textContent() . '</a>';
00162 }
00163 }
00164
00165 return $tocText;
00166 }
00167
00168 var $HeaderCounter = array();
00169 var $LastHeaderLevel = 0;
00170
00171 var $ObjectAttributeId;
00172 }
00173
00174 ?>