Completed
Push — develop ( 17fbc1...f065be )
by Dylan
02:50
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   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -61,8 +61,9 @@  discard block
 block discarded – undo
61 61
         $alpha = 'abcdefghijklm[)0123456789(]nopqrstuvwxyz';
62 62
         $alpha_len = strlen($alpha);
63 63
 
64
-        while (strlen($ret) < 14)
65
-            $ret .= (rand(0, 1) == 0) ? strtoupper($alpha[rand(0, $alpha_len-1)]) : $alpha[rand(0, $alpha_len-1)];
64
+        while (strlen($ret) < 14) {
65
+                    $ret .= (rand(0, 1) == 0) ? strtoupper($alpha[rand(0, $alpha_len-1)]) : $alpha[rand(0, $alpha_len-1)];
66
+        }
66 67
 
67 68
         return $ret;
68 69
     }
@@ -77,7 +78,9 @@  discard block
 block discarded – undo
77 78
      */
78 79
         public function AllowedIn(){
79 80
         $classes = array_values( ClassInfo::subclassesFor( 'SiteTree' ) );
80
-        if( !$this->AddTo ) return $classes;
81
+        if( !$this->AddTo ) {
82
+            return $classes;
83
+        }
81 84
 
82 85
         $sanitized = explode( ',', str_replace( ' ', '', strtolower( $this->AddTo ) ) );
83 86
 
@@ -92,7 +95,9 @@  discard block
 block discarded – undo
92 95
                 }
93 96
             }
94 97
 
95
-            if( !$found ) unset( $sanitized[$x] );
98
+            if( !$found ) {
99
+                unset( $sanitized[$x] );
100
+            }
96 101
         }
97 102
 
98 103
         return (array) $sanitized;
Please login to merge, or discard this patch.
code/dataobjects/AutomatedLink.php 1 patch
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -263,7 +263,7 @@
 block discarded – undo
263 263
                 while($html5->length > 0) {
264 264
                     $dom->appendChild($html5->item(0));
265 265
                 }
266
-            }else{
266
+            } else{
267 267
                 $dom = $html5;
268 268
             }
