Swift_Swiftplugin - Version 1.1.8

Version Notes

SwiftPlugin works over http and https

Download this release

Release Info

Developer Simon Cooper
Extension Swift_Swiftplugin
Version 1.1.8
Comparing to
See all releases


Version 1.1.8

Files changed (39) hide show
  1. app/code/community/Swift/Swiftplugin/Block/Adminhtml/Swift/Edit.php +26 -0
  2. app/code/community/Swift/Swiftplugin/Block/Adminhtml/Swift/Edit/Form.php +28 -0
  3. app/code/community/Swift/Swiftplugin/Block/Adminhtml/Swift/Edit/Tab/Form.php +40 -0
  4. app/code/community/Swift/Swiftplugin/Block/Adminhtml/Swift/Edit/Tab/Instruct.php +19 -0
  5. app/code/community/Swift/Swiftplugin/Block/Adminhtml/Swift/Edit/Tabs.php +33 -0
  6. app/code/community/Swift/Swiftplugin/Block/Swiftblock.php +174 -0
  7. app/code/community/Swift/Swiftplugin/Helper/Data.php +54 -0
  8. app/code/community/Swift/Swiftplugin/Model/Mysql4/Swift.php +10 -0
  9. app/code/community/Swift/Swiftplugin/Model/Mysql4/Swift/Collection.php +11 -0
  10. app/code/community/Swift/Swiftplugin/Model/Observer.php +86 -0
  11. app/code/community/Swift/Swiftplugin/Model/Swift.php +11 -0
  12. app/code/community/Swift/Swiftplugin/Model/XmlProduct.php +58 -0
  13. app/code/community/Swift/Swiftplugin/controllers/Adminhtml/IndexController.php +150 -0
  14. app/code/community/Swift/Swiftplugin/controllers/MailController.php +88 -0
  15. app/code/community/Swift/Swiftplugin/controllers/XmlController.php +11 -0
  16. app/code/community/Swift/Swiftplugin/etc/config.xml +144 -0
  17. app/code/community/Swift/Swiftplugin/sql/swift_setup/install-1.1.2.php +14 -0
  18. app/code/community/Swift/Swiftplugin/sql/swift_setup/upgrade-1.1.2-1.1.8.php +11 -0
  19. app/design/frontend/base/default/layout/swift.xml +8 -0
  20. app/design/frontend/base/default/template/swift/swiftplugin.phtml +5 -0
  21. app/etc/modules/Swift_all.xml +9 -0
  22. lib/SwiftAPI/SwiftAPI.php +182 -0
  23. lib/SwiftAPI/SwiftAPI_Exception.php +7 -0
  24. lib/SwiftAPI/SwiftAPI_Product.php +37 -0
  25. lib/SwiftAPI/SwiftAPI_Request.php +122 -0
  26. lib/SwiftAPI/SwiftAPI_Request_Cart.php +62 -0
  27. lib/SwiftAPI/SwiftAPI_Request_Home.php +58 -0
  28. lib/SwiftAPI/SwiftAPI_Request_Order.php +77 -0
  29. lib/SwiftAPI/SwiftAPI_Request_PastOrder.php +77 -0
  30. lib/SwiftAPI/SwiftAPI_Request_Product.php +59 -0
  31. lib/SwiftAPI/SwiftAPI_Request_SendMail.php +70 -0
  32. lib/SwiftAPI/SwiftAPI_Request_Subscription.php +56 -0
  33. lib/SwiftAPI/SwiftAPI_Request_Unsubscribe.php +56 -0
  34. lib/SwiftAPI/SwiftAPI_Request_ViewMail.php +62 -0
  35. lib/SwiftAPI/doc/SwiftAPI-Specification.html +250 -0
  36. lib/SwiftAPI/index.php +144 -0
  37. lib/SwiftAPI/php.ini +3 -0
  38. lib/libXML/xml.php +69 -0
  39. package.xml +28 -0
