Aoe_HtmlChecker - Version 0.1.1

Version Notes

still in development, don't use it in live projects

Download this release

Release Info

Developer Christoph Frenes
Extension Aoe_HtmlChecker
Version 0.1.1
Comparing to
See all releases


Version 0.1.1

app/code/community/Aoe/HtmlChecker/Helper/Data.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * just the usal empty helper class
4
+ *
5
+ * @author Christoph Frenes <cfrenes@animachi.de>
6
+ */
7
+ class Aoe_HtmlChecker_Helper_Data extends Mage_Core_Helper_Abstract
8
+ {
9
+
10
+ }
app/code/community/Aoe/HtmlChecker/Model/Validator.php ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Validator class
4
+ *
5
+ * @category Aoe
6
+ * @package Aoe_HtmlChecker
7
+ * @author Christoph Frenes <cfrenes@animachi.de>
8
+ */
9
+ class Aoe_HtmlChecker_Model_Validator
10
+ {
11
+ const W3C_VALIDATOR = 'http://validator.w3.org/check';
12
+
13
+ /**
14
+ * check given url via curl and extract w3c response from the headers
15
+ *
16
+ * @see http://validator.w3.org/docs/api.html
17
+ * @param string $url
18
+ * @return array
19
+ */
20
+ public function checkPage($url = null, $detail = false)
21
+ {
22
+ if (empty($url)) {
23
+ Mage::throwException('URL must be given for W3C check');
24
+ }
25
+
26
+ $file = Mage::getBaseDir(Mage_Core_Model_Store::URL_TYPE_MEDIA) . '/aoehtmlchecker.html';
27
+ //$this->_data['detailUrl'] = self::W3C_VALIDATOR . "?uri=$url";
28
+
29
+ $ch = curl_init($url);
30
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
31
+
32
+ // save current page to temp file in media dir
33
+ file_put_contents($file, curl_exec($ch));
34
+
35
+ $post = array(
36
+ 'uploaded_file' => '@'.$file.';type=text/html',
37
+ 'submit_button' => 'Check'
38
+ );
39
+
40
+ if ($detail == false) {
41
+ $post['output'] = 'soap12';
42
+ }
43
+
44
+ curl_setopt($ch, CURLOPT_URL, 'http://validator.w3.org/check');
45
+
46
+ if ($detail == false) {
47
+ curl_setopt($ch, CURLOPT_HEADER, 1);
48
+ } else {
49
+ curl_setopt($ch, CURLOPT_HEADER, 0);
50
+ }
51
+ curl_setopt($ch, CURLOPT_VERBOSE, 0);
52
+ curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
53
+ curl_setopt($ch, CURLOPT_POST, 1);
54
+ curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
55
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
56
+
57
+ $result = curl_exec($ch);
58
+ $error = curl_error($ch);
59
+
60
+ curl_close($ch);
61
+ unlink($file);
62
+
63
+ $data = array(
64
+ 'connection' => false,
65
+ 'errors' => 0,
66
+ 'warnings' => 0,
67
+ 'status' => '',
68
+ 'detailUrl' => Mage::getBaseUrl() . 'htmlchecker/validation/detail?url='.urlencode($url),
69
+ 'detailUrlShort' => Mage::getBaseUrl() . 'htmlchecker/validation/detail'
70
+ );
71
+
72
+ if (preg_match('/X-W3C-Validator-Status:(.+)\n/uUi', $result, $state) &&
73
+ preg_match('/X-W3C-Validator-Errors:(.+)\n/uUi', $result, $errors) &&
74
+ preg_match('/X-W3C-Validator-Warnings:(.+)\n/uUi', $result, $warnings) &&
75
+ empty($error)) {
76
+ $data['connection'] = true;
77
+ $data['status'] = trim($state[1]);
78
+ $data['errors'] = trim($errors[1]);
79
+ $data['warnings'] = trim($warnings[1]);
80
+ $data['message'] = Mage::helper('core')->__('Validation ready! Your result: <span style="font-weight: bold;">%s - %s error(s) / %s warning(s)</span>.<br />See %s for details.', trim($state[1]), trim($errors[1]), trim($warnings[1]), '<a href="'.$data['detailUrl'].'">'.$data['detailUrlShort'].'</a>');
81
+ } else {
82
+ $data['connection'] = false;
83
+ $data['message'] = Mage::helper('core')->__('Connection to W3C validator failed.');
84
+ }
85
+
86
+ if ($detail == false) {
87
+ return $data;
88
+ } else {
89
+ $result = preg_replace('/(\.\/style\/base)/uUi', self::W3C_VALIDATOR . "/../$1", $result);
90
+ $result = preg_replace('/(\.\/style\/results)/uUi', self::W3C_VALIDATOR . "/../$1", $result);
91
+ $result = preg_replace('/(\.?\/?images\/)/uUi', self::W3C_VALIDATOR . "/../$1", $result);
92
+
93
+ return $result;
94
+ }
95
+ }
96
+ }
app/code/community/Aoe/HtmlChecker/controllers/ValidationController.php ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Controller for ayax requests
4
+ *
5
+ * @category Aoe
6
+ * @package Aoe_HtmlChecker
7
+ * @author Christoph Frenes <cfrenes@animachi.de>
8
+ */
9
+ class Aoe_HtmlChecker_ValidationController extends Mage_Core_Controller_Front_Action
10
+ {
11
+ public function indexAction()
12
+ {
13
+ echo 'Aoe_HtmlChecker';
14
+ }
15
+
16
+
17
+ public function htmlAction()
18
+ {
19
+ header("Pragma: no-cache");
20
+ header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
21
+ header("Content-Type: text/html");
22
+
23
+ try {
24
+ $url = urldecode($this->_request->getParam('url'));
25
+ $_data = Mage::getModel('aoehtmlchecker/validator')->checkPage($url);
26
+ echo json_encode($_data);
27
+ } catch (Exception $e) {
28
+ Mage::getSingleton('core/session')->addError($e->getMessage());
29
+ $this->loadLayout();
30
+ $this->renderLayout();
31
+ }
32
+ }
33
+
34
+ public function detailAction()
35
+ {
36
+ header("Pragma: no-cache");
37
+ header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate");
38
+ header("Content-Type: text/html");
39
+
40
+ echo '<div style="text-align: center; padding: 5px; font-size: 18px; color: red; background-color: white; border: 4px solid red;">'.$this->__('Attention! This page is not the original W3C validator. It\'s just rendered from there and so not all links will work.<br>Click <a href="'.Aoe_HtmlChecker_Model_Validator::W3C_VALIDATOR.'">here</a> for the original.').'</div>';
41
+
42
+ try {
43
+ $url = urldecode($this->_request->getParam('url'));
44
+ $_data = Mage::getModel('aoehtmlchecker/validator')->checkPage($url, true);
45
+ echo $_data;
46
+ } catch (Exception $e) {
47
+ Mage::getSingleton('core/session')->addError($e->getMessage());
48
+ $this->loadLayout();
49
+ $this->renderLayout();
50
+ }
51
+
52
+ }
53
+ }
app/code/community/Aoe/HtmlChecker/etc/config.xml ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Aoe_HtmlChecker>
5
+ <version>0.1.1</version>
6
+ </Aoe_HtmlChecker>
7
+ </modules>
8
+
9
+ <global>
10
+ <helpers>
11
+ <aoehtmlchecker>
12
+ <class>Aoe_HtmlChecker_Helper</class>
13
+ </aoehtmlchecker>
14
+ </helpers>
15
+ <models>
16
+ <aoehtmlchecker>
17
+ <class>Aoe_HtmlChecker_Model</class>
18
+ </aoehtmlchecker>
19
+ </models>
20
+
21
+ <!--
22
+ <events>
23
+ <controller_action_layout_render_before>
24
+ <observers>
25
+ <aoehtmlchecker>
26
+ <type>model</type>
27
+ <class>Aoe_HtmlChecker_Model_Observer</class>
28
+ <method>checkCurrentPage</method>
29
+ </aoehtmlchecker>
30
+ </observers>
31
+ </controller_action_layout_render_before>
32
+ </events>-->
33
+ </global>
34
+
35
+ <frontend>
36
+ <routers>
37
+ <aoehtmlchecker>
38
+ <use>standard</use>
39
+ <args>
40
+ <module>Aoe_HtmlChecker</module>
41
+ <frontName>htmlchecker</frontName>
42
+ </args>
43
+ </aoehtmlchecker>
44
+ </routers>
45
+
46
+ <layout>
47
+ <updates>
48
+ <aoehtmlchecker>
49
+ <file>htmlchecker.xml</file>
50
+ </aoehtmlchecker>
51
+ </updates>
52
+ </layout>
53
+ </frontend>
54
+ </config>
app/code/community/Aoe/HtmlChecker/etc/system.xml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <sections>
4
+ <dev>
5
+ <groups>
6
+ <debug>
7
+ <fields>
8
+ <htmlchecker translate="label" module="aoehtmlchecker">
9
+ <label>HTML Check</label>
10
+ <frontend_type>select</frontend_type>
11
+ <sort_order>30</sort_order>
12
+ <show_in_default>1</show_in_default>
13
+ <show_in_website>1</show_in_website>
14
+ <show_in_store>1</show_in_store>
15
+ <source_model>adminhtml/system_config_source_yesno</source_model>
16
+ </htmlchecker>
17
+ </fields>
18
+ </debug>
19
+ </groups>
20
+ </dev>
21
+ </sections>
22
+ </config>
app/design/frontend/base/default/layout/htmlchecker.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <layout version="0.1.0">
3
+ <default>
4
+ <reference name="before_body_end">
5
+ <block type="core/template" name="htmlchecker" as="htmlchecker" after="-" template="htmlchecker/html.phtml" />
6
+ </reference>
7
+ </default>
8
+ </layout>
app/design/frontend/base/default/template/htmlchecker/html.phtml ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php if (Mage::getStoreConfig('dev/debug/htmlchecker') == 1): ?>
2
+ <div id="htmlchecker">
3
+ <div id="validationResult"><?php echo $this->__('Validating... Please wait') ?></div>
4
+ </div>
5
+
6
+ <script type="text/javascript">
7
+ $('htmlchecker').setStyle({
8
+ position: 'fixed',
9
+ bottom: '35px',
10
+ zIndex: '999999',
11
+ left: '35px',
12
+ border: '2px solid gray',
13
+ borderRadius: '5px',
14
+ padding: '6px 12px 5px 30px',
15
+ textAlign: 'left',
16
+ background: 'white url(<?php echo $this->getSkinUrl('images/htmlchecker/htmlchecker_processing.gif') ?>) 8px 4px no-repeat'
17
+ });
18
+
19
+ $('validationResult').setStyle({
20
+ font: '12px arial, verdana, helvetica, sans-serif',
21
+ color: 'black'
22
+ });
23
+
24
+ document.observe('dom:loaded', function() {
25
+ var url = '<?php echo Mage::getBaseUrl() . '/htmlchecker/validation/html?url=' . urlencode(Mage::helper('core/url')->getCurrentUrl()) ?>';
26
+ var styleError = '#faebe7 url(<?php echo $this->getSkinUrl('images/htmlchecker/htmlchecker_error.gif') ?>) 8px 4px no-repeat';
27
+ var styleSuccess = '#eff5ea url(<?php echo $this->getSkinUrl('images/htmlchecker/htmlchecker_success.gif') ?>) 8px 4px no-repeat';
28
+
29
+ new Ajax.Request(url, {
30
+ method: 'post',
31
+ onSuccess: function(transport) {
32
+ var data = transport.responseText.evalJSON();
33
+
34
+ $('validationResult').update(data.message);
35
+
36
+ if (data.success == false || data.errors > 0) {
37
+ $('htmlchecker').setStyle({ background: styleError });
38
+ } else {
39
+ $('htmlchecker').setStyle({ background: styleSuccess });
40
+ }
41
+ },
42
+ onFailure: function() {
43
+ $('validationResult').update('<?php echo $this->__('Connection to W3C validator failed.') ?>');
44
+ $('htmlchecker').setStyle({ background: styleError });
45
+ }
46
+ });
47
+ });
48
+ </script>
49
+ <?php endif ?>
app/design/frontend/base/default/template/htmlchecker/msg.phtml ADDED
@@ -0,0 +1 @@
 
