Skip to content

Commit 1cea728

Browse files
committed
fix formatting, cleanup weird characters, reorder methods
1 parent e3c780f commit 1cea728

File tree

15 files changed

+215
-166
lines changed

15 files changed

+215
-166
lines changed

README.md

+19-10
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
# About Hackathon Magento Honey Spam
22

3-
This Magento Extension adds a field which is hidden with JavaScript to the Customer Register and the Product Review Form which looks like the URL Field of a Wordpress Comment Form.
4-
If this field gets filled and the Form is send, there appears a error message and nothing will be saved.
3+
This Magento Extension adds a field which is hidden with JavaScript to the Customer Register and the Product Review Form
4+
which looks like the URL Field of a Wordpress Comment Form. If this field gets filled and the Form is send, there
5+
appears a error message and nothing will be saved.
56

67
There is also a check if this form is too fast transmitted, a human normally takes a couple of Seconds or more.
78

8-
You can enable and disable the functionalities or set the time how long it should take to transmit this forms in the Magento Admin Backend.
9+
You can enable and disable the functionalities or set the time how long it should take to transmit this forms in the
10+
Magento Admin Backend.
911

10-
Freshly added: Regex-checking on all input-fields to determine a loose index for spam-level. It is not the most accurate thing at all, but it may prevent the low-end spam ("broadband spam"). You also can enable/disable this feature in the backend and set a maximum spam index trust level.
12+
Freshly added: Regex-checking on all input-fields to determine a loose index for spam-level. It is not the most accurate
13+
thing at all, but it may prevent the low-end spam ("broadband spam"). You also can enable/disable this feature in the
14+
backend and set a maximum spam index trust level.
1115

1216
## Installation
1317

1418
### Compiler
19+
1520
Please disable Compiler. In our experience it doens't give performance wins and costs a lot of time while debugging.
1621

1722
### Installation with modman
@@ -31,23 +36,26 @@ Clean the cache after installation!
3136

3237
#### Contacts form modifications
3338

34-
Copy the file `app/design/frontend/{base_or_rwd}/default/template/contacts/form.phtml` to your own theme and insert the code
39+
Copy the file `app/design/frontend/{base_or_rwd}/default/template/contacts/form.phtml` to your own theme and insert the
40+
code
3541

3642
<?php echo $this->getChildHtml('form_fields_before') ?>
37-
43+
3844
within the `<form> ... </form>` tag.
3945

4046
#### Newsletter Subscription Form Modifications
4147

42-
Copy the file `app/design/frontend/{base_or_rwd}/default/template/newsletter/subscribe.phtml` to your own theme and insert the code
48+
Copy the file `app/design/frontend/{base_or_rwd}/default/template/newsletter/subscribe.phtml` to your own theme and
49+
insert the code
4350

4451
<?php echo $this->getChildHtml('form_fields_before') ?>
45-
52+
4653
within the `<form> ... </form>` tag.
4754

4855
## Testing
4956

50-
After the Installation you should be able to find a input field with the id="url" in the Customer Register and in the Product Review Form, which should be hidden with our JS.
57+
After the Installation you should be able to find a input field with the id="url" in the Customer Register and in the
58+
Product Review Form, which should be hidden with our JS.
5159

5260
## Further Information
5361

@@ -64,4 +72,5 @@ After the Installation you should be able to find a input field with the id="url
6472

6573
Complete and working.
6674