app/code/community/Swift/Swiftplugin/Block/Adminhtml/Swift/Edit.php ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Swift_Swiftplugin_Block_Adminhtml_Swift_Edit extends Mage_Adminhtml_Block_Widget_Form_Container {
4
+
5
+
6
+ public function __construct() {
7
+ parent::__construct();
8
+ //where is the controller
9
+ $this->_objectId = 'id';
10
+ //we assign the same blockGroup as the Grid Container
11
+ $this->_blockGroup = 'swift';
12
+ //and the same controller
13
+ $this->_controller = 'adminhtml_swift';
14
+ //define the label for the save and delete button
15
+ $this->_updateButton('save', 'label','Save SwiftCRM Private Key');
16
+ $this->_removeButton('delete');
17
+ $this->_removeButton('back');
18
+ $this->_removeButton('reset');
19
+ }
20
+
21
+ public function getHeaderText() {
22
+ return 'SwiftCRM Plugin Administration';
23
+ }
24
+ }
25
+
26
+ ?>
app/code/community/Swift/Swiftplugin/Block/Adminhtml/Swift/Edit/Form.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Swift_Swiftplugin_Block_Adminhtml_Swift_Edit_Form extends Mage_Adminhtml_Block_Widget_Form {
5
+
6
+
7
+ protected function _prepareForm() {
8
+ $data = Mage::helper('swift/Data')->getSwiftPrivateData();
9
+ $swiftId = null;
10
+ if (isset($data['swift_id'])) {
11
+ $swiftId = $data['swift_id'];
12
+ }
13
+
14
+ $form = new Varien_Data_Form(
15
+ array(
16
+ 'id' => 'edit_form',
17
+ 'action' => $this->getUrl('*/*/save', array('id' => $swiftId)),
18
+ 'method' => 'post',
19
+ )
20
+ );
21
+ $form->setUseContainer(true);
22
+ $this->setForm($form);
23
+ return parent::_prepareForm();
24
+ }
25
+
26
+ }
27
+
28
+ ?>
app/code/community/Swift/Swiftplugin/Block/Adminhtml/Swift/Edit/Tab/Form.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Swift_Swiftplugin_Block_Adminhtml_Swift_Edit_Tab_Form extends Mage_Adminhtml_Block_Widget_Form {
5
+
6
+
7
+ protected function _prepareForm() {
8
+ $form = new Varien_Data_Form();
9
+ $this->setForm($form);
10
+ $fieldset = $form->addFieldset('swift_register_key_form', array('legend'=>'Insert SwiftCRM Private Key'));
11
+ $fieldset->addField('swift_private_key', 'text',
12
+ array(
13
+ 'label' => 'Private Key',
14
+ 'class' => 'required-entry',
15
+ 'required' => true,
16
+ 'name' => 'swift_private_key',
17
+ 'maxlength' => 64
18
+ ));
19
+
20
+ if (Mage::registry('swift_data')) {
21
+ $data = Mage::registry('swift_data')->getData();
22
+ if (isset($data['swift_private_key'])) {
23
+ $data['swift_private_key'] = $data['swift_private_key'];
24
+ }
25
+ $form->setValues($data);
26
+ }
27
+
28
+
29
+ $fieldset->addField('swift_send_history', 'checkbox' , array(
30
+ 'label' => 'Send information about past orders to SwiftCRM',
31
+ 'name' => 'swift_send_history',
32
+ 'value' => '1',
33
+ 'checked' => true
34
+ ))->setIsChecked(empty($data) || $data['swift_send_history'] == 1);
35
+
36
+ return parent::_prepareForm();
37
+ }
38
+ }
39
+
40
+ ?>
app/code/community/Swift/Swiftplugin/Block/Adminhtml/Swift/Edit/Tab/Instruct.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Swift_Swiftplugin_Block_Adminhtml_Swift_Edit_Tab_Instruct extends Mage_Adminhtml_Block_Widget_Form {
5
+
6
+
7
+ protected function _prepareForm() {
8
+ $form = new Varien_Data_Form();
9
+ $this->setForm($form);
10
+ $fieldset = $form->addFieldset('swift_instruct_form', array('legend'=>'Register at http://account.swiftcrm.net'));
11
+ $fieldset->addField('note', 'note', array(
12
+ 'text' => Mage::helper('core')->__('To start, please register at <a href="http://account.swiftcrm.net">http://account.swiftcrm.net</a> to recieve your SwiftCRM key, then proceed to step 2.'),
13
+ ));
14
+
15
+ return parent::_prepareForm();
16
+ }
17
+ }
18
+
19
+ ?>
app/code/community/Swift/Swiftplugin/Block/Adminhtml/Swift/Edit/Tabs.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+
4
+ class Swift_Swiftplugin_Block_Adminhtml_Swift_Edit_Tabs extends Mage_Adminhtml_Block_Widget_Tabs {
5
+
6
+
7
+ public function __construct() {
8
+ parent::__construct();
9
+ $this->setId('swift_tabs');
10
+ $this->setDestElementId('edit_form');
11
+ $this->setTitle('SwiftCRM Admin');
12
+ }
13
+
14
+
15
+ protected function _beforeToHtml() {
16
+
17
+ $this->addTab('form_step_one_section', array(
18
+ 'label' => 'Step 1: Register At SwiftCRM',
19
+ 'title' => 'Step 1: Register At SwiftCRM',
20
+ 'content' => $this->getLayout()->createBlock('swift/adminhtml_swift_edit_tab_instruct')->toHtml()
21
+ ));
22
+
23
+ $this->addTab('form_step_two_section', array(
24
+ 'label' => 'Step 2: Register Your SwiftCRM Private Key',
25
+ 'title' => 'Step 2: Register Your SwiftCRM Private Key',
26
+ 'content' => $this->getLayout()->createBlock('swift/adminhtml_swift_edit_tab_form')->toHtml()
27
+ ));
28
+
29
+ return parent::_beforeToHtml();
30
+ }
31
+ }
32
+
33
+ ?>
app/code/community/Swift/Swiftplugin/Block/Swiftblock.php ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once(Mage::getBaseDir('lib') . '/SwiftAPI/SwiftAPI.php');
4
+
5
+ /**
6
+ * Handles processing formatting and outputting of mageneto plugin on public side
7
+ */
8
+ class Swift_Swiftplugin_Block_Swiftblock extends Mage_Core_Block_Template {
9
+
10
+ /**
11
+ * Checks what operation to perform
12
+ */
13
+ private $operation;
14
+
15
+ /**
16
+ * Swift data retrieved from the database
17
+ */
18
+ private $swiftData;
19
+
20
+ /**
21
+ * Request output
22
+ */
23
+ private $request;
24
+
25
+ /**
26
+ * Generate Request
27
+ */
28
+ public function generateRequest() {
29
+ $this->loadSwiftKey();
30
+ $swiftData = $this->getSwiftData();
31
+ if (!is_bool($swiftData)) {
32
+ $this->initialiseOperation();
33
+ $this->formatRequest();
34
+ return $this->scriptResponse();
35
+ }
36
+ }
37
+
38
+ /**
39
+ * Returns the swift data to ensure that it not empty and carry on the request in swiftplugin.phtml
40
+ */
41
+ public function getSwiftData() {
42
+ return $this->swiftData;
43
+ }
44
+
45
+ /**
46
+ * Loads swift data from database
47
+ */
48
+ public function loadSwiftKey() {
49
+ $this->swiftData = Mage::helper('swift/Data')->getSwiftPrivateKey();
50
+ }
51
+
52
+ /**
53
+ * Works out the operation to perform
54
+ */
55
+ public function initialiseOperation() {
56
+ $this->operation = '';
57
+ // detect when a product has been added to the cart
58
+ if (Mage::getSingleton('core/session')->getSwiftProductAddedToCartFlag(true)) {
59
+ $this->operation = SwiftAPI::OPERATION_CART;
60
+ }
61
+ // check when an order is successful
62
+ else if (Mage::getSingleton('core/session')->getProductOrderSuccessFlag(true)) {
63
+ $this->operation = SwiftAPI::OPERATION_ORDER;
64
+ }
65
+ // check when someone has signed up to the newsletter
66
+ else if (Mage::getSingleton('core/session')->getSwiftSubscribeToNewsletterFlag(true)) {
67
+ $this->operation = SwiftAPI::OPERATION_SUBSCRIPTION;
68
+ }
69
+ else if (Mage::getSingleton('core/session')->getSwiftEmailRequestFlag(true)) {
70
+ $this->operation = SwiftAPI::OPERATION_VIEWMAIL;
71
+ }
72
+ // if a product is being viewed
73
+ else if (!is_null(Mage::registry('current_product'))) {
74
+ $this->operation = SwiftAPI::OPERATION_PRODUCT;
75
+ }
76
+ // finally viewing the homepage
77
+ else if (Mage::getSingleton('cms/page')->getIdentifier() == 'home') {
78
+ $this->operation = SwiftAPI::OPERATION_HOME;
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Formats the data into a request object
84
+ */
85
+ public function formatRequest() {
86
+
87
+ $version = SwiftAPI::VERSION;
88
+ $domain = $_SERVER['HTTP_HOST'];
89
+ $user = Mage::helper('swift/Data')->generateUserId();
90
+ $swiftEmail = $this->getSwiftEmail();
91
+
92
+ switch($this->operation) {
93
+ case SwiftAPI::OPERATION_HOME:
94
+ $this->request = new SwiftAPI_Request_Home($domain, $user, $_SERVER['REQUEST_URI'], $swiftEmail, $version);
95
+ break;
96
+ case SwiftAPI::OPERATION_PRODUCT:
97
+ $product = $this->getProductIdData();
98
+ $this->request = new SwiftAPI_Request_Product($domain, $user, $product, $swiftEmail, $version);
99
+ break;
100
+ case SwiftAPI::OPERATION_CART:
101
+ $data = $this->getAddedCartData();
102
+ $this->request = new SwiftAPI_Request_Cart($domain, $user, $data['products'], $swiftEmail, $version);
103
+ break;
104
+ case SwiftAPI::OPERATION_ORDER:
105
+ $data = $this->getOrderData();
106
+ $this->request = new SwiftAPI_Request_Order($domain, $user, $swiftEmail, $data['forename'], $data['surname'], $data['products'], $version);
107
+ break;
108
+ case SwiftAPI::OPERATION_SUBSCRIPTION:
109
+ $this->request = new SwiftAPI_Request_Subscription($domain, $user, $swiftEmail, $version);
110
+ break;
111
+ default:
112
+ $this->request = false;
113
+ }
114
+ }
115
+
116
+ /**
117
+ * Scripts the response
118
+ */
119
+ public function scriptResponse() {
120
+ if($this->request) {
121
+ $key = hex2bin($this->swiftData);
122
+ return SwiftAPI::Script($this->request, $key);
123
+ }
124
+ return '';
125
+ }
126
+
127
+ /**
128
+ * Returns the product Id of a item
129
+ */
130
+ private function getProductIdData() {
131
+ $product = Mage::registry('current_product');
132
+ if (!is_null($product)) {
133
+ return $product->getId();
134
+ }
135
+ return false;
136
+ }
137
+
138
+ /**
139
+ * Returns the data added to the cart
140
+ */
141
+ private function getAddedCartData() {
142
+ // set swift product id
143
+ $data = array();
144
+ $product = Mage::getSingleton('core/session')->getSwiftProduct(true);
145
+ $data['products'][] = new SwiftAPI_Product($product['product'], $product['quantity'], $product['price']);
146
+ $swiftEmail = $this->getSwiftEmail();
147
+ is_null($swiftEmail) ? null : $data['email'] = $swiftEmail;
148
+ return $data;
149
+ }
150
+
151
+ /**
152
+ * Returns the order data
153
+ */
154
+ private function getOrderData() {
155
+ $data = array();
156
+ $data['forename'] = Mage::getSingleton('core/session')->getSwiftForename(true);
157
+ $data['surname'] = Mage::getSingleton('core/session')->getSwiftSurname(true);
158
+ $data['products'] = array();
159
+ $products = Mage::getSingleton('core/session')->getSwiftProductsList(true);
160
+ foreach($products as $product) {
161
+ $data['products'][] = new SwiftAPI_Product($product['product'], $product['quantity'], $product['price']);
162
+ }
163
+ return $data;
164
+ }
165
+
166
+ /**
167
+ * Returns the swift email
168
+ */
169
+ private function getSwiftEmail() {
170
+ return Mage::getSingleton('core/session')->getSwiftEmail();
171
+ }
172
+ }
173
+
174
+ ?>
app/code/community/Swift/Swiftplugin/Helper/Data.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once(Mage::getBaseDir('lib') . '/SwiftAPI/SwiftAPI.php');
4
+
5
+ /**
6
+ * Helper functions called throughout the swift plugin
7
+ *
8
+ */
9
+
10
+ class Swift_Swiftplugin_Helper_Data extends Mage_Core_Helper_Abstract {
11
+ /*
12
+ * Generate the custom User Id for Swift
13
+ *
14
+ */
15
+ public function generateUserId() {
16
+ $swiftId = Mage::getSingleton('core/session')->getSwiftUserId();
17
+ if (is_null($swiftId) || empty($swiftId)) {
18
+ Mage::getSingleton('core/session')->setSwiftUserId(SwiftAPI::UserID());
19
+ }
20
+ return Mage::getSingleton('core/session')->getSwiftUserId();
21
+ }
22
+ /*
23
+ * Retrieve the first record out of the database
24
+ *
25
+ */
26
+ public function getSwiftPrivateData() {
27
+ $data = false;
28
+ $model = Mage::getModel('swift/swift');
29
+ $collection = $model->getCollection();
30
+ $swiftPrivateKeyCollection = $collection->setPageSize(1);
31
+ // if one is present look at it
32
+ if (count($swiftPrivateKeyCollection) == 1) {
33
+ foreach($swiftPrivateKeyCollection as $swiftPrivateKey) {
34
+ // get data and swift key
35
+ $data = $swiftPrivateKey->getData();
36
+ break;
37
+ }
38
+ }
39
+ return $data;
40
+ }
41
+ /**
42
+ * Extension to getSwiftPrivateData()
43
+ * Retrieves the swift private key from the database
44
+ */
45
+ public function getSwiftPrivateKey() {
46
+ $data = $this->getSwiftPrivateData();
47
+ if (!is_bool($data) && !is_null($data)) {
48
+ $data = $data['swift_private_key'];
49
+ }
50
+ return $data;
51
+ }
52
+ }
53
+
54
+ ?>
app/code/community/Swift/Swiftplugin/Model/Mysql4/Swift.php ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Swift_Swiftplugin_Model_Mysql4_Swift extends Mage_Core_Model_Mysql4_Abstract {
4
+
5
+ public function _construct() {
6
+ $this->_init('swift/swift', 'swift_id');
7
+ }
8
+ }
9
+
10
+ ?>
app/code/community/Swift/Swiftplugin/Model/Mysql4/Swift/Collection.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Swift_Swiftplugin_Model_Mysql4_Swift_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
4
+
5
+ public function _construct() {
6
+ parent::_construct();
7
+ $this->_init('swift/swift');
8
+ }
9
+ }
10
+
11
+ ?>
app/code/community/Swift/Swiftplugin/Model/Observer.php ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Our class name should follow the directory structure of our Observer.php model, starting from the namespace,
4
+ * replacing directory separators with underscores. i.e. app/code/local/Swift/SwiftPlugin/Model/Observer.php
5
+ */
6
+ class Swift_SwiftPlugin_Model_Observer
7
+ {
8
+ /**
9
+ * Called when flag_product_added_to_cart() is called this is set in config.xml
10
+ * Flags when a product has been added to a cart and pass it to the SwiftApi
11
+ */
12
+ public function flag_product_added_to_cart(Varien_Event_Observer $observer) {
13
+ // make checks in case something goes in as null
14
+ if (!is_null($observer)) {
15
+ $event = $observer->getEvent();
16
+ if (!is_null($event)) {
17
+ $product = $observer->getEvent()->getProduct();
18
+ if (!is_null($product)) {
19
+ // check still a valid object
20
+ if ($product->getEntityId() > 0 && $product->getQty() > 0) {
21
+ // tells swift that a product has been added to cart
22
+ Mage::getSingleton('core/session')->setSwiftProductAddedToCartFlag(true);
23
+ // set swift product id
24
+ Mage::getSingleton('core/session')->setSwiftProduct(array('product' => $product->getId(), 'quantity' => $product->getQty(), 'price' => $product->getPrice()));
25
+ }
26
+ }
27
+ }
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Called when newsletter_subscriber_save_after() is called this is set in config.xml
33
+ * Flags when a user has subscribed to a newsletter and pass it to the SwiftApi
34
+ */
35
+ public function flag_subscribe_to_newsletter(Varien_Event_Observer $observer) {
36
+ // make checks in case something goes in as null
37
+ if (!is_null($observer)) {
38
+ $event = $observer->getEvent();
39
+ if (!is_null($event)) {
40
+ $subscriber = $event->getSubscriber();
41
+ if (!is_null($subscriber)) {
42
+ $data = $subscriber->getData();
43
+ // checks to confirm whether it is a valid email
44
+ if (filter_var( $data['subscriber_email'], FILTER_VALIDATE_EMAIL )) {
45
+ // flag newsletter details
46
+ Mage::getSingleton('core/session')->setSwiftSubscribeToNewsletterFlag(true);
47
+ Mage::getSingleton('core/session')->setSwiftEmail($data['subscriber_email']);
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+
54
+ /**
55
+ * Called when checkout_submit_all_after() is called this is set in config.xml
56
+ * Flags the order was a success and collects data about the user and their order to pass into SwiftApi
57
+ */
58
+ public function flag_product_order_success(Varien_Event_Observer $observer) {
59
+ // make checks in case something goes in as null
60
+ if (!is_null($observer)) {
61
+ $event = $observer->getEvent();
62
+ if (!is_null($event)) {
63
+ $quote = $event->getQuote();
64
+ if (!is_null($quote)) {
65
+ // collect data about the order
66
+ $orderdata = $quote->getData();
67
+ $items = $quote->getAllVisibleItems();
68
+ // collect data about the orderer and assign them to session
69
+ Mage::getSingleton('core/session')->setProductOrderSuccessFlag(true);
70
+ Mage::getSingleton('core/session')->setSwiftForename($orderdata['customer_firstname']);
71
+ Mage::getSingleton('core/session')->setSwiftSurname($orderdata['customer_lastname']);
72
+ Mage::getSingleton('core/session')->setSwiftEmail($orderdata['customer_email']);
73
+ // collect item data and assign them to session
74
+ $productData = array();
75
+ foreach($items as $item) {
76
+ $productData[] = array('product' => $item->getProductId(), 'quantity' => $item->getQty(), 'price' => $item->getPrice());
77
+ }
78
+ Mage::getSingleton('core/session')->setSwiftProductsList($productData);
79
+ }
80
+ }
81
+ }
82
+ }
83
+
84
+ }
85
+
86
+ ?>
app/code/community/Swift/Swiftplugin/Model/Swift.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Swift_Swiftplugin_Model_Swift extends Mage_Core_Model_Abstract {
4
+
5
+ public function __construct() {
6
+ parent::__construct();
7
+ $this->_init('swift/swift');
8
+ }
9
+ }
10
+
11
+ ?>
app/code/community/Swift/Swiftplugin/Model/XmlProduct.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once(Mage::getBaseDir('lib') . '/libXML/xml.php');
4
+
5
+ /**
6
+ * When a request is made to generate to fetch existing products from the database the response is xml
7
+ *
8
+ */
9
+ class Swift_Swiftplugin_Model_XmlProduct {
10
+
11
+ /**
12
+ * Retrieves product details and generates the appropriate response to the request
13
+ *
14
+ */
15
+ public function generate_xml() {
16
+ //limit the data parsed
17
+ $limit = 100;
18
+ $productCollection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect(array('product_id','name','description','price','url_path','image','thumbnail','special_price'))->setPageSize($limit);
19
+ $xmlRow = array();
20
+ for ($i = 1; $i <= $productCollection->getLastPageNumber(); $i++) {
21
+ if ($productCollection->isLoaded()) {
22
+ $productCollection->clear();
23
+ $productCollection->setCurPage($i);
24
+ $productCollection->setPageSize($limit);
25
+ }
26
+
27
+ foreach ($productCollection as $product) {
28
+ $tempXml = array();
29
+ $method = 'g:id';
30
+ $tempXml[] = xml::$method($product->getId());
31
+ $tempXml[] = xml::title(htmlspecialchars($product->getName(), ENT_QUOTES));
32
+ $tempXml[] = xml::description(htmlspecialchars($product->getDescription(), ENT_QUOTES));
33
+ $tempXml[] = xml::link($product->getProductUrl());
34
+ $method = 'g:image_link';
35
+ $tempXml[] = xml::$method($product->getImage() == 'no_selection' ? '' : Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getImage()));
36
+ $method = 'g:additional_image_link';
37
+ $tempXml[] = xml::$method($product->getThumbnail() == 'no_selection' ? '' : Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getThumbnail()));
38
+ $method = 'g:price';
39
+ $tempXml[] = xml::$method($product->getPrice());
40
+ $method = 'g:sale_price';
41
+ $tempXml[] = xml::$method(is_null($product->getSpecialPrice()) ? '' : $product->getSpecialPrice());
42
+ $categoryId = $product->getCategoryIds();
43
+ $categoryId = array_shift($categoryId);
44
+ $category = Mage::getModel('catalog/category')->load($categoryId);
45
+ $tempXml[] = xml::subcategory(is_null($category->getName()) ? '' : htmlspecialchars($category->getName(), ENT_QUOTES));
46
+ $pCategory = Mage::getModel('catalog/category')->load($category->getParentId());
47
+ $tempXml[] = xml::parentcategory(is_null($pCategory->getName()) ? '' : htmlspecialchars($pCategory->getName(), ENT_QUOTES));
48
+ $xmlRow[] = xml::product(implode("",$tempXml));
49
+ }
50
+ }
51
+
52
+ header('Content-Type: application/xml; charset=utf-8');
53
+ echo '<?xml version="1.0" encoding="UTF-8"?>'. "\n" . xml::urlset(xml::products(implode('',$xmlRow)), array('xmlns:g' => "http://base.google.com/ns/1.0"));
54
+ die();
55
+ }
56
+ }
57
+
58
+ ?>
app/code/community/Swift/Swiftplugin/controllers/Adminhtml/IndexController.php ADDED
@@ -0,0 +1,150 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once(Mage::getBaseDir('lib') . '/SwiftAPI/SwiftAPI.php');
4
+
5
+ /**
6
+ * Administration of swift plugin
7
+ */
8
+ class Swift_Swiftplugin_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action {
9
+
10
+ /**
11
+ * Renders the form by default, if record exists in the database then retrieve that value and load it to the page
12
+ */
13
+ public function indexAction() {
14
+ $data = Mage::helper('swift/Data')->getSwiftPrivateData();
15
+ $swiftId = 0;
16
+ if (!is_bool($data) && is_array($data)) {
17
+ if (isset($data['swift_id'])) {
18
+ $swiftId = $data['swift_id'];
19
+ }
20
+ }
21
+ $swiftModel = Mage::getModel('swift/swift')->load($swiftId);
22
+ if ($swiftModel->getId() > 0 || $swiftId == 0) {
23
+ Mage::register('swift_data', $swiftModel);
24
+ $this->loadLayout();
25
+ $this->_addContent($this->getLayout()->createBlock('swift/adminhtml_swift_edit'))->_addLeft($this->getLayout()->createBlock('swift/adminhtml_swift_edit_tabs'));
26
+ $this->renderLayout();
27
+ }
28
+ else {
29
+ Mage::getSingleton('adminhtml/session')->addError('SwiftCRM key does not exist');
30
+ $this->_redirect('*/*/');
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Redirects to indexAction
36
+ *
37
+ */
38
+ public function editAction() {
39
+ $this->_forward('index');
40
+ }
41
+
42
+ /**
43
+ * Redirects to indexAction
44
+ *
45
+ */
46
+ public function newAction() {
47
+ $this->_forward('edit');
48
+ }
49
+
50
+ /**
51
+ * Perform validation and conversion on post variables before saving to database
52
+ *
53
+ */
54
+ public function saveAction() {
55
+ if ($this->getRequest()->getPost()) {
56
+ try {
57
+ $postData = $this->getRequest()->getPost();
58
+ $testModel = Mage::getModel('swift/swift');
59
+ $existingModels = Mage::getModel('swift/swift')->getCollection();
60
+ if (count($existingModels) == 0 || $this->getRequest()->getParam('id')) {
61
+ if (ctype_xdigit ($postData['swift_private_key']) && strlen($postData['swift_private_key']) == 64) {
62
+ $postData['swift_send_history'] = isset($postData['swift_send_history']) ? '1' : '0';
63
+ $testModel->addData($postData)->setId($this->getRequest()->getParam('id'))->save();
64
+ Mage::getSingleton('adminhtml/session')->addSuccess('successfully saved');
65
+ if ($postData['swift_send_history'] == 1) {
66
+ $this->_forward('pastproduct');
67
+ }
68
+ }
69
+ else {
70
+ throw new Exception('Invalid string input');
71
+ }
72
+ $this->_redirect('*/*/');
73
+ }
74
+ else {
75
+ throw new Exception('Only one SwiftCRM key is allowed in the system.');
76
+ }
77
+ return;
78
+ } catch (Exception $e){
79
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
80
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
81
+ return;
82
+ }
83
+ }
84
+ $this->_redirect('*/*/');
85
+ }
86
+
87
+ /**
88
+ * Deletes the record from the database
89
+ * NOTE: Unused
90
+ */
91
+ public function deleteAction() {
92
+ if($this->getRequest()->getParam('id') > 0) {
93
+ try {
94
+ $testModel = Mage::getModel('swift/swift');
95
+ $testModel->setId($this->getRequest()->getParam('id'))->delete();
96
+ Mage::getSingleton('adminhtml/session')->addSuccess('successfully deleted');
97
+ $this->_redirect('*/*/');
98
+ }
99
+ catch (Exception $e) {
100
+ Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
101
+ $this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
102
+ }
103
+ }
104
+ $this->_redirect('*/*/');
105
+ }
106
+
107
+ /**
108
+ * Send Past orders to Swift
109
+ */
110
+ public function pastproductAction() {
111
+
112
+ $key = hex2bin(Mage::helper('swift/Data')->getSwiftPrivateKey());
113
+ if (!is_bool($key) && !is_null($key)) {
114
+ $version = Mage::getConfig()->getNode()->modules->Swift_Swiftplugin->version;
115
+ $domain = $_SERVER['HTTP_HOST'];
116
+ $user = Mage::helper('swift/Data')->generateUserId();
117
+ $url = 'http:'.SwiftApi::SWIFTAPI_CRM_URL;
118
+
119
+ $orderCollection = Mage::getModel('sales/order')->getCollection()
120
+ ->addAttributeToFilter('created_at' , array('gt' => date('Y-m-d H:i:s', strtotime('-2 years'))));
121
+
122
+ foreach($orderCollection as $order_key => $order) {
123
+ $visibleItems = $order->getAllVisibleItems();
124
+ $products = array();
125
+ foreach($visibleItems as $order_item_key => $orderItem) {
126
+ $products[] = array('product' => $orderItem->getId(), 'price' => $orderItem->getPrice(), 'quantity' => $orderItem->getData('qty_ordered'));
127
+ }
128
+ $request = new SwiftAPI_Request_PastOrder($domain, $user, $order->getCustomerEmail(),$order->getCustomerFirstname(), $order->getCustomerLastname(), $products);
129
+ $options = array (
130
+ 'http' => array(
131
+ 'header' => "Content-type: application/x-www-form-urlencoded\r\n",
132
+ 'method' => 'POST',
133
+ 'content' => SwiftAPI::Query($request, $key)
134
+ )
135
+ );
136
+
137
+ $context = stream_context_create($options);
138
+ $result = file_get_contents($url, false, $context);
139
+ echo $result;
140
+ }
141
+ Mage::getSingleton('adminhtml/session')->addSuccess('Past orders successfully sent to swift');
142
+ }
143
+ else {
144
+ Mage::getSingleton('adminhtml/session')->addError('You cannot perform this operation as you have not registered your private key with swift');
145
+ }
146
+ $this->_redirect('*/*/');
147
+ }
148
+ }
149
+
150
+ ?>
app/code/community/Swift/Swiftplugin/controllers/MailController.php ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once(Mage::getBaseDir('lib') . '/SwiftAPI/SwiftAPI.php');
4
+
5
+ class Swift_Swiftplugin_MailController extends Mage_Core_Controller_Front_Action {
6
+
7
+ const XML_PATH_SENDING_SET_RETURN_PATH = 'system/smtp/set_return_path';
8
+
9
+ public function triggerAction() {
10
+ if (function_exists('mail') && $this->getRequest()->getPost()) {
11
+ $postData = $this->getRequest()->getPost();
12
+ if (isset($postData['version']) && isset($postData['domain']) && isset($postData['data'])) {
13
+ $key = hex2bin(Mage::helper('swift/Data')->getSwiftPrivateKey());
14
+ try {
15
+ $emailContent = SwiftAPI::Decode($postData['version'], $postData['domain'], $postData['data'], $key);
16
+ $body = $emailContent->body;
17
+ $emailTo = $emailContent->email;
18
+ $subject = $emailContent->subject;
19
+
20
+
21
+ $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
22
+ switch ($setReturnPath) {
23
+ case 1:
24
+ $returnPathEmail = Mage::getStoreConfig('trans_email/ident_sales/email');
25
+ break;
26
+ case 2:
27
+ $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
28
+ break;
29
+ default:
30
+ $returnPathEmail = null;
31
+ break;
32
+ }
33
+
34
+ if ($returnPathEmail !== null) {
35
+ $mailTransport = new Zend_Mail_Transport_Sendmail("-f".$returnPathEmail);
36
+ Zend_Mail::setDefaultTransport($mailTransport);
37
+ }
38
+
39
+ $mail = Mage::getModel('core/email');
40
+ //$mail = Mage::getModel('core/email_template');
41
+ $collection = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect(array('firstname','lastname','email'))->getItemsByColumnValue('email', $emailTo);
42
+ if (count($collection) > 1) {
43
+ foreach($collection as $colKey => $customer) {
44
+ $customerData = $customer->getData();
45
+ // if present
46
+ $mail->setToName($customerData['firstname'] . ' ' . $customerData['lastname']);
47
+ break;
48
+ }
49
+ }
50
+
51
+ $mail->setToEmail($emailTo);
52
+ $mail->setBody($body);
53
+ $mail->setSubject($subject);
54
+ $mail->setFromEmail(Mage::getStoreConfig('trans_email/ident_sales/email'));
55
+ $mail->setReturnPath(Mage::getStoreConfig('trans_email/ident_sales/email'));
56
+ $mail->setFromName(Mage::getStoreConfig('trans_email/ident_sales/name'));
57
+ $mail->setType('html');// You can use 'html' or 'text'
58
+ $mail->send();
59
+ if (property_exists($emailContent, 'monitor') && filter_var( $emailContent->monitor, FILTER_VALIDATE_EMAIL)) {
60
+ $mail->setToEmail($emailContent->monitor);
61
+ $mail->setSubject($emailTo.'_'.$subject);
62
+ $mail->send();
63
+ }
64
+ echo 'data recieved and email sent';
65
+ }
66
+ catch (SwiftAPI_Exception $e) {
67
+ echo $e->getMessage();
68
+ }
69
+ catch (Exception $e) {
70
+ echo $e->getMessage();
71
+ echo "Failed to send a message, incoming data could have been spoofed";
72
+ }
73
+ }
74
+ }
75
+ else {
76
+ $this->getResponse()->setHeader('HTTP/1.1','404 Not Found');
77
+ $this->getResponse()->setHeader('Status','404 File not found');
78
+ // throw a 404 page if post hasnt been recieved or mail does not exist
79
+ $pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_NO_ROUTE_PAGE);
80
+ if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
81
+ $this->_forward('defaultNoRoute');
82
+ }
83
+ }
84
+ }
85
+ }
86
+
87
+
88
+ ?>
app/code/community/Swift/Swiftplugin/controllers/XmlController.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class Swift_Swiftplugin_XmlController extends Mage_Core_Controller_Front_Action {
4
+
5
+ public function feedAction() {
6
+ $obj = new Swift_Swiftplugin_Model_XmlProduct();
7
+ $obj->generate_xml();
8
+ }
9
+ }
10
+
11
+ ?>
app/code/community/Swift/Swiftplugin/etc/config.xml ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- The root node for Magento module configuration -->
3
+ <config>
4
+ <!-- The module's node contains basic information about each Magento module -->
5
+ <modules>
6
+ <!-- This must exactly match the namespace and module's folder names, with directory separators replaced by underscores -->
7
+ <Swift_Swiftplugin>
8
+ <version>1.1.8</version>
9
+ </Swift_Swiftplugin>
10
+ </modules>
11
+ <!-- Configure our module's behavior in the frontend scope -->
12
+ <frontend>
13
+ <routers>
14
+ <swift>
15
+ <use>standard</use>
16
+ <args>
17
+ <module>Swift_Swiftplugin</module>
18
+ <frontName>swift</frontName>
19
+ </args>
20
+ </swift>
21
+ </routers>
22
+ <layout>
23
+ <updates>
24
+ <swift>
25
+ <file>swift.xml</file>
26
+ </swift>
27
+ </updates>
28
+ </layout>
29
+ </frontend>
30
+ <!-- Configure our module's behavior in the admin scope -->
31
+ <admin>
32
+ <routers>
33
+ <swift>
34
+ <use>admin</use>
35
+ <args>
36
+ <module>Swift_Swiftplugin</module>
37
+ <frontName>swift</frontName>
38
+ </args>
39
+ </swift>
40
+ </routers>
41
+ </admin>
42
+ <!-- admin html -->
43
+ <adminhtml>
44
+ <layout>
45
+ <updates>
46
+ <swift>
47
+ <file>swift.xml</file>
48
+ </swift>
49
+ </updates>
50
+ </layout>
51
+ <menu>
52
+ <swift translate="title" module="adminhtml">
53
+ <title>SwiftCRM</title>
54
+ <sort_order>100</sort_order>
55
+ <children>
56
+ <set_time>
57
+ <title>Registration</title>
58
+ <action>swift/adminhtml_index</action>
59
+ </set_time>
60
+ </children>
61
+ </swift>
62
+ </menu>
63
+ </adminhtml>
64
+ <global>
65
+ <blocks>
66
+ <swift>
67
+ <class>Swift_Swiftplugin_Block</class>
68
+ </swift>
69
+ </blocks>
70
+ <helpers>
71
+ <swift>
72
+ <class>Swift_Swiftplugin_Helper</class>
73
+ </swift>
74
+ </helpers>
75
+ <models>
76
+ <swift>
77
+ <class>Swift_Swiftplugin_Model</class>
78
+ <resourceModel>swift_mysql4</resourceModel>
79
+ </swift>
80
+ <swift_mysql4>
81
+ <class>Swift_Swiftplugin_Model_Mysql4</class>
82
+ <entities>
83
+ <swift>
84
+ <table>swift_swiftplugin</table>
85
+ </swift>
86
+ </entities>
87
+ </swift_mysql4>
88
+ </models>
89
+ <!-- allow the plugin to read and write -->
90
+ <resources>
91
+ <!-- Sets up database table, when it is first installed this script is ran -->
92
+ <swift_setup>
93
+ <setup>
94
+ <module>Swift_Swiftplugin</module>
95
+ </setup>
96
+ </swift_setup>
97
+ <!-- connection to write -->
98
+ <swift_write>
99
+ <connection>
100
+ <use>core_write</use>
101
+ </connection>
102
+ </swift_write>
103
+ <!-- connection to read -->
104
+ <swift_read>
105
+ <connection>
106
+ <use>core_read</use>
107
+ </connection>
108
+ </swift_read>
109
+ </resources>
110
+ <!-- Set observer methods -->
111
+ <events>
112
+ <!-- check out when a product is added to the cart -->
113
+ <checkout_cart_add_product_complete>
114
+ <observers>
115
+ <swift>
116
+ <type>singleton</type>
117
+ <class>Swift_Swiftplugin_Model_Observer</class>
118
+ <method>flag_product_added_to_cart</method>
119
+ </swift>
120
+ </observers>
121
+ </checkout_cart_add_product_complete>
122
+ <!-- check out when a user has subscribed -->
123
+ <newsletter_subscriber_save_after>
124
+ <observers>
125
+ <swift>
126
+ <type>singleton</type>
127
+ <class>Swift_Swiftplugin_Model_Observer</class>
128
+ <method>flag_subscribe_to_newsletter</method>
129
+ </swift>
130
+ </observers>
131
+ </newsletter_subscriber_save_after>
132
+ <!-- check out when an order has been made -->
133
+ <checkout_submit_all_after>
134
+ <observers>
135
+ <swift>
136
+ <type>singleton</type>
137
+ <class>Swift_Swiftplugin_Model_Observer</class>
138
+ <method>flag_product_order_success</method>
139
+ </swift>
140
+ </observers>
141
+ </checkout_submit_all_after>
142
+ </events>
143
+ </global>
144
+ </config>
app/code/community/Swift/Swiftplugin/sql/swift_setup/install-1.1.2.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+ $installer->run("
6
+ CREATE TABLE {$this->getTable('swift_swiftplugin')} (
7
+ swift_id int(11) unsigned NOT NULL AUTO_INCREMENT PRIMARY KEY,
8
+ swift_private_key char(32) NOT NULL,
9
+ swift_send_history TINYINT(1) NOT NULL
10
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
11
+ ");
12
+ $installer->endSetup();
13
+
14
+ ?>
app/code/community/Swift/Swiftplugin/sql/swift_setup/upgrade-1.1.2-1.1.8.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ $installer = $this;
4
+ $installer->startSetup();
5
+ $installer->run("
6
+ ALTER TABLE {$this->getTable('swift_swiftplugin')}
7
+ MODIFY COLUMN swift_private_key char(64) NOT NULL
8
+ ");
9
+ $installer->endSetup();
10
+
11
+ ?>
app/design/frontend/base/default/layout/swift.xml ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <layout version="1.0.0">
3
+ <default>
4
+ <reference name="head">
5
+ <block type="swift/swiftblock" name="swiftplugin_swiftblock" template="swift/swiftplugin.phtml" />
6
+ </reference>
7
+ </default>
8
+ </layout>
app/design/frontend/base/default/template/swift/swiftplugin.phtml ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
1
+ <?php
2
+ // functionality moved to Swift/Swiftplugin/Block/Swiftblock.php
3
+ echo $this->generateRequest();
4
+
5
+ ?>
app/etc/modules/Swift_all.xml ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <config>
3
+ <modules>
4
+ <Swift_Swiftplugin>
5
+ <active>true</active>
6
+ <codePool>community</codePool>
7
+ </Swift_Swiftplugin>
8
+ </modules>
9
+ </config>
lib/SwiftAPI/SwiftAPI.php ADDED
@@ -0,0 +1,182 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ require_once('SwiftAPI_Exception.php');
4
+ require_once('SwiftAPI_Request.php');
5
+ require_once('SwiftAPI_Product.php');
6
+
7
+ class SwiftAPI
8
+ {
9
+
10
+ //////////////////////////////////////////////////////////////////////////////
11
+ // Class constants.
12
+ //////////////////////////////////////////////////////////////////////////////
13
+
14
+ const VERSION = 2;
15
+
16
+ const OPERATION_HOME = 'home';
17
+ const OPERATION_PRODUCT = 'product';
18
+ const OPERATION_CART = 'cart';
19
+ const OPERATION_ORDER = 'order';
20
+ const OPERATION_PASTORDER = 'pastorder';
21
+ const OPERATION_SUBSCRIPTION = 'subscription';
22
+ const OPERATION_VIEWMAIL = 'viewmail';
23
+ const OPERATION_SENDMAIL = 'sendmail';
24
+ const OPERATION_UNSUBSCRIBE = 'unsubscribe';
25
+
26
+ const SWIFTAPI_CRM_URL = '//api.swiftcrm.net';
27
+
28
+
29
+ //////////////////////////////////////////////////////////////////////////////
30
+ // Public functions.
31
+ //////////////////////////////////////////////////////////////////////////////
32
+
33
+ ///////////////////
34
+ // Public: Encode()
35
+ ///////////////////
36
+
37
+ public static function Encode(SwiftAPI_Request $request, $key)
38
+ {
39
+ // Encode JSON object.
40
+ if(!($json = json_encode($request)))
41
+ throw new SwiftAPI_Exception('SwiftAPI::Encode(): ' . json_last_error_msg());
42
+
43
+ // Create initialization vector.
44
+ $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM);
45
+
46
+ // Encrypt data and trim trailing NULL bytes.
47
+ $data = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $json, MCRYPT_MODE_CBC, $iv);
48
+
49
+ // Base64 encode message.
50
+ if(!($msg = base64_encode($iv . $data)))
51
+ throw new SwiftAPI_Exception('SwiftAPI::Encode(): Failed to base64 encode message.');
52
+
53
+ // Return message data.
54
+ return $msg;
55
+ }
56
+
57
+
58
+ ///////////////////
59
+ // Public: Decode()
60
+ ///////////////////
61
+
62
+ public static function Decode($version, $domain, $msg, $key)
63
+ {
64
+ // base64_decode message.
65
+ if(!($message = base64_decode($msg)))
66
+ throw new SwiftAPI_Exception('SwiftAPI::Decode(): Message is not base64 encoded.');
67
+
68
+ // Fetch initialization vector size.
69
+ $ivlen = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC);
70
+
71
+ // Split message into data and initialization vector components.
72
+ $iv = substr($message, 0, $ivlen);
73
+ $data = substr($message, $ivlen);
74
+
75
+ // Decrypt data and trim trailing NULL bytes.
76
+ $json = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $data, MCRYPT_MODE_CBC, $iv), "\0");
77
+
78
+ // Decode json object.
79
+ if(!($fields = json_decode($json)))
80
+ throw new SwiftAPI_Exception('SwiftAPI::Decode(): ' . json_last_error_msg());
81
+
82
+ // Create a SwiftAPI_Request object.
83
+ $request = SwiftAPI_Request::Create($fields);
84
+
85
+ // Validate domain.
86
+ if($request -> domain !== $fields -> domain)
87
+ throw new SwiftAPI_Exception('SwiftAPI::Decode(): Encoded domain does not match requested domain.');
88
+
89
+ // Return request.
90
+ return $request;
91
+ }
92
+
93
+
94
+ //////////////////
95
+ // Public: Query()
96
+ //////////////////
97
+
98
+ public static function Query(SwiftAPI_Request $request, $key)
99
+ {
100
+ return http_build_query(array
101
+ (
102
+ 'version' => $request -> version,
103
+ 'domain' => $request -> domain,
104
+ 'data' => SwiftAPI::Encode($request, $key)
105
+ ));
106
+ }
107
+
108
+
109
+ /////////////////
110
+ // Public: Link()
111
+ /////////////////
112
+
113
+ public static function Link(SwiftAPI_Request $request, $key, $content)
114
+ {
115
+ return '<a href="' . self::SWIFTAPI_CRM_URL . '?' . self::Query($request, $key) . '">' . $content . '</a>';
116
+ }
117
+
118
+
119
+ ///////////////////
120
+ // Public: Script()
121
+ ///////////////////
122
+
123
+ public static function Script($request, $key)
124
+ {
125
+ return '
126
+ <script language="javascript" type="text/javascript">
127
+ window.onload = function()
128
+ {
129
+ var query = "' . SwiftAPI::Query($request, $key) . '";
130
+ var http;
131
+
132
+ // IE7+, Firefox, Chrome, Opera, Safari.
133
+ if(window.XMLHttpRequest)
134
+ http=new XMLHttpRequest();
135
+
136
+ // IE6, IE5.
137
+ else
138
+ http=new ActiveXObject("Microsoft.XMLHTTP");
139
+
140
+ http.open("POST","'. self::SWIFTAPI_CRM_URL .'", true);
141
+
142
+ http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
143
+ http.setRequestHeader("Content-length", query.length);
144
+ http.setRequestHeader("Connection", "close");
145
+
146
+ http.onreadystatechange= function()
147
+ {
148
+ if (http.readyState==4 && http.status==200)
149
+ console.log("success");
150
+ }
151
+
152
+ http.send(query);
153
+ }
154
+ </script>';
155
+ }
156
+
157
+
158
+ ////////////////////////////////////
159
+ // Public: UserID()
160
+ ////////////////////////////////////
161
+ // Generate a random UUIDv4 user ID.
162
+ ////////////////////////////////////
163
+
164
+ public static function UserID()
165
+ {
166
+ return sprintf
167
+ (
168
+ '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
169
+ mt_rand(0, 0xffff),
170
+ mt_rand(0, 0xffff),
171
+ mt_rand(0, 0xffff),
172
+ mt_rand(0, 0x0fff) | 0x4000,
173
+ mt_rand(0, 0x3fff) | 0x8000,
174
+ mt_rand(0, 0xffff),
175
+ mt_rand(0, 0xffff),
176
+ mt_rand(0, 0xffff)
177
+ );
178
+ }
179
+
180
+ }
181
+
182
+ ?>
lib/SwiftAPI/SwiftAPI_Exception.php ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ class SwiftAPI_Exception extends Exception
4
+ {
5
+ }
6
+
7
+ ?>
lib/SwiftAPI/SwiftAPI_Product.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // Class: SwiftAPI_Product
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+
7
+
8
+ class SwiftAPI_Product
9
+ {
10
+
11
+ //////////////////////////////////////////////////////////////////////////////
12
+ // Public properties.
13
+ //////////////////////////////////////////////////////////////////////////////
14
+
15
+ public $product;
16
+ public $quantity;
17
+ public $price;
18
+
19
+
20
+ //////////////////////////////////////////////////////////////////////////////
21
+ // Public functions
22
+ //////////////////////////////////////////////////////////////////////////////
23
+
24
+ ////////////////////////
25
+ // Public: __construct()
26
+ ////////////////////////
27
+
28
+ public function __construct($product, $quantity, $price)
29
+ {
30
+ $this -> product = $product;
31
+ $this -> quantity = $quantity;
32
+ $this -> price = $price;
33
+ }
34
+
35
+ }
36
+
37
+ ?>
lib/SwiftAPI/SwiftAPI_Request.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // Class: SwiftAPI_Request
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+
7
+ require_once('SwiftAPI_Request_Home.php');
8
+ require_once('SwiftAPI_Request_Product.php');
9
+ require_once('SwiftAPI_Request_Cart.php');
10
+ require_once('SwiftAPI_Request_Order.php');
11
+ require_once('SwiftAPI_Request_PastOrder.php');
12
+ require_once('SwiftAPI_Request_Subscription.php');
13
+ require_once('SwiftAPI_Request_ViewMail.php');
14
+ require_once('SwiftAPI_Request_SendMail.php');
15
+
16
+
17
+ abstract class SwiftAPI_Request
18
+ {
19
+
20
+ //////////////////////////////////////////////////////////////////////////////
21
+ // Public properties.
22
+ //////////////////////////////////////////////////////////////////////////////
23
+
24
+ public $domain;
25
+ public $operation;
26
+ public $user;
27
+ public $version;
28
+ public $date;
29
+
30
+
31
+ //////////////////////////////////////////////////////////////////////////////
32
+ // Public functions.
33
+ //////////////////////////////////////////////////////////////////////////////
34
+
35
+ ////////////////////////
36
+ // Public: __construct()
37
+ ////////////////////////
38
+
39
+ public function __construct($domain, $operation, $user, $version = NULL, $date = NULL)
40
+ {
41
+ $this -> domain = $domain;
42
+ $this -> operation = $operation;
43
+ $this -> user = $user;
44
+ $this -> version = $version ? $version : SwiftAPI::VERSION;
45
+ $this -> date = $date ? $date : date_create() -> format('c');
46
+ }
47
+
48
+
49
+ ///////////////////
50
+ // Public: Create()
51
+ ///////////////////
52
+
53
+ public static function Create(stdClass $fields)
54
+ {
55
+ switch($fields -> operation)
56
+ {
57
+ case SwiftAPI::OPERATION_HOME:
58
+ return SwiftAPI_Request_Home::Create($fields);
59
+
60
+ case SwiftAPI::OPERATION_PRODUCT:
61
+ return SwiftAPI_Request_Product::Create($fields);
62
+
63
+ case SwiftAPI::OPERATION_CART:
64
+ return SwiftAPI_Request_Cart::Create($fields);
65
+
66
+ case SwiftAPI::OPERATION_ORDER:
67
+ return SwiftAPI_Request_Order::Create($fields);
68
+
69
+ case SwiftAPI::OPERATION_PASTORDER:
70
+ return SwiftAPI_Request_PastOrder::Create($fields);
71
+
72
+ case SwiftAPI::OPERATION_SUBSCRIPTION:
73
+ return SwiftAPI_Request_Subscription::Create($fields);
74
+
75
+ case SwiftAPI::OPERATION_VIEWMAIL:
76
+ return SwiftAPI_Request_ViewMail::Create($fields);
77
+
78
+ case SwiftAPI::OPERATION_SENDMAIL:
79
+ return SwiftAPI_Request_SendMail::Create($fields);
80
+ case SwiftAPI::OPERATION_UNSUBSCRIBE:
81
+ return SwiftAPI_Request_Unsubscribe::Create($fields);
82
+
83
+ default:
84
+ throw new SwiftAPI_Exception('SwiftAPI_Request::Create(): Invalid operation: "' . $fields -> operation . '".');
85
+ }
86
+ }
87
+
88
+
89
+ //////////////////////////////////////////////////////////////////////////////
90
+ // Protected functions.
91
+ //////////////////////////////////////////////////////////////////////////////
92
+
93
+ ////////////////////////
94
+ // Protected: Validate()
95
+ ////////////////////////
96
+
97
+ protected static function Validate(stdClass $fields)
98
+ {
99
+ // Check for domain field.
100
+ if(empty($fields -> domain))
101
+ throw new SwiftAPI_Exception('SwiftAPI_Request::Validate(): "domain" field is missing or empty.');
102
+
103
+ // Check for operation field.
104
+ if(empty($fields -> operation))
105
+ throw new SwiftAPI_Exception('SwiftAPI_Request::Validate(): "operation" field is missing or empty.');
106
+
107
+ // Check for user field.
108
+ if(empty($fields -> user))
109
+ throw new SwiftAPI_Exception('SwiftAPI_Request::Validate(): "user" field is missing or empty.');
110
+
111
+ // Check for version field.
112
+ if(empty($fields -> version))
113
+ throw new SwiftAPI_Exception('SwiftAPI_Request::Validate(): "version" field is missing or empty.');
114
+
115
+ // Check for date field.
116
+ if(empty($fields -> date))
117
+ throw new SwiftAPI_Exception('SwiftAPI_Request::Validate(): "date" field is missing or empty.');
118
+ }
119
+
120
+ }
121
+
122
+ ?>
lib/SwiftAPI/SwiftAPI_Request_Cart.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // Class: SwiftAPI_Request_Cart
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+
7
+
8
+ class SwiftAPI_Request_Cart extends SwiftAPI_Request
9
+ {
10
+
11
+ //////////////////////////////////////////////////////////////////////////////
12
+ // Public properties.
13
+ //////////////////////////////////////////////////////////////////////////////
14
+
15
+ public $products;
16
+ public $email;
17
+
18
+
19
+ //////////////////////////////////////////////////////////////////////////////
20
+ // Public functions
21
+ //////////////////////////////////////////////////////////////////////////////
22
+
23
+ ////////////////////////
24
+ // Public: __construct()
25
+ ////////////////////////
26
+
27
+ public function __construct($domain, $user, array $products, $email = NULL, $version = NULL, $date = NULL)
28
+ {
29
+ $this -> products = $products;
30
+ $this -> email = $email;
31
+
32
+ parent::__construct($domain, SwiftAPI::OPERATION_CART, $user, $version, $date);
33
+ }
34
+
35
+
36
+ ///////////////////
37
+ // Public: Create()
38
+ ///////////////////
39
+
40
+ public static function Create(stdClass $fields)
41
+ {
42
+ parent::Validate($fields);
43
+
44
+ if(empty($fields -> products))
45
+ throw new SwiftAPI_Exception('SwiftAPI_Request_Cart::Create(): "products" field is missing or empty.');
46
+
47
+ if(!is_array($fields -> products))
48
+ throw new SwiftAPI_Exception('SwiftAPI_Request_Cart::Create(): "products" field is not an array.');
49
+
50
+ return new self
51
+ (
52
+ $fields -> domain,
53
+ $fields -> user,
54
+ $fields -> products,
55
+ empty($fields -> email) ? NULL : $fields -> email,
56
+ $fields -> version,
57
+ $fields -> date
58
+ );
59
+ }
60
+ }
61
+
62
+ ?>
lib/SwiftAPI/SwiftAPI_Request_Home.php ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // Class: SwiftAPI_Request_Home
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+
7
+
8
+ class SwiftAPI_Request_Home extends SwiftAPI_Request
9
+ {
10
+
11
+ //////////////////////////////////////////////////////////////////////////////
12
+ // Public properties.
13
+ //////////////////////////////////////////////////////////////////////////////
14
+
15
+ public $url;
16
+ public $email;
17
+
18
+
19
+ //////////////////////////////////////////////////////////////////////////////
20
+ // Public functions
21
+ //////////////////////////////////////////////////////////////////////////////
22
+
23
+ ////////////////////////
24
+ // Public: __construct()
25
+ ////////////////////////
26
+
27
+ public function __construct($domain, $user, $url, $email = NULL, $version = NULL, $date = NULL)
28
+ {
29
+ $this -> url = $url;
30
+ $this -> email = $email;
31
+
32
+ parent::__construct($domain, SwiftAPI::OPERATION_HOME, $user, $version, $date);
33
+ }
34
+
35
+ ///////////////////
36
+ // Public: Create()
37
+ ///////////////////
38
+
39
+ public static function Create(stdClass $fields)
40
+ {
41
+ parent::Validate($fields);
42
+
43
+ if(empty($fields -> url))
44
+ throw new SwiftAPI_Exception('SwiftAPI_Request_Home::Create(): "url" field is missing or empty.');
45
+
46
+ return new self
47
+ (
48
+ $fields -> domain,
49
+ $fields -> user,
50
+ $fields -> url,
51
+ empty($fields -> email) ? NULL : $fields -> email,
52
+ $fields -> version,
53
+ $fields -> date
54
+ );
55
+ }
56
+ }
57
+
58
+ ?>
lib/SwiftAPI/SwiftAPI_Request_Order.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // Class: SwiftAPI_Request_Order
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+
7
+
8
+ class SwiftAPI_Request_Order extends SwiftAPI_Request
9
+ {
10
+
11
+ //////////////////////////////////////////////////////////////////////////////
12
+ // Public properties.
13
+ //////////////////////////////////////////////////////////////////////////////
14
+
15
+ public $email;
16
+ public $forename;
17
+ public $surname;
18
+ public $products;
19
+
20
+
21
+ //////////////////////////////////////////////////////////////////////////////
22
+ // Public functions
23
+ //////////////////////////////////////////////////////////////////////////////
24
+
25
+ ////////////////////////
26
+ // Public: __construct()
27
+ ////////////////////////
28
+
29
+ public function __construct($domain, $user, $email, $forename, $surname, array $products, $version = NULL, $date = NULL)
30
+ {
31
+ $this -> email = $email;
32
+ $this -> forename = $forename;
33
+ $this -> surname = $surname;
34
+ $this -> products = $products;
35
+
36
+ parent::__construct($domain, SwiftAPI::OPERATION_ORDER, $user, $version, $date);
37
+ }
38
+
39
+
40
+ ///////////////////
41
+ // Public: Create()
42
+ ///////////////////
43
+
44
+ public static function Create(stdClass $fields)
45
+ {
46
+ parent::Validate($fields);
47
+
48
+ if(empty($fields -> email))
49
+ throw new SwiftAPI_Exception('SwiftAPI_Request_Order::Create(): "email" field is missing or empty.');
50
+
51
+ if(empty($fields -> forename))
52
+ throw new SwiftAPI_Exception('SwiftAPI_Request_Order::Create(): "forename" field is missing or empty.');
53
+
54
+ if(empty($fields -> surname))
55
+ throw new SwiftAPI_Exception('SwiftAPI_Request_Order::Create(): "surname" field is missing or empty.');
56
+
57
+ if(empty($fields -> products))
58
+ throw new SwiftAPI_Exception('SwiftAPI_Request_Order::Create(): "products" field is missing or empty.');
59
+
60
+ if(!is_array($fields -> products))
61
+ throw new SwiftAPI_Exception('SwiftAPI_Request_Order::Create(): "products" field is not an array.');
62
+
63
+ return new self
64
+ (
65
+ $fields -> domain,
66
+ $fields -> user,
67
+ $fields -> email,
68
+ $fields -> forename,
69
+ $fields -> surname,
70
+ $fields -> products,
71
+ $fields -> version,
72
+ $fields -> date
73
+ );
74
+ }
75
+ }
76
+
77
+ ?>
lib/SwiftAPI/SwiftAPI_Request_PastOrder.php ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // Class: SwiftAPI_Request_PastOrder
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+
7
+
8
+ class SwiftAPI_Request_PastOrder extends SwiftAPI_Request
9
+ {
10
+
11
+ //////////////////////////////////////////////////////////////////////////////
12
+ // Public properties.
13
+ //////////////////////////////////////////////////////////////////////////////
14
+
15
+ public $email;
16
+ public $forename;
17
+ public $surname;
18
+ public $products;
19
+
20
+
21
+ //////////////////////////////////////////////////////////////////////////////
22
+ // Public functions
23
+ //////////////////////////////////////////////////////////////////////////////
24
+
25
+ ////////////////////////
26
+ // Public: __construct()
27
+ ////////////////////////
28
+
29
+ public function __construct($domain, $user, $email, $forename, $surname, array $products, $version = NULL, $date = NULL)
30
+ {
31
+ $this -> email = $email;
32
+ $this -> forename = $forename;
33
+ $this -> surname = $surname;
34
+ $this -> products = $products;
35
+
36
+ parent::__construct($domain, SwiftAPI::OPERATION_PASTORDER, $user, $version, $date);
37
+ }
38
+
39
+
40
+ ///////////////////
41
+ // Public: Create()
42
+ ///////////////////
43
+
44
+ public static function Create(stdClass $fields)
45
+ {
46
+ parent::Validate($fields);
47
+
48
+ if(empty($fields -> email))
49
+ throw new SwiftAPI_Exception('SwiftAPI_Request_PastOrder::Create(): "email" field is missing or empty.');
50
+
51
+ if(empty($fields -> forename))
52
+ throw new SwiftAPI_Exception('SwiftAPI_Request_PastOrder::Create(): "forename" field is missing or empty.');
53
+
54
+ if(empty($fields -> surname))
55
+ throw new SwiftAPI_Exception('SwiftAPI_Request_PastOrder::Create(): "surname" field is missing or empty.');
56
+
57
+ if(empty($fields -> products))
58
+ throw new SwiftAPI_Exception('SwiftAPI_Request_PastOrder::Create(): "products" field is missing or empty.');
59
+
60
+ if(!is_array($fields -> products))
61
+ throw new SwiftAPI_Exception('SwiftAPI_Request_PastOrder::Create(): "products" field is not an array.');
62
+
63
+ return new self
64
+ (
65
+ $fields -> domain,
66
+ $fields -> user,
67
+ $fields -> email,
68
+ $fields -> forename,
69
+ $fields -> surname,
70
+ $fields -> products,
71
+ $fields -> version,
72
+ $fields -> date
73
+ );
74
+ }
75
+ }
76
+
77
+ ?>
lib/SwiftAPI/SwiftAPI_Request_Product.php ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // Class: SwiftAPI_Request_Product
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+
7
+
8
+ class SwiftAPI_Request_Product extends SwiftAPI_Request
9
+ {
10
+
11
+ //////////////////////////////////////////////////////////////////////////////
12
+ // Public properties.
13
+ //////////////////////////////////////////////////////////////////////////////
14
+
15
+ public $product;
16
+ public $email;
17
+
18
+
19
+ //////////////////////////////////////////////////////////////////////////////
20
+ // Public functions
21
+ //////////////////////////////////////////////////////////////////////////////
22
+
23
+ ////////////////////////
24
+ // Public: __construct()
25
+ ////////////////////////
26
+
27
+ public function __construct($domain, $user, $product, $email = NULL, $version = NULL, $date = NULL)
28
+ {
29
+ $this -> product = $product;
30
+ $this -> email = $email;
31
+
32
+ parent::__construct($domain, SwiftAPI::OPERATION_PRODUCT, $user, $version, $date);
33
+ }
34
+
35
+
36
+ ///////////////////
37
+ // Public: Create()
38
+ ///////////////////
39
+
40
+ public static function Create(stdClass $fields)
41
+ {
42
+ parent::Validate($fields);
43
+
44
+ if(empty($fields -> product))
45
+ throw new SwiftAPI_Exception('SwiftAPI_Request_Product::Create(): "product" field is missing or empty.');
46
+
47
+ return new self
48
+ (
49
+ $fields -> domain,
50
+ $fields -> user,
51
+ $fields -> product,
52
+ empty($fields -> email) ? NULL : $fields -> email,
53
+ $fields -> version,
54
+ $fields -> date
55
+ );
56
+ }
57
+ }
58
+
59
+ ?>
lib/SwiftAPI/SwiftAPI_Request_SendMail.php ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // Class: SwiftAPI_Request_SendMail
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+
7
+
8
+ class SwiftAPI_Request_SendMail extends SwiftAPI_Request
9
+ {
10
+
11
+ //////////////////////////////////////////////////////////////////////////////
12
+ // Public properties.
13
+ //////////////////////////////////////////////////////////////////////////////
14
+
15
+ public $email;
16
+ public $subject;
17
+ public $body;
18
+ public $monitor;
19
+
20
+
21
+ //////////////////////////////////////////////////////////////////////////////
22
+ // Public functions
23
+ //////////////////////////////////////////////////////////////////////////////
24
+
25
+ ////////////////////////
26
+ // Public: __construct()
27
+ ////////////////////////
28
+
29
+ public function __construct($domain, $user, $email, $subject, $body, $version = NULL, $date = NULL, $monitor = null)
30
+ {
31
+ $this -> email = $email;
32
+ $this -> subject = $subject;
33
+ $this -> body = $body;
34
+ $this->monitor = $monitor;
35
+ parent::__construct($domain, SwiftAPI::OPERATION_SENDMAIL, $user, $version, $date);
36
+ }
37
+
38
+
39
+ ///////////////////
40
+ // Public: Create()
41
+ ///////////////////
42
+
43
+ public static function Create(stdClass $fields)
44
+ {
45
+ parent::Validate($fields);
46
+
47
+ if(empty($fields -> email))
48
+ throw new SwiftAPI_Exception('SwiftAPI_Request_SendMail::Create(): "email" field is missing or empty.');
49
+
50
+ if(empty($fields -> subject))
51
+ throw new SwiftAPI_Exception('SwiftAPI_Request_SendMail::Create(): "subject" field is missing or empty.');
52
+
53
+ if(empty($fields -> body))
54
+ throw new SwiftAPI_Exception('SwiftAPI_Request_SendMail::Create(): "body" field is missing or empty.');
55
+
56
+ return new self
57
+ (
58
+ $fields -> domain,
59
+ $fields -> user,
60
+ $fields -> email,
61
+ $fields -> subject,
62
+ $fields -> body,
63
+ $fields -> version,
64
+ $fields -> date,
65
+ $fields -> monitor
66
+ );
67
+ }
68
+ }
69
+
70
+ ?>
lib/SwiftAPI/SwiftAPI_Request_Subscription.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // Class: SwiftAPI_Request_Subscription
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+
7
+
8
+ class SwiftAPI_Request_Subscription extends SwiftAPI_Request
9
+ {
10
+
11
+ //////////////////////////////////////////////////////////////////////////////
12
+ // Public properties.
13
+ //////////////////////////////////////////////////////////////////////////////
14
+
15
+ public $email;
16
+
17
+
18
+ //////////////////////////////////////////////////////////////////////////////
19
+ // Public functions
20
+ //////////////////////////////////////////////////////////////////////////////
21
+
22
+ ////////////////////////
23
+ // Public: __construct()
24
+ ////////////////////////
25
+
26
+ public function __construct($domain, $user, $email, $version = NULL, $date = NULL)
27
+ {
28
+ $this -> email = $email;
29
+
30
+ parent::__construct($domain, SwiftAPI::OPERATION_SUBSCRIPTION, $user, $version, $date);
31
+ }
32
+
33
+
34
+ ///////////////////
35
+ // Public: Create()
36
+ ///////////////////
37
+
38
+ public static function Create(stdClass $fields)
39
+ {
40
+ parent::Validate($fields);
41
+
42
+ if(empty($fields -> email))
43
+ throw new SwiftAPI_Exception('SwiftAPI_Request_Subscription::Create(): "email" field is missing or empty.');
44
+
45
+ return new self
46
+ (
47
+ $fields -> domain,
48
+ $fields -> user,
49
+ $fields -> email,
50
+ $fields -> version,
51
+ $fields -> date
52
+ );
53
+ }
54
+ }
55
+
56
+ ?>
lib/SwiftAPI/SwiftAPI_Request_Unsubscribe.php ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // Class: SwiftAPI_Request_Unsubscribe
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+
7
+
8
+ class SwiftAPI_Request_Unsubscribe extends SwiftAPI_Request
9
+ {
10
+
11
+ //////////////////////////////////////////////////////////////////////////////
12
+ // Public properties.
13
+ //////////////////////////////////////////////////////////////////////////////
14
+
15
+ public $email;
16
+
17
+
18
+ //////////////////////////////////////////////////////////////////////////////
19
+ // Public functions
20
+ //////////////////////////////////////////////////////////////////////////////
21
+
22
+ ////////////////////////
23
+ // Public: __construct()
24
+ ////////////////////////
25
+
26
+ public function __construct($domain, $user, $email, $version = NULL, $date = NULL)
27
+ {
28
+ $this -> email = $email;
29
+
30
+ parent::__construct($domain, SwiftAPI::OPERATION_UNSUBSCRIBE, $user, $version, $date);
31
+ }
32
+
33
+
34
+ ///////////////////
35
+ // Public: Create()
36
+ ///////////////////
37
+
38
+ public static function Create(stdClass $fields)
39
+ {
40
+ parent::Validate($fields);
41
+
42
+ if(empty($fields -> email))
43
+ throw new SwiftAPI_Exception('SwiftAPI_Request_Unsubscribe::Create(): "email" field is missing or empty.');
44
+
45
+ return new self
46
+ (
47
+ $fields -> domain,
48
+ $fields -> user,
49
+ $fields -> email,
50
+ $fields -> version,
51
+ $fields -> date
52
+ );
53
+ }
54
+ }
55
+
56
+ ?>
lib/SwiftAPI/SwiftAPI_Request_ViewMail.php ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // Class: SwiftAPI_Request_ViewMail
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+
7
+
8
+ class SwiftAPI_Request_ViewMail extends SwiftAPI_Request
9
+ {
10
+
11
+ //////////////////////////////////////////////////////////////////////////////
12
+ // Public properties.
13
+ //////////////////////////////////////////////////////////////////////////////
14
+
15
+ public $email;
16
+ public $product;
17
+
18
+
19
+ //////////////////////////////////////////////////////////////////////////////
20
+ // Public functions
21
+ //////////////////////////////////////////////////////////////////////////////
22
+
23
+ ////////////////////////
24
+ // Public: __construct()
25
+ ////////////////////////
26
+
27
+ public function __construct($domain, $user, $email, $product, $version = NULL, $date = NULL)
28
+ {
29
+ $this -> email = $email;
30
+ $this -> product = $product;
31
+
32
+ parent::__construct($domain, SwiftAPI::OPERATION_VIEWMAIL, $user, $version, $date);
33
+ }
34
+
35
+
36
+ ///////////////////
37
+ // Public: Create()
38
+ ///////////////////
39
+
40
+ public static function Create(stdClass $fields)
41
+ {
42
+ parent::Validate($fields);
43
+
44
+ if(empty($fields -> email))
45
+ throw new SwiftAPI_Exception('SwiftAPI_Request_ViewMail::Create(): "email" field is missing or empty.');
46
+
47
+ if(empty($fields -> product))
48
+ throw new SwiftAPI_Exception('SwiftAPI_Request_ViewMail::Create(): "product" field is missing or empty.');
49
+
50
+ return new self
51
+ (
52
+ $fields -> domain,
53
+ $fields -> user,
54
+ $fields -> email,
55
+ $fields -> product,
56
+ $fields -> version,
57
+ $fields -> date
58
+ );
59
+ }
60
+ }
61
+
62
+ ?>
lib/SwiftAPI/doc/SwiftAPI-Specification.html ADDED
@@ -0,0 +1,250 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+
3
+ <head>
4
+ <title>SwiftAPI Specification</title>
5
+
6
+ <style>
7
+ body
8
+ {
9
+ font-family: sans-serif;
10
+ color: #333;
11
+ }
12
+
13
+ table
14
+ {
15
+ border-collapse: collapse;
16
+ }
17
+
18
+ thead
19
+ {
20
+ background-color: LightSteelBlue;
21
+ border-bottom: 3px double Gray;
22
+ }
23
+
24
+ td, th
25
+ {
26
+ border:1px solid Gray;
27
+ padding: 0.2em;
28
+ }
29
+ </style>
30
+
31
+ </head>
32
+
33
+ <body>
34
+
35
+ <h1>SwiftAPI Specification</h1>
36
+
37
+ <h2>Version</h2>
38
+ <p>2</p>
39
+
40
+ <h2>Overview</h2>
41
+ <p>This document details the operations, transfer method, fields, and encryption scheme used to implement the SwiftAPI.</p>
42
+
43
+ <h2 id="Operations">Operations</h2>
44
+ <table>
45
+ <thead>
46
+ <tr>
47
+ <th>Operation</th>
48
+ <th>Description</th>
49
+ </tr>
50
+ </thead>
51
+ <tbody>
52
+ <tr>
53
+ <td>home</td>
54
+ <td>A user visits the website's homepage.</td>
55
+ </tr>
56
+ <tr>
57
+ <td>product</td>
58
+ <td>A user visits a product details page - a page that lists all information about a single product.</td>
59
+ </tr>
60
+ <tr>
61
+ <td>cart</td>
62
+ <td>A user adds products to the shopping cart.</td>
63
+ </tr>
64
+ <tr>
65
+ <td>order</td>
66
+ <td>A user successfully places an order on the website.</td>
67
+ </tr>
68
+ <tr>
69
+ <td>pastorder</td>
70
+ <td>When a client first sets up the plugin on their website it will send all historical order data to the Swift system, unless the client decides to opt out.</td>
71
+ </tr>
72
+ <tr>
73
+ <td>subscription</td>
74
+ <td>A user submits their email address to join a newsletter using Magento's standard newsletter subscription feature.</td>
75
+ </tr>
76
+ <tr>
77
+ <td>viewmail</td>
78
+ <td>A user accesses the website via a link in one of the Swift system's emails.</td>
79
+ </tr>
80
+ <tr>
81
+ <td>sendmail</td>
82
+ <td>The Swift system has generated an email to be sent by a clients site.</td>
83
+ </tr>
84
+ <tr>
85
+ <td>unsubscribe</td>
86
+ <td>A user unsubscribes from the Swift system.</td>
87
+ </tr>
88
+ </tbody>
89
+ </table>
90
+
91
+ <h2>Transfer Method</h2>
92
+ <p>Requests to the API will be send via <strong>HTTPS POST</strong>.</p>
93
+
94
+ <h2>POST Format</h2>
95
+ <table>
96
+ <thead>
97
+ <tr>
98
+ <th>Key</th>
99
+ <th>Data Type</th>
100
+ <th>Description</th>
101
+ </tr>
102
+ </thead>
103
+ <tbody>
104
+ <tr>
105
+ <td>version</td>
106
+ <td>Integer</td>
107
+ <td>The API version number.</td>
108
+ </tr>
109
+ <tr>
110
+ <td>domain</td>
111
+ <td>String</td>
112
+ <td>The domain name of the SwiftCRM clients site.</td>
113
+ </tr>
114
+ <tr>
115
+ <td>data</td>
116
+ <td>String</td>
117
+ <td>A <strong>base64</strong> encoded string containing an <strong>AES-256</strong> initialization vector followed by a <strong>AES-256</strong> encrypted <strong>JSON</strong> object comprised of the <a href="#DataFields">Data Fields</a> listed below.</td>
118
+ </tr>
119
+ </tbody>
120
+ </table>
121
+
122
+ <h2 id="DataFields">Data Fields</h2>
123
+ <table>
124
+ <thead>
125
+ <tr>
126
+ <th>Field</th>
127
+ <th>Data Type</th>
128
+ <th>Required for Operations</th>
129
+ <th>Optional for Operations</th>
130
+ <th>Description</th>
131
+ </tr>
132
+ </thead>
133
+ <tbody>
134
+ <tr>
135
+ <td>domain</td>
136
+ <td>String</td>
137
+ <td>ALL</td>
138
+ <td></td>
139
+ <td>The domain name of the SwiftCRM clients site. (This is required to be duplicated in the data section to prevent forged requests.)</td>
140
+ </tr>
141
+ <tr>
142
+ <td>date</td>
143
+ <td>String - <a href="http://en.wikipedia.org/wiki/ISO_8601">ISO 8601 Date</a></td>
144
+ <td>ALL</td>
145
+ <td></td>
146
+ <td>An ISO Date when the request was generated in the format YYYY-MM-DDThh:mm e.g. 2007-04-05T14:30</td>
147
+ </tr>
148
+ <tr>
149
+ <td>operation</td>
150
+ <td>String - <a href="#Operations">SwiftAPI Operation ID</a></td>
151
+ <td>ALL</td>
152
+ <td></td>
153
+ <td>One of the <a href="#Operations">SwiftAPI operation ID's</a></td>
154
+ </tr>
155
+ <tr>
156
+ <td>user</td>
157
+ <td>String - <a href="http://en.wikipedia.org/wiki/Universally_unique_identifier">UUID</a></td>
158
+ <td>ALL</td>
159
+ <td></td>
160
+ <td>A universally unique identifier generated by the SwiftCRM client site/plugin used to identify a user over the duration of their visit to a site.</td>
161
+ </tr>
162
+ <tr>
163
+ <td>url</td>
164
+ <td>String</td>
165
+ <td>home</td>
166
+ <td></td>
167
+ <td>The URL of the page where the API request was triggered.</td>
168
+ </tr>
169
+ <tr>
170
+ <td>email</td>
171
+ <td>String</td>
172
+ <td>order, pastorder, subscription, viewmail, sendmail, unsubscribe</td>
173
+ <td>home, product, cart</td>
174
+ <td>The users email address.</td>
175
+ </tr>
176
+ <tr>
177
+ <td>forename</td>
178
+ <td>String</td>
179
+ <td>order, pastorder</td>
180
+ <td></td>
181
+ <td>The users forename.</td>
182
+ </tr>
183
+ <tr>
184
+ <td>surname</td>
185
+ <td>String</td>
186
+ <td>order, pastorder</td>
187
+ <td></td>
188
+ <td>The users surname.</td>
189
+ <tr>
190
+ <td>product</td>
191
+ <td>String</td>
192
+ <td>product, viewmail</td>
193
+ <td></td>
194
+ <td>A site specific product identifier (Should correspond to ID's provided in the sites 'product XML file').</td>
195
+ </tr>
196
+ <tr>
197
+ <td>products</td>
198
+ <td>Array</td>
199
+ <td>cart, order, pastorder</td>
200
+ <td></td>
201
+ <td>An array of JSON objects containing <a href="#ProductFields">Product Fields</a>.</td>
202
+ </tr>
203
+ <tr>
204
+ <td>subject</td>
205
+ <td>String</td>
206
+ <td>sendmail</td>
207
+ <td></td>
208
+ <td>Message subject for a swift email.</td>
209
+ </tr>
210
+ <tr>
211
+ <td>body</td>
212
+ <td>String</td>
213
+ <td>sendmail</td>
214
+ <td></td>
215
+ <td>Message content for a swift email.</td>
216
+ </tr>
217
+ </tbody>
218
+ </table>
219
+
220
+ <h2 id="ProductFields">Product Fields</h2>
221
+ <table>
222
+ <thead>
223
+ <tr>
224
+ <th>Field</th>
225
+ <th>Data Type</th>
226
+ <th>Description</th>
227
+ </tr>
228
+ </thead>
229
+ <tbody>
230
+ <tr>
231
+ <td>product</td>
232
+ <td>String</td>
233
+ <td>A site specific product identifier (Should correspond to ID's provided in the sites 'product XML file').</td>
234
+ </tr>
235
+ <tr>
236
+ <td>quantity</td>
237
+ <td>Integer</td>
238
+ <td>The number of products in the order.</td>
239
+ </tr>
240
+ <tr>
241
+ <td>price</td>
242
+ <td>String</td>
243
+ <td>The product price (May potentially differ from the value specified in the sites 'product XML file').</td>
244
+ </tr>
245
+ </tbody>
246
+ </table>
247
+
248
+ </body>
249
+
250
+ </html>
lib/SwiftAPI/index.php ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?
2
+
3
+ require_once('SwiftAPI.php');
4
+
5
+ session_start();
6
+
7
+
8
+ if(!isset($_SESSION['swiftuser']) || empty($_SESSION['swiftuser']))
9
+ $_SESSION['swiftuser'] = SwiftAPI::UserID();
10
+
11
+ $key = '8ca0KOynGlxFpX7CVHNuzO7yNGdO1bl7';
12
+ $version = '1';
13
+ $domain = 'netready.biz';
14
+ $user = $_SESSION['swiftuser'];
15
+ $date = date(DATE_ISO8601, time());
16
+ $operation = isset($_POST['operation']) ? $_POST['operation'] : NULL;
17
+ $url = $_SERVER['REQUEST_URI'];
18
+ $email = 'wayne@netready.biz';
19
+ $forename = 'Wayne';
20
+ $surname = 'Hemsley';
21
+ $product = 'test_product_1';
22
+ $quantity = '1';
23
+ $price = '1.00';
24
+ $subject = 'SwiftCRM Test Email';
25
+ $body = 'SwiftCRM Test Email';
26
+ $products = array
27
+ (
28
+ new SwiftAPI_Product('test_product_1', 1, 10),
29
+ new SwiftAPI_Product('test_product_2', 2, 20),
30
+ new SwiftAPI_Product('test_product_3', 3, 30)
31
+ );
32
+
33
+ switch($operation)
34
+ {
35
+ // done
36
+ case SwiftAPI::OPERATION_HOME:
37
+ $request = new SwiftAPI_Request_Home($domain, $user, $url);
38
+ break;
39
+
40
+ // done
41
+ case SwiftAPI::OPERATION_PRODUCT:
42
+ $request = new SwiftAPI_Request_Product($domain, $user, $product);
43
+ break;
44
+
45
+ //done? the api spec has changed but swift api request is still referncing old data
46
+ case SwiftAPI::OPERATION_CART:
47
+ $request = new SwiftAPI_Request_Cart($domain, $user, $products);
48
+ break;
49
+
50
+ // done
51
+ case SwiftAPI::OPERATION_ORDER:
52
+ $request = new SwiftAPI_Request_Order($domain, $user, $email, $forename, $surname, $products);
53
+ break;
54
+
55
+ // yet to be done
56
+ case SwiftAPI::OPERATION_PASTORDER:
57
+ $request = new SwiftAPI_Request_PastOrder($domain, $user, $email, $forename, $surname, $products);
58
+ break;
59
+
60
+ // done
61
+ case SwiftAPI::OPERATION_SUBSCRIPTION:
62
+ $request = new SwiftAPI_Request_Subscription($domain, $user, $email);
63
+ break;
64
+
65
+ // havent done an operation to check for that yet
66
+ case SwiftAPI::OPERATION_VIEWMAIL:
67
+ $request = new SwiftAPI_Request_ViewMail($domain, $user, $product);
68
+ break;
69
+
70
+ // havent done an operation to check for that yet
71
+ case SwiftAPI::OPERATION_SENDMAIL:
72
+ $request = new SwiftAPI_Request_SendMail($domain, $user, $email, $subject, $body);
73
+ break;
74
+
75
+ default:
76
+ $request = NULL;
77
+ }
78
+
79
+
80
+ $content[] = <<<HTML
81
+ <!DOCTYPE html>
82
+ <html>
83
+ <head>
84
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
85
+ <title></title>
86
+ </head>
87
+ <body>
88
+ <form action="/index.php" method="post">
89
+ <label>product<input type="radio" id="cobTransferType1" name="operation" value="product"/></label><br />
90
+ <label>home<input type="radio" id="cobTransferType2" name="operation" value="home"/></label><br />
91
+ <label>cart<input type="radio" id="cobTransferType3" name="operation" value="cart"/></label><br />
92
+ <label>order<input type="radio" id="cobTransferType4" name="operation" value="order"/></label><br />
93
+ <label>pastorder<input type="radio" id="cobTransferType5" name="operation" value="pastorder"/></label><br />
94
+ <label>subscription<input type="radio" id="cobTransferType6" name="operation" value="subscription"/></label><br />
95
+ <label>viewmail<input type="radio" id="cobTransferType7" name="operation" value="viewmail"/></label><br />
96
+ <label>sendmail<input type="radio" id="cobTransferType7" name="operation" value="sendmail"/></label><br />
97
+ <input type="submit"/>
98
+ </form>
99
+ <p id="Result"></p>
100
+ HTML;
101
+
102
+ if($request)
103
+ $content[] = '
104
+ <script language="javascript" type="text/javascript">
105
+ window.onload = function()
106
+ {
107
+ var query = "' . SwiftAPI::Query($request, $key) . '";
108
+ var http;
109
+
110
+ // IE7+, Firefox, Chrome, Opera, Safari.
111
+ if(window.XMLHttpRequest)
112
+ http=new XMLHttpRequest();
113
+
114
+ // IE6, IE5.
115
+ else
116
+ http=new ActiveXObject("Microsoft.XMLHTTP");
117
+
118
+ http.onload = function(e)
119
+ {
120
+ document.getElementById("Result").innerHTML = this.responseText;
121
+ }
122
+
123
+ http.open("POST","http://swiftcrm.wayne.netready.lan", true);
124
+
125
+ http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
126
+ http.setRequestHeader("Content-length", query.length);
127
+ http.setRequestHeader("Connection", "close");
128
+
129
+ http.onreadystatechange= function()
130
+ {
131
+ if (http.readyState==4 && http.status==200)
132
+ console.log("success");
133
+ }
134
+
135
+ http.send(query);
136
+ }
137
+ </script>';
138
+
139
+ $content[] = <<<HTML
140
+ </body>
141
+ </html>
142
+ HTML;
143
+
144
+ echo implode($content);
lib/SwiftAPI/php.ini ADDED
@@ -0,0 +1,3 @@
 
 
 
1
+ zend_extension="/opt/php55/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
2
+ date.timezone=Europe/London
3
+ xdebug.profiler_enable_trigger=1
lib/libXML/xml.php ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ ////////////////////////////////////////////////////////////////////////////////
4
+ // Class: xml
5
+ ////////////////////////////////////////////////////////////////////////////////
6
+ // Class for quickly generating xml tags
7
+ ////////////////////////////////////////////////////////////////////////////////
8
+ // Examples:
9
+ //// xml::br(); - Empty <br /> tag.
10
+ //// xml::p('hello') - Paragraph with content
11
+ //// xml::a('click here', array('href' => '/home')) - Anchor with href attribute
12
+ ////////////////////////////////////////////////////////////////////////////////
13
+
14
+ class xml
15
+ {
16
+
17
+ //////////////////////////////////////////////////////////////////////////////
18
+ // Public methods
19
+ //////////////////////////////////////////////////////////////////////////////
20
+
21
+ /////////////////////////
22
+ // Public: __callStatic()
23
+ /////////////////////////
24
+
25
+ public static function __callStatic($name, array $args = NULL)
26
+ {
27
+ return self::createElement($name, array_shift($args), array_shift($args));
28
+ }
29
+
30
+
31
+ //////////////////////////////////////////////////////////////////////////////
32
+ // Private methods
33
+ //////////////////////////////////////////////////////////////////////////////
34
+
35
+ ///////////////////////////
36
+ // Private: createElement()
37
+ ///////////////////////////
38
+
39
+ private static function createElement($name, $content = NULL, $attributes = NULL)
40
+ {
41
+ $xml = '<' . $name;
42
+
43
+ if($attributes)
44
+ {
45
+ if(!is_array($attributes))
46
+ throw new xmlException('xml::createElement() expected array for \'$attributes\' parameter, ' . gettype($attributes) . ' given.');
47
+
48
+ foreach($attributes as $attrName => $attrValue)
49
+ $xml .= ' ' . $attrName . '="' . $attrValue . '"';
50
+ }
51
+
52
+ if(isset($content))
53
+ $xml .= '>' . (is_array($content) ? implode($content) : $content) . '</' . $name . '>';
54
+ else
55
+ $xml .= ' />';
56
+
57
+ return $xml;
58
+ }
59
+
60
+ }
61
+
62
+
63
+ ////////////////////////////////////////////////////////////////////////////////
64
+ // Exceptions
65
+ ////////////////////////////////////////////////////////////////////////////////
66
+
67
+ class xmlException extends Exception{}
68
+
69
+ ?>
package.xml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>Swift_Swiftplugin</name>
4
+ <version>1.1.8</version>
5
+ <stability>stable</stability>
6
+ <license uri="http://opensource.org/licenses/LGPL-3.0">LGPL</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>Uses the SwiftCRM marketing service to send customers emails based on their shopping history and purchases.</summary>
10
+ <description>&lt;h1&gt;SwiftCRM enables your site to personalise product selection in emails, so every email is unique to each end consumer&lt;/h1&gt;&#xD;
11
+ &#xD;
12
+ &lt;p&gt;&#xD;
13
+ The extension captures customers shopping habits and their past orders so that it can use the swiftcrm.net service to send personalised emails to your customers. These emails promote the products on your store, giving priority to those products that are most relevant to the customer.&#xD;
14
+ &lt;/p&gt;&#xD;
15
+ &lt;p&gt;&#xD;
16
+ The extension uses background JavaScript calls to collect and store the customer&#x2019;s shopping habits, without impeding the customer&#x2019;s experience on your site.&#xD;
17
+ &lt;/p&gt;&#xD;
18
+ &lt;p&gt;&#xD;
19
+ The extension is easy to set up and uses Magento&#x2019;s built in features to collect information and send emails to the customers. Visit swiftcrm.net for prices and free trails.&#xD;
20
+ &lt;/p&gt;</description>
21
+ <notes>SwiftPlugin works over http and https</notes>
22
+ <authors><author><name>Simon Cooper</name><user>Netready</user><email>simon@netready.biz</email></author></authors>
23
+ <date>2015-02-17</date>
24
+ <time>10:18:43</time>
25
+ <contents><target name="magelib"><dir name="libXML"><file name="xml.php" hash="fc4d7c79c7b7ea2ac75f28c008cde8eb"/></dir><dir name="SwiftAPI"><file name="SwiftAPI.php" hash="69d2544d19ff2fa099acf8d45b980abd"/><file name="SwiftAPI_Exception.php" hash="879b899a7961f4de1212b7296ccafb16"/><file name="SwiftAPI_Product.php" hash="063922cccb485d81c6022de5c4e8e044"/><file name="SwiftAPI_Request.php" hash="5c80deaeca64897ca886d3e08dd2cc27"/><file name="SwiftAPI_Request_Cart.php" hash="f8955c78200ddb0512adb5214fd64bb2"/><file name="SwiftAPI_Request_Home.php" hash="9268da121dd10db50d5c2675afd1c65e"/><file name="SwiftAPI_Request_Order.php" hash="cd8ce90614468bd4347df3c541482a4b"/><file name="SwiftAPI_Request_PastOrder.php" hash="be620e2e35d6634e6a616431f5312527"/><file name="SwiftAPI_Request_Product.php" hash="e5fab27bb2dd45946ed8c143a18fe3c4"/><file name="SwiftAPI_Request_SendMail.php" hash="6e520291609cd87d95837606b0f9f7e5"/><file name="SwiftAPI_Request_Subscription.php" hash="5545738b941d8ca4dca69b6059a0cce4"/><file name="SwiftAPI_Request_Unsubscribe.php" hash="78aa37cc0ecb98d501674350a4a409c9"/><file name="SwiftAPI_Request_ViewMail.php" hash="4155b64e3d152a37750d34dfd6839130"/><dir name="doc"><file name="SwiftAPI-Specification.html" hash="093cb08b66a596ebaeb0b50b4a0f8d79"/></dir><file name="index.php" hash="82886bb98883bd5868ea04c7d8c88ba5"/><file name="php.ini" hash="ef29c923925a1d1bbc8879c22297daa4"/></dir></target><target name="magecommunity"><dir name="Swift"><dir name="Swiftplugin"><dir name="Block"><dir name="Adminhtml"><dir name="Swift"><dir name="Edit"><file name="Form.php" hash="bd80ab8170f7f2286f13ac579e5249d9"/><dir name="Tab"><file name="Form.php" hash="04a1dcfb31537ff3ab7028066ed46967"/><file name="Instruct.php" hash="2fd453261a19b833363405c4ae2bcd34"/></dir><file name="Tabs.php" hash="0c556dafe429af303e3a908ccbb859aa"/></dir><file name="Edit.php" hash="934add564cd4406ef0a439700faa73be"/></dir></dir><file name="Swiftblock.php" hash="ef4796eaf44aa8e4a9b144e5a9365166"/></dir><dir name="Helper"><file name="Data.php" hash="85c5cbc3567cc52243158a204b0897fc"/></dir><dir name="Model"><dir name="Mysql4"><dir name="Swift"><file name="Collection.php" hash="82de0fe56cd875d3e78c8fc690424ee1"/></dir><file name="Swift.php" hash="252d5f2ecb1119804b415758d2db6800"/></dir><file name="Observer.php" hash="fe80df82ef8c72ee7ab493d841a5cb14"/><file name="Swift.php" hash="1f9e49d4db7f8987cfd8858061fedc6a"/><file name="XmlProduct.php" hash="39bc19d44a3c877697d06382b0ad669a"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="IndexController.php" hash="287421a261f2a8847f9ffbe45160fb83"/></dir><file name="MailController.php" hash="511d30670177eb7286b71afc1ea5bdef"/><file name="XmlController.php" hash="97b777935db5174501034493dd561099"/></dir><dir name="etc"><file name="config.xml" hash="492e43bd1a514f69a3382ea6e806a969"/></dir><dir name="sql"><dir name="swift_setup"><file name="install-1.1.2.php" hash="00832a00c34cb4c997a96330cb28cbfb"/><file name="upgrade-1.1.2-1.1.8.php" hash="cbe3c3fa07facb7b720d7dd518acbeca"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="frontend"><dir name="base"><dir name="default"><dir name="layout"><file name="swift.xml" hash="d80a5229e30cf4b76f5a5150ac1c27c3"/></dir><dir name="template"><dir name="swift"><file name="swiftplugin.phtml" hash="d4d25148e09529e457b6436d7655627b"/></dir></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Swift_all.xml" hash="0ae5a788c805a9fc79b402fe7a02e54d"/></dir></target></contents>
26
+ <compatible/>
27
+ <dependencies><required><php><min>5.4.0</min><max>6.0.0</max></php><extension><name>mcrypt</name><min/><max/></extension></required></dependencies>
28
+ </package>