Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztocoperator.php
Go to the documentation of this file.
1 <?php
17 class eZTOCOperator
18 {
22 function operatorList()
23 {
24 return array( 'eztoc' );
25 }
26
31 function namedParameterPerOperator()
32 {
33 return true;
34 }
35
39 function namedParameterList()
40 {
41 return array( 'eztoc' => array( 'dom' => array( 'type' => 'object',
42 'required' => true,
43 'default' => 0 ) ) );
44 }
48 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
49 {
50 $dom = $namedParameters['dom'];
51 if ( $dom instanceof eZContentObjectAttribute )
52 {
53 $this->ObjectAttributeId = $dom->attribute( 'id' );
54 $content = $dom->attribute( 'content' );
55 $xmlData = $content->attribute( 'xml_data' );
56
57 $domTree = new DOMDocument( '1.0', 'utf-8' );
58 $domTree->preserveWhiteSpace = false;
59 $success = $domTree->loadXML( $xmlData );
60
61 $tocText = '';
62 if ( $success )
63 {
64 $this->HeaderCounter = array();
65 $this->LastHeaderLevel = 0;
66
67 $rootNode = $domTree->documentElement;
68 $tocText .= $this->handleSection( $rootNode );
69
70 while ( $this->LastHeaderLevel > 0 )
71 {
72 $tocText .= "</li>\n</ul>\n";
73 $this->LastHeaderLevel--;
74 }
75 }
76 }
77 $operatorValue = $tocText;
78 }
79
80 function handleSection( $sectionNode, $level = 0 )
81 {
82 // Reset next level counter
83 if ( !isset( $this->HeaderCounter[$level + 1] ) )
84 {
85 $this->HeaderCounter[$level + 1] = 0;
86 }
87
88 $tocText = '';
89 $children = $sectionNode->childNodes;
90 foreach ( $children as $child )
91 {
92 if ( $child->nodeName == 'section' )
93 {
94 $tocText .= $this->handleSection( $child, $level + 1 );
95 }
96
97 if ( $child->nodeName == 'header' )
98 {
99 if ( $level > $this->LastHeaderLevel )
100 {
101 while ( $level > $this->LastHeaderLevel )
102 {
103 $tocText .= "\n<ul><li>";
104 $this->LastHeaderLevel++;
105 }
106 }
107 elseif ( $level == $this->LastHeaderLevel )
108 {
109 $tocText .= "</li>\n<li>";
110 }
111 else
112 {
113 $tocText .= "</li>\n";
114 while ( $level < $this->LastHeaderLevel )
115 {
116 $tocText .= "</ul></li>\n";
117 $this->LastHeaderLevel--;
118 }
119 $tocText .= "<li>";
120 }
121 $this->LastHeaderLevel = $level;
122
123 $this->HeaderCounter[$level] += 1;
124 $i = 1;
125 $headerAutoName = "";
126 while ( $i <= $level )
127 {
128 if ( $i > 1 )
129 $headerAutoName .= "_";
130
131 $headerAutoName .= $this->HeaderCounter[$i];
132 $i++;
133 }
134 $tocText .= '<a href="#eztoc' . $this->ObjectAttributeId . '_' . $headerAutoName . '">' . $child->textContent . '</a>';
135 }
136 }
137
138 return $tocText;
139 }
140
141 public $HeaderCounter = array();
142 public $LastHeaderLevel = 0;
143
144 public $ObjectAttributeId;
145 }
146
147 ?>
eZContentObjectAttribute
Encapsulates the data for an object attribute.
Definition: ezcontentobjectattribute.php:20
eZTOCOperator
The class eZTOCOperator does.
Definition: eztocoperator.php:18
eZTOCOperator\$ObjectAttributeId
$ObjectAttributeId
Definition: eztocoperator.php:144
eZTOCOperator\namedParameterPerOperator
namedParameterPerOperator()
Definition: eztocoperator.php:31
eZTOCOperator\namedParameterList
namedParameterList()
Definition: eztocoperator.php:39
eZTOCOperator\$HeaderCounter
$HeaderCounter
Definition: eztocoperator.php:141
eZTOCOperator\$LastHeaderLevel
$LastHeaderLevel
Definition: eztocoperator.php:142
eZTOCOperator\operatorList
operatorList()
Definition: eztocoperator.php:22
eZTOCOperator\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: eztocoperator.php:48
eZTOCOperator\handleSection
handleSection( $sectionNode, $level=0)
Definition: eztocoperator.php:80
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.