Passed
Branch master (af9096)
by Dylan
03:47
created
code/dataobjects/AutomatedLinkPageResult.php 1 patch
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,7 +52,9 @@  discard block
 block discarded – undo
52 52
      */
53 53
     public static function add_or_update( SiteTree $page ){
54 54
         $obj = self::get()->find( 'PageID', $page->ID );
55
-        if( !$obj ) $obj = self::create( array( 'PageID' => $page->ID ) );
55
+        if( !$obj ) {
56
+            $obj = self::create( array( 'PageID' => $page->ID ) );
57
+        }
56 58
 
57 59
         $obj->OriginalLinkCount = $page->OriginalLinkCount;
58 60
         $obj->LinksCreatedCount = $page->LinkCount;
@@ -68,6 +70,8 @@  discard block
 block discarded – undo
68 70
      * @return void
69 71
      */
70 72
     public static function remove_old_data(){
71
-        foreach( self::get() as $obj ) if( !SiteTree::get()->byID( $obj->PageID ) ) $obj->delete();
73
+        foreach( self::get() as $obj ) {
74
+            if( !SiteTree::get()->byID( $obj->PageID ) ) $obj->delete();
75
+        }
72 76
     }
73 77
 }
Please login to merge, or discard this patch.
code/dataobjects/GlobalAutoLinkSettings.php 1 patch
Braces   +10 added lines, -5 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
             $obj->CrawlID = $this->createCrawlID();
48 48
             $obj->write();
49 49
             DB::alteration_message("Added default records to $className table","created");
50
-        }else{
50
+        } else{
51 51
             if(!$hasData->CrawlID){
52 52
                 $hasData->CrawlID = $this->createCrawlID();
53 53
                 $hasData->write();
@@ -62,8 +62,9 @@  discard block
 block discarded – undo
62 62
         $alpha = 'abcdefghijklm[)0123456789(]nopqrstuvwxyz';
63 63
         $alpha_len = strlen($alpha);
64 64
 
65
-        while( strlen($ret) < 14)
66
-            $ret .= ( rand(0,1) == 0 ) ? strtoupper($alpha[rand(0, $alpha_len-1)]) : $alpha[rand(0, $alpha_len-1)];
65
+        while( strlen($ret) < 14) {
66
+                    $ret .= ( rand(0,1) == 0 ) ? strtoupper($alpha[rand(0, $alpha_len-1)]) : $alpha[rand(0, $alpha_len-1)];
67
+        }
67 68
 
68 69
         return $ret;
69 70
     }
@@ -78,7 +79,9 @@  discard block
 block discarded – undo
78 79
      */
79 80
      public function AllowedIn(){
80 81
         $classes = array_values( ClassInfo::subclassesFor( 'SiteTree' ) );
81
-        if( !$this->AddTo ) return $classes;
82
+        if( !$this->AddTo ) {
83
+            return $classes;
84
+        }
82 85
         
83 86
         $sanitized = explode( ',', str_replace( ' ', '', strtolower( $this->AddTo ) ) );
84 87
         
@@ -93,7 +96,9 @@  discard block
 block discarded – undo
93 96
                 }
94 97
             }
95 98
             
96
-            if( !$found ) unset( $sanitized[$x] );
99
+            if( !$found ) {
100
+                unset( $sanitized[$x] );
101
+            }
97 102
         }
98 103
         
99 104
         return (array) $sanitized;
Please login to merge, or discard this patch.
code/dataobjects/AutomatedLink.php 1 patch
Braces   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -79,7 +79,9 @@  discard block
 block discarded – undo
79 79
 		parent::requireDefaultRecords();
80 80
 		
81 81
 		// Update all links to redirector pages during dev/build
82
-		foreach( self::get() as $link ) $link->CheckAndUpdateDestination( true );
82
+		foreach( self::get() as $link ) {
83
+		    $link->CheckAndUpdateDestination( true );
84
+		}
83 85
 	}
84 86
 	
