Skip to content

Commit

Permalink
fix formatting, cleanup weird characters, reorder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Schrank committed Dec 3, 2020
1 parent e3c780f commit 1cea728
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 166 deletions.
29 changes: 19 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

<?php echo $this->getChildHtml('form_fields_before') ?>

within the `<form> ... </form>` 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

<?php echo $this->getChildHtml('form_fields_before') ?>

within the `<form> ... </form>` 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

Expand All @@ -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!
21 changes: 11 additions & 10 deletions app/code/community/Hackathon/HoneySpam/Block/Honeypot.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Magento
*
Expand All @@ -12,26 +13,21 @@
* 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 <honeyspam@emdec.de>
* @category Hackathon
* @package Hackathon_HoneySpam
* @author Andreas Emer <honeyspam@emdec.de>
* @author Fabian Blechschmidt <hackathon@fabian-blechschmidt.de>
* @author Sascha Wohlgemuth <sascha.wohlgemuth@gmail.com>
* @author Bastian Ike <bastian.ike@gmail.com>
* @author Peter Ukener <peterukener@gmail.com>
* @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
*/
Expand All @@ -42,5 +38,10 @@ public function getHoneypotName()
return $helper->getHoneypotName();
}

protected function _construct()
{
parent::_construct();
}


}
65 changes: 35 additions & 30 deletions app/code/community/Hackathon/HoneySpam/Helper/Data.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Magento
*
Expand All @@ -12,35 +13,27 @@
* 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 <honeyspam@emdec.de>
* @category Hackathon
* @package Hackathon_HoneySpam
* @author Andreas Emer <honeyspam@emdec.de>
* @author Fabian Blechschmidt <hackathon@fabian-blechschmidt.de>
* @author Sascha Wohlgemuth <sascha.wohlgemuth@gmail.com>
* @author Bastian Ike <bastian.ike@gmail.com>
* @author Peter Ukener <peterukener@gmail.com>
* @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
Expand All @@ -49,27 +42,31 @@ public function isHoneypotNameEnabled()
{
return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLE_POT);
}

/**
* @return bool
*/
public function isSpamIndexingEnabled()
{
return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLE_SPAM);
}

/**
* @return bool
*/
public function isHoneypotAccountCreateTimeEnabled()
{
return Mage::getStoreConfigFlag(self::CONFIG_PATH_ENABLE_TIME);
}

/**
* @return string
*/
public function getSpamIndexLevel()
{
return Mage::getStoreConfig(self::CONFIG_PATH_INDEX_LEVEL);
}

/**
* @return string
*/
Expand All @@ -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
*/
Expand All @@ -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);
}

/**
Expand Down
18 changes: 10 additions & 8 deletions app/code/community/Hackathon/HoneySpam/Model/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <honeyspam@emdec.de>
* @category Hackathon
* @package Hackathon_HoneySpam
* @author Andreas Emer <honeyspam@emdec.de>
* @author Fabian Blechschmidt <hackathon@fabian-blechschmidt.de>
* @author Sascha Wohlgemuth <sascha.wohlgemuth@gmail.com>
* @author Bastian Ike <bastian.ike@gmail.com>
* @author Peter Ukener <peterukener@gmail.com>
* @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
Expand All @@ -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)
Expand Down Expand Up @@ -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");
}
Expand All @@ -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...");
}
Expand Down
Loading

0 comments on commit 1cea728

Please sign in to comment.