forked from th3fallen/Lyris-API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lyrisapi.php
1422 lines (1199 loc) · 55.7 KB
/
lyrisapi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* LyrisHQ API Library
* @author Clark Tomlinson
* @package LyrisAPI
* @since Jun 19, 2012, 12:16:32 PM
* @link http://www.clarkt.com
* @copyright 2012
*/
namespace Lyris;
/**
* Handles all LyrisHQ API interactions
*/
class API
{
/**
* Stores siteID for class functions
* @var
*/
private $siteid;
/**
* Stores global api password for all requests
* @var null
*/
private $apipassword;
/**
* Gathers Site id and global api password for requests
* @param $siteid
* @param null $apipassword
*/
public function __construct($siteid, $apipassword = null)
{
//set site id
$this->siteid = $siteid;
//set global api password
if (!is_null($apipassword)) {
$this->apipassword = $apipassword;
}
}
/**
* LIST FUNCTIONS
* @see Lyris API Docs Block 2.0
* Omitted 2.2, 2.6 to 2.8
*/
/**
* Add Mailing List
* @see Block 2.1
* @param string $name
* @param array $attributes
* @param string $listapipass
* @throws \Exception
* @return array
*/
public function listAdd($name, array $attributes = array(), $listapipass = null)
{
//if api pass is set in constructor assume lyris global api pass is enabled and use for all requests
$this->setApiPassword($listapipass);
if (empty($name)) {
die('List name required');
}
//loop through attributes and add to query
$attributesstring = '';
if (!empty($attributes)) {
foreach ($attributes as $k => $v) {
$attributesstring .= PHP_EOL . '<DATA type="extra" id="' . strtoupper(trim($k)) . '">' . trim($v) . '</DATA>' . PHP_EOL;
}
}
//build data for query
$querydata = array(
'type' => 'list',
'activity' => 'add',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
<DATA type="name">' . $name . '</DATA>' . $attributesstring . '</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Adding of list failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
foreach ($responseobj->DATA as $value) {
$returnarray[(string) $value['type']] = (string) $value;
}
return $returnarray;
}
/**
* Delete Mailing List
* @see Block 2.3
* @param string $mlid
* @param $listapipass
* @throws \Exception
* @return array
*/
public function listDelete($mlid, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//build query array
$querydata = array(
'type' => 'list',
'activity' => 'delete',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
<MLID>' . $mlid . '</MLID>
</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Removing of list failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
$returnarray['message'] = (string) $responseobj->DATA;
return $returnarray;
}
/**
* Edit Mailing List
* @see Block 2.4
* @param string $mlid
* @param string $name
* @param string $from_name
* @param string $from_email
* @param string $listapipass
* @throws \Exception
* @return array
*/
public function listEdit($mlid, $name, $from_name, $from_email, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//build data for query
$querydata = array(
'type' => 'list',
'activity' => 'edit',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MLID>' . $mlid . '</MLID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
<DATA type="name">' . $name . '</DATA>
<DATA type="extra" id="FROM_NAME">' . $from_name . '</DATA>
<DATA type="extra" id="FROM_EMAIL">' . $from_email . '</DATA>
</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Editing of list failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
$returnarray['message'] = (string) $responseobj->DATA;
return $returnarray;
}
/**
* Query for all lists and relevent data
* @see Block 2.5
* @param string $listapipass
* @throws \Exception
* @return array
*/
public function listQuery($listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//build query array
$querydata = array(
'type' => 'list',
'activity' => 'query-listdata',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//create new SimpleXMLElement Instance
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('List Query failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
$i = 0;
foreach ($responseobj->RECORD as $value) {
$returnarray[$i] = array();
//add list id as array value
$returnarray[$i]['mlid'] = (string) $value->DATA['id'];
foreach ($value->DATA as $k => $v) {
$returnarray[$i][(string) $v['type']] = (string) $v;
}
$i++;
}
return $returnarray;
}
/**
* MEMBER FUNCTIONS
* @see Lyris API Docs Block 4.0
*/
/**
* Add member to list
* @see Block 4.1
* @param int $mlid
* @param string $email
* @param array $demographics
* @param array $attributes
* @param string $listapipass
* @throws \Exception
* @return array
*/
public function memberAdd($mlid, $email, array $demographics = null, array $attributes = null, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//loop through attributes and add to query
$attributesstring = '';
if (!empty($attributes)) {
foreach ($attributes as $k => $v) {
$attributesstring .= PHP_EOL . '<DATA type="extra" id="' . strtoupper(trim($k)) . '">' . trim($v) . '</DATA>' . PHP_EOL;
}
}
//loop through demographics and add to query
$demographicsstring = '';
if (!empty($demographics)) {
foreach ($demographics as $k => $v) {
$demographicsstring .= PHP_EOL . '<DATA type="demographic" id="' . trim($k) . '">' . trim($v) . '</DATA>' . PHP_EOL;
}
}
//build data for query
$querydata = array(
'type' => 'record',
'activity' => 'add',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MLID>' . $mlid . '</MLID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
<DATA type="email">' . $email . '</DATA>' . $attributesstring . $demographicsstring . '</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for success
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Adding Member failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
$returnarray['memberid'] = (string) $responseobj->DATA;
return $returnarray;
}
/**
* Download Members of Mailing list
* @see Block 4.2
* @param type $mlid
* @param type $email
* @param type $type
* @param string $listapipass
* @throws \Exception
* @return array
*/
public function memberDownload($mlid, $email, $type, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//build data for query
$querydata = array(
'type' => 'record',
'activity' => 'download',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MLID>' . $mlid . '</MLID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
<DATA type="extra" id="email_notify">' . $email . '</DATA>
<DATA type="extra" id="type">' . $type . '</DATA>
</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Member download failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
return $returnarray;
}
/**
* Query Members
* @see Block 4.3
* @param numeric $mlid
* @param string $email
* @param string $listapipass
* @throws \Exception
* @return array
*/
public function memberQuery($mlid, $email, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//build data for query
$querydata = array(
'type' => 'record',
'activity' => 'query-data',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MLID>' . $mlid . '</MLID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
<DATA type="email">' . $email . '</DATA>
</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Member Query failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
if ($returnarray['status'] == 'error') {
$returnarray['message'] = (string) $responseobj->DATA;
}
foreach ($responseobj->RECORD->DATA as $value) {
$returnarray[(string) $value['id']] = (string) $value;
}
return $returnarray;
}
/**
* Query list for member data
* @see Block 4.4
* @param $mlid
* @param $type
* @param null $listapipass
* @throws \Exception
* @return array
*/
public function memberQueryList($mlid, $type, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//build data for query
$querydata = array(
'type' => 'record',
'activity' => 'query-listdata',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MLID>' . $mlid . '</MLID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
<DATA type="extra" id="type">' . $type . '</DATA>
</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Query member list failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
if ($returnarray['status'] == 'error') {
$returnarray['message'] = (string) $responseobj->DATA;
}
foreach ($responseobj->RECORD->DATA as $value) {
if ((string) $value['type'] == 'email') {
$returnarray[(string) $value['type']] = (string) $value;
} else {
$returnarray[(string) $value['id']] = (string) $value;
}
}
return $returnarray;
}
/**
* Return statistical data for a single contact
* @see Block 4.5
* @param $mlid
* @param string $email
* @param string $start_date (YYYY-MM-DD, optional)
* @param string $end_date (YYYY-MM-DD, optional)
* @param null $listapipass
* @throws \Exception
* @return array
*/
/*
* @author Ryan Field
* @since June 14, 2015, 5:13:32 PM
* @link https://github.com/kokuou
* @copyright 2015
*/
public function memberQueryStats($mlid, $email, $start_date = null, $end_date = null, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//check if $start_date and $end_date are null
$start_date = $start_date === null ? '' : $start_date;
$end_date = $start_date === null ? '' : $end_date;
//build data for query
$querydata = array(
'type' => 'record',
'activity' => 'query-stats',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MLID>' . $mlid . '</MLID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
<DATA type="email">' . $email . '</DATA>
'.$start_date.$end_date.'
</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Contact Management - Query-Stats failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//create array to add records to
$record_array = array();
//iterate through each <RECORD>
foreach($responseobj->RECORD as $record) {
//iterate through each DATA child node and add information to array
$temp_record = array();
foreach($record->DATA as $data) {
$attr = $data->attributes();
$type = (string)$attr['type'];
$item = $type;
//if there is no id set, ignore
if (isset($attr['id'])) {
$item .= '-'.(string)$attr['id'];
}
$temp_record[$item] = (string) $data;
}
//add $temp_record to $record_array to return
$record_array[] = $temp_record;
}
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
$returnarray['records'] = (array) $record_array;
return $returnarray;
}
/**
* Edit List Member(Subscriber)
* @see Block 4.6
* @param string $mlid
* @param string $email
* @param array $attributes
* @param array $demographics
* @param $listapipass
* @throws \Exception
* @return array
*/
public function memberEdit($mlid, $email, array $attributes, array $demographics = null, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//loop through attributes and add to query
$attributesstring = '';
if (!empty($attributes)) {
foreach ($attributes as $k => $v) {
$attributesstring .= PHP_EOL . '<DATA type="extra" id="' . trim($k) . '">' . trim($v) . '</DATA>' . PHP_EOL;
}
}
//loop through demographics and add to query
$demographicsstring = '';
if (!empty($demographics)) {
foreach ($demographics as $k => $v) {
$demographicsstring .= PHP_EOL . '<DATA type="demographic" id="' . trim($k) . '">' . trim($v) . '</DATA>' . PHP_EOL;
}
}
//build data for query
$querydata = array(
'type' => 'record',
'activity' => 'update',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MLID>' . $mlid . '</MLID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
<DATA type="email">' . $email . '</DATA>' . $attributesstring . $demographicsstring . '</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Editing of member failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
$returnarray['memberid'] = (string) $responseobj->DATA;
return $returnarray;
}
/**
* Message Management
* @see Lyris API Docs Block 5.0
*/
/**
* Add Message
* @see Block 5.1
* @param string $mlid
* @param string $fromEmail
* @param string $fromName
* @param string $subject
* @param string $messageFormat
* @param string $messageText
* @param string $messageHTML
* @param $listapipass
* @throws \Exception
* @return array
*/
public function messageAdd($mlid, $fromEmail, $fromName, $subject, $messageFormat, $messageText, $messageHTML, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//check if format is html if so add messagehtml to querydata
if (strtoupper($messageFormat) == 'HTML') {
$html = '<DATA type="message-html">' . htmlentities($messageHTML) . '</DATA>';
} else {
$html = '';
}
//build data for query
$querydata = array(
'type' => 'message',
'activity' => 'add',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MLID>' . $mlid . '</MLID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
<DATA type="subject">' . $subject . '</DATA>
<DATA type="from-email">' . $fromEmail . '</DATA>
<DATA type="from-name">' . $fromName . '</DATA>
<DATA type="message-format">' . $messageFormat . '</DATA>
<DATA type="message-text">' . $messageText . '</DATA>' . $html . '</DATASET>
<DATA type="charset">UTF-8</DATA>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check if query was successful if not throw exception
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Adding Message Failed with message: ' . $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
$returnarray['messageid'] = (string) $responseobj->DATA;
return $returnarray;
}
/**
* Copy message
* @see Block 5.2
* @param $mlid
* @param $mid
* @param null $listapipass
* @throws \Exception
* @return array
*/
public function messageCopy($mlid, $mid, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//build data for query
$querydata = array(
'type' => 'message',
'activity' => 'copy',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MID>' . $mid . '</MID>
<MLID>' . $mlid . '</MLID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Coping of message failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
$returnarray['messageid'] = (string) $responseobj->DATA;
return $returnarray;
}
/**
* Send quick proof of message to emails
* @see Block 5.3
* @param $mlid
* @param $mid
* @param $emails
* @param string $contentanalyzer
* @param string $inboxsnap
* @param string $blmon
* @param string $multi
* @param null $listapipass
* @throws \Exception
* @return array
*/
public function messageQuickTest($mlid, $mid, $emails, $contentanalyzer = 'off', $inboxsnap = 'off', $blmon = 'off', $multi = '1', $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//explode emails array into csv format
if (is_array($emails)) {
$emails = implode(', ', $emails);
}
//build data for query
$querydata = array(
'type' => 'message',
'activity' => 'message-quicktest',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MID>' . $mid . '</MID>
<MLID>' . $mlid . '</MLID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
<DATA type="extra" id="emails">' . $emails . '</DATA>
<DATA type="extra" id="content_analyzer">' . $contentanalyzer . '</DATA>
<DATA type="extra" id="inbox_snapshot">' . $inboxsnap . '</DATA>
<DATA type="extra" id="back_list_monitor">' . $blmon . '</DATA>
<DATA type="extra" id="multi">' . $multi . '</DATA>
</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Message quick test failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
$returnarray['message'] = (string) $responseobj->DATA;
$returnarray['htmlmid'] = (string) $responseobj->HTML_MID;
$returnarray['textmid'] = (string) $responseobj->TEXT_MLID;
$returnarray['contentanalyizer'] = (string) $responseobj->CONTENT_ANALYZER;
$returnarray['inboxsnap'] = (string) $responseobj->INBOX_SNAPSHOT;
return $returnarray;
}
/**
* Proof a created message
* @see Block 5.4
* @param $mlid
* @param $mid
* @param $text
* @param null $listapipass
* @throws \Exception
* @return array
*/
public function messageProof($mlid, $mid, $text, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//build data for query
$querydata = array(
'type' => 'message',
'activity' => 'proof',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MID>' . $mid . '</MID>
<MLID>' . $mlid . '</MLID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
<DATA type="text">' . $text . '</DATA>
</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Message proofing failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
$returnarray['message'] = (string) $responseobj->DATA;
foreach ($responseobj->EMAIL as $email) {
$returnarray['email'][] = (string) $email;
}
return $returnarray;
}
/**
* Gathers all stats of single message
* @see Block 5.5
* @param $mlid
* @param $mid
* @param null $listapipass
* @return array
* @throws \Exception
*/
public function messageQueryData($mlid, $mid, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//build data for query
$querydata = array(
'type' => 'message',
'activity' => 'query-data',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MLID>' . $mlid . '</MLID>
<MID>' . $mid . '</MID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Message data query failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$returnarray = array();
//clean up result and return array
$returnarray['status'] = (string) $responseobj->TYPE;
foreach ($responseobj->RECORD->DATA as $value) {
$returnarray[(string) $value['type']] = (string) $value;
}
return $returnarray;
}
/**
* Get all messages in a list
* @see Block 5.6
* @param $mlid
* @param null $startdate
* @param null $enddate
* @param null $listapipass
* @throws \Exception
* @return array
*/
/*
* @author Henry Paradiz
* @since Jan 7, 2013, 10:04:32 AM
* @link http://akuj.in
* @copyright 2013
*/
public function messageQueryListData($mlid, $startdate = null, $enddate = null, $listapipass = null)
{
//check api password
$this->setApiPassword($listapipass);
//build data for query
$querydata = array(
'type' => 'message',
'activity' => 'query-listdata',
'input' => '<DATASET>
<SITE_ID>' . $this->siteid . '</SITE_ID>
<MLID>' . $mlid . '</MLID>
<DATA type="extra" id="password">' . $this->apipassword . '</DATA>
</DATASET>'
);
//submit data
$response = $this->submit($querydata);
//convert xml to array
$responseobj = new \SimpleXMLElement($response);
//check for errors
if ((string) $responseobj->TYPE !== 'success') {
throw new \Exception('Message list query failed with message: ' . (string) $responseobj->DATA);
}
//create blank array to bind items to
$output = array();
//parse through return data and bind to output array
foreach($responseobj->children() as $Record)
{
$temp = array();
foreach($Record->children() as $Data)
{
$Attributes = $Data->attributes();
$Type = (string) $Attributes['type'][0];
$temp[$Type] = (string) $Data;
}
if(count($temp))
{
$output[] = $temp;
}
}
return $output;
}
/**
* Query Messages Stats
* @see Block 5.10
* @param $mid
* @param $mlid
* @param $action
* @param null $params
* @param null $listapipass
* @throws \Exception
* @return array
*/
/*
* @author Henry Paradiz
* @since Jan 7, 2013, 10:04:32 AM
* @link http://akuj.in
* @copyright 2013
*/
public function messageQueryStats($mid, $mlid, $action = null, $params = null, $listapipass = null)
{