269 269
         } else{
Please login to merge, or discard this patch.
code/controllers/AutomatedLinkReportTask.php 1 patch
Braces   +36 added lines, -15 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@  discard block
 block discarded – undo
16 16
     private static $exclude_classes = array('RedirectorPage', 'VirtualPage');
17 17
 
18 18
     public function index() {
19
-        if (!Director::is_cli()) return 'Please run this controller in CLI';
19
+        if (!Director::is_cli()) {
20
+            return 'Please run this controller in CLI';
21
+        }
20 22
 
21 23
         libxml_use_internal_errors(true);
22 24
         set_time_limit(600);
@@ -52,15 +54,23 @@  discard block
 block discarded – undo
52 54
         $exclude = Config::inst()->get($this->class, 'exclude_classes');
53 55
         $exclude = ($exclude) ? "'".implode("','", $exclude)."'" : '';
54 56
         foreach (SiteTree::get()->where("ClassName NOT IN($exclude)") as $page) {
55
-            if (!$this->checkForPossibleLinks($page, $includeInFields)) continue;
57
+            if (!$this->checkForPossibleLinks($page, $includeInFields)) {
58
+                continue;
59
+            }
56 60
             $page = $this->getLinkData($page, $includeInFields);
57
-            if (!$page) continue;
61
+            if (!$page) {
62
+                continue;
63
+            }
58 64
 
59
-            if (!$run_in_realtime) AutomatedLinkPageResult::add_or_update($page);
65
+            if (!$run_in_realtime) {
66
+                AutomatedLinkPageResult::add_or_update($page);
67
+            }
60 68
             $data->push($page);
61 69
         }
62 70
 
63
-        if (!$run_in_realtime) AutomatedLinkPageResult::remove_old_data();
71
+        if (!$run_in_realtime) {
72
+            AutomatedLinkPageResult::remove_old_data();
73
+        }
64 74
 
65 75
         return $data;
66 76
     }
@@ -78,15 +88,18 @@  discard block
 block discarded – undo
78 88
         // Set a list of all fields that can have autolinks created in them
79 89
         $page->AutomateableFields = ArrayList::create();
80 90
 
81
-        foreach (AutomatedLink::getAllDatabaseFields($page->class) as $field => $type)
82
-            if (in_array($field, $includeIn) &&
91
+        foreach (AutomatedLink::getAllDatabaseFields($page->class) as $field => $type) {
92
+                    if (in_array($field, $includeIn) &&
83 93
                 !$page->AutomateableFields->find('DataField', $field) &&
84 94
                 AutomatedLink::isFieldParsable($page, $field)
85 95
             ) $page->AutomateableFields->push(DataObject::create(array('DataField' => $field)));
96
+        }
86 97
 
87 98
         // Get data Pre-Automated Links creation
88 99
         $withLinks = $this->getPageDOM($page);
89
-        if (!$withLinks) return false;
100
+        if (!$withLinks) {
101
+            return false;
102
+        }
90 103
 
91 104
         $links = $withLinks->getElementsByTagName('a');
92 105
 
@@ -96,10 +109,11 @@  discard block
 block discarded – undo
96 109
 
97 110
         // List all automated links that were created in this $page
98 111
         $linksUsed = array();
99
-        foreach ($this->Links as $autolink)
100
-            foreach ($links as $link) {
112
+        foreach ($this->Links as $autolink) {
113
+                    foreach ($links as $link) {
101 114
                 if ($link->getAttribute('data-id') == $autolink->ID) {
102 115
                     $linksUsed[$autolink->ID] = $autolink->Phrase;
116
+        }
103 117
                     $page->OriginalLinkCount--;
104 118
                     $page->LinkCount++;
105 119
                 }
@@ -107,7 +121,9 @@  discard block
 block discarded – undo
107 121
 
108 122
         $page->Links = implode(', ', $linksUsed);
109 123
 
110
-        if ($page->LinkCount < 1) return false;
124
+        if ($page->LinkCount < 1) {
125
+            return false;
126
+        }
111 127
 
112 128
         return $page;
113 129
     }
@@ -122,8 +138,12 @@  discard block
 block discarded – undo
122 138
      */
123 139
     private function getPageDOM(SiteTree $page) {
124 140
         $controllerClass = $page->class.'_Controller';
125
-        if (!class_exists($controllerClass))  $controllerClass = $page->class.'Controller';
126
-        if (!class_exists($controllerClass)) return false;
141
+        if (!class_exists($controllerClass)) {
142
+            $controllerClass = $page->class.'Controller';
143
+        }
144
+        if (!class_exists($controllerClass)) {
145
+            return false;
146
+        }
127 147
 
128 148
         $controller = $controllerClass::create($page);
129 149
         $controller->invokeWithExtensions('addAutomatedLinks');
@@ -154,9 +174,10 @@  discard block
 block discarded – undo
154 174
      * @return Boolean
155 175
      */
156 176
     private function checkForPossibleLinks(SiteTree $page, array $includeIn) {
157
-        foreach ($this->Links as $link)
158
-            foreach ($includeIn as $possibleField)
177
+        foreach ($this->Links as $link) {
178
+                    foreach ($includeIn as $possibleField)
159 179
                 if (isset($page->$possibleField) && preg_match("/\b{$link->Phrase}\b/i", $page->$possibleField)) return true;
180
+        }
160 181
 
161 182
         return false;
162 183
     }
Please login to merge, or discard this patch.
code/extenstions/SEOToolboxControllerExtension.php 1 patch
Braces   +21 added lines, -7 removed lines patch added patch discarded remove patch
@@ -73,12 +73,16 @@  discard block
 block discarded – undo
73 73
     private function getSettings() {
74 74
         if ($this->settings === null) {
75 75
             $this->settings = GlobalAutoLinkSettings::get_current();
76
-            if (!$this->settings) return $this->addLinks = false;
76
+            if (!$this->settings) {
77
+                return $this->addLinks = false;
78
+            }
77 79
 
78 80
             $this->excludeTags = (array) $this->settings->ExcludeTags();
79 81
             $this->maxLinks = (int) ($this->settings->MaxLinksPerPage) ? $this->settings->MaxLinksPerPage : PHP_INT_MAX;
80 82
 
81
-            if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) $this->addLinks = false;
83
+            if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) {
84
+                $this->addLinks = false;
85
+            }
82 86
         }
83 87
 
84 88
         return $this->settings;
@@ -134,7 +138,9 @@  discard block
 block discarded – undo
134 138
         $excluded = array();
135 139
         foreach( $hash_tags as $eTag ){
136 140
             while( $tags = $html->getElementsByTagName( $eTag ) ){
137
-                if( !$tags->length ) break 1;
141
+                if( !$tags->length ) {
142
+                    break 1;
143
+                }
138 144
                 $tag	= $tags->item(0);
139 145
                 $value  = $html->saveHTML( $tag );
140 146
                 $key    = (string) crc32( $value );
@@ -166,7 +172,9 @@  discard block
 block discarded – undo
166 172
         // Count the matches
167 173
         preg_match_all( $regex, $content, $count );
168 174
         $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0;
169
-        if( $count < 1 ) $links;
175
+        if( $count < 1 ) {
176
+            $links;
177
+        }
170 178
 
171 179
         if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) {
172 180
             $max -= $this->maxLinksPerPage[$link->ID];
@@ -176,13 +184,19 @@  discard block
 block discarded – undo
176 184
 
177 185
         for( $x = 0; $x < $count; $x++ ){
178 186
             // Stop adding links if we reached the link or page limit
179
-            if( $x >= $max || $this->linkCount >= $this->maxLinks ) break;
187
+            if( $x >= $max || $this->linkCount >= $this->maxLinks ) {
188
+                break;
189
+            }
180 190
 
181 191
             // Check if there is anything else to replace else stop
182 192
             preg_match( $regex, $content, $match );
183
-            if( !is_array( $match ) || !count( $match ) ) break;
193
+            if( !is_array( $match ) || !count( $match ) ) {
194
+                break;
195
+            }
184 196
 
185
-            if( !$html = (string) $link->getHTML( $match[0] ) ) continue;
197
+            if( !$html = (string) $link->getHTML( $match[0] ) ) {
198
+                continue;
199
+            }
186 200
             $key            = (string) crc32( $html );
187 201
             $links[ $key ]  = (string) $html;
188 202
 
Please login to merge, or discard this patch.
code/controllers/SEOTestSiteTreeController.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -113,8 +113,9 @@
 block discarded – undo
113 113
                 $phrases = array_merge($phrases, $matches[$commands['find_pos']]);
114 114
             }
115 115
 
116
-            if (isset($commands['replace']))
117
-                $html = preg_replace($commands['replace'], ' ', $html);
116
+            if (isset($commands['replace'])) {
117
+                            $html = preg_replace($commands['replace'], ' ', $html);
118
+            }
118 119
         }
119 120
 
120 121
         // Remove the empty elements
Please login to merge, or discard this patch.