85 87
 	/**
@@ -187,7 +189,9 @@  discard block
 block discarded – undo
187 189
 			$this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' )
188 190
 		{
189 191
 			$this->PageID = $this->Page()->LinkToID;
190
-			if( $write ) $this->write();
192
+			if( $write ) {
193
+			    $this->write();
194
+			}
191 195
 		}
192 196
 	}
193 197
 	
@@ -203,8 +207,9 @@  discard block
 block discarded – undo
203 207
         if( !isset( self::$parsableFields[$page->ID] ) || !isset( self::$parsableFields[$page->ID][$field] ) ){
204 208
             $fields = array();
205 209
             
206
-            foreach( ClassInfo::ancestry( $page->ClassName, true ) as $class )
207
-                $fields = array_merge( $fields, (array) DataObject::database_fields( $class ) );
210
+            foreach( ClassInfo::ancestry( $page->ClassName, true ) as $class ) {
211
+                            $fields = array_merge( $fields, (array) DataObject::database_fields( $class ) );
212
+            }
208 213
             
209 214
             self::$parsableFields[$page->ID][$field] = 
210 215
                 (Boolean) array_key_exists( $field, $fields ) && strtolower( $fields[$field] ) === 'htmltext' && $page->$field;
Please login to merge, or discard this patch.
code/controllers/AutomatedLinkReportTask.php 1 patch
Braces   +43 added lines, -19 removed lines patch added patch discarded remove patch
@@ -8,7 +8,9 @@  discard block
 block discarded – undo
8 8
     private static $exclude_classes = array( 'RedirectorPage', 'VirtualPage' );
9 9
 
10 10
     public function index(){
11
-        if( !Director::is_cli() ) return 'Please run this controller in CLI';
11
+        if( !Director::is_cli() ) {
12
+            return 'Please run this controller in CLI';
13
+        }
12 14
 
13 15
         libxml_use_internal_errors(true);
14 16
         set_time_limit(600);
@@ -44,15 +46,23 @@  discard block
 block discarded – undo
44 46
         $exclude = Config::inst()->get( $this->class, 'exclude_classes' );
45 47
         $exclude = ( $exclude ) ? "'".implode( "','", $exclude )."'" : '';
46 48
         foreach( SiteTree::get()->where( "ClassName NOT IN($exclude)" ) as $page ){
47
-            if( !$this->checkForPossibleLinks( $page, $includeInFields ) ) continue;
49
+            if( !$this->checkForPossibleLinks( $page, $includeInFields ) ) {
50
+                continue;
51
+            }
48 52
             $page = $this->getLinkData( $page, $includeInFields );
49
-            if( !$page ) continue;
53
+            if( !$page ) {
54
+                continue;
55
+            }
50 56
 
51
-            if( !$run_in_realtime ) AutomatedLinkPageResult::add_or_update( $page );
57
+            if( !$run_in_realtime ) {
58
+                AutomatedLinkPageResult::add_or_update( $page );
59
+            }
52 60
             $data->push( $page );
53 61
         }
54 62
 
55
-        if( !$run_in_realtime ) AutomatedLinkPageResult::remove_old_data();
63
+        if( !$run_in_realtime ) {
64
+            AutomatedLinkPageResult::remove_old_data();
65
+        }
56 66
 
57 67
         return $data;
58 68
     }
@@ -70,15 +80,18 @@  discard block
 block discarded – undo
70 80
         // Set a list of all fields that can have autolinks created in them
71 81
         $page->AutomateableFields = ArrayList::create();
72 82
 
73
-        foreach( $this->getAllDatabaseFields( $page->class ) as $field => $type )
74
-            if( in_array( $field, $includeIn )                          &&
83
+        foreach( $this->getAllDatabaseFields( $page->class ) as $field => $type ) {
84
+                    if( in_array( $field, $includeIn )                          &&
75 85
                 !$page->AutomateableFields->find( 'DataField', $field ) &&
76 86
                 AutomatedLink::isFieldParsable( $page, $field )
77 87
             ) $page->AutomateableFields->push( DataObject::create( array( 'DataField' => $field ) ) );
88
+        }
78 89
 
79 90
         // Get data Pre-Automated Links creation
80 91
         $withLinks = $this->getPageDOM( $page, true );
81
-        if( !$withLinks ) return false;
92
+        if( !$withLinks ) {
93
+            return false;
94
+        }
82 95
 
83 96
         $links = $withLinks->getElementsByTagName('a');
84 97
 
@@ -88,10 +101,11 @@  discard block
 block discarded – undo
88 101
 
89 102
         // List all automated links that were created in this $page
90 103
         $linksUsed = array();
91
-        foreach( $this->Links as $autolink )
92
-            foreach( $links as $link ){
104
+        foreach( $this->Links as $autolink ) {
105
+                    foreach( $links as $link ){
93 106
                 if( $link->getAttribute('data-id') == $autolink->ID ){
94 107
                     $linksUsed[$autolink->ID] = $autolink->Phrase;
108
+        }
95 109
                     $page->OriginalLinkCount--;
96 110
                     $page->LinkCount++;
97 111
                 }
@@ -99,7 +113,9 @@  discard block
 block discarded – undo
99 113
 
100 114
         $page->Links = implode( ', ', $linksUsed );
101 115
 
102
-        if( $page->LinkCount < 1 ) return false;
116
+        if( $page->LinkCount < 1 ) {
117
+            return false;
118
+        }
103 119
 
104 120
         return $page;
105 121
     }
@@ -113,8 +129,9 @@  discard block
 block discarded – undo
113 129
      */
