chat_tidio - Version 1.0.0

Version Notes

Notes

Download this release

Release Info

Developer Tytus Gołas
Extension chat_tidio
Version 1.0.0
Comparing to
See all releases


Version 1.0.0

app/code/local/Tidio/Chat/Block/Adminhtml/Menu.php ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Tidio_Chat_Block_Adminhtml_Menu extends Mage_Adminhtml_Block_Page_Menu
4
+ {
5
+ const XML_PATH_EXTENSION_PRIVATE_KEY = 'chat_section/chat_group/privatekey';
6
+ public function getMenuArray()
7
+ {
8
+ //Load standard menu
9
+ $parentArr = parent::getMenuArray();
10
+ $privateKey = Mage::getStoreConfig(self::XML_PATH_EXTENSION_PRIVATE_KEY);
11
+
12
+
13
+ $chatUrl = "'http://external.tidiochat.com/access?privateKey=$privateKey'";
14
+ $parentArr['tidio_chat'] = array(
15
+ 'label' => 'Tidio Chat',
16
+ 'active' => false,
17
+ 'sort_order' => 16,
18
+ 'click' => 'return false;',
19
+ 'url'=> '#' ,
20
+ 'level'=> 0,
21
+ 'last'=> true,
22
+ 'children' => array(
23
+ array(
24
+ 'label' => 'Tidio Chat',
25
+ 'active' => false,
26
+ 'sort_order' => 1,
27
+ 'click' => "window.open($chatUrl)",
28
+ 'url'=> '#' ,
29
+ 'level'=> 0,
30
+ 'last'=> true,
31
+ )
32
+ )
33
+ );
34
+
35
+ return $parentArr;
36
+ }
37
+
38
+ }
app/code/local/Tidio/Chat/Block/Script.php ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Tidio_Chat_Block_Script extends Mage_Core_Block_Template
4
+ {
5
+ const XML_PATH_EXTENSION_ENABLED = 'chat_section/chat_group/tidio_enable';
6
+ const XML_PATH_EXTENSION_PUBLIC_KEY = 'chat_section/chat_group/publickey';
7
+
8
+ protected function _construct()
9
+ {
10
+ parent::_construct();
11
+
12
+ }
13
+
14
+ public function canGenerate()
15
+ {
16
+ $extEnabled = (int) Mage::getStoreConfig(self::XML_PATH_EXTENSION_ENABLED);
17
+ $publicKey = Mage::getStoreConfig(self::XML_PATH_EXTENSION_PUBLIC_KEY);
18
+
19
+ if ($extEnabled && (trim($publicKey) != '')) {
20
+ return true;
21
+ }
22
+
23
+ return false;
24
+ }
25
+
26
+ public function getPublicKey()
27
+ {
28
+ return Mage::getStoreConfig(self::XML_PATH_EXTENSION_PUBLIC_KEY);
29
+ }
30
+ }
app/code/local/Tidio/Chat/Helper/Data.php ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Helper class file.
5
+ *
6
+ * @category TB
7
+ * @package Tidio_Chat
8
+ * @author tb
9
+ * @copyright Copyright (c) 2014
10
+ */
11
+ class Tidio_Chat_Helper_Data extends Mage_Core_Helper_Abstract
12
+ {
13
+
14
+ }
15
+
16
+ ?>
app/code/local/Tidio/Chat/Model/Observer.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Observer class file.
5
+ *
6
+ * @category TB
7
+ * @package Tidio_Chat
8
+ * @author tb
9
+ * @copyright Copyright (c) 2014
10
+ */
11
+
12
+ class Tidio_Chat_Model_Observer extends Mage_Core_Model_Abstract
13
+ {
14
+ // paths to configuration
15
+ const XML_PATH_EXTENSION_ENABLED = 'chat_section/chat_group/tidio_enable';
16
+ const XML_PATH_EXTENSION_PUBLIC_KEY = 'chat_section/chat_group/publickey';
17
+ const XML_PATH_EXTENSION_PRIVATE_KEY = 'chat_section/chat_group/privatekey';
18
+
19
+ private $extEnabled = null;
20
+ /**
21
+ * Constructor
22
+ *
23
+ */
24
+ public function __construct()
25
+ {
26
+ $this->extEnabled = (int) Mage::getStoreConfig(self::XML_PATH_EXTENSION_ENABLED);
27
+
28
+ // if extension not enabled, then return
29
+ if (!$this->extEnabled) {
30
+ return;
31
+ }
32
+
33
+ try {
34
+ } catch (Exception $e) {
35
+ }
36
+ }
37
+ /**
38
+ * Event dispatched after backoffice loaded
39
+ *
40
+ * @param array $observer
41
+ *
42
+ */
43
+ public function hookToAdminLoad($observer)
44
+ {
45
+ if ($this->extEnabled) {
46
+ $publicKey = Mage::getStoreConfig(self::XML_PATH_EXTENSION_PUBLIC_KEY);
47
+ $privateKey = Mage::getStoreConfig(self::XML_PATH_EXTENSION_PUBLIC_KEY);
48
+ if ((trim($publicKey) == '') || (trim($privateKey) == '')) {
49
+ $keys = $this->_getKeys();
50
+
51
+ $config = new Mage_Core_Model_Config();
52
+ $config->saveConfig(self::XML_PATH_EXTENSION_PUBLIC_KEY, $keys['public_key']);
53
+ $config->saveConfig(self::XML_PATH_EXTENSION_PRIVATE_KEY, $keys['private_key']);
54
+ }
55
+ }
56
+ }
57
+
58
+ private function _getKeys()
59
+ {
60
+ $domainName = $_SERVER['HTTP_HOST'];
61
+ $adminEmail = Mage::getStoreConfig('trans_email/ident_general/email');
62
+ $remoteAddr = $_SERVER['REMOTE_ADDR'];
63
+
64
+ $ch = curl_init();
65
+
66
+ curl_setopt($ch,CURLOPT_URL, "http://www.tidiochat.com/access/create?url=" . urlencode($domainName) . "&platform=magento&email=$adminEmail&_ip=$remoteAddr");
67
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
68
+
69
+ curl_setopt($ch, CURLOPT_HEADER, 0);
70
+ $output = curl_exec($ch);
71
+ curl_close($ch);
72
+
73
+ $json = json_decode($output);
74
+
75
+ return array('public_key' => $json->value->public_key, 'private_key' => $json->value->private_key);
76
+ }
77
+
78
+
79
+
80
+
81
+ }
app/code/local/Tidio/Chat/etc/config.xml ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+
3
+ <config>
4
+ <modules>
5
+ <Tidio_Chat>
6
+ <version>0.1</version>
7
+ </Tidio_Chat>
8
+ </modules>
9
+
10
+ <frontend>
11
+ <layout>
12
+ <updates>
13
+ <chat>
14
+ <file>tidio_chat.xml</file>
15
+ </chat>
16
+ </updates>
17
+ </layout>
18
+ </frontend>
19
+
20
+ <global>
21
+ <helpers>
22
+ <chat>
23
+ <class>Tidio_Chat_Helper</class>
24
+ </chat>
25
+ </helpers>
26
+
27
+ <resources>
28
+ <chat_setup>
29
+ <setup>
30
+ <module>Tidio_Chat</module>
31
+ </setup>
32
+ <connection>
33
+ <use>core_setup</use>
34
+ </connection>
35
+ </chat_setup>
36
+
37
+ <chat_write>
38
+ <connection>
39
+ <use>core_write</use>
40
+ </connection>
41
+ </chat_write>
42
+
43
+ <chat_read>
44
+ <connection>
45
+ <use>core_read</use>
46
+ </connection>
47
+ </chat_read>
48
+
49
+ <tidio_module_setup>
50
+ <setup>
51
+ <module>Tidio_Module</module>
52
+ </setup>
53
+ <connection>
54
+ <use>core_setup</use>
55
+ </connection>
56
+ </tidio_module_setup>
57
+ </resources>
58
+
59
+ <blocks>
60
+ <adminhtml>
61
+ <rewrite>
62
+ <page_menu>Tidio_Chat_Block_Adminhtml_Menu</page_menu>
63
+ </rewrite>
64
+ </adminhtml>
65
+
66
+ <chat>
67
+ <class>Tidio_Chat_Block</class>
68
+ </chat>
69
+ </blocks>
70
+
71
+ <events>
72
+ <adminhtml_block_html_before>
73
+ <observers>
74
+ <tidio_chat_load_model_observer>
75
+ <type>singleton</type>
76
+ <class>Tidio_Chat_Model_Observer</class>
77
+ <method>hookToAdminLoad</method>
78
+ </tidio_chat_load_model_observer>
79
+ </observers>
80
+ </adminhtml_block_html_before>
81
+
82
+ </events>
83
+
84
+ </global>
85
+
86
+ <adminhtml>
87
+ <acl>
88
+ <resources>
89
+ <admin>
90
+ <children>
91
+ <system>
92
+ <children>
93
+ <config>
94
+ <children>
95
+ <chat_section translate="title" module="chat">
96
+ <title>Chat</title>
97
+ <sort_order>100</sort_order>
98
+ </chat_section>
99
+ </children>
100
+ </config>
101
+ </children>
102
+ </system>
103
+ </children>
104
+ </admin>
105
+ </resources>
106
+ </acl>
107
+
108
+ </adminhtml>
109
+
110
+ </config>
app/code/local/Tidio/Chat/etc/system.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <config>
2
+ <tabs>
3
+ <chat_tab translate="label" module="chat">
4
+ <label>Tidio Extensions</label>
5
+ <sort_order>100</sort_order>
6
+ </chat_tab>
7
+ </tabs>
8
+
9
+ <sections>
10
+ <chat_section translate="label" module="chat">
11
+ <label>Tidio Chat Options</label>
12
+ <tab>chat_tab</tab>
13
+ <sort_order>1000</sort_order>
14
+ <show_in_default>1</show_in_default>
15
+ <show_in_website>1</show_in_website>
16
+ <show_in_store>1</show_in_store>
17
+ <groups>
18
+ <chat_group translate="label" module="chat">
19
+ <label>Tidio Chat Configuration</label>
20
+ <frontend_type>text</frontend_type>
21
+ <sort_order>1000</sort_order>
22
+ <show_in_default>1</show_in_default>
23
+ <show_in_website>1</show_in_website>
24
+ <show_in_store>1</show_in_store>
25
+ <fields>
26
+ <tidio_enable translate="label">
27
+ <label>Enable extension: </label>
28
+ <frontend_type>select</frontend_type>
29
+ <sort_order>10</sort_order>
30
+ <show_in_default>1</show_in_default>
31
+ <show_in_website>1</show_in_website>
32
+ <show_in_store>1</show_in_store>
33
+ <source_model>adminhtml/system_config_source_yesno</source_model>
34
+ </tidio_enable>
35
+ </fields>
36
+ </chat_group>
37
+ </groups>
38
+ </chat_section>
39
+ </sections>
40
+ </config>
app/design/frontend/base/default/layout/tidio_chat.xml ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * Magento
5
+ *
6
+ * NOTICE OF LICENSE
7
+ *
8
+ * This source file is subject to the Academic Free License (AFL 3.0)
9
+ * that is bundled with this package in the file LICENSE_AFL.txt.
10
+ * It is also available through the world-wide-web at this URL:
11
+ * http://opensource.org/licenses/afl-3.0.php
12
+ * If you did not receive a copy of the license and are unable to
13
+ * obtain it through the world-wide-web, please send an email
14
+ * to license@magentocommerce.com so we can send you a copy immediately.
15
+ *
16
+ * DISCLAIMER
17
+ *
18
+ * Do not edit or add to this file if you wish to upgrade Magento to newer
19
+ * versions in the future. If you wish to customize Magento for your
20
+ * needs please refer to http://www.magentocommerce.com for more information.
21
+ *
22
+ * @category design
23
+ * @package base_default
24
+ * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
25
+ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
26
+ */
27
+
28
+ -->
29
+ <layout version="0.1.0">
30
+
31
+ <!--
32
+ Default layout, loads most of the pages
33
+ -->
34
+ <default>
35
+ <!-- Tidio_Chat -->
36
+ <reference name="head">
37
+ <block type="chat/script" name="tidio_chat" as="tidio_chat" template="tidiochat/script.phtml" />
38
+ </reference>
39
+ </default>
40
+ </layout>
app/design/frontend/base/default/template/tidiochat/script.phtml ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ <?php if ($this->canGenerate()): ?>
2
+ <script src="http://www.tidiochat.com/uploads/redirect/<?php echo $this->getPublicKey() ?>.js"></script>
3
+ <?php endif; ?>
app/etc/modules/Tidio_Chat.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Tidio_Chat>
5
+ <active>true</active>
6
+ <codePool>local</codePool>
7
+ </Tidio_Chat>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>chat_tidio</name>
4
+ <version>1.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>GNU G eneral Public License ( GPL )</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Summary </summary>
10
+ <description>Description </description>
11
+ <notes>Notes </notes>
12
+ <authors><author><name>Tytus Go&#x142;as</name><user>tytustytus</user><email>tytus@tidio.net</email></author></authors>
13
+ <date>2014-08-26</date>
14
+ <time>09:48:01</time>
15
+ <contents><target name="magelocal"><dir name="Tidio"><dir name="Chat"><dir name="Block"><dir name="Adminhtml"><file name="Menu.php" hash="a36eeb7b9240eb4cae2b52d817883acb"/></dir><file name="Script.php" hash="4807b8dcd76f35a5b9d59aa8a7521d26"/></dir><dir name="Helper"><file name="Data.php" hash="4c45ffbb6ea2d5a043f7203842e2c079"/></dir><dir name="Model"><file name="Observer.php" hash="1452f7189bc873b4cbbb0dc15409a78e"/></dir><dir name="etc"><file name="config.xml" hash="3dc148206920cd8198644097705188ed"/><file name="system.xml" hash="ae343f9c2378f7e99252f8fb57b5f6a0"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Tidio_Chat.xml" hash="9788abdf12bd16ab9f6a83a908a05d31"/></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="tidio_chat.xml" hash="d969c4490a190e2127fd8e7caa5bf294"/></dir><dir name="template"><dir name="tidiochat"><file name="script.phtml" hash="b02b8e0f7bd476473eee0a0453f3491b"/></dir></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>