@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | { |
64 | 64 | $c = $this->owner; |
65 | 65 | $model = $c->customisedObject ? $c->customisedObject : $c->data(); |
66 | - if (! $model) { |
|
66 | + if (!$model) { |
|
67 | 67 | return null; |
68 | 68 | } |
69 | 69 | |
70 | 70 | $field = $this->_contentField(); |
71 | - if (! $model->hasField($field)) { |
|
71 | + if (!$model->hasField($field)) { |
|
72 | 72 | return null; |
73 | 73 | } |
74 | 74 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | public function getAutotoc() |
89 | 89 | { |
90 | 90 | $tocifier = $this->_getTocifier(); |
91 | - if (! $tocifier) { |
|
91 | + if (!$tocifier) { |
|
92 | 92 | return null; |
93 | 93 | } |
94 | 94 |
@@ -59,6 +59,9 @@ |
||
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | + /** |
|
63 | + * @return string |
|
64 | + */ |
|
62 | 65 | private function _getHtml() |
63 | 66 | { |
64 | 67 | $c = $this->owner; |
@@ -89,7 +89,7 @@ |
||
89 | 89 | |
90 | 90 | $body = $doc->getElementsByTagName('body')->item(0); |
91 | 91 | $this->_html = str_replace(array('<body>', '</body>'), '', |
92 | - $doc->saveHTML($body)); |
|
92 | + $doc->saveHTML($body)); |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | private function _dumpBranch($node, $indent = '') |
@@ -57,28 +57,28 @@ discard block |
||
57 | 57 | } |
58 | 58 | |
59 | 59 | // Consider this node a potential dangling parent |
60 | - $this->_dangling[$level] =& $node; |
|
60 | + $this->_dangling[$level] = & $node; |
|
61 | 61 | |
62 | 62 | return $node; |
63 | 63 | } |
64 | 64 | |
65 | 65 | private function _processDocument($doc) |
66 | 66 | { |
67 | - $this->_tree =& $this->_newNode(self::$prefix, '', 0); |
|
67 | + $this->_tree = & $this->_newNode(self::$prefix, '', 0); |
|
68 | 68 | $n = 1; |
69 | 69 | |
70 | 70 | $xpath = new DOMXPath($doc); |
71 | 71 | foreach ($xpath->query('//h1|//h2|//h3|//h4|//h5|//h6') as $h) { |
72 | 72 | $text = $this->_getPlainText($h); |
73 | 73 | $level = (int) substr($h->tagName, 1); |
74 | - $id = self::$prefix . $n; |
|
74 | + $id = self::$prefix.$n; |
|
75 | 75 | ++$n; |
76 | 76 | |
77 | 77 | // Build the tree |
78 | - $parent =& $this->_getParent($level); |
|
79 | - $node =& $this->_newNode($id, $text, $level); |
|
78 | + $parent = & $this->_getParent($level); |
|
79 | + $node = & $this->_newNode($id, $text, $level); |
|
80 | 80 | isset($parent['children']) or $parent['children'] = array(); |
81 | - $parent['children'][] =& $node; |
|
81 | + $parent['children'][] = & $node; |
|
82 | 82 | |
83 | 83 | // Prepend the anchor |
84 | 84 | $anchor = $doc->createElement('a'); |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | private function _dumpBranch($node, $indent = '') |
96 | 96 | { |
97 | - echo $indent . $node['title'] . "\n"; |
|
97 | + echo $indent.$node['title']."\n"; |
|
98 | 98 | if (isset($node['children'])) { |
99 | 99 | foreach ($node['children'] as &$child) { |
100 | 100 | $this->_dumpBranch($child, "$indent\t"); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | public function process() |
137 | 137 | { |
138 | 138 | // Check if $this->_raw_html is valid |
139 | - if (! is_string($this->_raw_html) || empty($this->_raw_html)) { |
|
139 | + if (!is_string($this->_raw_html) || empty($this->_raw_html)) { |
|
140 | 140 | return false; |
141 | 141 | } |
142 | 142 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | |
148 | 148 | // Parse the HTML into a DOMDocument tree |
149 | 149 | $doc = new DOMDocument(); |
150 | - if (! @$doc->loadHTML($html)) { |
|
150 | + if (!@$doc->loadHTML($html)) { |
|
151 | 151 | return false; |
152 | 152 | } |
153 | 153 |
@@ -18,6 +18,9 @@ discard block |
||
18 | 18 | private $_dangling = array(); |
19 | 19 | |
20 | 20 | |
21 | + /** |
|
22 | + * @param integer $level |
|
23 | + */ |
|
21 | 24 | private function &_getParent($level) |
22 | 25 | { |
23 | 26 | while (--$level >= 0) { |
@@ -42,6 +45,10 @@ discard block |
||
42 | 45 | return $clone->textContent; |
43 | 46 | } |
44 | 47 | |
48 | + /** |
|
49 | + * @param string $id |
|
50 | + * @param integer $level |
|
51 | + */ |
|
45 | 52 | private function &_newNode($id, $text, $level) |
46 | 53 | { |
47 | 54 | $node = array( |
@@ -62,6 +69,9 @@ discard block |
||
62 | 69 | return $node; |
63 | 70 | } |
64 | 71 | |
72 | + /** |
|
73 | + * @param DOMDocument $doc |
|
74 | + */ |
|
65 | 75 | private function _processDocument($doc) |
66 | 76 | { |
67 | 77 | $this->_tree =& $this->_newNode(self::$prefix, '', 0); |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | |
23 | 23 | public function testHtml() |
24 | 24 | { |
25 | - $tocifier = new Tocifier(file_get_contents(__DIR__ . '/test1')); |
|
25 | + $tocifier = new Tocifier(file_get_contents(__DIR__.'/test1')); |
|
26 | 26 | $this->assertEquals($tocifier->getHtml(), ''); |
27 | 27 | $this->assertTrue($tocifier->process()); |
28 | - $this->assertStringEqualsFile(__DIR__ . '/html1', $tocifier->getHtml()); |
|
28 | + $this->assertStringEqualsFile(__DIR__.'/html1', $tocifier->getHtml()); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | public function testTOC() |
32 | 32 | { |
33 | - $tocifier = new Tocifier(file_get_contents(__DIR__ . '/test1')); |
|
33 | + $tocifier = new Tocifier(file_get_contents(__DIR__.'/test1')); |
|
34 | 34 | $this->assertEquals($tocifier->getTOC(), array()); |
35 | 35 | $this->assertTrue($tocifier->process()); |
36 | 36 | $this->assertNotNull($tocifier->getTOC()); |
@@ -38,6 +38,6 @@ discard block |
||
38 | 38 | ob_start(); |
39 | 39 | $tocifier->dumpTOC(); |
40 | 40 | $returned = ob_get_clean(); |
41 | - $this->assertStringEqualsFile(__DIR__ . '/toc1', $returned); |
|
41 | + $this->assertStringEqualsFile(__DIR__.'/toc1', $returned); |
|
42 | 42 | } |
43 | 43 | } |