114 130
     private function getAllDatabaseFields( $class ){
115 131
         $fields = array();
116
-        foreach( ClassInfo::ancestry( $class, true ) as $cls )
117
-            $fields = array_merge( $fields, (array) DataObject::database_fields( $cls ) );
132
+        foreach( ClassInfo::ancestry( $class, true ) as $cls ) {
133
+                    $fields = array_merge( $fields, (array) DataObject::database_fields( $cls ) );
134
+        }
118 135
 
119 136
         return $fields;
120 137
     }
@@ -130,8 +147,12 @@  discard block
 block discarded – undo
130 147
      */
131 148
     private function getPageDOM( SiteTree $page ){
132 149
         $controllerClass = $page->class.'_Controller';
133
-        if( !class_exists( $controllerClass ) )  $controller = $page->class.'Controller';
134
-        if( !class_exists( $controllerClass  ) ) return false;
150
+        if( !class_exists( $controllerClass ) ) {
151
+            $controller = $page->class.'Controller';
152
+        }
153
+        if( !class_exists( $controllerClass  ) ) {
154
+            return false;
155
+        }
135 156
 
136 157
         $controller = $controllerClass::create( $page );
137 158
         $controller->invokeWithExtensions( 'addAutomatedLinks' );
@@ -150,11 +171,13 @@  discard block
 block discarded – undo
150 171
             GlobalAutoLinkSettings::$encoding
151 172
         );
152 173
 
153
-        if( !$content ) return false;
174
+        if( !$content ) {
175
+            return false;
176
+        }
154 177
 
155 178
         if( class_exists( 'HTML5_Parser' ) ){
156 179
             $dom = HTML5_Parser::parse($content);
157
-        }else{
180
+        } else{
158 181
             $dom = new DOMDocument();
159 182
             $dom->loadHTML( $content );
160 183
         }
@@ -171,9 +194,10 @@  discard block
 block discarded – undo
171 194
      * @return Boolean
172 195
      */
173 196
     private function checkForPossibleLinks( SiteTree $page, array $includeIn ){
174
-        foreach( $this->Links as $link )
175
-            foreach( $includeIn as $possibleField )
197
+        foreach( $this->Links as $link ) {
198
+                    foreach( $includeIn as $possibleField )
176 199
                 if( isset( $page->$possibleField ) && preg_match( "/\b{$link->Phrase}\b/i", $page->$possibleField ) ) return true;
200
+        }
177 201
 
178 202
         return false;
179 203
     }
Please login to merge, or discard this patch.
code/controllers/SEOTestSiteTreeController.php 1 patch
Braces   +24 added lines, -9 removed lines patch added patch discarded remove patch
@@ -17,21 +17,29 @@  discard block
 block discarded – undo
17 17
         parent::init();
18 18
 
19 19
         // Check user is logged in and has permission to access to SEO Toolbox Admin
20
-        if (!Member::currentUser()) return $this->redirect(Security::login_url() . '?BackURL=/seotest');
21
-        if (!Permission::check('CMS_ACCESS_SEOToolboxAdmin')) return $this->redirect(self::getPermissionDeniedPage()->Link());
20
+        if (!Member::currentUser()) {
21
+            return $this->redirect(Security::login_url() . '?BackURL=/seotest');
22
+        }
23
+        if (!Permission::check('CMS_ACCESS_SEOToolboxAdmin')) {
24
+            return $this->redirect(self::getPermissionDeniedPage()->Link());
25
+        }
22 26
 
23 27
         Requirements::clear();
24 28
 
25 29
         // Sprite Location needs to be dynamic as devs can install module in different locations
26 30
         $sprite_path = $this->config()->get('sprite_path');
27
-        if ($sprite_path === null) $sprite_path = SEOTOOLBOX_DIR . '/css/icons/icon_sprite.png';
31
+        if ($sprite_path === null) {
32
+            $sprite_path = SEOTOOLBOX_DIR . '/css/icons/icon_sprite.png';
33
+        }
28 34
         Requirements::customCSS(".icon{width:16px;height: 16px;cursor:pointer;background: url(/{$sprite_path});}");
29 35
 
30 36
         // CSS can be replaced by devs if they desire to change styling
31 37
         Requirements::css(SEOTOOLBOX_DIR.'/third-party/bootstrap/css/bootstrap.min.css');
