1: <?php
2:
3: /*
4:
5: *
6: * NOTICE OF LICENSE
7: *
8: * This source file is subject to the Open Software License (OSL 3.0)
9: * or OpenGPL v3 license (GNU Public License V3.0)
10: * that is bundled with this package in the file LICENSE.txt.
11: * It is also available through the world-wide-web at this URL:
12: * http://opensource.org/licenses/osl-3.0.php
13: * or
14: * http://www.gnu.org/licenses/gpl-3.0.txt
15: * If you did not receive a copy of the license and are unable to
16: * obtain it through the world-wide-web, please send an email
17: * to info@e-abi.ee so we can send you a copy immediately.
18: *
19: * DISCLAIMER
20: *
21: * Do not edit or add to this file if you wish to upgrade this module to newer
22: * versions in the future.
23: *
24: * @category Eabi
25: * @package Eabi_Dpd
26: * @copyright Copyright (c) 2014 Aktsiamaailm LLC (http://en.e-abi.ee/)
27: * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
28: * @license http://www.gnu.org/licenses/gpl-3.0.txt GNU Public License V3.0
29: * @author Matis Halmann
30: *
31:
32: */
33:
34: /**
35: * Description of Email
36: *
37: * @author Matis
38: */
39: class Eabi_Livehandler_Block_Email extends Mage_Core_Block_Template {
40: protected $_addressEncoded;
41: protected $_key;
42:
43: public function _construct() {
44: $this->setTemplate('eabi_livehandler/email.phtml');
45: parent::_construct();
46: }
47:
48: /**
49: *
50: * @return Eabi_Livehandler_Helper_Data
51: */
52: protected function _getEabi() {
53: return Mage::helper('eabi');
54: }
55:
56: public function getHtmlId() {
57: $id = $this->getData('html_id');
58: if (!$id) {
59: $id = uniqid();
60: $this->setData('html_id', $id);
61: }
62: return $id;
63:
64: }
65:
66: protected function _encodeAddress() {
67: $encoding = 'UTF-8';
68: $address = $this->getAddress();
69: $addressAssocArray = array();
70: for ($i = 0; $i < mb_strlen($address, $encoding); $i++) {
71: $addressAssocArray[(string)$i] = mb_substr($address, $i, 1, $encoding);
72: }
73: $this->_arrayShuffleAssoc($addressAssocArray);
74: $addressArray = array();
75: foreach ($addressAssocArray as $letter) {
76: $addressArray[] = $letter;
77: }
78: $this->_addressEncoded = $addressArray;
79: $this->_key = array_keys($addressAssocArray);
80: return $addressArray;
81:
82: }
83:
84: public function getAddressEncoded() {
85: if (!$this->_addressEncoded) {
86: $this->_encodeAddress();
87: }
88: return $this->_addressEncoded;
89: }
90:
91: public function getAddressKey() {
92: if (!$this->_addressEncoded) {
93: $this->_encodeAddress();
94: }
95: return $this->_key;
96: }
97:
98:
99: public function directToJson($value) {
100: return json_encode($value);
101: }
102:
103: protected function _arrayShuffleAssoc(&$array) {
104: $keys = array_keys($array);
105:
106: shuffle($keys);
107:
108: foreach($keys as $key) {
109: $new[$key] = $array[$key];
110: }
111:
112: $array = $new;
113:
114: return true;
115: }
116:
117:
118: }
119: