Completed
Pull Request — master (#17)
by Helpful
03:10
created
code/AkismetField.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 	protected function confirmationField() {
28 28
 		// Check if confirmation is required
29 29
 		$requireConfirmation = Config::inst()->get('AkismetSpamProtector', 'require_confirmation');
30
-		if(empty($requireConfirmation)) return null;
30
+		if (empty($requireConfirmation)) return null;
31 31
 		
32 32
 		// If confirmation is required then return a checkbox
33 33
 		return CheckboxField::create(
@@ -41,24 +41,24 @@  discard block
 block discarded – undo
41 41
 	
42 42
 	public function Field($properties = array()) {
43 43
 		$checkbox = $this->confirmationField();
44
-		if($checkbox) return $checkbox->Field($properties);
44
+		if ($checkbox) return $checkbox->Field($properties);
45 45
 	}
46 46
 	
47 47
 	function FieldHolder($properties = array()) {
48 48
 		$checkbox = $this->confirmationField();
49
-		if($checkbox) return $checkbox->FieldHolder($properties);
49
+		if ($checkbox) return $checkbox->FieldHolder($properties);
50 50
 	}
51 51
 	
52 52
 	/**
53 53
 	 * @return array
54 54
 	 */
55 55
 	public function getSpamMappedData() {
56
-		if(empty($this->fieldMapping)) return null;
56
+		if (empty($this->fieldMapping)) return null;
57 57
 		
58 58
 		$result = array();
59 59
 		$data = $this->form->getData();
60 60
 
61
-		foreach($this->fieldMapping as $fieldName => $mappedName) {
61
+		foreach ($this->fieldMapping as $fieldName => $mappedName) {
62 62
 			$result[$mappedName] = (isset($data[$fieldName])) ? $data[$fieldName] : null;
63 63
 		}
64 64
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 		
80 80
 		// Check that, if necessary, the user has given permission to check for spam
81 81
 		$requireConfirmation = Config::inst()->get('AkismetSpamProtector', 'require_confirmation');
82
-		if($requireConfirmation && !$this->Value()) {
82
+		if ($requireConfirmation && !$this->Value()) {
83 83
 			$validator->validationError(
84 84
 				$this->name,
85 85
 				_t(
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		
94 94
 		// Check result
95 95
 		$isSpam = $this->getIsSpam();
96
-		if(!$isSpam) return true;
96
+		if (!$isSpam) return true;
97 97
 
98 98
 		// Save error message
99 99
 		$errorMessage = _t(
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
 		);
103 103
 
104 104
 		// If spam should be allowed, let it pass and save it for later
105
-		if(Config::inst()->get('AkismetSpamProtector', 'save_spam')) {
105
+		if (Config::inst()->get('AkismetSpamProtector', 'save_spam')) {
106 106
 			// In order to save spam but still display the spam message, we must mock a form message
107 107
 			// without failing the validation
108 108
 			$errors = array(array(
@@ -127,15 +127,15 @@  discard block
 block discarded – undo
127 127
 	 */
128 128
 	public function getIsSpam() {
129 129
 		// Prevent multiple API calls
130
-		if($this->isSpam !== null) return $this->isSpam;
130
+		if ($this->isSpam !== null) return $this->isSpam;
131 131
 
132 132
 		// Check bypass permission
133 133
 		$permission = Config::inst()->get('AkismetSpamProtector', 'bypass_permission');
134
-		if($permission && Permission::check($permission)) return false;
134
+		if ($permission && Permission::check($permission)) return false;
135 135
 
136 136
 		// if the user has logged and there's no force check on member
137 137
 		$bypassMember = Config::inst()->get('AkismetSpamProtector', 'bypass_members');
138
-		if($bypassMember && Member::currentUser()) return false;
138
+		if ($bypassMember && Member::currentUser()) return false;
139 139
 
140 140
 		// Map input fields to spam fields
141 141
 		$mappedData = $this->getSpamMappedData();
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
 	 * @param \DataObjectInterface $record
181 181
 	 */
182 182
 	public function saveInto(\DataObjectInterface $record) {
183
-		if(Config::inst()->get('AkismetSpamProtector', 'save_spam')) {
183
+		if (Config::inst()->get('AkismetSpamProtector', 'save_spam')) {
184 184
 			$dataValue = $this->getIsSpam() ? 1 : 0;
185 185
 			$record->setCastedField($this->name, $dataValue);
186 186
 		}
Please login to merge, or discard this patch.
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,7 +27,9 @@  discard block
 block discarded – undo
27 27
 	protected function confirmationField() {
28 28
 		// Check if confirmation is required
29 29
 		$requireConfirmation = Config::inst()->get('AkismetSpamProtector', 'require_confirmation');
30
-		if(empty($requireConfirmation)) return null;
30
+		if(empty($requireConfirmation)) {
31
+			return null;
32
+		}
31 33
 		
32 34
 		// If confirmation is required then return a checkbox
33 35
 		return CheckboxField::create(
@@ -41,19 +43,25 @@  discard block
 block discarded – undo
41 43
 	
42 44
 	public function Field($properties = array()) {
43 45
 		$checkbox = $this->confirmationField();
44
-		if($checkbox) return $checkbox->Field($properties);
46
+		if($checkbox) {
47
+			return $checkbox->Field($properties);
48
+		}
45 49
 	}
46 50
 	
47 51
 	function FieldHolder($properties = array()) {
48 52
 		$checkbox = $this->confirmationField();
49
-		if($checkbox) return $checkbox->FieldHolder($properties);
53
+		if($checkbox) {
54
+			return $checkbox->FieldHolder($properties);
55
+		}
50 56
 	}
51 57
 	
52 58
 	/**
53 59
 	 * @return array
54 60
 	 */
55 61
 	public function getSpamMappedData() {
56
-		if(empty($this->fieldMapping)) return null;
62
+		if(empty($this->fieldMapping)) {
63
+			return null;
64
+		}
57 65
 		
58 66
 		$result = array();
59 67
 		$data = $this->form->getData();
@@ -93,7 +101,9 @@  discard block
 block discarded – undo
93 101
 		
94 102
 		// Check result
95 103
 		$isSpam = $this->getIsSpam();
96
-		if(!$isSpam) return true;
104
+		if(!$isSpam) {
105
+			return true;
106
+		}
97 107
 
98 108
 		// Save error message
99 109
 		$errorMessage = _t(
@@ -127,15 +137,21 @@  discard block
 block discarded – undo
127 137
 	 */
128 138
 	public function getIsSpam() {
129 139
 		// Prevent multiple API calls
130
-		if($this->isSpam !== null) return $this->isSpam;
140
+		if($this->isSpam !== null) {
141
+			return $this->isSpam;
142
+		}
131 143
 
132 144
 		// Check bypass permission
133 145
 		$permission = Config::inst()->get('AkismetSpamProtector', 'bypass_permission');
134
-		if($permission && Permission::check($permission)) return false;
146
+		if($permission && Permission::check($permission)) {
147
+			return false;
148
+		}
135 149
 
136 150
 		// if the user has logged and there's no force check on member
137 151
 		$bypassMember = Config::inst()->get('AkismetSpamProtector', 'bypass_members');
138
-		if($bypassMember && Member::currentUser()) return false;
152
+		if($bypassMember && Member::currentUser()) {
153
+			return false;
154
+		}
139 155
 
140 156
 		// Map input fields to spam fields
141 157
 		$mappedData = $this->getSpamMappedData();
Please login to merge, or discard this patch.
code/AkismetSpamProtector.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -79,14 +79,14 @@  discard block
 block discarded – undo
79 79
 	 * @return string
80 80
 	 */
81 81
 	protected static function get_api_key() {
82
-		if(self::$_api_key) return self::$_api_key;
82
+		if (self::$_api_key) return self::$_api_key;
83 83
 		
84 84
 		// Check config
85 85
 		$key = Config::inst()->get('AkismetSpamProtector', 'api_key');
86
-		if(!empty($key)) return $key;
86
+		if (!empty($key)) return $key;
87 87
 		
88 88
 		// Check environment
89
-		if(defined('SS_AKISMET_API_KEY')) return SS_AKISMET_API_KEY;
89
+		if (defined('SS_AKISMET_API_KEY')) return SS_AKISMET_API_KEY;
90 90
 	}
91 91
 	
92 92
 	/**
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	public static function api() {
98 98
 		// Get API key and URL
99 99
 		$key = self::get_api_key();
100
-		if(empty($key)) {
100
+		if (empty($key)) {
101 101
 			user_error("AkismetSpamProtector is incorrectly configured. Please specify an API key.", E_USER_WARNING);
102 102
 			return null;
103 103
 		}
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -79,14 +79,20 @@
 block discarded – undo
79 79
 	 * @return string
80 80
 	 */
81 81
 	protected static function get_api_key() {
82
-		if(self::$_api_key) return self::$_api_key;
82
+		if(self::$_api_key) {
83
+			return self::$_api_key;
84
+		}
83 85
 		
84 86
 		// Check config
85 87
 		$key = Config::inst()->get('AkismetSpamProtector', 'api_key');
86
-		if(!empty($key)) return $key;
88
+		if(!empty($key)) {
89
+			return $key;
90
+		}
87 91
 		
88 92
 		// Check environment
89
-		if(defined('SS_AKISMET_API_KEY')) return SS_AKISMET_API_KEY;
93
+		if(defined('SS_AKISMET_API_KEY')) {
94
+			return SS_AKISMET_API_KEY;
95
+		}
90 96
 	}
91 97
 	
92 98
 	/**
Please login to merge, or discard this patch.
code/config/AkismetProcessor.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -11,18 +11,18 @@  discard block
 block discarded – undo
11 11
 
12 12
 	public function preRequest(SS_HTTPRequest $request, Session $session, DataModel $model) {
13 13
 		// Skip if database isn't ready
14
-		if(!$this->isDBReady()) {
14
+		if (!$this->isDBReady()) {
15 15
 			return;
16 16
 		}
17 17
 
18 18
 		// Skip if SiteConfig doesn't have this extension
19
-		if(!SiteConfig::has_extension('AkismetConfig')) {
19
+		if (!SiteConfig::has_extension('AkismetConfig')) {
20 20
 			return;
21 21
 		}
22 22
 
23 23
 		// Check if key exists
24 24
 		$akismetKey = SiteConfig::current_site_config()->AkismetKey;
25
-		if($akismetKey) {
25
+		if ($akismetKey) {
26 26
 			AkismetSpamProtector::set_api_key($akismetKey);
27 27
 		}
28 28
 	}
@@ -33,18 +33,18 @@  discard block
 block discarded – undo
33 33
 	 * @return bool
34 34
 	 */
35 35
 	protected function isDBReady() {
36
-		if(!DB::isActive()) {
36
+		if (!DB::isActive()) {
37 37
 			return false;
38 38
 		}
39 39
 
40 40
 		// Require table
41
-		if(!DB::getConn()->hasTable('SiteConfig')) {
41
+		if (!DB::getConn()->hasTable('SiteConfig')) {
42 42
 			return false;
43 43
 		}
44 44
 
45 45
 		// Ensure siteconfig has all fields necessary
46 46
 		$dbFields = DB::fieldList('SiteConfig');
47
-		if(empty($dbFields)) {
47
+		if (empty($dbFields)) {
48 48
 			return false;
49 49
 		}
50 50
 
Please login to merge, or discard this patch.
code/service/AkismetService.php 1 patch
Indentation   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -6,34 +6,34 @@
 block discarded – undo
6 6
 interface AkismetService {
7 7
 	
8 8
 	/**
9
-     * Check if the comment is spam or not
10
-     * This is basically the core of everything. This call takes a number of
11
-     * arguments and characteristics about the submitted content and then
12
-     * returns a thumbs up or thumbs down.
13
-     * Almost everything is optional, but performance can drop dramatically if
14
-     * you exclude certain elements.
15
-     * REMARK: If you are having trouble triggering you can send
16
-     * "viagra-test-123" as the author and it will trigger a true response,
17
-     * always.
18
-     *
19
-     * @param string[optional] $content   The content that was submitted.
20
-     * @param string[optional] $author    The name.
21
-     * @param string[optional] $email     The email address.
22
-     * @param string[optional] $url       The URL.
23
-     * @param string[optional] $permalink The permanent location of the entry
24
-     *                                    the comment was submitted to.
25
-     * @param string[optional] $type The type, can be blank, comment,
26
-     *                                    trackback, pingback, or a made up
27
-     *                                    value like "registration".
28
-     * @return bool If the comment is spam true will be
29
-     *                                    returned, otherwise false.
30
-     */
31
-    public function isSpam(
32
-        $content,
33
-        $author = null,
34
-        $email = null,
35
-        $url = null,
36
-        $permalink = null,
37
-        $type = null
38
-    );
9
+	 * Check if the comment is spam or not
10
+	 * This is basically the core of everything. This call takes a number of
11
+	 * arguments and characteristics about the submitted content and then
12
+	 * returns a thumbs up or thumbs down.
13
+	 * Almost everything is optional, but performance can drop dramatically if
14
+	 * you exclude certain elements.
15
+	 * REMARK: If you are having trouble triggering you can send
16
+	 * "viagra-test-123" as the author and it will trigger a true response,
17
+	 * always.
18
+	 *
19
+	 * @param string[optional] $content   The content that was submitted.
20
+	 * @param string[optional] $author    The name.
21
+	 * @param string[optional] $email     The email address.
22
+	 * @param string[optional] $url       The URL.
23
+	 * @param string[optional] $permalink The permanent location of the entry
24
+	 *                                    the comment was submitted to.
25
+	 * @param string[optional] $type The type, can be blank, comment,
26
+	 *                                    trackback, pingback, or a made up
27
+	 *                                    value like "registration".
28
+	 * @return bool If the comment is spam true will be
29
+	 *                                    returned, otherwise false.
30
+	 */
31
+	public function isSpam(
32
+		$content,
33
+		$author = null,
34
+		$email = null,
35
+		$url = null,
36
+		$permalink = null,
37
+		$type = null
38
+	);
39 39
 }
Please login to merge, or discard this patch.