32 38
         Requirements::css(SEOTOOLBOX_DIR.'/third-party/bootstrap/css/bootstrap-theme.min.css');
33 39
         $css = $this->config()->get('css');
34
-        if ($css === null) $css = array(SEOTOOLBOX_DIR . '/fonts/lato/lato.css', SEOTOOLBOX_DIR . '/css/seotest.css');
40
+        if ($css === null) {
41
+            $css = array(SEOTOOLBOX_DIR . '/fonts/lato/lato.css', SEOTOOLBOX_DIR . '/css/seotest.css');
42
+        }
35 43
         Requirements::combine_files('seotest.css', $css);
36 44
 
37 45
         Requirements::combine_files('seotest.js', array(
@@ -80,7 +88,9 @@  discard block
 block discarded – undo
80 88
         );
81 89
         $html = str_replace(array("\n", "\r"), ' ', mb_strtolower($html));
82 90
 
83
-        if( $get_pure_word_count ) return strip_tags($html);
91
+        if( $get_pure_word_count ) {
92
+            return strip_tags($html);
93
+        }
84 94
 
85 95
         $phrases = array();
86 96
 
@@ -118,14 +128,17 @@  discard block
 block discarded – undo
118 128
                 $phrases = array_merge($phrases, $matches[$commands['find_pos']]);
119 129
             }
120 130
 
121
-            if(isset($commands['replace']))
122
-                $html = preg_replace($commands['replace'], ' ', $html);
131
+            if(isset($commands['replace'])) {
132
+                            $html = preg_replace($commands['replace'], ' ', $html);
133
+            }
123 134
         }
124 135
 
125 136
         // Remove the empty elements
126 137
         $phrases = array_filter($phrases, function($phrase){return strlen(trim($phrase)) > 0;});
127 138
         $count = 0;
128
-        foreach( $phrases as $p ) $count += count(explode(' ', $p));
139
+        foreach( $phrases as $p ) {
140
+            $count += count(explode(' ', $p));
141
+        }
129 142
         return $phrases;
130 143
     }
131 144
 
@@ -178,7 +191,9 @@  discard block
 block discarded – undo
178 191
 
179 192
         curl_close( $ch );
180 193
 
181
-        if( !strpos( $header, ' 200 ' ) )return array( 'headers' => false, 'body' => false );
194
+        if( !strpos( $header, ' 200 ' ) ) {
195
+            return array( 'headers' => false, 'body' => false );
196
+        }
182 197
 
183 198
         $field_data = $this->getHTMLFieldsData($body);
184 199
         $body = str_replace($field_data[0], $field_data[2], $body);
Please login to merge, or discard this patch.
code/extenstions/SEOToolboxControllerExtension.php 1 patch
Braces   +42 added lines, -17 removed lines patch added patch discarded remove patch
@@ -51,7 +51,9 @@  discard block
 block discarded – undo