67-
If you found errors or have ideas, [open an issue](https://github.com/magento-hackathon/HoneySpam/issues) on github or a pull request!
75+
If you found errors or have ideas, [open an issue](https://github.com/magento-hackathon/HoneySpam/issues) on github or a
76+
pull request!
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Magento
45
*
@@ -12,26 +13,21 @@
1213
* obtain it through the world-wide-web, please send an email
1314
* to [email protected] so we can send you a copy immediately.
1415
*
15-
* @category  Hackathon
16-
* @package   Hackathon_HoneySpam
17-
* @author    Andreas Emer <[email protected]>
16+
* @category Hackathon
17+
* @package Hackathon_HoneySpam
18+
* @author Andreas Emer <[email protected]>
1819
* @author Fabian Blechschmidt <[email protected]>
1920
* @author Sascha Wohlgemuth <[email protected]>
2021
* @author Bastian Ike <[email protected]>
2122
* @author Peter Ukener <[email protected]>
2223
* @copyright 2012 Magento Hackathon
23-
* @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
24-
* @link      http://www.magento-hackathon.de/
24+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25+
* @link http://www.magento-hackathon.de/
2526
*/
2627
class Hackathon_HoneySpam_Block_Honeypot extends Mage_Core_Block_Template
2728
{
2829
protected $_template = 'hackathon/honeyspam/honeypot.phtml';
2930

30-
protected function _construct()
31-
{
32-
parent::_construct();
33-
}
34-
3531
/**
3632
* @return string
3733
*/
@@ -42,5 +38,10 @@ public function getHoneypotName()
4238
return $helper->getHoneypotName();
4339
}
4440

41+
protected function _construct()
42+
{
43+
parent::_construct();
44+
}
45+
4546

4647
}

app/code/community/Hackathon/HoneySpam/Helper/Data.php

+35-30
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Magento
45
*
@@ -12,35 +13,27 @@
1213
* obtain it through the world-wide-web, please send an email
1314
* to [email protected] so we can send you a copy immediately.
1415
*
15-
* @category  Hackathon
16-
* @package   Hackathon_HoneySpam
17-
* @author    Andreas Emer <[email protected]>
16+
* @category Hackathon
17+
* @package Hackathon_HoneySpam
18+
* @author Andreas Emer <[email protected]>
1819
* @author Fabian Blechschmidt <[email protected]>
1920
* @author Sascha Wohlgemuth <[email protected]>
2021
* @author Bastian Ike <[email protected]>
2122
* @author Peter Ukener <[email protected]>
2223
* @copyright 2012 Magento Hackathon
23-
* @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
24-
* @link      http://www.magento-hackathon.de/
24+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
25+
* @link http://www.magento-hackathon.de/
2526
*/
2627
class Hackathon_HoneySpam_Helper_Data extends Mage_Core_Helper_Abstract
2728
{
28-
const CONFIG_PATH_INPUT_NAME = 'hackathon/honeyspam/honeypotName';
29-
const CONFIG_PATH_ENABLE_POT = 'hackathon/honeyspam/enableHoneypotName';
30-
const CONFIG_PATH_ENABLE_TIME = 'hackathon/honeyspam/enableHoneypotAccountCreateTime';
31-
const CONFIG_PATH_ENABLE_SPAM = 'hackathon/honeyspam/enableSpamIndexing';
32-
const CONFIG_PATH_INDEX_LEVEL = 'hackathon/honeyspam/spamIndexLevel';
33-
const CONFIG_PATH_CREATE_TIME = 'hackathon/honeyspam/honeypotAccountCreateTime';
34-
const CONFIG_PATH_ENABLE_LOG = 'hackathon/honeyspam/enableLogging';
35-
const CONFIG_PATH_LOG_FILE = 'hackathon/honeyspam/logfile';
36-
37-
/**
38-
* @return string
39-
*/
40-
public function getHoneypotName()
41-
{
42-
return Mage::getStoreConfig(self::CONFIG_PATH_INPUT_NAME);
43-
}
29+
const CONFIG_PATH_INPUT_NAME = 'hackathon/honeyspam/honeypotName';
30+
const CONFIG_PATH_ENABLE_POT = 'hackathon/honeyspam/enableHoneypotName';
31+
const CONFIG_PATH_ENABLE_TIME = 'hackathon/honeyspam/enableHoneypotAccountCreateTime';
32+
const CONFIG_PATH_ENABLE_SPAM = 'hackathon/honeyspam/enableSpamIndexing';
33+
const CONFIG_PATH_INDEX_LEVEL = 'hackathon/honeyspam/spamIndexLevel';
34+
const CONFIG_PATH_CREATE_TIME = 'hackathon/honeyspam/honeypotAccountCreateTime';
35+
const CONFIG_PATH_ENABLE_LOG = 'hackathon/honeyspam/enableLogging';
36+
const CONFIG_PATH_LOG_FILE = 'hackathon/honeyspam/logfile';
4437

4538
/**
4639
* @return bool
@@ -49,27 +42,31 @@ public function isHoneypotNameEnabled()
4942
{
5043
return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLE_POT);
5144
}
45+
5246
/**
5347
* @return bool
5448
*/
5549
public function isSpamIndexingEnabled()
5650
{
5751
return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLE_SPAM);
5852
}
53+
5954
/**
6055
* @return bool
6156
*/
6257
public function isHoneypotAccountCreateTimeEnabled()
6358
{
6459
return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLE_TIME);
6560
}
61+
6662
/**
6763
* @return string
6864
*/
6965
public function getSpamIndexLevel()
7066
{
7167
return Mage::getStoreConfig(self::CONFIG_PATH_INDEX_LEVEL);
7268
}
69+
7370
/**
7471
* @return string
7572
*/
@@ -78,6 +75,17 @@ public function getHoneypotAccountCreateTime()
7875
return Mage::getStoreConfig(self::CONFIG_PATH_CREATE_TIME);
7976
}
8077

