HusseyCoding_CookiesForComments - Version 1.0.0

Version Notes

Initial release.

Download this release

Release Info

Developer Hussey Coding
Extension HusseyCoding_CookiesForComments
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/community/HusseyCoding/CookiesForComments/Block/CookiesForComments.php ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_CookiesForComments_Block_CookiesForComments extends Mage_Core_Block_Template
3
+ {
4
+ public function getImageUrl()
5
+ {
6
+ return Mage::helper('cookiesforcomments')->getImageUrl();
7
+ }
8
+ }
app/code/community/HusseyCoding/CookiesForComments/Helper/Data.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class HusseyCoding_CookiesForComments_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+ public function getImageUrl()
5
+ {
6
+ if ($string = $this->_getRandomString()):
7
+ if ($image = Mage::getDesign()->getSkinUrl('images/cookiesforcomments.php')):
8
+ return $image . '?k=' . $string;
9
+ endif;
10
+ endif;
11
+
12
+ return false;
13
+ }
14
+
15
+ private function _getRandomString()
16
+ {
17
+ $session = Mage::getSingleton('customer/session');
18
+ if (!$session->getCookiesForComments()):
19
+ $this->_setRandomString($session);
20
+ endif;
21
+
22
+ return $session->getCookiesForComments();
23
+ }
24
+
25
+ private function _setRandomString($session)
26
+ {
27
+ $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
28
+ $size = strlen($chars);
29
+ $string = '';
30
+ for ($i = 0; $i < 20; $i++):
31
+ $string .= $chars[rand(0, $size - 1)];
32
+ endfor;
33
+
34
+ $session->setCookiesForComments($string);
35
+ }
36
+ }
app/code/community/HusseyCoding/CookiesForComments/controllers/IndexController.php ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ include_once('Mage/Contacts/controllers/IndexController.php');
3
+
4
+ class HusseyCoding_CookiesForComments_IndexController extends Mage_Contacts_IndexController
5
+ {
6
+ public function postAction()
7
+ {
8
+ $session = Mage::getSingleton('customer/session');
9
+ if ($string = $session->getCookiesForComments()):
10
+ if (Mage::getModel('core/cookie')->get($string)):
11
+ parent::postAction();
12
+ endif;
13
+ endif;
14
+
15
+ return;
16
+ }
17
+ }
app/code/community/HusseyCoding/CookiesForComments/etc/config.xml ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <HusseyCoding_CookiesForComments>
5
+ <version>1.0.0</version>
6
+ </HusseyCoding_CookiesForComments>
7
+ </modules>
8
+ <global>
9
+ <blocks>
10
+ <cookiesforcomments>
11
+ <class>HusseyCoding_CookiesForComments_Block</class>
12
+ </cookiesforcomments>
13
+ </blocks>
14
+ <helpers>
15
+ <cookiesforcomments>
16
+ <class>HusseyCoding_CookiesForComments_Helper</class>
17
+ </cookiesforcomments>
18
+ </helpers>
19
+ </global>
20
+ <frontend>
21
+ <layout>
22
+ <updates>
23
+ <cookiesforcomments>
24
+ <file>cookiesforcomments.xml</file>
25
+ </cookiesforcomments>
26
+ </updates>
27
+ </layout>
28
+ <routers>
29
+ <contacts>
30
+ <args>
31
+ <modules>
32
+ <HusseyCoding_CookiesForComments before="Mage_Contacts">HusseyCoding_CookiesForComments</HusseyCoding_CookiesForComments>
33
+ </modules>
34
+ </args>
35
+ </contacts>
36
+ </routers>
37
+ </frontend>
38
+ </config>
app/design/frontend/base/default/layout/cookiesforcomments.xml ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="0.1.0">
3
+ <contacts_index_index>
4
+ <block type="cookiesforcomments/cookiesForComments" template="cookiesforcomments/cookiesforcomments.phtml" name="cookiesforcomments" after="-" parent="content" />
5
+ </contacts_index_index>
6
+ </layout>
app/design/frontend/base/default/template/cookiesforcomments/cookiesforcomments.phtml ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php if ($url = $this->getImageUrl()): ?>
2
+ <img src="<?php echo $url; ?>" alt="" />
3
+ <?php endif; ?>
app/etc/modules/HusseyCoding_CookiesForComments.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <HusseyCoding_CookiesForComments>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </HusseyCoding_CookiesForComments>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>HusseyCoding_CookiesForComments</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/osl-3.0.php">OSL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Adds contact form spam protection based on the popular WordPress plugin.</summary>
10
+ <description>This solution protects your contact form from spam submissions by requiring particular cookie contents for the form to be successfully submitted. This cookie contents will not be generated by spam submissions meaning the submission fails.</description>
11
+ <notes>Initial release.</notes>
12
+ <authors><author><name>Hussey Coding</name><user>husseycoding</user><email>info@husseycoding.co.uk</email></author></authors>
13
+ <date>2015-02-27</date>
14
+ <time>12:42:20</time>
15
+ <contents><target name="magecommunity"><dir name="HusseyCoding"><dir name="CookiesForComments"><dir name="Block"><file name="CookiesForComments.php" hash="4718fdc64ed69c4ba83eb40f24d5a85c"/></dir><dir name="controllers"><file name="IndexController.php" hash="1f5d2044804bdf69e5840f278a72013c"/></dir><dir name="etc"><file name="config.xml" hash="e1800e7fb76f7f3187c9d480f7ff216b"/></dir><dir name="Helper"><file name="Data.php" hash="08f291c7f4a3167b2ccd3b62a5b787fc"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="HusseyCoding_CookiesForComments.xml" hash="f20db159beaacf3e65aa9748289416e5"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="cookiesforcomments.xml" hash="258a9712d36b8efd445168af3bbf3ad8"/></dir><dir name="template"><dir name="cookiesforcomments"><file name="cookiesforcomments.phtml" hash="0241a5891f68a6b9a7ae7bd866276d6a"/></dir></dir></dir></dir></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><file name="blank.gif" hash="b47f9339eb4c6d57b918e80429ed9b8e"/><file name="cookiesforcomments.php" hash="37f803bd7c9b9eb913a7e4ffae0ea8e8"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
skin/frontend/base/default/images/blank.gif ADDED
Binary file
skin/frontend/base/default/images/cookiesforcomments.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ if (isset($_GET['k'])):
3
+ @setcookie($_GET['k'], time(), time() + 604800, '/', $_SERVER['HTTP_HOST'], false, false);
4
+ endif;
5
+
6
+ header("Content-type: image/gif");
7
+ readfile( './blank.gif' );
8
+
9
+ die();
10
+ ?>