51 51
         foreach( Config::inst()->get($this->owner->ClassName, 'db') as $field => $type ){
52 52
             if( strtolower( $type ) == 'htmltext' ){
53 53
                 $data = ($this->owner->hasMethod($field)) ? $this->owner->$field() : $this->owner->$field;
54
-                if( !$data ) continue;
54
+                if( !$data ) {
55
+                    continue;
56
+                }
55 57
                 $tmp = new HTMLText('tmp');
56 58
                 $tmp->setValue($data);
57 59
                 $data = base64_encode($tmp->forTemplate());
@@ -83,12 +85,16 @@  discard block
 block discarded – undo
83 85
     private function getSettings(){
84 86
         if( $this->settings === null ) {
85 87
             $this->settings = GlobalAutoLinkSettings::get_current();
86
-            if (!$this->settings) return $this->addLinks = false;
88
+            if (!$this->settings) {
89
+                return $this->addLinks = false;
90
+            }
87 91
 
88 92
             $this->excludeTags = (array)$this->settings->ExcludeTags();
89 93
             $this->maxLinks = (int)($this->settings->MaxLinksPerPage) ? $this->settings->MaxLinksPerPage : PHP_INT_MAX;
90 94
 
91
-            if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) $this->addLinks = false;
95
+            if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) {
96
+                $this->addLinks = false;
97
+            }
92 98
         }
93 99
 
94 100
         return $this->settings;
@@ -103,7 +109,9 @@  discard block
 block discarded – undo
103 109
 	public function addAutomatedLinks(){
104 110
         if( GlobalAutoLinkSettings::$enabled && $this->owner->class != 'RedirectorPage' ) {
105 111
             $this->getSettings();
106
-            if( !$this->addLinks ) return;
112
+            if( !$this->addLinks ) {
113
+                return;
114
+            }
107 115
 
108 116
             foreach( $this->getSettings()->IncludeInFields() as $field ){
109 117
                 // Check that the field provided by user exists in this object, is of type HTMLText and has content
@@ -117,14 +125,16 @@  discard block
 block discarded – undo
117 125
 
118 126
                     if( class_exists( 'HTML5_Parser' ) ){
119 127
                         $dom = HTML5_Parser::parse( $content );
120
-                    }else{
128
+                    } else{
121 129
                         $dom = new DOMDocument();
122 130
                         $dom->loadHTML( $content );
123 131
                     }
124 132
 
125 133
                     // Check current link count and if it's already exceeded do nothing
126 134
                     $this->linkCount += (int) $dom->getElementsByTagName( 'a' )->length;
127
-                    if( $this->linkCount >= $this->maxLinks ) return;
135
+                    if( $this->linkCount >= $this->maxLinks ) {
136
+                        return;
137
+                    }
128 138
 
129 139
                     $parsed = $this->parseField( $dom, $field );
130 140
                     $this->owner->data()->$field = $parsed;
@@ -148,7 +158,9 @@  discard block
 block discarded – undo
148 158
 		$excluded = array();
149 159
 		foreach( $this->excludeTags as $eTag ){
150 160
 		    while( $tags = $html->getElementsByTagName( $eTag ) ){
151
-		        if( !$tags->length ) break 1;
161
+		        if( !$tags->length ) {
162
+		            break 1;
163
+		        }
152 164
 		        $tag	= $tags->item(0);
153 165
                 $value  = $html->saveHTML( $tag );
154 166
                 $key    = (string) crc32( $value );
@@ -167,7 +179,9 @@  discard block
 block discarded – undo
167 179
 		$links = AutomatedLink::get()->sort('Priority');
168 180
 		foreach( $links as $link ){
169 181
 			// Check if self-linking is allowed and if current pagetype is allowed
170
-			if( !$link->canBeAdded( $this->owner, $field ) ) continue;
182
+			if( !$link->canBeAdded( $this->owner, $field ) ) {
183
+			    continue;
184
+			}
171 185
 
172 186
 			$max    = (int) ( $link->MaxLinksPerPage > 0 ) ? $link->MaxLinksPerPage : PHP_INT_MAX;
173 187
             $escape = (string) preg_quote( $link->Phrase, '/' );
@@ -176,22 +190,31 @@  discard block
 block discarded – undo
176 190
             // Count the matches
177 191
             preg_match_all( $regex, $content, $count );
178 192
             $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0;
179
-            if( $count < 1 ) continue;
193
+            if( $count < 1 ) {
194
+                continue;
195
+            }
180 196
 
181
-			if( isset( $this->maxLinksPerPage[ $link->ID ] ) )
182
-				$max -= $this->maxLinksPerPage[ $link->ID ];
183
-			else
184
-				$this->maxLinksPerPage[ $link->ID ] = 0;
197
+			if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) {
198
+							$max -= $this->maxLinksPerPage[ $link->ID ];
199
+			} else {
200
+							$this->maxLinksPerPage[ $link->ID ] = 0;
201
+			}
185 202
 
186 203
 			for( $x = 0; $x < $count; $x++ ){
187 204
 				// Stop adding links if we reached the link or page limit
188
-				if( $x >= $max || $this->linkCount >= $this->maxLinks ) break;
205
+				if( $x >= $max || $this->linkCount >= $this->maxLinks ) {
206
+				    break;
207
+				}
189 208
 
190 209
                 // Check if there is anything else to replace else stop
191 210
                 preg_match( $regex, $content, $match );
192
-                if( !is_array( $match ) || !count( $match ) ) break;
211
+                if( !is_array( $match ) || !count( $match ) ) {
212
+                    break;
213
+                }
193 214
 
194
-                if( !$html = (string) $link->getHTML( $match[0] ) ) continue;
215
+                if( !$html = (string) $link->getHTML( $match[0] ) ) {
216
+                    continue;
217
+                }
195 218
                 $key              = (string) crc32( $html );
196 219
                 $excluded[ $key ] = (string) $html;
197 220
 
@@ -201,7 +224,9 @@  discard block
 block discarded – undo
201 224
             }
202 225
 
203 226
 			// Stop Adding links if we reached the page limit
204
-			if( $this->linkCount >= $this->maxLinks ) break;
227
+			if( $this->linkCount >= $this->maxLinks ) {
228
+			    break;
229
+			}
205 230
 		}
206 231
 
207 232
 		// Re-add the excluded Tags
Please login to merge, or discard this patch.