diff --git a/README.md b/README.md index 8104f93..133bead 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,22 @@ # About Hackathon Magento Honey Spam -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. -If this field gets filled and the Form is send, there appears a error message and nothing will be saved. +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. If this field gets filled and the Form is send, there +appears a error message and nothing will be saved. There is also a check if this form is too fast transmitted, a human normally takes a couple of Seconds or more. -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. +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. -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. +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. ## Installation ### Compiler + Please disable Compiler. In our experience it doens't give performance wins and costs a lot of time while debugging. ### Installation with modman @@ -31,23 +36,26 @@ Clean the cache after installation! #### Contacts form modifications -Copy the file `app/design/frontend/{base_or_rwd}/default/template/contacts/form.phtml` to your own theme and insert the code +Copy the file `app/design/frontend/{base_or_rwd}/default/template/contacts/form.phtml` to your own theme and insert the +code getChildHtml('form_fields_before') ?> - + within the `
...
` tag. #### Newsletter Subscription Form Modifications -Copy the file `app/design/frontend/{base_or_rwd}/default/template/newsletter/subscribe.phtml` to your own theme and insert the code +Copy the file `app/design/frontend/{base_or_rwd}/default/template/newsletter/subscribe.phtml` to your own theme and +insert the code getChildHtml('form_fields_before') ?> - + within the `
...
` tag. ## Testing -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. +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. ## Further Information @@ -64,4 +72,5 @@ After the Installation you should be able to find a input field with the id="url Complete and working. -If you found errors or have ideas, [open an issue](https://github.com/magento-hackathon/HoneySpam/issues) on github or a pull request! +If you found errors or have ideas, [open an issue](https://github.com/magento-hackathon/HoneySpam/issues) on github or a +pull request! diff --git a/app/code/community/Hackathon/HoneySpam/Block/Honeypot.php b/app/code/community/Hackathon/HoneySpam/Block/Honeypot.php index 9cd616b..130e84e 100644 --- a/app/code/community/Hackathon/HoneySpam/Block/Honeypot.php +++ b/app/code/community/Hackathon/HoneySpam/Block/Honeypot.php @@ -1,4 +1,5 @@ + * @category Hackathon + * @package Hackathon_HoneySpam + * @author Andreas Emer * @author Fabian Blechschmidt * @author Sascha Wohlgemuth * @author Bastian Ike * @author Peter Ukener * @copyright 2012 Magento Hackathon - * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0) - * @link      http://www.magento-hackathon.de/ + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @link http://www.magento-hackathon.de/ */ class Hackathon_HoneySpam_Block_Honeypot extends Mage_Core_Block_Template { protected $_template = 'hackathon/honeyspam/honeypot.phtml'; - protected function _construct() - { - parent::_construct(); - } - /** * @return string */ @@ -42,5 +38,10 @@ public function getHoneypotName() return $helper->getHoneypotName(); } + protected function _construct() + { + parent::_construct(); + } + } diff --git a/app/code/community/Hackathon/HoneySpam/Helper/Data.php b/app/code/community/Hackathon/HoneySpam/Helper/Data.php index 2e3f44c..66c0e59 100644 --- a/app/code/community/Hackathon/HoneySpam/Helper/Data.php +++ b/app/code/community/Hackathon/HoneySpam/Helper/Data.php @@ -1,4 +1,5 @@ + * @category Hackathon + * @package Hackathon_HoneySpam + * @author Andreas Emer * @author Fabian Blechschmidt * @author Sascha Wohlgemuth * @author Bastian Ike * @author Peter Ukener * @copyright 2012 Magento Hackathon - * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0) - * @link      http://www.magento-hackathon.de/ + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @link http://www.magento-hackathon.de/ */ class Hackathon_HoneySpam_Helper_Data extends Mage_Core_Helper_Abstract { - const CONFIG_PATH_INPUT_NAME = 'hackathon/honeyspam/honeypotName'; - const CONFIG_PATH_ENABLE_POT = 'hackathon/honeyspam/enableHoneypotName'; - const CONFIG_PATH_ENABLE_TIME = 'hackathon/honeyspam/enableHoneypotAccountCreateTime'; - const CONFIG_PATH_ENABLE_SPAM = 'hackathon/honeyspam/enableSpamIndexing'; - const CONFIG_PATH_INDEX_LEVEL = 'hackathon/honeyspam/spamIndexLevel'; - const CONFIG_PATH_CREATE_TIME = 'hackathon/honeyspam/honeypotAccountCreateTime'; - const CONFIG_PATH_ENABLE_LOG = 'hackathon/honeyspam/enableLogging'; - const CONFIG_PATH_LOG_FILE = 'hackathon/honeyspam/logfile'; - - /** - * @return string - */ - public function getHoneypotName() - { - return Mage::getStoreConfig(self::CONFIG_PATH_INPUT_NAME); - } + const CONFIG_PATH_INPUT_NAME = 'hackathon/honeyspam/honeypotName'; + const CONFIG_PATH_ENABLE_POT = 'hackathon/honeyspam/enableHoneypotName'; + const CONFIG_PATH_ENABLE_TIME = 'hackathon/honeyspam/enableHoneypotAccountCreateTime'; + const CONFIG_PATH_ENABLE_SPAM = 'hackathon/honeyspam/enableSpamIndexing'; + const CONFIG_PATH_INDEX_LEVEL = 'hackathon/honeyspam/spamIndexLevel'; + const CONFIG_PATH_CREATE_TIME = 'hackathon/honeyspam/honeypotAccountCreateTime'; + const CONFIG_PATH_ENABLE_LOG = 'hackathon/honeyspam/enableLogging'; + const CONFIG_PATH_LOG_FILE = 'hackathon/honeyspam/logfile'; /** * @return bool @@ -49,6 +42,7 @@ public function isHoneypotNameEnabled() { return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLE_POT); } + /** * @return bool */ @@ -56,6 +50,7 @@ public function isSpamIndexingEnabled() { return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLE_SPAM); } + /** * @return bool */ @@ -63,6 +58,7 @@ public function isHoneypotAccountCreateTimeEnabled() { return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLE_TIME); } + /** * @return string */ @@ -70,6 +66,7 @@ public function getSpamIndexLevel() { return Mage::getStoreConfig(self::CONFIG_PATH_INDEX_LEVEL); } + /** * @return string */ @@ -78,6 +75,17 @@ public function getHoneypotAccountCreateTime() return Mage::getStoreConfig(self::CONFIG_PATH_CREATE_TIME); } + /** + * @param string $message + * @param int $level + */ + public function log($message, $level = Zend_Log::INFO) + { + if ($this->isLoggingEnabled()) { + Mage::log($message, $level, $this->getLogFilename()); + } + } + /** * @return bool */ @@ -95,22 +103,19 @@ public function getLogFilename() } /** - * @param string $message - * @param int $level + * @return bool */ - public function log($message, $level = Zend_Log::INFO) + public function isHoneypotFilled() { - if ($this->isLoggingEnabled()) { - Mage::log($message, $level, $this->getLogFilename()); - } + return strlen($this->_getRequest()->getParam($this->getHoneypotName())); } /** - * @return bool + * @return string */ - public function isHoneypotFilled() + public function getHoneypotName() { - return strlen($this->_getRequest()->getParam($this->getHoneypotName())); + return Mage::getStoreConfig(self::CONFIG_PATH_INPUT_NAME); } /** diff --git a/app/code/community/Hackathon/HoneySpam/Model/Checker.php b/app/code/community/Hackathon/HoneySpam/Model/Checker.php index b008da4..1bcad7e 100644 --- a/app/code/community/Hackathon/HoneySpam/Model/Checker.php +++ b/app/code/community/Hackathon/HoneySpam/Model/Checker.php @@ -12,16 +12,16 @@ * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * - * @category  Hackathon - * @package   Hackathon_HoneySpam - * @author    Andreas Emer + * @category Hackathon + * @package Hackathon_HoneySpam + * @author Andreas Emer * @author Fabian Blechschmidt * @author Sascha Wohlgemuth * @author Bastian Ike * @author Peter Ukener * @copyright 2012 Magento Hackathon - * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0) - * @link      http://www.magento-hackathon.de/ + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @link http://www.magento-hackathon.de/ */ class Hackathon_HoneySpam_Model_Checker extends Mage_Core_Model_Abstract @@ -46,7 +46,7 @@ public function init($params) * @param string $firstname * @param string $lastname * @param string $emailprefix - * @param array $params + * @param array $params * @return int */ public function check($firstname, $lastname, $emailprefix, $params) @@ -110,7 +110,8 @@ public function check($firstname, $lastname, $emailprefix, $params) } } - if (preg_match("([A-Z]{2,})", substr($param, -4))) { // At least two CAPITALS at the end of a string == Spam! + if (preg_match("([A-Z]{2,})", + substr($param, -4))) { // At least two CAPITALS at the end of a string == Spam! $_index += 1; $helper->log("SPAM: " . $param . " has at least 2 CAPITAL letters at the end"); } @@ -120,7 +121,8 @@ public function check($firstname, $lastname, $emailprefix, $params) $helper->log("SPAM: " . $param . " contains more than 3 CAPITALS at all"); } - if (preg_match("([a-z])", substr($param, 1, 1)) && preg_match("([A-Z])", substr($param, 1, 1))) { // Param starts with a lowercase+uppercase + if (preg_match("([a-z])", substr($param, 1, 1)) + && preg_match("([A-Z])", substr($param, 1, 1))) { // Param starts with a lowercase+uppercase $_index += 1; $helper->log("SPAM: " . $param . " starts with a combination lc/uc. E.g. aJohn, bSmith..."); } diff --git a/app/code/community/Hackathon/HoneySpam/Model/Observer.php b/app/code/community/Hackathon/HoneySpam/Model/Observer.php index 23c8631..54caf26 100644 --- a/app/code/community/Hackathon/HoneySpam/Model/Observer.php +++ b/app/code/community/Hackathon/HoneySpam/Model/Observer.php @@ -1,4 +1,5 @@ - * @author Fabian Blechschmidt - * @author Sascha Wohlgemuth - * @author Bastian Ike - * @author Peter Ukener - * @copyright 2012 Magento Hackathon - * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0) - * @link      http://www.magento-hackathon.de/ + * @category Hackathon + * @package Hackathon_HoneySpam + * @author Andreas Emer + * @author Fabian Blechschmidt + * @author Sascha Wohlgemuth + * @author Bastian Ike + * @author Peter Ukener + * @copyright 2012 Magento Hackathon + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @link http://www.magento-hackathon.de/ */ class Hackathon_HoneySpam_Model_Observer { @@ -47,13 +48,11 @@ public function checkHoneypotCustomerAccountCreatepost() } /** - * @throws Mage_Core_Controller_Varien_Exception + * @return Hackathon_HoneySpam_Helper_Data */ - public function checkHoneypot() + private function getHelper() { - if ($this->getHelper()->isHoneypotNameEnabled()) { - $this->_checkHoneypot(); - } + return Mage::helper('hackathon_honeyspam'); } /** @@ -80,7 +79,7 @@ protected function _checkHoneypot() */ protected function _checkTimestamp() { - $helper = $this->getHelper(); + $helper = $this->getHelper(); $session = $this->getCustomerSession(); if (!$session->getData('account_create_time', false) @@ -95,11 +94,11 @@ protected function _checkTimestamp() } /** - * set access timestamp + * @return Mage_Customer_Model_Session */ - public function checkHoneypotCustomerAccountCreate() + private function getCustomerSession() { - $this->getCustomerSession()->setData('account_create_time', time()); + return Mage::getSingleton('customer/session'); } /** @@ -121,26 +120,28 @@ protected function _indexLoginParams() } /** - * @return Mage_Customer_Model_Session + * @return Hackathon_HoneySpam_Model_Checker */ - private function getCustomerSession() + private function getCheckerModel() { - return Mage::getSingleton('customer/session'); + return Mage::getModel('hackathon_honeyspam/checker'); } /** - * @return Hackathon_HoneySpam_Model_Checker + * @throws Hackathon_HoneySpam_Exception */ - private function getCheckerModel() + public function checkHoneypot() { - return Mage::getModel('hackathon_honeyspam/checker'); + if ($this->getHelper()->isHoneypotNameEnabled()) { + $this->_checkHoneypot(); + } } /** - * @return Hackathon_HoneySpam_Helper_Data + * set access timestamp */ - private function getHelper() + public function checkHoneypotCustomerAccountCreate() { - return Mage::helper('hackathon_honeyspam'); + $this->getCustomerSession()->setData('account_create_time', time()); } } diff --git a/app/code/community/Hackathon/HoneySpam/controllers/ErrorController.php b/app/code/community/Hackathon/HoneySpam/controllers/ErrorController.php index 9a5bcd1..bccf4a6 100644 --- a/app/code/community/Hackathon/HoneySpam/controllers/ErrorController.php +++ b/app/code/community/Hackathon/HoneySpam/controllers/ErrorController.php @@ -1,4 +1,5 @@ + * @category Hackathon + * @package Hackathon_HoneySpam + * @author Andreas Emer * @author Fabian Blechschmidt * @author Sascha Wohlgemuth * @author Bastian Ike * @author Peter Ukener * @copyright 2012 Magento Hackathon - * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0) - * @link      http://www.magento-hackathon.de/ + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @link http://www.magento-hackathon.de/ */ class Hackathon_HoneySpam_ErrorController extends Mage_Core_Controller_Front_Action { diff --git a/app/code/community/Hackathon/HoneySpam/controllers/IndexController.php b/app/code/community/Hackathon/HoneySpam/controllers/IndexController.php index ed5f1f7..60c1641 100644 --- a/app/code/community/Hackathon/HoneySpam/controllers/IndexController.php +++ b/app/code/community/Hackathon/HoneySpam/controllers/IndexController.php @@ -1,4 +1,5 @@ + * @category Hackathon + * @package Hackathon_HoneySpam + * @author Andreas Emer * @author Fabian Blechschmidt * @author Sascha Wohlgemuth * @author Bastian Ike * @author Peter Ukener * @copyright 2012 Magento Hackathon - * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0) - * @link      http://www.magento-hackathon.de/ + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @link http://www.magento-hackathon.de/ */ class Hackathon_HoneySpam_IndexController extends Mage_Core_Controller_Front_Action { diff --git a/app/code/community/Hackathon/HoneySpam/etc/adminhtml.xml b/app/code/community/Hackathon/HoneySpam/etc/adminhtml.xml index 3757cfb..3d310df 100644 --- a/app/code/community/Hackathon/HoneySpam/etc/adminhtml.xml +++ b/app/code/community/Hackathon/HoneySpam/etc/adminhtml.xml @@ -1,5 +1,4 @@ - - diff --git a/app/code/community/Hackathon/HoneySpam/etc/config.xml b/app/code/community/Hackathon/HoneySpam/etc/config.xml index 5df3d15..edddd9b 100644 --- a/app/code/community/Hackathon/HoneySpam/etc/config.xml +++ b/app/code/community/Hackathon/HoneySpam/etc/config.xml @@ -1,5 +1,4 @@ - - diff --git a/app/code/community/Hackathon/HoneySpam/etc/system.xml b/app/code/community/Hackathon/HoneySpam/etc/system.xml index 58dc32e..a01a906 100644 --- a/app/code/community/Hackathon/HoneySpam/etc/system.xml +++ b/app/code/community/Hackathon/HoneySpam/etc/system.xml @@ -1,5 +1,4 @@ - - - + 100 - + hackathon text @@ -43,7 +44,8 @@ 1 1 - + 10 1 @@ -64,12 +66,14 @@ text - 20 + 20 validate-xml-identifier 1 1 1 - 1 + + 1 + @@ -90,7 +94,9 @@ 1 1 1 - 1 + + 1 + @@ -112,7 +118,9 @@ 1 1 1 - 1 + + 1 + diff --git a/app/design/frontend/base/default/layout/honeyspam.xml b/app/design/frontend/base/default/layout/honeyspam.xml index 39ca00d..cf8310b 100644 --- a/app/design/frontend/base/default/layout/honeyspam.xml +++ b/app/design/frontend/base/default/layout/honeyspam.xml @@ -1,5 +1,4 @@ - - @@ -34,55 +33,79 @@ - - + + - - + + - - + + - - - - + - - + diff --git a/app/design/frontend/base/default/template/hackathon/honeyspam/error.phtml b/app/design/frontend/base/default/template/hackathon/honeyspam/error.phtml index 210cb85..985e052 100644 --- a/app/design/frontend/base/default/template/hackathon/honeyspam/error.phtml +++ b/app/design/frontend/base/default/template/hackathon/honeyspam/error.phtml @@ -12,16 +12,16 @@ * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * - * @category  Hackathon - * @package   Hackathon_HoneySpam - * @author    Andreas Emer + * @category Hackathon + * @package Hackathon_HoneySpam + * @author Andreas Emer * @author Fabian Blechschmidt * @author Sascha Wohlgemuth * @author Bastian Ike * @author Peter Ukener * @copyright 2012 Magento Hackathon - * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0) - * @link      http://www.magento-hackathon.de/ + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @link http://www.magento-hackathon.de/ */ ?> -__('The form could not be sent because of SPAM detection!') ?> \ No newline at end of file +__('The form could not be sent because of SPAM detection!') ?> diff --git a/app/design/frontend/base/default/template/hackathon/honeyspam/honeypot.phtml b/app/design/frontend/base/default/template/hackathon/honeyspam/honeypot.phtml index 7133e3f..2feaaef 100644 --- a/app/design/frontend/base/default/template/hackathon/honeyspam/honeypot.phtml +++ b/app/design/frontend/base/default/template/hackathon/honeyspam/honeypot.phtml @@ -12,19 +12,20 @@ * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * - * @category  Hackathon - * @package   Hackathon_HoneySpam - * @author    Andreas Emer + * @category Hackathon + * @package Hackathon_HoneySpam + * @author Andreas Emer * @author Fabian Blechschmidt * @author Sascha Wohlgemuth * @author Bastian Ike * @author Peter Ukener * @copyright 2012 Magento Hackathon - * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0) - * @link      http://www.magento-hackathon.de/ + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + * @link http://www.magento-hackathon.de/ */ ?> - + diff --git a/app/etc/modules/Hackathon_HoneySpam.xml b/app/etc/modules/Hackathon_HoneySpam.xml index 97e0146..cba0107 100644 --- a/app/etc/modules/Hackathon_HoneySpam.xml +++ b/app/etc/modules/Hackathon_HoneySpam.xml @@ -1,5 +1,4 @@ - - diff --git a/js/hackathon/HoneySpam/honeyspam.js b/js/hackathon/HoneySpam/honeyspam.js index b76f195..15f43d5 100644 --- a/js/hackathon/HoneySpam/honeyspam.js +++ b/js/hackathon/HoneySpam/honeyspam.js @@ -11,15 +11,15 @@ * obtain it through the world-wide-web, please send an email * to license@magentocommerce.com so we can send you a copy immediately. * - * @category  Hackathon - * @package   Hackathon_HoneySpam - * @author    Andreas Emer + * @category Hackathon + * @package Hackathon_HoneySpam + * @author Andreas Emer * @author Fabian Blechschmidt * @author Sascha Wohlgemuth * @author Bastian Ike * @author Peter Ukener * @copyright 2012 Magento Hackathon - * @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @link http://www.magento-hackathon.de/ */