mailplatformconnector - Version 1.0.1

Version Notes

Changed code style to PSR-2
Moved code files from local to community
Removed unnecessary files
Removed unnecessary code lines
Removed unnecessary code logic
Fixed file names
Alternated code by Magento standards
Corrected English grammar
Tested on Magento CE 1.7, 1.8 and 1.9

Download this release

Release Info

Developer ADEO WEB
Extension mailplatformconnector
Version 1.0.1
Comparing to
See all releases


Version 1.0.1

app/code/community/Mp/Mailplatform/Block/Adminhtml/Newsletter/Subscriber.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_mailplatform_Block_Adminhtml_Newsletter_Subscriber extends Mage_Adminhtml_Block_Newsletter_Subscriber
4
+ {
5
+
6
+ public function __construct()
7
+ {
8
+ $this->setTemplate('newsletter/subscriber/list_mailplatform.phtml');
9
+ }
10
+
11
+ public function getmailplatformSyn()
12
+ {
13
+ return $this->getUrl('mailplatform/index/index');
14
+ }
15
+ }
app/code/community/Mp/Mailplatform/Helper/Data.php ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ <?php
2
+ class Mp_Mailplatform_Helper_Data extends Mage_Core_Helper_Abstract
3
+ {
4
+
5
+ }
6
+ ?>
app/code/community/Mp/Mailplatform/Model/Emailtype.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Model_Emailtype
4
+ {
5
+
6
+ public function toOptionArray()
7
+ {
8
+ return array(
9
+ array(
10
+ 'value' => 'html',
11
+ 'label' => Mage::helper('adminhtml')->__('HTML')
12
+ ),
13
+ array(
14
+ 'value' => 'text',
15
+ 'label' => Mage::helper('adminhtml')->__('Text')
16
+ )
17
+ );
18
+ }
19
+ }
app/code/community/Mp/Mailplatform/Model/Listids.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Model_Listids extends Varien_Object
4
+ {
5
+
6
+ protected $_options;
7
+
8
+ protected $_lists = array();
9
+
10
+ protected function getmodeloptions()
11
+ {
12
+ return Mage::getModel('mailplatform/mailplatform');
13
+ }
14
+
15
+ public function toOptionArray($isMultiselect = false)
16
+ {
17
+ if (! $this->_options) {
18
+ $arrresult = explode("/", Mage::app()->getRequest()->getRequestUri());
19
+
20
+ $i = 0;
21
+ $store = "";
22
+ $storetoload = 0;
23
+ foreach ($arrresult as $arr) {
24
+ if ($arr == "store") {
25
+ $store = $arrresult[$i + 1];
26
+ }
27
+ $i ++;
28
+ }
29
+
30
+ $allstores = Mage::getModel('core/store')->getCollection();
31
+
32
+ foreach ($allstores as $actualstore) {
33
+ if ($actualstore->getCode() == $store) {
34
+ $storetoload = (int) $actualstore->getId();
35
+ }
36
+ }
37
+
38
+ Mage::app()->setCurrentStore($storetoload);
39
+ $url2 = Mage::getStoreConfig('mailplatform/general/url');
40
+
41
+ $url = $this->getmodeloptions()->getXMLGeneralConfig("url", 1);
42
+
43
+ $username = $this->getmodeloptions()->getXMLGeneralConfig("username");
44
+ $token = $this->getmodeloptions()->getXMLGeneralConfig("token");
45
+
46
+ $xml = '<xmlrequest>
47
+ <username>' . trim($username) . '</username>
48
+ <usertoken>' . trim($token) . '</usertoken>
49
+ <requesttype>lists</requesttype>
50
+ <requestmethod>GetLists</requestmethod>
51
+ <details>all</details></xmlrequest>';
52
+
53
+ $ch = curl_init($url);
54
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
55
+ curl_setopt($ch, CURLOPT_POST, 1);
56
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
57
+ $result = @curl_exec($ch);
58
+ $xml_doc = simplexml_load_string($result);
59
+
60
+ if ($result === false) {
61
+ Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error!');
62
+ } else {
63
+ if ($xml_doc->status == 'SUCCESS') {
64
+ foreach ($xml_doc->data->item as $item) {
65
+ if ($item->username == $username) {
66
+ $this->_lists[] = array(
67
+ 'value' => $item->listid,
68
+ 'label' => $item->name
69
+ );
70
+ }
71
+ }
72
+ }
73
+ }
74
+
75
+ $this->_options = $this->_lists;
76
+ }
77
+
78
+ $options = $this->_options;
79
+ if (! $isMultiselect) {
80
+ array_unshift($options, array(
81
+ 'value' => '',
82
+ 'label' => Mage::helper('adminhtml')->__('--Please Select--')
83
+ ));
84
+ }
85
+ Mage::app()->setCurrentStore(0);
86
+ return $options;
87
+ }
88
+ }
app/code/community/Mp/Mailplatform/Model/Mailplatform.php ADDED
@@ -0,0 +1,283 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Model_Mailplatform extends Varien_Object
4
+ {
5
+
6
+ public function getXMLGeneralConfig($field)
7
+ {
8
+ return Mage::getStoreConfig('mailplatform/general/' . $field);
9
+ }
10
+
11
+ public function mailplatformAvailable()
12
+ {
13
+ $requestUri = Mage::app()->getRequest()->getRequestUri();
14
+ if ($this->getXMLGeneralConfig('active') == true && $this->getXMLGeneralConfig('username') != '' && $this->getXMLGeneralConfig('token') != '' && $this->getXMLGeneralConfig('listid') != '' && (strstr($requestUri, 'newsletter/') || strstr($requestUri, 'newsletter_subscriber/') || strstr($requestUri, 'customer/') || strstr($requestUri, 'mailplatform/index') || strstr($requestUri, 'checkout/onepage/'))) {
15
+ return true;
16
+ }
17
+ if (Mage::app()->getStore()->getId() == 0) {
18
+ if ($this->getXMLGeneralConfig('active') != true)
19
+ Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: Mailplatform is innactive');
20
+ if ($this->getXMLGeneralConfig('username') == '')
21
+ Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: API Username field is empty');
22
+ if ($this->getXMLGeneralConfig('token') == '')
23
+ Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: API Token field is empty');
24
+ if ($this->getXMLGeneralConfig('listid') == '')
25
+ Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: Mailplatform list field is empty');
26
+ }
27
+ return false;
28
+ }
29
+
30
+ private function getCustomerByEmail($email)
31
+ {
32
+ if ($email instanceof Mage_Customer_Model_Customer) {
33
+
34
+ $customer = $email;
35
+
36
+ return $customer;
37
+ }
38
+
39
+ $collection = Mage::getResourceModel('newsletter/subscriber_collection');
40
+ $collection->showCustomerInfo(true)
41
+ ->addSubscriberTypeField()
42
+ ->showStoreInfo()
43
+ ->addFieldToFilter('subscriber_email', $email)
44
+ ;
45
+
46
+ return $collection->getFirstItem();
47
+ }
48
+
49
+ private function getListIdByStoreId($storeId)
50
+ {
51
+ $store = Mage::getModel('core/store')->load($storeId);
52
+ $list_id = $store->getConfig('mailplatform/general/listid');
53
+
54
+ return $list_id;
55
+ }
56
+
57
+ public function subscribe($email)
58
+ {
59
+ if (! $this->mailplatformAvailable()) {
60
+ return;
61
+ }
62
+
63
+ $customer = $this->getCustomerByEmail($email);
64
+ $customerOldMail = $this->getCustomerOldEmail();
65
+
66
+ $merge_vars = array();
67
+
68
+ if ($email instanceof Mage_Customer_Model_Customer) {
69
+
70
+ $email = $customer->getEmail();
71
+
72
+ $merge_vars['FNAME'] = $customer->getFirstname();
73
+ $merge_vars['LNAME'] = $customer->getLastname();
74
+ } elseif ($customer->getCustomerId() != 0) {
75
+ $merge_vars['FNAME'] = $customer->getCustomerFirstname();
76
+ $merge_vars['LNAME'] = $customer->getCustomerLastname();
77
+ } else {
78
+ $merge_vars['FNAME'] = 'Guest';
79
+ $merge_vars['LNAME'] = 'Guest';
80
+ }
81
+
82
+ try {
83
+
84
+ $url2 = Mage::getStoreConfig('mailplatform/general/url');
85
+ $username = Mage::getStoreConfig('mailplatform/general/username');
86
+ $token = Mage::getStoreConfig('mailplatform/general/token');
87
+ $listid = Mage::getStoreConfig('mailplatform/general/listid');
88
+
89
+ $xml = '<xmlrequest>
90
+ <username>' . $username . '</username>
91
+ <usertoken>' . $token . '</usertoken>
92
+ <requesttype>subscribers</requesttype>
93
+ <requestmethod>AddSubscriberToList</requestmethod>
94
+ <details>';
95
+ $xml = $xml . '<emailaddress>' . $email . '</emailaddress>';
96
+ $xml = $xml . '<mailinglist>' . $listid . '</mailinglist>
97
+ <format>html</format>
98
+ <confirmed>yes</confirmed>
99
+ </details>
100
+ </xmlrequest>';
101
+ $ch = curl_init($url2);
102
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
103
+ curl_setopt($ch, CURLOPT_POST, 1);
104
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
105
+ $result = @curl_exec($ch);
106
+ if ($result === false) {
107
+ Mage::getSingleton('customer/session')->addError("Mailplatform - Error Performing the Request");
108
+ } else {
109
+ $xml_doc = simplexml_load_string($result);
110
+ Mage::getSingleton('customer/session')->addSuccess("Mailplatform - Added - " . $email . " OK");
111
+ if ($xml_doc->status != 'SUCCESS') {
112
+ Mage::getSingleton('customer/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
113
+ }
114
+ }
115
+
116
+ } catch (exception $e) {
117
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
118
+ }
119
+ }
120
+
121
+ public function unsubscribe($email)
122
+ {
123
+ if (! $this->mailplatformAvailable()) {
124
+ return;
125
+ }
126
+
127
+ try {
128
+
129
+ $url2 = Mage::getStoreConfig('mailplatform/general/url');
130
+ $username = Mage::getStoreConfig('mailplatform/general/username');
131
+ $token = Mage::getStoreConfig('mailplatform/general/token');
132
+ $listid = Mage::getStoreConfig('mailplatform/general/listid');
133
+
134
+ $xml = '<xmlrequest>
135
+ <username>' . $username . '</username>
136
+ <usertoken>' . $token . '</usertoken>
137
+ <requesttype>subscribers</requesttype>
138
+ <requestmethod>DeleteSubscriber</requestmethod>
139
+ <details>
140
+ <emailaddress>' . $email->getEmail() . '</emailaddress>
141
+ <list>' . $listid . '</list>
142
+ </details>
143
+ </xmlrequest>';
144
+
145
+ $ch = curl_init($url2);
146
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
147
+ curl_setopt($ch, CURLOPT_POST, 1);
148
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
149
+ $result = @curl_exec($ch);
150
+ if ($result === false) {
151
+ Mage::getSingleton('customer/session')->addError("Mailplatform - Error Performing the Request");
152
+ } else {
153
+ $xml_doc = simplexml_load_string($result);
154
+
155
+ Mage::getSingleton('customer/session')->addSuccess("Mailplatform - Removal - " . $email . " OK");
156
+
157
+ if ($xml_doc->status != 'SUCCESS') {
158
+ Mage::getSingleton('customer/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Submit to Mailplatform
164
+ */
165
+ } catch (exception $e) {
166
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
167
+ }
168
+ }
169
+
170
+ public function batchSubscribe($items)
171
+ {
172
+ if (! $this->mailplatformAvailable()) {
173
+ return;
174
+ }
175
+
176
+ $batch = array();
177
+ $customerInList = array();
178
+ foreach ($items as $item) {
179
+
180
+ $merge_vars = array();
181
+
182
+ if ($item['customer_id'] != 0) {
183
+ $merge_vars['FNAME'] = $item['customer_firstname'];
184
+ $merge_vars['LNAME'] = $item['customer_lastname'];
185
+ $merge_vars['StoreId'] = $item['store_id'];
186
+ } else {
187
+ $merge_vars['FNAME'] = 'Guest';
188
+ $merge_vars['LNAME'] = 'Guest';
189
+ $merge_vars['StoreId'] = $item['store_id'];
190
+ }
191
+
192
+ $merge_vars['EMAIL'] = $item['subscriber_email'];
193
+
194
+ $customerInList[$item['store_id']][] = $merge_vars;
195
+ }
196
+
197
+ try {
198
+ foreach ($customerInList as $store => $customers) {
199
+
200
+ Mage::app()->setCurrentStore($store);
201
+ $url2 = Mage::getStoreConfig('mailplatform/general/url');
202
+ $username = Mage::getStoreConfig('mailplatform/general/username');
203
+ $token = Mage::getStoreConfig('mailplatform/general/token');
204
+ $listid = Mage::getStoreConfig('mailplatform/general/listid');
205
+
206
+ if (count($customers) == 1) {
207
+
208
+ $xml = '<xmlrequest>
209
+ <username>' . $username . '</username>
210
+ <usertoken>' . $token . '</usertoken>
211
+ <requesttype>subscribers</requesttype>
212
+ <requestmethod>AddSubscriberToList</requestmethod>
213
+ <details>';
214
+ $xml = $xml . '<emailaddress>' . $customers[0]["EMAIL"] . '</emailaddress>';
215
+ $xml = $xml . '<mailinglist>' . $listid . '</mailinglist>
216
+ <format>html</format>
217
+ <confirmed>yes</confirmed>
218
+ </details>
219
+ </xmlrequest>';
220
+ $ch = curl_init($url2);
221
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
222
+ curl_setopt($ch, CURLOPT_POST, 1);
223
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
224
+ $result = @curl_exec($ch);
225
+ if ($result === false) {
226
+ Mage::getSingleton('adminhtml/session')->addError("Mailplatform - Error Performing the Request");
227
+ } else {
228
+ $xml_doc = simplexml_load_string($result);
229
+ Mage::getSingleton('adminhtml/session')->addSuccess("Mailplatform - " . $customers[0]["EMAIL"] . " OK");
230
+
231
+ if ($xml_doc->status != 'SUCCESS') {
232
+ Mage::getSingleton('adminhtml/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
233
+ }
234
+ }
235
+
236
+ } else {
237
+ foreach ($customers as $custom) {
238
+
239
+ $xml = '<xmlrequest>
240
+ <username>' . $username . '</username>
241
+ <usertoken>' . $token . '</usertoken>
242
+ <requesttype>subscribers</requesttype>
243
+ <requestmethod>AddSubscriberToList</requestmethod>
244
+ <details>';
245
+ $xml = $xml . '<emailaddress>' . $custom["EMAIL"] . '</emailaddress>';
246
+ $xml = $xml . '<mailinglist>' . $listid . '</mailinglist>
247
+ <format>html</format>
248
+ <confirmed>yes</confirmed>
249
+ </details>
250
+ </xmlrequest>';
251
+
252
+ $ch = curl_init($url2);
253
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
254
+ curl_setopt($ch, CURLOPT_POST, 1);
255
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
256
+ $result = @curl_exec($ch);
257
+ if ($result === false) {
258
+ Mage::getSingleton('adminhtml/session')->addError("Mailplatform - Error Performing the Request");
259
+ } else {
260
+ $xml_doc = simplexml_load_string($result);
261
+
262
+ Mage::getSingleton('adminhtml/session')->addSuccess("Mailplatform - " . $custom["EMAIL"] . " OK");
263
+ if ($xml_doc->status != 'SUCCESS') {
264
+ Mage::getSingleton('adminhtml/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
265
+ }
266
+ }
267
+ }
268
+ }
269
+ }
270
+
271
+ Mage::app()->setCurrentStore(0);
272
+
273
+ } catch (exception $e) {
274
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
275
+ }
276
+ }
277
+
278
+ public function getCustomerOldEmail()
279
+ {
280
+ return Mage::getSingleton('core/session', array('name' => 'frontend'))->getData('customer_old_email');
281
+ }
282
+
283
+ }
app/code/community/Mp/Mailplatform/Model/Mailplatform/Emailtype.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Model_Mailplatform_emailtype
4
+ {
5
+
6
+ public function toOptionArray()
7
+ {
8
+ return array(
9
+ array('value'=>'html', 'label'=>Mage::helper('adminhtml')->__('HTML')),
10
+ array('value'=>'text', 'label'=>Mage::helper('adminhtml')->__('Text')),
11
+ );
12
+ }
13
+
14
+ }
app/code/community/Mp/Mailplatform/Model/Mailplatform/Listids.php ADDED
@@ -0,0 +1,92 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mp_Mailplatform_Model_Mailplatform_Listids extends Varien_Object
3
+ {
4
+ protected $_options;
5
+ protected $_lists = array();
6
+
7
+ protected function getmodeloptions()
8
+ {
9
+ return Mage::getModel('mailplatform/mailplatform');
10
+ }
11
+
12
+ public function toOptionArray($isMultiselect=false)
13
+ {
14
+ if (!$this->_options) {
15
+ $arrresult = explode("/", $_SERVER["REQUEST_URI"]);
16
+ //$arrresult;
17
+ //Zend_Debug::dump($arrresult);
18
+ $i = 0;
19
+ $store = "";
20
+ $storetoload = 0;
21
+ foreach($arrresult as $arr)
22
+ {
23
+ if($arr == "store")
24
+ {
25
+ $store = $arrresult[$i+1];
26
+ }
27
+ $i++;
28
+ }
29
+
30
+ $allstores = Mage::getModel('core/store')->getCollection();
31
+
32
+ foreach($allstores as $actualstore)
33
+ {
34
+ if($actualstore->getCode() == $store)
35
+ {
36
+ $storetoload = (int)$actualstore->getId();
37
+ }
38
+ }
39
+
40
+ Mage::app()->setCurrentStore($storetoload);
41
+ $url2 = Mage::getStoreConfig('mailplatform/general/url');
42
+
43
+ $url = $this->getmodeloptions()->getXMLGeneralConfig("url" ,1);
44
+ //Zend_Debug::dump($url);
45
+
46
+ $username = $this->getmodeloptions()->getXMLGeneralConfig("username");
47
+ $tocken = $this->getmodeloptions()->getXMLGeneralConfig("tocken");
48
+
49
+
50
+
51
+ $xml = '<xmlrequest>
52
+ <username>'. trim($username) .'</username>
53
+ <usertoken>'. trim($tocken) .'</usertoken>
54
+ <requesttype>lists</requesttype>
55
+ <requestmethod>GetLists</requestmethod>
56
+ <details>all</details></xmlrequest>';
57
+ //Zend_Debug::dump($xml);
58
+
59
+ $ch = curl_init($url);
60
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
61
+ curl_setopt($ch, CURLOPT_POST, 1);
62
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
63
+ $result = @curl_exec($ch);
64
+ $xml_doc = simplexml_load_string($result);
65
+ //Zend_Debug::dump($result);
66
+ if($result === false) {
67
+ Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error!');
68
+ }else {
69
+ if ($xml_doc->status == 'SUCCESS')
70
+ {
71
+ foreach($xml_doc->data->item as $item)
72
+ {
73
+ if($item->username == $username){
74
+ $this->_lists[] = array('value'=>$item->listid,
75
+ 'label'=>$item->name);
76
+ }
77
+ }
78
+ }
79
+ }
80
+
81
+ $this->_options = $this->_lists;
82
+ }
83
+
84
+
85
+ $options = $this->_options;
86
+ if(!$isMultiselect){
87
+ array_unshift($options, array('value'=>'', 'label'=> Mage::helper('adminhtml')->__('--Please Select--')));
88
+ }
89
+ Mage::app()->setCurrentStore(0);
90
+ return $options;
91
+ }
92
+ }
app/code/community/Mp/Mailplatform/Model/Mailplatform/Mailplatform.php ADDED
@@ -0,0 +1,344 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ class Mp_Mailplatform_Model_Mailplatform_Mailplatform extends Varien_Object
3
+ {
4
+
5
+ public function getXMLGeneralConfig($field) {
6
+ return Mage::getStoreConfig('mailplatform/general/'.$field);
7
+ }
8
+
9
+ public function mailplatformAvailable() {
10
+ if ( $this->getXMLGeneralConfig('active') == true &&
11
+ $this->getXMLGeneralConfig('username') != '' &&
12
+ $this->getXMLGeneralConfig('tocken') != '' &&
13
+ $this->getXMLGeneralConfig('listid') != ''
14
+ &&
15
+ (
16
+ strstr($_SERVER['REQUEST_URI'], 'newsletter/') ||
17
+ strstr($_SERVER['REQUEST_URI'], 'newsletter_subscriber/') ||
18
+ strstr($_SERVER['REQUEST_URI'], 'customer/') ||
19
+ strstr($_SERVER['REQUEST_URI'], 'mailplatform/index') ||
20
+ strstr($_SERVER['REQUEST_URI'], 'checkout/onepage/')
21
+ )
22
+ ) {
23
+ return true;
24
+ }
25
+ if (Mage::app()->getStore()->getId() == 0){
26
+ if($this->getXMLGeneralConfig('active') != true) Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: Mailplatform is innactive');
27
+ if($this->getXMLGeneralConfig('username') == '' ) Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: API Username field is empty');
28
+ if($this->getXMLGeneralConfig('tocken') == '' ) Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: API Tocken field is empty');
29
+ if($this->getXMLGeneralConfig('listid') == '' ) Mage::getSingleton('adminhtml/session')->addError('Mailplatform Configuration Error: Mailplatform list field is empty');
30
+ }
31
+ return false;
32
+ }
33
+
34
+ private function getCustomerByEmail($email)
35
+ {
36
+ if (($email instanceof Mage_Customer_Model_Customer)) {
37
+
38
+ $customer = $email;
39
+
40
+ return $customer;
41
+ }
42
+
43
+ $collection = Mage::getResourceModel('newsletter/subscriber_collection');
44
+ $collection
45
+ ->showCustomerInfo(true)
46
+ ->addSubscriberTypeField()
47
+ ->showStoreInfo()
48
+ ->addFieldToFilter('subscriber_email',$email);
49
+
50
+ return $collection->getFirstItem();
51
+ }
52
+
53
+ private function getListIdByStoreId($storeId)
54
+ {
55
+ $store = Mage::getModel('core/store')->load($storeId);
56
+ $list_id = $store->getConfig('mailplatform/general/listid');
57
+
58
+ return $list_id;
59
+
60
+ }
61
+
62
+ public function subscribe($email) {
63
+ if ($this->mailplatformAvailable()) {
64
+
65
+ $customer = $this->getCustomerByEmail($email);
66
+ $customerOldMail = $this->getCustomerOldEmail();
67
+
68
+ $merge_vars = array();
69
+
70
+ if (($email instanceof Mage_Customer_Model_Customer)) {
71
+
72
+ $email = $customer->getEmail();
73
+
74
+ $merge_vars['FNAME'] = $customer->getFirstname();
75
+ $merge_vars['LNAME'] = $customer->getLastname();
76
+
77
+ }elseif ($customer->getCustomerId() !=0 ) {
78
+ $merge_vars['FNAME'] = $customer->getCustomerFirstname();
79
+ $merge_vars['LNAME'] = $customer->getCustomerLastname();
80
+ } else {
81
+ $merge_vars['FNAME'] = 'Guest';
82
+ $merge_vars['LNAME'] = 'Guest';
83
+ }
84
+ try {
85
+
86
+
87
+ $url2 = Mage::getStoreConfig('mailplatform/general/url');
88
+ //$url = $this->getMailplatform()->getXMLGeneralConfig("url");
89
+ $username = Mage::getStoreConfig('mailplatform/general/username');
90
+ $tocken = Mage::getStoreConfig('mailplatform/general/tocken');
91
+ $listid = Mage::getStoreConfig('mailplatform/general/listid');
92
+
93
+ //Zend_Debug::dump($url2);
94
+ //Zend_Debug::dump($username);
95
+ //Zend_Debug::dump($tocken);
96
+ //Zend_Debug::dump($listid);
97
+ //Zend_Debug::dump($email);
98
+ //Zend_Debug::dump($customers);
99
+
100
+ $xml = '<xmlrequest>
101
+ <username>' . $username . '</username>
102
+ <usertoken>' . $tocken . '</usertoken>
103
+ <requesttype>subscribers</requesttype>
104
+ <requestmethod>AddSubscriberToList</requestmethod>
105
+ <details>';
106
+ $xml = $xml . '<emailaddress>' . $email . '</emailaddress>';
107
+ $xml = $xml . '<mailinglist>'. $listid .'</mailinglist>
108
+ <format>html</format>
109
+ <confirmed>yes</confirmed>
110
+ </details>
111
+ </xmlrequest>';
112
+ $ch = curl_init($url2);
113
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
114
+ curl_setopt($ch, CURLOPT_POST, 1);
115
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
116
+ $result = @curl_exec($ch);
117
+ if($result === false) {
118
+ Mage::getSingleton('customer/session')->addError("Mailplatform - Error Performing the Request");
119
+ } else {
120
+ $xml_doc = simplexml_load_string($result);
121
+ //Zend_Debug::dump($result);
122
+ Mage::getSingleton('customer/session')->addSuccess("Mailplatform - Addet - " . $email . " OK");
123
+ if ($xml_doc->status == 'SUCCESS') {
124
+ // echo 'Data is ', $xml_doc->data, '<br/>';
125
+ } else {
126
+ Mage::getSingleton('customer/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
127
+ }
128
+ }
129
+
130
+ //Zend_Debug::dump($result);
131
+ //echo "AAAAAAAAA";
132
+ //die("AAAAAA");
133
+
134
+ } catch ( exception $e ) {
135
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
136
+ }
137
+
138
+ }
139
+ }
140
+
141
+ public function unsubscribe($email) {
142
+ //Zend_Debug::dump($email->getEmail());
143
+ if ( $this->mailplatformAvailable() ) {
144
+
145
+ try {
146
+
147
+ $url2 = Mage::getStoreConfig('mailplatform/general/url');
148
+ //$url = $this->getMailplatform()->getXMLGeneralConfig("url");
149
+ $username = Mage::getStoreConfig('mailplatform/general/username');
150
+ $tocken = Mage::getStoreConfig('mailplatform/general/tocken');
151
+ $listid = Mage::getStoreConfig('mailplatform/general/listid');
152
+
153
+ //Zend_Debug::dump($url2);
154
+ //Zend_Debug::dump($username);
155
+ //Zend_Debug::dump($tocken);
156
+ //Zend_Debug::dump($listid);
157
+ //Zend_Debug::dump($store);
158
+ //Zend_Debug::dump($customers);
159
+ $xml = '<xmlrequest>
160
+ <username>' . $username . '</username>
161
+ <usertoken>' . $tocken . '</usertoken>
162
+ <requesttype>subscribers</requesttype>
163
+ <requestmethod>DeleteSubscriber</requestmethod>
164
+ <details>
165
+ <emailaddress>' . $email->getEmail() . '</emailaddress>
166
+ <list>' .$listid. '</list>
167
+ </details>
168
+ </xmlrequest>';
169
+
170
+ $ch = curl_init($url2);
171
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
172
+ curl_setopt($ch, CURLOPT_POST, 1);
173
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
174
+ $result = @curl_exec($ch);
175
+ if($result === false) {
176
+ Mage::getSingleton('customer/session')->addError("Mailplatform - Error Performing the Request");
177
+ } else {
178
+ $xml_doc = simplexml_load_string($result);
179
+ //Zend_Debug::dump($result);
180
+ Mage::getSingleton('customer/session')->addSuccess("Mailplatform - Removal - " . $email . " OK");
181
+ if ($xml_doc->status == 'SUCCESS') {
182
+ // echo 'Data is ', $xml_doc->data, '<br/>';
183
+ } else {
184
+ Mage::getSingleton('customer/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
185
+ }
186
+ }
187
+
188
+ //Zend_Debug::dump($result);
189
+ //echo "AAAAAAAAAAAA";
190
+ //die($email);
191
+ /**
192
+ * Submit to Mailplatform
193
+ * */
194
+
195
+ } catch ( exception $e ) {
196
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
197
+ }
198
+ }
199
+ }
200
+ public function batchSubscribe($items) {
201
+ //echo "In batch";
202
+
203
+ if ( $this->mailplatformAvailable() ) {
204
+
205
+ // echo "ENABLED";
206
+ $batch = array();
207
+ $customerInList = array();
208
+ foreach($items as $item) {
209
+
210
+ $merge_vars = array();
211
+
212
+ if($item['customer_id'] !=0) {
213
+ $merge_vars['FNAME'] = $item['customer_firstname'];
214
+ $merge_vars['LNAME'] = $item['customer_lastname'];
215
+ $merge_vars['StoreId'] = $item['store_id'];
216
+
217
+ } else {
218
+ $merge_vars['FNAME'] = 'Guest';
219
+ $merge_vars['LNAME'] = 'Guest';
220
+ $merge_vars['StoreId'] = $item['store_id'];
221
+ }
222
+
223
+ $merge_vars['EMAIL'] = $item['subscriber_email'];
224
+
225
+ //$batch[] = $merge_vars;
226
+ $customerInList[$item['store_id']][]= $merge_vars;
227
+
228
+ }
229
+
230
+ //Zend_Debug::dump($customerInList);
231
+
232
+ try {
233
+ foreach ($customerInList as $store => $customers)
234
+ {
235
+
236
+ Mage::app()->setCurrentStore($store);
237
+ $url2 = Mage::getStoreConfig('mailplatform/general/url');
238
+ //$url = $this->getMailplatform()->getXMLGeneralConfig("url");
239
+ $username = Mage::getStoreConfig('mailplatform/general/username');
240
+ $tocken = Mage::getStoreConfig('mailplatform/general/tocken');
241
+ $listid = Mage::getStoreConfig('mailplatform/general/listid');
242
+ //echo "<hr>";
243
+ //Zend_Debug::dump($url2);
244
+ //Zend_Debug::dump($username);
245
+ //Zend_Debug::dump($tocken);
246
+ //Zend_Debug::dump($listid);
247
+ //Zend_Debug::dump($store);
248
+ //Zend_Debug::dump($customers);
249
+ if(count($customers) == 1)
250
+ {
251
+
252
+ $xml = '<xmlrequest>
253
+ <username>' . $username . '</username>
254
+ <usertoken>' . $tocken . '</usertoken>
255
+ <requesttype>subscribers</requesttype>
256
+ <requestmethod>AddSubscriberToList</requestmethod>
257
+ <details>';
258
+ $xml = $xml . '<emailaddress>' . $customers[0]["EMAIL"] . '</emailaddress>';
259
+ $xml = $xml . '<mailinglist>'. $listid .'</mailinglist>
260
+ <format>html</format>
261
+ <confirmed>yes</confirmed>
262
+ </details>
263
+ </xmlrequest>';
264
+ $ch = curl_init($url2);
265
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
266
+ curl_setopt($ch, CURLOPT_POST, 1);
267
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
268
+ $result = @curl_exec($ch);
269
+ if($result === false) {
270
+ Mage::getSingleton('adminhtml/session')->addError("Mailplatform - Error Performing the Request");
271
+ }
272
+ else {
273
+ $xml_doc = simplexml_load_string($result);
274
+ //Zend_Debug::dump($result);
275
+ Mage::getSingleton('adminhtml/session')->addSuccess("Mailplatform - " . $customers[0]["EMAIL"] . " OK");
276
+ if ($xml_doc->status == 'SUCCESS') {
277
+ // echo 'Data is ', $xml_doc->data, '<br/>';
278
+ } else {
279
+ Mage::getSingleton('adminhtml/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
280
+ }
281
+ }
282
+ // Zend_Debug::dump($xml);
283
+ }else{
284
+ foreach($customers as $custom)
285
+ {
286
+
287
+ $xml = '<xmlrequest>
288
+ <username>' . $username . '</username>
289
+ <usertoken>' . $tocken . '</usertoken>
290
+ <requesttype>subscribers</requesttype>
291
+ <requestmethod>AddSubscriberToList</requestmethod>
292
+ <details>';
293
+ $xml = $xml . '<emailaddress>' . $custom["EMAIL"] . '</emailaddress>';
294
+ $xml = $xml . '<mailinglist>'. $listid .'</mailinglist>
295
+ <format>html</format>
296
+ <confirmed>yes</confirmed>
297
+ </details>
298
+ </xmlrequest>';
299
+ //Zend_Debug::dump($xml);
300
+ $ch = curl_init($url2);
301
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
302
+ curl_setopt($ch, CURLOPT_POST, 1);
303
+ curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
304
+ $result = @curl_exec($ch);
305
+ if($result === false) {
306
+ Mage::getSingleton('adminhtml/session')->addError("Mailplatform - Error Performing the Request");
307
+ }
308
+ else {
309
+ $xml_doc = simplexml_load_string($result);
310
+ //Zend_Debug::dump($result);
311
+ Mage::getSingleton('adminhtml/session')->addSuccess("Mailplatform - " . $custom["EMAIL"] . " OK");
312
+ if ($xml_doc->status == 'SUCCESS') {
313
+ //echo 'Data is ', $xml_doc->data, '<br/>';
314
+ } else {
315
+ Mage::getSingleton('adminhtml/session')->addError("Mailplatform -" . $xml_doc->errormessage . '<br/>');
316
+ }
317
+ }
318
+ }
319
+ //echo "more then 1";
320
+ }
321
+
322
+ }
323
+ Mage::app()->setCurrentStore(0);
324
+ } catch ( exception $e ) {
325
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
326
+ }
327
+ }
328
+ }
329
+
330
+ public function getCustomerOldEmail()
331
+ {
332
+ if(isset($_SESSION['customer_old_email']))
333
+ {
334
+ $customer_old_email = $_SESSION['customer_old_email'];
335
+ return $customer_old_email;
336
+ }else
337
+ {
338
+ return '';
339
+
340
+ }
341
+
342
+ }
343
+ }
344
+ ?>
app/code/community/Mp/Mailplatform/Model/Newsletter/Subscriber.php ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_Model_Newsletter_Subscriber extends Mage_Newsletter_Model_Subscriber
4
+ {
5
+
6
+ public function subscribe($email)
7
+ {
8
+ $this->loadByEmail($email);
9
+ $customer = Mage::getModel('customer/customer')
10
+ ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
11
+ ->loadByEmail($email)
12
+ ;
13
+ $isNewSubscriber = false;
14
+
15
+ $customerSession = Mage::getSingleton('customer/session');
16
+
17
+ if (! $this->getId()) {
18
+ $this->setSubscriberConfirmCode($this->randomSequence());
19
+ }
20
+
21
+ if (
22
+ ! $this->getId()
23
+ || $this->getStatus() == self::STATUS_UNSUBSCRIBED
24
+ || $this->getStatus() == self::STATUS_NOT_ACTIVE
25
+ ) {
26
+ if (Mage::getStoreConfig(self::XML_PATH_CONFIRMATION_FLAG) == 1) {
27
+ $this->setStatus(self::STATUS_NOT_ACTIVE);
28
+ } else {
29
+ $this->setStatus(self::STATUS_SUBSCRIBED);
30
+ }
31
+ $this->setSubscriberEmail($email);
32
+ }
33
+
34
+ if ($customerSession->isLoggedIn()) {
35
+ $this->setStoreId($customerSession->getCustomer()
36
+ ->getStoreId());
37
+ $this->setStatus(self::STATUS_SUBSCRIBED);
38
+ $this->setCustomerId($customerSession->getCustomerId());
39
+ } else
40
+ if ($customer->getId()) {
41
+ $this->setStoreId($customer->getStoreId());
42
+ $this->setSubscriberStatus(self::STATUS_SUBSCRIBED);
43
+ $this->setCustomerId($customer->getId());
44
+ } else {
45
+ $this->setStoreId(Mage::app()->getStore()
46
+ ->getId());
47
+ $this->setCustomerId(0);
48
+ $isNewSubscriber = true;
49
+ }
50
+
51
+ $this->setIsStatusChanged(true);
52
+
53
+ try {
54
+ $this->save();
55
+ if (Mage::getStoreConfig(self::XML_PATH_CONFIRMATION_FLAG) == 1 && $this->getSubscriberStatus() == self::STATUS_NOT_ACTIVE) {
56
+ $this->sendConfirmationRequestEmail();
57
+ } else {
58
+ $this->sendConfirmationSuccessEmail();
59
+ }
60
+
61
+ Mage::getSingleton('mailplatform/mailplatform')->subscribe($email);
62
+
63
+ return $this->getStatus();
64
+ } catch (Exception $e) {
65
+ throw new Exception($e->getMessage());
66
+ }
67
+ }
68
+
69
+ public function unsubscribe()
70
+ {
71
+ if ($this->hasCheckCode() && $this->getCode() != $this->getCheckCode()) {
72
+ Mage::throwException(Mage::helper('newsletter')->__('Invalid subscription confirmation code'));
73
+ }
74
+
75
+ $this->setSubscriberStatus(self::STATUS_UNSUBSCRIBED)->save();
76
+ $this->sendUnsubscriptionEmail();
77
+
78
+ Mage::getModel('mailplatform/mailplatform')->unsubscribe($this->getEmail());
79
+
80
+ return $this;
81
+ }
82
+
83
+ /**
84
+ * Saving customer cubscription status
85
+ *
86
+ * @param Mage_Customer_Model_Customer $customer
87
+ * @return Mage_Newsletter_Model_Subscriber
88
+ */
89
+ public function subscribeCustomer($customer)
90
+ {
91
+ $this->loadByCustomer($customer);
92
+
93
+ if ($customer->getImportMode()) {
94
+ $this->setImportMode(true);
95
+ }
96
+
97
+ if (! $customer->getIsSubscribed() && ! $this->getId()) {
98
+ // If subscription flag not seted or customer not subscriber
99
+ // and no subscribe bellow
100
+ return $this;
101
+ }
102
+
103
+ if (! $this->getId()) {
104
+ $this->setSubscriberConfirmCode($this->randomSequence());
105
+ }
106
+
107
+ if ($customer->hasIsSubscribed()) {
108
+ $status = $customer->getIsSubscribed() ? self::STATUS_SUBSCRIBED : self::STATUS_UNSUBSCRIBED;
109
+ } else {
110
+ $status = ($this->getStatus() == self::STATUS_NOT_ACTIVE ? self::STATUS_UNSUBSCRIBED : $this->getStatus());
111
+ }
112
+
113
+ if ($status != $this->getStatus()) {
114
+ $this->setIsStatusChanged(true);
115
+ }
116
+
117
+ $this->setStatus($status);
118
+
119
+ if (! $this->getId()) {
120
+ $this->setStoreId($customer->getStoreId())
121
+ ->setCustomerId($customer->getId())
122
+ ->setEmail($customer->getEmail());
123
+ } else {
124
+ $this->setEmail($customer->getEmail());
125
+ }
126
+
127
+ $this->save();
128
+
129
+ if ((! $customer->isConfirmationRequired()) && ! $customer->getConfirmation()) {
130
+ if ($this->getStatus() == self::STATUS_SUBSCRIBED) {
131
+ Mage::getSingleton('mailplatform/mailplatform')->subscribe($customer);
132
+ } else {
133
+ Mage::getSingleton('mailplatform/mailplatform')->unsubscribe($customer);
134
+ }
135
+ }
136
+
137
+ $sendSubscription = $customer->getData('sendSubscription');
138
+ if (is_null($sendSubscription) xor $sendSubscription) {
139
+ if ($this->getIsStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
140
+ $this->sendUnsubscriptionEmail();
141
+ } elseif ($this->getIsStatusChanged() && $status == self::STATUS_SUBSCRIBED) {
142
+ $this->sendConfirmationSuccessEmail();
143
+ }
144
+ }
145
+ return $this;
146
+ }
147
+ }
app/code/community/Mp/Mailplatform/controllers/AccountController.php ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ require_once (Mage::getModuleDir('controllers', 'Mage_Customer') . DS . 'AccountController.php');
3
+
4
+ class Mp_Mailplatform_AccountController extends Mage_Customer_AccountController
5
+ {
6
+
7
+ public function editAction()
8
+ {
9
+ $this->loadLayout(array(
10
+ 'default',
11
+ 'customer_account_edit'
12
+ ));
13
+
14
+ $this->_initLayoutMessages('customer/session');
15
+ $this->_initLayoutMessages('catalog/session');
16
+
17
+ if ($block = $this->getLayout()->getBlock('customer_edit')) {
18
+ $block->setRefererUrl($this->_getRefererUrl());
19
+ }
20
+
21
+ $data = $this->_getSession()->getCustomerFormData(true);
22
+ $customer = $this->_getSession()->getCustomer();
23
+ if (! empty($data)) {
24
+ $customer->addData($data);
25
+ }
26
+
27
+ if ($this->getRequest()->getParam('changepass') == 1) {
28
+ $customer->setChangePassword(1);
29
+ }
30
+
31
+ Mage::getSingleton('core/session', array('name' => 'frontend'))
32
+ ->setData('customer_old_email', $customer->getEmail())
33
+ ;
34
+
35
+ $this->getLayout()
36
+ ->getBlock('head')
37
+ ->setTitle($this->__('Account Information'))
38
+ ;
39
+
40
+ $this->renderLayout();
41
+ }
42
+
43
+ public function confirmAction()
44
+ {
45
+ if ($this->_getSession()->isLoggedIn()) {
46
+ $this->_redirect('*/*/');
47
+ return;
48
+ }
49
+
50
+ try {
51
+ $id = $this->getRequest()->getParam('id', false);
52
+ $key = $this->getRequest()->getParam('key', false);
53
+ $backUrl = $this->getRequest()->getParam('back_url', false);
54
+ if (empty($id) || empty($key)) {
55
+ throw new Exception($this->__('Bad request.'));
56
+ }
57
+
58
+ // load customer by id (try/catch in case if it throws exceptions)
59
+ try {
60
+ $customer = Mage::getModel('customer/customer')->load($id);
61
+ if ((! $customer) || (! $customer->getId())) {
62
+ throw new Exception('Failed to load customer by id.');
63
+ }
64
+ } catch (Exception $e) {
65
+ throw new Exception($this->__('Wrong customer account specified.'));
66
+ }
67
+
68
+ // check if it is inactive
69
+ if ($customer->getConfirmation()) {
70
+ if ($customer->getConfirmation() !== $key) {
71
+ throw new Exception($this->__('Wrong confirmation key.'));
72
+ }
73
+
74
+ // activate customer
75
+ try {
76
+ $customer->setConfirmation(null);
77
+ $customer->save();
78
+
79
+ $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($customer->getEmail());
80
+
81
+ if ($subscriber->isSubscribed() && Mage::getStoreConfig('mailplatform/general/active')) {
82
+ Mage::getSingleton('mailplatform/mailplatform')->subscribe($customer);
83
+ }
84
+ } catch (Exception $e) {
85
+ throw new Exception($this->__('Failed to confirm customer account.'));
86
+ }
87
+
88
+ // log in and send greeting email, then die happy
89
+ $this->_getSession()->setCustomerAsLoggedIn($customer);
90
+ $successUrl = $this->_welcomeCustomer($customer, true);
91
+ $this->_redirectSuccess($backUrl ? $backUrl : $successUrl);
92
+ return;
93
+ }
94
+
95
+ // die happy
96
+ $this->_redirectSuccess(Mage::getUrl('*/*/index', array('_secure' => true)));
97
+ return;
98
+ } catch (Exception $e) {
99
+ // die unhappy
100
+ $this->_getSession()->addError($e->getMessage());
101
+ $this->_redirectError(Mage::getUrl('*/*/index', array('_secure' => true)));
102
+ return;
103
+ }
104
+ }
105
+ }
app/code/community/Mp/Mailplatform/controllers/IndexController.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Mp_Mailplatform_IndexController extends Mage_Adminhtml_Controller_Action
4
+ {
5
+
6
+ public function indexAction()
7
+ {
8
+ // collect all subscribers users
9
+ $collectionarray = Mage::getResourceModel('newsletter/subscriber_collection')->showStoreInfo()
10
+ ->showCustomerInfo()
11
+ ->useOnlySubscribed()
12
+ ->toArray()
13
+ ;
14
+
15
+ if ($collectionarray['totalRecords'] > 0) {
16
+ Mage::getSingleton('mailplatform/mailplatform')->batchSubscribe($collectionarray['items']);
17
+ }
18
+
19
+ $this->_redirect('adminhtml/newsletter_subscriber/');
20
+ }
21
+ }
app/code/community/Mp/Mailplatform/etc/config.xml ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Mp_Mailplatform>
5
+ <version>1.0.1</version>
6
+ </Mp_Mailplatform>
7
+ </modules>
8
+ <global>
9
+ <rewrite>
10
+ <pnpweb_mailplatform_account_edit>
11
+ <from><![CDATA[#^/customer/account/edit/(.*)#]]></from>
12
+ <to>mailplatform/account/edit</to>
13
+ </pnpweb_mailplatform_account_edit>
14
+ <pnpweb_mailplatform_account_confirm>
15
+ <from><![CDATA[#^/customer/account/confirm/(.*)#]]></from>
16
+ <to>mailplatform/account/confirm</to>
17
+ </pnpweb_mailplatform_account_confirm>
18
+ </rewrite>
19
+ <blocks>
20
+ <adminhtml>
21
+ <rewrite>
22
+ <newsletter_subscriber>Mp_Mailplatform_Block_Adminhtml_Newsletter_Subscriber</newsletter_subscriber>
23
+ </rewrite>
24
+ </adminhtml>
25
+ </blocks>
26
+ <models>
27
+ <mailplatform>
28
+ <class>Mp_Mailplatform_Model</class>
29
+ </mailplatform>
30
+ <newsletter>
31
+ <rewrite>
32
+ <subscriber>Mp_Mailplatform_Model_Newsletter_Subscriber</subscriber>
33
+ </rewrite>
34
+ </newsletter>
35
+ </models>
36
+ </global>
37
+ <adminhtml>
38
+ <acl>
39
+ <resources>
40
+ <admin>
41
+ <children>
42
+ <system>
43
+ <children>
44
+ <config>
45
+ <children>
46
+ <mailplatform translate="title" module="mailplatform">
47
+ <title>mailplatform Section</title>
48
+ <sort_order>50</sort_order>
49
+ </mailplatform>
50
+ </children>
51
+ </config>
52
+ </children>
53
+ </system>
54
+ </children>
55
+ </admin>
56
+ </resources>
57
+ </acl>
58
+ </adminhtml>
59
+ <admin>
60
+ <routers>
61
+ <mailplatform>
62
+ <use>admin</use>
63
+ <args>
64
+ <module>Mp_Mailplatform</module>
65
+ <frontName>mailplatform</frontName>
66
+ </args>
67
+ </mailplatform>
68
+ </routers>
69
+ </admin>
70
+ <default>
71
+ <mailplatform>
72
+ <general>
73
+ <active>0</active>
74
+ <url>http://mailmailmail.net/xml.php</url>
75
+ <username>admin</username>
76
+ <token></token>
77
+ </general>
78
+ <subscribe>
79
+ <email_type>html</email_type>
80
+ <double_optin>0</double_optin>
81
+ <update_existing>1</update_existing>
82
+ </subscribe>
83
+ <unsubscribe>
84
+ <delete_member>0</delete_member>
85
+ <send_goodbye>0</send_goodbye>
86
+ <send_notify>0</send_notify>
87
+ </unsubscribe>
88
+ </mailplatform>
89
+ </default>
90
+ </config>
app/code/community/Mp/Mailplatform/etc/system.xml ADDED
@@ -0,0 +1,179 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <sections>
4
+ <mailplatform translate="label" module="newsletter">
5
+ <class>separator-top</class>
6
+ <label>Mailplatform Configuration</label>
7
+ <tab>customer</tab>
8
+ <sort_order>109</sort_order>
9
+ <show_in_default>1</show_in_default>
10
+ <show_in_website>1</show_in_website>
11
+ <show_in_store>1</show_in_store>
12
+ <groups>
13
+ <general translate="label">
14
+ <label>General</label>
15
+ <frontend_type>text</frontend_type>
16
+ <sort_order>1</sort_order>
17
+ <show_in_default>1</show_in_default>
18
+ <show_in_website>1</show_in_website>
19
+ <show_in_store>1</show_in_store>
20
+ <fields>
21
+ <active translate="label">
22
+ <label>Enabled</label>
23
+ <frontend_type>select</frontend_type>
24
+ <source_model>adminhtml/system_config_source_yesno</source_model>
25
+ <sort_order>1</sort_order>
26
+ <show_in_default>1</show_in_default>
27
+ <show_in_website>1</show_in_website>
28
+ <show_in_store>1</show_in_store>
29
+ </active>
30
+ <username translate="label comment">
31
+ <label>API Username</label>
32
+ <frontend_type>text</frontend_type>
33
+ <sort_order>2</sort_order>
34
+ <show_in_default>1</show_in_default>
35
+ <show_in_website>0</show_in_website>
36
+ <show_in_store>1</show_in_store>
37
+ <comment>The username used in the XML API requests.</comment>
38
+ </username>
39
+ <token translate="label comment">
40
+ <label>API token</label>
41
+ <frontend_type>text</frontend_type>
42
+ <sort_order>3</sort_order>
43
+ <show_in_default>1</show_in_default>
44
+ <show_in_website>0</show_in_website>
45
+ <show_in_store>1</show_in_store>
46
+ <comment>This token is what the user needs to include in their
47
+ XML requests. If this token is not present in the XML request or
48
+ does not match what is set here, the request will fail.
49
+ </comment>
50
+ </token>
51
+ <listid translate="label comment">
52
+ <label>List id</label>
53
+ <frontend_type>select</frontend_type>
54
+ <source_model>mailplatform/listids</source_model>
55
+ <sort_order>4</sort_order>
56
+ <show_in_default>1</show_in_default>
57
+ <show_in_website>0</show_in_website>
58
+ <show_in_store>1</show_in_store>
59
+ <comment>The mailplatform list id where customers will be
60
+ added/removed
61
+ </comment>
62
+ </listid>
63
+ <url translate="label comment">
64
+ <label>XML-RPC URL</label>
65
+ <frontend_type>text</frontend_type>
66
+ <sort_order>5</sort_order>
67
+ <show_in_default>1</show_in_default>
68
+ <show_in_website>1</show_in_website>
69
+ <show_in_store>1</show_in_store>
70
+ <comment>This is the path to the file where all XML API requests
71
+ should be sent.
72
+ </comment>
73
+ </url>
74
+ </fields>
75
+ </general>
76
+ <subscribe>
77
+ <label>Subscribe options</label>
78
+ <frontend_type>text</frontend_type>
79
+ <sort_order>2</sort_order>
80
+ <show_in_default>1</show_in_default>
81
+ <show_in_website>0</show_in_website>
82
+ <show_in_store>1</show_in_store>
83
+ <fields>
84
+ <opt-in translate="label comment">
85
+ <label>Opt-in</label>
86
+ <frontend_type>text</frontend_type>
87
+ <sort_order>2</sort_order>
88
+ <show_in_default>0</show_in_default>
89
+ <show_in_website>0</show_in_website>
90
+ <show_in_store>0</show_in_store>
91
+ <comment>Set the Opt-in IP fields.</comment>
92
+ </opt-in>
93
+ <email_type translate="label">
94
+ <label>Email type</label>
95
+ <frontend_type>select</frontend_type>
96
+ <source_model>mailplatform/emailtype</source_model>
97
+ <sort_order>3</sort_order>
98
+ <show_in_default>1</show_in_default>
99
+ <show_in_website>0</show_in_website>
100
+ <show_in_store>0</show_in_store>
101
+ <comment>Email type preference for the email</comment>
102
+ </email_type>
103
+ <double_optin translate="label">
104
+ <label>Double optin</label>
105
+ <frontend_type>select</frontend_type>
106
+ <source_model>adminhtml/system_config_source_yesno</source_model>
107
+ <sort_order>4</sort_order>
108
+ <show_in_default>0</show_in_default>
109
+ <show_in_website>0</show_in_website>
110
+ <show_in_store>0</show_in_store>
111
+ <comment>Flag to control whether a double opt-in confirmation
112
+ message is sent
113
+ </comment>
114
+ </double_optin>
115
+ <update_existing translate="label">
116
+ <label>Update existing</label>
117
+ <frontend_type>select</frontend_type>
118
+ <source_model>adminhtml/system_config_source_yesno</source_model>
119
+ <sort_order>5</sort_order>
120
+ <show_in_default>0</show_in_default>
121
+ <show_in_website>0</show_in_website>
122
+ <show_in_store>0</show_in_store>
123
+ <comment>Flag to control whether a existing subscribers should be
124
+ updated instead of throwing and error
125
+ </comment>
126
+ </update_existing>
127
+
128
+
129
+ </fields>
130
+ </subscribe>
131
+ <unsubscribe>
132
+ <label>Unsubscribe options</label>
133
+ <frontend_type>text</frontend_type>
134
+ <sort_order>3</sort_order>
135
+ <show_in_default>1</show_in_default>
136
+ <show_in_website>0</show_in_website>
137
+ <show_in_store>1</show_in_store>
138
+ <fields>
139
+ <delete_member translate="label">
140
+ <label>Delete members</label>
141
+ <frontend_type>select</frontend_type>
142
+ <source_model>adminhtml/system_config_source_yesno</source_model>
143
+ <sort_order>1</sort_order>
144
+ <show_in_default>1</show_in_default>
145
+ <show_in_website>0</show_in_website>
146
+ <show_in_store>1</show_in_store>
147
+ <comment>Flag to completely delete the member from your list
148
+ instead of just unsubscribing
149
+ </comment>
150
+ </delete_member>
151
+ <send_goodbye translate="label">
152
+ <label>Send goodbye</label>
153
+ <frontend_type>select</frontend_type>
154
+ <source_model>adminhtml/system_config_source_yesno</source_model>
155
+ <sort_order>1</sort_order>
156
+ <show_in_default>1</show_in_default>
157
+ <show_in_website>0</show_in_website>
158
+ <show_in_store>1</show_in_store>
159
+ <comment>Flag to send the goodbye email to the email address
160
+ </comment>
161
+ </send_goodbye>
162
+ <send_notify translate="label">
163
+ <label>Send notify</label>
164
+ <frontend_type>select</frontend_type>
165
+ <source_model>adminhtml/system_config_source_yesno</source_model>
166
+ <sort_order>1</sort_order>
167
+ <show_in_default>1</show_in_default>
168
+ <show_in_website>0</show_in_website>
169
+ <show_in_store>1</show_in_store>
170
+ <comment>Flag to send the unsubscribe notification email to the
171
+ address defined in the list email notification settings
172
+ </comment>
173
+ </send_notify>
174
+ </fields>
175
+ </unsubscribe>
176
+ </groups>
177
+ </mailplatform>
178
+ </sections>
179
+ </config>
app/code/community/Mp/Mailplatform/sql/mp_mailplatform_setup/mysql4-install-0.0.1.php ADDED
File without changes
app/design/adminhtml/default/default/template/newsletter/subscriber/list_mailplatform.phtml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="content-header">
2
+ <table cellspacing="0">
3
+ <tr>
4
+ <td style="width: 50%;"><h3><?php echo $this->__('Newsletter Subscribers') ?></h3></td>
5
+ <td align="right">
6
+ <button type="button" class="scalable"
7
+ onclick="window.location='<?php echo $this->getMailplatformSyn() ?>'"
8
+ style="">
9
+ <span>Mailplatform Batch Synchronization</span>
10
+ </button>
11
+ </td>
12
+ </tr>
13
+ </table>
14
+ </div>
15
+ <div>
16
+ <b>Batch Sync is intended for <300 subscribers. Is your database is
17
+ larger please export it in Magento and import in MailPlatform. Contact
18
+ support@mailplatform.dk for further help.<br />&nbsp;
19
+ </b>
20
+ </div>
21
+ <div>
22
+ <?php echo $this->getChildHtml('grid')?>
23
+ </div>
24
+ <?php if(count($this->getQueueAsOptions()) > 0 && $this->getShowQueueAdd()): ?>
25
+ <div class="form-buttons">
26
+ <select id="queueList" name="queue">
27
+ <?php foreach ($this->getQueueAsOptions() as $_queue): ?>
28
+ <option value="<?php echo $_queue['value'] ?>"><?php echo $_queue['label'] ?> #<?php echo $_queue['value'] ?></option>
29
+ <?php endforeach; ?>
30
+ </select>
31
+ <button class="scalable" onclick="subscriberController.addToQueue();">
32
+ <span><?php echo $this->__('Add to Queue'); ?></span>
33
+ </button>
34
+ </div>
35
+ <?php endif ?>
app/etc/modules/Mp_Mailplattform.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Mp_Mailplatform>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Mp_Mailplatform>
8
+ </modules>
9
+ </config>
package.xml ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>mailplatformconnector</name>
4
+ <version>1.0.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>Sign-up for a free 30 days trial of award winning MailPlatform email marketing system - and connect Magento.</summary>
10
+ <description>MailPlatform is a danish company serving large international and national retailers. Among the reference customers are: BoConcept, Toyota, Blockbuster, Guldbageren, Kop &amp;amp; Kande, TravelMarket, Skoringen, Zjoos, NEYE and hundreds of other clients.&#xD;
11
+ &#xD;
12
+ Try us for free the first month, signup here:&#xD;
13
+ (all european countries)&#xD;
14
+ http://mailplatform.biz/free-trial-access/&#xD;
15
+ &#xD;
16
+ (danish clients only)&#xD;
17
+ http://mailplatform.dk/gratis-test-konto/&#xD;
18
+ &#xD;
19
+ The packages start at 25&#x20AC;/month.</description>
20
+ <notes>Changed code style to PSR-2&#xD;
21
+ Moved code files from local to community&#xD;
22
+ Removed unnecessary files &#xD;
23
+ Removed unnecessary code lines&#xD;
24
+ Removed unnecessary code logic&#xD;
25
+ Fixed file names&#xD;
26
+ Alternated code by Magento standards&#xD;
27
+ Corrected English grammar&#xD;
28
+ Tested on Magento CE 1.7, 1.8 and 1.9</notes>
29
+ <authors><author><name>ADEO WEB</name><user>adeoweb</user><email>info@adeoweb.biz</email></author></authors>
30
+ <date>2015-07-01</date>
31
+ <time>14:54:44</time>
32
+ <contents><target name="magecommunity"><dir name="Mp"><dir name="Mailplatform"><dir name="Block"><dir name="Adminhtml"><dir name="Newsletter"><file name="Subscriber.php" hash="c493b153d8a1fb000b84695c04f3424f"/></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="43f52f0bc701ffd903d9e1cd88bcbc91"/></dir><dir name="Model"><file name="Emailtype.php" hash="f36192a5e1049df8794c5b76b8531b44"/><file name="Listids.php" hash="9962e23f391753c58389351c78763294"/><dir name="Mailplatform"><file name="Emailtype.php" hash="a1642c3a488fdf2bd4dc209d445d9e3c"/><file name="Listids.php" hash="0c459e26f6064dd59dd4b3a6f0551d82"/><file name="Mailplatform.php" hash="a418ea5de60146650d5bd8b95f0c2eef"/></dir><file name="Mailplatform.php" hash="951d2ec0a92d6b64a2e00992f4c90797"/><dir name="Newsletter"><file name="Subscriber.php" hash="dc4425c7238597310bce656fef96e297"/></dir></dir><dir name="controllers"><file name="AccountController.php" hash="27adffc92b19306ce4b1bd81a621a59c"/><file name="IndexController.php" hash="c51427dd3d390822dfd41995a3de99e5"/></dir><dir name="etc"><file name="config.xml" hash="d835123d7c5ef961f93de038928ab938"/><file name="system.xml" hash="c146365b6c17fdde937698a2e5817d25"/></dir><dir name="sql"><dir name="mp_mailplatform_setup"><file name="mysql4-install-0.0.1.php" hash="d41d8cd98f00b204e9800998ecf8427e"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Mp_Mailplattform.xml" hash="4a03e6902800e6435720616ed9c29826"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="newsletter"><dir name="subscriber"><file name="list_mailplatform.phtml" hash="9360f96d57fb8c9d2ade7b2cd564f5d7"/></dir></dir></dir></dir></dir></dir></target></contents>
33
+ <compatible/>
34
+ <dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php></required></dependencies>
35
+ </package>