Passed
Branch master (af9096)
by Dylan
03:47
created
code/controllers/SEOTestSiteTreeController.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -145,6 +145,9 @@
 block discarded – undo
145 145
         ));
146 146
     }
147 147
 
148
+    /**
149
+     * @param string $data
150
+     */
148 151
     private function getHTMLFieldsData($data){
149 152
         preg_match_all('/\[\*\*\[(.*?)\]\*\*\[(.*?)\]\*\*\]/im', $data, $matches);
150 153
         foreach( $matches[2] as $key => $field_text ){
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class SEOTestSiteTreeController extends Controller{
3
+class SEOTestSiteTreeController extends Controller {
4 4
 
5 5
     private static $sprite_path = null;
6 6
     private static $css         = null;
@@ -11,34 +11,34 @@  discard block
 block discarded – undo
11 11
     // Array of regex that will be used by the crawler. If the url we're going to crawl matches any filter in here, it will be ignored
12 12
     private static $ignore_paths = array();
13 13
 
14
-    private static $allowed_actions = array( 'urlsAndSettings', 'getPageData' );
14
+    private static $allowed_actions = array('urlsAndSettings', 'getPageData');
15 15
 
16
-    public function init(){
16
+    public function init() {
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');
20
+        if (!Member::currentUser()) return $this->redirect(Security::login_url().'?BackURL=/seotest');
21 21
         if (!Permission::check('CMS_ACCESS_SEOToolboxAdmin')) return $this->redirect(self::getPermissionDeniedPage()->Link());
22 22
 
23 23
         Requirements::clear();
24 24
 
25 25
         // Sprite Location needs to be dynamic as devs can install module in different locations
26 26
         $sprite_path = $this->config()->get('sprite_path');
27
-        if ($sprite_path === null) $sprite_path = SEOTOOLBOX_DIR . '/css/icons/icon_sprite.png';
27
+        if ($sprite_path === null) $sprite_path = SEOTOOLBOX_DIR.'/css/icons/icon_sprite.png';
28 28
         Requirements::customCSS(".icon{width:16px;height: 16px;cursor:pointer;background: url(/{$sprite_path});}");
29 29
 
30 30
         // CSS can be replaced by devs if they desire to change styling
31 31
         Requirements::css(SEOTOOLBOX_DIR.'/third-party/bootstrap/css/bootstrap.min.css');
32 32
         Requirements::css(SEOTOOLBOX_DIR.'/third-party/bootstrap/css/bootstrap-theme.min.css');
33 33
         $css = $this->config()->get('css');
34
-        if ($css === null) $css = array(SEOTOOLBOX_DIR . '/fonts/lato/lato.css', SEOTOOLBOX_DIR . '/css/seotest.css');
34
+        if ($css === null) $css = array(SEOTOOLBOX_DIR.'/fonts/lato/lato.css', SEOTOOLBOX_DIR.'/css/seotest.css');
35 35
         Requirements::combine_files('seotest.css', $css);
36 36
 
37 37
         Requirements::combine_files('seotest.js', array(
38
-            SEOTOOLBOX_DIR . '/third-party/jquery-1.12.0.js',
39
-            SEOTOOLBOX_DIR . '/js/crawler.js',
40
-            SEOTOOLBOX_DIR . '/js/default_tests.js',
41
-            SEOTOOLBOX_DIR . '/js/crawler_init.js'
38
+            SEOTOOLBOX_DIR.'/third-party/jquery-1.12.0.js',
39
+            SEOTOOLBOX_DIR.'/js/crawler.js',
40
+            SEOTOOLBOX_DIR.'/js/default_tests.js',
41
+            SEOTOOLBOX_DIR.'/js/crawler_init.js'
42 42
         ));
43 43
     }
44 44
 
@@ -59,28 +59,28 @@  discard block
 block discarded – undo
59 59
      * @param SS_HTTPRequest $request
60 60
      * @return String
61 61
      */
62
-    public function getPageData(SS_HTTPRequest $request){
63
-        $agent  = ( $request->getVar('agent') == 'mobile' )
62
+    public function getPageData(SS_HTTPRequest $request) {
63
+        $agent = ($request->getVar('agent') == 'mobile')
64 64
             ? $this->config()->get('mobile_user_agent')
65 65
             : $this->config()->get('desktop_user_agent');
66 66
 
67
-        $curl   = $this->loadPage($request->getVar('u'), $agent);
67
+        $curl = $this->loadPage($request->getVar('u'), $agent);
68 68
         $curl['phrases'] = $this->extractWords($curl['body']);
69 69
 
70 70
         Requirements::clear();
71 71
         return json_encode($curl);
72 72
     }
73 73
 
74
-    private function extractWords($html, $get_pure_word_count=false){
74
+    private function extractWords($html, $get_pure_word_count = false) {
75 75
         mb_internal_encoding('UTF-8');
76 76
         $html = preg_replace_callback(
77 77
             "/(&#[0-9]+;)/",
78
-            function($m){return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");},
78
+            function($m) {return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES"); },
79 79
             $html
80 80
         );
81 81
         $html = str_replace(array("\n", "\r"), ' ', mb_strtolower($html));
82 82
 
83
-        if( $get_pure_word_count ) return strip_tags($html);
83
+        if ($get_pure_word_count) return strip_tags($html);
84 84
 
85 85
         $phrases = array();
86 86
 
@@ -105,12 +105,12 @@  discard block
 block discarded – undo
105 105
             )
106 106
         );
107 107
 
108
-        foreach( $regex_find_replace as $commands ){
109
-            if(isset($commands['find'])){
110
-                preg_match_all( $commands['find'], $html, $matches );
111
-                array_walk($matches[$commands['find_pos']], function(&$phrase){
108
+        foreach ($regex_find_replace as $commands) {
109
+            if (isset($commands['find'])) {
110
+                preg_match_all($commands['find'], $html, $matches);
111
+                array_walk($matches[$commands['find_pos']], function(&$phrase) {
112 112
                     $words = explode(' ', strip_tags($phrase));
113
-                    array_walk($words, function(&$w){
113
+                    array_walk($words, function(&$w) {
114 114
                         $w = trim(preg_replace('/\s+/', ' ', strip_tags($w)));
115 115
                     });
116 116
                     $phrase = preg_replace('/\s+/', ' ', implode(' ', $words));
@@ -118,24 +118,24 @@  discard block
 block discarded – undo
118 118
                 $phrases = array_merge($phrases, $matches[$commands['find_pos']]);
119 119
             }
120 120
 
121
-            if(isset($commands['replace']))
121
+            if (isset($commands['replace']))
122 122
                 $html = preg_replace($commands['replace'], ' ', $html);
123 123
         }
124 124
 
125 125
         // Remove the empty elements
126
-        $phrases = array_filter($phrases, function($phrase){return strlen(trim($phrase)) > 0;});
126
+        $phrases = array_filter($phrases, function($phrase) {return strlen(trim($phrase)) > 0; });
127 127
         $count = 0;
128
-        foreach( $phrases as $p ) $count += count(explode(' ', $p));
128
+        foreach ($phrases as $p) $count += count(explode(' ', $p));
129 129
         return $phrases;
130 130
     }
131 131
 
132
-    public function urlsAndSettings( SS_HTTPRequest $request ){
132
+    public function urlsAndSettings(SS_HTTPRequest $request) {
133 133
         Requirements::clear();
134 134
         return json_encode(array(
135 135
             'urls' => Versioned::get_by_stage('SiteTree', 'Live')
136
-                ->exclude( 'ClassName', 'RedirectorPage' )
137
-                ->exclude( 'ClassName', 'ErrorPage' )
138
-                ->map( 'ID', 'AbsoluteLink' )
136
+                ->exclude('ClassName', 'RedirectorPage')
137
+                ->exclude('ClassName', 'ErrorPage')
138
+                ->map('ID', 'AbsoluteLink')
139 139
                 ->toArray(),
140 140
 
141 141
             'settings' => array(
@@ -145,45 +145,45 @@  discard block
 block discarded – undo
145 145
         ));
146 146
     }
147 147
 
148
-    private function getHTMLFieldsData($data){
148
+    private function getHTMLFieldsData($data) {
149 149
         preg_match_all('/\[\*\*\[(.*?)\]\*\*\[(.*?)\]\*\*\]/im', $data, $matches);
150
-        foreach( $matches[2] as $key => $field_text ){
150
+        foreach ($matches[2] as $key => $field_text) {
151 151
             $matches[2][$key] = base64_decode($field_text);
152 152
             $matches[3][$key] = preg_replace('/[\s]+/mu', ' ', strip_tags($matches[2][$key]));
153 153
         }
154 154
         return $matches;
155 155
     }
156 156
 
157
-    public function loadPage($url, $agent=null){
157
+    public function loadPage($url, $agent = null) {
158 158
         $crawl_id = GlobalAutoLinkSettings::get_current()->CrawlID;
159 159
         $ch = curl_init();
160
-        curl_setopt( $ch, CURLOPT_URL, Director::absoluteBaseURL().'/'.$url );
161
-        curl_setopt( $ch, CURLOPT_HEADER, true );
162
-        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
163
-        curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
164
-        curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
165
-        curl_setopt( $ch, CURLOPT_USERAGENT, $agent );
166
-        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 10 );
167
-        curl_setopt( $ch, CURLOPT_TIMEOUT, 30 );
168
-        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
169
-        curl_setopt( $ch, CURLOPT_HTTPHEADER, array( 'X-Crawl-Id: '.$crawl_id ) );
170
-        $data = curl_exec( $ch );
160
+        curl_setopt($ch, CURLOPT_URL, Director::absoluteBaseURL().'/'.$url);
161
+        curl_setopt($ch, CURLOPT_HEADER, true);
162
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
163
+        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
164
+        curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
165
+        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
166
+        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
167
+        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
168
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
169
+        curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Crawl-Id: '.$crawl_id));
170
+        $data = curl_exec($ch);
171 171
 
172 172
         $fetched        = parse_url(curl_getinfo($ch, CURLINFO_EFFECTIVE_URL), PHP_URL_PATH);
173
-        $header_size    = curl_getinfo( $ch, CURLINFO_HEADER_SIZE );
174
-        $header 	    = explode( "\r\n\r\n", substr( $data, 0, $header_size ) );
175
-        array_pop( $header ); // Remove last element as it will always be empty
176
-        $header = array_pop( $header );
177
-        $body   = preg_replace('/[\s]+/mu', ' ', substr( $data, $header_size ));
173
+        $header_size    = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
174
+        $header = explode("\r\n\r\n", substr($data, 0, $header_size));
175
+        array_pop($header); // Remove last element as it will always be empty
176
+        $header = array_pop($header);
177
+        $body   = preg_replace('/[\s]+/mu', ' ', substr($data, $header_size));
178 178
 
179
-        curl_close( $ch );
179
+        curl_close($ch);
180 180
 
181
-        if( !strpos( $header, ' 200 ' ) )return array( 'headers' => false, 'body' => false );
181
+        if (!strpos($header, ' 200 '))return array('headers' => false, 'body' => false);
182 182
 
183 183
         $field_data = $this->getHTMLFieldsData($body);
184 184
         $body = str_replace($field_data[0], $field_data[2], $body);
185 185
 
186
-        return array( 'headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched );
186
+        return array('headers' => $header, 'body' => $body, 'field_data' => $field_data, 'url_fetched' => $fetched);
187 187
     }
188 188
 
189 189
     /**
@@ -192,13 +192,13 @@  discard block
 block discarded – undo
192 192
      *
193 193
      * @return ErrorPage
194 194
      */
195
-    public static function getPermissionDeniedPage(){
196
-        $page = ErrorPage::get()->find( 'ErrorCode', 503 );
197
-        if( !$page ){
198
-            $page = ErrorPage::create( array(
195
+    public static function getPermissionDeniedPage() {
196
+        $page = ErrorPage::get()->find('ErrorCode', 503);
197
+        if (!$page) {
198
+            $page = ErrorPage::create(array(
199 199
                 'ErrorCode' => 503,
200 200
                 'Title'		=> 'Permission Denied'
201
-            ) );
201
+            ));
202 202
             $page->write();
203 203
         }
204 204
 
Please login to merge, or discard this 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/dataobjects/AutomatedLink.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -195,7 +195,7 @@
 block discarded – undo
195 195
      * Checks if the field is parable
196 196
      * 
197 197
      * @param SiteTree $page
198
-     * @param String   $fieldName
198
+     * @param String   $field
199 199
      * 
200 200
      * @return Boolean
201 201
      */
Please login to merge, or discard this patch.
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -10,45 +10,45 @@  discard block
 block discarded – undo
10 10
  */
11 11
 class AutomatedLink extends DataObject implements PermissionProvider{
12 12
 	
13
-	private static $db = array(
14
-		'Phrase'     	  => 'VARCHAR(255)',
15
-		'TitleTag'   	  => 'VARCHAR(255)',
16
-		'AnchorTag' 	  => 'VARCHAR(255)',
17
-		'NewWindow'  	  => 'Boolean',
18
-		'NoFollow'   	  => 'Boolean',
19
-		'SelfLinking'     => 'Boolean',
20
-		'CaseSensitive'   => 'Boolean',
21
-		'MaxLinksPerPage' => 'INT',
22
-		'Priority'		  => 'Int'
23
-	);
13
+    private static $db = array(
14
+        'Phrase'     	  => 'VARCHAR(255)',
15
+        'TitleTag'   	  => 'VARCHAR(255)',
16
+        'AnchorTag' 	  => 'VARCHAR(255)',
17
+        'NewWindow'  	  => 'Boolean',
18
+        'NoFollow'   	  => 'Boolean',
19
+        'SelfLinking'     => 'Boolean',
20
+        'CaseSensitive'   => 'Boolean',
21
+        'MaxLinksPerPage' => 'INT',
22
+        'Priority'		  => 'Int'
23
+    );
24 24
 	
25
-	private static $defaults = array(
26
-		'MaxLinksPerPage' => 10
27
-	);
25
+    private static $defaults = array(
26
+        'MaxLinksPerPage' => 10
27
+    );
28 28
 	
29
-	private static $default_sort = 'Priority';
29
+    private static $default_sort = 'Priority';
30 30
 	
31
-	private static $has_one = array(
32
-		'Page' => 'SiteTree'
33
-	);
31
+    private static $has_one = array(
32
+        'Page' => 'SiteTree'
33
+    );
34 34
 	
35
-	private static $summary_fields    = array( 'Phrase', 'PointsTo' );
36
-	private static $searchable_fields = array( 'Phrase' );
37
-	private static $singular_name	  = 'Automated Link';
38
-	private static $plural_name	      = 'Automated Links';
35
+    private static $summary_fields    = array( 'Phrase', 'PointsTo' );
36
+    private static $searchable_fields = array( 'Phrase' );
37
+    private static $singular_name	  = 'Automated Link';
38
+    private static $plural_name	      = 'Automated Links';
39 39
     private static $parsableFields    = array();
40 40
 
41 41
     public function PointsTo(){
42 42
         return $this->Page()->Link();
43 43
     }
44 44
 
45
-	public function Title(){
46
-		return $this->Phrase;
47
-	}
45
+    public function Title(){
46
+        return $this->Phrase;
47
+    }
48 48
 	
49
-	public function forTemplate(){
50
-		return $this->getHTML();
51
-	}
49
+    public function forTemplate(){
50
+        return $this->getHTML();
51
+    }
52 52
     
53 53
     function canView( $member = false ){
54 54
         return Permission::check('AUTOMATEDLINK_VIEW');
@@ -67,129 +67,129 @@  discard block
 block discarded – undo
67 67
     }
68 68
     
69 69
     function providePermissions() {
70
-       return array(
71
-         'AUTOMATEDLINK_VIEW'   => 'View Automated Links',
72
-         'AUTOMATEDLINK_EDIT'   => 'Edit Automated Links',
73
-         'AUTOMATEDLINK_DELETE' => 'Delete Automated Links',
74
-         'AUTOMATEDLINK_CREATE' => 'Create Automated Links',
75
-       );
76
-     }
70
+        return array(
71
+            'AUTOMATEDLINK_VIEW'   => 'View Automated Links',
72
+            'AUTOMATEDLINK_EDIT'   => 'Edit Automated Links',
73
+            'AUTOMATEDLINK_DELETE' => 'Delete Automated Links',
74
+            'AUTOMATEDLINK_CREATE' => 'Create Automated Links',
75
+        );
76
+        }
77 77
 	
78
-	public function requireDefaultRecords(){
79
-		parent::requireDefaultRecords();
78
+    public function requireDefaultRecords(){
79
+        parent::requireDefaultRecords();
80 80
 		
81
-		// Update all links to redirector pages during dev/build
82
-		foreach( self::get() as $link ) $link->CheckAndUpdateDestination( true );
83
-	}
81
+        // Update all links to redirector pages during dev/build
82
+        foreach( self::get() as $link ) $link->CheckAndUpdateDestination( true );
83
+    }
84 84
 	
85
-	/**
86
-	 * Returns the HTML Representation of this object
87
-	 * 
85
+    /**
86
+     * Returns the HTML Representation of this object
87
+     * 
88 88
      * @param  String $originalPhrase
89
-	 * @return String
90
-	 */
91
-	public function getHTML( $originalPhrase = NULL ){
92
-		$link     = ( $this->PageID )     ? $this->Page()->Link() 	    : '#';
93
-		$title    = ( $this->TitleTag )   ? "title='{$this->TitleTag}'" : '';
94
-		$nofollow = ( $this->NoFollow )   ? 'rel="nofollow"' 		    : '';
95
-		$newtab   = ( $this->NewWindow )  ? 'target="_blank"' 		    : '';
89
+     * @return String
90
+     */
91
+    public function getHTML( $originalPhrase = NULL ){
92
+        $link     = ( $this->PageID )     ? $this->Page()->Link() 	    : '#';
93
+        $title    = ( $this->TitleTag )   ? "title='{$this->TitleTag}'" : '';
94
+        $nofollow = ( $this->NoFollow )   ? 'rel="nofollow"' 		    : '';
95
+        $newtab   = ( $this->NewWindow )  ? 'target="_blank"' 		    : '';
96 96
         $anchor   = ( $originalPhrase )   ? $originalPhrase             : $this->Phrase;
97
-		$link     = ( $this->AnchorTag )  ? rtrim( $link, '#' ).'#'.$this->AnchorTag : $link;
98
-		return "<a href=\"$link\" $title $nofollow $newtab data-id=\"{$this->ID}\">{$anchor}</a>";
99
-	}
97
+        $link     = ( $this->AnchorTag )  ? rtrim( $link, '#' ).'#'.$this->AnchorTag : $link;
98
+        return "<a href=\"$link\" $title $nofollow $newtab data-id=\"{$this->ID}\">{$anchor}</a>";
99
+    }
100 100
 	
101
-	public function getCMSFields(){
102
-		$fields = FieldList::create( TabSet::create( 'Root' ) );
101
+    public function getCMSFields(){
102
+        $fields = FieldList::create( TabSet::create( 'Root' ) );
103 103
 				
104
-		$fields->addFieldsToTab( 'Root.LinkSettings', array(
105
-			TextField::create( 'Phrase', 'Phrase to search for', $this->Phrase, 255 ),
106
-			TextField::create( 'TitleTag', 'Title Tag', $this->TitleTag, 255 ),
107
-			TextField::create( 'AnchorTag', 'Anchor Tag(#)', $this->AnchorTag, 255 ),
108
-			FieldGroup::create(
109
-				CheckboxField::create( 'NoFollow' ),
110
-				CheckboxField::create( 'NewWindow' ),
111
-				CheckboxField::create( 'SelfLinking', 'Allow page to link to itself' ),
112
-				CheckboxField::create( 'CaseSensitive', 'Match the case of the phrase' )
113
-			),
114
-			NumericField::create( 'MaxLinksPerPage', 'Maximum amount of this link to be created on a single page( 0 = unlimited )' ),
115
-			TreeDropdownField::create( 'PageID', 'Page to link to', 'SiteTree' )
116
-		) );
104
+        $fields->addFieldsToTab( 'Root.LinkSettings', array(
105
+            TextField::create( 'Phrase', 'Phrase to search for', $this->Phrase, 255 ),
106
+            TextField::create( 'TitleTag', 'Title Tag', $this->TitleTag, 255 ),
107
+            TextField::create( 'AnchorTag', 'Anchor Tag(#)', $this->AnchorTag, 255 ),
108
+            FieldGroup::create(
109
+                CheckboxField::create( 'NoFollow' ),
110
+                CheckboxField::create( 'NewWindow' ),
111
+                CheckboxField::create( 'SelfLinking', 'Allow page to link to itself' ),
112
+                CheckboxField::create( 'CaseSensitive', 'Match the case of the phrase' )
113
+            ),
114
+            NumericField::create( 'MaxLinksPerPage', 'Maximum amount of this link to be created on a single page( 0 = unlimited )' ),
115
+            TreeDropdownField::create( 'PageID', 'Page to link to', 'SiteTree' )
116
+        ) );
117 117
 		
118
-		$settings = GlobalAutoLinkSettings::get_current();
119
-		if( $settings ){
120
-			$fields->addFieldsToTab( 'Root.Global', array(
121
-				NumericField::create( 
122
-					'Global_MaxLinksPerPage', 
123
-					'Maximum amount of links a single page can have ( 0 = unlimited )', 
124
-					$settings->MaxLinksPerPage 
125
-				),
126
-				TextField::create(
127
-					'Global_ExcludeTags',
128
-					'Do not include links into these HTML Tags ( comma seperated )',
129
-					$settings->ExcludeTags
130
-				),
131
-				TextField::create( 
132
-				    'Global_AddTo', 
133
-				    'Page types where links should be created in ( leave blank for all page types )',
134
-				    $settings->AddTo ),
135
-				TextField::create(
136
-					'Global_IncludeIn',
137
-					'Include Links into these fields ( comma seperated & field must support html injection )',
138
-					$settings->IncludeIn
139
-				)
140
-			) );
141
-		}
118
+        $settings = GlobalAutoLinkSettings::get_current();
119
+        if( $settings ){
120
+            $fields->addFieldsToTab( 'Root.Global', array(
121
+                NumericField::create( 
122
+                    'Global_MaxLinksPerPage', 
123
+                    'Maximum amount of links a single page can have ( 0 = unlimited )', 
124
+                    $settings->MaxLinksPerPage 
125
+                ),
126
+                TextField::create(
127
+                    'Global_ExcludeTags',
128
+                    'Do not include links into these HTML Tags ( comma seperated )',
129
+                    $settings->ExcludeTags
130
+                ),
131
+                TextField::create( 
132
+                    'Global_AddTo', 
133
+                    'Page types where links should be created in ( leave blank for all page types )',
134
+                    $settings->AddTo ),
135
+                TextField::create(
136
+                    'Global_IncludeIn',
137
+                    'Include Links into these fields ( comma seperated & field must support html injection )',
138
+                    $settings->IncludeIn
139
+                )
140
+            ) );
141
+        }
142 142
 		
143
-		return $fields;
144
-	}
143
+        return $fields;
144
+    }
145 145
 
146 146
     public function getCMSValidator(){
147 147
         return new RequiredFields( array( 'Phrase', 'PageID' ) );
148 148
     }
149 149
 	
150
-	/**
151
-	 * Save the Global Settings into the 
152
-	 * Global Auto Link Settings Object
153
-	 * 
154
-	 * @return void
155
-	 */
156
-	public function onBeforeWrite(){
157
-		parent::onBeforeWrite();
150
+    /**
151
+     * Save the Global Settings into the 
152
+     * Global Auto Link Settings Object
153
+     * 
154
+     * @return void
155
+     */
156
+    public function onBeforeWrite(){
157
+        parent::onBeforeWrite();
158 158
 		
159
-		$settings = GlobalAutoLinkSettings::get_current();
160
-		if( $settings ){
159
+        $settings = GlobalAutoLinkSettings::get_current();
160
+        if( $settings ){
161 161
 			
162
-			foreach( $this->getChangedFields() as $field => $value ){
163
-				if( strpos( $field, 'Global_' ) === 0 && isset( $value['after'] ) ){
164
-					$field = str_replace( 'Global_', '', $field );
165
-					$settings->$field = $value['after'];
166
-				}
167
-			}
162
+            foreach( $this->getChangedFields() as $field => $value ){
163
+                if( strpos( $field, 'Global_' ) === 0 && isset( $value['after'] ) ){
164
+                    $field = str_replace( 'Global_', '', $field );
165
+                    $settings->$field = $value['after'];
166
+                }
167
+            }
168 168
 
169
-			$settings->write();
170
-		}
169
+            $settings->write();
170
+        }
171 171
 		
172
-		$this->CheckAndUpdateDestination();
173
-	}
172
+        $this->CheckAndUpdateDestination();
173
+    }
174 174
     
175
-	/**
176
-	 * Checks if the destination is a redirector page if so
177
-	 * it updates it to the destination of the redirector page
178
-	 * 
179
-	 * @Boolean $write - Write the changes if any
180
-	 * @return void
181
-	 */
182
-	public function CheckAndUpdateDestination( $write = false ){
183
-		$this->extend('beforeCheckAndUpdateDestination', $write);
175
+    /**
176
+     * Checks if the destination is a redirector page if so
177
+     * it updates it to the destination of the redirector page
178
+     * 
179
+     * @Boolean $write - Write the changes if any
180
+     * @return void
181
+     */
182
+    public function CheckAndUpdateDestination( $write = false ){
183
+        $this->extend('beforeCheckAndUpdateDestination', $write);
184 184
 		
185
-		if( $this->PageID && $this->Page() && 
186
-			$this->Page()->ClassName == 'RedirectorPage' && 
187
-			$this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' )
188
-		{
189
-			$this->PageID = $this->Page()->LinkToID;
190
-			if( $write ) $this->write();
191
-		}
192
-	}
185
+        if( $this->PageID && $this->Page() && 
186
+            $this->Page()->ClassName == 'RedirectorPage' && 
187
+            $this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' )
188
+        {
189
+            $this->PageID = $this->Page()->LinkToID;
190
+            if( $write ) $this->write();
191
+        }
192
+    }
193 193
 	
194 194
     /**
195 195
      * Checks if the field is parable
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
      *
222 222
      * @return Boolean
223 223
      */
224
-	public function canBeAdded( ContentController $controller ){
224
+    public function canBeAdded( ContentController $controller ){
225 225
         return ( $this->SelfLinking || $controller->ID != $this->PageID );
226 226
     }
227 227
 }
Please login to merge, or discard this patch.
Spacing   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * Automated Link is a dataobject that contains all the data
9 9
  * about a link that should be created automatically to a page
10 10
  */
11
-class AutomatedLink extends DataObject implements PermissionProvider{
11
+class AutomatedLink extends DataObject implements PermissionProvider {
12 12
 	
13 13
 	private static $db = array(
14 14
 		'Phrase'     	  => 'VARCHAR(255)',
@@ -32,37 +32,37 @@  discard block
 block discarded – undo
32 32
 		'Page' => 'SiteTree'
33 33
 	);
34 34
 	
35
-	private static $summary_fields    = array( 'Phrase', 'PointsTo' );
36
-	private static $searchable_fields = array( 'Phrase' );
37
-	private static $singular_name	  = 'Automated Link';
35
+	private static $summary_fields    = array('Phrase', 'PointsTo');
36
+	private static $searchable_fields = array('Phrase');
37
+	private static $singular_name = 'Automated Link';
38 38
 	private static $plural_name	      = 'Automated Links';
39
-    private static $parsableFields    = array();
39
+    private static $parsableFields = array();
40 40
 
41
-    public function PointsTo(){
41
+    public function PointsTo() {
42 42
         return $this->Page()->Link();
43 43
     }
44 44
 
45
-	public function Title(){
45
+	public function Title() {
46 46
 		return $this->Phrase;
47 47
 	}
48 48
 	
49
-	public function forTemplate(){
49
+	public function forTemplate() {
50 50
 		return $this->getHTML();
51 51
 	}
52 52
     
53
-    function canView( $member = false ){
53
+    function canView($member = false) {
54 54
         return Permission::check('AUTOMATEDLINK_VIEW');
55 55
     }
56 56
     
57
-    function canEdit( $member = false ){
57
+    function canEdit($member = false) {
58 58
         return Permission::check('AUTOMATEDLINK_EDIT');
59 59
     }
60 60
     
61
-    function canDelete( $member = false ){
61
+    function canDelete($member = false) {
62 62
         return Permission::check('AUTOMATEDLINK_DELETE');
63 63
     }
64 64
     
65
-    function canCreate( $member = false ){
65
+    function canCreate($member = false) {
66 66
         return Permission::check('AUTOMATEDLINK_CREATE');
67 67
     }
68 68
     
@@ -75,11 +75,11 @@  discard block
 block discarded – undo
75 75
        );
76 76
      }
77 77
 	
78
-	public function requireDefaultRecords(){
78
+	public function requireDefaultRecords() {
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) $link->CheckAndUpdateDestination(true);
83 83
 	}
84 84
 	
85 85
 	/**
@@ -88,36 +88,36 @@  discard block
 block discarded – undo
88 88
      * @param  String $originalPhrase
89 89
 	 * @return String
90 90
 	 */
91
-	public function getHTML( $originalPhrase = NULL ){
92
-		$link     = ( $this->PageID )     ? $this->Page()->Link() 	    : '#';
93
-		$title    = ( $this->TitleTag )   ? "title='{$this->TitleTag}'" : '';
94
-		$nofollow = ( $this->NoFollow )   ? 'rel="nofollow"' 		    : '';
95
-		$newtab   = ( $this->NewWindow )  ? 'target="_blank"' 		    : '';
96
-        $anchor   = ( $originalPhrase )   ? $originalPhrase             : $this->Phrase;
97
-		$link     = ( $this->AnchorTag )  ? rtrim( $link, '#' ).'#'.$this->AnchorTag : $link;
91
+	public function getHTML($originalPhrase = NULL) {
92
+		$link     = ($this->PageID) ? $this->Page()->Link() : '#';
93
+		$title    = ($this->TitleTag) ? "title='{$this->TitleTag}'" : '';
94
+		$nofollow = ($this->NoFollow) ? 'rel="nofollow"' : '';
95
+		$newtab   = ($this->NewWindow) ? 'target="_blank"' : '';
96
+        $anchor = ($originalPhrase) ? $originalPhrase : $this->Phrase;
97
+		$link     = ($this->AnchorTag) ? rtrim($link, '#').'#'.$this->AnchorTag : $link;
98 98
 		return "<a href=\"$link\" $title $nofollow $newtab data-id=\"{$this->ID}\">{$anchor}</a>";
99 99
 	}
100 100
 	
101
-	public function getCMSFields(){
102
-		$fields = FieldList::create( TabSet::create( 'Root' ) );
101
+	public function getCMSFields() {
102
+		$fields = FieldList::create(TabSet::create('Root'));
103 103
 				
104
-		$fields->addFieldsToTab( 'Root.LinkSettings', array(
105
-			TextField::create( 'Phrase', 'Phrase to search for', $this->Phrase, 255 ),
106
-			TextField::create( 'TitleTag', 'Title Tag', $this->TitleTag, 255 ),
107
-			TextField::create( 'AnchorTag', 'Anchor Tag(#)', $this->AnchorTag, 255 ),
104
+		$fields->addFieldsToTab('Root.LinkSettings', array(
105
+			TextField::create('Phrase', 'Phrase to search for', $this->Phrase, 255),
106
+			TextField::create('TitleTag', 'Title Tag', $this->TitleTag, 255),
107
+			TextField::create('AnchorTag', 'Anchor Tag(#)', $this->AnchorTag, 255),
108 108
 			FieldGroup::create(
109
-				CheckboxField::create( 'NoFollow' ),
110
-				CheckboxField::create( 'NewWindow' ),
111
-				CheckboxField::create( 'SelfLinking', 'Allow page to link to itself' ),
112
-				CheckboxField::create( 'CaseSensitive', 'Match the case of the phrase' )
109
+				CheckboxField::create('NoFollow'),
110
+				CheckboxField::create('NewWindow'),
111
+				CheckboxField::create('SelfLinking', 'Allow page to link to itself'),
112
+				CheckboxField::create('CaseSensitive', 'Match the case of the phrase')
113 113
 			),
114
-			NumericField::create( 'MaxLinksPerPage', 'Maximum amount of this link to be created on a single page( 0 = unlimited )' ),
115
-			TreeDropdownField::create( 'PageID', 'Page to link to', 'SiteTree' )
116
-		) );
114
+			NumericField::create('MaxLinksPerPage', 'Maximum amount of this link to be created on a single page( 0 = unlimited )'),
115
+			TreeDropdownField::create('PageID', 'Page to link to', 'SiteTree')
116
+		));
117 117
 		
118 118
 		$settings = GlobalAutoLinkSettings::get_current();
119
-		if( $settings ){
120
-			$fields->addFieldsToTab( 'Root.Global', array(
119
+		if ($settings) {
120
+			$fields->addFieldsToTab('Root.Global', array(
121 121
 				NumericField::create( 
122 122
 					'Global_MaxLinksPerPage', 
123 123
 					'Maximum amount of links a single page can have ( 0 = unlimited )', 
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
 					'Include Links into these fields ( comma seperated & field must support html injection )',
138 138
 					$settings->IncludeIn
139 139
 				)
140
-			) );
140
+			));
141 141
 		}
142 142
 		
143 143
 		return $fields;
144 144
 	}
145 145
 
146
-    public function getCMSValidator(){
147
-        return new RequiredFields( array( 'Phrase', 'PageID' ) );
146
+    public function getCMSValidator() {
147
+        return new RequiredFields(array('Phrase', 'PageID'));
148 148
     }
149 149
 	
150 150
 	/**
@@ -153,15 +153,15 @@  discard block
 block discarded – undo
153 153
 	 * 
154 154
 	 * @return void
155 155
 	 */
156
-	public function onBeforeWrite(){
156
+	public function onBeforeWrite() {
157 157
 		parent::onBeforeWrite();
158 158
 		
159 159
 		$settings = GlobalAutoLinkSettings::get_current();
160
-		if( $settings ){
160
+		if ($settings) {
161 161
 			
162
-			foreach( $this->getChangedFields() as $field => $value ){
163
-				if( strpos( $field, 'Global_' ) === 0 && isset( $value['after'] ) ){
164
-					$field = str_replace( 'Global_', '', $field );
162
+			foreach ($this->getChangedFields() as $field => $value) {
163
+				if (strpos($field, 'Global_') === 0 && isset($value['after'])) {
164
+					$field = str_replace('Global_', '', $field);
165 165
 					$settings->$field = $value['after'];
166 166
 				}
167 167
 			}
@@ -179,15 +179,15 @@  discard block
 block discarded – undo
179 179
 	 * @Boolean $write - Write the changes if any
180 180
 	 * @return void
181 181
 	 */
182
-	public function CheckAndUpdateDestination( $write = false ){
182
+	public function CheckAndUpdateDestination($write = false) {
183 183
 		$this->extend('beforeCheckAndUpdateDestination', $write);
184 184
 		
185
-		if( $this->PageID && $this->Page() && 
185
+		if ($this->PageID && $this->Page() && 
186 186
 			$this->Page()->ClassName == 'RedirectorPage' && 
187
-			$this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal' )
187
+			$this->Page()->LinkToID && $this->Page()->RedirectionType == 'Internal')
188 188
 		{
189 189
 			$this->PageID = $this->Page()->LinkToID;
190
-			if( $write ) $this->write();
190
+			if ($write) $this->write();
191 191
 		}
192 192
 	}
193 193
 	
@@ -199,15 +199,15 @@  discard block
 block discarded – undo
199 199
      * 
200 200
      * @return Boolean
201 201
      */
202
-    public static function isFieldParsable( SiteTree $page, $field ){
203
-        if( !isset( self::$parsableFields[$page->ID] ) || !isset( self::$parsableFields[$page->ID][$field] ) ){
202
+    public static function isFieldParsable(SiteTree $page, $field) {
203
+        if (!isset(self::$parsableFields[$page->ID]) || !isset(self::$parsableFields[$page->ID][$field])) {
204 204
             $fields = array();
205 205
             
206
-            foreach( ClassInfo::ancestry( $page->ClassName, true ) as $class )
207
-                $fields = array_merge( $fields, (array) DataObject::database_fields( $class ) );
206
+            foreach (ClassInfo::ancestry($page->ClassName, true) as $class)
207
+                $fields = array_merge($fields, (array) DataObject::database_fields($class));
208 208
             
209 209
             self::$parsableFields[$page->ID][$field] = 
210
-                (Boolean) array_key_exists( $field, $fields ) && strtolower( $fields[$field] ) === 'htmltext' && $page->$field;
210
+                (Boolean) array_key_exists($field, $fields) && strtolower($fields[$field]) === 'htmltext' && $page->$field;
211 211
         }
212 212
         
213 213
         return self::$parsableFields[$page->ID][$field];
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
      *
222 222
      * @return Boolean
223 223
      */
224
-	public function canBeAdded( ContentController $controller ){
225
-        return ( $this->SelfLinking || $controller->ID != $this->PageID );
224
+	public function canBeAdded(ContentController $controller) {
225
+        return ($this->SelfLinking || $controller->ID != $this->PageID);
226 226
     }
227 227
 }
Please login to merge, or discard this 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/logic/GridFieldExportAllAutomatedLinksButton.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 block discarded – undo
5 5
 * Generate export fields for CSV. 
6 6
 * 
7 7
 * @param GridField $gridField 
8
-* @return array 
8
+* @return string 
9 9
 * 
10 10
 * ---------- 
11 11
 * replaces definition in GridFieldExportButton 
Please login to merge, or discard this patch.
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php 
2 2
 if (!class_exists('GridFieldExportAllAutomatedLinksButton')) {
3
-	class GridFieldExportAllAutomatedLinksButton extends GridFieldExportButton {
3
+    class GridFieldExportAllAutomatedLinksButton extends GridFieldExportButton {
4 4
 /** 
5 5
 * Generate export fields for CSV. 
6 6
 * 
@@ -14,44 +14,44 @@  discard block
 block discarded – undo
14 14
 * 
15 15
 */ 
16 16
 public function generateExportFileData($gridField) { 
17
-	$separator = $this->csvSeparator; 
18
-	$csvColumns =$gridField->getColumns();
19
-	$fileData = ''; 
20
-	$columnData = array(); 
21
-	$fieldItems = new ArrayList();
22
-	if($this->csvHasHeader) {
23
-		$headers = array();
17
+    $separator = $this->csvSeparator; 
18
+    $csvColumns =$gridField->getColumns();
19
+    $fileData = ''; 
20
+    $columnData = array(); 
21
+    $fieldItems = new ArrayList();
22
+    if($this->csvHasHeader) {
23
+        $headers = array();
24 24
 // determine the CSV headers. If a field is callable (e.g. anonymous function) then use the 
25 25
 // source name as the header instead 
26
-		foreach($csvColumns as $columnSource => $columnHeader) {
27
-			$headers[] = (!is_string($columnHeader) && is_callable($columnHeader)) ? $columnSource : $columnHeader; 
28
-		}
29
-		$fileData .= "\"" . implode("\"{$separator}\"", array_values($headers)) . "\""; 
30
-		$fileData .= "\n";
31
-	}
26
+        foreach($csvColumns as $columnSource => $columnHeader) {
27
+            $headers[] = (!is_string($columnHeader) && is_callable($columnHeader)) ? $columnSource : $columnHeader; 
28
+        }
29
+        $fileData .= "\"" . implode("\"{$separator}\"", array_values($headers)) . "\""; 
30
+        $fileData .= "\n";
31
+    }
32 32
 // ----------------------- 
33 33
 //$items = $gridField->getManipulatedList(); 
34 34
 
35
-	$items = $gridField->getList(); 
35
+    $items = $gridField->getList(); 
36 36
 // -----------------------
37 37
 // @todo should GridFieldComponents change behaviour based on whether others are available in the config? 
38
-	foreach($gridField->getConfig()->getComponents() as $component){ 
39
-		if($component instanceof GridFieldFilterHeader || $component instanceof GridFieldSortableHeader) { 
40
-			$items = $component->getManipulatedData($gridField, $items); 
41
-		} 
42
-	}
43
-	foreach($items->limit(null) as $item) { 
44
-		$columnData = array();
45
-		foreach($csvColumns as $columnSource => $columnHeader) { 
46
-			$value = ( $item->hasMethod( $columnHeader ) ) ? $item->$columnHeader() : $item->$columnHeader;
47
-			$value = str_replace(array("\r", "\n"), "\n", $value); 
48
-			$columnData[] = '"' . str_replace('"', '\"', $value) . '"'; 
49
-		}
50
-		$fileData .= implode($separator, $columnData); 
51
-		$fileData .= "\n";
52
-		$item->destroy(); 
53
-	}
54
-	return $fileData; 
38
+    foreach($gridField->getConfig()->getComponents() as $component){ 
39
+        if($component instanceof GridFieldFilterHeader || $component instanceof GridFieldSortableHeader) { 
40
+            $items = $component->getManipulatedData($gridField, $items); 
41
+        } 
42
+    }
43
+    foreach($items->limit(null) as $item) { 
44
+        $columnData = array();
45
+        foreach($csvColumns as $columnSource => $columnHeader) { 
46
+            $value = ( $item->hasMethod( $columnHeader ) ) ? $item->$columnHeader() : $item->$columnHeader;
47
+            $value = str_replace(array("\r", "\n"), "\n", $value); 
48
+            $columnData[] = '"' . str_replace('"', '\"', $value) . '"'; 
49
+        }
50
+        $fileData .= implode($separator, $columnData); 
51
+        $fileData .= "\n";
52
+        $item->destroy(); 
53
+    }
54
+    return $fileData; 
55 55
 }
56 56
 } // end class GridFieldExportAllButton
57 57
 } 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -15,18 +15,18 @@  discard block
 block discarded – undo
15 15
 */ 
16 16
 public function generateExportFileData($gridField) { 
17 17
 	$separator = $this->csvSeparator; 
18
-	$csvColumns =$gridField->getColumns();
18
+	$csvColumns = $gridField->getColumns();
19 19
 	$fileData = ''; 
20 20
 	$columnData = array(); 
21 21
 	$fieldItems = new ArrayList();
22
-	if($this->csvHasHeader) {
22
+	if ($this->csvHasHeader) {
23 23
 		$headers = array();
24 24
 // determine the CSV headers. If a field is callable (e.g. anonymous function) then use the 
25 25
 // source name as the header instead 
26
-		foreach($csvColumns as $columnSource => $columnHeader) {
26
+		foreach ($csvColumns as $columnSource => $columnHeader) {
27 27
 			$headers[] = (!is_string($columnHeader) && is_callable($columnHeader)) ? $columnSource : $columnHeader; 
28 28
 		}
29
-		$fileData .= "\"" . implode("\"{$separator}\"", array_values($headers)) . "\""; 
29
+		$fileData .= "\"".implode("\"{$separator}\"", array_values($headers))."\""; 
30 30
 		$fileData .= "\n";
31 31
 	}
32 32
 // ----------------------- 
@@ -35,17 +35,17 @@  discard block
 block discarded – undo
35 35
 	$items = $gridField->getList(); 
36 36
 // -----------------------
37 37
 // @todo should GridFieldComponents change behaviour based on whether others are available in the config? 
38
-	foreach($gridField->getConfig()->getComponents() as $component){ 
39
-		if($component instanceof GridFieldFilterHeader || $component instanceof GridFieldSortableHeader) { 
38
+	foreach ($gridField->getConfig()->getComponents() as $component) { 
39
+		if ($component instanceof GridFieldFilterHeader || $component instanceof GridFieldSortableHeader) { 
40 40
 			$items = $component->getManipulatedData($gridField, $items); 
41 41
 		} 
42 42
 	}
43
-	foreach($items->limit(null) as $item) { 
43
+	foreach ($items->limit(null) as $item) { 
44 44
 		$columnData = array();
45
-		foreach($csvColumns as $columnSource => $columnHeader) { 
46
-			$value = ( $item->hasMethod( $columnHeader ) ) ? $item->$columnHeader() : $item->$columnHeader;
45
+		foreach ($csvColumns as $columnSource => $columnHeader) { 
46
+			$value = ($item->hasMethod($columnHeader)) ? $item->$columnHeader() : $item->$columnHeader;
47 47
 			$value = str_replace(array("\r", "\n"), "\n", $value); 
48
-			$columnData[] = '"' . str_replace('"', '\"', $value) . '"'; 
48
+			$columnData[] = '"'.str_replace('"', '\"', $value).'"'; 
49 49
 		}
50 50
 		$fileData .= implode($separator, $columnData); 
51 51
 		$fileData .= "\n";
Please login to merge, or discard this patch.
code/forms/SEOToolboxAnalyzerField.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-class SEOToolboxAnalyzerField extends LiteralField{
3
+class SEOToolboxAnalyzerField extends LiteralField {
4 4
 
5
-    public function __construct($name, $url){
5
+    public function __construct($name, $url) {
6 6
         $content = $this->createBaseHTML($name, $url);
7 7
         parent::__construct($name, $content);
8 8
     }
9 9
 
10
-    private function createBaseHTML($name, $url){
10
+    private function createBaseHTML($name, $url) {
11 11
         $div    = "<div id='seotoolbox_con_{$name}'><div class='clearfix result_cont'></div></div>";
12 12
         $script = "<script type='text/javascript'>
13 13
                     (function(\$){new PageAnalyzer(\$('#seotoolbox_con_{$name} .result_cont'),'{$url}')}(jQuery))
Please login to merge, or discard this patch.
code/logic/GridFieldPrintAllAutomatedLinksButton.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php 
2 2
 if (!class_exists('GridFieldPrintAllAutomatedLinksButton')) {
3
-	class GridFieldPrintAllAutomatedLinksButton extends GridFieldPrintButton {
3
+    class GridFieldPrintAllAutomatedLinksButton extends GridFieldPrintButton {
4 4
 /** 
5 5
 * Export core. 
6 6
 * 
@@ -13,42 +13,42 @@  discard block
 block discarded – undo
13 13
 * 
14 14
 */ 
15 15
 public function generatePrintData(GridField $gridField) { 
16
-	$printColumns = $this->getPrintColumnsForGridField($gridField);
17
-	$header = null;
18
-	if($this->printHasHeader) { 
19
-		$header = new ArrayList();
20
-		foreach($printColumns as $field => $label){ 
21
-			$header->push(new ArrayData(array( 
22
-				"CellString" => $label, 
23
-				))); 
24
-		} 
25
-	}
16
+    $printColumns = $this->getPrintColumnsForGridField($gridField);
17
+    $header = null;
18
+    if($this->printHasHeader) { 
19
+        $header = new ArrayList();
20
+        foreach($printColumns as $field => $label){ 
21
+            $header->push(new ArrayData(array( 
22
+                "CellString" => $label, 
23
+                ))); 
24
+        } 
25
+    }
26 26
 // ----------------------- 
27 27
 //$items = $gridField->getManipulatedList(); 
28
-	$items = $gridField->getList(); 
28
+    $items = $gridField->getList(); 
29 29
 // -----------------------
30
-	$itemRows = new ArrayList();
31
-	foreach($items as $item) { 
32
-		$itemRow = new ArrayList();
33
-		foreach($printColumns as $field => $label) { 
34
-			$value = $gridField->getDataFieldValue($item, $field);
35
-			$itemRow->push(new ArrayData(array( 
36
-				"CellString" => $value, 
37
-				))); 
38
-		}
39
-		$itemRows->push(new ArrayData(array( 
40
-			"ItemRow" => $itemRow 
41
-			)));
42
-		$item->destroy(); 
43
-	}
44
-	$ret = new ArrayData(array( 
45
-		"Title" => $this->getTitle($gridField), 
46
-		"Header" => $header, 
47
-		"ItemRows" => $itemRows, 
48
-		"Datetime" => SS_Datetime::now(), 
49
-		"Member" => Member::currentUser(), 
50
-		));
51
-	return $ret;
30
+    $itemRows = new ArrayList();
31
+    foreach($items as $item) { 
32
+        $itemRow = new ArrayList();
33
+        foreach($printColumns as $field => $label) { 
34
+            $value = $gridField->getDataFieldValue($item, $field);
35
+            $itemRow->push(new ArrayData(array( 
36
+                "CellString" => $value, 
37
+                ))); 
38
+        }
39
+        $itemRows->push(new ArrayData(array( 
40
+            "ItemRow" => $itemRow 
41
+            )));
42
+        $item->destroy(); 
43
+    }
44
+    $ret = new ArrayData(array( 
45
+        "Title" => $this->getTitle($gridField), 
46
+        "Header" => $header, 
47
+        "ItemRows" => $itemRows, 
48
+        "Datetime" => SS_Datetime::now(), 
49
+        "Member" => Member::currentUser(), 
50
+        ));
51
+    return $ret;
52 52
 } 
53 53
 } // end class GridFieldPrintAllButton
54 54
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@  discard block
 block discarded – undo
15 15
 public function generatePrintData(GridField $gridField) { 
16 16
 	$printColumns = $this->getPrintColumnsForGridField($gridField);
17 17
 	$header = null;
18
-	if($this->printHasHeader) { 
18
+	if ($this->printHasHeader) { 
19 19
 		$header = new ArrayList();
20
-		foreach($printColumns as $field => $label){ 
20
+		foreach ($printColumns as $field => $label) { 
21 21
 			$header->push(new ArrayData(array( 
22 22
 				"CellString" => $label, 
23 23
 				))); 
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
 	$items = $gridField->getList(); 
29 29
 // -----------------------
30 30
 	$itemRows = new ArrayList();
31
-	foreach($items as $item) { 
31
+	foreach ($items as $item) { 
32 32
 		$itemRow = new ArrayList();
33
-		foreach($printColumns as $field => $label) { 
33
+		foreach ($printColumns as $field => $label) { 
34 34
 			$value = $gridField->getDataFieldValue($item, $field);
35 35
 			$itemRow->push(new ArrayData(array( 
36 36
 				"CellString" => $value, 
Please login to merge, or discard this patch.
code/dataobjects/AutomatedLinkPageResult.php 2 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class AutomatedLinkPageResult extends DataObject{
3
+class AutomatedLinkPageResult extends DataObject {
4 4
 
5 5
     private static $db = array(
6 6
         'OriginalLinkCount' => 'INT',
@@ -22,25 +22,25 @@  discard block
 block discarded – undo
22 22
     );
23 23
 
24 24
     // Disable all permissions to this object no one needs to touch it except the code itself
25
-    public function canView($member = null){return true;}
26
-    public function canEdit($member = null){return false;}
27
-    public function canDelete($member = null){return false;}
28
-    public function canCreate($member = null){return false;}
25
+    public function canView($member = null) {return true; }
26
+    public function canEdit($member = null) {return false; }
27
+    public function canDelete($member = null) {return false; }
28
+    public function canCreate($member = null) {return false; }
29 29
 
30
-    public function Title(){
30
+    public function Title() {
31 31
         return $this->Page()->Title;
32 32
     }
33 33
 
34
-    public function URLSegment(){
34
+    public function URLSegment() {
35 35
         return $this->Page()->Link();
36 36
     }
37 37
 
38
-    public function LinkCount(){
38
+    public function LinkCount() {
39 39
         return $this->LinksCreatedCount;
40 40
     }
41 41
 
42
-    public function TotalLinks(){
43
-        return $this->OriginalLinkCount + $this->LinksCreatedCount;
42
+    public function TotalLinks() {
43
+        return $this->OriginalLinkCount+$this->LinksCreatedCount;
44 44
     }
45 45
 
46 46
     /**
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
      * @param SiteTree $page
51 51
      * @return void
52 52
      */
53
-    public static function add_or_update( SiteTree $page ){
54
-        $obj = self::get()->find( 'PageID', $page->ID );
55
-        if( !$obj ) $obj = self::create( array( 'PageID' => $page->ID ) );
53
+    public static function add_or_update(SiteTree $page) {
54
+        $obj = self::get()->find('PageID', $page->ID);
55
+        if (!$obj) $obj = self::create(array('PageID' => $page->ID));
56 56
 
57 57
         $obj->OriginalLinkCount = $page->OriginalLinkCount;
58 58
         $obj->LinksCreatedCount = $page->LinkCount;
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      *
68 68
      * @return void
69 69
      */
70
-    public static function remove_old_data(){
71
-        foreach( self::get() as $obj ) if( !SiteTree::get()->byID( $obj->PageID ) ) $obj->delete();
70
+    public static function remove_old_data() {
71
+        foreach (self::get() as $obj) if (!SiteTree::get()->byID($obj->PageID)) $obj->delete();
72 72
     }
73 73
 }
Please login to merge, or discard this 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   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -11,20 +11,20 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class GlobalAutoLinkSettings extends DataObject{
13 13
 	
14
-	public static $enabled  = true;
14
+    public static $enabled  = true;
15 15
     public static $encoding = 'UTF-8';
16 16
 	
17
-	private static $db = array(
18
-		'MaxLinksPerPage' => 'INT',
19
-		'ExcludeTags'	  => 'VARCHAR(255)',
20
-		'IncludeIn'		  => 'Text',
21
-		'AddTo'           => 'Text',
17
+    private static $db = array(
18
+        'MaxLinksPerPage' => 'INT',
19
+        'ExcludeTags'	  => 'VARCHAR(255)',
20
+        'IncludeIn'		  => 'Text',
21
+        'AddTo'           => 'Text',
22 22
         'CrawlID'         => 'VARCHAR(15)'
23
-	);
23
+    );
24 24
 	
25
-	private static $defaults = array(
26
-		'IncludeIn' => 'Content'
27
-	);
25
+    private static $defaults = array(
26
+        'IncludeIn' => 'Content'
27
+    );
28 28
 
29 29
     public static $default_create_config = array(
30 30
         'MaxLinksPerPage' => 0,
@@ -32,13 +32,13 @@  discard block
 block discarded – undo
32 32
         'IncludeIn'		  => 'Content'
33 33
     );
34 34
 	
35
-	public function ExcludeTags(){
36
-		return array_unique( explode( ',', str_replace( ' ', '', $this->ExcludeTags ).',a,img,iframe,video,object' ) );
37
-	}
35
+    public function ExcludeTags(){
36
+        return array_unique( explode( ',', str_replace( ' ', '', $this->ExcludeTags ).',a,img,iframe,video,object' ) );
37
+    }
38 38
 	
39
-	public function IncludeInFields(){
40
-		return explode( ',', str_replace( ' ', '', $this->IncludeIn ) );
41
-	}
39
+    public function IncludeInFields(){
40
+        return explode( ',', str_replace( ' ', '', $this->IncludeIn ) );
41
+    }
42 42
 
43 43
     public function requireDefaultRecords() {
44 44
         $hasData = self::get()->first();
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
      * 
77 77
      * @return array
78 78
      */
79
-     public function AllowedIn(){
79
+        public function AllowedIn(){
80 80
         $classes = array_values( ClassInfo::subclassesFor( 'SiteTree' ) );
81 81
         if( !$this->AddTo ) return $classes;
82 82
         
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
         }
98 98
         
99 99
         return (array) $sanitized;
100
-     }
100
+        }
101 101
 
102 102
     /**
103 103
      * Gets the current config
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -9,9 +9,9 @@  discard block
 block discarded – undo
9 9
  * on dev/build and contains all the global settings for the 
10 10
  * automated links
11 11
  */
12
-class GlobalAutoLinkSettings extends DataObject{
12
+class GlobalAutoLinkSettings extends DataObject {
13 13
 	
14
-	public static $enabled  = true;
14
+	public static $enabled = true;
15 15
     public static $encoding = 'UTF-8';
16 16
 	
17 17
 	private static $db = array(
@@ -32,23 +32,23 @@  discard block
 block discarded – undo
32 32
         'IncludeIn'		  => 'Content'
33 33
     );
34 34
 	
35
-	public function ExcludeTags(){
36
-		return array_unique( explode( ',', str_replace( ' ', '', $this->ExcludeTags ).',a,img,iframe,video,object' ) );
35
+	public function ExcludeTags() {
36
+		return array_unique(explode(',', str_replace(' ', '', $this->ExcludeTags).',a,img,iframe,video,object'));
37 37
 	}
38 38
 	
39
-	public function IncludeInFields(){
40
-		return explode( ',', str_replace( ' ', '', $this->IncludeIn ) );
39
+	public function IncludeInFields() {
40
+		return explode(',', str_replace(' ', '', $this->IncludeIn));
41 41
 	}
42 42
 
43 43
     public function requireDefaultRecords() {
44 44
         $hasData = self::get()->first();
45
-        if(!$hasData) {
45
+        if (!$hasData) {
46 46
             $obj = self::create(self::$default_create_config);
47 47
             $obj->CrawlID = $this->createCrawlID();
48 48
             $obj->write();
49
-            DB::alteration_message("Added default records to $className table","created");
50
-        }else{
51
-            if(!$hasData->CrawlID){
49
+            DB::alteration_message("Added default records to $className table", "created");
50
+        }else {
51
+            if (!$hasData->CrawlID) {
52 52
                 $hasData->CrawlID = $this->createCrawlID();
53 53
                 $hasData->write();
54 54
             }
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
         parent::requireDefaultRecords();
58 58
     }
59 59
 
60
-    private function createCrawlID(){
60
+    private function createCrawlID() {
61 61
         $ret   = '';
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
         return $ret;
69 69
     }
@@ -76,24 +76,24 @@  discard block
 block discarded – undo
76 76
      * 
77 77
      * @return array
78 78
      */
79
-     public function AllowedIn(){
80
-        $classes = array_values( ClassInfo::subclassesFor( 'SiteTree' ) );
81
-        if( !$this->AddTo ) return $classes;
79
+     public function AllowedIn() {
80
+        $classes = array_values(ClassInfo::subclassesFor('SiteTree'));
81
+        if (!$this->AddTo) return $classes;
82 82
         
83
-        $sanitized = explode( ',', str_replace( ' ', '', strtolower( $this->AddTo ) ) );
83
+        $sanitized = explode(',', str_replace(' ', '', strtolower($this->AddTo)));
84 84
         
85
-        for( $x = 0; $x < count( $sanitized ); $x++ ){
85
+        for ($x = 0; $x < count($sanitized); $x++) {
86 86
             $found = false;
87 87
             
88
-            foreach( $classes as $class ){
89
-                if( strtolower( $class ) === $sanitized[$x] ){
88
+            foreach ($classes as $class) {
89
+                if (strtolower($class) === $sanitized[$x]) {
90 90
                     $sanitized[$x] = $class;
91 91
                     $found = true;
92 92
                     break 1;
93 93
                 }
94 94
             }
95 95
             
96
-            if( !$found ) unset( $sanitized[$x] );
96
+            if (!$found) unset($sanitized[$x]);
97 97
         }
98 98
         
99 99
         return (array) $sanitized;
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
      * @throws \ValidationException
107 107
      * @throws null
108 108
      */
109
-    public static function get_current(){
109
+    public static function get_current() {
110 110
         $obj = self::get()->first();
111
-        if( !$obj ){
111
+        if (!$obj) {
112 112
             self::create(self::$default_create_config)->write();
113 113
             self::flush_and_destroy_cache();
114 114
         }
Please login to merge, or discard this 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/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.
code/controllers/AutomatedLinkReportTask.php 2 patches
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -1,14 +1,14 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class AutomatedLinkReportTask extends Controller{
3
+class AutomatedLinkReportTask extends Controller {
4 4
 
5 5
     private   $GlobalSettings;
6 6
     private   $Links;
7 7
 
8
-    private static $exclude_classes = array( 'RedirectorPage', 'VirtualPage' );
8
+    private static $exclude_classes = array('RedirectorPage', 'VirtualPage');
9 9
 
10
-    public function index(){
11
-        if( !Director::is_cli() ) return 'Please run this controller in CLI';
10
+    public function index() {
11
+        if (!Director::is_cli()) return 'Please run this controller in CLI';
12 12
 
13 13
         libxml_use_internal_errors(true);
14 14
         set_time_limit(600);
@@ -25,34 +25,34 @@  discard block
 block discarded – undo
25 25
      * @see AutomatedLinkPageResult
26 26
      * @return ArrayList
27 27
      */
28
-    public function checkLinks(){
28
+    public function checkLinks() {
29 29
         $data = ArrayList::create();
30 30
 
31
-        $run_in_realtime = Config::inst()->get( 'AutomatedLinkReport', 'run_in_realtime' );
31
+        $run_in_realtime = Config::inst()->get('AutomatedLinkReport', 'run_in_realtime');
32 32
 
33 33
         // Enable this since we will need to render the pages for the report
34 34
         Config::inst()->update('SSViewer', 'theme_enabled', true);
35 35
         
36 36
         $this->GlobalSettings = GlobalAutoLinkSettings::get_current();
37
-        $this->Links          = AutomatedLink::get()->sort( 'Priority' );
37
+        $this->Links          = AutomatedLink::get()->sort('Priority');
38 38
         $includeInFields      = $this->GlobalSettings->IncludeInFields();
39
-        if( !$this->GlobalSettings ){
40
-            user_error( 'Run dev/build before starting to use SEOToolbox' );
39
+        if (!$this->GlobalSettings) {
40
+            user_error('Run dev/build before starting to use SEOToolbox');
41 41
             return $data;
42 42
         }
43 43
 
44
-        $exclude = Config::inst()->get( $this->class, 'exclude_classes' );
45
-        $exclude = ( $exclude ) ? "'".implode( "','", $exclude )."'" : '';
46
-        foreach( SiteTree::get()->where( "ClassName NOT IN($exclude)" ) as $page ){
47
-            if( !$this->checkForPossibleLinks( $page, $includeInFields ) ) continue;
48
-            $page = $this->getLinkData( $page, $includeInFields );
49
-            if( !$page ) continue;
44
+        $exclude = Config::inst()->get($this->class, 'exclude_classes');
45
+        $exclude = ($exclude) ? "'".implode("','", $exclude)."'" : '';
46
+        foreach (SiteTree::get()->where("ClassName NOT IN($exclude)") as $page) {
47
+            if (!$this->checkForPossibleLinks($page, $includeInFields)) continue;
48
+            $page = $this->getLinkData($page, $includeInFields);
49
+            if (!$page) continue;
50 50
 
51
-            if( !$run_in_realtime ) AutomatedLinkPageResult::add_or_update( $page );
52
-            $data->push( $page );
51
+            if (!$run_in_realtime) AutomatedLinkPageResult::add_or_update($page);
52
+            $data->push($page);
53 53
         }
54 54
 
55
-        if( !$run_in_realtime ) AutomatedLinkPageResult::remove_old_data();
55
+        if (!$run_in_realtime) AutomatedLinkPageResult::remove_old_data();
56 56
 
57 57
         return $data;
58 58
     }
@@ -66,19 +66,19 @@  discard block
 block discarded – undo
66 66
      *
67 67
      * @return SiteTree $page
68 68
      */
69
-    private function getLinkData( SiteTree $page, array $includeIn ){
69
+    private function getLinkData(SiteTree $page, array $includeIn) {
70 70
         // Set a list of all fields that can have autolinks created in them
71 71
         $page->AutomateableFields = ArrayList::create();
72 72
 
73
-        foreach( $this->getAllDatabaseFields( $page->class ) as $field => $type )
74
-            if( in_array( $field, $includeIn )                          &&
75
-                !$page->AutomateableFields->find( 'DataField', $field ) &&
76
-                AutomatedLink::isFieldParsable( $page, $field )
77
-            ) $page->AutomateableFields->push( DataObject::create( array( 'DataField' => $field ) ) );
73
+        foreach ($this->getAllDatabaseFields($page->class) as $field => $type)
74
+            if (in_array($field, $includeIn) &&
75
+                !$page->AutomateableFields->find('DataField', $field) &&
76
+                AutomatedLink::isFieldParsable($page, $field)
77
+            ) $page->AutomateableFields->push(DataObject::create(array('DataField' => $field)));
78 78
 
79 79
         // Get data Pre-Automated Links creation
80
-        $withLinks = $this->getPageDOM( $page, true );
81
-        if( !$withLinks ) return false;
80
+        $withLinks = $this->getPageDOM($page, true);
81
+        if (!$withLinks) return false;
82 82
 
83 83
         $links = $withLinks->getElementsByTagName('a');
84 84
 
@@ -88,18 +88,18 @@  discard block
 block discarded – undo
88 88
 
89 89
         // List all automated links that were created in this $page
90 90
         $linksUsed = array();
91
-        foreach( $this->Links as $autolink )
92
-            foreach( $links as $link ){
93
-                if( $link->getAttribute('data-id') == $autolink->ID ){
91
+        foreach ($this->Links as $autolink)
92
+            foreach ($links as $link) {
93
+                if ($link->getAttribute('data-id') == $autolink->ID) {
94 94
                     $linksUsed[$autolink->ID] = $autolink->Phrase;
95 95
                     $page->OriginalLinkCount--;
96 96
                     $page->LinkCount++;
97 97
                 }
98 98
             }
99 99
 
100
-        $page->Links = implode( ', ', $linksUsed );
100
+        $page->Links = implode(', ', $linksUsed);
101 101
 
102
-        if( $page->LinkCount < 1 ) return false;
102
+        if ($page->LinkCount < 1) return false;
103 103
 
104 104
         return $page;
105 105
     }
@@ -111,10 +111,10 @@  discard block
 block discarded – undo
111 111
      * @param String $class
112 112
      * @return array
113 113
      */
114
-    private function getAllDatabaseFields( $class ){
114
+    private function getAllDatabaseFields($class) {
115 115
         $fields = array();
116
-        foreach( ClassInfo::ancestry( $class, true ) as $cls )
117
-            $fields = array_merge( $fields, (array) DataObject::database_fields( $cls ) );
116
+        foreach (ClassInfo::ancestry($class, true) as $cls)
117
+            $fields = array_merge($fields, (array) DataObject::database_fields($cls));
118 118
 
119 119
         return $fields;
120 120
     }
@@ -128,35 +128,35 @@  discard block
 block discarded – undo
128 128
      *
129 129
      * @return DOMDocument | false
130 130
      */
131
-    private function getPageDOM( SiteTree $page ){
131
+    private function getPageDOM(SiteTree $page) {
132 132
         $controllerClass = $page->class.'_Controller';
133
-        if( !class_exists( $controllerClass ) )  $controller = $page->class.'Controller';
134
-        if( !class_exists( $controllerClass  ) ) return false;
133
+        if (!class_exists($controllerClass))  $controller = $page->class.'Controller';
134
+        if (!class_exists($controllerClass)) return false;
135 135
 
136
-        $controller = $controllerClass::create( $page );
137
-        $controller->invokeWithExtensions( 'addAutomatedLinks' );
136
+        $controller = $controllerClass::create($page);
137
+        $controller->invokeWithExtensions('addAutomatedLinks');
138 138
 
139 139
         // Set the fields with possible links into a single variable that
140 140
         // will be dumped in the link checker template
141 141
         $page->AutomateableText = '';
142
-        foreach( $page->AutomateableFields as $field ){
142
+        foreach ($page->AutomateableFields as $field) {
143 143
             $field = $field->DataField;
144 144
             $page->AutomateableText .= $page->$field;
145 145
         }
146 146
 
147 147
         $content = mb_convert_encoding(
148
-            $controller->renderWith( 'LinkCheckerTemplate' ),
148
+            $controller->renderWith('LinkCheckerTemplate'),
149 149
             'html-entities',
150 150
             GlobalAutoLinkSettings::$encoding
151 151
         );
152 152
 
153
-        if( !$content ) return false;
153
+        if (!$content) return false;
154 154
 
155
-        if( class_exists( 'HTML5_Parser' ) ){
155
+        if (class_exists('HTML5_Parser')) {
156 156
             $dom = HTML5_Parser::parse($content);
157
-        }else{
157
+        }else {
158 158
             $dom = new DOMDocument();
159
-            $dom->loadHTML( $content );
159
+            $dom->loadHTML($content);
160 160
         }
161 161
 
162 162
         return $dom;
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
      *
171 171
      * @return Boolean
172 172
      */
173
-    private function checkForPossibleLinks( SiteTree $page, array $includeIn ){
174
-        foreach( $this->Links as $link )
175
-            foreach( $includeIn as $possibleField )
176
-                if( isset( $page->$possibleField ) && preg_match( "/\b{$link->Phrase}\b/i", $page->$possibleField ) ) return true;
173
+    private function checkForPossibleLinks(SiteTree $page, array $includeIn) {
174
+        foreach ($this->Links as $link)
175
+            foreach ($includeIn as $possibleField)
176
+                if (isset($page->$possibleField) && preg_match("/\b{$link->Phrase}\b/i", $page->$possibleField)) return true;
177 177
 
178 178
         return false;
179 179
     }
Please login to merge, or discard this 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.