Passed
Push — develop ( 6d5733...09225f )
by Dylan
02:55
created
code/admin/SEOToolboxAdmin.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,18 +11,18 @@
 block discarded – undo
11 11
  */
12 12
 class SEOToolboxAdmin extends ModelAdmin{
13 13
 	
14
-	private static $menu_title      = 'SEO Tool box';
15
-	private static $url_segment     = 'seo-tool-box';
16
-	private static $managed_models  = array( 'AutomatedLink' );
14
+    private static $menu_title      = 'SEO Tool box';
15
+    private static $url_segment     = 'seo-tool-box';
16
+    private static $managed_models  = array( 'AutomatedLink' );
17 17
     private static $menu_priority   = 10;
18 18
 
19 19
 
20
-	public function getEditForm($id = null, $fields = null) {
21
-		$form = parent::getEditForm( $id, $fields );
22
-		$class = $this->sanitiseClassName($this->modelClass);
23
-		$grid   = $form->Fields()->fieldByName($class);
24
-		$grid->getConfig()->addComponent( new GridFieldSortableRows( 'Priority' ) );
20
+    public function getEditForm($id = null, $fields = null) {
21
+        $form = parent::getEditForm( $id, $fields );
22
+        $class = $this->sanitiseClassName($this->modelClass);
23
+        $grid   = $form->Fields()->fieldByName($class);
24
+        $grid->getConfig()->addComponent( new GridFieldSortableRows( 'Priority' ) );
25 25
 		
26
-		return $form;
27
-	}
26
+        return $form;
27
+    }
28 28
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -9,19 +9,19 @@
 block discarded – undo
9 9
  * all the automated links and automated link global settings
10 10
  * for this site
11 11
  */
12
-class SEOToolboxAdmin extends ModelAdmin{
12
+class SEOToolboxAdmin extends ModelAdmin {
13 13
 	
14 14
 	private static $menu_title      = 'SEO Tool box';
15 15
 	private static $url_segment     = 'seo-tool-box';
16
-	private static $managed_models  = array( 'AutomatedLink' );
17
-    private static $menu_priority   = 10;
16
+	private static $managed_models  = array('AutomatedLink');
17
+    private static $menu_priority = 10;
18 18
 
19 19
 
20 20
 	public function getEditForm($id = null, $fields = null) {
21
-		$form = parent::getEditForm( $id, $fields );
21
+		$form = parent::getEditForm($id, $fields);
22 22
 		$class = $this->sanitiseClassName($this->modelClass);
23
-		$grid   = $form->Fields()->fieldByName($class);
24
-		$grid->getConfig()->addComponent( new GridFieldSortableRows( 'Priority' ) );
23
+		$grid = $form->Fields()->fieldByName($class);
24
+		$grid->getConfig()->addComponent(new GridFieldSortableRows('Priority'));
25 25
 		
26 26
 		return $form;
27 27
 	}
Please login to merge, or discard this patch.
_config.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -33,11 +33,11 @@
 block discarded – undo
33 33
  * to view this report.
34 34
  */
35 35
 
36
-define( 'SEOTOOLBOX_DIR', str_replace( Director::baseFolder().'/', '', __DIR__ ) );
36
+define('SEOTOOLBOX_DIR', str_replace(Director::baseFolder().'/', '', __DIR__));
37 37
 
38 38
 Config::inst()->update('SEOToolboxAdmin', 'menu_icon', SEOTOOLBOX_DIR.'/code/admin/icon/seotoolbox-icon.png');
39
-Config::inst()->update('LeftAndMain','extra_requirements_javascript', array(SEOTOOLBOX_DIR.'/js/seo_page_analyzer.js'));
40
-Config::inst()->update('LeftAndMain','extra_requirements_css', array(SEOTOOLBOX_DIR.'/css/seo_page_analyzer.css'));
39
+Config::inst()->update('LeftAndMain', 'extra_requirements_javascript', array(SEOTOOLBOX_DIR.'/js/seo_page_analyzer.js'));
40
+Config::inst()->update('LeftAndMain', 'extra_requirements_css', array(SEOTOOLBOX_DIR.'/css/seo_page_analyzer.css'));
41 41
 
42 42
 CMSMenu::add_link('seotest', 'Run Crawler', '/seotest', 9, array('target' => '_blank'));
43 43
 Requirements::customCSS('.icon.icon-16.icon-seotest{background:url('.SEOTOOLBOX_DIR.'/code/admin/icon/crawl-icon.png)}');
Please login to merge, or discard this patch.
code/extenstions/SEOToolboxControllerExtension.php 2 patches
Braces   +32 added lines, -13 removed lines patch added patch discarded remove patch
@@ -84,12 +84,16 @@  discard block
 block discarded – undo
84 84
     private function getSettings() {
85 85
         if ($this->settings === null) {
86 86
             $this->settings = GlobalAutoLinkSettings::get_current();
87
-            if (!$this->settings) return $this->addLinks = false;
87
+            if (!$this->settings) {
88
+                return $this->addLinks = false;
89
+            }
88 90
 
89 91
             $this->excludeTags = (array) $this->settings->ExcludeTags();
90 92
             $this->maxLinks = (int) ($this->settings->MaxLinksPerPage) ? $this->settings->MaxLinksPerPage : PHP_INT_MAX;
91 93
 
92
-            if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) $this->addLinks = false;
94
+            if (!in_array($this->owner->ClassName, $this->settings->AllowedIn())) {
95
+                $this->addLinks = false;
96
+            }
93 97
         }
94 98
 
95 99
         return $this->settings;
@@ -153,7 +157,9 @@  discard block
 block discarded – undo
153 157
         $excluded = array();
154 158
         foreach( $this->excludeTags as $eTag ){
155 159
             while( $tags = $html->getElementsByTagName( $eTag ) ){
156
-                if( !$tags->length ) break 1;
160
+                if( !$tags->length ) {
161
+                    break 1;
162
+                }
157 163
                 $tag	= $tags->item(0);
158 164
                 $value  = $html->saveHTML( $tag );
159 165
                 $key    = (string) crc32( $value );
@@ -172,7 +178,9 @@  discard block
 block discarded – undo
172 178
         $links = AutomatedLink::get()->sort('Priority');
173 179
         foreach( $links as $link ){
174 180
             // Check if self-linking is allowed and if current pagetype is allowed
175
-            if( !$link->canBeAdded( $this->owner, $field ) ) continue;
181
+            if( !$link->canBeAdded( $this->owner, $field ) ) {
182
+                continue;
183
+            }
176 184
 
177 185
             $max    = (int) ( $link->MaxLinksPerPage > 0 ) ? $link->MaxLinksPerPage : PHP_INT_MAX;
178 186
             $escape = (string) preg_quote( $link->Phrase, '/' );
@@ -181,22 +189,31 @@  discard block
 block discarded – undo
181 189
             // Count the matches
182 190
             preg_match_all( $regex, $content, $count );
183 191
             $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0;
184
-            if( $count < 1 ) continue;
192
+            if( $count < 1 ) {
193
+                continue;
194
+            }
185 195
 
186
-            if( isset( $this->maxLinksPerPage[ $link->ID ] ) )
187
-                $max -= $this->maxLinksPerPage[ $link->ID ];
188
-            else
189
-                $this->maxLinksPerPage[ $link->ID ] = 0;
196
+            if( isset( $this->maxLinksPerPage[ $link->ID ] ) ) {
197
+                            $max -= $this->maxLinksPerPage[ $link->ID ];
198
+            } else {
199
+                            $this->maxLinksPerPage[ $link->ID ] = 0;
200
+            }
190 201
 
191 202
             for( $x = 0; $x < $count; $x++ ){
192 203
                 // Stop adding links if we reached the link or page limit
193
-                if( $x >= $max || $this->linkCount >= $this->maxLinks ) break;
204
+                if( $x >= $max || $this->linkCount >= $this->maxLinks ) {
205
+                    break;
206
+                }
194 207
 
195 208
                 // Check if there is anything else to replace else stop
196 209
                 preg_match( $regex, $content, $match );
197
-                if( !is_array( $match ) || !count( $match ) ) break;
210
+                if( !is_array( $match ) || !count( $match ) ) {
211
+                    break;
212
+                }
198 213
 
199
-                if( !$html = (string) $link->getHTML( $match[0] ) ) continue;
214
+                if( !$html = (string) $link->getHTML( $match[0] ) ) {
215
+                    continue;
216
+                }
200 217
                 $key              = (string) crc32( $html );
201 218
                 $excluded[ $key ] = (string) $html;
202 219
 
@@ -206,7 +223,9 @@  discard block
 block discarded – undo
206 223
             }
207 224
 
208 225
             // Stop Adding links if we reached the page limit
209
-            if( $this->linkCount >= $this->maxLinks ) break;
226
+            if( $this->linkCount >= $this->maxLinks ) {
227
+                break;
228
+            }
210 229
         }
211 230
 
212 231
         // Re-add the excluded Tags
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 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,13 +31,13 @@  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
-        foreach( Config::inst()->get($this->owner->ClassName, 'db') as $field => $type ){
38
-            if( strtolower( $type ) == 'htmltext' ){
37
+        foreach (Config::inst()->get($this->owner->ClassName, 'db') as $field => $type) {
38
+            if (strtolower($type) == 'htmltext') {
39 39
                 $data = ($this->owner->hasMethod($field)) ? $this->owner->$field() : $this->owner->$field;
40
-                if( !$data ) {
40
+                if (!$data) {
41 41
                     continue;
42 42
                 }
43 43
                 $tmp = new HTMLText('tmp');
@@ -88,37 +88,37 @@  discard block
 block discarded – undo
88 88
      *
89 89
      * @return void
90 90
      */
91
-    public function addAutomatedLinks(){
92
-        if( GlobalAutoLinkSettings::$enabled && $this->owner->class != 'RedirectorPage' ) {
91
+    public function addAutomatedLinks() {
92
+        if (GlobalAutoLinkSettings::$enabled && $this->owner->class != 'RedirectorPage') {
93 93
             $this->getSettings();
94
-            if( !$this->addLinks ) {
94
+            if (!$this->addLinks) {
95 95
                 return;
96 96
             }
97 97
 
98
-            foreach( $this->getSettings()->IncludeInFields() as $field ){
98
+            foreach ($this->getSettings()->IncludeInFields() as $field) {
99 99
                 // Check that the field provided by user exists in this object, is of type HTMLText and has content
100
-                if( AutomatedLink::isFieldParsable( $this->owner->data(), $field ) ){
100
+                if (AutomatedLink::isFieldParsable($this->owner->data(), $field)) {
101 101
 
102 102
                     // Create dummy object so we can parse the HTML
103
-                    $dummy = new HTMLText( $field );
104
-                    $dummy->setValue( $this->owner->$field );
103
+                    $dummy = new HTMLText($field);
104
+                    $dummy->setValue($this->owner->$field);
105 105
                     // Create DOMDocument Object
106
-                    $content = mb_convert_encoding( $dummy->forTemplate(), 'html-entities', GlobalAutoLinkSettings::$encoding );
106
+                    $content = mb_convert_encoding($dummy->forTemplate(), 'html-entities', GlobalAutoLinkSettings::$encoding);
107 107
 
108
-                    if( class_exists( 'HTML5_Parser' ) ){
109
-                        $dom = HTML5_Parser::parse( $content );
110
-                    } else{
108
+                    if (class_exists('HTML5_Parser')) {
109
+                        $dom = HTML5_Parser::parse($content);
110
+                    }else {
111 111
                         $dom = new DOMDocument();
112
-                        $dom->loadHTML( $content );
112
+                        $dom->loadHTML($content);
113 113
                     }
114 114
 
115 115
                     // Check current link count and if it's already exceeded do nothing
116
-                    $this->linkCount += (int) $dom->getElementsByTagName( 'a' )->length;
117
-                    if( $this->linkCount >= $this->maxLinks ) {
116
+                    $this->linkCount += (int) $dom->getElementsByTagName('a')->length;
117
+                    if ($this->linkCount >= $this->maxLinks) {
118 118
                         return;
119 119
                     }
120 120
 
121
-                    $parsed = $this->parseField( $dom, $field );
121
+                    $parsed = $this->parseField($dom, $field);
122 122
                     $this->owner->data()->$field = $parsed;
123 123
                     $this->owner->$field         = $parsed;
124 124
                 }
@@ -133,71 +133,71 @@  discard block
 block discarded – undo
133 133
      * @param String $field
134 134
      * @return string
135 135
      */
136
-    private function parseField( DOMDocument $html, $field ){
137
-        $this->owner->extend( 'beforeParseField', $html, $field );
136
+    private function parseField(DOMDocument $html, $field) {
137
+        $this->owner->extend('beforeParseField', $html, $field);
138 138
 
139 139
         // Remove Tags from Content we wown't be using
140 140
         $excluded = array();
141
-        foreach( $this->excludeTags as $eTag ){
142
-            while( $tags = $html->getElementsByTagName( $eTag ) ){
143
-                if( !$tags->length ) break 1;
144
-                $tag	= $tags->item(0);
145
-                $value  = $html->saveHTML( $tag );
146
-                $key    = (string) crc32( $value );
141
+        foreach ($this->excludeTags as $eTag) {
142
+            while ($tags = $html->getElementsByTagName($eTag)) {
143
+                if (!$tags->length) break 1;
144
+                $tag = $tags->item(0);
145
+                $value  = $html->saveHTML($tag);
146
+                $key    = (string) crc32($value);
147 147
 
148 148
                 // Convert back children nodes of this node if they were already hashed
149
-                $excluded[$key] = str_replace( array_keys( $excluded ), array_values( $excluded ), $value );
149
+                $excluded[$key] = str_replace(array_keys($excluded), array_values($excluded), $value);
150 150
 
151
-                $tag->parentNode->replaceChild( $html->createTextNode( $key ), $tag );
151
+                $tag->parentNode->replaceChild($html->createTextNode($key), $tag);
152 152
             }
153 153
         }
154 154
 
155
-        $body    = (string)$html->saveHTML( $html->getElementsByTagName('body')->item(0) );
156
-        $content = preg_replace( array( '/\<body\>/is', '/\<\/body\>/is' ), '', $body, 1 );
155
+        $body    = (string) $html->saveHTML($html->getElementsByTagName('body')->item(0));
156
+        $content = preg_replace(array('/\<body\>/is', '/\<\/body\>/is'), '', $body, 1);
157 157
 
158 158
         // Create the links
159 159
         $links = AutomatedLink::get()->sort('Priority');
160
-        foreach( $links as $link ){
160
+        foreach ($links as $link) {
161 161
             // Check if self-linking is allowed and if current pagetype is allowed
162
-            if( !$link->canBeAdded( $this->owner, $field ) ) continue;
162
+            if (!$link->canBeAdded($this->owner, $field)) continue;
163 163
 
164
-            $max    = (int) ( $link->MaxLinksPerPage > 0 ) ? $link->MaxLinksPerPage : PHP_INT_MAX;
165
-            $escape = (string) preg_quote( $link->Phrase, '/' );
166
-            $regex  = (string) ( $link->CaseSensitive ) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i";
164
+            $max    = (int) ($link->MaxLinksPerPage > 0) ? $link->MaxLinksPerPage : PHP_INT_MAX;
165
+            $escape = (string) preg_quote($link->Phrase, '/');
166
+            $regex  = (string) ($link->CaseSensitive) ? "/(\b{$escape}\b)/" : "/(\b{$escape}\b)/i";
167 167
 
168 168
             // Count the matches
169
-            preg_match_all( $regex, $content, $count );
170
-            $count = ( is_array( $count ) && isset( $count[0] ) ) ? count( $count[0] ) : 0;
171
-            if( $count < 1 ) continue;
169
+            preg_match_all($regex, $content, $count);
170
+            $count = (is_array($count) && isset($count[0])) ? count($count[0]) : 0;
171
+            if ($count < 1) continue;
172 172
 
173
-            if( isset( $this->maxLinksPerPage[ $link->ID ] ) )
174
-                $max -= $this->maxLinksPerPage[ $link->ID ];
173
+            if (isset($this->maxLinksPerPage[$link->ID]))
174
+                $max -= $this->maxLinksPerPage[$link->ID];
175 175
             else
176
-                $this->maxLinksPerPage[ $link->ID ] = 0;
176
+                $this->maxLinksPerPage[$link->ID] = 0;
177 177
 
178
-            for( $x = 0; $x < $count; $x++ ){
178
+            for ($x = 0; $x < $count; $x++) {
179 179
                 // Stop adding links if we reached the link or page limit
180
-                if( $x >= $max || $this->linkCount >= $this->maxLinks ) break;
180
+                if ($x >= $max || $this->linkCount >= $this->maxLinks) break;
181 181
 
182 182
                 // Check if there is anything else to replace else stop
183
-                preg_match( $regex, $content, $match );
184
-                if( !is_array( $match ) || !count( $match ) ) break;
183
+                preg_match($regex, $content, $match);
184
+                if (!is_array($match) || !count($match)) break;
185 185
 
186
-                if( !$html = (string) $link->getHTML( $match[0] ) ) continue;
187
-                $key              = (string) crc32( $html );
188
-                $excluded[ $key ] = (string) $html;
186
+                if (!$html = (string) $link->getHTML($match[0])) continue;
187
+                $key              = (string) crc32($html);
188
+                $excluded[$key] = (string) $html;
189 189
 
190
-                $content = preg_replace( $regex, $key, $content, 1 );
190
+                $content = preg_replace($regex, $key, $content, 1);
191 191
                 $this->linkCount++;
192
-                $this->maxLinksPerPage[ $link->ID ]++;
192
+                $this->maxLinksPerPage[$link->ID]++;
193 193
             }
194 194
 
195 195
             // Stop Adding links if we reached the page limit
196
-            if( $this->linkCount >= $this->maxLinks ) break;
196
+            if ($this->linkCount >= $this->maxLinks) break;
197 197
         }
198 198
 
199 199
         // Re-add the excluded Tags
200
-        $content = str_replace( array_keys( $excluded ), array_values( $excluded ), $content );
200
+        $content = str_replace(array_keys($excluded), array_values($excluded), $content);
201 201
 
202 202
         return $content;
203 203
     }
Please login to merge, or discard this patch.
code/dataobjects/AutomatedLink.php 3 patches
Indentation   +120 added lines, -120 removed lines patch added patch discarded remove patch
@@ -66,133 +66,133 @@
 block discarded – undo
66 66
     }
67 67
 
68 68
     function providePermissions() {
69
-       return array(
70
-         'AUTOMATEDLINK_VIEW'   => 'View Automated Links',
71
-         'AUTOMATEDLINK_EDIT'   => 'Edit Automated Links',
72
-         'AUTOMATEDLINK_DELETE' => 'Delete Automated Links',
73
-         'AUTOMATEDLINK_CREATE' => 'Create Automated Links',
74
-       );
75
-     }
76
-
77
-	public function requireDefaultRecords(){
78
-		parent::requireDefaultRecords();
79
-
80
-		// Update all links to redirector pages during dev/build
81
-		foreach( self::get() as $link ) {
82
-		    $link->CheckAndUpdateDestination( true );
83
-		}
84
-	}
85
-
86
-	/**
87
-	 * Returns the HTML Representation of this object
88
-	 *
69
+        return array(
70
+            'AUTOMATEDLINK_VIEW'   => 'View Automated Links',
71
+            'AUTOMATEDLINK_EDIT'   => 'Edit Automated Links',
72
+            'AUTOMATEDLINK_DELETE' => 'Delete Automated Links',
73
+            'AUTOMATEDLINK_CREATE' => 'Create Automated Links',
74
+        );
75
+        }
76
+
77
+    public function requireDefaultRecords(){
78
+        parent::requireDefaultRecords();
79
+
80
+        // Update all links to redirector pages during dev/build
81
+        foreach( self::get() as $link ) {
82
+            $link->CheckAndUpdateDestination( true );
83
+        }
84
+    }
85
+
86
+    /**
87
+     * Returns the HTML Representation of this object
88
+     *
89 89
      * @param  String $originalPhrase
90
-	 * @return String
91
-	 */
92
-	public function getHTML($originalPhrase = NULL) {
93
-		$link     = ($this->PageID) ? $this->Page()->Link() : '#';
94
-		$title    = ($this->TitleTag) ? "title='{$this->TitleTag}'" : '';
95
-		$nofollow = ($this->NoFollow) ? 'rel="nofollow"' : '';
96
-		$newtab   = ($this->NewWindow) ? 'target="_blank"' : '';
90
+     * @return String
91
+     */
92
+    public function getHTML($originalPhrase = NULL) {
93
+        $link     = ($this->PageID) ? $this->Page()->Link() : '#';
94
+        $title    = ($this->TitleTag) ? "title='{$this->TitleTag}'" : '';
95
+        $nofollow = ($this->NoFollow) ? 'rel="nofollow"' : '';
96
+        $newtab   = ($this->NewWindow) ? 'target="_blank"' : '';
97 97
         $anchor = ($originalPhrase) ? $originalPhrase : $this->Phrase;
98
-		$link     = ($this->AnchorTag) ? rtrim($link, '#').'#'.$this->AnchorTag : $link;
99
-		return "<a href=\"$link\" $title $nofollow $newtab data-id=\"{$this->ID}\">{$anchor}</a>";
100
-	}
101
-
102
-	public function getCMSFields() {
103
-		$fields = FieldList::create(TabSet::create('Root'));
104
-
105
-		$fields->addFieldsToTab('Root.LinkSettings', array(
106
-			TextField::create('Phrase', 'Phrase to search for', $this->Phrase, 255),
107
-			TextField::create('TitleTag', 'Title Tag', $this->TitleTag, 255),
108
-			TextField::create('AnchorTag', 'Anchor Tag(#)', $this->AnchorTag, 255),
109
-			FieldGroup::create(
110
-				CheckboxField::create('NoFollow'),
111
-				CheckboxField::create('NewWindow'),
112
-				CheckboxField::create('SelfLinking', 'Allow page to link to itself'),
113
-				CheckboxField::create('CaseSensitive', 'Match the case of the phrase')
114
-			),
115
-			NumericField::create('MaxLinksPerPage', 'Maximum amount of this link to be created on a single page( 0 = unlimited )'),
116
-			TreeDropdownField::create('PageID', 'Page to link to', 'SiteTree')
117
-		));
118
-
119
-		$settings = GlobalAutoLinkSettings::get_current();
120
-		if ($settings) {
121
-			$fields->addFieldsToTab('Root.Global', array(
122
-				NumericField::create(
123
-					'Global_MaxLinksPerPage',
124
-					'Maximum amount of links a single page can have ( 0 = unlimited )',
125
-					$settings->MaxLinksPerPage
126
-				),
127
-				TextField::create(
128
-					'Global_ExcludeTags',
129
-					'Do not include links into these HTML Tags ( comma seperated )',
130
-					$settings->ExcludeTags
131
-				),
132
-				TextField::create(
133
-				    'Global_AddTo',
134
-				    'Page types where links should be created in ( leave blank for all page types )',
135
-				    $settings->AddTo ),
136
-				TextField::create(
137
-					'Global_IncludeIn',
138
-					'Include Links into these fields ( comma seperated & field must support html injection )',
139
-					$settings->IncludeIn
140
-				)
141
-			));
142
-		}
143
-
144
-		return $fields;
145
-	}
98
+        $link     = ($this->AnchorTag) ? rtrim($link, '#').'#'.$this->AnchorTag : $link;
99
+        return "<a href=\"$link\" $title $nofollow $newtab data-id=\"{$this->ID}\">{$anchor}</a>";
100
+    }
101
+
102
+    public function getCMSFields() {
103
+        $fields = FieldList::create(TabSet::create('Root'));
104
+
105
+        $fields->addFieldsToTab('Root.LinkSettings', array(
106
+            TextField::create('Phrase', 'Phrase to search for', $this->Phrase, 255),
107
+            TextField::create('TitleTag', 'Title Tag', $this->TitleTag, 255),
108
+            TextField::create('AnchorTag', 'Anchor Tag(#)', $this->AnchorTag, 255),
109
+            FieldGroup::create(
110
+                CheckboxField::create('NoFollow'),
111
+                CheckboxField::create('NewWindow'),
112
+                CheckboxField::create('SelfLinking', 'Allow page to link to itself'),
113
+                CheckboxField::create('CaseSensitive', 'Match the case of the phrase')
114
+            ),
115
+            NumericField::create('MaxLinksPerPage', 'Maximum amount of this link to be created on a single page( 0 = unlimited )'),
116
+            TreeDropdownField::create('PageID', 'Page to link to', 'SiteTree')
117
+        ));
118
+
119
+        $settings = GlobalAutoLinkSettings::get_current();
120
+        if ($settings) {
121
+            $fields->addFieldsToTab('Root.Global', array(
122
+                NumericField::create(
123
+                    'Global_MaxLinksPerPage',
124
+                    'Maximum amount of links a single page can have ( 0 = unlimited )',
125
+                    $settings->MaxLinksPerPage
126
+                ),
127
+                TextField::create(
128
+                    'Global_ExcludeTags',
129
+                    'Do not include links into these HTML Tags ( comma seperated )',
130
+                    $settings->ExcludeTags
131
+                ),
132
+                TextField::create(
133
+                    'Global_AddTo',
134
+                    'Page types where links should be created in ( leave blank for all page types )',
135
+                    $settings->AddTo ),
136
+                TextField::create(
137
+                    'Global_IncludeIn',
138
+                    'Include Links into these fields ( comma seperated & field must support html injection )',
139
+                    $settings->IncludeIn
140
+                )
141
+            ));
142
+        }
143
+
144
+        return $fields;
145
+    }
146 146
 
147 147
     public function getCMSValidator() {
148 148
         return new RequiredFields(array('Phrase', 'PageID'));
149 149
     }
150 150
 
151
-	/**
152
-	 * Save the Global Settings into the
153
-	 * Global Auto Link Settings Object
154
-	 *
155
-	 * @return void
156
-	 */
157
-	public function onBeforeWrite() {
158
-		parent::onBeforeWrite();
159
-
160
-		$settings = GlobalAutoLinkSettings::get_current();
161
-		if ($settings) {
162
-
163
-			foreach ($this->getChangedFields() as $field => $value) {
164
-				if (strpos($field, 'Global_') === 0 && isset($value['after'])) {
165
-					$field = str_replace('Global_', '', $field);
166
-					$settings->$field = $value['after'];
167
-				}
168
-			}
169
-
170
-			$settings->write();
171
-		}
172
-
173
-		$this->CheckAndUpdateDestination();
174
-	}
175
-
176
-	/**
177
-	 * Checks if the destination is a redirector page if so
178
-	 * it updates it to the destination of the redirector page
179
-	 *
180
-	 * @Boolean $write - Write the changes if any
181
-	 * @return void
182
-	 */
183
-	public function CheckAndUpdateDestination( $write = false ){
184
-		$this->extend('beforeCheckAndUpdateDestination', $write);
185
-
186
-		if( $this->PageID && $this->Page() &&
187
-			$this->Page()->ClassName == 'RedirectorPage' &&
188
-			$this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' )
189
-		{
190
-			$this->PageID = $this->Page()->LinkToID;
191
-			if( $write ) {
192
-			    $this->write();
193
-			}
194
-		}
195
-	}
151
+    /**
152
+     * Save the Global Settings into the
153
+     * Global Auto Link Settings Object
154
+     *
155
+     * @return void
156
+     */
157
+    public function onBeforeWrite() {
158
+        parent::onBeforeWrite();
159
+
160
+        $settings = GlobalAutoLinkSettings::get_current();
161
+        if ($settings) {
162
+
163
+            foreach ($this->getChangedFields() as $field => $value) {
164
+                if (strpos($field, 'Global_') === 0 && isset($value['after'])) {
165
+                    $field = str_replace('Global_', '', $field);
166
+                    $settings->$field = $value['after'];
167
+                }
168
+            }
169
+
170
+            $settings->write();
171
+        }
172
+
173
+        $this->CheckAndUpdateDestination();
174
+    }
175
+
176
+    /**
177
+     * Checks if the destination is a redirector page if so
178
+     * it updates it to the destination of the redirector page
179
+     *
180
+     * @Boolean $write - Write the changes if any
181
+     * @return void
182
+     */
183
+    public function CheckAndUpdateDestination( $write = false ){
184
+        $this->extend('beforeCheckAndUpdateDestination', $write);
185
+
186
+        if( $this->PageID && $this->Page() &&
187
+            $this->Page()->ClassName == 'RedirectorPage' &&
188
+            $this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' )
189
+        {
190
+            $this->PageID = $this->Page()->LinkToID;
191
+            if( $write ) {
192
+                $this->write();
193
+            }
194
+        }
195
+    }
196 196
 
197 197
     /**
198 198
      * Checks if the field is parable
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -31,37 +31,37 @@  discard block
 block discarded – undo
31 31
         'Page' => 'SiteTree'
32 32
     );
33 33
 
34
-    private static $summary_fields    = array( 'Phrase', 'PointsTo' );
35
-    private static $searchable_fields = array( 'Phrase' );
36
-    private static $singular_name	  = 'Automated Link';
34
+    private static $summary_fields    = array('Phrase', 'PointsTo');
35
+    private static $searchable_fields = array('Phrase');
36
+    private static $singular_name = 'Automated Link';
37 37
     private static $plural_name	      = 'Automated Links';
38 38
     private static $parsableFields    = array();
39 39
 
40
-    public function PointsTo(){
40
+    public function PointsTo() {
41 41
         return $this->Page()->Link();
42 42
     }
43 43
 
44
-    public function Title(){
44
+    public function Title() {
45 45
         return $this->Phrase;
46 46
     }
47 47
 
48
-    public function forTemplate(){
48
+    public function forTemplate() {
49 49
         return $this->getHTML();
50 50
     }
51 51
 
52
-    function canView( $member = false ){
52
+    function canView($member = false) {
53 53
         return Permission::check('AUTOMATEDLINK_VIEW');
54 54
     }
55 55
 
56
-    function canEdit( $member = false ){
56
+    function canEdit($member = false) {
57 57
         return Permission::check('AUTOMATEDLINK_EDIT');
58 58
     }
59 59
 
60
-    function canDelete( $member = false ){
60
+    function canDelete($member = false) {
61 61
         return Permission::check('AUTOMATEDLINK_DELETE');
62 62
     }
63 63
 
64
-    function canCreate( $member = false ){
64
+    function canCreate($member = false) {
65 65
         return Permission::check('AUTOMATEDLINK_CREATE');
66 66
     }
67 67
 
@@ -74,12 +74,12 @@  discard block
 block discarded – undo
74 74
        );
75 75
      }
76 76
 
77
-	public function requireDefaultRecords(){
77
+	public function requireDefaultRecords() {
78 78
 		parent::requireDefaultRecords();
79 79
 
80 80
 		// Update all links to redirector pages during dev/build
81
-		foreach( self::get() as $link ) {
82
-		    $link->CheckAndUpdateDestination( true );
81
+		foreach (self::get() as $link) {
82
+		    $link->CheckAndUpdateDestination(true);
83 83
 		}
84 84
 	}
85 85
 
@@ -180,15 +180,15 @@  discard block
 block discarded – undo
180 180
 	 * @Boolean $write - Write the changes if any
181 181
 	 * @return void
182 182
 	 */
183
-	public function CheckAndUpdateDestination( $write = false ){
183
+	public function CheckAndUpdateDestination($write = false) {
184 184
 		$this->extend('beforeCheckAndUpdateDestination', $write);
185 185
 
186
-		if( $this->PageID && $this->Page() &&
186
+		if ($this->PageID && $this->Page() &&
187 187
 			$this->Page()->ClassName == 'RedirectorPage' &&
188
-			$this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' )
188
+			$this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal')
189 189
 		{
190 190
 			$this->PageID = $this->Page()->LinkToID;
191
-			if( $write ) {
191
+			if ($write) {
192 192
 			    $this->write();
193 193
 			}
194 194
 		}
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      *
225 225
      * @return Boolean
226 226
      */
227
-    public function canBeAdded( ContentController $controller ){
228
-        return ( $this->SelfLinking || $controller->ID != $this->PageID );
227
+    public function canBeAdded(ContentController $controller) {
228
+        return ($this->SelfLinking || $controller->ID != $this->PageID);
229 229
     }
230 230
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -206,8 +206,9 @@
 block discarded – undo
206 206
         if (!isset(self::$parsableFields[$page->ID]) || !isset(self::$parsableFields[$page->ID][$field])) {
207 207
             $fields = array();
208 208
 
209
-            foreach (ClassInfo::ancestry($page->ClassName, true) as $class)
210
-                $fields = array_merge($fields, (array) DataObject::database_fields($class));
209
+            foreach (ClassInfo::ancestry($page->ClassName, true) as $class) {
210
+                            $fields = array_merge($fields, (array) DataObject::database_fields($class));
211
+            }
211 212
 
212 213
             self::$parsableFields[$page->ID][$field] =
213 214
                 (Boolean) array_key_exists($field, $fields) && strtolower($fields[$field]) === 'htmltext' && $page->$field;
Please login to merge, or discard this patch.
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 3 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -10,20 +10,20 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class GlobalAutoLinkSettings extends DataObject{
12 12
 
13
-	public static $enabled  = true;
13
+    public static $enabled  = true;
14 14
     public static $encoding = 'UTF-8';
15 15
 
16
-	private static $db = array(
17
-		'MaxLinksPerPage' => 'INT',
18
-		'ExcludeTags'	  => 'VARCHAR(255)',
19
-		'IncludeIn'		  => 'Text',
20
-		'AddTo'           => 'Text',
16
+    private static $db = array(
17
+        'MaxLinksPerPage' => 'INT',
18
+        'ExcludeTags'	  => 'VARCHAR(255)',
19
+        'IncludeIn'		  => 'Text',
20
+        'AddTo'           => 'Text',
21 21
         'CrawlID'         => 'VARCHAR(15)'
22
-	);
22
+    );
23 23
 
24
-	private static $defaults = array(
25
-		'IncludeIn' => 'Content'
26
-	);
24
+    private static $defaults = array(
25
+        'IncludeIn' => 'Content'
26
+    );
27 27
 
28 28
     public static $default_create_config = array(
29 29
         'MaxLinksPerPage' => 0,
@@ -31,13 +31,13 @@  discard block
 block discarded – undo
31 31
         'IncludeIn'		  => 'Content'
32 32
     );
33 33
 
34
-	public function ExcludeTags(){
35
-		return array_unique( explode( ',', str_replace( ' ', '', $this->ExcludeTags ).',a,img,iframe,video,object' ) );
36
-	}
34
+    public function ExcludeTags(){
35
+        return array_unique( explode( ',', str_replace( ' ', '', $this->ExcludeTags ).',a,img,iframe,video,object' ) );
36
+    }
37 37
 
38
-	public function IncludeInFields(){
39
-		return explode( ',', str_replace( ' ', '', $this->IncludeIn ) );
40
-	}
38
+    public function IncludeInFields(){
39
+        return explode( ',', str_replace( ' ', '', $this->IncludeIn ) );
40
+    }
41 41
 
42 42
     public function requireDefaultRecords() {
43 43
         $hasData = self::get()->first();
Please login to merge, or discard this 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.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -8,9 +8,9 @@  discard block
 block discarded – undo
8 8
  * on dev/build and contains all the global settings for the
9 9
  * automated links
10 10
  */
11
-class GlobalAutoLinkSettings extends DataObject{
11
+class GlobalAutoLinkSettings extends DataObject {
12 12
 
13
-	public static $enabled  = true;
13
+	public static $enabled = true;
14 14
     public static $encoding = 'UTF-8';
15 15
 
16 16
 	private static $db = array(
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
      *
37 37
      * @return array
38 38
      */
39
-	public function ExcludeTags(){
40
-		return array_unique( explode( ',', str_replace( ' ', '', $this->ExcludeTags ).',a,img,iframe,video,object' ) );
39
+	public function ExcludeTags() {
40
+		return array_unique(explode(',', str_replace(' ', '', $this->ExcludeTags).',a,img,iframe,video,object'));
41 41
 	}
42 42
 
43 43
     /**
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
      *
46 46
      * @return array
47 47
      */
48
-	public function IncludeInFields(){
49
-		return explode( ',', str_replace( ' ', '', $this->IncludeIn ) );
48
+	public function IncludeInFields() {
49
+		return explode(',', str_replace(' ', '', $this->IncludeIn));
50 50
 	}
51 51
 
52 52
     public function requireDefaultRecords() {
53 53
         $hasData = self::get()->first();
54
-        if(!$hasData) {
54
+        if (!$hasData) {
55 55
             $obj = self::create(self::$default_create_config);
56 56
             $obj->CrawlID = $this->createCrawlID();
57 57
             $obj->write();
58
-            DB::alteration_message("Added default Global Auto Link Settings","created");
59
-        } else{
60
-            if(!$hasData->CrawlID){
58
+            DB::alteration_message("Added default Global Auto Link Settings", "created");
59
+        }else {
60
+            if (!$hasData->CrawlID) {
61 61
                 $hasData->CrawlID = $this->createCrawlID();
62 62
                 $hasData->write();
63 63
             }
@@ -90,24 +90,24 @@  discard block
 block discarded – undo
90 90
      *
91 91
      * @return array
92 92
      */
93
-        public function AllowedIn(){
94
-        $classes = array_values( ClassInfo::subclassesFor( 'SiteTree' ) );
95
-        if( !$this->AddTo ) return $classes;
93
+        public function AllowedIn() {
94
+        $classes = array_values(ClassInfo::subclassesFor('SiteTree'));
95
+        if (!$this->AddTo) return $classes;
96 96
 
97
-        $sanitized = explode( ',', str_replace( ' ', '', strtolower( $this->AddTo ) ) );
97
+        $sanitized = explode(',', str_replace(' ', '', strtolower($this->AddTo)));
98 98
 
99
-        for( $x = 0; $x < count( $sanitized ); $x++ ){
99
+        for ($x = 0; $x < count($sanitized); $x++) {
100 100
             $found = false;
101 101
 
102
-            foreach( $classes as $class ){
103
-                if( strtolower( $class ) === $sanitized[$x] ){
102
+            foreach ($classes as $class) {
103
+                if (strtolower($class) === $sanitized[$x]) {
104 104
                     $sanitized[$x] = $class;
105 105
                     $found = true;
106 106
                     break 1;
107 107
                 }
108 108
             }
109 109
 
110
-            if( !$found ) unset( $sanitized[$x] );
110
+            if (!$found) unset($sanitized[$x]);
111 111
         }
112 112
 
113 113
         return (array) $sanitized;
Please login to merge, or discard this patch.
code/reports/AutomatedLinkReport.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * Automated Link Report is a report that lists all automated
8 8
  * links and how they affect the website
9 9
  */
10
-class AutomatedLinkReport extends SS_Report{
10
+class AutomatedLinkReport extends SS_Report {
11 11
 
12 12
     protected $title       = 'Automated Link Report';
13 13
     protected $description = 'Shows a list of all automated links and how they affect the site';
@@ -33,8 +33,8 @@  discard block
 block discarded – undo
33 33
         );
34 34
     }
35 35
 
36
-    public function sourceRecords( $params, $sort, $limit ){
37
-        if( !Config::inst()->get( $this->class, 'run_in_realtime' ) ) {
36
+    public function sourceRecords($params, $sort, $limit) {
37
+        if (!Config::inst()->get($this->class, 'run_in_realtime')) {
38 38
             return AutomatedLinkPageResult::get();
39 39
         }
40 40
 
Please login to merge, or discard this patch.
code/controllers/SEOTestSiteTreeController.php 2 patches
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -148,47 +148,47 @@
 block discarded – undo
148 148
     /**
149 149
      * @param string $data
150 150
      */
151
-    private function getHTMLFieldsData($data){
151
+    private function getHTMLFieldsData($data) {
152 152
         preg_match_all('/\[\*\*\[(.*?)\]\*\*\[(.*?)\]\*\*\]/im', $data, $matches);
153
-        foreach( $matches[2] as $key => $field_text ){
153
+        foreach ($matches[2] as $key => $field_text) {
154 154
             $matches[2][$key] = base64_decode($field_text);
155 155
             $matches[3][$key] = preg_replace('/[\s]+/mu', ' ', strip_tags($matches[2][$key]));
156 156
         }
157 157
         return $matches;
158 158
     }
159 159
 
160
-    public function loadPage($url, $agent=null){
160
+    public function loadPage($url, $agent = null) {
161 161
         $crawl_id = GlobalAutoLinkSettings::get_current()->CrawlID;
162 162
         $ch = curl_init();
163
-        curl_setopt( $ch, CURLOPT_URL, Director::absoluteBaseURL().'/'.$url );
164
-        curl_setopt( $ch, CURLOPT_HEADER, true );
165
-        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
166
-        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
167
-        curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
168
-        curl_setopt( $ch, CURLOPT_USERAGENT, $agent );
169
-        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
170
-        curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
171
-        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
172
-        curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'X-Crawl-Id: '.$crawl_id ) );
173
-        $data = curl_exec( $ch );
163
+        curl_setopt($ch, CURLOPT_URL, Director::absoluteBaseURL().'/'.$url);
164
+        curl_setopt($ch, CURLOPT_HEADER, true);
165
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
166
+        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
167
+        curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
168
+        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
169
+        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
170
+        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
171
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
172
+        curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Crawl-Id: '.$crawl_id));
173
+        $data = curl_exec($ch);
174 174
 
175 175
         $fetched        = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), PHP_URL_PATH);
176
-        $header_size    = curl_getinfo( $ch, CURLINFO_HEADER_SIZE );
177
-        $header 	    = explode( "\r\n\r\n", substr( $data, 0, $header_size ) );
178
-        array_pop( $header ); // Remove last element as it will always be empty
179
-        $header = array_pop( $header );
180
-        $body   = preg_replace('/[\s]+/mu', ' ', substr( $data, $header_size ));
176
+        $header_size    = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
177
+        $header = explode("\r\n\r\n", substr($data, 0, $header_size));
178
+        array_pop($header); // Remove last element as it will always be empty
179
+        $header = array_pop($header);
180
+        $body   = preg_replace('/[\s]+/mu', ' ', substr($data, $header_size));
181 181
 
182
-        curl_close( $ch );
182
+        curl_close($ch);
183 183
 
184
-        if( !strpos( $header, ' 200 ' ) ) {
185
-            return array( 'headers' => false, 'body' => false );
184
+        if (!strpos($header, ' 200 ')) {
185
+            return array('headers' => false, 'body' => false);
186 186
         }
187 187
 
188 188
         $field_data = $this->getHTMLFieldsData($body);
189 189
         $body = str_replace($field_data[0], $field_data[2], $body);
190 190
 
191
-        return array( 'headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched );
191
+        return array('headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched);
192 192
     }
193 193
 
194 194
     /**
Please login to merge, or discard this patch.
Braces   +15 added lines, -6 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(
@@ -120,8 +128,9 @@  discard block
 block discarded – undo
120 128
                 $phrases = array_merge($phrases, $matches[$commands['find_pos']]);
121 129
             }
122 130
 
123
-            if (isset($commands['replace']))
124
-                $html = preg_replace($commands['replace'], ' ', $html);
131
+            if (isset($commands['replace'])) {
132
+                            $html = preg_replace($commands['replace'], ' ', $html);
133
+            }
125 134
         }
126 135
 
127 136
         // Remove the empty elements
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.