Passed
Push — develop ( 09225f...2749c8 )
by Dylan
02:47
created
code/controllers/AutomatedLinkReportTask.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -151,19 +151,19 @@
 block discarded – undo
151 151
 
152 152
         if (!$content) return false;
153 153
 
154
-        if( class_exists( 'HTML5_Parser' ) ){
155
-            $html5 = HTML5_Parser::parse( $content );
156
-            if($html5 instanceof DOMNodeList){
154
+        if (class_exists('HTML5_Parser')) {
155
+            $html5 = HTML5_Parser::parse($content);
156
+            if ($html5 instanceof DOMNodeList) {
157 157
                 $dom = new DOMDocument();
158
-                while($html5->length > 0) {
158
+                while ($html5->length > 0) {
159 159
                     $dom->appendChild($html5->item(0));
160 160
                 }
161
-            }else{
161
+            }else {
162 162
                 $dom = $html5;
163 163
             }
164
-        } else{
164
+        }else {
165 165
             $dom = new DOMDocument();
166
-            $dom->loadHTML( $content );
166
+            $dom->loadHTML($content);
167 167
         }
168 168
 
169 169
         return $dom;
Please login to merge, or discard this patch.
code/extenstions/SEOToolboxControllerExtension.php 1 patch
Spacing   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -18,12 +18,12 @@  discard block
 block discarded – undo
18 18
     private $excludeTags    = array();
19 19
     private $maxLinks       = 0;
20 20
 
21
-    public function index(){
21
+    public function index() {
22 22
         $this->addAutomatedLinks();
23 23
 
24 24
         // If we have a crawl request check the CrawlID so we're sure we didn't hit another SS site running our module
25
-        if( $crawl_id = $this->owner->request->getHeader('X-Crawl-Id') ){
26
-            return( $crawl_id == GlobalAutoLinkSettings::get_current()->CrawlID )
25
+        if ($crawl_id = $this->owner->request->getHeader('X-Crawl-Id')) {
26
+            return($crawl_id == GlobalAutoLinkSettings::get_current()->CrawlID)
27 27
                 ? $this->crawl_response()
28 28
                 : $this->owner->redirect(SEOTestSiteTreeController::getPermissionDeniedPage()->Link());
29 29
         }
@@ -31,15 +31,15 @@  discard block
 block discarded – undo
31 31
         return array();
32 32
     }
33 33
 
34
-    private function crawl_response(){
34
+    private function crawl_response() {
35 35
         // Encoded version to detect which fields are being used
36 36
         $customize = array();
37 37
         $dbFields  = Config::inst()->get($this->owner->ClassName, 'db');
38
-        if(is_array($dbFields)) {
39
-            foreach ( $dbFields as $field => $type) {
38
+        if (is_array($dbFields)) {
39
+            foreach ($dbFields as $field => $type) {
40 40
                 if (strtolower($type) == 'htmltext') {
41 41
                     $data = ($this->owner->hasMethod($field)) ? $this->owner->$field() : $this->owner->$field;
42
-                    if($data){
42
+                    if ($data) {
43 43
                         $tmp = new HTMLText('tmp');
44 44
                         $tmp->setValue($data);
45 45
                         $data = base64_encode($tmp->forTemplate());
@@ -90,45 +90,45 @@  discard block
 block discarded – undo
90 90
      *
91 91
      * @return void
92 92
      */
93
-    public function addAutomatedLinks(){
94
-        if( GlobalAutoLinkSettings::$enabled && $this->owner->class != 'RedirectorPage' ) {
93
+    public function addAutomatedLinks() {
94
+        if (GlobalAutoLinkSettings::$enabled && $this->owner->class != 'RedirectorPage') {
95 95
             $this->getSettings();
96
-            if( !$this->addLinks ) {
96
+            if (!$this->addLinks) {
97 97
                 return;
98 98
             }
99 99
 
100
-            foreach( $this->getSettings()->IncludeInFields() as $field ){
100
+            foreach ($this->getSettings()->IncludeInFields() as $field) {
101 101
                 // Check that the field provided by user exists in this object, is of type HTMLText and has content
102
-                if( AutomatedLink::isFieldParsable( $this->owner->data(), $field ) ){
102
+                if (AutomatedLink::isFieldParsable($this->owner->data(), $field)) {
103 103
 
104 104
                     // Create dummy object so we can parse the HTML
105
-                    $dummy = new HTMLText( $field );
106
-                    $dummy->setValue( $this->owner->$field );
105
+                    $dummy = new HTMLText($field);
106
+                    $dummy->setValue($this->owner->$field);
107 107
                     // Create DOMDocument Object
108
-                    $content = mb_convert_encoding( $dummy->forTemplate(), 'html-entities', GlobalAutoLinkSettings::$encoding );
108
+                    $content = mb_convert_encoding($dummy->forTemplate(), 'html-entities', GlobalAutoLinkSettings::$encoding);
109 109
 
110
-                    if( class_exists( 'HTML5_Parser' ) ){
111
-                        $html5 = HTML5_Parser::parse( $content );
112
-                        if($html5 instanceof DOMNodeList){
110
+                    if (class_exists('HTML5_Parser')) {
111
+                        $html5 = HTML5_Parser::parse($content);
112
+                        if ($html5 instanceof DOMNodeList) {
113 113
                             $dom = new DOMDocument();
114
-                            while($html5->length > 0) {
114
+                            while ($html5->length > 0) {
115 115
                                 $dom->appendChild($html5->item(0));
116 116
                             }
117
-                        }else{
117
+                        }else {
118 118
                             $dom = $html5;
119 119
                         }
120
-                    } else{
120
+                    }else {
121 121
                         $dom = new DOMDocument();
122
-                        $dom->loadHTML( $content );
122
+                        $dom->loadHTML($content);
123 123
                     }
124 124
 
125 125
                     // Check current link count and if it's already exceeded do nothing
126
-                    $this->linkCount += (int) $dom->getElementsByTagName( 'a' )->length;
127
-                    if( $this->linkCount >= $this->maxLinks ) {
126
+                    $this->linkCount += (int) $dom->getElementsByTagName('a')->length;
127
+                    if ($this->linkCount >= $this->maxLinks) {
128 128
                         return;
129 129
                     }
130 130
 
131
-                    $parsed = $this->parseField( $dom, $field );
131
+                    $parsed = $this->parseField($dom, $field);
132 132
                     $this->owner->data()->$field = $parsed;
133 133
                     $this->owner->$field         = $parsed;
134 134
                 }
@@ -143,71 +143,71 @@  discard block
 block discarded – undo
143 143
      * @param String $field
144 144
      * @return string
145 145
      */
146
-    private function parseField( DOMDocument $html, $field ){
147
-        $this->owner->extend( 'beforeParseField', $html, $field );
146
+    private function parseField(DOMDocument $html, $field) {
147
+        $this->owner->extend('beforeParseField', $html, $field);
148 148
 
149 149
         // Remove Tags from Content we wown't be using
150 150
         $excluded = array();
151
-        foreach( $this->excludeTags as $eTag ){
152
-            while( $tags = $html->getElementsByTagName( $eTag ) ){
153
-                if( !$tags->length ) break 1;
154
-                $tag	= $tags->item(0);
155
-                $value  = $html->saveHTML( $tag );
156
-                $key    = (string) crc32( $value );
151
+        foreach ($this->excludeTags as $eTag) {
152
+            while ($tags = $html->getElementsByTagName($eTag)) {
153
+                if (!$tags->length) break 1;
154
+                $tag = $tags->item(0);
155
+                $value  = $html->saveHTML($tag);
156
+                $key    = (string) crc32($value);
157 157
 
158 158
                 // Convert back children nodes of this node if they were already hashed
159
-                $excluded[$key] = str_replace( array_keys( $excluded ), array_values( $excluded ), $value );
159
+                $excluded[$key] = str_replace(array_keys($excluded), array_values($excluded), $value);
160 160
 
161
-                $tag->parentNode->replaceChild( $html->createTextNode( $key ), $tag );
161
+                $tag->parentNode->replaceChild($html->createTextNode($key), $tag);
162 162
             }
163 163
         }
164 164
 
165
-        $body    = (string)$html->saveHTML( $html->getElementsByTagName('body')->item(0) );
166
-        $content = preg_replace( array( '/\<body\>/is', '/\<\/body\>/is' ), '', $body, 1 );
165
+        $body    = (string) $html->saveHTML($html->getElementsByTagName('body')->item(0));
166
+        $content = preg_replace(array('/\<body\>/is', '/\<\/body\>/is'), '', $body, 1);
167 167
 
168 168
         // Create the links
169 169
         $links = AutomatedLink::get()->sort('Priority');
170
-        foreach( $links as $link ){
170
+        foreach ($links as $link) {
171 171
             // Check if self-linking is allowed and if current pagetype is allowed
172
-            if( !$link->canBeAdded( $this->owner, $field ) ) continue;
172
+            if (!$link->canBeAdded($this->owner, $field)) continue;
173 173
 
174
-            $max    = (int) ( $link->MaxLinksPerPage > 0 ) ? $link->MaxLinksPerPage : PHP_INT_MAX;
175
-            $escape = (string) preg_quote( $link->Phrase, '/' );
176
-            $regex  = (string) ( $link->CaseSensitive ) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i";
174
+            $max    = (int) ($link->MaxLinksPerPage > 0) ? $link->MaxLinksPerPage : PHP_INT_MAX;
175
+            $escape = (string) preg_quote($link->Phrase, '/');
176
+            $regex  = (string) ($link->CaseSensitive) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i";
177 177
 
178 178
             // Count the matches
179
-            preg_match_all( $regex, $content, $count );
180
-            $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0;
181
-            if( $count < 1 ) continue;
179
+            preg_match_all($regex, $content, $count);
180
+            $count = (is_array($count) && isset($count[0])) ? count($count[0]) : 0;
181
+            if ($count < 1) continue;
182 182
 
183
-            if( isset( $this->maxLinksPerPage[ $link->ID ] ) )
184
-                $max -= $this->maxLinksPerPage[ $link->ID ];
183
+            if (isset($this->maxLinksPerPage[$link->ID]))
184
+                $max -= $this->maxLinksPerPage[$link->ID];
185 185
             else
186
-                $this->maxLinksPerPage[ $link->ID ] = 0;
186
+                $this->maxLinksPerPage[$link->ID] = 0;
187 187
 
188
-            for( $x = 0; $x < $count; $x++ ){
188
+            for ($x = 0; $x < $count; $x++) {
189 189
                 // Stop adding links if we reached the link or page limit
190
-                if( $x >= $max || $this->linkCount >= $this->maxLinks ) break;
190
+                if ($x >= $max || $this->linkCount >= $this->maxLinks) break;
191 191
 
192 192
                 // Check if there is anything else to replace else stop
193
-                preg_match( $regex, $content, $match );
194
-                if( !is_array( $match ) || !count( $match ) ) break;
193
+                preg_match($regex, $content, $match);
194
+                if (!is_array($match) || !count($match)) break;
195 195
 
196
-                if( !$html = (string) $link->getHTML( $match[0] ) ) continue;
197
-                $key              = (string) crc32( $html );
198
-                $excluded[ $key ] = (string) $html;
196
+                if (!$html = (string) $link->getHTML($match[0])) continue;
197
+                $key              = (string) crc32($html);
198
+                $excluded[$key] = (string) $html;
199 199
 
200
-                $content = preg_replace( $regex, $key, $content, 1 );
200
+                $content = preg_replace($regex, $key, $content, 1);
201 201
                 $this->linkCount++;
202
-                $this->maxLinksPerPage[ $link->ID ]++;
202
+                $this->maxLinksPerPage[$link->ID]++;
203 203
             }
204 204
 
205 205
             // Stop Adding links if we reached the page limit
206
-            if( $this->linkCount >= $this->maxLinks ) break;
206
+            if ($this->linkCount >= $this->maxLinks) break;
207 207
         }
208 208
 
209 209
         // Re-add the excluded Tags
210
-        $content = str_replace( array_keys( $excluded ), array_values( $excluded ), $content );
210
+        $content = str_replace(array_keys($excluded), array_values($excluded), $content);
211 211
 
212 212
         return $content;
213 213
     }
Please login to merge, or discard this patch.