1
+ <?php echo 'Hallo Welt' ?>
app/etc/modules/Aoe_HtmlChecker.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <config>
3
+ <modules>
4
+ <Aoe_HtmlChecker>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Aoe_HtmlChecker>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Aoe_HtmlChecker</name>
4
+ <version>0.1.1</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://www.opensource.org/licenses/osl-3.0.php">OSL v3.0</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Check your magento project against w3c validator.</summary>
10
+ <description>The module provides you with a little info bubble that shows you the W3C validator results of each page of your magento project you open.</description>
11
+ <notes>still in development, don't use it in live projects</notes>
12
+ <authors><author><name>Christoph Frenes</name><user>Blitz</user><email>cfrenes@animachi.de</email></author></authors>
13
+ <date>2011-11-19</date>
14
+ <time>08:06:26</time>
15
+ <contents><target name="magecommunity"><dir name="Aoe"><dir name="HtmlChecker"><dir name="Helper"><file name="Data.php" hash="3a07b4964f2d49714d578be111330585"/></dir><dir name="Model"><file name="Validator.php" hash="85268544604cc452459a97f049ead016"/></dir><dir name="controllers"><file name="ValidationController.php" hash="77413ba9f33e0aa99b063427cfb13027"/></dir><dir name="etc"><file name="config.xml" hash="fcffb3ca2f43d5b571929c3a42705c3f"/><file name="system.xml" hash="6a84213fe27f07f600e8289fc0862234"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Aoe_HtmlChecker.xml" hash="90bf794b95f57bdffe735488324efaae"/></dir></target><target name="mageskin"><dir name="frontend"><dir name="base"><dir name="default"><dir name="images"><dir name="htmlchecker"><file name="htmlchecker_error.gif" hash="e4f28607f075a105e53fa3113d84bd26"/><file name="htmlchecker_processing.gif" hash="e805ea7eca1f34c75ba0f93780d32d38"/><file name="htmlchecker_success.gif" hash="834dfafd5f8b44c4b24a4c00add56fcf"/></dir></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="htmlchecker"><file name="html.phtml" hash="85120e2d024d7d605d59041202c99d2a"/><file name="msg.phtml" hash="fc2bdde7730eed7faa7373c962aac8fe"/></dir></dir><dir name="layout"><file name="htmlchecker.xml" hash="5a5de51c65ffd2bf236caca33da44bc8"/></dir></dir></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>
skin/frontend/base/default/images/htmlchecker/htmlchecker_error.gif ADDED
Binary file
skin/frontend/base/default/images/htmlchecker/htmlchecker_processing.gif ADDED
Binary file
skin/frontend/base/default/images/htmlchecker/htmlchecker_success.gif ADDED
Binary file