Passed
Branch develop (be29f2)
by Dylan
03:49 queued 01:13
created
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/GridFieldExportAllAutomatedLinksButton.php 1 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/logic/GridFieldPrintAllAutomatedLinksButton.php 1 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 1 patch
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.
code/dataobjects/GlobalAutoLinkSettings.php 1 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.
code/admin/SEOToolboxAdmin.php 1 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 1 patch
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.
code/controllers/SEOTestSiteTreeController.php 1 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.
code/extenstions/SEOToolboxSiteTreeExtension.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-class SEOToolboxSiteTreeExtension extends DataExtension{
3
+class SEOToolboxSiteTreeExtension extends DataExtension {
4 4
 
5 5
     private static $db = array(
6 6
         'MetaTitle' => 'VARCHAR(255)'
7 7
     );
8 8
 
9
-    public function MetaTags($tags){
10
-        $tags = preg_replace('/<title(.*?)<\/title>/im','', $tags);
11
-        $title = ( $this->owner->MetaTitle ) ? $this->owner->MetaTitle : $this->owner->Title;
9
+    public function MetaTags($tags) {
10
+        $tags = preg_replace('/<title(.*?)<\/title>/im', '', $tags);
11
+        $title = ($this->owner->MetaTitle) ? $this->owner->MetaTitle : $this->owner->Title;
12 12
         $tags .= "<title>{$title}</title>";
13 13
         return $tags;
14 14
     }
15 15
 
16
-    public function updateCMSFields(FieldList $fields){
16
+    public function updateCMSFields(FieldList $fields) {
17 17
         $fields->removeByName('Metadata');
18 18
         $fields->addFieldsToTab('Root.SEO', array(
19 19
             TextField::create("MetaTitle",
@@ -29,13 +29,13 @@  discard block
 block discarded – undo
29 29
                         "Search engines use this content for displaying search results 
30 30
                         (although it will not influence their ranking).")
31 31
                 )->addExtraClass('help'),
32
-            TextareaField::create("ExtraMeta",$this->owner->fieldLabel('ExtraMeta'))
32
+            TextareaField::create("ExtraMeta", $this->owner->fieldLabel('ExtraMeta'))
33 33
                 ->setRightTitle(
34 34
                     _t('SEOToolbox.METAEXTRAHELP',
35 35
                         "HTML tags for additional meta information. For example &lt;meta name=\"customName\" 
36 36
                         content=\"your custom content here\" /&gt;")
37 37
                 )->addExtraClass('help'),
38
-            SEOToolboxAnalyzerField::create('Analyzer', $this->owner->URLSegment ),
38
+            SEOToolboxAnalyzerField::create('Analyzer', $this->owner->URLSegment),
39 39
         ));
40 40
     }
41 41
 
Please login to merge, or discard this patch.