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