78+
/**
79+
* @param string $message
80+
* @param int $level
81+
*/
82+
public function log($message, $level = Zend_Log::INFO)
83+
{
84+
if ($this->isLoggingEnabled()) {
85+
Mage::log($message, $level, $this->getLogFilename());
86+
}
87+
}
88+
8189
/**
8290
* @return bool
8391
*/
@@ -95,22 +103,19 @@ public function getLogFilename()
95103
}
96104

97105
/**
98-
* @param string $message
99-
* @param int $level
106+
* @return bool
100107
*/
101-
public function log($message, $level = Zend_Log::INFO)
108+
public function isHoneypotFilled()
102109
{
103-
if ($this->isLoggingEnabled()) {
104-
Mage::log($message, $level, $this->getLogFilename());
105-
}
110+
return strlen($this->_getRequest()->getParam($this->getHoneypotName()));
106111
}
107112

108113
/**
109-
* @return bool
114+
* @return string
110115
*/
111-
public function isHoneypotFilled()
116+
public function getHoneypotName()
112117
{
113-
return strlen($this->_getRequest()->getParam($this->getHoneypotName()));
118+
return Mage::getStoreConfig(self::CONFIG_PATH_INPUT_NAME);
114119
}
115120

116121
/**

app/code/community/Hackathon/HoneySpam/Model/Checker.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
* obtain it through the world-wide-web, please send an email
1313
* to [email protected] so we can send you a copy immediately.
1414
*
15-
* @category  Hackathon
16-
* @package   Hackathon_HoneySpam
17-
* @author    Andreas Emer <[email protected]>
15+
* @category Hackathon
16+
* @package Hackathon_HoneySpam
17+
* @author Andreas Emer <[email protected]>
1818
* @author Fabian Blechschmidt <[email protected]>
1919
* @author Sascha Wohlgemuth <[email protected]>
2020
* @author Bastian Ike <[email protected]>
2121
* @author Peter Ukener <[email protected]>
2222
* @copyright 2012 Magento Hackathon
23-
* @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
24-
* @link      http://www.magento-hackathon.de/
23+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
24+
* @link http://www.magento-hackathon.de/
2525
*/
2626

2727
class Hackathon_HoneySpam_Model_Checker extends Mage_Core_Model_Abstract
@@ -46,7 +46,7 @@ public function init($params)
4646
* @param string $firstname
4747
* @param string $lastname
4848
* @param string $emailprefix
49-
* @param array $params
49+
* @param array $params
5050
* @return int
5151
*/
5252
public function check($firstname, $lastname, $emailprefix, $params)
@@ -110,7 +110,8 @@ public function check($firstname, $lastname, $emailprefix, $params)
110110
}
111111
}
112112

113-
if (preg_match("([A-Z]{2,})", substr($param, -4))) { // At least two CAPITALS at the end of a string == Spam!
113+
if (preg_match("([A-Z]{2,})",
114+
substr($param, -4))) { // At least two CAPITALS at the end of a string == Spam!
114115
$_index += 1;
115116
$helper->log("SPAM: " . $param . " has at least 2 CAPITAL letters at the end");
116117
}
@@ -120,7 +121,8 @@ public function check($firstname, $lastname, $emailprefix, $params)
120121
$helper->log("SPAM: " . $param . " contains more than 3 CAPITALS at all");
121122
}
122123

123-
if (preg_match("([a-z])", substr($param, 1, 1)) && preg_match("([A-Z])", substr($param, 1, 1))) { // Param starts with a lowercase+uppercase
124+
if (preg_match("([a-z])", substr($param, 1, 1))
125+
&& preg_match("([A-Z])", substr($param, 1, 1))) { // Param starts with a lowercase+uppercase
124126
$_index += 1;
125127
$helper->log("SPAM: " . $param . " starts with a combination lc/uc. E.g. aJohn, bSmith...");
126128
}

0 commit comments

Comments
 (0)