Completed
Push — master ( 3d52ac...1d7363 )
by Daniel
03:51
created
code/AkismetField.php 1 patch
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.
code/AkismetSpamProtector.php 1 patch
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.
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.