Version Notes
* Change product re-crawl to send both id and url for products that have been added/modified
Download this release
Release Info
Developer | Nosto |
Extension | Nosto_Tagging |
Version | 2.2.0 |
Comparing to | |
See all releases |
Version 2.2.0
- app/code/community/Nosto/Tagging/Block/Adminhtml/Iframe.php +119 -0
- app/code/community/Nosto/Tagging/Block/Adminhtml/Wizard.php +38 -0
- app/code/community/Nosto/Tagging/Block/Cart.php +134 -0
- app/code/community/Nosto/Tagging/Block/Category.php +77 -0
- app/code/community/Nosto/Tagging/Block/Customer.php +55 -0
- app/code/community/Nosto/Tagging/Block/Element.php +75 -0
- app/code/community/Nosto/Tagging/Block/Embed.php +86 -0
- app/code/community/Nosto/Tagging/Block/Meta.php +76 -0
- app/code/community/Nosto/Tagging/Block/Order.php +71 -0
- app/code/community/Nosto/Tagging/Block/Product.php +100 -0
- app/code/community/Nosto/Tagging/Helper/Account.php +201 -0
- app/code/community/Nosto/Tagging/Helper/Customer.php +92 -0
- app/code/community/Nosto/Tagging/Helper/Data.php +92 -0
- app/code/community/Nosto/Tagging/Helper/Date.php +48 -0
- app/code/community/Nosto/Tagging/Helper/Oauth.php +53 -0
- app/code/community/Nosto/Tagging/Helper/Price.php +123 -0
- app/code/community/Nosto/Tagging/Helper/Url.php +174 -0
- app/code/community/Nosto/Tagging/Model/Container/Cart.php +69 -0
- app/code/community/Nosto/Tagging/Model/Container/Customer.php +81 -0
- app/code/community/Nosto/Tagging/Model/Customer.php +54 -0
- app/code/community/Nosto/Tagging/Model/Meta/Account.php +289 -0
- app/code/community/Nosto/Tagging/Model/Meta/Account/Billing.php +80 -0
- app/code/community/Nosto/Tagging/Model/Meta/Account/Iframe.php +361 -0
- app/code/community/Nosto/Tagging/Model/Meta/Account/Owner.php +134 -0
- app/code/community/Nosto/Tagging/Model/Meta/Oauth.php +153 -0
- app/code/community/Nosto/Tagging/Model/Meta/Order.php +190 -0
- app/code/community/Nosto/Tagging/Model/Meta/Order/Buyer.php +103 -0
- app/code/community/Nosto/Tagging/Model/Meta/Order/Item.php +201 -0
- app/code/community/Nosto/Tagging/Model/Meta/Product.php +392 -0
- app/code/community/Nosto/Tagging/Model/Observer.php +135 -0
- app/code/community/Nosto/Tagging/Model/Resource/Customer.php +45 -0
- app/code/community/Nosto/Tagging/Model/Resource/Customer/Collection.php +45 -0
- app/code/community/Nosto/Tagging/Model/Resource/Setup.php +37 -0
- app/code/community/Nosto/Tagging/controllers/Adminhtml/NostoController.php +256 -0
- app/code/community/Nosto/Tagging/controllers/ExportController.php +129 -0
- app/code/community/Nosto/Tagging/controllers/OauthController.php +114 -0
- app/code/community/Nosto/Tagging/etc/adminhtml.xml +49 -0
- app/code/community/Nosto/Tagging/etc/cache.xml +46 -0
- app/code/community/Nosto/Tagging/etc/config.xml +156 -0
- app/code/community/Nosto/Tagging/sql/tagging_setup/mysql4-install-1.2.0.php +83 -0
- app/code/community/Nosto/Tagging/sql/tagging_setup/mysql4-upgrade-1.1.7-1.2.0.php +88 -0
- app/design/adminhtml/default/default/layout/nostotagging.xml +56 -0
- app/design/adminhtml/default/default/template/nostotagging/iframe.phtml +50 -0
- app/design/adminhtml/default/default/template/nostotagging/wizard.phtml +42 -0
- app/design/frontend/base/default/layout/nostotagging.xml +273 -0
- app/design/frontend/base/default/template/nostotagging/cart.phtml +52 -0
- app/design/frontend/base/default/template/nostotagging/category.phtml +38 -0
- app/design/frontend/base/default/template/nostotagging/category/view.phtml +38 -0
- app/design/frontend/base/default/template/nostotagging/customer.phtml +43 -0
- app/design/frontend/base/default/template/nostotagging/element.phtml +37 -0
- app/design/frontend/base/default/template/nostotagging/embed.phtml +40 -0
- app/design/frontend/base/default/template/nostotagging/meta.phtml +40 -0
- app/design/frontend/base/default/template/nostotagging/order.phtml +61 -0
- app/design/frontend/base/default/template/nostotagging/product.phtml +67 -0
- app/etc/modules/Nosto_Tagging.xml +41 -0
- js/nosto/NostoIframe.min.js +1 -0
- js/nosto/iframeresizer.min.js +9 -0
- js/nosto/nostotagging-config.js +32 -0
- lib/nosto/php-sdk/src/.env.example +5 -0
- lib/nosto/php-sdk/src/classes/Nosto.php +130 -0
- lib/nosto/php-sdk/src/classes/NostoAccount.php +238 -0
- lib/nosto/php-sdk/src/classes/NostoCipher.php +95 -0
- lib/nosto/php-sdk/src/classes/NostoDotEnv.php +202 -0
- lib/nosto/php-sdk/src/classes/NostoException.php +41 -0
- lib/nosto/php-sdk/src/classes/NostoMessage.php +50 -0
- lib/nosto/php-sdk/src/classes/NostoOrderConfirmation.php +96 -0
- lib/nosto/php-sdk/src/classes/NostoProductReCrawl.php +111 -0
- lib/nosto/php-sdk/src/classes/NostoXhrResponse.php +103 -0
- lib/nosto/php-sdk/src/classes/api/NostoApiRequest.php +62 -0
- lib/nosto/php-sdk/src/classes/api/NostoApiToken.php +91 -0
- lib/nosto/php-sdk/src/classes/export/NostoExportCollection.php +95 -0
- lib/nosto/php-sdk/src/classes/export/NostoExportOrderCollection.php +78 -0
- lib/nosto/php-sdk/src/classes/export/NostoExportProductCollection.php +73 -0
- lib/nosto/php-sdk/src/classes/export/NostoExporter.php +70 -0
- lib/nosto/php-sdk/src/classes/helper/NostoHelper.php +44 -0
- lib/nosto/php-sdk/src/classes/helper/NostoHelperDate.php +51 -0
- lib/nosto/php-sdk/src/classes/helper/NostoHelperIframe.php +127 -0
- lib/nosto/php-sdk/src/classes/helper/NostoHelperPrice.php +51 -0
- lib/nosto/php-sdk/src/classes/http/NostoHttpRequest.php +368 -0
- lib/nosto/php-sdk/src/classes/http/NostoHttpRequestAdapter.php +82 -0
- lib/nosto/php-sdk/src/classes/http/NostoHttpRequestAdapterCurl.php +110 -0
- lib/nosto/php-sdk/src/classes/http/NostoHttpRequestAdapterSocket.php +106 -0
- lib/nosto/php-sdk/src/classes/http/NostoHttpResponse.php +140 -0
- lib/nosto/php-sdk/src/classes/oauth/NostoOAuthClient.php +143 -0
- lib/nosto/php-sdk/src/classes/oauth/NostoOAuthToken.php +98 -0
- lib/nosto/php-sdk/src/config.inc.php +100 -0
- lib/nosto/php-sdk/src/interfaces/NostoOAuthClientMetaDataInterface.php +83 -0
- lib/nosto/php-sdk/src/interfaces/NostoProductInterface.php +139 -0
- lib/nosto/php-sdk/src/interfaces/account/NostoAccountInterface.php +108 -0
- lib/nosto/php-sdk/src/interfaces/account/NostoAccountMetaDataBillingDetailsInterface.php +48 -0
- lib/nosto/php-sdk/src/interfaces/account/NostoAccountMetaDataIframeInterface.php +157 -0
- lib/nosto/php-sdk/src/interfaces/account/NostoAccountMetaDataInterface.php +113 -0
- lib/nosto/php-sdk/src/interfaces/account/NostoAccountMetaDataOwnerInterface.php +62 -0
- lib/nosto/php-sdk/src/interfaces/order/NostoOrderBuyerInterface.php +62 -0
- lib/nosto/php-sdk/src/interfaces/order/NostoOrderInterface.php +76 -0
- lib/nosto/php-sdk/src/interfaces/order/NostoOrderPurchasedItemInterface.php +79 -0
- lib/nosto/php-sdk/src/js/NostoIframe.min.js +1 -0
- lib/nosto/php-sdk/src/js/src/NostoIframe.js +230 -0
- lib/nosto/php-sdk/src/libs/phpseclib/crypt/NostoCryptAES.php +175 -0
- lib/nosto/php-sdk/src/libs/phpseclib/crypt/NostoCryptBase.php +2016 -0
- lib/nosto/php-sdk/src/libs/phpseclib/crypt/NostoCryptRandom.php +223 -0
- lib/nosto/php-sdk/src/libs/phpseclib/crypt/NostoCryptRijndael.php +3638 -0
- package.xml +18 -0
app/code/community/Nosto/Tagging/Block/Adminhtml/Iframe.php
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Nosto iframe block.
|
30 |
+
* Adds an iframe for configuring a Nosto account.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Block_Adminhtml_Iframe extends Mage_Adminhtml_Block_Template
|
37 |
+
{
|
38 |
+
const DEFAULT_ADMIN_IFRAME_ORIGIN = 'https://my.nosto.com';
|
39 |
+
|
40 |
+
/**
|
41 |
+
* @var string the iframe url if SSO to Nosto can be made.
|
42 |
+
*/
|
43 |
+
private $_iframeUrl;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* @var Mage_Core_Model_Store the currently selected store view.
|
47 |
+
*/
|
48 |
+
private $_store;
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Gets the iframe url for the account settings page from Nosto.
|
52 |
+
* This url is only returned if the current admin user can be logged in
|
53 |
+
* with SSO to Nosto.
|
54 |
+
*
|
55 |
+
* @return string the iframe url or empty string if it cannot be created.
|
56 |
+
*/
|
57 |
+
public function getIframeUrl()
|
58 |
+
{
|
59 |
+
if ($this->_iframeUrl !== null) {
|
60 |
+
return $this->_iframeUrl;
|
61 |
+
}
|
62 |
+
$params = array();
|
63 |
+
// Pass any error/success messages we might have to the iframe.
|
64 |
+
// These can be available when getting redirect back from the OAuth
|
65 |
+
// front controller after connecting a Nosto account to a store.
|
66 |
+
$session = Mage::getSingleton('adminhtml/session');
|
67 |
+
if ($session !== null) {
|
68 |
+
$nostoMessage = $session->getData('nosto_message');
|
69 |
+
if (is_array($nostoMessage)) {
|
70 |
+
if (isset($nostoMessage['type'], $nostoMessage['code'])) {
|
71 |
+
$params['message_type'] = $nostoMessage['type'];
|
72 |
+
$params['message_code'] = $nostoMessage['code'];
|
73 |
+
}
|
74 |
+
$session->setData('nosto_message', null);
|
75 |
+
}
|
76 |
+
}
|
77 |
+
$store = $this->getSelectedStore();
|
78 |
+
$account = Mage::helper('nosto_tagging/account')->find($store);
|
79 |
+
return $this->_iframeUrl = Mage::helper('nosto_tagging/account')
|
80 |
+
->getIframeUrl($store, $account, $params);
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Returns the currently selected store view.
|
85 |
+
*
|
86 |
+
* @return Mage_Core_Model_Store the store view model.
|
87 |
+
*
|
88 |
+
* @throws Exception if store view cannot be found.
|
89 |
+
*/
|
90 |
+
public function getSelectedStore()
|
91 |
+
{
|
92 |
+
if ($this->_store !== null) {
|
93 |
+
return $this->_store;
|
94 |
+
}
|
95 |
+
|
96 |
+
if (Mage::app()->isSingleStoreMode()) {
|
97 |
+
$store = Mage::app()->getStore(true);
|
98 |
+
} elseif (($id = (int)$this->getRequest()->getParam('store')) !== 0) {
|
99 |
+
$store = Mage::app()->getStore($id);
|
100 |
+
} else {
|
101 |
+
throw new Exception('Failed to find currently selected store view.');
|
102 |
+
}
|
103 |
+
|
104 |
+
return $this->_store = $store;
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Returns the valid origin url from where the iframe should accept
|
109 |
+
* postMessage calls.
|
110 |
+
* This is configurable to support different origins based on $_ENV.
|
111 |
+
*
|
112 |
+
* @return string the origin url.
|
113 |
+
*/
|
114 |
+
public function getIframeOrigin()
|
115 |
+
{
|
116 |
+
return (string)Mage::app()->getRequest()
|
117 |
+
->getEnv('NOSTO_IFRAME_ORIGIN', self::DEFAULT_ADMIN_IFRAME_ORIGIN);
|
118 |
+
}
|
119 |
+
}
|
app/code/community/Nosto/Tagging/Block/Adminhtml/Wizard.php
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Nosto configuration wizard block.
|
30 |
+
* Adds the 'wizard' markup for creating and managing Nosto accounts.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Block_Adminhtml_Wizard extends Mage_Adminhtml_Block_Template
|
37 |
+
{
|
38 |
+
}
|
app/code/community/Nosto/Tagging/Block/Cart.php
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Shopping cart content tagging block.
|
30 |
+
* Adds meta-data to the HTML document for shopping cart content.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Block_Cart extends Mage_Checkout_Block_Cart_Abstract
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* @var Mage_Sales_Model_Quote_Item[] Cached items in cart.
|
40 |
+
*/
|
41 |
+
protected $_items;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* Render shopping cart content as hidden meta data if the module is
|
45 |
+
* enabled for the current store.
|
46 |
+
*
|
47 |
+
* @return string
|
48 |
+
*/
|
49 |
+
protected function _toHtml()
|
50 |
+
{
|
51 |
+
if (!Mage::helper('nosto_tagging')->isModuleEnabled()
|
52 |
+
|| !Mage::helper('nosto_tagging/account')->existsAndIsConnected()
|
53 |
+
) {
|
54 |
+
return '';
|
55 |
+
}
|
56 |
+
|
57 |
+
// If we have items in the cart, then update the Nosto customer quote
|
58 |
+
// link. This is done to enable server-to-server order confirmation
|
59 |
+
// requests once the quote is turned into an order.
|
60 |
+
// We do it here as this will be run on every request when we have a
|
61 |
+
// quote. This is important as the Nosto customer ID will change after
|
62 |
+
// a period of time while the Mage quote ID can be the same.
|
63 |
+
// The ideal place to run it would be once when the customer goes to
|
64 |
+
// the `checkout/cart` page, but there are no events that are fired on
|
65 |
+
// that page only, and the cart page recommendation elements we output
|
66 |
+
// come through a generic block that cannot be used for this specific
|
67 |
+
// action.
|
68 |
+
if (count($this->getItems()) > 0) {
|
69 |
+
Mage::helper('nosto_tagging/customer')->updateNostoId();
|
70 |
+
}
|
71 |
+
|
72 |
+
return parent::_toHtml();
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Returns all visible cart items. If it is a bundle product with dynamic
|
77 |
+
* price settings, we get it's products and return them. Fixed price bundle
|
78 |
+
* is not supported.
|
79 |
+
*
|
80 |
+
* @return Mage_Sales_Model_Quote_Item[]
|
81 |
+
*/
|
82 |
+
public function getItems()
|
83 |
+
{
|
84 |
+
if (!$this->_items) {
|
85 |
+
$items = array();
|
86 |
+
/** @var $visibleItems Mage_Sales_Model_Quote_Item[] */
|
87 |
+
$visibleItems = parent::getItems();
|
88 |
+
foreach ($visibleItems as $item) {
|
89 |
+
$product = $item->getProduct();
|
90 |
+
if ($product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
|
91 |
+
if ((int)$product->getPriceType() === Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) {
|
92 |
+
continue;
|
93 |
+
}
|
94 |
+
$items = array_merge($items, $item->getChildren());
|
95 |
+
} else {
|
96 |
+
$items[] = $item;
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
$this->_items = $items;
|
101 |
+
}
|
102 |
+
|
103 |
+
return $this->_items;
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Returns the product id for a quote item.
|
108 |
+
* If the product type is "grouped", then return the grouped product's id
|
109 |
+
* and not the id of the actual product.
|
110 |
+
*
|
111 |
+
* @param Mage_Sales_Model_Quote_Item $item the quote item model.
|
112 |
+
*
|
113 |
+
* @return int
|
114 |
+
*/
|
115 |
+
public function getProductId($item)
|
116 |
+
{
|
117 |
+
switch ($item->getProductType()) {
|
118 |
+
case Mage_Catalog_Model_Product_Type::TYPE_GROUPED:
|
119 |
+
$option = $item->getOptionByCode('product_type');
|
120 |
+
if ($option !== null) {
|
121 |
+
$productId = $option->getProductId();
|
122 |
+
} else {
|
123 |
+
$productId = $item->getProductId();
|
124 |
+
}
|
125 |
+
break;
|
126 |
+
|
127 |
+
default:
|
128 |
+
$productId = $item->getProductId();
|
129 |
+
break;
|
130 |
+
}
|
131 |
+
|
132 |
+
return (int)$productId;
|
133 |
+
}
|
134 |
+
}
|
app/code/community/Nosto/Tagging/Block/Category.php
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Current category tagging block.
|
30 |
+
* Adds meta-data to the HTML document for the current catalog category
|
31 |
+
* (including parent categories).
|
32 |
+
*
|
33 |
+
* @category Nosto
|
34 |
+
* @package Nosto_Tagging
|
35 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
36 |
+
*/
|
37 |
+
class Nosto_Tagging_Block_Category extends Mage_Core_Block_Template
|
38 |
+
{
|
39 |
+
/**
|
40 |
+
* @var string Cached category string.
|
41 |
+
*/
|
42 |
+
protected $_category;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Render category string as hidden meta data if the module is enabled for
|
46 |
+
* the current store.
|
47 |
+
*
|
48 |
+
* @return string
|
49 |
+
*/
|
50 |
+
protected function _toHtml()
|
51 |
+
{
|
52 |
+
if (!Mage::helper('nosto_tagging')->isModuleEnabled()
|
53 |
+
|| !Mage::helper('nosto_tagging/account')->existsAndIsConnected()
|
54 |
+
|| !$this->getCategory()
|
55 |
+
) {
|
56 |
+
return '';
|
57 |
+
}
|
58 |
+
|
59 |
+
return parent::_toHtml();
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Return the current product category string for the category tagging.
|
64 |
+
*
|
65 |
+
* @return string
|
66 |
+
*/
|
67 |
+
public function getCategory()
|
68 |
+
{
|
69 |
+
if (!$this->_category) {
|
70 |
+
$category = Mage::registry('current_category');
|
71 |
+
$this->_category = Mage::helper('nosto_tagging')
|
72 |
+
->buildCategoryString($category);
|
73 |
+
}
|
74 |
+
|
75 |
+
return $this->_category;
|
76 |
+
}
|
77 |
+
}
|
app/code/community/Nosto/Tagging/Block/Customer.php
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Customer info tagging block.
|
30 |
+
* Adds meta-data to the HTML document for logged in customer.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Block_Customer extends Mage_Customer_Block_Account_Dashboard
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* Render customer info as hidden meta data if the customer is logged in,
|
40 |
+
* the module is enabled for the current store.
|
41 |
+
*
|
42 |
+
* @return string
|
43 |
+
*/
|
44 |
+
protected function _toHtml()
|
45 |
+
{
|
46 |
+
if (!$this->helper('customer')->isLoggedIn()
|
47 |
+
|| !$this->helper('nosto_tagging')->isModuleEnabled()
|
48 |
+
|| !Mage::helper('nosto_tagging/account')->existsAndIsConnected()
|
49 |
+
) {
|
50 |
+
return '';
|
51 |
+
}
|
52 |
+
|
53 |
+
return parent::_toHtml();
|
54 |
+
}
|
55 |
+
}
|
app/code/community/Nosto/Tagging/Block/Element.php
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Nosto element block.
|
30 |
+
* Used to render placeholder elements that display the product recommendations.
|
31 |
+
*
|
32 |
+
* @method string getDivId() Return the id of the element (defined in layout).
|
33 |
+
*
|
34 |
+
* @category Nosto
|
35 |
+
* @package Nosto_Tagging
|
36 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
37 |
+
*/
|
38 |
+
class Nosto_Tagging_Block_Element extends Mage_Core_Block_Template
|
39 |
+
{
|
40 |
+
/**
|
41 |
+
* Default id assigned to the element if none is set in the layout xml.
|
42 |
+
*/
|
43 |
+
const DEFAULT_ID = 'missingDivIdParameter';
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Render HTML placeholder element for the product recommendations if the
|
47 |
+
* module is enabled for the current store.
|
48 |
+
*
|
49 |
+
* @return string
|
50 |
+
*/
|
51 |
+
protected function _toHtml()
|
52 |
+
{
|
53 |
+
if (!Mage::helper('nosto_tagging')->isModuleEnabled()
|
54 |
+
|| !Mage::helper('nosto_tagging/account')->existsAndIsConnected()
|
55 |
+
) {
|
56 |
+
return '';
|
57 |
+
}
|
58 |
+
return parent::_toHtml();
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Return the id of the element. If none is defined in the layout xml,
|
63 |
+
* then set a default one.
|
64 |
+
*
|
65 |
+
* @return string
|
66 |
+
*/
|
67 |
+
public function getElementId()
|
68 |
+
{
|
69 |
+
$id = $this->getDivId();
|
70 |
+
if ($id === null) {
|
71 |
+
$id = self::DEFAULT_ID;
|
72 |
+
}
|
73 |
+
return $id;
|
74 |
+
}
|
75 |
+
}
|
app/code/community/Nosto/Tagging/Block/Embed.php
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Nosto embed script block.
|
30 |
+
* Adds JavaScript to the document HEAD that takes care of the meta-data gathering
|
31 |
+
* and displaying of recommended products.
|
32 |
+
*
|
33 |
+
* @category Nosto
|
34 |
+
* @package Nosto_Tagging
|
35 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
36 |
+
*/
|
37 |
+
class Nosto_Tagging_Block_Embed extends Mage_Core_Block_Template
|
38 |
+
{
|
39 |
+
const DEFAULT_SERVER_ADDRESS = 'connect.nosto.com';
|
40 |
+
|
41 |
+
/**
|
42 |
+
* Render JavaScript that handles the data gathering and displaying of
|
43 |
+
* recommended products if the module is enabled for the current store.
|
44 |
+
*
|
45 |
+
* @return string
|
46 |
+
*/
|
47 |
+
protected function _toHtml()
|
48 |
+
{
|
49 |
+
if (!Mage::helper('nosto_tagging')->isModuleEnabled()
|
50 |
+
|| !Mage::helper('nosto_tagging/account')->existsAndIsConnected()
|
51 |
+
) {
|
52 |
+
return '';
|
53 |
+
}
|
54 |
+
|
55 |
+
return parent::_toHtml();
|
56 |
+
}
|
57 |
+
|
58 |
+
/**
|
59 |
+
* Gets the account name for the current store scope.
|
60 |
+
*
|
61 |
+
* @return string the account name or empty string if account is not found.
|
62 |
+
*/
|
63 |
+
public function getAccountName()
|
64 |
+
{
|
65 |
+
$account = Mage::helper('nosto_tagging/account')->find();
|
66 |
+
if ($account !== null) {
|
67 |
+
return $account->name;
|
68 |
+
}
|
69 |
+
return '';
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Gets the Nosto server address.
|
74 |
+
* This is either taken from the local environment if exists or else it
|
75 |
+
* defaults to "connect.nosto.com".
|
76 |
+
*
|
77 |
+
* @return string the url.
|
78 |
+
*/
|
79 |
+
public function getServerAddress()
|
80 |
+
{
|
81 |
+
return Mage::app()->getRequest()->getEnv(
|
82 |
+
'NOSTO_SERVER_URL',
|
83 |
+
self::DEFAULT_SERVER_ADDRESS
|
84 |
+
);
|
85 |
+
}
|
86 |
+
}
|
app/code/community/Nosto/Tagging/Block/Meta.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Nosto meta block.
|
30 |
+
* Used to render meta tag elements to page <head> section.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Block_Meta extends Mage_Core_Block_Template
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* Render meta tags if the module is enabled for the current store.
|
40 |
+
*
|
41 |
+
* @return string
|
42 |
+
*/
|
43 |
+
protected function _toHtml()
|
44 |
+
{
|
45 |
+
if (!Mage::helper('nosto_tagging')->isModuleEnabled()
|
46 |
+
|| !Mage::helper('nosto_tagging/account')->existsAndIsConnected()
|
47 |
+
) {
|
48 |
+
return '';
|
49 |
+
}
|
50 |
+
return parent::_toHtml();
|
51 |
+
}
|
52 |
+
|
53 |
+
/**
|
54 |
+
* Returns the version number of the Nosto extension.
|
55 |
+
*
|
56 |
+
* @return string the module version.
|
57 |
+
*/
|
58 |
+
public function getVersionModule()
|
59 |
+
{
|
60 |
+
// Path is hard-coded to be like in "etc/config.xml".
|
61 |
+
return (string)Mage::getConfig()
|
62 |
+
->getNode('modules/Nosto_Tagging/version');
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Returns the 2-letter ISO code (ISO 639-1) for the shop language.
|
67 |
+
*
|
68 |
+
* @return string the language ISO code.
|
69 |
+
*/
|
70 |
+
public function getLanguageIsoCode()
|
71 |
+
{
|
72 |
+
return substr(
|
73 |
+
Mage::app()->getStore()->getConfig('general/locale/code'), 0, 2
|
74 |
+
);
|
75 |
+
}
|
76 |
+
}
|
app/code/community/Nosto/Tagging/Block/Order.php
ADDED
@@ -0,0 +1,71 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Order tagging block.
|
30 |
+
* Adds meta-data to the HTML document for successful orders.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Block_Order extends Mage_Checkout_Block_Success
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* Render order info as hidden meta data if the module is enabled for the
|
40 |
+
* current store.
|
41 |
+
*
|
42 |
+
* @return string
|
43 |
+
*/
|
44 |
+
protected function _toHtml()
|
45 |
+
{
|
46 |
+
if (!Mage::helper('nosto_tagging')->isModuleEnabled()
|
47 |
+
|| !Mage::helper('nosto_tagging/account')->existsAndIsConnected()
|
48 |
+
) {
|
49 |
+
return '';
|
50 |
+
}
|
51 |
+
|
52 |
+
return parent::_toHtml();
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Return the last placed order meta data for the customer.
|
57 |
+
*
|
58 |
+
* @return Nosto_Tagging_Model_Meta_Order the order meta data model.
|
59 |
+
*/
|
60 |
+
public function getLastOrder()
|
61 |
+
{
|
62 |
+
$orderId = Mage::getSingleton('checkout/session')->getLastOrderId();
|
63 |
+
/** @var Mage_Sales_Model_Order $order */
|
64 |
+
$order = Mage::getModel('sales/order')->load($orderId);
|
65 |
+
$meta = new Nosto_Tagging_Model_Meta_Order();
|
66 |
+
if ($order instanceof Mage_Sales_Model_Order) {
|
67 |
+
$meta->loadData($order);
|
68 |
+
}
|
69 |
+
return $meta;
|
70 |
+
}
|
71 |
+
}
|
app/code/community/Nosto/Tagging/Block/Product.php
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Product tagging block.
|
30 |
+
* Adds meta-data to the HTML document for the currently viewed product.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Block_Product extends Mage_Catalog_Block_Product_Abstract
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* @var Nosto_Tagging_Model_Meta_Product runtime cache for the product meta.
|
40 |
+
*/
|
41 |
+
protected $_product;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @var string runtime cache for the current category path string.
|
45 |
+
*/
|
46 |
+
protected $_currentCategory;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Render product info as hidden meta data if the module is enabled for the
|
50 |
+
* current store.
|
51 |
+
* If it is a "bundle" product with fixed price type, then do not render.
|
52 |
+
* These are not supported due to their child products not having prices
|
53 |
+
* available.
|
54 |
+
*
|
55 |
+
* @return string
|
56 |
+
*/
|
57 |
+
protected function _toHtml()
|
58 |
+
{
|
59 |
+
$product = $this->getProduct();
|
60 |
+
if (!Mage::helper('nosto_tagging')->isModuleEnabled()
|
61 |
+
|| !Mage::helper('nosto_tagging/account')->existsAndIsConnected()
|
62 |
+
|| ($product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE
|
63 |
+
&& (int)$product->getPriceType() === Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED)
|
64 |
+
) {
|
65 |
+
return '';
|
66 |
+
}
|
67 |
+
|
68 |
+
return parent::_toHtml();
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* Returns the product meta data to tag.
|
73 |
+
*
|
74 |
+
* @return Nosto_Tagging_Model_Meta_Product the meta data.
|
75 |
+
*/
|
76 |
+
public function getMetaProduct()
|
77 |
+
{
|
78 |
+
if ($this->_product === null) {
|
79 |
+
$this->_product = new Nosto_Tagging_Model_Meta_Product();
|
80 |
+
$this->_product->loadData($this->getProduct());
|
81 |
+
}
|
82 |
+
return $this->_product;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Returns the current category under which the product is viewed.
|
87 |
+
*
|
88 |
+
* @return string the category path or empty if not found.
|
89 |
+
*/
|
90 |
+
public function getCurrentCategory()
|
91 |
+
{
|
92 |
+
if (!$this->_currentCategory) {
|
93 |
+
$category = Mage::registry('current_category');
|
94 |
+
$this->_currentCategory = Mage::helper('nosto_tagging')
|
95 |
+
->buildCategoryString($category);
|
96 |
+
}
|
97 |
+
|
98 |
+
return $this->_currentCategory;
|
99 |
+
}
|
100 |
+
}
|
app/code/community/Nosto/Tagging/Helper/Account.php
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
require_once Mage::getBaseDir('lib') . '/nosto/php-sdk/src/config.inc.php';
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Helper class for managing Nosto accounts.
|
32 |
+
* Includes methods for saving, removing and finding accounts for a specific
|
33 |
+
* store.
|
34 |
+
*
|
35 |
+
* @category Nosto
|
36 |
+
* @package Nosto_Tagging
|
37 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
38 |
+
*/
|
39 |
+
class Nosto_Tagging_Helper_Account extends Mage_Core_Helper_Abstract
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* Path to store config nosto account name.
|
43 |
+
*/
|
44 |
+
const XML_PATH_ACCOUNT = 'nosto_tagging/settings/account';
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Path to store config nosto account tokens.
|
48 |
+
*/
|
49 |
+
const XML_PATH_TOKENS = 'nosto_tagging/settings/tokens';
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Saves the account and the associated api tokens for the store view scope.
|
53 |
+
*
|
54 |
+
* @param NostoAccount $account the account to save.
|
55 |
+
* @param Mage_Core_Model_Store|null $store the store view to save it for.
|
56 |
+
*
|
57 |
+
* @return bool true on success, false otherwise.
|
58 |
+
*/
|
59 |
+
public function save(NostoAccount $account, Mage_Core_Model_Store $store = null)
|
60 |
+
{
|
61 |
+
if ($store === null) {
|
62 |
+
$store = Mage::app()->getStore();
|
63 |
+
}
|
64 |
+
if ((int)$store->getId() < 1) {
|
65 |
+
return false;
|
66 |
+
}
|
67 |
+
/** @var Mage_Core_Model_Config $config */
|
68 |
+
$config = Mage::getModel('core/config');
|
69 |
+
$config->saveConfig(
|
70 |
+
self::XML_PATH_ACCOUNT, $account->name, 'stores', $store->getId()
|
71 |
+
);
|
72 |
+
$tokens = array();
|
73 |
+
foreach ($account->tokens as $token) {
|
74 |
+
$tokens[$token->name] = $token->value;
|
75 |
+
}
|
76 |
+
$config->saveConfig(
|
77 |
+
self::XML_PATH_TOKENS, json_encode($tokens), 'stores',
|
78 |
+
$store->getId()
|
79 |
+
);
|
80 |
+
Mage::app()->getCacheInstance()->cleanType('config');
|
81 |
+
return true;
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Removes an account with associated api tokens for the store view scope.
|
86 |
+
*
|
87 |
+
* @param NostoAccount $account the account to remove.
|
88 |
+
* @param Mage_Core_Model_Store|null $store the store view to remove it for.
|
89 |
+
*
|
90 |
+
* @return bool true on success, false otherwise.
|
91 |
+
*/
|
92 |
+
public function remove(NostoAccount $account, Mage_Core_Model_Store $store = null)
|
93 |
+
{
|
94 |
+
if ($store === null) {
|
95 |
+
$store = Mage::app()->getStore();
|
96 |
+
}
|
97 |
+
if ((int)$store->getId() < 1) {
|
98 |
+
return false;
|
99 |
+
}
|
100 |
+
/** @var Mage_Core_Model_Config $config */
|
101 |
+
$config = Mage::getModel('core/config');
|
102 |
+
$config->saveConfig(
|
103 |
+
self::XML_PATH_ACCOUNT, null, 'stores', $store->getId()
|
104 |
+
);
|
105 |
+
$config->saveConfig(
|
106 |
+
self::XML_PATH_TOKENS, null, 'stores', $store->getId()
|
107 |
+
);
|
108 |
+
Mage::app()->getCacheInstance()->cleanType('config');
|
109 |
+
|
110 |
+
try {
|
111 |
+
// Notify Nosto that the account was deleted.
|
112 |
+
$account->delete();
|
113 |
+
} catch (NostoException $e) {
|
114 |
+
// Failures are logged but not shown to the user.
|
115 |
+
Mage::log(
|
116 |
+
"\n" . $e->__toString(), Zend_Log::ERR, 'nostotagging.log'
|
117 |
+
);
|
118 |
+
}
|
119 |
+
|
120 |
+
return true;
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Returns the account with associated api tokens for the store view scope.
|
125 |
+
*
|
126 |
+
* @param Mage_Core_Model_Store|null $store the account store view.
|
127 |
+
*
|
128 |
+
* @return NostoAccount|null the account or null if not found.
|
129 |
+
*/
|
130 |
+
public function find(Mage_Core_Model_Store $store = null)
|
131 |
+
{
|
132 |
+
if ($store === null) {
|
133 |
+
$store = Mage::app()->getStore();
|
134 |
+
}
|
135 |
+
$accountName = $store->getConfig(self::XML_PATH_ACCOUNT);
|
136 |
+
if (!empty($accountName)) {
|
137 |
+
$account = new NostoAccount();
|
138 |
+
$account->name = $accountName;
|
139 |
+
$tokens = json_decode(
|
140 |
+
$store->getConfig(self::XML_PATH_TOKENS), true
|
141 |
+
);
|
142 |
+
if (is_array($tokens) && !empty($tokens)) {
|
143 |
+
foreach ($tokens as $name => $value) {
|
144 |
+
$token = new NostoApiToken();
|
145 |
+
$token->name = $name;
|
146 |
+
$token->value = $value;
|
147 |
+
$account->tokens[] = $token;
|
148 |
+
}
|
149 |
+
}
|
150 |
+
return $account;
|
151 |
+
}
|
152 |
+
return null;
|
153 |
+
}
|
154 |
+
|
155 |
+
/**
|
156 |
+
* Checks that an account exists for the given store and that it is
|
157 |
+
* connected to nosto.
|
158 |
+
*
|
159 |
+
* @param Mage_Core_Model_Store $store the store to check the account for.
|
160 |
+
*
|
161 |
+
* @return bool true if exists and is connected, false otherwise.
|
162 |
+
*/
|
163 |
+
public function existsAndIsConnected(Mage_Core_Model_Store $store = null)
|
164 |
+
{
|
165 |
+
$account = $this->find($store);
|
166 |
+
return ($account !== null && $account->isConnectedToNosto());
|
167 |
+
}
|
168 |
+
|
169 |
+
/**
|
170 |
+
* Returns the meta data model needed for creating a new nosto account
|
171 |
+
* using the Nosto SDk.
|
172 |
+
*
|
173 |
+
* @param Mage_Core_Model_Store $store the store view to get the data for.
|
174 |
+
*
|
175 |
+
* @return Nosto_Tagging_Model_Meta_Account the meta data instance.
|
176 |
+
*/
|
177 |
+
public function getMetaData(Mage_Core_Model_Store $store)
|
178 |
+
{
|
179 |
+
$meta = new Nosto_Tagging_Model_Meta_Account();
|
180 |
+
$meta->loadData($store);
|
181 |
+
return $meta;
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Returns the account administration iframe url.
|
186 |
+
* If there is no account the "front page" url will be returned where an
|
187 |
+
* account can be created from.
|
188 |
+
*
|
189 |
+
* @param Mage_Core_Model_Store $store the store view to get the url for.
|
190 |
+
* @param NostoAccount $account the Nosto account to get the iframe url for.
|
191 |
+
* @param array $params optional extra params for the url.
|
192 |
+
*
|
193 |
+
* @return string the iframe url.
|
194 |
+
*/
|
195 |
+
public function getIframeUrl(Mage_Core_Model_Store $store, NostoAccount $account = null, array $params = array())
|
196 |
+
{
|
197 |
+
$meta = new Nosto_Tagging_Model_Meta_Account_Iframe();
|
198 |
+
$meta->loadData($store);
|
199 |
+
return Nosto::helper('iframe')->getUrl($meta, $account, $params);
|
200 |
+
}
|
201 |
+
}
|
app/code/community/Nosto/Tagging/Helper/Customer.php
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Helper class for Nosto customer related actions.
|
30 |
+
*
|
31 |
+
* @category Nosto
|
32 |
+
* @package Nosto_Tagging
|
33 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
34 |
+
*/
|
35 |
+
class Nosto_Tagging_Helper_Customer extends Mage_Core_Helper_Abstract
|
36 |
+
{
|
37 |
+
/**
|
38 |
+
* @var string the name of the cookie where the Nosto ID can be found.
|
39 |
+
*/
|
40 |
+
const COOKIE_NAME = '2c_cId';
|
41 |
+
|
42 |
+
/**
|
43 |
+
* Gets the Nosto ID for an order model.
|
44 |
+
* The Nosto ID represents the customer who placed to the order on Nosto's
|
45 |
+
* side.
|
46 |
+
*
|
47 |
+
* @param Mage_Sales_Model_Order $order the order to get the Nosto ID for.
|
48 |
+
*
|
49 |
+
* @return bool|string the Nosto ID or false if not found for order.
|
50 |
+
*/
|
51 |
+
public function getNostoId(Mage_Sales_Model_Order $order)
|
52 |
+
{
|
53 |
+
/** @var Nosto_Tagging_Model_Customer $customer */
|
54 |
+
$customer = Mage::getModel('nosto_tagging/customer');
|
55 |
+
$customer->load($order->getQuoteId(), 'quote_id');
|
56 |
+
return $customer->hasData('nosto_id') ? $customer->getNostoId() : false;
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Update the Nosto ID form the current quote if it exists.
|
61 |
+
* The Nosto ID is present in a cookie set by the JavaScript loaded from
|
62 |
+
* Nosto.
|
63 |
+
*/
|
64 |
+
public function updateNostoId()
|
65 |
+
{
|
66 |
+
/** @var Mage_Checkout_Model_Cart $cart */
|
67 |
+
$cart = Mage::getModel('checkout/cart');
|
68 |
+
/** @var Mage_Core_Model_Cookie $cookie */
|
69 |
+
$cookie = Mage::getModel('core/cookie');
|
70 |
+
$quoteId = ($cart->getQuote() !== null)
|
71 |
+
? $cart->getQuote()->getId()
|
72 |
+
: false;
|
73 |
+
$nostoId = $cookie->get(self::COOKIE_NAME);
|
74 |
+
if (!empty($quoteId) && !empty($nostoId)) {
|
75 |
+
/** @var Nosto_Tagging_Model_Customer $customer */
|
76 |
+
$customer = Mage::getModel('nosto_tagging/customer')
|
77 |
+
->getCollection()
|
78 |
+
->addFieldToFilter('quote_id', $quoteId)
|
79 |
+
->addFieldToFilter('nosto_id', $nostoId)
|
80 |
+
->getFirstItem();
|
81 |
+
if ($customer->hasData()) {
|
82 |
+
$customer->setUpdatedAt(date('Y-m-d H:i:s'));
|
83 |
+
$customer->save();
|
84 |
+
} else {
|
85 |
+
$customer->setQuoteId($quoteId);
|
86 |
+
$customer->setNostoId($nostoId);
|
87 |
+
$customer->setCreatedAt(date('Y-m-d H:i:s'));
|
88 |
+
$customer->save();
|
89 |
+
}
|
90 |
+
}
|
91 |
+
}
|
92 |
+
}
|
app/code/community/Nosto/Tagging/Helper/Data.php
ADDED
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Helper class for common operations.
|
30 |
+
*
|
31 |
+
* @category Nosto
|
32 |
+
* @package Nosto_Tagging
|
33 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
34 |
+
*/
|
35 |
+
class Nosto_Tagging_Helper_Data extends Mage_Core_Helper_Abstract
|
36 |
+
{
|
37 |
+
const XML_PATH_INSTALLATION_ID = 'nosto_tagging/installation/id';
|
38 |
+
|
39 |
+
/**
|
40 |
+
* Builds a tagging string of the given category including all its parent
|
41 |
+
* categories.
|
42 |
+
* The categories are sorted by their position in the category tree path.
|
43 |
+
*
|
44 |
+
* @param Mage_Catalog_Model_Category $category the category model.
|
45 |
+
*
|
46 |
+
* @return string
|
47 |
+
*/
|
48 |
+
public function buildCategoryString($category)
|
49 |
+
{
|
50 |
+
$data = array();
|
51 |
+
|
52 |
+
if ($category instanceof Mage_Catalog_Model_Category) {
|
53 |
+
/** @var $categories Mage_Catalog_Model_Category[] */
|
54 |
+
$categories = $category->getParentCategories();
|
55 |
+
$path = $category->getPathInStore();
|
56 |
+
$ids = array_reverse(explode(',', $path));
|
57 |
+
foreach ($ids as $id) {
|
58 |
+
if (isset($categories[$id]) && $categories[$id]->getName()) {
|
59 |
+
$data[] = $categories[$id]->getName();
|
60 |
+
}
|
61 |
+
}
|
62 |
+
}
|
63 |
+
if (!empty($data)) {
|
64 |
+
return DS . implode(DS, $data);
|
65 |
+
} else {
|
66 |
+
return '';
|
67 |
+
}
|
68 |
+
}
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Returns a unique ID that identifies this Magento installation.
|
72 |
+
* This ID is sent to the Nosto account config iframe and used to link all
|
73 |
+
* Nosto accounts used on this installation.
|
74 |
+
*
|
75 |
+
* @return string the ID.
|
76 |
+
*/
|
77 |
+
public function getInstallationId()
|
78 |
+
{
|
79 |
+
$installationId = Mage::getStoreConfig(self::XML_PATH_INSTALLATION_ID);
|
80 |
+
if (empty($installationId)) {
|
81 |
+
// Running bin2hex() will make the ID string length 64 characters.
|
82 |
+
$installationId = bin2hex(NostoCryptRandom::getRandomString(32));
|
83 |
+
/** @var Mage_Core_Model_Config $config */
|
84 |
+
$config = Mage::getModel('core/config');
|
85 |
+
$config->saveConfig(
|
86 |
+
self::XML_PATH_INSTALLATION_ID, $installationId, 'default', 0
|
87 |
+
);
|
88 |
+
Mage::app()->getCacheInstance()->cleanType('config');
|
89 |
+
}
|
90 |
+
return $installationId;
|
91 |
+
}
|
92 |
+
}
|
app/code/community/Nosto/Tagging/Helper/Date.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Helper class for common date operations.
|
30 |
+
*
|
31 |
+
* @category Nosto
|
32 |
+
* @package Nosto_Tagging
|
33 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
34 |
+
*/
|
35 |
+
class Nosto_Tagging_Helper_Date extends Mage_Core_Helper_Abstract
|
36 |
+
{
|
37 |
+
/**
|
38 |
+
* Formats date into Nosto format, i.e. Y-m-d.
|
39 |
+
*
|
40 |
+
* @param string $date the date to format.
|
41 |
+
*
|
42 |
+
* @return string the formatted date.
|
43 |
+
*/
|
44 |
+
public function getFormattedDate($date)
|
45 |
+
{
|
46 |
+
return date('Y-m-d', strtotime($date));
|
47 |
+
}
|
48 |
+
}
|
app/code/community/Nosto/Tagging/Helper/Oauth.php
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
require_once Mage::getBaseDir('lib') . '/nosto/php-sdk/src/config.inc.php';
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Helper class for OAuth2 related tasks.
|
32 |
+
*
|
33 |
+
* @category Nosto
|
34 |
+
* @package Nosto_Tagging
|
35 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
36 |
+
*/
|
37 |
+
class Nosto_Tagging_Helper_Oauth extends Mage_Core_Helper_Abstract
|
38 |
+
{
|
39 |
+
/**
|
40 |
+
* Returns the meta data model needed for using the OAuth2 client included
|
41 |
+
* in the Nosto SDk.
|
42 |
+
*
|
43 |
+
* @param Mage_Core_Model_Store $store the store to get the oauth meta data for..
|
44 |
+
*
|
45 |
+
* @return Nosto_Tagging_Model_Meta_Oauth the meta data instance.
|
46 |
+
*/
|
47 |
+
public function getMetaData(Mage_Core_Model_Store $store)
|
48 |
+
{
|
49 |
+
$meta = new Nosto_Tagging_Model_Meta_Oauth();
|
50 |
+
$meta->loadData($store);
|
51 |
+
return $meta;
|
52 |
+
}
|
53 |
+
}
|
app/code/community/Nosto/Tagging/Helper/Price.php
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Helper class for common price operations.
|
30 |
+
*
|
31 |
+
* @category Nosto
|
32 |
+
* @package Nosto_Tagging
|
33 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
34 |
+
*/
|
35 |
+
class Nosto_Tagging_Helper_Price extends Mage_Core_Helper_Abstract
|
36 |
+
{
|
37 |
+
/**
|
38 |
+
* Formats price into Nosto format, e.g. 1000.99.
|
39 |
+
*
|
40 |
+
* @param string|int|float $price the price to format.
|
41 |
+
*
|
42 |
+
* @return string
|
43 |
+
*/
|
44 |
+
public function getFormattedPrice($price)
|
45 |
+
{
|
46 |
+
return number_format($price, 2, '.', '');
|
47 |
+
}
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Gets the unit price for a product model.
|
51 |
+
*
|
52 |
+
* @param Mage_Catalog_Model_Product $product the product model.
|
53 |
+
*
|
54 |
+
* @return float
|
55 |
+
*/
|
56 |
+
public function getProductPrice($product)
|
57 |
+
{
|
58 |
+
return $this->_getProductPrice($product);
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Get the final price for a product model.
|
63 |
+
*
|
64 |
+
* @param Mage_Catalog_Model_Product $product the product model.
|
65 |
+
*
|
66 |
+
* @return float
|
67 |
+
*/
|
68 |
+
public function getProductFinalPrice($product)
|
69 |
+
{
|
70 |
+
return $this->_getProductPrice($product, true);
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* Get unit/final price for a product model.
|
75 |
+
*
|
76 |
+
* @param Mage_Catalog_Model_Product $product the product model.
|
77 |
+
* @param bool $finalPrice if final price.
|
78 |
+
*
|
79 |
+
* @return float
|
80 |
+
*/
|
81 |
+
protected function _getProductPrice($product, $finalPrice = false)
|
82 |
+
{
|
83 |
+
$price = 0;
|
84 |
+
|
85 |
+
switch ($product->getTypeId()) {
|
86 |
+
case Mage_Catalog_Model_Product_Type::TYPE_BUNDLE:
|
87 |
+
// Get the bundle product "from" price.
|
88 |
+
$price = $product->getPriceModel()
|
89 |
+
->getTotalPrices($product, 'min', true);
|
90 |
+
break;
|
91 |
+
|
92 |
+
case Mage_Catalog_Model_Product_Type::TYPE_GROUPED:
|
93 |
+
// Get the grouped product "starting at" price.
|
94 |
+
/** @var $tmpProduct Mage_Catalog_Model_Product */
|
95 |
+
$tmpProduct = Mage::getModel('catalog/product')
|
96 |
+
->getCollection()
|
97 |
+
->addAttributeToSelect(
|
98 |
+
Mage::getSingleton('catalog/config')
|
99 |
+
->getProductAttributes()
|
100 |
+
)
|
101 |
+
->addAttributeToFilter('entity_id', $product->getId())
|
102 |
+
->setPage(1, 1)
|
103 |
+
->addMinimalPrice()
|
104 |
+
->addTaxPercents()
|
105 |
+
->load()
|
106 |
+
->getFirstItem();
|
107 |
+
if ($tmpProduct) {
|
108 |
+
$price = $tmpProduct->getMinimalPrice();
|
109 |
+
}
|
110 |
+
break;
|
111 |
+
|
112 |
+
default:
|
113 |
+
if ($finalPrice) {
|
114 |
+
$price = $product->getFinalPrice();
|
115 |
+
} else {
|
116 |
+
$price = $product->getPrice();
|
117 |
+
}
|
118 |
+
break;
|
119 |
+
}
|
120 |
+
|
121 |
+
return (float)$price;
|
122 |
+
}
|
123 |
+
}
|
app/code/community/Nosto/Tagging/Helper/Url.php
ADDED
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Helper class for building urls.
|
30 |
+
* Includes getters for all preview urls for the Nosto account configuration
|
31 |
+
* iframe.
|
32 |
+
*
|
33 |
+
* @category Nosto
|
34 |
+
* @package Nosto_Tagging
|
35 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
36 |
+
*/
|
37 |
+
class Nosto_Tagging_Helper_Url extends Mage_Core_Helper_Abstract
|
38 |
+
{
|
39 |
+
/**
|
40 |
+
* Gets the absolute preview URL to the current store view product page.
|
41 |
+
* The product is the first one found in the database for the store.
|
42 |
+
* The preview url includes "nostodebug=true" parameter.
|
43 |
+
*
|
44 |
+
* @param Mage_Core_Model_Store $store the store to get the url for.
|
45 |
+
*
|
46 |
+
* @return string the url.
|
47 |
+
*/
|
48 |
+
public function getPreviewUrlProduct(Mage_Core_Model_Store $store)
|
49 |
+
{
|
50 |
+
$collection = Mage::getModel('catalog/product')
|
51 |
+
->getCollection()
|
52 |
+
->addStoreFilter($store->getId())
|
53 |
+
->addAttributeToSelect('*')
|
54 |
+
->addAttributeToFilter(
|
55 |
+
'status', array(
|
56 |
+
'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
|
57 |
+
)
|
58 |
+
)
|
59 |
+
->addFieldToFilter(
|
60 |
+
'visibility',
|
61 |
+
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH
|
62 |
+
)
|
63 |
+
->setPageSize(1)
|
64 |
+
->setCurPage(1);
|
65 |
+
foreach ($collection as $product) {
|
66 |
+
/** @var Mage_Catalog_Model_Product $product */
|
67 |
+
$url = $product->getProductUrl();
|
68 |
+
$url = NostoHttpRequest::replaceQueryParamInUrl(
|
69 |
+
'___store', $store->getCode(), $url
|
70 |
+
);
|
71 |
+
return NostoHttpRequest::replaceQueryParamInUrl(
|
72 |
+
'nostodebug', 'true', $url
|
73 |
+
);
|
74 |
+
}
|
75 |
+
return '';
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Gets the absolute preview URL to the current store view category page.
|
80 |
+
* The category is the first one found in the database for the store.
|
81 |
+
* The preview url includes "nostodebug=true" parameter.
|
82 |
+
*
|
83 |
+
* @param Mage_Core_Model_Store $store the store to get the url for.
|
84 |
+
*
|
85 |
+
* @return string the url.
|
86 |
+
*/
|
87 |
+
public function getPreviewUrlCategory(Mage_Core_Model_Store $store)
|
88 |
+
{
|
89 |
+
$rootCategoryId = (int)$store->getRootCategoryId();
|
90 |
+
$collection = Mage::getModel('catalog/category')
|
91 |
+
->getCollection()
|
92 |
+
->addFieldToFilter('is_active', 1)
|
93 |
+
->addFieldToFilter('path', array('like' => "1/$rootCategoryId/%"))
|
94 |
+
->addAttributeToSelect('*')
|
95 |
+
->setPageSize(1)
|
96 |
+
->setCurPage(1);
|
97 |
+
foreach ($collection as $category) {
|
98 |
+
/** @var Mage_Catalog_Model_Category $category */
|
99 |
+
$url = $category->getUrl();
|
100 |
+
$url = NostoHttpRequest::replaceQueryParamInUrl(
|
101 |
+
'___store', $store->getCode(), $url
|
102 |
+
);
|
103 |
+
return NostoHttpRequest::replaceQueryParamInUrl(
|
104 |
+
'nostodebug', 'true', $url
|
105 |
+
);
|
106 |
+
}
|
107 |
+
return '';
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Gets the absolute preview URL to the current store view search page.
|
112 |
+
* The search query in the URL is "q=nosto".
|
113 |
+
* The preview url includes "nostodebug=true" parameter.
|
114 |
+
*
|
115 |
+
* @param Mage_Core_Model_Store $store the store to get the url for.
|
116 |
+
*
|
117 |
+
* @return string the url.
|
118 |
+
*/
|
119 |
+
public function getPreviewUrlSearch(Mage_Core_Model_Store $store)
|
120 |
+
{
|
121 |
+
$url = Mage::getUrl(
|
122 |
+
'catalogsearch/result', array(
|
123 |
+
'_store' => $store->getId(),
|
124 |
+
'_store_to_url' => true
|
125 |
+
)
|
126 |
+
);
|
127 |
+
$url = NostoHttpRequest::replaceQueryParamInUrl('q', 'nosto', $url);
|
128 |
+
return NostoHttpRequest::replaceQueryParamInUrl(
|
129 |
+
'nostodebug', 'true', $url
|
130 |
+
);
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Gets the absolute preview URL to the current store view cart page.
|
135 |
+
* The preview url includes "nostodebug=true" parameter.
|
136 |
+
*
|
137 |
+
* @param Mage_Core_Model_Store $store the store to get the url for.
|
138 |
+
*
|
139 |
+
* @return string the url.
|
140 |
+
*/
|
141 |
+
public function getPreviewUrlCart(Mage_Core_Model_Store $store)
|
142 |
+
{
|
143 |
+
$url = Mage::getUrl(
|
144 |
+
'checkout/cart', array(
|
145 |
+
'_store' => $store->getId(),
|
146 |
+
'_store_to_url' => true
|
147 |
+
)
|
148 |
+
);
|
149 |
+
return NostoHttpRequest::replaceQueryParamInUrl(
|
150 |
+
'nostodebug', 'true', $url
|
151 |
+
);
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Gets the absolute preview URL to the current store view front page.
|
156 |
+
* The preview url includes "nostodebug=true" parameter.
|
157 |
+
*
|
158 |
+
* @param Mage_Core_Model_Store $store the store to get the url for.
|
159 |
+
*
|
160 |
+
* @return string the url.
|
161 |
+
*/
|
162 |
+
public function getPreviewUrlFront(Mage_Core_Model_Store $store)
|
163 |
+
{
|
164 |
+
$url = Mage::getUrl(
|
165 |
+
'', array(
|
166 |
+
'_store' => $store->getId(),
|
167 |
+
'_store_to_url' => true
|
168 |
+
)
|
169 |
+
);
|
170 |
+
return NostoHttpRequest::replaceQueryParamInUrl(
|
171 |
+
'nostodebug', 'true', $url
|
172 |
+
);
|
173 |
+
}
|
174 |
+
}
|
app/code/community/Nosto/Tagging/Model/Container/Cart.php
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Cart Container model.
|
30 |
+
* Used to keep cart tagging block up to date when Magento EE FPC is used.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Model_Container_Cart extends Enterprise_PageCache_Model_Container_Advanced_Quote
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* Get identifier from cookies.
|
40 |
+
*
|
41 |
+
* @deprecated since 1.12.0.0
|
42 |
+
* @return string
|
43 |
+
*/
|
44 |
+
protected function _getIdentifier()
|
45 |
+
{
|
46 |
+
return $this->_getCookieValue(
|
47 |
+
Enterprise_PageCache_Model_Cookie::COOKIE_CART, ''
|
48 |
+
)
|
49 |
+
. '_'
|
50 |
+
. $this->_getCookieValue(
|
51 |
+
Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, ''
|
52 |
+
);
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* @inheritdoc
|
57 |
+
*/
|
58 |
+
protected function _renderBlock()
|
59 |
+
{
|
60 |
+
$block = $this->_getPlaceHolderBlock();
|
61 |
+
Mage::dispatchEvent(
|
62 |
+
'render_block', array(
|
63 |
+
'block' => $block,
|
64 |
+
'placeholder' => $this->_placeholder
|
65 |
+
)
|
66 |
+
);
|
67 |
+
return $block->toHtml();
|
68 |
+
}
|
69 |
+
}
|
app/code/community/Nosto/Tagging/Model/Container/Customer.php
ADDED
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Customer Container model.
|
30 |
+
* Used to keep customer tagging block up to date when Magento EE FPC is used.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Model_Container_Customer extends Enterprise_PageCache_Model_Container_Customer
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* Get identifier from cookies.
|
40 |
+
*
|
41 |
+
* @deprecated since 1.12.0.0
|
42 |
+
* @return string
|
43 |
+
*/
|
44 |
+
protected function _getIdentifier()
|
45 |
+
{
|
46 |
+
return $this->_getCookieValue(
|
47 |
+
Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, ''
|
48 |
+
)
|
49 |
+
. '_'
|
50 |
+
. $this->_getCookieValue(
|
51 |
+
Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER_LOGGED_IN, ''
|
52 |
+
);
|
53 |
+
}
|
54 |
+
|
55 |
+
/**
|
56 |
+
* @inheritdoc
|
57 |
+
*/
|
58 |
+
protected function _getCacheId()
|
59 |
+
{
|
60 |
+
return 'CONTAINER_NOSTO_TAGGING_CUSTOMER_'
|
61 |
+
. md5(
|
62 |
+
$this->_placeholder->getAttribute('cache_id')
|
63 |
+
. $this->_getIdentifier()
|
64 |
+
);
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* @inheritdoc
|
69 |
+
*/
|
70 |
+
protected function _renderBlock()
|
71 |
+
{
|
72 |
+
$block = $this->_getPlaceHolderBlock();
|
73 |
+
Mage::dispatchEvent(
|
74 |
+
'render_block', array(
|
75 |
+
'block' => $block,
|
76 |
+
'placeholder' => $this->_placeholder
|
77 |
+
)
|
78 |
+
);
|
79 |
+
return $block->toHtml();
|
80 |
+
}
|
81 |
+
}
|
app/code/community/Nosto/Tagging/Model/Customer.php
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Customer model.
|
30 |
+
* Used for keeping a link between a Mage quote and a Nosto customer.
|
31 |
+
*
|
32 |
+
* @method void setQuoteId($quoteId)
|
33 |
+
* @method int getQuoteId()
|
34 |
+
* @method void setNostoId($nostoId)
|
35 |
+
* @method string getNostoId()
|
36 |
+
* @method void setUpdatedAt($updatedAt)
|
37 |
+
* @method string getUpdatedAt()
|
38 |
+
* @method void setCreatedAt($createdAt)
|
39 |
+
* @method string getCreatedAt()
|
40 |
+
*
|
41 |
+
* @category Nosto
|
42 |
+
* @package Nosto_Tagging
|
43 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
44 |
+
*/
|
45 |
+
class Nosto_Tagging_Model_Customer extends Mage_Core_Model_Abstract
|
46 |
+
{
|
47 |
+
/**
|
48 |
+
* @inheritdoc
|
49 |
+
*/
|
50 |
+
protected function _construct()
|
51 |
+
{
|
52 |
+
$this->_init('nosto_tagging/customer');
|
53 |
+
}
|
54 |
+
}
|
app/code/community/Nosto/Tagging/Model/Meta/Account.php
ADDED
@@ -0,0 +1,289 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Meta data class which holds information about a new Nosto account.
|
30 |
+
* This is used during the Nosto account creation.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Model_Meta_Account extends Mage_Core_Model_Abstract implements NostoAccountMetaDataInterface
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* @var string the store name.
|
40 |
+
*/
|
41 |
+
protected $_title;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @var string the account name.
|
45 |
+
*/
|
46 |
+
protected $_name;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* @var string the store front end url.
|
50 |
+
*/
|
51 |
+
protected $_frontPageUrl;
|
52 |
+
|
53 |
+
/**
|
54 |
+
* @var string the store currency ISO (ISO 4217) code.
|
55 |
+
*/
|
56 |
+
protected $_currencyCode;
|
57 |
+
|
58 |
+
/**
|
59 |
+
* @var string the store language ISO (ISO 639-1) code.
|
60 |
+
*/
|
61 |
+
protected $_languageCode;
|
62 |
+
|
63 |
+
/**
|
64 |
+
* @var string the owner language ISO (ISO 639-1) code.
|
65 |
+
*/
|
66 |
+
protected $_ownerLanguageCode;
|
67 |
+
|
68 |
+
/**
|
69 |
+
* @var Nosto_Tagging_Model_Meta_Account_Owner the account owner meta model.
|
70 |
+
*/
|
71 |
+
protected $_owner;
|
72 |
+
|
73 |
+
/**
|
74 |
+
* @var Nosto_Tagging_Model_Meta_Account_Billing the billing meta model.
|
75 |
+
*/
|
76 |
+
protected $_billing;
|
77 |
+
|
78 |
+
/**
|
79 |
+
* @var string the API token used to identify an account creation.
|
80 |
+
*/
|
81 |
+
protected $_signUpApiToken = 'YBDKYwSqTCzSsU8Bwbg4im2pkHMcgTy9cCX7vevjJwON1UISJIwXOLMM0a8nZY7h';
|
82 |
+
|
83 |
+
/**
|
84 |
+
* @inheritdoc
|
85 |
+
*/
|
86 |
+
protected function _construct()
|
87 |
+
{
|
88 |
+
$this->_init('nosto_tagging/meta_account');
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Loads the meta data for the given store.
|
93 |
+
*
|
94 |
+
* @param Mage_Core_Model_Store $store the store view to load the data for.
|
95 |
+
*/
|
96 |
+
public function loadData(Mage_Core_Model_Store $store)
|
97 |
+
{
|
98 |
+
$this->_title = $store->getWebsite()->getName()
|
99 |
+
. ' - '
|
100 |
+
. $store->getGroup()->getName()
|
101 |
+
. ' - '
|
102 |
+
. $store->getName();
|
103 |
+
$this->_name = substr(sha1(rand()), 0, 8);
|
104 |
+
$this->_frontPageUrl = NostoHttpRequest::replaceQueryParamInUrl(
|
105 |
+
'___store',
|
106 |
+
$store->getCode(),
|
107 |
+
$store->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB)
|
108 |
+
);
|
109 |
+
$this->_currencyCode = $store->getBaseCurrencyCode();
|
110 |
+
$this->_languageCode = substr(
|
111 |
+
$store->getConfig('general/locale/code'), 0, 2
|
112 |
+
);
|
113 |
+
$this->_ownerLanguageCode = substr(
|
114 |
+
Mage::app()->getLocale()->getLocaleCode(), 0, 2
|
115 |
+
);
|
116 |
+
$this->_owner = new Nosto_Tagging_Model_Meta_Account_Owner();
|
117 |
+
$this->_owner->loadData($store);
|
118 |
+
$this->_billing = new Nosto_Tagging_Model_Meta_Account_Billing();
|
119 |
+
$this->_billing->loadData($store);
|
120 |
+
}
|
121 |
+
|
122 |
+
/**
|
123 |
+
* Sets the store title.
|
124 |
+
*
|
125 |
+
* @param string $title the store title.
|
126 |
+
*/
|
127 |
+
public function setTitle($title)
|
128 |
+
{
|
129 |
+
$this->_title = $title;
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* The shops name for which the account is to be created for.
|
134 |
+
*
|
135 |
+
* @return string the name.
|
136 |
+
*/
|
137 |
+
public function getTitle()
|
138 |
+
{
|
139 |
+
return $this->_title;
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Sets the account name.
|
144 |
+
*
|
145 |
+
* @param string $name the account name.
|
146 |
+
*/
|
147 |
+
public function setName($name)
|
148 |
+
{
|
149 |
+
$this->_name = $name;
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* The name of the account to create.
|
154 |
+
* This has to follow the pattern of
|
155 |
+
* "[platform name]-[8 character lowercase alpha numeric string]".
|
156 |
+
*
|
157 |
+
* @return string the account name.
|
158 |
+
*/
|
159 |
+
public function getName()
|
160 |
+
{
|
161 |
+
return $this->_name;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* The name of the platform the account is used on.
|
166 |
+
* A list of valid platform names is issued by Nosto.
|
167 |
+
*
|
168 |
+
* @return string the platform names.
|
169 |
+
*/
|
170 |
+
public function getPlatform()
|
171 |
+
{
|
172 |
+
return 'magento';
|
173 |
+
}
|
174 |
+
|
175 |
+
/**
|
176 |
+
* Sets the store front page url.
|
177 |
+
*
|
178 |
+
* @param string $url the front page url.
|
179 |
+
*/
|
180 |
+
public function setFrontPageUrl($url)
|
181 |
+
{
|
182 |
+
$this->_frontPageUrl = $url;
|
183 |
+
}
|
184 |
+
|
185 |
+
/**
|
186 |
+
* Absolute url to the front page of the shop for which the account is
|
187 |
+
* created for.
|
188 |
+
*
|
189 |
+
* @return string the url.
|
190 |
+
*/
|
191 |
+
public function getFrontPageUrl()
|
192 |
+
{
|
193 |
+
return $this->_frontPageUrl;
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Sets the store currency ISO (ISO 4217) code.
|
198 |
+
*
|
199 |
+
* @param string $code the currency ISO code.
|
200 |
+
*/
|
201 |
+
public function setCurrencyCode($code)
|
202 |
+
{
|
203 |
+
$this->_currencyCode = $code;
|
204 |
+
}
|
205 |
+
|
206 |
+
/**
|
207 |
+
* The 3-letter ISO code (ISO 4217) for the currency used by the shop for
|
208 |
+
* which the account is created for.
|
209 |
+
*
|
210 |
+
* @return string the currency ISO code.
|
211 |
+
*/
|
212 |
+
public function getCurrencyCode()
|
213 |
+
{
|
214 |
+
return $this->_currencyCode;
|
215 |
+
}
|
216 |
+
|
217 |
+
/**
|
218 |
+
* Sets the store language ISO (ISO 639-1) code.
|
219 |
+
*
|
220 |
+
* @param string $languageCode the language ISO code.
|
221 |
+
*/
|
222 |
+
public function setLanguageCode($languageCode)
|
223 |
+
{
|
224 |
+
$this->_languageCode = $languageCode;
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* The 2-letter ISO code (ISO 639-1) for the language used by the shop for
|
229 |
+
* which the account is created for.
|
230 |
+
*
|
231 |
+
* @return string the language ISO code.
|
232 |
+
*/
|
233 |
+
public function getLanguageCode()
|
234 |
+
{
|
235 |
+
return $this->_languageCode;
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Sets the owner language ISO (ISO 639-1) code.
|
240 |
+
*
|
241 |
+
* @param string $languageCode the language ISO code.
|
242 |
+
*/
|
243 |
+
public function setOwnerLanguageCode($languageCode)
|
244 |
+
{
|
245 |
+
$this->_ownerLanguageCode = $languageCode;
|
246 |
+
}
|
247 |
+
|
248 |
+
/**
|
249 |
+
* The 2-letter ISO code (ISO 639-1) for the language of the account owner
|
250 |
+
* who is creating the account.
|
251 |
+
*
|
252 |
+
* @return string the language ISO code.
|
253 |
+
*/
|
254 |
+
public function getOwnerLanguageCode()
|
255 |
+
{
|
256 |
+
return $this->_ownerLanguageCode;
|
257 |
+
}
|
258 |
+
|
259 |
+
/**
|
260 |
+
* Meta data model for the account owner who is creating the account.
|
261 |
+
*
|
262 |
+
* @return NostoAccountMetaDataOwnerInterface the meta data model.
|
263 |
+
*/
|
264 |
+
public function getOwner()
|
265 |
+
{
|
266 |
+
return $this->_owner;
|
267 |
+
}
|
268 |
+
|
269 |
+
/**
|
270 |
+
* Meta data model for the account billing details.
|
271 |
+
*
|
272 |
+
* @return NostoAccountMetaDataBillingDetailsInterface the meta data model.
|
273 |
+
*/
|
274 |
+
public function getBillingDetails()
|
275 |
+
{
|
276 |
+
return $this->_billing;
|
277 |
+
}
|
278 |
+
|
279 |
+
/**
|
280 |
+
* The API token used to identify an account creation.
|
281 |
+
* This token is platform specific and issued by Nosto.
|
282 |
+
*
|
283 |
+
* @return string the API token.
|
284 |
+
*/
|
285 |
+
public function getSignUpApiToken()
|
286 |
+
{
|
287 |
+
return $this->_signUpApiToken;
|
288 |
+
}
|
289 |
+
}
|
app/code/community/Nosto/Tagging/Model/Meta/Account/Billing.php
ADDED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Meta data class which holds information about Nosto account billing.
|
30 |
+
* This is used during the Nosto account creation.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Model_Meta_Account_Billing extends Mage_Core_Model_Abstract implements NostoAccountMetaDataBillingDetailsInterface
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* @var string country ISO (ISO 3166-1 alpha-2) code for billing details.
|
40 |
+
*/
|
41 |
+
protected $_country;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @inheritdoc
|
45 |
+
*/
|
46 |
+
protected function _construct()
|
47 |
+
{
|
48 |
+
$this->_init('nosto_tagging/meta_account_billing');
|
49 |
+
}
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Loads the meta data for the given store.
|
53 |
+
*
|
54 |
+
* @param Mage_Core_Model_Store $store the store view to load the data for.
|
55 |
+
*/
|
56 |
+
public function loadData(Mage_Core_Model_Store $store)
|
57 |
+
{
|
58 |
+
$this->_country = $store->getConfig('general/country/default');
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Sets the account billing details country ISO (ISO 3166-1 alpha-2) code.
|
63 |
+
*
|
64 |
+
* @param string $country the country ISO code.
|
65 |
+
*/
|
66 |
+
public function setCountry($country)
|
67 |
+
{
|
68 |
+
$this->_country = $country;
|
69 |
+
}
|
70 |
+
|
71 |
+
/**
|
72 |
+
* The 2-letter ISO code (ISO 3166-1 alpha-2) for billing details country.
|
73 |
+
*
|
74 |
+
* @return string the country ISO code.
|
75 |
+
*/
|
76 |
+
public function getCountry()
|
77 |
+
{
|
78 |
+
return $this->_country;
|
79 |
+
}
|
80 |
+
}
|
app/code/community/Nosto/Tagging/Model/Meta/Account/Iframe.php
ADDED
@@ -0,0 +1,361 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Meta data class which holds information to be sent to the Nosto account
|
30 |
+
* configuration iframe.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Model_Meta_Account_Iframe extends Mage_Core_Model_Abstract implements NostoAccountMetaDataIframeInterface
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* @var string the name of the platform the iframe is used on.
|
40 |
+
*/
|
41 |
+
protected $_platform = 'magento';
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @var string the admin user first name.
|
45 |
+
*/
|
46 |
+
protected $_firstName;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* @var string the admin user last name.
|
50 |
+
*/
|
51 |
+
protected $_lastName;
|
52 |
+
|
53 |
+
/**
|
54 |
+
* @var string the admin user email address.
|
55 |
+
*/
|
56 |
+
protected $_email;
|
57 |
+
|
58 |
+
/**
|
59 |
+
* @var string the language ISO (ISO 639-1) code for oauth server locale.
|
60 |
+
*/
|
61 |
+
protected $_languageIsoCode;
|
62 |
+
|
63 |
+
/**
|
64 |
+
* @var string the language ISO (ISO 639-1) for the store view scope.
|
65 |
+
*/
|
66 |
+
protected $_languageIsoCodeShop;
|
67 |
+
|
68 |
+
/**
|
69 |
+
* @var string unique ID that identifies the Magento installation.
|
70 |
+
*/
|
71 |
+
protected $_uniqueId;
|
72 |
+
|
73 |
+
/**
|
74 |
+
* @var string preview url for the product page in the active store scope.
|
75 |
+
*/
|
76 |
+
protected $_previewUrlProduct;
|
77 |
+
|
78 |
+
/**
|
79 |
+
* @var string preview url for the category page in the active store scope.
|
80 |
+
*/
|
81 |
+
protected $_previewUrlCategory;
|
82 |
+
|
83 |
+
/**
|
84 |
+
* @var string preview url for the search page in the active store scope.
|
85 |
+
*/
|
86 |
+
protected $_previewUrlSearch;
|
87 |
+
|
88 |
+
/**
|
89 |
+
* @var string preview url for the cart page in the active store scope.
|
90 |
+
*/
|
91 |
+
protected $_previewUrlCart;
|
92 |
+
|
93 |
+
/**
|
94 |
+
* @var string preview url for the front page in the active store scope.
|
95 |
+
*/
|
96 |
+
protected $_previewUrlFront;
|
97 |
+
|
98 |
+
/**
|
99 |
+
* @var string the name of the store Nosto is installed in or about to be installed.
|
100 |
+
*/
|
101 |
+
protected $_shopName;
|
102 |
+
|
103 |
+
/**
|
104 |
+
* @inheritdoc
|
105 |
+
*/
|
106 |
+
protected function _construct()
|
107 |
+
{
|
108 |
+
$this->_init('nosto_tagging/meta_account_iframe');
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Loads the meta data for the given store.
|
113 |
+
*
|
114 |
+
* @param Mage_Core_Model_Store $store the store view to load the data for.
|
115 |
+
*/
|
116 |
+
public function loadData(Mage_Core_Model_Store $store)
|
117 |
+
{
|
118 |
+
/** @var Mage_Admin_Model_User $user */
|
119 |
+
$user = Mage::getSingleton('admin/session')->getUser();
|
120 |
+
/** @var Nosto_Tagging_Helper_Url $urlHelper */
|
121 |
+
$urlHelper = Mage::helper('nosto_tagging/url');
|
122 |
+
/** @var Nosto_Tagging_Helper_Data $dataHelper */
|
123 |
+
$dataHelper = Mage::helper('nosto_tagging/data');
|
124 |
+
|
125 |
+
$this->_firstName = $user->getFirstname();
|
126 |
+
$this->_lastName = $user->getLastname();
|
127 |
+
$this->_email = $user->getEmail();
|
128 |
+
$this->_languageIsoCode = substr(
|
129 |
+
Mage::app()->getLocale()->getLocaleCode(), 0, 2
|
130 |
+
);
|
131 |
+
$this->_languageIsoCodeShop = substr(
|
132 |
+
$store->getConfig('general/locale/code'), 0, 2
|
133 |
+
);
|
134 |
+
$this->_uniqueId = $dataHelper->getInstallationId();
|
135 |
+
$this->_previewUrlProduct = $urlHelper->getPreviewUrlProduct($store);
|
136 |
+
$this->_previewUrlCategory = $urlHelper->getPreviewUrlCategory($store);
|
137 |
+
$this->_previewUrlSearch = $urlHelper->getPreviewUrlSearch($store);
|
138 |
+
$this->_previewUrlCart = $urlHelper->getPreviewUrlCart($store);
|
139 |
+
$this->_previewUrlFront = $urlHelper->getPreviewUrlFront($store);
|
140 |
+
$this->_shopName = $store->getName();
|
141 |
+
}
|
142 |
+
|
143 |
+
/**
|
144 |
+
* The name of the platform the iframe is used on.
|
145 |
+
* A list of valid platform names is issued by Nosto.
|
146 |
+
*
|
147 |
+
* @return string the platform name.
|
148 |
+
*/
|
149 |
+
public function getPlatform()
|
150 |
+
{
|
151 |
+
return $this->_platform;
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Sets the first name of the admin user.
|
156 |
+
*
|
157 |
+
* @param string $firstName the first name.
|
158 |
+
*/
|
159 |
+
public function setFirstName($firstName)
|
160 |
+
{
|
161 |
+
$this->_firstName = $firstName;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* The first name of the user who is loading the config iframe.
|
166 |
+
*
|
167 |
+
* @return string the first name.
|
168 |
+
*/
|
169 |
+
public function getFirstName()
|
170 |
+
{
|
171 |
+
return $this->_firstName;
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Sets the last name of the admin user.
|
176 |
+
*
|
177 |
+
* @param string $lastName the last name.
|
178 |
+
*/
|
179 |
+
public function setLastName($lastName)
|
180 |
+
{
|
181 |
+
$this->_lastName = $lastName;
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* The last name of the user who is loading the config iframe.
|
186 |
+
*
|
187 |
+
* @return string the last name.
|
188 |
+
*/
|
189 |
+
public function getLastName()
|
190 |
+
{
|
191 |
+
return $this->_lastName;
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* Sets the email address of the admin user.
|
196 |
+
*
|
197 |
+
* @param string $email the email address.
|
198 |
+
*/
|
199 |
+
public function setEmail($email)
|
200 |
+
{
|
201 |
+
$this->_email = $email;
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* The email address of the user who is loading the config iframe.
|
206 |
+
*
|
207 |
+
* @return string the email address.
|
208 |
+
*/
|
209 |
+
public function getEmail()
|
210 |
+
{
|
211 |
+
return $this->_email;
|
212 |
+
}
|
213 |
+
|
214 |
+
/**
|
215 |
+
* Sets the language ISO code.
|
216 |
+
*
|
217 |
+
* @param string $code the ISO code.
|
218 |
+
*/
|
219 |
+
public function setLanguageIsoCode($code)
|
220 |
+
{
|
221 |
+
$this->_languageIsoCode = $code;
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* The 2-letter ISO code (ISO 639-1) for the language of the user who is
|
226 |
+
* loading the config iframe.
|
227 |
+
*
|
228 |
+
* @return string the language ISO code.
|
229 |
+
*/
|
230 |
+
public function getLanguageIsoCode()
|
231 |
+
{
|
232 |
+
return $this->_languageIsoCode;
|
233 |
+
}
|
234 |
+
|
235 |
+
/**
|
236 |
+
* The 2-letter ISO code (ISO 639-1) for the language of the shop the
|
237 |
+
* account belongs to.
|
238 |
+
*
|
239 |
+
* @return string the language ISO code.
|
240 |
+
*/
|
241 |
+
public function getLanguageIsoCodeShop()
|
242 |
+
{
|
243 |
+
return $this->_languageIsoCodeShop;
|
244 |
+
}
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Unique identifier for the e-commerce installation.
|
248 |
+
* This identifier is used to link accounts together that are created on
|
249 |
+
* the same installation.
|
250 |
+
*
|
251 |
+
* @return string the identifier.
|
252 |
+
*/
|
253 |
+
public function getUniqueId()
|
254 |
+
{
|
255 |
+
return $this->_uniqueId;
|
256 |
+
}
|
257 |
+
|
258 |
+
/**
|
259 |
+
* The version number of the platform the e-commerce installation is
|
260 |
+
* running on.
|
261 |
+
*
|
262 |
+
* @return string the platform version.
|
263 |
+
*/
|
264 |
+
public function getVersionPlatform()
|
265 |
+
{
|
266 |
+
return Mage::getVersion();
|
267 |
+
}
|
268 |
+
|
269 |
+
/**
|
270 |
+
* The version number of the Nosto module/extension running on the
|
271 |
+
* e-commerce installation.
|
272 |
+
*
|
273 |
+
* @return string the module version.
|
274 |
+
*/
|
275 |
+
public function getVersionModule()
|
276 |
+
{
|
277 |
+
// Path is hard-coded to be like in "etc/config.xml".
|
278 |
+
return (string)Mage::getConfig()
|
279 |
+
->getNode('modules/Nosto_Tagging/version');
|
280 |
+
}
|
281 |
+
|
282 |
+
/**
|
283 |
+
* An absolute URL for any product page in the shop the account is linked
|
284 |
+
* to, with the nostodebug GET parameter enabled.
|
285 |
+
* e.g. http://myshop.com/products/product123?nostodebug=true
|
286 |
+
* This is used in the config iframe to allow the user to quickly preview
|
287 |
+
* the recommendations on the given page.
|
288 |
+
*
|
289 |
+
* @return string the url.
|
290 |
+
*/
|
291 |
+
public function getPreviewUrlProduct()
|
292 |
+
{
|
293 |
+
return $this->_previewUrlProduct;
|
294 |
+
}
|
295 |
+
|
296 |
+
/**
|
297 |
+
* An absolute URL for any category page in the shop the account is linked
|
298 |
+
* to, with the nostodebug GET parameter enabled.
|
299 |
+
* e.g. http://myshop.com/products/category123?nostodebug=true
|
300 |
+
* This is used in the config iframe to allow the user to quickly preview
|
301 |
+
* the recommendations on the given page.
|
302 |
+
*
|
303 |
+
* @return string the url.
|
304 |
+
*/
|
305 |
+
public function getPreviewUrlCategory()
|
306 |
+
{
|
307 |
+
return $this->_previewUrlCategory;
|
308 |
+
}
|
309 |
+
|
310 |
+
/**
|
311 |
+
* An absolute URL for the search page in the shop the account is linked
|
312 |
+
* to, with the nostodebug GET parameter enabled.
|
313 |
+
* e.g. http://myshop.com/search?query=red?nostodebug=true
|
314 |
+
* This is used in the config iframe to allow the user to quickly preview
|
315 |
+
* the recommendations on the given page.
|
316 |
+
*
|
317 |
+
* @return string the url.
|
318 |
+
*/
|
319 |
+
public function getPreviewUrlSearch()
|
320 |
+
{
|
321 |
+
return $this->_previewUrlSearch;
|
322 |
+
}
|
323 |
+
|
324 |
+
/**
|
325 |
+
* An absolute URL for the shopping cart page in the shop the account is
|
326 |
+
* linked to, with the nostodebug GET parameter enabled.
|
327 |
+
* e.g. http://myshop.com/cart?nostodebug=true
|
328 |
+
* This is used in the config iframe to allow the user to quickly preview
|
329 |
+
* the recommendations on the given page.
|
330 |
+
*
|
331 |
+
* @return string the url.
|
332 |
+
*/
|
333 |
+
public function getPreviewUrlCart()
|
334 |
+
{
|
335 |
+
return $this->_previewUrlCart;
|
336 |
+
}
|
337 |
+
|
338 |
+
/**
|
339 |
+
* An absolute URL for the front page in the shop the account is linked to,
|
340 |
+
* with the nostodebug GET parameter enabled.
|
341 |
+
* e.g. http://myshop.com?nostodebug=true
|
342 |
+
* This is used in the config iframe to allow the user to quickly preview
|
343 |
+
* the recommendations on the given page.
|
344 |
+
*
|
345 |
+
* @return string the url.
|
346 |
+
*/
|
347 |
+
public function getPreviewUrlFront()
|
348 |
+
{
|
349 |
+
return $this->_previewUrlFront;
|
350 |
+
}
|
351 |
+
|
352 |
+
/**
|
353 |
+
* Returns the name of the shop context where Nosto is installed or about to be installed in.
|
354 |
+
*
|
355 |
+
* @return string the name.
|
356 |
+
*/
|
357 |
+
public function getShopName()
|
358 |
+
{
|
359 |
+
return $this->_shopName;
|
360 |
+
}
|
361 |
+
}
|
app/code/community/Nosto/Tagging/Model/Meta/Account/Owner.php
ADDED
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Meta data class which holds information about the Nosto account owner.
|
30 |
+
* This is used during the Nosto account creation.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Model_Meta_Account_Owner extends Mage_Core_Model_Abstract implements NostoAccountMetaDataOwnerInterface
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* @var string the account owner first name.
|
40 |
+
*/
|
41 |
+
protected $_firstName;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @var string the account owner last name.
|
45 |
+
*/
|
46 |
+
protected $_lastName;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* @var string the account owner email address.
|
50 |
+
*/
|
51 |
+
protected $_email;
|
52 |
+
|
53 |
+
/**
|
54 |
+
* @inheritdoc
|
55 |
+
*/
|
56 |
+
protected function _construct()
|
57 |
+
{
|
58 |
+
$this->_init('nosto_tagging/meta_account_owner');
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Loads the meta data for the given store.
|
63 |
+
*
|
64 |
+
* @param Mage_Core_Model_Store $store the store view to load the data for.
|
65 |
+
*/
|
66 |
+
public function loadData(Mage_Core_Model_Store $store)
|
67 |
+
{
|
68 |
+
/** @var Mage_Admin_Model_User $user */
|
69 |
+
$user = Mage::getSingleton('admin/session')->getUser();
|
70 |
+
$this->_firstName = $user->getFirstname();
|
71 |
+
$this->_lastName = $user->getLastname();
|
72 |
+
$this->_email = $user->getEmail();
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Sets the first name of the account owner.
|
77 |
+
*
|
78 |
+
* @param string $firstName the first name.
|
79 |
+
*/
|
80 |
+
public function setFirstName($firstName)
|
81 |
+
{
|
82 |
+
$this->_firstName = $firstName;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* The first name of the account owner.
|
87 |
+
*
|
88 |
+
* @return string the first name.
|
89 |
+
*/
|
90 |
+
public function getFirstName()
|
91 |
+
{
|
92 |
+
return $this->_firstName;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Sets the last name of the account owner.
|
97 |
+
*
|
98 |
+
* @param string $lastName the last name.
|
99 |
+
*/
|
100 |
+
public function setLastName($lastName)
|
101 |
+
{
|
102 |
+
$this->_lastName = $lastName;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* The last name of the account owner.
|
107 |
+
*
|
108 |
+
* @return string the last name.
|
109 |
+
*/
|
110 |
+
public function getLastName()
|
111 |
+
{
|
112 |
+
return $this->_lastName;
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Sets the email address of the account owner.
|
117 |
+
*
|
118 |
+
* @param string $email the email address.
|
119 |
+
*/
|
120 |
+
public function setEmail($email)
|
121 |
+
{
|
122 |
+
$this->_email = $email;
|
123 |
+
}
|
124 |
+
|
125 |
+
/**
|
126 |
+
* The email address of the account owner.
|
127 |
+
*
|
128 |
+
* @return string the email address.
|
129 |
+
*/
|
130 |
+
public function getEmail()
|
131 |
+
{
|
132 |
+
return $this->_email;
|
133 |
+
}
|
134 |
+
}
|
app/code/community/Nosto/Tagging/Model/Meta/Oauth.php
ADDED
@@ -0,0 +1,153 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Meta data class which holds information needed to complete OAuth2 requests.
|
30 |
+
*
|
31 |
+
* @category Nosto
|
32 |
+
* @package Nosto_Tagging
|
33 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
34 |
+
*/
|
35 |
+
class Nosto_Tagging_Model_Meta_Oauth extends Mage_Core_Model_Abstract implements NostoOAuthClientMetaDataInterface
|
36 |
+
{
|
37 |
+
/**
|
38 |
+
* @var string the url where the oauth2 server should redirect after
|
39 |
+
* authorization is done.
|
40 |
+
*/
|
41 |
+
protected $_redirectUrl;
|
42 |
+
|
43 |
+
/**
|
44 |
+
* @var string the language ISO code for localization on oauth2 server.
|
45 |
+
*/
|
46 |
+
protected $_languageIsoCode;
|
47 |
+
|
48 |
+
/**
|
49 |
+
* @inheritdoc
|
50 |
+
*/
|
51 |
+
protected function _construct()
|
52 |
+
{
|
53 |
+
$this->_init('nosto_tagging/meta_oauth');
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Loads the meta data for the given store.
|
58 |
+
*
|
59 |
+
* @param Mage_Core_Model_Store $store the store view to load the data for.
|
60 |
+
*/
|
61 |
+
public function loadData(Mage_Core_Model_Store $store)
|
62 |
+
{
|
63 |
+
$this->_redirectUrl = Mage::getUrl(
|
64 |
+
'nosto/oauth',
|
65 |
+
array(
|
66 |
+
'_store' => $store->getId(),
|
67 |
+
'_store_to_url' => true
|
68 |
+
)
|
69 |
+
);
|
70 |
+
$this->_languageIsoCode = substr(
|
71 |
+
Mage::app()->getLocale()->getLocaleCode(), 0, 2
|
72 |
+
);
|
73 |
+
}
|
74 |
+
|
75 |
+
/**
|
76 |
+
* The OAuth2 client ID.
|
77 |
+
* This will be a platform specific ID that Nosto will issue.
|
78 |
+
*
|
79 |
+
* @return string the client id.
|
80 |
+
*/
|
81 |
+
public function getClientId()
|
82 |
+
{
|
83 |
+
return 'magento';
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* The OAuth2 client secret.
|
88 |
+
* This will be a platform specific secret that Nosto will issue.
|
89 |
+
*
|
90 |
+
* @return string the client secret.
|
91 |
+
*/
|
92 |
+
public function getClientSecret()
|
93 |
+
{
|
94 |
+
return 'magento';
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* The scopes for the OAuth2 request.
|
99 |
+
* These are used to request specific API tokens from Nosto and should
|
100 |
+
* almost always be the ones defined in NostoApiToken::$tokenNames.
|
101 |
+
*
|
102 |
+
* @return array the scopes.
|
103 |
+
*/
|
104 |
+
public function getScopes()
|
105 |
+
{
|
106 |
+
// We want all the available Nosto API tokens.
|
107 |
+
return NostoApiToken::$tokenNames;
|
108 |
+
}
|
109 |
+
|
110 |
+
/**
|
111 |
+
* The OAuth2 redirect url to where the OAuth2 server should redirect the
|
112 |
+
* user after authorizing the application to act on the users behalf.
|
113 |
+
* This url must by publicly accessible and the domain must match the one
|
114 |
+
* defined for the Nosto account.
|
115 |
+
*
|
116 |
+
* @return string the url.
|
117 |
+
*/
|
118 |
+
public function getRedirectUrl()
|
119 |
+
{
|
120 |
+
return $this->_redirectUrl;
|
121 |
+
}
|
122 |
+
|
123 |
+
/**
|
124 |
+
* Sets the redirect url.
|
125 |
+
*
|
126 |
+
* @param string $url the url.
|
127 |
+
*/
|
128 |
+
public function setRedirectUrl($url)
|
129 |
+
{
|
130 |
+
$this->_redirectUrl = $url;
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* The 2-letter ISO code (ISO 639-1) for the language the OAuth2 server
|
135 |
+
* uses for UI localization.
|
136 |
+
*
|
137 |
+
* @return string the ISO code.
|
138 |
+
*/
|
139 |
+
public function getLanguageIsoCode()
|
140 |
+
{
|
141 |
+
return $this->_languageIsoCode;
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Sets the language ISO code.
|
146 |
+
*
|
147 |
+
* @param string $code the ISO code.
|
148 |
+
*/
|
149 |
+
public function setLanguageIsoCode($code)
|
150 |
+
{
|
151 |
+
$this->_languageIsoCode = $code;
|
152 |
+
}
|
153 |
+
}
|
app/code/community/Nosto/Tagging/Model/Meta/Order.php
ADDED
@@ -0,0 +1,190 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Meta data class which holds information about an order.
|
30 |
+
* This is used during the order confirmation API request and the order
|
31 |
+
* history export.
|
32 |
+
*
|
33 |
+
* @category Nosto
|
34 |
+
* @package Nosto_Tagging
|
35 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
36 |
+
*/
|
37 |
+
class Nosto_Tagging_Model_Meta_Order extends Mage_Core_Model_Abstract implements NostoOrderInterface
|
38 |
+
{
|
39 |
+
/**
|
40 |
+
* @var bool if the special items, e.g. shipping cost, discounts, should be
|
41 |
+
* included in the `$_items` list.
|
42 |
+
*/
|
43 |
+
public $includeSpecialItems = true;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* @var string|int the unique order number identifying the order.
|
47 |
+
*/
|
48 |
+
protected $_orderNumber;
|
49 |
+
|
50 |
+
/**
|
51 |
+
* @var string the date when the order was placed.
|
52 |
+
*/
|
53 |
+
protected $_createdDate;
|
54 |
+
|
55 |
+
/**
|
56 |
+
* @var string the payment provider used for order.
|
57 |
+
*
|
58 |
+
* Formatted according to "[provider name] [provider version]".
|
59 |
+
*/
|
60 |
+
protected $_paymentProvider;
|
61 |
+
|
62 |
+
/**
|
63 |
+
* @var Nosto_Tagging_Model_Meta_Order_Buyer The user info of the buyer.
|
64 |
+
*/
|
65 |
+
protected $_buyer;
|
66 |
+
|
67 |
+
/**
|
68 |
+
* @var Nosto_Tagging_Model_Meta_Order_Item[] the items in the order.
|
69 |
+
*/
|
70 |
+
protected $_items = array();
|
71 |
+
|
72 |
+
/**
|
73 |
+
* @inheritdoc
|
74 |
+
*/
|
75 |
+
protected function _construct()
|
76 |
+
{
|
77 |
+
$this->_init('nosto_tagging/meta_order');
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* The unique order number identifying the order.
|
82 |
+
*
|
83 |
+
* @return string|int the order number.
|
84 |
+
*/
|
85 |
+
public function getOrderNumber()
|
86 |
+
{
|
87 |
+
return $this->_orderNumber;
|
88 |
+
}
|
89 |
+
|
90 |
+
/**
|
91 |
+
* The date when the order was placed.
|
92 |
+
*
|
93 |
+
* @return string the creation date.
|
94 |
+
*/
|
95 |
+
public function getCreatedDate()
|
96 |
+
{
|
97 |
+
return $this->_createdDate;
|
98 |
+
}
|
99 |
+
|
100 |
+
/**
|
101 |
+
* The payment provider used for placing the order, formatted according to
|
102 |
+
* "[provider name] [provider version]".
|
103 |
+
*
|
104 |
+
* @return string the payment provider.
|
105 |
+
*/
|
106 |
+
public function getPaymentProvider()
|
107 |
+
{
|
108 |
+
return $this->_paymentProvider;
|
109 |
+
}
|
110 |
+
|
111 |
+
/**
|
112 |
+
* The buyer info of the user who placed the order.
|
113 |
+
*
|
114 |
+
* @return NostoOrderBuyerInterface the meta data model.
|
115 |
+
*/
|
116 |
+
public function getBuyerInfo()
|
117 |
+
{
|
118 |
+
return $this->_buyer;
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* The purchased items which were included in the order.
|
123 |
+
*
|
124 |
+
* @return NostoOrderPurchasedItemInterface[] the meta data models.
|
125 |
+
*/
|
126 |
+
public function getPurchasedItems()
|
127 |
+
{
|
128 |
+
return $this->_items;
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Loads the order info from a Magento order model.
|
133 |
+
*
|
134 |
+
* @param Mage_Sales_Model_Order $order the order model.
|
135 |
+
*/
|
136 |
+
public function loadData(Mage_Sales_Model_Order $order)
|
137 |
+
{
|
138 |
+
$this->_orderNumber = $order->getId();
|
139 |
+
$this->_createdDate = $order->getCreatedAt();
|
140 |
+
|
141 |
+
$method = $order->getPayment()->getMethodInstance();
|
142 |
+
$this->_paymentProvider = $method->getCode();
|
143 |
+
|
144 |
+
$this->_buyer = new Nosto_Tagging_Model_Meta_Order_Buyer();
|
145 |
+
$this->_buyer->loadData($order);
|
146 |
+
|
147 |
+
/** @var $item Mage_Sales_Model_Order_Item */
|
148 |
+
foreach ($order->getAllVisibleItems() as $item) {
|
149 |
+
/** @var Mage_Catalog_Model_Product $product */
|
150 |
+
$product = Mage::getModel('catalog/product')
|
151 |
+
->load($item->getProductId());
|
152 |
+
if ($product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) {
|
153 |
+
if ((int)$product->getPriceType() === Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED) {
|
154 |
+
continue;
|
155 |
+
}
|
156 |
+
foreach ($item->getChildrenItems() as $child) {
|
157 |
+
$orderItem = new Nosto_Tagging_Model_Meta_Order_Item();
|
158 |
+
$orderItem->loadData($child);
|
159 |
+
$this->_items[] = $orderItem;
|
160 |
+
}
|
161 |
+
} else {
|
162 |
+
$orderItem = new Nosto_Tagging_Model_Meta_Order_Item();
|
163 |
+
$orderItem->loadData($item);
|
164 |
+
$this->_items[] = $orderItem;
|
165 |
+
}
|
166 |
+
}
|
167 |
+
|
168 |
+
if ($this->includeSpecialItems) {
|
169 |
+
if (($discount = $order->getDiscountAmount()) > 0) {
|
170 |
+
$orderItem = new Nosto_Tagging_Model_Meta_Order_Item();
|
171 |
+
$orderItem->setProductId(-1);
|
172 |
+
$orderItem->setQuantity(1);
|
173 |
+
$orderItem->setName('Discount');
|
174 |
+
$orderItem->setUnitPrice($discount);
|
175 |
+
$orderItem->setCurrencyCode($order->getOrderCurrencyCode());
|
176 |
+
$this->_items[] = $orderItem;
|
177 |
+
}
|
178 |
+
|
179 |
+
if (($shippingInclTax = $order->getShippingInclTax()) > 0) {
|
180 |
+
$orderItem = new Nosto_Tagging_Model_Meta_Order_Item();
|
181 |
+
$orderItem->setProductId(-1);
|
182 |
+
$orderItem->setQuantity(1);
|
183 |
+
$orderItem->setName('Shipping and handling');
|
184 |
+
$orderItem->setUnitPrice($shippingInclTax);
|
185 |
+
$orderItem->setCurrencyCode($order->getOrderCurrencyCode());
|
186 |
+
$this->_items[] = $orderItem;
|
187 |
+
}
|
188 |
+
}
|
189 |
+
}
|
190 |
+
}
|
app/code/community/Nosto/Tagging/Model/Meta/Order/Buyer.php
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Meta data class which holds information about the buyer of an order.
|
30 |
+
* This is used during the order confirmation API request and the order history
|
31 |
+
* export.
|
32 |
+
*
|
33 |
+
* @category Nosto
|
34 |
+
* @package Nosto_Tagging
|
35 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
36 |
+
*/
|
37 |
+
class Nosto_Tagging_Model_Meta_Order_Buyer extends Mage_Core_Model_Abstract implements NostoOrderBuyerInterface
|
38 |
+
{
|
39 |
+
/**
|
40 |
+
* @var string the first name of the user who placed the order.
|
41 |
+
*/
|
42 |
+
protected $_firstName;
|
43 |
+
|
44 |
+
/**
|
45 |
+
* @var string the last name of the user who placed the order.
|
46 |
+
*/
|
47 |
+
protected $_lastName;
|
48 |
+
|
49 |
+
/**
|
50 |
+
* @var string the email address of the user who placed the order.
|
51 |
+
*/
|
52 |
+
protected $_email;
|
53 |
+
|
54 |
+
/**
|
55 |
+
* @inheritdoc
|
56 |
+
*/
|
57 |
+
protected function _construct()
|
58 |
+
{
|
59 |
+
$this->_init('nosto_tagging/meta_order_buyer');
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Gets the first name of the user who placed the order.
|
64 |
+
*
|
65 |
+
* @return string the first name.
|
66 |
+
*/
|
67 |
+
public function getFirstName()
|
68 |
+
{
|
69 |
+
return $this->_firstName;
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Gets the last name of the user who placed the order.
|
74 |
+
*
|
75 |
+
* @return string the last name.
|
76 |
+
*/
|
77 |
+
public function getLastName()
|
78 |
+
{
|
79 |
+
return $this->_lastName;
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Gets the email address of the user who placed the order.
|
84 |
+
*
|
85 |
+
* @return string the email address.
|
86 |
+
*/
|
87 |
+
public function getEmail()
|
88 |
+
{
|
89 |
+
return $this->_email;
|
90 |
+
}
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Loads the buyer info from a Magento order model.
|
94 |
+
*
|
95 |
+
* @param Mage_Sales_Model_Order $order the order model.
|
96 |
+
*/
|
97 |
+
public function loadData(Mage_Sales_Model_Order $order)
|
98 |
+
{
|
99 |
+
$this->_firstName = $order->getCustomerFirstname();
|
100 |
+
$this->_lastName = $order->getCustomerLastname();
|
101 |
+
$this->_email = $order->getCustomerEmail();
|
102 |
+
}
|
103 |
+
}
|
app/code/community/Nosto/Tagging/Model/Meta/Order/Item.php
ADDED
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Meta data class which holds information about an item included in an order.
|
30 |
+
* This is used during the order confirmation API request and the order history
|
31 |
+
* export.
|
32 |
+
*
|
33 |
+
* @category Nosto
|
34 |
+
* @package Nosto_Tagging
|
35 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
36 |
+
*/
|
37 |
+
class Nosto_Tagging_Model_Meta_Order_Item extends Mage_Core_Model_Abstract implements NostoOrderPurchasedItemInterface
|
38 |
+
{
|
39 |
+
/**
|
40 |
+
* @var string|int the unique identifier of the purchased item.
|
41 |
+
* If this item is for discounts or shipping cost, the id can be 0.
|
42 |
+
*/
|
43 |
+
protected $_productId;
|
44 |
+
|
45 |
+
/**
|
46 |
+
* @var int the quantity of the item included in the order.
|
47 |
+
*/
|
48 |
+
protected $_quantity;
|
49 |
+
|
50 |
+
/**
|
51 |
+
* @var string the name of the item included in the order.
|
52 |
+
*/
|
53 |
+
protected $_name;
|
54 |
+
|
55 |
+
/**
|
56 |
+
* @var float The unit price of the item included in the order.
|
57 |
+
*/
|
58 |
+
protected $_unitPrice;
|
59 |
+
|
60 |
+
/**
|
61 |
+
* @var string the 3-letter ISO code (ISO 4217) for the item currency.
|
62 |
+
*/
|
63 |
+
protected $_currencyCode;
|
64 |
+
|
65 |
+
/**
|
66 |
+
* @inheritdoc
|
67 |
+
*/
|
68 |
+
protected function _construct()
|
69 |
+
{
|
70 |
+
$this->_init('nosto_tagging/meta_order_item');
|
71 |
+
}
|
72 |
+
|
73 |
+
/**
|
74 |
+
* The unique identifier of the purchased item.
|
75 |
+
* If this item is for discounts or shipping cost, the id can be 0.
|
76 |
+
*
|
77 |
+
* @return string|int
|
78 |
+
*/
|
79 |
+
public function getProductId()
|
80 |
+
{
|
81 |
+
return $this->_productId;
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Sets the unique identifier for the item.
|
86 |
+
*
|
87 |
+
* @param string|int $id the product id.
|
88 |
+
*/
|
89 |
+
public function setProductId($id)
|
90 |
+
{
|
91 |
+
$this->_productId = $id;
|
92 |
+
}
|
93 |
+
|
94 |
+
/**
|
95 |
+
* The quantity of the item included in the order.
|
96 |
+
*
|
97 |
+
* @return int the quantity.
|
98 |
+
*/
|
99 |
+
public function getQuantity()
|
100 |
+
{
|
101 |
+
return $this->_quantity;
|
102 |
+
}
|
103 |
+
|
104 |
+
/**
|
105 |
+
* Sets the item quantity.
|
106 |
+
*
|
107 |
+
* @param int $qty the quantity.
|
108 |
+
*/
|
109 |
+
public function setQuantity($qty)
|
110 |
+
{
|
111 |
+
$this->_quantity = $qty;
|
112 |
+
}
|
113 |
+
|
114 |
+
/**
|
115 |
+
* The name of the item included in the order.
|
116 |
+
*
|
117 |
+
* @return string the name.
|
118 |
+
*/
|
119 |
+
public function getName()
|
120 |
+
{
|
121 |
+
return $this->_name;
|
122 |
+
}
|
123 |
+
|
124 |
+
/**
|
125 |
+
* Sets the item name.
|
126 |
+
*
|
127 |
+
* @param string $name the item name.
|
128 |
+
*/
|
129 |
+
public function setName($name)
|
130 |
+
{
|
131 |
+
$this->_name = $name;
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* The unit price of the item included in the order.
|
136 |
+
*
|
137 |
+
* @return float the unit price.
|
138 |
+
*/
|
139 |
+
public function getUnitPrice()
|
140 |
+
{
|
141 |
+
return $this->_unitPrice;
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Sets the item unit price.
|
146 |
+
*
|
147 |
+
* @param float $price the item unit price.
|
148 |
+
*/
|
149 |
+
public function setUnitPrice($price)
|
150 |
+
{
|
151 |
+
$this->_unitPrice = $price;
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* The 3-letter ISO code (ISO 4217) for the item currency.
|
156 |
+
*
|
157 |
+
* @return string the currency ISO code.
|
158 |
+
*/
|
159 |
+
public function getCurrencyCode()
|
160 |
+
{
|
161 |
+
return $this->_currencyCode;
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Sets the items currency code (ISO 4217).
|
166 |
+
*
|
167 |
+
* @param string $code the currency ISO code.
|
168 |
+
*/
|
169 |
+
public function setCurrencyCode($code)
|
170 |
+
{
|
171 |
+
$this->_currencyCode = $code;
|
172 |
+
}
|
173 |
+
|
174 |
+
/**
|
175 |
+
* Loads the item info from the Magento order item model.
|
176 |
+
*
|
177 |
+
* @param Mage_Sales_Model_Order_Item $item the item model.
|
178 |
+
*/
|
179 |
+
public function loadData(Mage_Sales_Model_Order_Item $item)
|
180 |
+
{
|
181 |
+
switch ($item->getProductType()) {
|
182 |
+
case Mage_Catalog_Model_Product_Type::TYPE_GROUPED:
|
183 |
+
$info = $item->getProductOptionByCode('info_buyRequest');
|
184 |
+
if ($info !== null && isset($info['super_product_config']['product_id'])) {
|
185 |
+
$this->_productId = (int)$info['super_product_config']['product_id'];
|
186 |
+
} else {
|
187 |
+
$this->_productId = (int)$item->getProductId();
|
188 |
+
}
|
189 |
+
break;
|
190 |
+
|
191 |
+
default:
|
192 |
+
$this->_productId = (int)$item->getProductId();
|
193 |
+
break;
|
194 |
+
}
|
195 |
+
|
196 |
+
$this->_quantity = (int)$item->getQtyOrdered();
|
197 |
+
$this->_name = $item->getName();
|
198 |
+
$this->_unitPrice = $item->getPriceInclTax();
|
199 |
+
$this->_currencyCode = $item->getOrder()->getOrderCurrencyCode();
|
200 |
+
}
|
201 |
+
}
|
app/code/community/Nosto/Tagging/Model/Meta/Product.php
ADDED
@@ -0,0 +1,392 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Meta data class which holds information about a product.
|
30 |
+
* This is used during the order confirmation API request and the product
|
31 |
+
* history export.
|
32 |
+
*
|
33 |
+
* @category Nosto
|
34 |
+
* @package Nosto_Tagging
|
35 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
36 |
+
*/
|
37 |
+
class Nosto_Tagging_Model_Meta_Product extends Mage_Core_Model_Abstract implements NostoProductInterface
|
38 |
+
{
|
39 |
+
/**
|
40 |
+
* Product "in stock" tagging string.
|
41 |
+
*/
|
42 |
+
const PRODUCT_IN_STOCK = 'InStock';
|
43 |
+
|
44 |
+
/**
|
45 |
+
* Product "out of stock" tagging string.
|
46 |
+
*/
|
47 |
+
const PRODUCT_OUT_OF_STOCK = 'OutOfStock';
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Product "can be directly added to cart" tag string.
|
51 |
+
*/
|
52 |
+
const PRODUCT_ADD_TO_CART = 'add-to-cart';
|
53 |
+
|
54 |
+
/**
|
55 |
+
* @var string the absolute url to the product page in the shop frontend.
|
56 |
+
*/
|
57 |
+
protected $_url;
|
58 |
+
|
59 |
+
/**
|
60 |
+
* @var string the product's unique identifier.
|
61 |
+
*/
|
62 |
+
protected $_productId;
|
63 |
+
|
64 |
+
/**
|
65 |
+
* @var string the name of the product.
|
66 |
+
*/
|
67 |
+
protected $_name;
|
68 |
+
|
69 |
+
/**
|
70 |
+
* @var string the absolute url the one of the product images in frontend.
|
71 |
+
*/
|
72 |
+
protected $_imageUrl;
|
73 |
+
|
74 |
+
/**
|
75 |
+
* @var string the product price including possible discounts and taxes.
|
76 |
+
*/
|
77 |
+
protected $_price;
|
78 |
+
|
79 |
+
/**
|
80 |
+
* @var string the product list price without discounts but incl taxes.
|
81 |
+
*/
|
82 |
+
protected $_listPrice;
|
83 |
+
|
84 |
+
/**
|
85 |
+
* @var string the currency code (ISO 4217) the product is sold in.
|
86 |
+
*/
|
87 |
+
protected $_currencyCode;
|
88 |
+
|
89 |
+
/**
|
90 |
+
* @var string the availability of the product, i.e. is in stock or not.
|
91 |
+
*/
|
92 |
+
protected $_availability;
|
93 |
+
|
94 |
+
/**
|
95 |
+
* @var array the tags for the product.
|
96 |
+
*/
|
97 |
+
protected $_tags = array();
|
98 |
+
|
99 |
+
/**
|
100 |
+
* @var array the categories the product is located in.
|
101 |
+
*/
|
102 |
+
protected $_categories = array();
|
103 |
+
|
104 |
+
/**
|
105 |
+
* @var string the product short description.
|
106 |
+
*/
|
107 |
+
protected $_shortDescription;
|
108 |
+
|
109 |
+
/**
|
110 |
+
* @var string the product description.
|
111 |
+
*/
|
112 |
+
protected $_description;
|
113 |
+
|
114 |
+
/**
|
115 |
+
* @var string the product brand name.
|
116 |
+
*/
|
117 |
+
protected $_brand;
|
118 |
+
|
119 |
+
/**
|
120 |
+
* @var string the product publication date in the shop.
|
121 |
+
*/
|
122 |
+
protected $_datePublished;
|
123 |
+
|
124 |
+
/**
|
125 |
+
* @inheritdoc
|
126 |
+
*/
|
127 |
+
protected function _construct()
|
128 |
+
{
|
129 |
+
$this->_init('nosto_tagging/meta_product');
|
130 |
+
}
|
131 |
+
|
132 |
+
/**
|
133 |
+
* Returns the absolute url to the product page in the shop frontend.
|
134 |
+
*
|
135 |
+
* @return string the url.
|
136 |
+
*/
|
137 |
+
public function getUrl()
|
138 |
+
{
|
139 |
+
return $this->_url;
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Setter for the absolute url to the product page in the shop frontend.
|
144 |
+
*
|
145 |
+
* @param $url string the url.
|
146 |
+
*/
|
147 |
+
public function setUrl($url)
|
148 |
+
{
|
149 |
+
$this->_url = $url;
|
150 |
+
}
|
151 |
+
|
152 |
+
/**
|
153 |
+
* Returns the product's unique identifier.
|
154 |
+
*
|
155 |
+
* @return int|string the ID.
|
156 |
+
*/
|
157 |
+
public function getProductId()
|
158 |
+
{
|
159 |
+
return $this->_productId;
|
160 |
+
}
|
161 |
+
|
162 |
+
/**
|
163 |
+
* Sets the product's unique identifier.
|
164 |
+
*
|
165 |
+
* @param int|string $productId the ID.
|
166 |
+
*/
|
167 |
+
public function setProductId($productId)
|
168 |
+
{
|
169 |
+
$this->_productId = $productId;
|
170 |
+
}
|
171 |
+
|
172 |
+
/**
|
173 |
+
* Returns the name of the product.
|
174 |
+
*
|
175 |
+
* @return string the name.
|
176 |
+
*/
|
177 |
+
public function getName()
|
178 |
+
{
|
179 |
+
return $this->_name;
|
180 |
+
}
|
181 |
+
|
182 |
+
/**
|
183 |
+
* Returns the absolute url the one of the product images in the frontend.
|
184 |
+
*
|
185 |
+
* @return string the url.
|
186 |
+
*/
|
187 |
+
public function getImageUrl()
|
188 |
+
{
|
189 |
+
return $this->_imageUrl;
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Returns the price of the product including possible discounts and taxes.
|
194 |
+
*
|
195 |
+
* @return float the price.
|
196 |
+
*/
|
197 |
+
public function getPrice()
|
198 |
+
{
|
199 |
+
return $this->_price;
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Returns the list price of the product without discounts but incl taxes.
|
204 |
+
*
|
205 |
+
* @return float the price.
|
206 |
+
*/
|
207 |
+
public function getListPrice()
|
208 |
+
{
|
209 |
+
return $this->_listPrice;
|
210 |
+
}
|
211 |
+
|
212 |
+
/**
|
213 |
+
* Returns the currency code (ISO 4217) the product is sold in.
|
214 |
+
*
|
215 |
+
* @return string the currency ISO code.
|
216 |
+
*/
|
217 |
+
public function getCurrencyCode()
|
218 |
+
{
|
219 |
+
return $this->_currencyCode;
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Returns the availability of the product, i.e. if it is in stock or not.
|
224 |
+
*
|
225 |
+
* @return string the availability, either "InStock" or "OutOfStock".
|
226 |
+
*/
|
227 |
+
public function getAvailability()
|
228 |
+
{
|
229 |
+
return $this->_availability;
|
230 |
+
}
|
231 |
+
|
232 |
+
/**
|
233 |
+
* Returns the tags for the product.
|
234 |
+
*
|
235 |
+
* @return array the tags array, e.g. array("winter", "shoe").
|
236 |
+
*/
|
237 |
+
public function getTags()
|
238 |
+
{
|
239 |
+
return $this->_tags;
|
240 |
+
}
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Returns the categories the product is located in.
|
244 |
+
*
|
245 |
+
* @return array list of category strings, e.g. array("/shoes/winter").
|
246 |
+
*/
|
247 |
+
public function getCategories()
|
248 |
+
{
|
249 |
+
return $this->_categories;
|
250 |
+
}
|
251 |
+
|
252 |
+
/**
|
253 |
+
* Returns the product short description.
|
254 |
+
*
|
255 |
+
* @return string the short description.
|
256 |
+
*/
|
257 |
+
public function getShortDescription()
|
258 |
+
{
|
259 |
+
return $this->_shortDescription;
|
260 |
+
}
|
261 |
+
|
262 |
+
/**
|
263 |
+
* Returns the product description.
|
264 |
+
*
|
265 |
+
* @return string the description.
|
266 |
+
*/
|
267 |
+
public function getDescription()
|
268 |
+
{
|
269 |
+
return $this->_description;
|
270 |
+
}
|
271 |
+
|
272 |
+
/**
|
273 |
+
* Returns the product brand name.
|
274 |
+
*
|
275 |
+
* @return string the brand name.
|
276 |
+
*/
|
277 |
+
public function getBrand()
|
278 |
+
{
|
279 |
+
return $this->_brand;
|
280 |
+
}
|
281 |
+
|
282 |
+
/**
|
283 |
+
* Returns the product publication date in the shop.
|
284 |
+
*
|
285 |
+
* @return string the date.
|
286 |
+
*/
|
287 |
+
public function getDatePublished()
|
288 |
+
{
|
289 |
+
return $this->_datePublished;
|
290 |
+
}
|
291 |
+
|
292 |
+
/**
|
293 |
+
* Loads the product info from a Magento product model.
|
294 |
+
*
|
295 |
+
* @param Mage_Catalog_Model_Product $product the product model.
|
296 |
+
*/
|
297 |
+
public function loadData(Mage_Catalog_Model_Product $product)
|
298 |
+
{
|
299 |
+
// Unset the cached url first, as it won't include the `___store` param.
|
300 |
+
// We need to define the specific store view in the url for the crawler
|
301 |
+
// to see the correct product data when crawling the site.
|
302 |
+
$this->_url = $product
|
303 |
+
->unsetData('url')
|
304 |
+
->getUrlInStore(array('_ignore_category' => true));
|
305 |
+
|
306 |
+
$this->_productId = $product->getId();
|
307 |
+
$this->_name = $product->getName();
|
308 |
+
|
309 |
+
if (!$product->getImage() || $product->getImage() == 'no_selection') {
|
310 |
+
$this->_imageUrl = $product->getImageUrl();
|
311 |
+
} else {
|
312 |
+
$this->_imageUrl = $product->getMediaConfig()
|
313 |
+
->getMediaUrl($product->getImage());
|
314 |
+
}
|
315 |
+
|
316 |
+
$this->_price = Mage::helper('tax')->getPrice(
|
317 |
+
$product,
|
318 |
+
Mage::helper('nosto_tagging/price')->getProductFinalPrice($product),
|
319 |
+
true
|
320 |
+
);
|
321 |
+
$this->_listPrice = Mage::helper('tax')->getPrice(
|
322 |
+
$product,
|
323 |
+
Mage::helper('nosto_tagging/price')->getProductPrice($product),
|
324 |
+
true
|
325 |
+
);
|
326 |
+
$this->_currencyCode = Mage::app()->getStore()
|
327 |
+
->getCurrentCurrencyCode();
|
328 |
+
|
329 |
+
$this->_availability = $product->isAvailable()
|
330 |
+
? self::PRODUCT_IN_STOCK
|
331 |
+
: self::PRODUCT_OUT_OF_STOCK;
|
332 |
+
|
333 |
+
if (Mage::helper('core')->isModuleEnabled('Mage_Tag')) {
|
334 |
+
$tagCollection = Mage::getModel('tag/tag')
|
335 |
+
->getCollection()
|
336 |
+
->addPopularity()
|
337 |
+
->addStatusFilter(Mage_Tag_Model_Tag::STATUS_APPROVED)
|
338 |
+
->addProductFilter($product->getId())
|
339 |
+
->setFlag('relation', true)
|
340 |
+
->addStoreFilter(Mage::app()->getStore()->getId())
|
341 |
+
->setActiveFilter();
|
342 |
+
foreach ($tagCollection as $tag) {
|
343 |
+
$this->_tags[] = $tag->getName();
|
344 |
+
}
|
345 |
+
}
|
346 |
+
|
347 |
+
if (!$product->canConfigure()) {
|
348 |
+
$this->_tags[] = self::PRODUCT_ADD_TO_CART;
|
349 |
+
}
|
350 |
+
|
351 |
+
$this->_categories = $this->getProductCategories($product);
|
352 |
+
$this->_shortDescription = (string)$product->getShortDescription();
|
353 |
+
$this->_description = (string)$product->getDescription();
|
354 |
+
$this->_brand = $product->getManufacturer()
|
355 |
+
? (string)$product->getAttributeText('manufacturer')
|
356 |
+
: '';
|
357 |
+
|
358 |
+
$this->_datePublished = $product->getCreatedAt();
|
359 |
+
}
|
360 |
+
|
361 |
+
/**
|
362 |
+
* Return array of categories for the product.
|
363 |
+
* The items in the array are strings combined of the complete category
|
364 |
+
* path to the products own category.
|
365 |
+
*
|
366 |
+
* Structure:
|
367 |
+
* array (
|
368 |
+
* /Electronics/Computers
|
369 |
+
* )
|
370 |
+
*
|
371 |
+
* @param Mage_Catalog_Model_Product $product the product model.
|
372 |
+
*
|
373 |
+
* @return array
|
374 |
+
*/
|
375 |
+
public function getProductCategories(Mage_Catalog_Model_Product $product)
|
376 |
+
{
|
377 |
+
$data = array();
|
378 |
+
|
379 |
+
if ($product instanceof Mage_Catalog_Model_Product) {
|
380 |
+
$categoryCollection = $product->getCategoryCollection();
|
381 |
+
foreach ($categoryCollection as $category) {
|
382 |
+
$categoryString = Mage::helper('nosto_tagging')
|
383 |
+
->buildCategoryString($category);
|
384 |
+
if (!empty($categoryString)) {
|
385 |
+
$data[] = $categoryString;
|
386 |
+
}
|
387 |
+
}
|
388 |
+
}
|
389 |
+
|
390 |
+
return $data;
|
391 |
+
}
|
392 |
+
}
|
app/code/community/Nosto/Tagging/Model/Observer.php
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
require_once Mage::getBaseDir('lib') . '/nosto/php-sdk/src/config.inc.php';
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Event observer model.
|
32 |
+
* Used to interact with Magento events.
|
33 |
+
*
|
34 |
+
* @category Nosto
|
35 |
+
* @package Nosto_Tagging
|
36 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
37 |
+
*/
|
38 |
+
class Nosto_Tagging_Model_Observer
|
39 |
+
{
|
40 |
+
/**
|
41 |
+
* Xml layout handle for the default page footer section.
|
42 |
+
*/
|
43 |
+
const XML_LAYOUT_PAGE_DEFAULT_FOOTER_HANDLE = 'nosto_tagging_page_default_footer';
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Adds Nosto footer block at the end of the content block.
|
47 |
+
*
|
48 |
+
* Event 'controller_action_layout_load_before'.
|
49 |
+
*
|
50 |
+
* @param Varien_Event_Observer $observer the event observer.
|
51 |
+
*
|
52 |
+
* @return Nosto_Tagging_Model_Observer
|
53 |
+
*/
|
54 |
+
public function addBlockAfterMainContent(Varien_Event_Observer $observer)
|
55 |
+
{
|
56 |
+
if (Mage::helper('nosto_tagging')->isModuleEnabled()) {
|
57 |
+
/** @var $layout Mage_Core_Model_Layout_Update */
|
58 |
+
$layout = $observer->getEvent()->getLayout()->getUpdate();
|
59 |
+
$layout->addHandle(self::XML_LAYOUT_PAGE_DEFAULT_FOOTER_HANDLE);
|
60 |
+
}
|
61 |
+
|
62 |
+
return $this;
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Event handler for the "catalog_product_save_after" event.
|
67 |
+
* Sends a product re-crawl API call to Nosto.
|
68 |
+
*
|
69 |
+
* @param Varien_Event_Observer $observer the event observer.
|
70 |
+
*
|
71 |
+
* @return Nosto_Tagging_Model_Observer
|
72 |
+
*/
|
73 |
+
public function recrawlProduct(Varien_Event_Observer $observer)
|
74 |
+
{
|
75 |
+
if (Mage::helper('nosto_tagging')->isModuleEnabled()) {
|
76 |
+
try {
|
77 |
+
/** @var Mage_Catalog_Model_Product $product */
|
78 |
+
$product = $observer->getEvent()->getProduct();
|
79 |
+
/** @var Mage_Core_Model_Store $store */
|
80 |
+
foreach (Mage::app()->getStores() as $store) {
|
81 |
+
/** @var NostoAccount $account */
|
82 |
+
$account = Mage::helper('nosto_tagging/account')
|
83 |
+
->find($store);
|
84 |
+
if ($account === null || !$account->isConnectedToNosto()) {
|
85 |
+
continue;
|
86 |
+
}
|
87 |
+
$model = new Nosto_Tagging_Model_Meta_Product();
|
88 |
+
$model->setProductId($product->getId());
|
89 |
+
$model->setUrl(
|
90 |
+
$product->unsetData('url')
|
91 |
+
->getUrlInStore(array('_store' => $store->getCode()))
|
92 |
+
);
|
93 |
+
NostoProductReCrawl::send($model, $account);
|
94 |
+
}
|
95 |
+
} catch (NostoException $e) {
|
96 |
+
Mage::log("\n" . $e->__toString(), Zend_Log::ERR, 'nostotagging.log');
|
97 |
+
}
|
98 |
+
}
|
99 |
+
|
100 |
+
return $this;
|
101 |
+
}
|
102 |
+
|
103 |
+
/**
|
104 |
+
* Sends an order confirmation API request to Nosto if the order is completed.
|
105 |
+
*
|
106 |
+
* Event 'sales_order_save_commit_after'.
|
107 |
+
*
|
108 |
+
* @param Varien_Event_Observer $observer the event observer.
|
109 |
+
*
|
110 |
+
* @return Nosto_Tagging_Model_Observer
|
111 |
+
*/
|
112 |
+
public function sendOrderConfirmation(Varien_Event_Observer $observer)
|
113 |
+
{
|
114 |
+
if (Mage::helper('nosto_tagging')->isModuleEnabled()) {
|
115 |
+
try {
|
116 |
+
/** @var Mage_Sales_Model_Order $mageOrder */
|
117 |
+
$mageOrder = $observer->getEvent()->getOrder();
|
118 |
+
$order = new Nosto_Tagging_Model_Meta_Order();
|
119 |
+
$order->loadData($mageOrder);
|
120 |
+
/** @var NostoAccount $account */
|
121 |
+
$account = Mage::helper('nosto_tagging/account')
|
122 |
+
->find($mageOrder->getStore());
|
123 |
+
$customerId = Mage::helper('nosto_tagging/customer')
|
124 |
+
->getNostoId($mageOrder);
|
125 |
+
if ($account !== null && $account->isConnectedToNosto()) {
|
126 |
+
NostoOrderConfirmation::send($order, $account, $customerId);
|
127 |
+
}
|
128 |
+
} catch (NostoException $e) {
|
129 |
+
Mage::log("\n" . $e->__toString(), Zend_Log::ERR, 'nostotagging.log');
|
130 |
+
}
|
131 |
+
}
|
132 |
+
|
133 |
+
return $this;
|
134 |
+
}
|
135 |
+
}
|
app/code/community/Nosto/Tagging/Model/Resource/Customer.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Customer resource.
|
30 |
+
* Used for keeping a link between a Mage quote and a Nosto customer.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Model_Resource_Customer extends Mage_Core_Model_Resource_Db_Abstract
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* @inheritdoc
|
40 |
+
*/
|
41 |
+
protected function _construct()
|
42 |
+
{
|
43 |
+
$this->_init('nosto_tagging/customer', 'customer_id');
|
44 |
+
}
|
45 |
+
}
|
app/code/community/Nosto/Tagging/Model/Resource/Customer/Collection.php
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Customer resource collection.
|
30 |
+
* Used for keeping a link between a Mage quote and a Nosto customer.
|
31 |
+
*
|
32 |
+
* @category Nosto
|
33 |
+
* @package Nosto_Tagging
|
34 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
35 |
+
*/
|
36 |
+
class Nosto_Tagging_Model_Resource_Customer_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
|
37 |
+
{
|
38 |
+
/**
|
39 |
+
* @inheritdoc
|
40 |
+
*/
|
41 |
+
protected function _construct()
|
42 |
+
{
|
43 |
+
$this->_init('nosto_tagging/customer');
|
44 |
+
}
|
45 |
+
}
|
app/code/community/Nosto/Tagging/Model/Resource/Setup.php
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* Nosto Tagging Resource Setup Model.
|
30 |
+
*
|
31 |
+
* @category Nosto
|
32 |
+
* @package Nosto_Tagging
|
33 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
34 |
+
*/
|
35 |
+
class Nosto_Tagging_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup
|
36 |
+
{
|
37 |
+
}
|
app/code/community/Nosto/Tagging/controllers/Adminhtml/NostoController.php
ADDED
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
require_once Mage::getBaseDir('lib') . '/nosto/php-sdk/src/config.inc.php';
|
29 |
+
|
30 |
+
/**
|
31 |
+
* Nosto admin controller.
|
32 |
+
* Handles all actions for the configuration wizard as well as redirecting
|
33 |
+
* logic for the OAuth2 authorization cycle.
|
34 |
+
*
|
35 |
+
* @category Nosto
|
36 |
+
* @package Nosto_Tagging
|
37 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
38 |
+
*/
|
39 |
+
class Nosto_Tagging_Adminhtml_NostoController extends Mage_Adminhtml_Controller_Action
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* @var array Actions which can be processed without secret key validation.
|
43 |
+
*/
|
44 |
+
protected $_publicActions = array('redirectProxy');
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Redirect action that acts as a proxy when the front end oauth controller
|
48 |
+
* redirects the admin user back to the backend after finishing the oauth
|
49 |
+
* authorization cycle.
|
50 |
+
* This is a workaround as you cannot redirect directly to a protected
|
51 |
+
* action in the backend end from the front end. The action also handles
|
52 |
+
* passing along any error/success messages.
|
53 |
+
*/
|
54 |
+
public function redirectProxyAction()
|
55 |
+
{
|
56 |
+
$session = Mage::getSingleton('adminhtml/session');
|
57 |
+
if ($session !== null) {
|
58 |
+
$type = $this->getRequest()->getParam('message_type');
|
59 |
+
$code = $this->getRequest()->getParam('message_code');
|
60 |
+
if ($type !== null && $code !== null) {
|
61 |
+
$session->setData('nosto_message', array(
|
62 |
+
'type' => $type,
|
63 |
+
'code' => $code,
|
64 |
+
));
|
65 |
+
}
|
66 |
+
}
|
67 |
+
$params = array();
|
68 |
+
if (($storeId = (int)$this->getRequest()->getParam('store')) !== 0) {
|
69 |
+
$params['store'] = $storeId;
|
70 |
+
}
|
71 |
+
$this->_redirect('*/*/index', $params);
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Shows the main config page for the extension.
|
76 |
+
*/
|
77 |
+
public function indexAction()
|
78 |
+
{
|
79 |
+
$this->_title($this->__('Nosto'));
|
80 |
+
if (!$this->getSelectedStore()) {
|
81 |
+
// If we are not under a store view, then redirect to the first
|
82 |
+
// found one. Nosto is configured per store.
|
83 |
+
foreach (Mage::app()->getWebsites() as $website) {
|
84 |
+
$storeId = $website->getDefaultGroup()->getDefaultStoreId();
|
85 |
+
if (!empty($storeId)) {
|
86 |
+
$this->_redirect('*/*/index', array('store' => $storeId));
|
87 |
+
return; // stop execution after redirect is set.
|
88 |
+
}
|
89 |
+
}
|
90 |
+
}
|
91 |
+
$this->loadLayout();
|
92 |
+
$this->renderLayout();
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Redirects user to the Nosto OAuth 2 authorization server to connect and
|
97 |
+
* existing nosto account to current scope.
|
98 |
+
*/
|
99 |
+
public function connectAccountAction()
|
100 |
+
{
|
101 |
+
$store = $this->getSelectedStore();
|
102 |
+
if ($this->getRequest()->isPost() && $store !== null) {
|
103 |
+
$client = new NostoOAuthClient(
|
104 |
+
Mage::helper('nosto_tagging/oauth')->getMetaData($store)
|
105 |
+
);
|
106 |
+
$response = new NostoXhrResponse();
|
107 |
+
$response->setSuccess(true)
|
108 |
+
->setRedirectUrl($client->getAuthorizationUrl());
|
109 |
+
}
|
110 |
+
|
111 |
+
if (!isset($response)) {
|
112 |
+
/** @var Nosto_Tagging_Helper_Account $accountHelper */
|
113 |
+
$accountHelper = Mage::helper('nosto_tagging/account');
|
114 |
+
$response = new NostoXhrResponse();
|
115 |
+
$response->setRedirectUrl(
|
116 |
+
$accountHelper->getIframeUrl(
|
117 |
+
$store,
|
118 |
+
null, // connect attempt failed, so we have no account.
|
119 |
+
array(
|
120 |
+
'message_type' => NostoMessage::TYPE_ERROR,
|
121 |
+
'message_code' => NostoMessage::CODE_ACCOUNT_CONNECT,
|
122 |
+
)
|
123 |
+
)
|
124 |
+
);
|
125 |
+
}
|
126 |
+
|
127 |
+
$this->sendXhrResponse($response);
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Creates a new Nosto account for the current scope using the Nosto API.
|
132 |
+
*/
|
133 |
+
public function createAccountAction()
|
134 |
+
{
|
135 |
+
/** @var Nosto_Tagging_Helper_Account $accountHelper */
|
136 |
+
$accountHelper = Mage::helper('nosto_tagging/account');
|
137 |
+
|
138 |
+
$store = $this->getSelectedStore();
|
139 |
+
if ($this->getRequest()->isPost() && $store !== null) {
|
140 |
+
try {
|
141 |
+
$email = $this->getRequest()->getPost('email');
|
142 |
+
$meta = $accountHelper->getMetaData($store);
|
143 |
+
if (Zend_Validate::is($email, 'EmailAddress')) {
|
144 |
+
$meta->getOwner()->setEmail($email);
|
145 |
+
}
|
146 |
+
$account = NostoAccount::create($meta);
|
147 |
+
if ($accountHelper->save($account, $store)) {
|
148 |
+
$response = new NostoXhrResponse();
|
149 |
+
$response->setSuccess(true)->setRedirectUrl(
|
150 |
+
$accountHelper->getIframeUrl(
|
151 |
+
$store,
|
152 |
+
$account,
|
153 |
+
array(
|
154 |
+
'message_type' => NostoMessage::TYPE_SUCCESS,
|
155 |
+
'message_code' => NostoMessage::CODE_ACCOUNT_CREATE,
|
156 |
+
)
|
157 |
+
)
|
158 |
+
);
|
159 |
+
}
|
160 |
+
} catch (NostoException $e) {
|
161 |
+
Mage::log(
|
162 |
+
"\n" . $e->__toString(), Zend_Log::ERR, 'nostotagging.log'
|
163 |
+
);
|
164 |
+
}
|
165 |
+
}
|
166 |
+
|
167 |
+
if (!isset($response)) {
|
168 |
+
$response = new NostoXhrResponse();
|
169 |
+
$response->setRedirectUrl(
|
170 |
+
$accountHelper->getIframeUrl(
|
171 |
+
$store,
|
172 |
+
null, // account creation failed, so we have none.
|
173 |
+
array(
|
174 |
+
'message_type' => NostoMessage::TYPE_ERROR,
|
175 |
+
'message_code' => NostoMessage::CODE_ACCOUNT_CREATE,
|
176 |
+
)
|
177 |
+
)
|
178 |
+
);
|
179 |
+
}
|
180 |
+
|
181 |
+
$this->sendXhrResponse($response);
|
182 |
+
}
|
183 |
+
|
184 |
+
/**
|
185 |
+
* Removes a Nosto account from the current scope and notifies Nosto.
|
186 |
+
*/
|
187 |
+
public function removeAccountAction()
|
188 |
+
{
|
189 |
+
/** @var Nosto_Tagging_Helper_Account $accountHelper */
|
190 |
+
$accountHelper = Mage::helper('nosto_tagging/account');
|
191 |
+
|
192 |
+
$store = $this->getSelectedStore();
|
193 |
+
if ($this->getRequest()->isPost() && $store !== null) {
|
194 |
+
$account = $accountHelper->find($store);
|
195 |
+
if ($account !== null && $accountHelper->remove($account, $store)) {
|
196 |
+
$response = new NostoXhrResponse();
|
197 |
+
$response->setSuccess(true)->setRedirectUrl(
|
198 |
+
$accountHelper->getIframeUrl(
|
199 |
+
$store,
|
200 |
+
null, // we don't have an account anymore
|
201 |
+
array(
|
202 |
+
'message_type' => NostoMessage::TYPE_SUCCESS,
|
203 |
+
'message_code' => NostoMessage::CODE_ACCOUNT_DELETE,
|
204 |
+
)
|
205 |
+
)
|
206 |
+
);
|
207 |
+
}
|
208 |
+
}
|
209 |
+
|
210 |
+
if (!isset($response)) {
|
211 |
+
$response = new NostoXhrResponse();
|
212 |
+
$response->setRedirectUrl(
|
213 |
+
$accountHelper->getIframeUrl(
|
214 |
+
$store,
|
215 |
+
$accountHelper->find($store),
|
216 |
+
array(
|
217 |
+
'message_type' => NostoMessage::TYPE_ERROR,
|
218 |
+
'message_code' => NostoMessage::CODE_ACCOUNT_DELETE,
|
219 |
+
)
|
220 |
+
)
|
221 |
+
);
|
222 |
+
}
|
223 |
+
|
224 |
+
$this->sendXhrResponse($response);
|
225 |
+
}
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Returns the currently selected store view.
|
229 |
+
* If it is single store setup, then just return the default store.
|
230 |
+
* If it is a multi store setup, the expect a store id to passed in the
|
231 |
+
* request params and return that store as the current one.
|
232 |
+
*
|
233 |
+
* @return Mage_Core_Model_Store|null the store view or null if not found.
|
234 |
+
*/
|
235 |
+
protected function getSelectedStore()
|
236 |
+
{
|
237 |
+
if (Mage::app()->isSingleStoreMode()) {
|
238 |
+
return Mage::app()->getStore(true);
|
239 |
+
} elseif (($storeId = (int)$this->getRequest()->getParam('store')) !== 0) {
|
240 |
+
return Mage::app()->getStore($storeId);
|
241 |
+
} else {
|
242 |
+
return null;
|
243 |
+
}
|
244 |
+
}
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Sends an XHR response to the browser.
|
248 |
+
*
|
249 |
+
* @param NostoXhrResponse $response the response object.
|
250 |
+
*/
|
251 |
+
protected function sendXhrResponse(NostoXhrResponse $response)
|
252 |
+
{
|
253 |
+
$this->getResponse()->setHeader('Content-type', $response->contentType);
|
254 |
+
$this->getResponse()->setBody($response->__toString());
|
255 |
+
}
|
256 |
+
}
|
app/code/community/Nosto/Tagging/controllers/ExportController.php
ADDED
@@ -0,0 +1,129 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
require_once Mage::getBaseDir('lib') . '/nosto/php-sdk/src/config.inc.php';
|
29 |
+
|
30 |
+
/**
|
31 |
+
* History data export controller.
|
32 |
+
* Handles the export of history data for orders and products that nosto can
|
33 |
+
* call when a new account has been set up.
|
34 |
+
* The exported data is encrypted with AES as the endpoint is public.
|
35 |
+
*
|
36 |
+
* @category Nosto
|
37 |
+
* @package Nosto_Tagging
|
38 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
39 |
+
*/
|
40 |
+
class Nosto_tagging_ExportController extends Mage_Core_Controller_Front_Action
|
41 |
+
{
|
42 |
+
/**
|
43 |
+
* Exports completed orders from the current store.
|
44 |
+
* Result can be limited by the `limit` and `offset` GET parameters.
|
45 |
+
*/
|
46 |
+
public function orderAction()
|
47 |
+
{
|
48 |
+
if (Mage::helper('nosto_tagging')->isModuleEnabled()) {
|
49 |
+
$pageSize = (int)$this->getRequest()->getParam('limit', 100);
|
50 |
+
$currentOffset = (int)$this->getRequest()->getParam('offset', 0);
|
51 |
+
$currentPage = ($currentOffset / $pageSize) + 1;
|
52 |
+
$orders = Mage::getModel('sales/order')
|
53 |
+
->getCollection()
|
54 |
+
->addFieldToFilter('store_id', Mage::app()->getStore()->getId())
|
55 |
+
->setPageSize($pageSize)
|
56 |
+
->setCurPage($currentPage);
|
57 |
+
if ($currentPage > $orders->getLastPageNumber()) {
|
58 |
+
$orders = array();
|
59 |
+
}
|
60 |
+
$collection = new NostoExportOrderCollection();
|
61 |
+
foreach ($orders as $order) {
|
62 |
+
$meta = new Nosto_Tagging_Model_Meta_Order();
|
63 |
+
// We don't need special items like shipping cost and discounts.
|
64 |
+
$meta->includeSpecialItems = false;
|
65 |
+
$meta->loadData($order);
|
66 |
+
$collection[] = $meta;
|
67 |
+
}
|
68 |
+
$this->export($collection);
|
69 |
+
}
|
70 |
+
}
|
71 |
+
|
72 |
+
/**
|
73 |
+
* Exports visible products from the current store.
|
74 |
+
* Result can be limited by the `limit` and `offset` GET parameters.
|
75 |
+
*/
|
76 |
+
public function productAction()
|
77 |
+
{
|
78 |
+
if (Mage::helper('nosto_tagging')->isModuleEnabled()) {
|
79 |
+
$pageSize = (int)$this->getRequest()->getParam('limit', 100);
|
80 |
+
$currentOffset = (int)$this->getRequest()->getParam('offset', 0);
|
81 |
+
$currentPage = ($currentOffset / $pageSize) + 1;
|
82 |
+
$products = Mage::getModel('catalog/product')
|
83 |
+
->getCollection()
|
84 |
+
->addStoreFilter(Mage::app()->getStore()->getId())
|
85 |
+
->addAttributeToSelect('*')
|
86 |
+
->addAttributeToFilter(
|
87 |
+
'status', array(
|
88 |
+
'eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED
|
89 |
+
)
|
90 |
+
)
|
91 |
+
->addFieldToFilter(
|
92 |
+
'visibility',
|
93 |
+
Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH
|
94 |
+
)
|
95 |
+
->setPageSize($pageSize)
|
96 |
+
->setCurPage($currentPage);
|
97 |
+
if ($currentPage > $products->getLastPageNumber()) {
|
98 |
+
$products = array();
|
99 |
+
}
|
100 |
+
$collection = new NostoExportProductCollection();
|
101 |
+
foreach ($products as $product) {
|
102 |
+
if ($product->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE
|
103 |
+
&& (int)$product->getPriceType() === Mage_Bundle_Model_Product_Price::PRICE_TYPE_FIXED
|
104 |
+
) {
|
105 |
+
continue;
|
106 |
+
}
|
107 |
+
$meta = new Nosto_Tagging_Model_Meta_Product();
|
108 |
+
$meta->loadData($product);
|
109 |
+
$collection[] = $meta;
|
110 |
+
}
|
111 |
+
$this->export($collection);
|
112 |
+
}
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Encrypts the export collection and outputs it to the browser.
|
117 |
+
*
|
118 |
+
* @param NostoExportCollection $collection the data collection to export.
|
119 |
+
*/
|
120 |
+
protected function export(NostoExportCollection $collection)
|
121 |
+
{
|
122 |
+
$account = Mage::helper('nosto_tagging/account')->find();
|
123 |
+
if ($account !== null) {
|
124 |
+
$cipherText = NostoExporter::export($account, $collection);
|
125 |
+
echo $cipherText;
|
126 |
+
}
|
127 |
+
die();
|
128 |
+
}
|
129 |
+
}
|
app/code/community/Nosto/Tagging/controllers/OauthController.php
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
require_once Mage::getBaseDir('lib') . '/nosto/php-sdk/src/config.inc.php';
|
29 |
+
|
30 |
+
/**
|
31 |
+
* OAuth2 controller.
|
32 |
+
* Handles the redirect from Nosto OAuth2 authorization server.
|
33 |
+
*
|
34 |
+
* @category Nosto
|
35 |
+
* @package Nosto_Tagging
|
36 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
37 |
+
*/
|
38 |
+
class Nosto_tagging_OauthController extends Mage_Core_Controller_Front_Action
|
39 |
+
{
|
40 |
+
/**
|
41 |
+
* Handles the redirect from Nosto oauth2 authorization server when an
|
42 |
+
* existing account is connected to a store.
|
43 |
+
* This is handled in the front end as the oauth2 server validates the
|
44 |
+
* "return_url" sent in the first step of the authorization cycle, and
|
45 |
+
* requires it to be from the same domain that the account is configured
|
46 |
+
* for and only redirects to that domain.
|
47 |
+
*/
|
48 |
+
public function indexAction()
|
49 |
+
{
|
50 |
+
// If the "Add Store Code to Urls" setting is set to "No" under
|
51 |
+
// System -> Configuration -> Web -> Url Options, then Magento won't
|
52 |
+
// set the store context based on the "___store" GET parameter if the
|
53 |
+
// store does NOT belong to the default website. When this setting is
|
54 |
+
// "Yes", then the store code will be a part of the url path and then
|
55 |
+
// the correct context is set by Magento, regardless of the website the
|
56 |
+
// store belongs to.
|
57 |
+
// If the "___store" parameter is present in the url in the current
|
58 |
+
// store context is not that store, then switch the store context.
|
59 |
+
if (($storeCode = $this->getRequest()->getParam('___store')) !== null) {
|
60 |
+
$store = Mage::app()->getStore($storeCode);
|
61 |
+
if ($store && $store->getId() !== Mage::app()->getStore()->getId()) {
|
62 |
+
Mage::app()->setCurrentStore($store->getCode());
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
$request = $this->getRequest();
|
67 |
+
if (($code = $request->getParam('code')) !== null) {
|
68 |
+
$store = Mage::app()->getStore();
|
69 |
+
try {
|
70 |
+
$account = NostoAccount::syncFromNosto(
|
71 |
+
Mage::helper('nosto_tagging/oauth')->getMetaData($store),
|
72 |
+
$code
|
73 |
+
);
|
74 |
+
if (Mage::helper('nosto_tagging/account')->save($account, $store)) {
|
75 |
+
$params = array(
|
76 |
+
'message_type' => NostoMessage::TYPE_SUCCESS,
|
77 |
+
'message_code' => NostoMessage::CODE_ACCOUNT_CONNECT,
|
78 |
+
'store' => (int)$store->getId(),
|
79 |
+
);
|
80 |
+
} else {
|
81 |
+
throw new NostoException('Failed to connect account');
|
82 |
+
}
|
83 |
+
} catch (NostoException $e) {
|
84 |
+
Mage::log(
|
85 |
+
"\n" . $e->__toString(), Zend_Log::ERR, 'nostotagging.log'
|
86 |
+
);
|
87 |
+
$params = array(
|
88 |
+
'message_type' => NostoMessage::TYPE_ERROR,
|
89 |
+
'message_code' => NostoMessage::CODE_ACCOUNT_CONNECT,
|
90 |
+
'store' => (int)$store->getId(),
|
91 |
+
);
|
92 |
+
}
|
93 |
+
$this->_redirect('adminhtml/nosto/redirectProxy', $params);
|
94 |
+
} elseif (($error = $request->getParam('error')) !== null) {
|
95 |
+
$logMsg = $error;
|
96 |
+
if (($reason = $request->getParam('error_reason')) !== null) {
|
97 |
+
$logMsg .= ' - ' . $reason;
|
98 |
+
}
|
99 |
+
if (($desc = $request->getParam('error_description')) !== null) {
|
100 |
+
$logMsg .= ' - ' . $desc;
|
101 |
+
}
|
102 |
+
Mage::log("\n" . $logMsg, Zend_Log::ERR, 'nostotagging.log');
|
103 |
+
$this->_redirect(
|
104 |
+
'adminhtml/nosto/redirectProxy', array(
|
105 |
+
'message_type' => NostoMessage::TYPE_ERROR,
|
106 |
+
'message_code' => !empty($reason) ? $reason : NostoMessage::CODE_ACCOUNT_CONNECT,
|
107 |
+
'store' => (int)Mage::app()->getStore()->getId(),
|
108 |
+
)
|
109 |
+
);
|
110 |
+
} else {
|
111 |
+
$this->norouteAction();
|
112 |
+
}
|
113 |
+
}
|
114 |
+
}
|
app/code/community/Nosto/Tagging/etc/adminhtml.xml
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* DISCLAIMER
|
17 |
+
*
|
18 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
19 |
+
* versions in the future. If you wish to customize Magento for your
|
20 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
21 |
+
*
|
22 |
+
* @category Nosto
|
23 |
+
* @package Nosto_Tagging
|
24 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
25 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
26 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
27 |
+
*/
|
28 |
+
-->
|
29 |
+
<config>
|
30 |
+
<menu>
|
31 |
+
<nosto translate="title">
|
32 |
+
<title>Nosto</title>
|
33 |
+
<sort_order>500</sort_order>
|
34 |
+
<action>adminhtml/nosto/index</action>
|
35 |
+
</nosto>
|
36 |
+
</menu>
|
37 |
+
<acl>
|
38 |
+
<resources>
|
39 |
+
<admin>
|
40 |
+
<children>
|
41 |
+
<nosto>
|
42 |
+
<title translate="title">Nosto</title>
|
43 |
+
<sort_order>500</sort_order>
|
44 |
+
</nosto>
|
45 |
+
</children>
|
46 |
+
</admin>
|
47 |
+
</resources>
|
48 |
+
</acl>
|
49 |
+
</config>
|
app/code/community/Nosto/Tagging/etc/cache.xml
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* DISCLAIMER
|
17 |
+
*
|
18 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
19 |
+
* versions in the future. If you wish to customize Magento for your
|
20 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
21 |
+
*
|
22 |
+
* @category Nosto
|
23 |
+
* @package Nosto_Tagging
|
24 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
25 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
26 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
27 |
+
*/
|
28 |
+
-->
|
29 |
+
<config>
|
30 |
+
<placeholders>
|
31 |
+
<nosto_tagging_cart>
|
32 |
+
<block>nosto_tagging/cart</block>
|
33 |
+
<name>nosto.cart</name>
|
34 |
+
<placeholder>NOSTO_TAGGING_CART_CACHE</placeholder>
|
35 |
+
<container>Nosto_Tagging_Model_Container_Cart</container>
|
36 |
+
<cache_life>86400</cache_life>
|
37 |
+
</nosto_tagging_cart>
|
38 |
+
<nosto_tagging_customer>
|
39 |
+
<block>nosto_tagging/customer</block>
|
40 |
+
<name>nosto.customer</name>
|
41 |
+
<placeholder>NOSTO_TAGGING_CUSTOMER_CACHE</placeholder>
|
42 |
+
<container>Nosto_Tagging_Model_Container_Customer</container>
|
43 |
+
<cache_life>86400</cache_life>
|
44 |
+
</nosto_tagging_customer>
|
45 |
+
</placeholders>
|
46 |
+
</config>
|
app/code/community/Nosto/Tagging/etc/config.xml
ADDED
@@ -0,0 +1,156 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* DISCLAIMER
|
17 |
+
*
|
18 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
19 |
+
* versions in the future. If you wish to customize Magento for your
|
20 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
21 |
+
*
|
22 |
+
* @category Nosto
|
23 |
+
* @package Nosto_Tagging
|
24 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
25 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
26 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
27 |
+
*/
|
28 |
+
-->
|
29 |
+
<config>
|
30 |
+
<modules>
|
31 |
+
<Nosto_Tagging>
|
32 |
+
<version>2.2.0</version>
|
33 |
+
</Nosto_Tagging>
|
34 |
+
</modules>
|
35 |
+
<global>
|
36 |
+
<resources>
|
37 |
+
<tagging_setup>
|
38 |
+
<setup>
|
39 |
+
<module>Nosto_Tagging</module>
|
40 |
+
<class>Nosto_Tagging_Model_Resource_Setup</class>
|
41 |
+
</setup>
|
42 |
+
</tagging_setup>
|
43 |
+
</resources>
|
44 |
+
<blocks>
|
45 |
+
<nosto_tagging>
|
46 |
+
<class>Nosto_Tagging_Block</class>
|
47 |
+
</nosto_tagging>
|
48 |
+
</blocks>
|
49 |
+
<helpers>
|
50 |
+
<nosto_tagging>
|
51 |
+
<class>Nosto_Tagging_Helper</class>
|
52 |
+
</nosto_tagging>
|
53 |
+
</helpers>
|
54 |
+
<models>
|
55 |
+
<nosto_tagging>
|
56 |
+
<class>Nosto_Tagging_Model</class>
|
57 |
+
<resourceModel>nosto_tagging_resource</resourceModel>
|
58 |
+
</nosto_tagging>
|
59 |
+
<nosto_tagging_resource>
|
60 |
+
<class>Nosto_Tagging_Model_Resource</class>
|
61 |
+
<entities>
|
62 |
+
<customer>
|
63 |
+
<table>nosto_tagging_customer</table>
|
64 |
+
</customer>
|
65 |
+
</entities>
|
66 |
+
</nosto_tagging_resource>
|
67 |
+
</models>
|
68 |
+
<events>
|
69 |
+
<catalog_product_save_after>
|
70 |
+
<observers>
|
71 |
+
<nosto_tagging_catalog_product_save_after>
|
72 |
+
<type>singleton</type>
|
73 |
+
<class>Nosto_Tagging_Model_Observer</class>
|
74 |
+
<method>recrawlProduct</method>
|
75 |
+
</nosto_tagging_catalog_product_save_after>
|
76 |
+
</observers>
|
77 |
+
</catalog_product_save_after>
|
78 |
+
<catalog_product_delete_after>
|
79 |
+
<observers>
|
80 |
+
<nosto_tagging_catalog_product_delete_after>
|
81 |
+
<type>singleton</type>
|
82 |
+
<class>Nosto_Tagging_Model_Observer</class>
|
83 |
+
<method>recrawlProduct</method>
|
84 |
+
</nosto_tagging_catalog_product_delete_after>
|
85 |
+
</observers>
|
86 |
+
</catalog_product_delete_after>
|
87 |
+
<sales_order_save_commit_after>
|
88 |
+
<observers>
|
89 |
+
<nosto_tagging_sales_order_save_commit_after>
|
90 |
+
<type>singleton</type>
|
91 |
+
<class>Nosto_Tagging_Model_Observer</class>
|
92 |
+
<method>sendOrderConfirmation</method>
|
93 |
+
</nosto_tagging_sales_order_save_commit_after>
|
94 |
+
</observers>
|
95 |
+
</sales_order_save_commit_after>
|
96 |
+
</events>
|
97 |
+
</global>
|
98 |
+
<adminhtml>
|
99 |
+
<layout>
|
100 |
+
<updates>
|
101 |
+
<nosto_tagging>
|
102 |
+
<file>nostotagging.xml</file>
|
103 |
+
</nosto_tagging>
|
104 |
+
</updates>
|
105 |
+
</layout>
|
106 |
+
<translate>
|
107 |
+
<modules>
|
108 |
+
<Nosto_Tagging>
|
109 |
+
<files>
|
110 |
+
<default>Nosto_Tagging.csv</default>
|
111 |
+
</files>
|
112 |
+
</Nosto_Tagging>
|
113 |
+
</modules>
|
114 |
+
</translate>
|
115 |
+
</adminhtml>
|
116 |
+
<admin>
|
117 |
+
<routers>
|
118 |
+
<adminhtml>
|
119 |
+
<args>
|
120 |
+
<modules>
|
121 |
+
<nosto_tagging after="Mage_Adminhtml">Nosto_Tagging_Adminhtml</nosto_tagging>
|
122 |
+
</modules>
|
123 |
+
</args>
|
124 |
+
</adminhtml>
|
125 |
+
</routers>
|
126 |
+
</admin>
|
127 |
+
<frontend>
|
128 |
+
<events>
|
129 |
+
<controller_action_layout_load_before>
|
130 |
+
<observers>
|
131 |
+
<nosto_tagging_layout_load_before>
|
132 |
+
<type>singleton</type>
|
133 |
+
<class>Nosto_Tagging_Model_Observer</class>
|
134 |
+
<method>addBlockAfterMainContent</method>
|
135 |
+
</nosto_tagging_layout_load_before>
|
136 |
+
</observers>
|
137 |
+
</controller_action_layout_load_before>
|
138 |
+
</events>
|
139 |
+
<layout>
|
140 |
+
<updates>
|
141 |
+
<nosto_tagging>
|
142 |
+
<file>nostotagging.xml</file>
|
143 |
+
</nosto_tagging>
|
144 |
+
</updates>
|
145 |
+
</layout>
|
146 |
+
<routers>
|
147 |
+
<nosto>
|
148 |
+
<use>standard</use>
|
149 |
+
<args>
|
150 |
+
<module>Nosto_Tagging</module>
|
151 |
+
<frontName>nosto</frontName>
|
152 |
+
</args>
|
153 |
+
</nosto>
|
154 |
+
</routers>
|
155 |
+
</frontend>
|
156 |
+
</config>
|
app/code/community/Nosto/Tagging/sql/tagging_setup/mysql4-install-1.2.0.php
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* This install script will run only when installing the version 1.2.0 or above,
|
30 |
+
* i.e. when no "tagging_setup" entry is present in the `core_resource` table.
|
31 |
+
*
|
32 |
+
* Creates the db table for matching Magento cart quotes to nosto customer ids.
|
33 |
+
*
|
34 |
+
* @var Nosto_Tagging_Model_Resource_Setup $installer
|
35 |
+
*/
|
36 |
+
|
37 |
+
$installer = $this;
|
38 |
+
$installer->startSetup();
|
39 |
+
|
40 |
+
$table = $installer
|
41 |
+
->getConnection()
|
42 |
+
->newTable($installer->getTable('nosto_tagging/customer'))
|
43 |
+
->addColumn(
|
44 |
+
'customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 10, array(
|
45 |
+
'unsigned' => true,
|
46 |
+
'nullable' => false,
|
47 |
+
'primary' => true,
|
48 |
+
'identity' => true
|
49 |
+
)
|
50 |
+
)
|
51 |
+
->addColumn(
|
52 |
+
'quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 10, array(
|
53 |
+
'unsigned' => true,
|
54 |
+
'nullable' => false
|
55 |
+
)
|
56 |
+
)
|
57 |
+
->addColumn(
|
58 |
+
'nosto_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
59 |
+
'nullable' => false
|
60 |
+
)
|
61 |
+
)
|
62 |
+
->addColumn(
|
63 |
+
'created_at', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(
|
64 |
+
'nullable' => false
|
65 |
+
)
|
66 |
+
)
|
67 |
+
->addColumn(
|
68 |
+
'updated_at', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(
|
69 |
+
'nullable' => true
|
70 |
+
)
|
71 |
+
)
|
72 |
+
->addIndex(
|
73 |
+
$installer->getIdxName(
|
74 |
+
'nosto_tagging/customer', array('quote_id', 'nosto_id'),
|
75 |
+
Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
|
76 |
+
),
|
77 |
+
array('quote_id', 'nosto_id'), array(
|
78 |
+
'type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
|
79 |
+
)
|
80 |
+
);
|
81 |
+
$installer->getConnection()->createTable($table);
|
82 |
+
|
83 |
+
$installer->endSetup();
|
app/code/community/Nosto/Tagging/sql/tagging_setup/mysql4-upgrade-1.1.7-1.2.0.php
ADDED
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category Nosto
|
22 |
+
* @package Nosto_Tagging
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
|
28 |
+
/**
|
29 |
+
* This upgrade script will run when upgrading from 1.1.7 to 1.2.0 or above.
|
30 |
+
*
|
31 |
+
* Deletes all existing module configurations.
|
32 |
+
* Creates the db table for matching Magento cart quotes to nosto customer ids.
|
33 |
+
*
|
34 |
+
* @var Nosto_Tagging_Model_Resource_Setup $installer
|
35 |
+
*/
|
36 |
+
|
37 |
+
$installer = $this;
|
38 |
+
$installer->startSetup();
|
39 |
+
|
40 |
+
$installer->getConnection()->delete(
|
41 |
+
$installer->getTable('core/config_data'),
|
42 |
+
'`path` LIKE "nosto_tagging/%"'
|
43 |
+
);
|
44 |
+
|
45 |
+
$table = $installer
|
46 |
+
->getConnection()
|
47 |
+
->newTable($installer->getTable('nosto_tagging/customer'))
|
48 |
+
->addColumn(
|
49 |
+
'customer_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 10, array(
|
50 |
+
'unsigned' => true,
|
51 |
+
'nullable' => false,
|
52 |
+
'primary' => true,
|
53 |
+
'identity' => true
|
54 |
+
)
|
55 |
+
)
|
56 |
+
->addColumn(
|
57 |
+
'quote_id', Varien_Db_Ddl_Table::TYPE_INTEGER, 10, array(
|
58 |
+
'unsigned' => true,
|
59 |
+
'nullable' => false
|
60 |
+
)
|
61 |
+
)
|
62 |
+
->addColumn(
|
63 |
+
'nosto_id', Varien_Db_Ddl_Table::TYPE_VARCHAR, 255, array(
|
64 |
+
'nullable' => false
|
65 |
+
)
|
66 |
+
)
|
67 |
+
->addColumn(
|
68 |
+
'created_at', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(
|
69 |
+
'nullable' => false
|
70 |
+
)
|
71 |
+
)
|
72 |
+
->addColumn(
|
73 |
+
'updated_at', Varien_Db_Ddl_Table::TYPE_DATETIME, null, array(
|
74 |
+
'nullable' => true
|
75 |
+
)
|
76 |
+
)
|
77 |
+
->addIndex(
|
78 |
+
$installer->getIdxName(
|
79 |
+
'nosto_tagging/customer', array('quote_id', 'nosto_id'),
|
80 |
+
Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
|
81 |
+
),
|
82 |
+
array('quote_id', 'nosto_id'), array(
|
83 |
+
'type' => Varien_Db_Adapter_Interface::INDEX_TYPE_UNIQUE
|
84 |
+
)
|
85 |
+
);
|
86 |
+
$installer->getConnection()->createTable($table);
|
87 |
+
|
88 |
+
$installer->endSetup();
|
app/design/adminhtml/default/default/layout/nostotagging.xml
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* DISCLAIMER
|
17 |
+
*
|
18 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
19 |
+
* versions in the future. If you wish to customize Magento for your
|
20 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
21 |
+
*
|
22 |
+
* @category design
|
23 |
+
* @package adminhtml_default_default
|
24 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
25 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
26 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
27 |
+
*/
|
28 |
+
-->
|
29 |
+
<config>
|
30 |
+
<!-- Nosto main menu link page -->
|
31 |
+
<adminhtml_nosto_index>
|
32 |
+
<!-- Add JavaScript file -->
|
33 |
+
<reference name="head">
|
34 |
+
<action method="addJs"><script>nosto/iframeresizer.min.js</script></action>
|
35 |
+
<action method="addJs"><script>nosto/NostoIframe.min.js</script></action>
|
36 |
+
<action method="addJs"><script>nosto/nostotagging-config.js</script></action>
|
37 |
+
</reference>
|
38 |
+
<!--Set active menu item-->
|
39 |
+
<reference name="menu">
|
40 |
+
<action method="setActive">
|
41 |
+
<menupath>nosto/index</menupath>
|
42 |
+
</action>
|
43 |
+
</reference>
|
44 |
+
<!-- Page content -->
|
45 |
+
<reference name="content">
|
46 |
+
<block type="nosto_tagging/adminhtml_wizard" name="nosto.wizard" template="nostotagging/wizard.phtml">
|
47 |
+
<!-- Store switcher -->
|
48 |
+
<block type="adminhtml/store_switcher" name="store_switcher" as="store_switcher">
|
49 |
+
<action method="setUseConfirm"><params>0</params></action>
|
50 |
+
</block>
|
51 |
+
<!-- Iframe -->
|
52 |
+
<block type="nosto_tagging/adminhtml_iframe" name="nosto.iframe" template="nostotagging/iframe.phtml"/>
|
53 |
+
</block>
|
54 |
+
</reference>
|
55 |
+
</adminhtml_nosto_index>
|
56 |
+
</config>
|
app/design/adminhtml/default/default/template/nostotagging/iframe.phtml
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package adminhtml_default_default
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
?>
|
28 |
+
|
29 |
+
<?php
|
30 |
+
/**
|
31 |
+
* @var $this Nosto_Tagging_Block_Adminhtml_Iframe
|
32 |
+
*/
|
33 |
+
$params = array('store' => $this->getSelectedStore()->getId(), 'isAjax' => true);
|
34 |
+
?>
|
35 |
+
<iframe id="nosto_iframe" src='<?php echo $this->getIframeUrl(); ?>' width='100%' frameborder='0' scrolling='no' style="min-height: 600px;"></iframe>
|
36 |
+
<script type="text/javascript">
|
37 |
+
// Define the "Nosto" namespace if not already defined.
|
38 |
+
if (typeof Nosto === "undefined") {
|
39 |
+
var Nosto = {};
|
40 |
+
}
|
41 |
+
Nosto.settings = {
|
42 |
+
origin: "<?php echo $this->getIframeOrigin(); ?>",
|
43 |
+
urls: {
|
44 |
+
createAccount: "<?php echo $this->getUrl('*/*/createAccount', $params); ?>",
|
45 |
+
connectAccount: "<?php echo $this->getUrl('*/*/connectAccount', $params); ?>",
|
46 |
+
deleteAccount: "<?php echo $this->getUrl('*/*/removeAccount', $params); ?>"
|
47 |
+
},
|
48 |
+
xhrParams: {form_key: window.FORM_KEY}
|
49 |
+
};
|
50 |
+
</script>
|
app/design/adminhtml/default/default/template/nostotagging/wizard.phtml
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package adminhtml_default_default
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
?>
|
28 |
+
|
29 |
+
<?php
|
30 |
+
/**
|
31 |
+
* @var $this Nosto_Tagging_Block_Adminhtml_Wizard
|
32 |
+
*/
|
33 |
+
?>
|
34 |
+
<div class="content-header">
|
35 |
+
<h3><?php echo $this->__('Nosto'); ?></h3>
|
36 |
+
</div>
|
37 |
+
<?php if (!Mage::app()->isSingleStoreMode()): ?>
|
38 |
+
<?php echo $this->getChildHtml('store_switcher'); ?>
|
39 |
+
<?php endif;?>
|
40 |
+
<div class="a-center">
|
41 |
+
<div id="nosto_iframe_container"><?php echo $this->getChildHtml('nosto.iframe'); ?></div>
|
42 |
+
</div>
|
app/design/frontend/base/default/layout/nostotagging.xml
ADDED
@@ -0,0 +1,273 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* DISCLAIMER
|
17 |
+
*
|
18 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
19 |
+
* versions in the future. If you wish to customize Magento for your
|
20 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
21 |
+
*
|
22 |
+
* @category design
|
23 |
+
* @package frontend_base_default
|
24 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
25 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
26 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
27 |
+
*/
|
28 |
+
-->
|
29 |
+
<layout version="1.0.0">
|
30 |
+
<!-- -->
|
31 |
+
<!-- Adds Nosto tagging meta-data to site -->
|
32 |
+
<!-- -->
|
33 |
+
|
34 |
+
<!-- Store wide blocks -->
|
35 |
+
<default>
|
36 |
+
<!-- Adds Nosto meta tags to head -->
|
37 |
+
<reference name="head">
|
38 |
+
<block type="nosto_tagging/meta" name="nosto.meta" template="nostotagging/meta.phtml" before="-"/>
|
39 |
+
</reference>
|
40 |
+
|
41 |
+
<!-- Adds Nosto embed script to head -->
|
42 |
+
<reference name="head">
|
43 |
+
<block type="nosto_tagging/embed" name="nosto.embed" template="nostotagging/embed.phtml"/>
|
44 |
+
</reference>
|
45 |
+
|
46 |
+
<!-- Tag shopping cart -->
|
47 |
+
<reference name="after_body_start">
|
48 |
+
<block type="nosto_tagging/cart" name="nosto.cart" template="nostotagging/cart.phtml"/>
|
49 |
+
</reference>
|
50 |
+
|
51 |
+
<!-- Tag customer -->
|
52 |
+
<reference name="after_body_start">
|
53 |
+
<block type="nosto_tagging/customer" name="nosto.customer" template="nostotagging/customer.phtml"/>
|
54 |
+
</reference>
|
55 |
+
</default>
|
56 |
+
|
57 |
+
<!-- Tag category -->
|
58 |
+
<catalog_category_default>
|
59 |
+
<update handle="nosto_tagging_category" />
|
60 |
+
</catalog_category_default>
|
61 |
+
<catalog_category_layered>
|
62 |
+
<update handle="nosto_tagging_category" />
|
63 |
+
</catalog_category_layered>
|
64 |
+
<nosto_tagging_category>
|
65 |
+
<reference name="after_body_start">
|
66 |
+
<block type="nosto_tagging/category" name="nosto.category" template="nostotagging/category.phtml"/>
|
67 |
+
</reference>
|
68 |
+
</nosto_tagging_category>
|
69 |
+
|
70 |
+
<!-- Tag product -->
|
71 |
+
<catalog_product_view>
|
72 |
+
<reference name="after_body_start">
|
73 |
+
<block type="nosto_tagging/product" name="nosto.product" template="nostotagging/product.phtml"/>
|
74 |
+
</reference>
|
75 |
+
</catalog_product_view>
|
76 |
+
|
77 |
+
<!-- Tag checkout -->
|
78 |
+
<checkout_onepage_success>
|
79 |
+
<reference name="after_body_start">
|
80 |
+
<block type="nosto_tagging/order" name="nosto.order" template="nostotagging/order.phtml"/>
|
81 |
+
</reference>
|
82 |
+
</checkout_onepage_success>
|
83 |
+
|
84 |
+
<!-- -->
|
85 |
+
<!-- Adds Nosto elements to site -->
|
86 |
+
<!-- -->
|
87 |
+
|
88 |
+
<!-- All pages -->
|
89 |
+
<default>
|
90 |
+
<!-- Adds 1 content placeholder first in page content section -->
|
91 |
+
<reference name="content">
|
92 |
+
<block type="nosto_tagging/element" name="nosto.page.top" before="-"
|
93 |
+
template="nostotagging/element.phtml">
|
94 |
+
<action method="setData">
|
95 |
+
<name>div_id</name>
|
96 |
+
<value>nosto-page-top</value>
|
97 |
+
</action>
|
98 |
+
</block>
|
99 |
+
</reference>
|
100 |
+
<!-- Adds 1 content placeholder to left sidebar -->
|
101 |
+
<reference name="left">
|
102 |
+
<block type="nosto_tagging/element" name="nosto.column.left" before="-"
|
103 |
+
template="nostotagging/element.phtml">
|
104 |
+
<action method="setData">
|
105 |
+
<name>div_id</name>
|
106 |
+
<value>nosto-column-left</value>
|
107 |
+
</action>
|
108 |
+
</block>
|
109 |
+
</reference>
|
110 |
+
<!-- Adds 1 content placeholder to right sidebar -->
|
111 |
+
<reference name="right">
|
112 |
+
<block type="nosto_tagging/element" name="nosto.column.right" after="-"
|
113 |
+
template="nostotagging/element.phtml">
|
114 |
+
<action method="setData">
|
115 |
+
<name>div_id</name>
|
116 |
+
<value>nosto-column-right</value>
|
117 |
+
</action>
|
118 |
+
</block>
|
119 |
+
</reference>
|
120 |
+
</default>
|
121 |
+
|
122 |
+
<!-- Custom handle for displaying 1 content placeholder last in page content section -->
|
123 |
+
<nosto_tagging_page_default_footer>
|
124 |
+
<reference name="content">
|
125 |
+
<block type="nosto_tagging/element" name="nosto.page.footer" after="-"
|
126 |
+
template="nostotagging/element.phtml">
|
127 |
+
<action method="setData">
|
128 |
+
<name>div_id</name>
|
129 |
+
<value>nosto-page-footer</value>
|
130 |
+
</action>
|
131 |
+
</block>
|
132 |
+
</reference>
|
133 |
+
</nosto_tagging_page_default_footer>
|
134 |
+
|
135 |
+
<!-- Home page -->
|
136 |
+
<cms_index_index>
|
137 |
+
<!-- Add 4 content placeholders after the home page content -->
|
138 |
+
<reference name="content">
|
139 |
+
<block type="nosto_tagging/element" name="nosto.page.home1" after="-"
|
140 |
+
template="nostotagging/element.phtml">
|
141 |
+
<action method="setData">
|
142 |
+
<name>div_id</name>
|
143 |
+
<value>frontpage-nosto-1</value>
|
144 |
+
</action>
|
145 |
+
</block>
|
146 |
+
<block type="nosto_tagging/element" name="nosto.page.home2" after="-"
|
147 |
+
template="nostotagging/element.phtml">
|
148 |
+
<action method="setData">
|
149 |
+
<name>div_id</name>
|
150 |
+
<value>frontpage-nosto-2</value>
|
151 |
+
</action>
|
152 |
+
</block>
|
153 |
+
<block type="nosto_tagging/element" name="nosto.page.home3" after="-"
|
154 |
+
template="nostotagging/element.phtml">
|
155 |
+
<action method="setData">
|
156 |
+
<name>div_id</name>
|
157 |
+
<value>frontpage-nosto-3</value>
|
158 |
+
</action>
|
159 |
+
</block>
|
160 |
+
<block type="nosto_tagging/element" name="nosto.page.home4" after="-"
|
161 |
+
template="nostotagging/element.phtml">
|
162 |
+
<action method="setData">
|
163 |
+
<name>div_id</name>
|
164 |
+
<value>frontpage-nosto-4</value>
|
165 |
+
</action>
|
166 |
+
</block>
|
167 |
+
</reference>
|
168 |
+
</cms_index_index>
|
169 |
+
|
170 |
+
<!-- Shopping cart checkout page -->
|
171 |
+
<checkout_cart_index>
|
172 |
+
<!-- Adds 3 content placeholders after the cart content -->
|
173 |
+
<reference name="content">
|
174 |
+
<block type="nosto_tagging/element" name="nosto.page.cart1" after="checkout.cart"
|
175 |
+
template="nostotagging/element.phtml">
|
176 |
+
<action method="setData">
|
177 |
+
<name>div_id</name>
|
178 |
+
<value>nosto-page-cart1</value>
|
179 |
+
</action>
|
180 |
+
</block>
|
181 |
+
<block type="nosto_tagging/element" name="nosto.page.cart2" after="nosto.page.cart1"
|
182 |
+
template="nostotagging/element.phtml">
|
183 |
+
<action method="setData">
|
184 |
+
<name>div_id</name>
|
185 |
+
<value>nosto-page-cart2</value>
|
186 |
+
</action>
|
187 |
+
</block>
|
188 |
+
<block type="nosto_tagging/element" name="nosto.page.cart3" after="nosto.page.cart2"
|
189 |
+
template="nostotagging/element.phtml">
|
190 |
+
<action method="setData">
|
191 |
+
<name>div_id</name>
|
192 |
+
<value>nosto-page-cart3</value>
|
193 |
+
</action>
|
194 |
+
</block>
|
195 |
+
</reference>
|
196 |
+
</checkout_cart_index>
|
197 |
+
|
198 |
+
<!-- Product page -->
|
199 |
+
<catalog_product_view>
|
200 |
+
<!-- Adds 3 content placeholders after the product info -->
|
201 |
+
<reference name="content">
|
202 |
+
<block type="nosto_tagging/element" name="nosto.page.product1" after="product.info"
|
203 |
+
template="nostotagging/element.phtml">
|
204 |
+
<action method="setData">
|
205 |
+
<name>div_id</name>
|
206 |
+
<value>nosto-page-product1</value>
|
207 |
+
</action>
|
208 |
+
</block>
|
209 |
+
<block type="nosto_tagging/element" name="nosto.page.product2" after="nosto.page.product1"
|
210 |
+
template="nostotagging/element.phtml">
|
211 |
+
<action method="setData">
|
212 |
+
<name>div_id</name>
|
213 |
+
<value>nosto-page-product2</value>
|
214 |
+
</action>
|
215 |
+
</block>
|
216 |
+
<block type="nosto_tagging/element" name="nosto.page.product3" after="nosto.page.product2"
|
217 |
+
template="nostotagging/element.phtml">
|
218 |
+
<action method="setData">
|
219 |
+
<name>div_id</name>
|
220 |
+
<value>nosto-page-product3</value>
|
221 |
+
</action>
|
222 |
+
</block>
|
223 |
+
</reference>
|
224 |
+
</catalog_product_view>
|
225 |
+
|
226 |
+
<!-- Category page -->
|
227 |
+
<catalog_category_default>
|
228 |
+
<update handle="nosto_tagging_catalog_category" />
|
229 |
+
</catalog_category_default>
|
230 |
+
<catalog_category_layered>
|
231 |
+
<update handle="nosto_tagging_catalog_category" />
|
232 |
+
</catalog_category_layered>
|
233 |
+
<nosto_tagging_catalog_category>
|
234 |
+
<!-- Adds 2 content placeholders; 1 before and 1 after the products -->
|
235 |
+
<reference name="content">
|
236 |
+
<block type="nosto_tagging/element" name="nosto.page.category1" before="category.products"
|
237 |
+
template="nostotagging/element.phtml">
|
238 |
+
<action method="setData">
|
239 |
+
<name>div_id</name>
|
240 |
+
<value>nosto-page-category1</value>
|
241 |
+
</action>
|
242 |
+
</block>
|
243 |
+
<block type="nosto_tagging/element" name="nosto.page.category2" after="category.products"
|
244 |
+
template="nostotagging/element.phtml">
|
245 |
+
<action method="setData">
|
246 |
+
<name>div_id</name>
|
247 |
+
<value>nosto-page-category2</value>
|
248 |
+
</action>
|
249 |
+
</block>
|
250 |
+
</reference>
|
251 |
+
</nosto_tagging_catalog_category>
|
252 |
+
|
253 |
+
<!-- Search result page -->
|
254 |
+
<catalogsearch_result_index>
|
255 |
+
<!-- Adds 2 content placeholders; 1 before and 1 after the search result -->
|
256 |
+
<reference name="content">
|
257 |
+
<block type="nosto_tagging/element" name="nosto.page.search1" before="search.result"
|
258 |
+
template="nostotagging/element.phtml">
|
259 |
+
<action method="setData">
|
260 |
+
<name>div_id</name>
|
261 |
+
<value>nosto-page-search1</value>
|
262 |
+
</action>
|
263 |
+
</block>
|
264 |
+
<block type="nosto_tagging/element" name="nosto.page.search2" after="search.result"
|
265 |
+
template="nostotagging/element.phtml">
|
266 |
+
<action method="setData">
|
267 |
+
<name>div_id</name>
|
268 |
+
<value>nosto-page-search2</value>
|
269 |
+
</action>
|
270 |
+
</block>
|
271 |
+
</reference>
|
272 |
+
</catalogsearch_result_index>
|
273 |
+
</layout>
|
app/design/frontend/base/default/template/nostotagging/cart.phtml
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package frontend_base_default
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
?>
|
28 |
+
|
29 |
+
<?php
|
30 |
+
/**
|
31 |
+
* @var $this Nosto_Tagging_Block_Cart
|
32 |
+
* @var $nostoHelper Nosto_Tagging_Helper_Data
|
33 |
+
* @var $nostoPriceHelper Nosto_Tagging_Helper_Price
|
34 |
+
*/
|
35 |
+
$items = $this->getItems();
|
36 |
+
$currency = Mage::app()->getStore()->getCurrentCurrencyCode();
|
37 |
+
$nostoHelper = Mage::helper('nosto_tagging');
|
38 |
+
$nostoPriceHelper = Mage::helper('nosto_tagging/price');
|
39 |
+
?>
|
40 |
+
|
41 |
+
<!-- Nosto Cart Tagging -->
|
42 |
+
<div class="nosto_cart" style="display:none">
|
43 |
+
<?php foreach ($items as $item): ?>
|
44 |
+
<div class="line_item">
|
45 |
+
<span class="product_id"><?php echo $this->getProductId($item); ?></span>
|
46 |
+
<span class="quantity"><?php echo (int)$item->getQty(); ?></span>
|
47 |
+
<span class="name"><?php echo $nostoHelper->escapeHtml($item->getName()); ?></span>
|
48 |
+
<span class="unit_price"><?php echo $nostoPriceHelper->getFormattedPrice($item->getPriceInclTax()); ?></span>
|
49 |
+
<span class="price_currency_code"><?php echo $currency; ?></span>
|
50 |
+
</div>
|
51 |
+
<?php endforeach; ?>
|
52 |
+
</div>
|
app/design/frontend/base/default/template/nostotagging/category.phtml
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package frontend_base_default
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
?>
|
28 |
+
|
29 |
+
<?php
|
30 |
+
/**
|
31 |
+
* @var $this Nosto_Tagging_Block_Category
|
32 |
+
* @var $nostoHelper Nosto_Tagging_Helper_Data
|
33 |
+
*/
|
34 |
+
$nostoHelper = Mage::helper('nosto_tagging');
|
35 |
+
?>
|
36 |
+
|
37 |
+
<!-- Nosto Category Tagging -->
|
38 |
+
<div class="nosto_category" style="display:none"><?php echo $nostoHelper->escapeHtml($this->getCategory()); ?></div>
|
app/design/frontend/base/default/template/nostotagging/category/view.phtml
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package frontend_base_default
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
?>
|
28 |
+
|
29 |
+
<?php
|
30 |
+
/**
|
31 |
+
* @var $this Mage_Catalog_Block_Category_View
|
32 |
+
* @var $nostoHelper Nosto_Tagging_Helper_Data
|
33 |
+
*/
|
34 |
+
$category = $this->getCurrentCategory();
|
35 |
+
$nostoHelper = Mage::helper('nosto_tagging');
|
36 |
+
?>
|
37 |
+
|
38 |
+
<div class="nosto_element" id="<?php echo $nostoHelper->escapeHtml($category->getNostoId()); ?>"></div>
|
app/design/frontend/base/default/template/nostotagging/customer.phtml
ADDED
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package frontend_base_default
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
?>
|
28 |
+
|
29 |
+
<?php
|
30 |
+
/**
|
31 |
+
* @var $this Nosto_Tagging_Block_Customer
|
32 |
+
* @var $nostoHelper Nosto_Tagging_Helper_Data
|
33 |
+
*/
|
34 |
+
$customer = $this->getCustomer();
|
35 |
+
$nostoHelper = Mage::helper('nosto_tagging');
|
36 |
+
?>
|
37 |
+
|
38 |
+
<!-- Nosto Customer Tagging -->
|
39 |
+
<div class="nosto_customer" style="display:none">
|
40 |
+
<span class="first_name"><?php echo $nostoHelper->escapeHtml($customer->getFirstname()); ?></span>
|
41 |
+
<span class="last_name"><?php echo $nostoHelper->escapeHtml($customer->getLastname()); ?></span>
|
42 |
+
<span class="email"><?php echo $nostoHelper->escapeHtml($customer->getEmail()); ?></span>
|
43 |
+
</div>
|
app/design/frontend/base/default/template/nostotagging/element.phtml
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package frontend_base_default
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
?>
|
28 |
+
|
29 |
+
<?php
|
30 |
+
/**
|
31 |
+
* @var $this Nosto_Tagging_Block_Element
|
32 |
+
* @var $nostoHelper Nosto_Tagging_Helper_Data
|
33 |
+
*/
|
34 |
+
$nostoHelper = Mage::helper('nosto_tagging');
|
35 |
+
?>
|
36 |
+
|
37 |
+
<div class="nosto_element" id="<?php echo $nostoHelper->escapeHtml($this->getElementId()); ?>"></div>
|
app/design/frontend/base/default/template/nostotagging/embed.phtml
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package frontend_base_default
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
?>
|
28 |
+
|
29 |
+
<?php
|
30 |
+
/**
|
31 |
+
* @var $this Nosto_Tagging_Block_Embed
|
32 |
+
*/
|
33 |
+
?>
|
34 |
+
<!-- Nosto Tagging Script -->
|
35 |
+
<script type="text/javascript">
|
36 |
+
//<![CDATA[
|
37 |
+
(function(){function a(a){var b,c,d=window.document.createElement("iframe");d.src="javascript:false",(d.frameElement||d).style.cssText="width: 0; height: 0; border: 0";var e=window.document.createElement("div");e.style.display="none";var f=window.document.createElement("div");e.appendChild(f),window.document.body.insertBefore(e,window.document.body.firstChild),f.appendChild(d);try{c=d.contentWindow.document}catch(g){b=document.domain,d.src="javascript:var d=document.open();d.domain='"+b+"';void(0);",c=d.contentWindow.document}return c.open()._l=function(){b&&(this.domain=b);var c=this.createElement("scr".concat("ipt"));c.src=a,this.body.appendChild(c)},c.write("<bo".concat('dy onload="document._l();">')),c.close(),d}var b="nostojs";window[b]=window[b]||function(a){(window[b].q=window[b].q||[]).push(a)},window[b].l=new Date;var c=function(d,e){if(!document.body)return setTimeout(function(){c(d,e)},30);e=e||{},window[b].o=e;var f=document.location.protocol,g=["https:"===f?f:"http:","//",e.host||"connect.nosto.com",e.path||"/include/",d].join("");a(g)};window[b].init=c})();
|
38 |
+
nostojs.init('<?php echo $this->getAccountName(); ?>', { host: '<?php echo $this->getServerAddress() ?>'});
|
39 |
+
//]]>
|
40 |
+
</script>
|
app/design/frontend/base/default/template/nostotagging/meta.phtml
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package frontend_base_default
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
?>
|
28 |
+
|
29 |
+
<?php
|
30 |
+
/**
|
31 |
+
* @var $this Nosto_Tagging_Block_Meta
|
32 |
+
* @var $helper Nosto_Tagging_Helper_Data
|
33 |
+
*/
|
34 |
+
$helper = Mage::helper('nosto_tagging');
|
35 |
+
?>
|
36 |
+
|
37 |
+
<!-- Nosto Meta Tags -->
|
38 |
+
<meta name="nosto-version" content="<?php echo $this->getVersionModule(); ?>">
|
39 |
+
<meta name="nosto-unique-id" content="<?php echo $helper->getInstallationId(); ?>">
|
40 |
+
<meta name="nosto-language" content="<?php echo strtolower($this->getLanguageIsoCode()); ?>">
|
app/design/frontend/base/default/template/nostotagging/order.phtml
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package frontend_base_default
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
?>
|
28 |
+
|
29 |
+
<?php
|
30 |
+
/**
|
31 |
+
* @var $this Nosto_Tagging_Block_Order
|
32 |
+
* @var $helper Nosto_Tagging_Helper_Data
|
33 |
+
* @var $priceHelper Nosto_Tagging_Helper_Price
|
34 |
+
*/
|
35 |
+
$order = $this->getLastOrder();
|
36 |
+
$helper = Mage::helper('nosto_tagging');
|
37 |
+
$priceHelper = Mage::helper('nosto_tagging/price');
|
38 |
+
?>
|
39 |
+
|
40 |
+
<?php if ($order->getPurchasedItems() !== array()): ?>
|
41 |
+
<!-- Nosto Order Tagging -->
|
42 |
+
<div class="nosto_purchase_order" style="display:none">
|
43 |
+
<span class="order_number"><?php echo $order->getOrderNumber(); ?></span>
|
44 |
+
<div class="buyer">
|
45 |
+
<span class="first_name"><?php echo $helper->escapeHtml($order->getBuyerInfo()->getFirstName()); ?></span>
|
46 |
+
<span class="last_name"><?php echo $helper->escapeHtml($order->getBuyerInfo()->getLastName()); ?></span>
|
47 |
+
<span class="email"><?php echo $helper->escapeHtml($order->getBuyerInfo()->getEmail()); ?></span>
|
48 |
+
</div>
|
49 |
+
<div class="purchased_items">
|
50 |
+
<?php foreach ($order->getPurchasedItems() as $item): ?>
|
51 |
+
<div class="line_item">
|
52 |
+
<span class="product_id"><?php echo (int)$item->getProductId(); ?></span>
|
53 |
+
<span class="quantity"><?php echo (int)$item->getQuantity(); ?></span>
|
54 |
+
<span class="name"><?php echo $helper->escapeHtml($item->getName()); ?></span>
|
55 |
+
<span class="unit_price"><?php echo $priceHelper->getFormattedPrice($item->getUnitPrice()); ?></span>
|
56 |
+
<span class="price_currency_code"><?php echo strtoupper($item->getCurrencyCode()); ?></span>
|
57 |
+
</div>
|
58 |
+
<?php endforeach; ?>
|
59 |
+
</div>
|
60 |
+
</div>
|
61 |
+
<?php endif; ?>
|
app/design/frontend/base/default/template/nostotagging/product.phtml
ADDED
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Magento
|
4 |
+
*
|
5 |
+
* NOTICE OF LICENSE
|
6 |
+
*
|
7 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
8 |
+
* that is bundled with this package in the file LICENSE.txt.
|
9 |
+
* It is also available through the world-wide-web at this URL:
|
10 |
+
* http://opensource.org/licenses/osl-3.0.php
|
11 |
+
* If you did not receive a copy of the license and are unable to
|
12 |
+
* obtain it through the world-wide-web, please send an email
|
13 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
14 |
+
*
|
15 |
+
* DISCLAIMER
|
16 |
+
*
|
17 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
18 |
+
* versions in the future. If you wish to customize Magento for your
|
19 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
20 |
+
*
|
21 |
+
* @category design
|
22 |
+
* @package frontend_base_default
|
23 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
24 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
25 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
26 |
+
*/
|
27 |
+
?>
|
28 |
+
|
29 |
+
<?php
|
30 |
+
/**
|
31 |
+
* @var $this Nosto_Tagging_Block_Product
|
32 |
+
* @var $helper Nosto_Tagging_Helper_Data
|
33 |
+
* @var $priceHelper Nosto_Tagging_Helper_Price
|
34 |
+
* @var $dateHelper Nosto_Tagging_Helper_Date
|
35 |
+
*/
|
36 |
+
$product = $this->getMetaProduct();
|
37 |
+
$currentCategory = $this->getCurrentCategory();
|
38 |
+
$helper = Mage::helper('nosto_tagging');
|
39 |
+
$priceHelper = Mage::helper('nosto_tagging/price');
|
40 |
+
$dateHelper = Mage::helper('nosto_tagging/date');
|
41 |
+
?>
|
42 |
+
|
43 |
+
<!-- Nosto Product Tagging -->
|
44 |
+
<div class="nosto_product" style="display:none">
|
45 |
+
<span class="url"><?php echo $product->getUrl(); ?></span>
|
46 |
+
<span class="product_id"><?php echo $product->getProductId(); ?></span>
|
47 |
+
<span class="name"><?php echo $helper->escapeHtml($product->getName()); ?></span>
|
48 |
+
<span class="image_url"><?php echo $product->getImageUrl(); ?></span>
|
49 |
+
<span class="price"><?php echo $priceHelper->getFormattedPrice($product->getPrice()); ?></span>
|
50 |
+
<span class="price_currency_code"><?php echo $product->getCurrencyCode(); ?></span>
|
51 |
+
<span class="availability"><?php echo $product->getAvailability(); ?></span>
|
52 |
+
<?php foreach ($product->getCategories() as $category): ?>
|
53 |
+
<span class="category"><?php echo $helper->escapeHtml($category); ?></span>
|
54 |
+
<?php endforeach; ?>
|
55 |
+
<span class="description"><?php echo $helper->escapeHtml($product->getDescription()); ?></span>
|
56 |
+
<span class="list_price"><?php echo $priceHelper->getFormattedPrice($product->getListPrice()); ?></span>
|
57 |
+
<?php if ($product->getBrand() !== ""): ?>
|
58 |
+
<span class="brand"><?php echo $helper->escapeHtml($product->getBrand()); ?></span>
|
59 |
+
<?php endif; ?>
|
60 |
+
<span class="date_published"><?php echo $dateHelper->getFormattedDate($product->getDatePublished()); ?></span>
|
61 |
+
<?php foreach ($product->getTags() as $tag): ?>
|
62 |
+
<span class="tag1"><?php echo $helper->escapeHtml($tag); ?></span>
|
63 |
+
<?php endforeach; ?>
|
64 |
+
</div>
|
65 |
+
<?php if (!empty($currentCategory)): ?>
|
66 |
+
<div class="nosto_category" style="display:none"><?php echo $helper->escapeHtml($currentCategory); ?></div>
|
67 |
+
<?php endif; ?>
|
app/etc/modules/Nosto_Tagging.xml
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<!--
|
3 |
+
/**
|
4 |
+
* Magento
|
5 |
+
*
|
6 |
+
* NOTICE OF LICENSE
|
7 |
+
*
|
8 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
9 |
+
* that is bundled with this package in the file LICENSE.txt.
|
10 |
+
* It is also available through the world-wide-web at this URL:
|
11 |
+
* http://opensource.org/licenses/osl-3.0.php
|
12 |
+
* If you did not receive a copy of the license and are unable to
|
13 |
+
* obtain it through the world-wide-web, please send an email
|
14 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
15 |
+
*
|
16 |
+
* DISCLAIMER
|
17 |
+
*
|
18 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
19 |
+
* versions in the future. If you wish to customize Magento for your
|
20 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
21 |
+
*
|
22 |
+
* @category Nosto
|
23 |
+
* @package Nosto_Tagging
|
24 |
+
* @author Nosto Solutions Ltd <magento@nosto.com>
|
25 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
26 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
27 |
+
*/
|
28 |
+
-->
|
29 |
+
<config>
|
30 |
+
<modules>
|
31 |
+
<Nosto_Tagging>
|
32 |
+
<active>true</active>
|
33 |
+
<codePool>community</codePool>
|
34 |
+
<depends>
|
35 |
+
<Mage_Core/>
|
36 |
+
<Mage_Catalog/>
|
37 |
+
<Mage_Sales/>
|
38 |
+
</depends>
|
39 |
+
</Nosto_Tagging>
|
40 |
+
</modules>
|
41 |
+
</config>
|
js/nosto/NostoIframe.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
if("undefined"==typeof Nosto)var Nosto={};Nosto.iframe=function(a){function b(a){if(a.origin===decodeURIComponent(j.origin)&&"[Nosto]"===(""+a.data).substr(0,7)){var b=(""+a.data).substr(7),d=JSON.parse(b);if("object"==typeof d&&d.type)switch(d.type){case g:c(j.urls.createAccount,{data:{email:d.params.email},success:function(a){var b=JSON.parse(a.target.response);if(!b.redirect_url)throw new Error("Nosto: failed to handle account creation.");f().src=b.redirect_url}});break;case h:c(j.urls.connectAccount,{success:function(a){var b=JSON.parse(a.target.response);if(!b.redirect_url)throw new Error("Nosto: failed to handle account connection.");b.success&&b.success===!0?window.location.href=b.redirect_url:f().src=b.redirect_url}});break;case i:c(j.urls.deleteAccount,{success:function(a){var b=JSON.parse(a.target.response);if(!b.redirect_url)throw new Error("Nosto: failed to handle account deletion.");f().src=b.redirect_url}});break;default:throw new Error("Nosto: invalid postMessage `type`.")}}}function c(a,b){var c=d({method:"POST",async:!0,data:{}},b);d(c.data,j.xhrParams);var f=e(c.data),g=new XMLHttpRequest;"function"==typeof c.success&&g.addEventListener("load",c.success,!1),"function"==typeof c.error&&g.addEventListener("error",c.error,!1),g.open(c.method,decodeURIComponent(a),c.async),g.setRequestHeader("X-Requested-With","XMLHttpRequest"),g.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),g.send(f)}function d(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}function e(a){var b="";for(var c in a)a.hasOwnProperty(c)&&(""!==b&&(b+="&"),b+=encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b}function f(){return document.getElementById(j.iframeId)}var g="newAccount",h="connectAccount",i="removeAccount",j={origin:"https://my.nosto.com",iframeId:"nosto_iframe",urls:{createAccount:"",connectAccount:"",deleteAccount:""},xhrParams:{}};d(j,a),window.addEventListener("message",b,!1)};
|
js/nosto/iframeresizer.min.js
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* iFrame Resizer (iframesizer.min.js ) - v2.6.2 - 2014-10-11
|
3 |
+
* Desc: Force cross domain iframes to size to content.
|
4 |
+
* Requires: iframeResizer.contentWindow.min.js to be loaded into the target frame.
|
5 |
+
* Copyright: (c) 2014 David J. Bradshaw - dave@bradshaw.net
|
6 |
+
* License: MIT
|
7 |
+
*/
|
8 |
+
|
9 |
+
!function(){"use strict";function a(a,b,c){"addEventListener"in window?a.addEventListener(b,c,!1):"attachEvent"in window&&a.attachEvent("on"+b,c)}function b(){var a,b=["moz","webkit","o","ms"];for(a=0;a<b.length&&!w;a+=1)w=window[b[a]+"RequestAnimationFrame"];w||c(" RequestAnimationFrame not supported")}function c(a){y.log&&"object"==typeof console&&console.log(s+"[Host page"+u+"]"+a)}function d(a){function b(){function a(){h(z),f(),y.resizedCallback(z)}i(a,z,"resetPage")}function d(a){var b=a.id;c(" Removing iFrame: "+b),a.parentNode.removeChild(a),y.closedCallback(b),c(" --")}function e(){var a=x.substr(t).split(":");return{iframe:document.getElementById(a[0]),id:a[0],height:a[1],width:a[2],type:a[3]}}function j(a){var b=Number(y["max"+a]),d=Number(y["min"+a]),e=a.toLowerCase(),f=Number(z[e]);if(d>b)throw new Error("Value for min"+a+" can not be greater than max"+a);c(" Checking "+e+" is in range "+d+"-"+b),d>f&&(f=d,c(" Set "+e+" to min value")),f>b&&(f=b,c(" Set "+e+" to max value")),z[e]=""+f}function k(){var b=a.origin,d=z.iframe.src.split("/").slice(0,3).join("/");if(y.checkOrigin&&(c(" Checking connection is from: "+d),""+b!="null"&&b!==d))throw new Error("Unexpected message received from: "+b+" for "+z.iframe.id+". Message was: "+a.data+". This error can be disabled by adding the checkOrigin: false option.");return!0}function l(){return s===(""+x).substr(0,t)}function m(){var a=z.type in{"true":1,"false":1};return a&&c(" Ignoring init message from meta parent page"),a}function n(){var a=x.substr(x.indexOf(":")+r+6);c(" MessageCallback passed: {iframe: "+z.iframe.id+", message: "+a+"}"),y.messageCallback({iframe:z.iframe,message:a}),c(" --")}function o(){if(null===z.iframe)throw new Error("iFrame ("+z.id+") does not exist on "+u);return!0}function q(){c(" Reposition requested from iFrame"),v={x:z.width,y:z.height},f()}function w(){switch(z.type){case"close":d(z.iframe),y.resizedCallback(z);break;case"message":n();break;case"scrollTo":q();break;case"reset":g(z);break;case"init":b(),y.initCallback(z.iframe);break;default:b()}}var x=a.data,z={};l()&&(c(" Received: "+x),z=e(),j("Height"),j("Width"),!m()&&o()&&k()&&(w(),p=!1))}function e(){null===v&&(v={x:void 0!==window.pageXOffset?window.pageXOffset:document.documentElement.scrollLeft,y:void 0!==window.pageYOffset?window.pageYOffset:document.documentElement.scrollTop},c(" Get position: "+v.x+","+v.y))}function f(){null!==v&&(window.scrollTo(v.x,v.y),c(" Set position: "+v.x+","+v.y),v=null)}function g(a){function b(){h(a),j("reset","reset",a.iframe)}c(" Size reset requested by "+("init"===a.type?"host page":"iFrame")),e(),i(b,a,"init")}function h(a){function b(b){a.iframe.style[b]=a[b]+"px",c(" IFrame ("+a.iframe.id+") "+b+" set to "+a[b]+"px")}y.sizeHeight&&b("height"),y.sizeWidth&&b("width")}function i(a,b,d){d!==b.type&&w?(c(" Requesting animation frame"),w(a)):a()}function j(a,b,d){c("["+a+"] Sending msg to iframe ("+b+")"),d.contentWindow.postMessage(s+b,"*")}function k(){function b(){function a(a){1/0!==y[a]&&0!==y[a]&&(k.style[a]=y[a]+"px",c(" Set "+a+" = "+y[a]+"px"))}a("maxHeight"),a("minHeight"),a("maxWidth"),a("minWidth")}function d(a){return""===a&&(k.id=a="iFrameResizer"+o++,c(" Added missing iframe ID: "+a+" ("+k.src+")")),a}function e(){c(" IFrame scrolling "+(y.scrolling?"enabled":"disabled")+" for "+l),k.style.overflow=!1===y.scrolling?"hidden":"auto",k.scrolling=!1===y.scrolling?"no":"yes"}function f(){("number"==typeof y.bodyMargin||"0"===y.bodyMargin)&&(y.bodyMarginV1=y.bodyMargin,y.bodyMargin=""+y.bodyMargin+"px")}function h(){return l+":"+y.bodyMarginV1+":"+y.sizeWidth+":"+y.log+":"+y.interval+":"+y.enablePublicMethods+":"+y.autoResize+":"+y.bodyMargin+":"+y.heightCalculationMethod+":"+y.bodyBackground+":"+y.bodyPadding+":"+y.tolerance}function i(b){a(k,"load",function(){var a=p;j("iFrame.onload",b,k),!a&&y.heightCalculationMethod in x&&g({iframe:k,height:0,width:0,type:"init"})}),j("init",b,k)}var k=this,l=d(k.id);e(),b(),f(),i(h())}function l(a){if("object"!=typeof a)throw new TypeError("Options is not an object.")}function m(){function a(a){if("IFRAME"!==a.tagName.toUpperCase())throw new TypeError("Expected <IFRAME> tag, found <"+a.tagName+">.");k.call(a)}function b(a){a=a||{},l(a);for(var b in z)z.hasOwnProperty(b)&&(y[b]=a.hasOwnProperty(b)?a[b]:z[b])}return function(c,d){b(c),Array.prototype.forEach.call(document.querySelectorAll(d||"iframe"),a)}}function n(a){a.fn.iFrameResize=function(b){return b=b||{},l(b),y=a.extend({},z,b),this.filter("iframe").each(k).end()}}var o=0,p=!0,q="message",r=q.length,s="[iFrameSizer]",t=s.length,u="",v=null,w=window.requestAnimationFrame,x={max:1,scroll:1,bodyScroll:1,documentElementScroll:1},y={},z={autoResize:!0,bodyBackground:null,bodyMargin:null,bodyMarginV1:8,bodyPadding:null,checkOrigin:!0,enablePublicMethods:!1,heightCalculationMethod:"offset",interval:32,log:!1,maxHeight:1/0,maxWidth:1/0,minHeight:0,minWidth:0,scrolling:!1,sizeHeight:!0,sizeWidth:!1,tolerance:0,closedCallback:function(){},initCallback:function(){},messageCallback:function(){},resizedCallback:function(){}};b(),a(window,"message",d),window.jQuery&&n(jQuery),"function"==typeof define&&define.amd?define(function(){return m()}):window.iFrameResize=m()}();
|
js/nosto/nostotagging-config.js
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Magento
|
3 |
+
*
|
4 |
+
* NOTICE OF LICENSE
|
5 |
+
*
|
6 |
+
* This source file is subject to the Open Software License (OSL 3.0)
|
7 |
+
* that is bundled with this package in the file LICENSE.txt.
|
8 |
+
* It is also available through the world-wide-web at this URL:
|
9 |
+
* http://opensource.org/licenses/osl-3.0.php
|
10 |
+
* If you did not receive a copy of the license and are unable to
|
11 |
+
* obtain it through the world-wide-web, please send an email
|
12 |
+
* to license@magentocommerce.com so we can send you a copy immediately.
|
13 |
+
*
|
14 |
+
* DISCLAIMER
|
15 |
+
*
|
16 |
+
* Do not edit or add to this file if you wish to upgrade Magento to newer
|
17 |
+
* versions in the future. If you wish to customize Magento for your
|
18 |
+
* needs please refer to http://www.magentocommerce.com for more information.
|
19 |
+
*
|
20 |
+
* @category Nosto
|
21 |
+
* @package Nosto_Tagging
|
22 |
+
* @copyright Copyright (c) 2013-2015 Nosto Solutions Ltd (http://www.nosto.com)
|
23 |
+
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
24 |
+
*/
|
25 |
+
|
26 |
+
document.observe("dom:loaded", function() {
|
27 |
+
// Init the iframe re-sizer.
|
28 |
+
iFrameResize({heightCalculationMethod : "bodyScroll"});
|
29 |
+
|
30 |
+
// Init the Nosto iframe API.
|
31 |
+
Nosto.iframe(Nosto.settings);
|
32 |
+
});
|
lib/nosto/php-sdk/src/.env.example
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
NOSTO_SERVER_URL=connect.nosto.com
|
2 |
+
NOSTO_API_BASE_URL=https://api.nosto.com
|
3 |
+
NOSTO_OAUTH_BASE_URL=https://my.nosto.com/oauth
|
4 |
+
NOSTO_WEB_HOOK_BASE_URL=https://my.nosto.com
|
5 |
+
NOSTO_IFRAME_ORIGIN=https://my.nosto.com
|
lib/nosto/php-sdk/src/classes/Nosto.php
ADDED
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Main SDK class.
|
38 |
+
* Provides common functionality for the SDK.
|
39 |
+
*/
|
40 |
+
class Nosto
|
41 |
+
{
|
42 |
+
/**
|
43 |
+
* @var array registry collection
|
44 |
+
*/
|
45 |
+
private static $registry = array();
|
46 |
+
|
47 |
+
/**
|
48 |
+
* Return environment variable.
|
49 |
+
*
|
50 |
+
* @param string $name the name of the variable.
|
51 |
+
* @param null $default the default value to return if the env variable cannot be found.
|
52 |
+
* @return mixed the env variable or null.
|
53 |
+
*/
|
54 |
+
public static function getEnvVariable($name, $default = null)
|
55 |
+
{
|
56 |
+
return isset($_ENV[$name]) ? $_ENV[$name] : $default;
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Gets a helper class instance by name.
|
61 |
+
*
|
62 |
+
* @param string $helper the name of the helper class to get.
|
63 |
+
* @return NostoHelper the helper instance.
|
64 |
+
* @throws NostoException if helper cannot be found.
|
65 |
+
*/
|
66 |
+
public static function helper($helper)
|
67 |
+
{
|
68 |
+
$registryKey = '__helper__/'.$helper;
|
69 |
+
if (!self::registry($registryKey)) {
|
70 |
+
$helperClass = self::getHelperClassName($helper);
|
71 |
+
if (!class_exists($helperClass)) {
|
72 |
+
throw new NostoException(sprintf('Unknown helper class %s', $helperClass));
|
73 |
+
}
|
74 |
+
self::register($registryKey, new $helperClass);
|
75 |
+
}
|
76 |
+
return self::registry($registryKey);
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Retrieve a value from registry by a key.
|
81 |
+
*
|
82 |
+
* @param string $key the register key for the variable.
|
83 |
+
* @return mixed the registered variable or null if not found.
|
84 |
+
*/
|
85 |
+
public static function registry($key)
|
86 |
+
{
|
87 |
+
if (isset(self::$registry[$key])) {
|
88 |
+
return self::$registry[$key];
|
89 |
+
}
|
90 |
+
return null;
|
91 |
+
}
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Register a new variable.
|
95 |
+
*
|
96 |
+
* @param string $key the key to register the variable for.
|
97 |
+
* @param mixed $value the variable to register.
|
98 |
+
* @throws NostoException if the key is already registered.
|
99 |
+
*/
|
100 |
+
public static function register($key, $value)
|
101 |
+
{
|
102 |
+
if (isset(self::$registry[$key])) {
|
103 |
+
throw new NostoException(sprintf('Nosto registry key %s already exists', $key));
|
104 |
+
}
|
105 |
+
self::$registry[$key] = $value;
|
106 |
+
}
|
107 |
+
|
108 |
+
/**
|
109 |
+
* Converts a helper class name reference name to a real class name.
|
110 |
+
*
|
111 |
+
* Examples:
|
112 |
+
*
|
113 |
+
* date => NostoHelperDate
|
114 |
+
* price_rule => NostoHelperPriceRule
|
115 |
+
* nosto/date => NostoHelperDate
|
116 |
+
* nosto/price_rule => NostoHelperPriceRule
|
117 |
+
* nosto_tagging/date => NostoTaggingHelperDate
|
118 |
+
* nosto_tagging/price_rule => NostoTaggingHelperPriceRule
|
119 |
+
*
|
120 |
+
* @param string $ref the helper reference name.
|
121 |
+
* @return string|bool the helper class name or false if it cannot be built.
|
122 |
+
*/
|
123 |
+
protected static function getHelperClassName($ref)
|
124 |
+
{
|
125 |
+
if (strpos($ref, '/') === false) {
|
126 |
+
$ref = 'nosto/'.$ref;
|
127 |
+
}
|
128 |
+
return str_replace(' ', '', ucwords(str_replace('_', ' ', str_replace('/', ' Helper ', $ref))));
|
129 |
+
}
|
130 |
+
}
|
lib/nosto/php-sdk/src/classes/NostoAccount.php
ADDED
@@ -0,0 +1,238 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Nosto account class for handling account related actions like, creation, OAuth2 syncing and SSO to Nosto.
|
38 |
+
*/
|
39 |
+
class NostoAccount implements NostoAccountInterface
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* @var string the name of the Nosto account.
|
43 |
+
*/
|
44 |
+
public $name;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @var NostoApiToken[] the Nosto API tokens associated with this account.
|
48 |
+
*/
|
49 |
+
public $tokens = array();
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @inheritdoc
|
53 |
+
*/
|
54 |
+
public static function create(NostoAccountMetaDataInterface $meta)
|
55 |
+
{
|
56 |
+
$params = array(
|
57 |
+
'title' => $meta->getTitle(),
|
58 |
+
'name' => $meta->getName(),
|
59 |
+
'platform' => $meta->getPlatform(),
|
60 |
+
'front_page_url' => $meta->getFrontPageUrl(),
|
61 |
+
'currency_code' => strtoupper($meta->getCurrencyCode()),
|
62 |
+
'language_code' => strtolower($meta->getOwnerLanguageCode()),
|
63 |
+
'owner' => array(
|
64 |
+
'first_name' => $meta->getOwner()->getFirstName(),
|
65 |
+
'last_name' => $meta->getOwner()->getLastName(),
|
66 |
+
'email' => $meta->getOwner()->getEmail(),
|
67 |
+
),
|
68 |
+
'billing_details' => array(
|
69 |
+
'country' => strtoupper($meta->getBillingDetails()->getCountry()),
|
70 |
+
),
|
71 |
+
'api_tokens' => array(),
|
72 |
+
);
|
73 |
+
|
74 |
+
foreach (NostoApiToken::$tokenNames as $name) {
|
75 |
+
$params['api_tokens'][] = 'api_'.$name;
|
76 |
+
}
|
77 |
+
|
78 |
+
$request = new NostoApiRequest();
|
79 |
+
$request->setPath(NostoApiRequest::PATH_SIGN_UP);
|
80 |
+
$request->setReplaceParams(array('{lang}' => $meta->getLanguageCode()));
|
81 |
+
$request->setContentType('application/json');
|
82 |
+
$request->setAuthBasic('', $meta->getSignUpApiToken());
|
83 |
+
$response = $request->post(json_encode($params));
|
84 |
+
|
85 |
+
if ($response->getCode() !== 200) {
|
86 |
+
throw new NostoException('Nosto account could not be created', $response->getCode());
|
87 |
+
}
|
88 |
+
|
89 |
+
$account = new self;
|
90 |
+
$account->name = $meta->getPlatform().'-'.$meta->getName();
|
91 |
+
$account->tokens = NostoApiToken::parseTokens($response->getJsonResult(true), '', '_token');
|
92 |
+
return $account;
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* @inheritdoc
|
97 |
+
*/
|
98 |
+
public static function syncFromNosto(NostoOAuthClientMetaDataInterface $meta, $code)
|
99 |
+
{
|
100 |
+
$oauthClient = new NostoOAuthClient($meta);
|
101 |
+
$token = $oauthClient->authenticate($code);
|
102 |
+
|
103 |
+
if (empty($token->accessToken)) {
|
104 |
+
throw new NostoException('No access token found when trying to sync account from Nosto');
|
105 |
+
}
|
106 |
+
if (empty($token->merchantName)) {
|
107 |
+
throw new NostoException('No merchant name found when trying to sync account from Nosto');
|
108 |
+
}
|
109 |
+
|
110 |
+
$request = new NostoHttpRequest();
|
111 |
+
// The request is currently not made according the the OAuth2 spec with the access token in the
|
112 |
+
// Authorization header. This is due to the authentication server not implementing the full OAuth2 spec yet.
|
113 |
+
$request->setUrl(NostoOAuthClient::$baseUrl.'/exchange');
|
114 |
+
$request->setQueryParams(array('access_token' => $token->accessToken));
|
115 |
+
$response = $request->get();
|
116 |
+
$result = $response->getJsonResult(true);
|
117 |
+
|
118 |
+
if ($response->getCode() !== 200) {
|
119 |
+
throw new NostoException('Failed to sync account from Nosto', $response->getCode());
|
120 |
+
}
|
121 |
+
if (empty($result)) {
|
122 |
+
throw new NostoException('Received invalid data from Nosto when trying to sync account');
|
123 |
+
}
|
124 |
+
|
125 |
+
$account = new self;
|
126 |
+
$account->name = $token->merchantName;
|
127 |
+
$account->tokens = NostoApiToken::parseTokens($result, 'api_');
|
128 |
+
if (!$account->isConnectedToNosto()) {
|
129 |
+
throw new NostoException('Failed to sync all account details from Nosto');
|
130 |
+
}
|
131 |
+
return $account;
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* @inheritdoc
|
136 |
+
*/
|
137 |
+
public function delete()
|
138 |
+
{
|
139 |
+
$token = $this->getApiToken('sso');
|
140 |
+
if ($token === null) {
|
141 |
+
throw new NostoException('Failed to notify Nosto about deleted account, no "sso" token');
|
142 |
+
}
|
143 |
+
|
144 |
+
$request = new NostoHttpRequest();
|
145 |
+
$request->setUrl(NostoHttpRequest::$baseUrl.NostoHttpRequest::PATH_ACCOUNT_DELETED);
|
146 |
+
$request->setAuthBasic('', $token->value);
|
147 |
+
$response = $request->post('');
|
148 |
+
|
149 |
+
if ($response->getCode() !== 200) {
|
150 |
+
throw new NostoException('Failed to notify Nosto about deleted account', $response->getCode());
|
151 |
+
}
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* @inheritdoc
|
156 |
+
*/
|
157 |
+
public function getName()
|
158 |
+
{
|
159 |
+
return $this->name;
|
160 |
+
}
|
161 |
+
|
162 |
+
/**
|
163 |
+
* @inheritdoc
|
164 |
+
*/
|
165 |
+
public function isConnectedToNosto()
|
166 |
+
{
|
167 |
+
if (empty($this->tokens)) {
|
168 |
+
return false;
|
169 |
+
}
|
170 |
+
$countTokens = count($this->tokens);
|
171 |
+
$foundTokens = 0;
|
172 |
+
foreach (NostoApiToken::$tokenNames as $name) {
|
173 |
+
foreach ($this->tokens as $token) {
|
174 |
+
if ($token->name === $name) {
|
175 |
+
$foundTokens++;
|
176 |
+
break;
|
177 |
+
}
|
178 |
+
}
|
179 |
+
}
|
180 |
+
return ($countTokens === $foundTokens);
|
181 |
+
}
|
182 |
+
|
183 |
+
/**
|
184 |
+
* @inheritdoc
|
185 |
+
*/
|
186 |
+
public function getApiToken($name)
|
187 |
+
{
|
188 |
+
foreach ($this->tokens as $token) {
|
189 |
+
if ($token->name === $name) {
|
190 |
+
return $token;
|
191 |
+
}
|
192 |
+
}
|
193 |
+
return null;
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* @inheritdoc
|
198 |
+
*/
|
199 |
+
public function getIframeUrl(NostoAccountMetaDataIframeInterface $meta, array $params = array())
|
200 |
+
{
|
201 |
+
return Nosto::helper('iframe')->getUrl($meta, $this, $params);
|
202 |
+
}
|
203 |
+
|
204 |
+
/**
|
205 |
+
* @inheritdoc
|
206 |
+
*/
|
207 |
+
public function ssoLogin(NostoAccountMetaDataIframeInterface $meta)
|
208 |
+
{
|
209 |
+
$token = $this->getApiToken('sso');
|
210 |
+
if ($token === null) {
|
211 |
+
return false;
|
212 |
+
}
|
213 |
+
|
214 |
+
$request = new NostoApiRequest();
|
215 |
+
$request->setPath(NostoApiRequest::PATH_SSO_AUTH);
|
216 |
+
$request->setReplaceParams(array('{email}' => $meta->getEmail()));
|
217 |
+
$request->setContentType('application/json');
|
218 |
+
$request->setAuthBasic('', $token->value);
|
219 |
+
$response = $request->post(
|
220 |
+
json_encode(
|
221 |
+
array(
|
222 |
+
'first_name' => $meta->getFirstName(),
|
223 |
+
'last_name' => $meta->getLastName(),
|
224 |
+
)
|
225 |
+
)
|
226 |
+
);
|
227 |
+
$result = $response->getJsonResult();
|
228 |
+
|
229 |
+
if ($response->getCode() !== 200) {
|
230 |
+
throw new NostoException('Unable to login employee to Nosto with SSO token', $response->getCode());
|
231 |
+
}
|
232 |
+
if (empty($result->login_url)) {
|
233 |
+
throw new NostoException('No "login_url" returned when logging in employee to Nosto');
|
234 |
+
}
|
235 |
+
|
236 |
+
return $result->login_url;
|
237 |
+
}
|
238 |
+
}
|
lib/nosto/php-sdk/src/classes/NostoCipher.php
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Helper class for encrypting/decrypting strings.
|
38 |
+
*/
|
39 |
+
class NostoCipher
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* @var NostoCryptBase the crypt library instance.
|
43 |
+
*/
|
44 |
+
private $crypt;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Constructor.
|
48 |
+
*/
|
49 |
+
public function __construct()
|
50 |
+
{
|
51 |
+
$this->crypt = new NostoCryptAES(CRYPT_AES_MODE_CBC);
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Sets the secret to use for encryption/decryption.
|
56 |
+
*
|
57 |
+
* @param string $secret the secret.
|
58 |
+
*/
|
59 |
+
public function setSecret($secret)
|
60 |
+
{
|
61 |
+
$this->crypt->setKey($secret);
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Sets the initialization vector to use for encryption/decryption.
|
66 |
+
*
|
67 |
+
* @param string $iv the initialization vector.
|
68 |
+
*/
|
69 |
+
public function setIV($iv)
|
70 |
+
{
|
71 |
+
$this->crypt->setIV($iv);
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Encrypts the string an returns iv.encrypted.
|
76 |
+
*
|
77 |
+
* @param string $plaintext the string to encrypt.
|
78 |
+
* @return string the encrypted string.
|
79 |
+
*/
|
80 |
+
public function encrypt($plaintext)
|
81 |
+
{
|
82 |
+
return $this->crypt->encrypt($plaintext);
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Decrypts the string and returns the plain text.
|
87 |
+
*
|
88 |
+
* @param string $ciphertext the encrypted cipher.
|
89 |
+
* @return string the decrypted plain text string.
|
90 |
+
*/
|
91 |
+
public function decrypt($ciphertext)
|
92 |
+
{
|
93 |
+
return $this->crypt->decrypt($ciphertext);
|
94 |
+
}
|
95 |
+
}
|
lib/nosto/php-sdk/src/classes/NostoDotEnv.php
ADDED
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Helper class for loading local environment variables and assigning them to $_ENV.
|
38 |
+
*/
|
39 |
+
class NostoDotEnv
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* @var NostoDotEnv the runtime cache for the class instance.
|
43 |
+
*/
|
44 |
+
private static $instance;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* Constructor.
|
48 |
+
* Private; Singleton pattern.
|
49 |
+
*/
|
50 |
+
private function __construct()
|
51 |
+
{
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Getter for the singleton instance.
|
56 |
+
*
|
57 |
+
* @return NostoDotEnv the singleton instance.
|
58 |
+
*/
|
59 |
+
public static function getInstance()
|
60 |
+
{
|
61 |
+
if (self::$instance === null) {
|
62 |
+
self::$instance = new NostoDotEnv();
|
63 |
+
}
|
64 |
+
return self::$instance;
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Initializes the environment variables from ".env" if it exists.
|
69 |
+
*
|
70 |
+
* @param string $path the path where to find the ".env" file.
|
71 |
+
* @param string $fileName the name of the file; defaults to ".env".
|
72 |
+
*/
|
73 |
+
public function init($path, $fileName = '.env')
|
74 |
+
{
|
75 |
+
$file = (!empty($path) ? rtrim($path, '/').'/' : '').$fileName;
|
76 |
+
if (is_file($file) && is_readable($file)) {
|
77 |
+
foreach ($this->parseFile($file) as $line) {
|
78 |
+
$this->setEnvVariable($line);
|
79 |
+
}
|
80 |
+
}
|
81 |
+
}
|
82 |
+
|
83 |
+
/**
|
84 |
+
* Parses the ".env" file into lines and returns them as an array.
|
85 |
+
*
|
86 |
+
* @param string $file the path of the file to parse.
|
87 |
+
* @return array the parsed lines from the file.
|
88 |
+
*/
|
89 |
+
protected function parseFile($file)
|
90 |
+
{
|
91 |
+
$autodetect = ini_get('auto_detect_line_endings');
|
92 |
+
ini_set('auto_detect_line_endings', '1');
|
93 |
+
$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
94 |
+
ini_set('auto_detect_line_endings', $autodetect);
|
95 |
+
return is_array($lines) ? $lines : array();
|
96 |
+
}
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Sets a non-existent variable in $_ENV.
|
100 |
+
*
|
101 |
+
* @param string $var the environment variable to set.
|
102 |
+
*/
|
103 |
+
protected function setEnvVariable($var)
|
104 |
+
{
|
105 |
+
if (strpos(trim($var), '#') !== 0 && strpos($var, '=') !== false) {
|
106 |
+
list($name, $value) = $this->normalizeEnvVariable($var);
|
107 |
+
if (!isset($_ENV[$name])) {
|
108 |
+
$_ENV[$name] = $value;
|
109 |
+
}
|
110 |
+
}
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Normalizes the given variable into a variable name and value.
|
115 |
+
*
|
116 |
+
* @param string $var the variable to normalize.
|
117 |
+
* @return array the variable name and value as an array.
|
118 |
+
*/
|
119 |
+
protected function normalizeEnvVariable($var)
|
120 |
+
{
|
121 |
+
list($name, $value) = array_map('trim', explode('=', $var, 2));
|
122 |
+
$name = $this->sanitizeVariableName($name);
|
123 |
+
$value = $this->sanitizeVariableValue($value);
|
124 |
+
$value = $this->resolveNestedVariables($value);
|
125 |
+
return array($name, $value);
|
126 |
+
}
|
127 |
+
|
128 |
+
/**
|
129 |
+
* Sanitizes the variable value, i.e. strips quotes.
|
130 |
+
*
|
131 |
+
* @param string $value the variable value to sanitize.
|
132 |
+
* @return string the sanitized value.
|
133 |
+
*/
|
134 |
+
protected function sanitizeVariableValue($value)
|
135 |
+
{
|
136 |
+
$value = trim($value);
|
137 |
+
if (!$value) {
|
138 |
+
return '';
|
139 |
+
}
|
140 |
+
if (strpbrk($value[0], '"\'') !== false) { // value starts with a quote
|
141 |
+
$quote = $value[0];
|
142 |
+
$regexPattern = sprintf(
|
143 |
+
'/^
|
144 |
+
%1$s # match a quote at the start of the value
|
145 |
+
( # capturing sub-pattern used
|
146 |
+
(?: # we do not need to capture this
|
147 |
+
[^%1$s\\\\] # any character other than a quote or backslash
|
148 |
+
|\\\\\\\\ # or two backslashes together
|
149 |
+
|\\\\%1$s # or an escaped quote e.g \"
|
150 |
+
)* # as many characters that match the previous rules
|
151 |
+
) # end of the capturing sub-pattern
|
152 |
+
%1$s # and the closing quote
|
153 |
+
.*$ # and discard any string after the closing quote
|
154 |
+
/mx',
|
155 |
+
$quote
|
156 |
+
);
|
157 |
+
$value = preg_replace($regexPattern, '$1', $value);
|
158 |
+
$value = str_replace("\\$quote", $quote, $value);
|
159 |
+
$value = str_replace('\\\\', '\\', $value);
|
160 |
+
} else {
|
161 |
+
$parts = explode(' #', $value, 2);
|
162 |
+
$value = $parts[0];
|
163 |
+
}
|
164 |
+
return trim($value);
|
165 |
+
}
|
166 |
+
|
167 |
+
/**
|
168 |
+
* Sanitizes the variable name, i.e. strips quotes.
|
169 |
+
*
|
170 |
+
* @param string $name the variable name to sanitize.
|
171 |
+
* @return string the sanitized name.
|
172 |
+
*/
|
173 |
+
protected function sanitizeVariableName($name)
|
174 |
+
{
|
175 |
+
return trim(str_replace(array('\'', '"'), '', $name));
|
176 |
+
}
|
177 |
+
|
178 |
+
/**
|
179 |
+
* Look for {$name} patterns in the variable value and replace with an existing environment variable.
|
180 |
+
*
|
181 |
+
* @param string $value the variable value to search for nested variables.
|
182 |
+
* @return string the resolved variable value.
|
183 |
+
*/
|
184 |
+
protected function resolveNestedVariables($value)
|
185 |
+
{
|
186 |
+
if (strpos($value, '$') !== false) {
|
187 |
+
$value = preg_replace_callback('/{\$([a-zA-Z0-9_]+)}/', array($this, 'getMatchedVariable'), $value);
|
188 |
+
}
|
189 |
+
return $value;
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Callback for getting the matched variable value.
|
194 |
+
*
|
195 |
+
* @param array $match the match from preg_replace_callback().
|
196 |
+
* @return mixed the matched variable value or the variable name if not found.
|
197 |
+
*/
|
198 |
+
protected function getMatchedVariable($match)
|
199 |
+
{
|
200 |
+
return isset($_ENV[$match[1]]) ? $_ENV[$match[1]] : $match[0];
|
201 |
+
}
|
202 |
+
}
|
lib/nosto/php-sdk/src/classes/NostoException.php
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Nosto exception class for all errors within the sdk.
|
38 |
+
*/
|
39 |
+
class NostoException extends Exception
|
40 |
+
{
|
41 |
+
}
|
lib/nosto/php-sdk/src/classes/NostoMessage.php
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Util class for providing message types and codes that are used for forwarding
|
38 |
+
* information to the account administration iframe so we can show feedback to
|
39 |
+
* the user.
|
40 |
+
*/
|
41 |
+
class NostoMessage
|
42 |
+
{
|
43 |
+
const TYPE_SUCCESS = 'success';
|
44 |
+
const TYPE_ERROR = 'error';
|
45 |
+
|
46 |
+
const CODE_ACCOUNT_CREATE = 'account_create';
|
47 |
+
const CODE_ACCOUNT_CONNECT = 'account_connect';
|
48 |
+
const CODE_ACCOUNT_DELETE = 'account_delete';
|
49 |
+
const CODE_ACCOUNT_CONNECT_REJECT = 'account_connect_reject';
|
50 |
+
}
|
lib/nosto/php-sdk/src/classes/NostoOrderConfirmation.php
ADDED
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Handles sending the order confirmations to Nosto via the API.
|
38 |
+
*
|
39 |
+
* Order confirmations can be sent two different ways:
|
40 |
+
* - matched orders; where we know the Nosto customer ID of the user who placed the order
|
41 |
+
* - un-matched orders: where we do not know the Nosto customer ID of the user who placed the order
|
42 |
+
*
|
43 |
+
* The second option is a fallback and should be avoided as much as possible.
|
44 |
+
*/
|
45 |
+
class NostoOrderConfirmation
|
46 |
+
{
|
47 |
+
/**
|
48 |
+
* Sends the order confirmation to Nosto.
|
49 |
+
*
|
50 |
+
* @param NostoOrderInterface $order the placed order model.
|
51 |
+
* @param NostoAccountInterface $account the Nosto account for the shop where the order was placed.
|
52 |
+
* @param null $customerId the Nosto customer ID of the user who placed the order.
|
53 |
+
* @throws NostoException on failure.
|
54 |
+
* @return true on success.
|
55 |
+
*/
|
56 |
+
public static function send(NostoOrderInterface $order, NostoAccountInterface $account, $customerId = null)
|
57 |
+
{
|
58 |
+
if (!empty($customerId)) {
|
59 |
+
$path = NostoApiRequest::PATH_ORDER_TAGGING;
|
60 |
+
$replaceParams = array('{m}' => $account->getName(), '{cid}' => $customerId);
|
61 |
+
} else {
|
62 |
+
$path = NostoApiRequest::PATH_UNMATCHED_ORDER_TAGGING;
|
63 |
+
$replaceParams = array('{m}' => $account->getName());
|
64 |
+
}
|
65 |
+
$request = new NostoApiRequest();
|
66 |
+
$request->setPath($path);
|
67 |
+
$request->setContentType('application/json');
|
68 |
+
$request->setReplaceParams($replaceParams);
|
69 |
+
|
70 |
+
$orderData = array(
|
71 |
+
'order_number' => $order->getOrderNumber(),
|
72 |
+
'buyer' => array(
|
73 |
+
'first_name' => $order->getBuyerInfo()->getFirstName(),
|
74 |
+
'last_name' => $order->getBuyerInfo()->getLastName(),
|
75 |
+
'email' => $order->getBuyerInfo()->getEmail(),
|
76 |
+
),
|
77 |
+
'created_at' => Nosto::helper('date')->format($order->getCreatedDate()),
|
78 |
+
'payment_provider' => $order->getPaymentProvider(),
|
79 |
+
'purchased_items' => array(),
|
80 |
+
);
|
81 |
+
foreach ($order->getPurchasedItems() as $item) {
|
82 |
+
$orderData['purchased_items'][] = array(
|
83 |
+
'product_id' => $item->getProductId(),
|
84 |
+
'quantity' => (int)$item->getQuantity(),
|
85 |
+
'name' => $item->getName(),
|
86 |
+
'unit_price' => Nosto::helper('price')->format($item->getUnitPrice()),
|
87 |
+
'price_currency_code' => strtoupper($item->getCurrencyCode()),
|
88 |
+
);
|
89 |
+
}
|
90 |
+
$response = $request->post(json_encode($orderData));
|
91 |
+
if ($response->getCode() !== 200) {
|
92 |
+
throw new NostoException('Failed to send order confirmation to Nosto');
|
93 |
+
}
|
94 |
+
return true;
|
95 |
+
}
|
96 |
+
}
|
lib/nosto/php-sdk/src/classes/NostoProductReCrawl.php
ADDED
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Handles product re-crawl requests to Nosto via the API.
|
38 |
+
*/
|
39 |
+
class NostoProductReCrawl
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* Sends a product re-crawl request to nosto.
|
43 |
+
*
|
44 |
+
* @param NostoProductInterface $product the product to re-crawl.
|
45 |
+
* @param NostoAccountInterface $account the account to re-crawl the product for.
|
46 |
+
* @return bool true on success, false otherwise.
|
47 |
+
* @throws NostoException if the request fails or cannot be made.
|
48 |
+
*/
|
49 |
+
public static function send(NostoProductInterface $product, NostoAccountInterface $account)
|
50 |
+
{
|
51 |
+
return self::sendRequest($account, array(
|
52 |
+
'products' => array(
|
53 |
+
array(
|
54 |
+
'product_id' => $product->getProductId(),
|
55 |
+
'url' => $product->getUrl(),
|
56 |
+
)
|
57 |
+
),
|
58 |
+
));
|
59 |
+
}
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Sends a batch product re-crawl request to nosto.
|
63 |
+
*
|
64 |
+
* @param NostoExportProductCollection $collection the product collection to re-crawl.
|
65 |
+
* @param NostoAccountInterface $account the account to re-crawl the products for.
|
66 |
+
* @return bool true on success, false otherwise.
|
67 |
+
* @throws NostoException if the request fails or cannot be made.
|
68 |
+
*/
|
69 |
+
public static function sendBatch(NostoExportProductCollection $collection, NostoAccountInterface $account)
|
70 |
+
{
|
71 |
+
if ($collection->count() === 0) {
|
72 |
+
throw new NostoException('Failed to send product re-crawl to Nosto. No products in collection (Error 400).', 400);
|
73 |
+
}
|
74 |
+
$payload = array(
|
75 |
+
'products' => array()
|
76 |
+
);
|
77 |
+
foreach ($collection->getArrayCopy() as $product) {
|
78 |
+
/** @var NostoProductInterface $product */
|
79 |
+
$payload['products'][] = array(
|
80 |
+
'product_id' => $product->getProductId(),
|
81 |
+
'url' => $product->getUrl(),
|
82 |
+
);
|
83 |
+
}
|
84 |
+
return self::sendRequest($account, $payload);
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Sends the re-crawl API request to Nosto.
|
89 |
+
*
|
90 |
+
* @param NostoAccountInterface $account the account to re-crawl the product(s) for.
|
91 |
+
* @param array $payload the request payload as an array that will be json encoded.
|
92 |
+
* @return bool true on success.
|
93 |
+
* @throws NostoException if the request fails or cannot be made.
|
94 |
+
*/
|
95 |
+
protected static function sendRequest(NostoAccountInterface $account, array $payload)
|
96 |
+
{
|
97 |
+
$token = $account->getApiToken('products');
|
98 |
+
if ($token === null) {
|
99 |
+
throw new NostoException('Failed to send product re-crawl to Nosto. No `products` API token found for account (Error 400).', 400);
|
100 |
+
}
|
101 |
+
$request = new NostoApiRequest();
|
102 |
+
$request->setPath(NostoApiRequest::PATH_PRODUCT_RE_CRAWL);
|
103 |
+
$request->setContentType('application/json');
|
104 |
+
$request->setAuthBasic('', $token->value);
|
105 |
+
$response = $request->post(json_encode($payload));
|
106 |
+
if ($response->getCode() !== 200) {
|
107 |
+
throw new NostoException('Failed to send product re-crawl to Nosto (Error '.$response->getCode().').', $response->getCode());
|
108 |
+
}
|
109 |
+
return true;
|
110 |
+
}
|
111 |
+
}
|
lib/nosto/php-sdk/src/classes/NostoXhrResponse.php
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Util class for representing a XHR response object used when responding to
|
38 |
+
* account administration iframe API calls.
|
39 |
+
*/
|
40 |
+
class NostoXhrResponse
|
41 |
+
{
|
42 |
+
/**
|
43 |
+
* @var string the `Content-Type` of the response.
|
44 |
+
*/
|
45 |
+
public $contentType = 'application/json';
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @var bool the response success flag.
|
49 |
+
*/
|
50 |
+
protected $success = false;
|
51 |
+
|
52 |
+
/**
|
53 |
+
* @var string the response redirect url.
|
54 |
+
*/
|
55 |
+
protected $redirectUrl;
|
56 |
+
|
57 |
+
/**
|
58 |
+
* Sets the response success state.
|
59 |
+
*
|
60 |
+
* @param boolean $success the state.
|
61 |
+
* @return NostoXhrResponse the response instance.
|
62 |
+
*/
|
63 |
+
public function setSuccess($success)
|
64 |
+
{
|
65 |
+
$this->success = $success;
|
66 |
+
return $this;
|
67 |
+
}
|
68 |
+
|
69 |
+
/**
|
70 |
+
* Sets the response redirect url.
|
71 |
+
*
|
72 |
+
* @param string $url the url.
|
73 |
+
* @return NostoXhrResponse the response instance.
|
74 |
+
*/
|
75 |
+
public function setRedirectUrl($url)
|
76 |
+
{
|
77 |
+
$this->redirectUrl = $url;
|
78 |
+
return $this;
|
79 |
+
}
|
80 |
+
|
81 |
+
/**
|
82 |
+
* Sends the response, i.e. sends it to the browser.
|
83 |
+
* This method also sends the `Content-Type` header for the response data.
|
84 |
+
*/
|
85 |
+
public function send()
|
86 |
+
{
|
87 |
+
header('Content-Type: '.$this->contentType);
|
88 |
+
echo $this;
|
89 |
+
}
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Converts the response to a string and returns it.
|
93 |
+
*
|
94 |
+
* @return string the string representation of the response.
|
95 |
+
*/
|
96 |
+
public function __toString()
|
97 |
+
{
|
98 |
+
return (string)json_encode(array(
|
99 |
+
'success' => (bool)$this->success,
|
100 |
+
'redirect_url' => (string)$this->redirectUrl,
|
101 |
+
));
|
102 |
+
}
|
103 |
+
}
|
lib/nosto/php-sdk/src/classes/api/NostoApiRequest.php
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* API request class for making API requests to Nosto.
|
38 |
+
*/
|
39 |
+
class NostoApiRequest extends NostoHttpRequest
|
40 |
+
{
|
41 |
+
const PATH_ORDER_TAGGING = '/visits/order/confirm/{m}/{cid}';
|
42 |
+
const PATH_UNMATCHED_ORDER_TAGGING = '/visits/order/unmatched/{m}';
|
43 |
+
const PATH_SIGN_UP = '/accounts/create/{lang}';
|
44 |
+
const PATH_SSO_AUTH = '/users/sso/{email}';
|
45 |
+
const PATH_PRODUCT_RE_CRAWL = '/products/recrawl';
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @var string base url for the nosto api.
|
49 |
+
*/
|
50 |
+
public static $baseUrl = 'https://api.nosto.com';
|
51 |
+
|
52 |
+
/**
|
53 |
+
* Setter for the end point path, e.g. one of the PATH_ constants.
|
54 |
+
* The API base url is always prepended.
|
55 |
+
*
|
56 |
+
* @param string $path the endpoint path (use PATH_ constants).
|
57 |
+
*/
|
58 |
+
public function setPath($path)
|
59 |
+
{
|
60 |
+
$this->setUrl(self::$baseUrl.$path);
|
61 |
+
}
|
62 |
+
}
|
lib/nosto/php-sdk/src/classes/api/NostoApiToken.php
ADDED
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Class representing an API token for the Nosto API's.
|
38 |
+
*/
|
39 |
+
class NostoApiToken
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* @var string the token name, must be one of the defined tokens from self::$tokenNames.
|
43 |
+
*/
|
44 |
+
public $name;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @var string the token value, e.g. the actual token string.
|
48 |
+
*/
|
49 |
+
public $value;
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @var array list of valid api tokens to request from Nosto.
|
53 |
+
*/
|
54 |
+
public static $tokenNames = array(
|
55 |
+
'sso',
|
56 |
+
'products'
|
57 |
+
);
|
58 |
+
|
59 |
+
/**
|
60 |
+
* Parses a list of token name=>value pairs and creates token instances of them.
|
61 |
+
*
|
62 |
+
* @param array $tokens the list of token name=>value pairs.
|
63 |
+
* @param string $prefix optional prefix for the token name in the list.
|
64 |
+
* @param string $postfix optional postfix for the token name in the list.
|
65 |
+
* @return NostoApiToken[] a list of token instances.
|
66 |
+
*/
|
67 |
+
public static function parseTokens(array $tokens, $prefix = '', $postfix = '')
|
68 |
+
{
|
69 |
+
$parsedTokens = array();
|
70 |
+
foreach (self::$tokenNames as $name) {
|
71 |
+
$key = $prefix.$name.$postfix;
|
72 |
+
if (isset($tokens[$key])) {
|
73 |
+
$token = new self();
|
74 |
+
$token->name = $name;
|
75 |
+
$token->value = $tokens[$key];
|
76 |
+
$parsedTokens[$name] = $token;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
return $parsedTokens;
|
80 |
+
}
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Returns all available API token names.
|
84 |
+
*
|
85 |
+
* @return array the token names.
|
86 |
+
*/
|
87 |
+
public static function getApiTokenNames()
|
88 |
+
{
|
89 |
+
return self::$tokenNames;
|
90 |
+
}
|
91 |
+
}
|
lib/nosto/php-sdk/src/classes/export/NostoExportCollection.php
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Base class for all export collection classes used for exporting historical data from the shop.
|
38 |
+
* The base class provides the functionality to validate the items added to the collection.
|
39 |
+
* The collection behaves like an array. making it easy to add items to it and iterate over it.
|
40 |
+
*/
|
41 |
+
abstract class NostoExportCollection extends ArrayObject
|
42 |
+
{
|
43 |
+
/**
|
44 |
+
* @var string the type of items this collection can contain.
|
45 |
+
*/
|
46 |
+
protected $validItemType = '';
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Returns the collection as a JSON string.
|
50 |
+
* In the JSON camel case variables are converted into underscore format.
|
51 |
+
*
|
52 |
+
* @return string the JSON.
|
53 |
+
*/
|
54 |
+
abstract public function getJson();
|
55 |
+
|
56 |
+
/**
|
57 |
+
* @inheritdoc
|
58 |
+
*/
|
59 |
+
public function offsetSet($index, $newval)
|
60 |
+
{
|
61 |
+
$this->validate($newval);
|
62 |
+
parent::offsetSet($index, $newval);
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* @inheritdoc
|
67 |
+
*/
|
68 |
+
public function append($value)
|
69 |
+
{
|
70 |
+
$this->validate($value);
|
71 |
+
parent::append($value);
|
72 |
+
}
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Validates that the given value is of correct type.
|
76 |
+
*
|
77 |
+
* @see NostoExportCollection::$validItemType
|
78 |
+
* @param mixed $value the value.
|
79 |
+
* @throws NostoException if the value is of invalid type.
|
80 |
+
*/
|
81 |
+
protected function validate($value)
|
82 |
+
{
|
83 |
+
if (!is_a($value, $this->validItemType)) {
|
84 |
+
$valueType = gettype($value);
|
85 |
+
if ($valueType === 'object') {
|
86 |
+
$valueType = get_class($value);
|
87 |
+
}
|
88 |
+
throw new NostoException(sprintf(
|
89 |
+
'Collection supports items of type "%s" (type "%s" given)',
|
90 |
+
$this->validItemType,
|
91 |
+
$valueType
|
92 |
+
));
|
93 |
+
}
|
94 |
+
}
|
95 |
+
}
|
lib/nosto/php-sdk/src/classes/export/NostoExportOrderCollection.php
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Order collection for historical data exports.
|
38 |
+
* Supports only items implementing "NostoOrderInterface".
|
39 |
+
*/
|
40 |
+
class NostoExportOrderCollection extends NostoExportCollection
|
41 |
+
{
|
42 |
+
/**
|
43 |
+
* @inheritdoc
|
44 |
+
*/
|
45 |
+
protected $validItemType = 'NostoOrderInterface';
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @inheritdoc
|
49 |
+
*/
|
50 |
+
public function getJson()
|
51 |
+
{
|
52 |
+
$array = array();
|
53 |
+
/** @var NostoOrderInterface $item */
|
54 |
+
foreach ($this->getArrayCopy() as $item) {
|
55 |
+
$data = array(
|
56 |
+
'order_number' => $item->getOrderNumber(),
|
57 |
+
'created_at' => Nosto::helper('date')->format($item->getCreatedDate()),
|
58 |
+
'buyer' => array(
|
59 |
+
'first_name' => $item->getBuyerInfo()->getFirstName(),
|
60 |
+
'last_name' => $item->getBuyerInfo()->getLastName(),
|
61 |
+
'email' => $item->getBuyerInfo()->getEmail(),
|
62 |
+
),
|
63 |
+
'purchased_items' => array(),
|
64 |
+
);
|
65 |
+
foreach ($item->getPurchasedItems() as $orderItem) {
|
66 |
+
$data['purchased_items'][] = array(
|
67 |
+
'product_id' => $orderItem->getProductId(),
|
68 |
+
'quantity' => (int)$orderItem->getQuantity(),
|
69 |
+
'name' => $orderItem->getName(),
|
70 |
+
'unit_price' => Nosto::helper('price')->format($orderItem->getUnitPrice()),
|
71 |
+
'price_currency_code' => strtoupper($orderItem->getCurrencyCode()),
|
72 |
+
);
|
73 |
+
}
|
74 |
+
$array[] = $data;
|
75 |
+
}
|
76 |
+
return json_encode($array);
|
77 |
+
}
|
78 |
+
}
|
lib/nosto/php-sdk/src/classes/export/NostoExportProductCollection.php
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Product collection for historical data exports.
|
38 |
+
* Supports only items implementing "NostoProductInterface".
|
39 |
+
*/
|
40 |
+
class NostoExportProductCollection extends NostoExportCollection
|
41 |
+
{
|
42 |
+
/**
|
43 |
+
* @inheritdoc
|
44 |
+
*/
|
45 |
+
protected $validItemType = 'NostoProductInterface';
|
46 |
+
|
47 |
+
/**
|
48 |
+
* @inheritdoc
|
49 |
+
*/
|
50 |
+
public function getJson()
|
51 |
+
{
|
52 |
+
$array = array();
|
53 |
+
/** @var NostoProductInterface $item */
|
54 |
+
foreach ($this->getArrayCopy() as $item) {
|
55 |
+
$array[] = array(
|
56 |
+
'url' => $item->getUrl(),
|
57 |
+
'product_id' => $item->getProductId(),
|
58 |
+
'name' => $item->getName(),
|
59 |
+
'image_url' => $item->getImageUrl(),
|
60 |
+
'price' => Nosto::helper('price')->format($item->getPrice()),
|
61 |
+
'list_price' => Nosto::helper('price')->format($item->getListPrice()),
|
62 |
+
'price_currency_code' => strtoupper($item->getCurrencyCode()),
|
63 |
+
'availability' => $item->getAvailability(),
|
64 |
+
'tags' => $item->getTags(),
|
65 |
+
'categories' => $item->getCategories(),
|
66 |
+
'description' => $item->getShortDescription().'<br/>'.$item->getDescription(),
|
67 |
+
'brand' => $item->getBrand(),
|
68 |
+
'date_published' => Nosto::helper('date')->format($item->getDatePublished()),
|
69 |
+
);
|
70 |
+
}
|
71 |
+
return json_encode($array);
|
72 |
+
}
|
73 |
+
}
|
lib/nosto/php-sdk/src/classes/export/NostoExporter.php
ADDED
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Helper class for exporting historical product and order data from the shop.
|
38 |
+
* This information is used to bootstrap recommendations and decreases the time needed to get accurate recommendations
|
39 |
+
* showing in the shop.
|
40 |
+
*/
|
41 |
+
class NostoExporter
|
42 |
+
{
|
43 |
+
/**
|
44 |
+
* Encrypts and returns the data.
|
45 |
+
*
|
46 |
+
* @param NostoAccountInterface $account the account to export the data for.
|
47 |
+
* @param NostoExportCollection $collection the data collection to export.
|
48 |
+
* @return string the encrypted data.
|
49 |
+
*/
|
50 |
+
public static function export(NostoAccountInterface $account, NostoExportCollection $collection)
|
51 |
+
{
|
52 |
+
$data = '';
|
53 |
+
// Use the first 16 chars of the SSO token as secret for encryption.
|
54 |
+
$token = $account->getApiToken('sso');
|
55 |
+
if (!empty($token)) {
|
56 |
+
$secret = substr($token->value, 0, 16);
|
57 |
+
if (!empty($secret)) {
|
58 |
+
$iv = NostoCryptRandom::getRandomString(16);
|
59 |
+
$cipher = new NostoCipher();
|
60 |
+
$cipher->setSecret($secret);
|
61 |
+
$cipher->setIV($iv);
|
62 |
+
$cipherText = $cipher->encrypt($collection->getJson());
|
63 |
+
// Prepend the IV to the cipher string so that nosto can parse and use it.
|
64 |
+
// There is no security concern with sending the IV as plain text.
|
65 |
+
$data = $iv.$cipherText;
|
66 |
+
}
|
67 |
+
}
|
68 |
+
return $data;
|
69 |
+
}
|
70 |
+
}
|
lib/nosto/php-sdk/src/classes/helper/NostoHelper.php
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Base class that all Nosto helpers must extend.
|
38 |
+
* Helper classes are used in the following manner:
|
39 |
+
*
|
40 |
+
* Nosto::helper('name')->invokeMethod();
|
41 |
+
*/
|
42 |
+
abstract class NostoHelper
|
43 |
+
{
|
44 |
+
}
|
lib/nosto/php-sdk/src/classes/helper/NostoHelperDate.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Date helper class for date related tasks.
|
38 |
+
*/
|
39 |
+
class NostoHelperDate extends NostoHelper
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* Formats date into Nosto format, i.e. Y-m-d.
|
43 |
+
*
|
44 |
+
* @param string $date the date string to format (must be a datetime description valid to pass to `strtotime`).
|
45 |
+
* @return string the formatted date.
|
46 |
+
*/
|
47 |
+
public function format($date)
|
48 |
+
{
|
49 |
+
return date('Y-m-d', strtotime($date));
|
50 |
+
}
|
51 |
+
}
|
lib/nosto/php-sdk/src/classes/helper/NostoHelperIframe.php
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Iframe helper class for account administration iframe.
|
38 |
+
*/
|
39 |
+
class NostoHelperIframe extends NostoHelper
|
40 |
+
{
|
41 |
+
const IFRAME_URI_MANAGE = '/hub/{platform}/{merchant}';
|
42 |
+
const IFRAME_URI_INSTALL = '/hub/{platform}/install';
|
43 |
+
const IFRAME_URI_UNINSTALL = '/hub/{platform}/uninstall';
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Returns the url for the account administration iframe.
|
47 |
+
* If the passed account is null, then the url will point to the start page where a new account can be created.
|
48 |
+
*
|
49 |
+
* @param NostoAccountMetaDataIframeInterface $meta the iframe meta data.
|
50 |
+
* @param NostoAccount|null $account the account to return the url for.
|
51 |
+
* @param array $params additional parameters to add to the iframe url.
|
52 |
+
* @return string the iframe url.
|
53 |
+
* @throws NostoException if the url cannot be created.
|
54 |
+
*/
|
55 |
+
public function getUrl(
|
56 |
+
NostoAccountMetaDataIframeInterface $meta,
|
57 |
+
NostoAccount $account = null,
|
58 |
+
array $params = array()
|
59 |
+
) {
|
60 |
+
$queryParams = http_build_query(
|
61 |
+
array_merge(
|
62 |
+
array(
|
63 |
+
'lang' => strtolower($meta->getLanguageIsoCode()),
|
64 |
+
'ps_version' => $meta->getVersionPlatform(),
|
65 |
+
'nt_version' => $meta->getVersionModule(),
|
66 |
+
'product_pu' => $meta->getPreviewUrlProduct(),
|
67 |
+
'category_pu' => $meta->getPreviewUrlCategory(),
|
68 |
+
'search_pu' => $meta->getPreviewUrlSearch(),
|
69 |
+
'cart_pu' => $meta->getPreviewUrlCart(),
|
70 |
+
'front_pu' => $meta->getPreviewUrlFront(),
|
71 |
+
'shop_lang' => strtolower($meta->getLanguageIsoCodeShop()),
|
72 |
+
'shop_name' => $meta->getShopName(),
|
73 |
+
'unique_id' => $meta->getUniqueId(),
|
74 |
+
'fname' => $meta->getFirstName(),
|
75 |
+
'lname' => $meta->getLastName(),
|
76 |
+
'email' => $meta->getEmail(),
|
77 |
+
),
|
78 |
+
$params
|
79 |
+
)
|
80 |
+
);
|
81 |
+
|
82 |
+
if ($account !== null && $account->isConnectedToNosto()) {
|
83 |
+
try {
|
84 |
+
$url = $account->ssoLogin($meta);
|
85 |
+
$url .= '?r='.urlencode(
|
86 |
+
NostoHttpRequest::buildUri(
|
87 |
+
self::IFRAME_URI_MANAGE.'?'.$queryParams,
|
88 |
+
array(
|
89 |
+
'{platform}' => $meta->getPlatform(),
|
90 |
+
'{merchant}' => $account->name,
|
91 |
+
)
|
92 |
+
)
|
93 |
+
);
|
94 |
+
} catch (NostoException $e) {
|
95 |
+
// If the SSO fails, we show a "remove account" page to the user in order to
|
96 |
+
// allow to remove Nosto and start over.
|
97 |
+
// The only case when this should happen is when the api token for some
|
98 |
+
// reason is invalid, which is the case when switching between environments.
|
99 |
+
$url = NostoHttpRequest::buildUri(
|
100 |
+
$this->getBaseUrl().self::IFRAME_URI_UNINSTALL.'?'.$queryParams,
|
101 |
+
array(
|
102 |
+
'{platform}' => $meta->getPlatform(),
|
103 |
+
)
|
104 |
+
);
|
105 |
+
}
|
106 |
+
} else {
|
107 |
+
$url = NostoHttpRequest::buildUri(
|
108 |
+
$this->getBaseUrl().self::IFRAME_URI_INSTALL.'?'.$queryParams,
|
109 |
+
array(
|
110 |
+
'{platform}' => $meta->getPlatform(),
|
111 |
+
)
|
112 |
+
);
|
113 |
+
}
|
114 |
+
|
115 |
+
return $url;
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Returns the base url for the Nosto iframe.
|
120 |
+
*
|
121 |
+
* @return string the url.
|
122 |
+
*/
|
123 |
+
protected function getBaseUrl()
|
124 |
+
{
|
125 |
+
return Nosto::getEnvVariable('NOSTO_WEB_HOOK_BASE_URL', NostoHttpRequest::$baseUrl);
|
126 |
+
}
|
127 |
+
}
|
lib/nosto/php-sdk/src/classes/helper/NostoHelperPrice.php
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Price helper class for price related tasks.
|
38 |
+
*/
|
39 |
+
class NostoHelperPrice extends NostoHelper
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* Formats price into Nosto format, e.g. 1000.99.
|
43 |
+
*
|
44 |
+
* @param string|int|float $price the price string to format.
|
45 |
+
* @return string the formatted price.
|
46 |
+
*/
|
47 |
+
public function format($price)
|
48 |
+
{
|
49 |
+
return number_format($price, 2, '.', '');
|
50 |
+
}
|
51 |
+
}
|
lib/nosto/php-sdk/src/classes/http/NostoHttpRequest.php
ADDED
@@ -0,0 +1,368 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Helper class for doing http requests and returning unified response including header info.
|
38 |
+
*/
|
39 |
+
class NostoHttpRequest
|
40 |
+
{
|
41 |
+
const AUTH_BASIC = 'basic';
|
42 |
+
const AUTH_BEARER = 'bearer';
|
43 |
+
|
44 |
+
const PATH_ACCOUNT_DELETED = '/hub/uninstall';
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @var string base url for the nosto web hook requests.
|
48 |
+
*/
|
49 |
+
public static $baseUrl = 'https://my.nosto.com';
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @var string the request url.
|
53 |
+
*/
|
54 |
+
protected $url;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* @var array list of headers to include in the requests.
|
58 |
+
*/
|
59 |
+
protected $headers = array();
|
60 |
+
|
61 |
+
/**
|
62 |
+
* @var array list of optional query params that are added to the request url.
|
63 |
+
*/
|
64 |
+
protected $queryParams = array();
|
65 |
+
|
66 |
+
/**
|
67 |
+
* @var array list of optional replace params that can be injected into the url if it contains placeholders.
|
68 |
+
*/
|
69 |
+
protected $replaceParams = array();
|
70 |
+
|
71 |
+
/**
|
72 |
+
* @var NostoHttpRequestAdapter the adapter to use for making the request.
|
73 |
+
*/
|
74 |
+
private $adapter;
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Constructor.
|
78 |
+
* Creates the http request adapter which is chosen automatically by default based on environment.
|
79 |
+
* Curl is preferred if available.
|
80 |
+
*
|
81 |
+
* @param NostoHttpRequestAdapter|null $adapter the http request adapter to use
|
82 |
+
* @throws NostoException
|
83 |
+
*/
|
84 |
+
public function __construct(NostoHttpRequestAdapter $adapter = null)
|
85 |
+
{
|
86 |
+
if ($adapter !== null) {
|
87 |
+
$this->adapter = $adapter;
|
88 |
+
} elseif (function_exists('curl_exec')) {
|
89 |
+
$this->adapter = new NostoHttpRequestAdapterCurl();
|
90 |
+
} else {
|
91 |
+
$this->adapter = new NostoHttpRequestAdapterSocket();
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
/**
|
96 |
+
* Setter for the request url.
|
97 |
+
*
|
98 |
+
* @param string $url the url.
|
99 |
+
*/
|
100 |
+
public function setUrl($url)
|
101 |
+
{
|
102 |
+
$this->url = $url;
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Setter for the content type to add to the request header.
|
107 |
+
*
|
108 |
+
* @param string $contentType the content type.
|
109 |
+
*/
|
110 |
+
public function setContentType($contentType)
|
111 |
+
{
|
112 |
+
$this->addHeader('Content-type', $contentType);
|
113 |
+
}
|
114 |
+
|
115 |
+
/**
|
116 |
+
* Adds a new header to the request.
|
117 |
+
*
|
118 |
+
* @param string $key the header key, e.g. 'Content-type'.
|
119 |
+
* @param string $value the header value, e.g. 'application/json'.
|
120 |
+
*/
|
121 |
+
public function addHeader($key, $value)
|
122 |
+
{
|
123 |
+
$this->headers[] = $key.': '.$value;
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Returns the registered headers.
|
128 |
+
*
|
129 |
+
* @return array
|
130 |
+
*/
|
131 |
+
public function getHeaders()
|
132 |
+
{
|
133 |
+
return $this->headers;
|
134 |
+
}
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Setter for the request url query params.
|
138 |
+
*
|
139 |
+
* @param array $queryParams the query params.
|
140 |
+
*/
|
141 |
+
public function setQueryParams($queryParams)
|
142 |
+
{
|
143 |
+
$this->queryParams = $queryParams;
|
144 |
+
}
|
145 |
+
|
146 |
+
/**
|
147 |
+
* Returns the registered query params.
|
148 |
+
*
|
149 |
+
* @return array
|
150 |
+
*/
|
151 |
+
public function getQueryParams()
|
152 |
+
{
|
153 |
+
return $this->queryParams;
|
154 |
+
}
|
155 |
+
|
156 |
+
/**
|
157 |
+
* Setter for the request url replace params.
|
158 |
+
*
|
159 |
+
* @param array $replaceParams the replace params.
|
160 |
+
*/
|
161 |
+
public function setReplaceParams($replaceParams)
|
162 |
+
{
|
163 |
+
$this->replaceParams = $replaceParams;
|
164 |
+
}
|
165 |
+
|
166 |
+
/**
|
167 |
+
* Setter for the request authentication header.
|
168 |
+
*
|
169 |
+
* @param string $type the auth type (use AUTH_ constants).
|
170 |
+
* @param mixed $value the auth header value, format depending on the auth type.
|
171 |
+
* @throws Exception if an incorrect auth type is given.
|
172 |
+
*/
|
173 |
+
public function setAuth($type, $value)
|
174 |
+
{
|
175 |
+
switch ($type) {
|
176 |
+
case self::AUTH_BASIC:
|
177 |
+
// The use of base64 encoding for authorization headers follow the RFC 2617 standard for http
|
178 |
+
// authentication (https://www.ietf.org/rfc/rfc2617.txt).
|
179 |
+
$this->addHeader('Authorization', 'Basic '.base64_encode(implode(':', $value)));
|
180 |
+
break;
|
181 |
+
|
182 |
+
case self::AUTH_BEARER:
|
183 |
+
$this->addHeader('Authorization', 'Bearer '.$value);
|
184 |
+
break;
|
185 |
+
|
186 |
+
default:
|
187 |
+
throw new NostoException('Unsupported auth type.');
|
188 |
+
}
|
189 |
+
}
|
190 |
+
|
191 |
+
/**
|
192 |
+
* Convenience method for setting the basic auth type.
|
193 |
+
*
|
194 |
+
* @param string $username the user name.
|
195 |
+
* @param string $password the password.
|
196 |
+
*/
|
197 |
+
public function setAuthBasic($username, $password)
|
198 |
+
{
|
199 |
+
$this->setAuth(self::AUTH_BASIC, array($username, $password));
|
200 |
+
}
|
201 |
+
|
202 |
+
/**
|
203 |
+
* Convenience method for setting the bearer auth type.
|
204 |
+
*
|
205 |
+
* @param string $token the access token.
|
206 |
+
*/
|
207 |
+
public function setAuthBearer($token)
|
208 |
+
{
|
209 |
+
$this->setAuth(self::AUTH_BEARER, $token);
|
210 |
+
}
|
211 |
+
|
212 |
+
/**
|
213 |
+
* Builds an uri by replacing the param placeholders in $uri with the ones given in $$replaceParams.
|
214 |
+
*
|
215 |
+
* @param string $uri
|
216 |
+
* @param array $replaceParams
|
217 |
+
* @return string
|
218 |
+
*/
|
219 |
+
public static function buildUri($uri, array $replaceParams)
|
220 |
+
{
|
221 |
+
return strtr($uri, $replaceParams);
|
222 |
+
}
|
223 |
+
|
224 |
+
/**
|
225 |
+
* Builds a url based on given parts.
|
226 |
+
*
|
227 |
+
* @see http://php.net/manual/en/function.parse-url.php
|
228 |
+
* @param array $parts part(s) of an URL in form of a string or associative array like parseUrl() returns.
|
229 |
+
* @return string
|
230 |
+
*/
|
231 |
+
public static function buildUrl(array $parts)
|
232 |
+
{
|
233 |
+
$scheme = isset($parts['scheme']) ? $parts['scheme'].'://' : '';
|
234 |
+
$host = isset($parts['host']) ? $parts['host'] : '';
|
235 |
+
$port = isset($parts['port']) ? ':'.$parts['port'] : '';
|
236 |
+
$user = isset($parts['user']) ? $parts['user'] : '';
|
237 |
+
$pass = isset($parts['pass']) ? ':'.$parts['pass'] : '';
|
238 |
+
$pass = ($user || $pass) ? "$pass@" : '';
|
239 |
+
$path = isset($parts['path']) ? $parts['path'] : '';
|
240 |
+
$query = isset($parts['query']) ? '?'.$parts['query'] : '';
|
241 |
+
$fragment = isset($parts['fragment']) ? '#'.$parts['fragment'] : '';
|
242 |
+
return $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
|
243 |
+
}
|
244 |
+
|
245 |
+
/**
|
246 |
+
* Parses the given url and returns the parts as an array.
|
247 |
+
*
|
248 |
+
* @see http://php.net/manual/en/function.parse-url.php
|
249 |
+
* @param string $url the url to parse.
|
250 |
+
* @return array the parsed url as an array.
|
251 |
+
*/
|
252 |
+
public static function parseUrl($url)
|
253 |
+
{
|
254 |
+
return parse_url($url);
|
255 |
+
}
|
256 |
+
|
257 |
+
/**
|
258 |
+
* Parses the given query string and returns the parts as an assoc array.
|
259 |
+
*
|
260 |
+
* @see http://php.net/manual/en/function.parse-str.php
|
261 |
+
* @param string $queryString the query string to parse.
|
262 |
+
* @return array the parsed string as assoc array.
|
263 |
+
*/
|
264 |
+
public static function parseQueryString($queryString)
|
265 |
+
{
|
266 |
+
if (empty($queryString)) {
|
267 |
+
return array();
|
268 |
+
}
|
269 |
+
parse_str($queryString, $parsedQueryString);
|
270 |
+
return $parsedQueryString;
|
271 |
+
}
|
272 |
+
|
273 |
+
/**
|
274 |
+
* Replaces a parameter in a query string with given value.
|
275 |
+
*
|
276 |
+
* @param string $param the query param name to replace.
|
277 |
+
* @param mixed $value the query param value to replace.
|
278 |
+
* @param string $queryString the query string.
|
279 |
+
* @return string the updated query string.
|
280 |
+
*/
|
281 |
+
public static function replaceQueryParam($param, $value, $queryString)
|
282 |
+
{
|
283 |
+
$parsedQuery = self::parseQueryString($queryString);
|
284 |
+
$parsedQuery[$param] = $value;
|
285 |
+
return http_build_query($parsedQuery);
|
286 |
+
}
|
287 |
+
|
288 |
+
/**
|
289 |
+
* Replaces or adds a query parameter to a url.
|
290 |
+
*
|
291 |
+
* @param string $param the query param name to replace.
|
292 |
+
* @param mixed $value the query param value to replace.
|
293 |
+
* @param string $url the url.
|
294 |
+
* @return string the updated url.
|
295 |
+
*/
|
296 |
+
public static function replaceQueryParamInUrl($param, $value, $url)
|
297 |
+
{
|
298 |
+
$parsedUrl = self::parseUrl($url);
|
299 |
+
$queryString = isset($parsedUrl['query']) ? $parsedUrl['query'] : '';
|
300 |
+
$queryString = self::replaceQueryParam($param, $value, $queryString);
|
301 |
+
$parsedUrl['query'] = $queryString;
|
302 |
+
return self::buildUrl($parsedUrl);
|
303 |
+
}
|
304 |
+
|
305 |
+
/**
|
306 |
+
* Replaces or adds a query parameters to a url.
|
307 |
+
*
|
308 |
+
* @param array $queryParams the query params to replace.
|
309 |
+
* @param string $url the url.
|
310 |
+
* @return string the updated url.
|
311 |
+
*/
|
312 |
+
public static function replaceQueryParamsInUrl(array $queryParams, $url)
|
313 |
+
{
|
314 |
+
if (empty($queryParams)) {
|
315 |
+
return $url;
|
316 |
+
}
|
317 |
+
$parsedUrl = self::parseUrl($url);
|
318 |
+
$queryString = isset($parsedUrl['query']) ? $parsedUrl['query'] : '';
|
319 |
+
foreach ($queryParams as $param => $value) {
|
320 |
+
$queryString = self::replaceQueryParam($param, $value, $queryString);
|
321 |
+
}
|
322 |
+
$parsedUrl['query'] = $queryString;
|
323 |
+
return self::buildUrl($parsedUrl);
|
324 |
+
}
|
325 |
+
|
326 |
+
/**
|
327 |
+
* Sends a POST request.
|
328 |
+
*
|
329 |
+
* @param string $content
|
330 |
+
* @return NostoHttpResponse
|
331 |
+
*/
|
332 |
+
public function post($content)
|
333 |
+
{
|
334 |
+
$url = $this->url;
|
335 |
+
if (!empty($this->replaceParams)) {
|
336 |
+
$url = self::buildUri($url, $this->replaceParams);
|
337 |
+
}
|
338 |
+
return $this->adapter->post(
|
339 |
+
$url,
|
340 |
+
array(
|
341 |
+
'headers' => $this->headers,
|
342 |
+
'content' => $content,
|
343 |
+
)
|
344 |
+
);
|
345 |
+
}
|
346 |
+
|
347 |
+
/**
|
348 |
+
* Sends a GET request.
|
349 |
+
*
|
350 |
+
* @return NostoHttpResponse
|
351 |
+
*/
|
352 |
+
public function get()
|
353 |
+
{
|
354 |
+
$url = $this->url;
|
355 |
+
if (!empty($this->replaceParams)) {
|
356 |
+
$url = self::buildUri($url, $this->replaceParams);
|
357 |
+
}
|
358 |
+
if (!empty($this->queryParams)) {
|
359 |
+
$url .= '?'.http_build_query($this->queryParams);
|
360 |
+
}
|
361 |
+
return $this->adapter->get(
|
362 |
+
$url,
|
363 |
+
array(
|
364 |
+
'headers' => $this->headers,
|
365 |
+
)
|
366 |
+
);
|
367 |
+
}
|
368 |
+
}
|
lib/nosto/php-sdk/src/classes/http/NostoHttpRequestAdapter.php
ADDED
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Base class for all http request adapters.
|
38 |
+
*/
|
39 |
+
abstract class NostoHttpRequestAdapter
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* @var array the request headers.
|
43 |
+
*/
|
44 |
+
protected $headers = array();
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @var mixed the request content.
|
48 |
+
*/
|
49 |
+
protected $content = null;
|
50 |
+
|
51 |
+
/**
|
52 |
+
* Initializes the request options.
|
53 |
+
*
|
54 |
+
* @param array $options the options.
|
55 |
+
*/
|
56 |
+
protected function init(array $options = array())
|
57 |
+
{
|
58 |
+
foreach ($options as $key => $value) {
|
59 |
+
if (property_exists($this, $key)) {
|
60 |
+
$this->{$key} = $value;
|
61 |
+
}
|
62 |
+
}
|
63 |
+
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Does a GET request and returns the http response object.
|
67 |
+
*
|
68 |
+
* @param string $url the URL to request.
|
69 |
+
* @param array $options the request options.
|
70 |
+
* @return NostoHttpResponse the response object.
|
71 |
+
*/
|
72 |
+
abstract public function get($url, array $options = array());
|
73 |
+
|
74 |
+
/**
|
75 |
+
* Does a POST request and returns the http response object.
|
76 |
+
*
|
77 |
+
* @param string $url the URL to request.
|
78 |
+
* @param array $options the request options.
|
79 |
+
* @return NostoHttpResponse the response object.
|
80 |
+
*/
|
81 |
+
abstract public function post($url, array $options = array());
|
82 |
+
}
|
lib/nosto/php-sdk/src/classes/http/NostoHttpRequestAdapterCurl.php
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Adapter class for making http requests using curl.
|
38 |
+
* This adapter requires curl to be installed.
|
39 |
+
*/
|
40 |
+
class NostoHttpRequestAdapterCurl extends NostoHttpRequestAdapter
|
41 |
+
{
|
42 |
+
/**
|
43 |
+
* @inheritdoc
|
44 |
+
*/
|
45 |
+
public function get($url, array $options = array())
|
46 |
+
{
|
47 |
+
$this->init($options);
|
48 |
+
return $this->send(
|
49 |
+
array(
|
50 |
+
CURLOPT_URL => $url,
|
51 |
+
CURLOPT_HEADER => 1,
|
52 |
+
CURLOPT_FRESH_CONNECT => 1,
|
53 |
+
CURLOPT_RETURNTRANSFER => 1,
|
54 |
+
CURLOPT_FORBID_REUSE => 1,
|
55 |
+
CURLOPT_TIMEOUT => 60,
|
56 |
+
)
|
57 |
+
);
|
58 |
+
}
|
59 |
+
|
60 |
+
/**
|
61 |
+
* @inheritdoc
|
62 |
+
*/
|
63 |
+
public function post($url, array $options = array())
|
64 |
+
{
|
65 |
+
$this->init($options);
|
66 |
+
return $this->send(
|
67 |
+
array(
|
68 |
+
CURLOPT_URL => $url,
|
69 |
+
CURLOPT_POSTFIELDS => $this->content,
|
70 |
+
CURLOPT_POST => 1,
|
71 |
+
CURLOPT_HEADER => 1,
|
72 |
+
CURLOPT_FRESH_CONNECT => 1,
|
73 |
+
CURLOPT_RETURNTRANSFER => 1,
|
74 |
+
CURLOPT_FORBID_REUSE => 1,
|
75 |
+
CURLOPT_TIMEOUT => 60,
|
76 |
+
)
|
77 |
+
);
|
78 |
+
}
|
79 |
+
|
80 |
+
/**
|
81 |
+
* Sends the request and creates a NostoHttpResponse instance containing the response headers and body.
|
82 |
+
*
|
83 |
+
* @param array $curlOptions options for curl_setopt_array().
|
84 |
+
* @return NostoHttpResponse
|
85 |
+
*/
|
86 |
+
protected function send(array $curlOptions)
|
87 |
+
{
|
88 |
+
if (!empty($this->headers)) {
|
89 |
+
$curlOptions[CURLOPT_HTTPHEADER] = $this->headers;
|
90 |
+
}
|
91 |
+
$ch = curl_init();
|
92 |
+
curl_setopt_array($ch, $curlOptions);
|
93 |
+
$result = curl_exec($ch);
|
94 |
+
$response = new NostoHttpResponse();
|
95 |
+
if ($result !== false) {
|
96 |
+
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
|
97 |
+
$header = substr($result, 0, $headerSize);
|
98 |
+
$header = explode("\r\n", $header);
|
99 |
+
$body = substr($result, $headerSize);
|
100 |
+
if (!empty($header)) {
|
101 |
+
$response->setHeaders($header);
|
102 |
+
}
|
103 |
+
$response->setResult($body);
|
104 |
+
} else {
|
105 |
+
$response->setMessage(curl_error($ch));
|
106 |
+
}
|
107 |
+
curl_close($ch);
|
108 |
+
return $response;
|
109 |
+
}
|
110 |
+
}
|
lib/nosto/php-sdk/src/classes/http/NostoHttpRequestAdapterSocket.php
ADDED
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Adapter class for making http requests using php sockets.
|
38 |
+
* This adapter uses file_get_contents() and stream_context_create() for creating http requests.
|
39 |
+
*
|
40 |
+
* Note that if php is compiled with "--with-curlwrappers" then headers are not sent properly in older php versions.
|
41 |
+
* @link https://bugs.php.net/bug.php?id=55438
|
42 |
+
*/
|
43 |
+
class NostoHttpRequestAdapterSocket extends NostoHttpRequestAdapter
|
44 |
+
{
|
45 |
+
/**
|
46 |
+
* @inheritdoc
|
47 |
+
*/
|
48 |
+
public function get($url, array $options = array())
|
49 |
+
{
|
50 |
+
$this->init($options);
|
51 |
+
return $this->send(
|
52 |
+
$url,
|
53 |
+
array(
|
54 |
+
'http' => array(
|
55 |
+
'method' => 'GET',
|
56 |
+
'header' => implode("\r\n", $this->headers),
|
57 |
+
// Fetch the content even on failure status codes.
|
58 |
+
'ignore_errors' => true,
|
59 |
+
),
|
60 |
+
)
|
61 |
+
);
|
62 |
+
}
|
63 |
+
|
64 |
+
/**
|
65 |
+
* @inheritdoc
|
66 |
+
*/
|
67 |
+
public function post($url, array $options = array())
|
68 |
+
{
|
69 |
+
$this->init($options);
|
70 |
+
return $this->send(
|
71 |
+
$url,
|
72 |
+
array(
|
73 |
+
'http' => array(
|
74 |
+
'method' => 'POST',
|
75 |
+
'header' => implode("\r\n", $this->headers),
|
76 |
+
'content' => $this->content,
|
77 |
+
// Fetch the content even on failure status codes.
|
78 |
+
'ignore_errors' => true,
|
79 |
+
),
|
80 |
+
)
|
81 |
+
);
|
82 |
+
}
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Sends the request and creates a NostoHttpResponse instance containing the response headers and body.
|
86 |
+
*
|
87 |
+
* @param string $url the url for the request.
|
88 |
+
* @param array $streamOptions options for stream_context_create().
|
89 |
+
* @return NostoHttpResponse
|
90 |
+
*/
|
91 |
+
protected function send($url, array $streamOptions)
|
92 |
+
{
|
93 |
+
$context = stream_context_create($streamOptions);
|
94 |
+
// We use file_get_contents() directly here as we need the http response headers which are automatically
|
95 |
+
// populated into $headers, which is only available in the local scope where file_get_contents()
|
96 |
+
// is executed (http://php.net/manual/en/reserved.variables.httpresponseheader.php).
|
97 |
+
$http_response_header = array();
|
98 |
+
$result = @file_get_contents($url, false, $context);
|
99 |
+
$response = new NostoHttpResponse();
|
100 |
+
if (!empty($http_response_header)) {
|
101 |
+
$response->setHeaders($http_response_header);
|
102 |
+
}
|
103 |
+
$response->setResult($result);
|
104 |
+
return $response;
|
105 |
+
}
|
106 |
+
}
|
lib/nosto/php-sdk/src/classes/http/NostoHttpResponse.php
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Represents a http request response returned by NostoHttpRequest.
|
38 |
+
*/
|
39 |
+
class NostoHttpResponse
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* @var array the response headers if there are any.
|
43 |
+
*/
|
44 |
+
protected $headers;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @var mixed the request result raw body.
|
48 |
+
*/
|
49 |
+
protected $result;
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @var string possible request error message.
|
53 |
+
*/
|
54 |
+
protected $message;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Setter for the request response data.
|
58 |
+
*
|
59 |
+
* @param mixed $result the response data of the request.
|
60 |
+
*/
|
61 |
+
public function setResult($result)
|
62 |
+
{
|
63 |
+
$this->result = $result;
|
64 |
+
}
|
65 |
+
|
66 |
+
/**
|
67 |
+
* Getter for the request response data.
|
68 |
+
*
|
69 |
+
* @return mixed the request response data.
|
70 |
+
*/
|
71 |
+
public function getResult()
|
72 |
+
{
|
73 |
+
return $this->result;
|
74 |
+
}
|
75 |
+
|
76 |
+
/**
|
77 |
+
* Setter for the error message of the request.
|
78 |
+
*
|
79 |
+
* @param string $message the message.
|
80 |
+
*/
|
81 |
+
public function setMessage($message)
|
82 |
+
{
|
83 |
+
$this->message = $message;
|
84 |
+
}
|
85 |
+
|
86 |
+
/**
|
87 |
+
* Getter for the error message of the request.
|
88 |
+
*
|
89 |
+
* @return string the message.
|
90 |
+
*/
|
91 |
+
public function getMessage()
|
92 |
+
{
|
93 |
+
return $this->message;
|
94 |
+
}
|
95 |
+
|
96 |
+
/**
|
97 |
+
* Getter for the request response as JSON.
|
98 |
+
*
|
99 |
+
* @param bool $assoc if the returned JSON should be formatted as an associative array or an stdClass instance.
|
100 |
+
* @return array|stdClass
|
101 |
+
*/
|
102 |
+
public function getJsonResult($assoc = false)
|
103 |
+
{
|
104 |
+
return json_decode($this->result, $assoc);
|
105 |
+
}
|
106 |
+
|
107 |
+
/**
|
108 |
+
* Setter for the request response headers.
|
109 |
+
*
|
110 |
+
* @param array $headers the headers,
|
111 |
+
*/
|
112 |
+
public function setHeaders($headers)
|
113 |
+
{
|
114 |
+
$this->headers = $headers;
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Returns the http request response code.
|
119 |
+
*
|
120 |
+
* @return int the http code or 0 if not set.
|
121 |
+
*/
|
122 |
+
public function getCode()
|
123 |
+
{
|
124 |
+
$matches = array();
|
125 |
+
if (isset($this->headers) && isset($this->headers[0])) {
|
126 |
+
preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $this->headers[0], $matches);
|
127 |
+
}
|
128 |
+
return isset($matches[1]) ? (int)$matches[1] : 0;
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Returns the raw http request response status string.
|
133 |
+
*
|
134 |
+
* @return string the status string or empty if not set.
|
135 |
+
*/
|
136 |
+
public function getRawStatus()
|
137 |
+
{
|
138 |
+
return (isset($this->headers) && isset($this->headers[0])) ? $this->headers[0] : '';
|
139 |
+
}
|
140 |
+
}
|
lib/nosto/php-sdk/src/classes/oauth/NostoOAuthClient.php
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Helper class for doing OAuth2 authorization with Nosto.
|
38 |
+
* The client implements the 'Authorization Code' grant type.
|
39 |
+
*/
|
40 |
+
class NostoOAuthClient
|
41 |
+
{
|
42 |
+
const PATH_AUTH = '?client_id={cid}&redirect_uri={uri}&response_type=code&scope={sco}&lang={iso}';
|
43 |
+
const PATH_TOKEN = '/token?code={cod}&client_id={cid}&client_secret={sec}&redirect_uri={uri}&grant_type=authorization_code';
|
44 |
+
|
45 |
+
/**
|
46 |
+
* @var string the nosto oauth endpoint base url.
|
47 |
+
*/
|
48 |
+
public static $baseUrl = 'https://my.nosto.com/oauth';
|
49 |
+
|
50 |
+
/**
|
51 |
+
* @var string the client id the identify this application to the oauth2 server.
|
52 |
+
*/
|
53 |
+
protected $clientId = 'nosto';
|
54 |
+
|
55 |
+
/**
|
56 |
+
* @var string the client secret the identify this application to the oauth2 server.
|
57 |
+
*/
|
58 |
+
protected $clientSecret = 'nosto';
|
59 |
+
|
60 |
+
/**
|
61 |
+
* @var string the redirect url that will be used by the oauth2 server when authenticating the client.
|
62 |
+
*/
|
63 |
+
protected $redirectUrl;
|
64 |
+
|
65 |
+
/**
|
66 |
+
* @var string the language ISO code used for localization on the oauth2 server.
|
67 |
+
*/
|
68 |
+
protected $languageIsoCode;
|
69 |
+
|
70 |
+
/**
|
71 |
+
* @var array list of scopes to request access for during "PATH_AUTH" request.
|
72 |
+
*/
|
73 |
+
protected $scopes = array();
|
74 |
+
|
75 |
+
/**
|
76 |
+
* @param NostoOAuthClientMetaDataInterface $metaData
|
77 |
+
*/
|
78 |
+
public function __construct(NostoOAuthClientMetaDataInterface $metaData)
|
79 |
+
{
|
80 |
+
$this->scopes = $metaData->getScopes();
|
81 |
+
$this->clientId = $metaData->getClientId();
|
82 |
+
$this->clientSecret = $metaData->getClientSecret();
|
83 |
+
$this->redirectUrl = $metaData->getRedirectUrl();
|
84 |
+
$this->languageIsoCode = $metaData->getLanguageIsoCode();
|
85 |
+
}
|
86 |
+
|
87 |
+
/**
|
88 |
+
* Returns the authorize url to the oauth2 server.
|
89 |
+
*
|
90 |
+
* @return string the url.
|
91 |
+
*/
|
92 |
+
public function getAuthorizationUrl()
|
93 |
+
{
|
94 |
+
return NostoHttpRequest::buildUri(
|
95 |
+
self::$baseUrl.self::PATH_AUTH,
|
96 |
+
array(
|
97 |
+
'{cid}' => $this->clientId,
|
98 |
+
'{uri}' => urlencode($this->redirectUrl),
|
99 |
+
'{sco}' => implode(' ', $this->scopes),
|
100 |
+
'{iso}' => strtolower($this->languageIsoCode),
|
101 |
+
)
|
102 |
+
);
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Authenticates the application with the given code to receive an access token.
|
107 |
+
*
|
108 |
+
* @param string $code code sent by the authorization server to exchange for an access token.
|
109 |
+
* @return NostoOAuthToken
|
110 |
+
* @throws NostoException
|
111 |
+
*/
|
112 |
+
public function authenticate($code)
|
113 |
+
{
|
114 |
+
if (empty($code)) {
|
115 |
+
throw new NostoException('Invalid authentication token');
|
116 |
+
}
|
117 |
+
|
118 |
+
$request = new NostoHttpRequest();
|
119 |
+
$request->setUrl(self::$baseUrl.self::PATH_TOKEN);
|
120 |
+
$request->setReplaceParams(
|
121 |
+
array(
|
122 |
+
'{cid}' => $this->clientId,
|
123 |
+
'{sec}' => $this->clientSecret,
|
124 |
+
'{uri}' => $this->redirectUrl,
|
125 |
+
'{cod}' => $code
|
126 |
+
)
|
127 |
+
);
|
128 |
+
$response = $request->get();
|
129 |
+
$result = $response->getJsonResult(true);
|
130 |
+
|
131 |
+
if ($response->getCode() !== 200) {
|
132 |
+
throw new NostoException('Failed to authenticate with code', $response->getCode());
|
133 |
+
}
|
134 |
+
if (empty($result['access_token'])) {
|
135 |
+
throw new NostoException('No "access_token" returned after authenticating with code');
|
136 |
+
}
|
137 |
+
if (empty($result['merchant_name'])) {
|
138 |
+
throw new NostoException('No "merchant_name" returned after authenticating with code');
|
139 |
+
}
|
140 |
+
|
141 |
+
return NostoOAuthToken::create($result);
|
142 |
+
}
|
143 |
+
}
|
lib/nosto/php-sdk/src/classes/oauth/NostoOAuthToken.php
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Helper class that represents a oauth2 access token.
|
38 |
+
*/
|
39 |
+
class NostoOAuthToken
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* @var string the access token string.
|
43 |
+
*/
|
44 |
+
public $accessToken;
|
45 |
+
|
46 |
+
/**
|
47 |
+
* @var string the merchant name string.
|
48 |
+
*/
|
49 |
+
public $merchantName;
|
50 |
+
|
51 |
+
/**
|
52 |
+
* @var string the type of token, e.g. "bearer".
|
53 |
+
*/
|
54 |
+
public $tokenType;
|
55 |
+
|
56 |
+
/**
|
57 |
+
* @var int the amount of time this token is valid for.
|
58 |
+
*/
|
59 |
+
public $expiresIn;
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Creates a new token instance and populates it with the given data.
|
63 |
+
*
|
64 |
+
* @param array $data the data to put in the token.
|
65 |
+
* @return NostoOAuthToken
|
66 |
+
*/
|
67 |
+
public static function create(array $data)
|
68 |
+
{
|
69 |
+
$token = new self();
|
70 |
+
foreach ($data as $key => $value) {
|
71 |
+
$key = self::underscore2CamelCase($key);
|
72 |
+
if (property_exists($token, $key)) {
|
73 |
+
$token->{$key} = $value;
|
74 |
+
}
|
75 |
+
}
|
76 |
+
return $token;
|
77 |
+
}
|
78 |
+
|
79 |
+
/**
|
80 |
+
* Converts string from underscore format to camel case format, e.g. variable_name => variableName.
|
81 |
+
*
|
82 |
+
* @param string $str the underscore formatted string to convert.
|
83 |
+
* @return string the converted string.
|
84 |
+
*/
|
85 |
+
protected static function underscore2CamelCase($str)
|
86 |
+
{
|
87 |
+
// Non-alpha and non-numeric characters become spaces.
|
88 |
+
$str = preg_replace('/[^a-z0-9]+/i', ' ', $str);
|
89 |
+
// Uppercase the first character of each word.
|
90 |
+
$str = ucwords(trim($str));
|
91 |
+
// Remove all spaces.
|
92 |
+
$str = str_replace(" ", "", $str);
|
93 |
+
// Lowercase the first character of the result.
|
94 |
+
$str[0] = strtolower($str[0]);
|
95 |
+
|
96 |
+
return $str;
|
97 |
+
}
|
98 |
+
}
|
lib/nosto/php-sdk/src/config.inc.php
ADDED
@@ -0,0 +1,100 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
// Interfaces
|
37 |
+
require_once(dirname(__FILE__).'/interfaces/account/NostoAccountInterface.php');
|
38 |
+
require_once(dirname(__FILE__).'/interfaces/account/NostoAccountMetaDataBillingDetailsInterface.php');
|
39 |
+
require_once(dirname(__FILE__).'/interfaces/account/NostoAccountMetaDataIframeInterface.php');
|
40 |
+
require_once(dirname(__FILE__).'/interfaces/account/NostoAccountMetaDataInterface.php');
|
41 |
+
require_once(dirname(__FILE__).'/interfaces/account/NostoAccountMetaDataOwnerInterface.php');
|
42 |
+
|
43 |
+
require_once(dirname(__FILE__).'/interfaces/order/NostoOrderBuyerInterface.php');
|
44 |
+
require_once(dirname(__FILE__).'/interfaces/order/NostoOrderInterface.php');
|
45 |
+
require_once(dirname(__FILE__).'/interfaces/order/NostoOrderPurchasedItemInterface.php');
|
46 |
+
|
47 |
+
require_once(dirname(__FILE__).'/interfaces/NostoOAuthClientMetaDataInterface.php');
|
48 |
+
require_once(dirname(__FILE__).'/interfaces/NostoProductInterface.php');
|
49 |
+
|
50 |
+
// Classes
|
51 |
+
require_once(dirname(__FILE__).'/classes/http/NostoHttpRequest.php'); // Must be loaded before `NostoApiRequest`
|
52 |
+
|
53 |
+
require_once(dirname(__FILE__).'/classes/api/NostoApiRequest.php');
|
54 |
+
require_once(dirname(__FILE__).'/classes/api/NostoApiToken.php');
|
55 |
+
|
56 |
+
require_once(dirname(__FILE__).'/classes/export/NostoExporter.php');
|
57 |
+
require_once(dirname(__FILE__).'/classes/export/NostoExportCollection.php');
|
58 |
+
require_once(dirname(__FILE__).'/classes/export/NostoExportProductCollection.php');
|
59 |
+
require_once(dirname(__FILE__).'/classes/export/NostoExportOrderCollection.php');
|
60 |
+
|
61 |
+
require_once(dirname(__FILE__).'/classes/helper/NostoHelper.php');
|
62 |
+
require_once(dirname(__FILE__).'/classes/helper/NostoHelperDate.php');
|
63 |
+
require_once(dirname(__FILE__).'/classes/helper/NostoHelperIframe.php');
|
64 |
+
require_once(dirname(__FILE__).'/classes/helper/NostoHelperPrice.php');
|
65 |
+
|
66 |
+
require_once(dirname(__FILE__).'/classes/http/NostoHttpRequestAdapter.php');
|
67 |
+
require_once(dirname(__FILE__).'/classes/http/NostoHttpRequestAdapterCurl.php');
|
68 |
+
require_once(dirname(__FILE__).'/classes/http/NostoHttpRequestAdapterSocket.php');
|
69 |
+
require_once(dirname(__FILE__).'/classes/http/NostoHttpResponse.php');
|
70 |
+
|
71 |
+
require_once(dirname(__FILE__).'/classes/oauth/NostoOAuthClient.php');
|
72 |
+
require_once(dirname(__FILE__).'/classes/oauth/NostoOAuthToken.php');
|
73 |
+
|
74 |
+
require_once(dirname(__FILE__).'/classes/Nosto.php');
|
75 |
+
require_once(dirname(__FILE__).'/classes/NostoAccount.php');
|
76 |
+
require_once(dirname(__FILE__).'/classes/NostoCipher.php');
|
77 |
+
require_once(dirname(__FILE__).'/classes/NostoDotEnv.php');
|
78 |
+
require_once(dirname(__FILE__).'/classes/NostoException.php');
|
79 |
+
require_once(dirname(__FILE__).'/classes/NostoMessage.php');
|
80 |
+
require_once(dirname(__FILE__).'/classes/NostoOrderConfirmation.php');
|
81 |
+
require_once(dirname(__FILE__).'/classes/NostoProductReCrawl.php');
|
82 |
+
require_once(dirname(__FILE__).'/classes/NostoXhrResponse.php');
|
83 |
+
|
84 |
+
// Libs
|
85 |
+
require_once(dirname(__FILE__).'/libs/phpseclib/crypt/NostoCryptBase.php');
|
86 |
+
require_once(dirname(__FILE__).'/libs/phpseclib/crypt/NostoCryptRijndael.php');
|
87 |
+
require_once(dirname(__FILE__).'/libs/phpseclib/crypt/NostoCryptAES.php');
|
88 |
+
require_once(dirname(__FILE__).'/libs/phpseclib/crypt/NostoCryptRandom.php');
|
89 |
+
|
90 |
+
// Parse .env if exists and assign configured environment variables.
|
91 |
+
NostoDotEnv::getInstance()->init(dirname(__FILE__));
|
92 |
+
if (isset($_ENV['NOSTO_API_BASE_URL'])) {
|
93 |
+
NostoApiRequest::$baseUrl = $_ENV['NOSTO_API_BASE_URL'];
|
94 |
+
}
|
95 |
+
if (isset($_ENV['NOSTO_OAUTH_BASE_URL'])) {
|
96 |
+
NostoOAuthClient::$baseUrl = $_ENV['NOSTO_OAUTH_BASE_URL'];
|
97 |
+
}
|
98 |
+
if (isset($_ENV['NOSTO_WEB_HOOK_BASE_URL'])) {
|
99 |
+
NostoHttpRequest::$baseUrl = $_ENV['NOSTO_WEB_HOOK_BASE_URL'];
|
100 |
+
}
|
lib/nosto/php-sdk/src/interfaces/NostoOAuthClientMetaDataInterface.php
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Interface for the OAuth2 client.
|
38 |
+
* The client implements the "Authorization Code" OAuth2 spec.
|
39 |
+
* @see https://tools.ietf.org/html/rfc6749
|
40 |
+
*/
|
41 |
+
interface NostoOAuthClientMetaDataInterface
|
42 |
+
{
|
43 |
+
/**
|
44 |
+
* The OAuth2 client ID.
|
45 |
+
* This will be a platform specific ID that Nosto will issue.
|
46 |
+
*
|
47 |
+
* @return string the client id.
|
48 |
+
*/
|
49 |
+
public function getClientId();
|
50 |
+
|
51 |
+
/**
|
52 |
+
* The OAuth2 client secret.
|
53 |
+
* This will be a platform specific secret that Nosto will issue.
|
54 |
+
*
|
55 |
+
* @return string the client secret.
|
56 |
+
*/
|
57 |
+
public function getClientSecret();
|
58 |
+
|
59 |
+
/**
|
60 |
+
* The OAuth2 redirect url to where the OAuth2 server should redirect the user after authorizing the application to
|
61 |
+
* act on the users behalf.
|
62 |
+
* This url must by publicly accessible and the domain must match the one defined for the Nosto account.
|
63 |
+
*
|
64 |
+
* @return string the url.
|
65 |
+
*/
|
66 |
+
public function getRedirectUrl();
|
67 |
+
|
68 |
+
/**
|
69 |
+
* The scopes for the OAuth2 request.
|
70 |
+
* These are used to request specific API tokens from Nosto and should almost always be the ones defined in
|
71 |
+
* NostoApiToken::$tokenNames.
|
72 |
+
*
|
73 |
+
* @return array the scopes.
|
74 |
+
*/
|
75 |
+
public function getScopes();
|
76 |
+
|
77 |
+
/**
|
78 |
+
* The 2-letter ISO code (ISO 639-1) for the language the OAuth2 server uses for UI localization.
|
79 |
+
*
|
80 |
+
* @return string the ISO code.
|
81 |
+
*/
|
82 |
+
public function getLanguageIsoCode();
|
83 |
+
}
|
lib/nosto/php-sdk/src/interfaces/NostoProductInterface.php
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Interface for the meta data of a product.
|
38 |
+
* This is used when making product re-crawl API requests and product history exports to Nosto.
|
39 |
+
*/
|
40 |
+
interface NostoProductInterface
|
41 |
+
{
|
42 |
+
/**
|
43 |
+
* Returns the absolute url to the product page in the shop frontend.
|
44 |
+
*
|
45 |
+
* @return string the url.
|
46 |
+
*/
|
47 |
+
public function getUrl();
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Returns the product's unique identifier.
|
51 |
+
*
|
52 |
+
* @return int|string the ID.
|
53 |
+
*/
|
54 |
+
public function getProductId();
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Returns the name of the product.
|
58 |
+
*
|
59 |
+
* @return string the name.
|
60 |
+
*/
|
61 |
+
public function getName();
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Returns the absolute url the one of the product images in the shop frontend.
|
65 |
+
*
|
66 |
+
* @return string the url.
|
67 |
+
*/
|
68 |
+
public function getImageUrl();
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Returns the price of the product including possible discounts and taxes.
|
72 |
+
*
|
73 |
+
* @return float the price with 2 decimals, e.g. 1000.99.
|
74 |
+
*/
|
75 |
+
public function getPrice();
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Returns the list price of the product without discounts but including possible taxes.
|
79 |
+
*
|
80 |
+
* @return float the price with 2 decimals, e.g. 1000.99.
|
81 |
+
*/
|
82 |
+
public function getListPrice();
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Returns the currency code (ISO 4217) the product is sold in.
|
86 |
+
*
|
87 |
+
* @return string the currency ISO code.
|
88 |
+
*/
|
89 |
+
public function getCurrencyCode();
|
90 |
+
|
91 |
+
/**
|
92 |
+
* Returns the availability of the product, i.e. if it is in stock or not.
|
93 |
+
*
|
94 |
+
* @return string the availability, either "InStock" or "OutOfStock".
|
95 |
+
*/
|
96 |
+
public function getAvailability();
|
97 |
+
|
98 |
+
/**
|
99 |
+
* Returns the tags for the product.
|
100 |
+
*
|
101 |
+
* @return array the tags array, e.g. array("winter", "shoe").
|
102 |
+
*/
|
103 |
+
public function getTags();
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Returns the categories the product is located in.
|
107 |
+
*
|
108 |
+
* @return array list of category strings, e.g. array("/shoes/winter", "shoes/boots").
|
109 |
+
*/
|
110 |
+
public function getCategories();
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Returns the product short description.
|
114 |
+
*
|
115 |
+
* @return string the short description.
|
116 |
+
*/
|
117 |
+
public function getShortDescription();
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Returns the product description.
|
121 |
+
*
|
122 |
+
* @return string the description.
|
123 |
+
*/
|
124 |
+
public function getDescription();
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Returns the product brand name.
|
128 |
+
*
|
129 |
+
* @return string the brand name.
|
130 |
+
*/
|
131 |
+
public function getBrand();
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Returns the product publication date in the shop.
|
135 |
+
*
|
136 |
+
* @return string the date in format "Y-m-d".
|
137 |
+
*/
|
138 |
+
public function getDatePublished();
|
139 |
+
}
|
lib/nosto/php-sdk/src/interfaces/account/NostoAccountInterface.php
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Interface for the Nosto account model that handles creation, syncing and SSO access for the Nosto account.
|
38 |
+
*/
|
39 |
+
interface NostoAccountInterface
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* Creates a new Nosto account with the specified data.
|
43 |
+
*
|
44 |
+
* @param NostoAccountMetaDataInterface $meta the account data model.
|
45 |
+
* @return NostoAccount the newly created account.
|
46 |
+
* @throws NostoException if the account cannot be created.
|
47 |
+
*/
|
48 |
+
public static function create(NostoAccountMetaDataInterface $meta);
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Syncs an existing Nosto account via Oauth2.
|
52 |
+
* Requires that the oauth cycle has already completed the first step in getting the authorization code.
|
53 |
+
*
|
54 |
+
* @param NostoOAuthClientMetaDataInterface $meta the oauth2 client meta data to use for connection to Nosto.
|
55 |
+
* @param string $code the authorization code that grants access to transfer data from nosto.
|
56 |
+
* @return NostoAccount the synced account.
|
57 |
+
* @throws NostoException if the account cannot be synced.
|
58 |
+
*/
|
59 |
+
public static function syncFromNosto(NostoOAuthClientMetaDataInterface $meta, $code);
|
60 |
+
|
61 |
+
/**
|
62 |
+
* Notifies Nosto that an account has been deleted.
|
63 |
+
*
|
64 |
+
* @throws NostoException if the API request to Nosto fails.
|
65 |
+
*/
|
66 |
+
public function delete();
|
67 |
+
|
68 |
+
/**
|
69 |
+
* Gets the account name.
|
70 |
+
*
|
71 |
+
* @return string the account name.
|
72 |
+
*/
|
73 |
+
public function getName();
|
74 |
+
|
75 |
+
/**
|
76 |
+
* Checks if this account has been connected to Nosto, i.e. all API tokens exist.
|
77 |
+
*
|
78 |
+
* @return bool true if it is connected, false otherwise.
|
79 |
+
*/
|
80 |
+
public function isConnectedToNosto();
|
81 |
+
|
82 |
+
/**
|
83 |
+
* Gets an api token associated with this account by it's name , e.g. "sso".
|
84 |
+
*
|
85 |
+
* @param string $name the api token name.
|
86 |
+
* @return NostoApiToken|null the token or null if not found.
|
87 |
+
*/
|
88 |
+
public function getApiToken($name);
|
89 |
+
|
90 |
+
/**
|
91 |
+
* Gets the secured iframe url for the account configuration page.
|
92 |
+
*
|
93 |
+
* @param NostoAccountMetaDataIframeInterface $meta the iframe meta data to use for fetching the secured url.
|
94 |
+
* @param array $params optional extra params to add to the iframe url.
|
95 |
+
* @return bool|string the url or false if could not be fetched.
|
96 |
+
*/
|
97 |
+
public function getIframeUrl(NostoAccountMetaDataIframeInterface $meta, array $params = array());
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Signs the user in to Nosto via SSO.
|
101 |
+
* Requires that the account has a valid sso token associated with it.
|
102 |
+
*
|
103 |
+
* @param NostoAccountMetaDataIframeInterface $meta the iframe meta data model.
|
104 |
+
* @return string a secure login url that can be used for example to build the config iframe url.
|
105 |
+
* @throws NostoException if SSO fails.
|
106 |
+
*/
|
107 |
+
public function ssoLogin(NostoAccountMetaDataIframeInterface $meta);
|
108 |
+
}
|
lib/nosto/php-sdk/src/interfaces/account/NostoAccountMetaDataBillingDetailsInterface.php
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Interface for account billing details.
|
38 |
+
* This is used by the NostoAccountMetaDataInterface meta data model when creating new Nosto accounts.
|
39 |
+
*/
|
40 |
+
interface NostoAccountMetaDataBillingDetailsInterface
|
41 |
+
{
|
42 |
+
/**
|
43 |
+
* The 2-letter ISO code (ISO 3166-1 alpha-2) for the country used in account's billing details.
|
44 |
+
*
|
45 |
+
* @return string the country ISO code.
|
46 |
+
*/
|
47 |
+
public function getCountry();
|
48 |
+
}
|
lib/nosto/php-sdk/src/interfaces/account/NostoAccountMetaDataIframeInterface.php
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Interface for the meta data needed for the account configuration iframe.
|
38 |
+
*/
|
39 |
+
interface NostoAccountMetaDataIframeInterface
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* The name of the platform the iframe is used on.
|
43 |
+
* A list of valid platform names is issued by Nosto.
|
44 |
+
*
|
45 |
+
* @return string the platform name.
|
46 |
+
*/
|
47 |
+
public function getPlatform();
|
48 |
+
|
49 |
+
/**
|
50 |
+
* The first name of the user who is loading the config iframe.
|
51 |
+
*
|
52 |
+
* @return string the first name.
|
53 |
+
*/
|
54 |
+
public function getFirstName();
|
55 |
+
|
56 |
+
/**
|
57 |
+
* The last name of the user who is loading the config iframe.
|
58 |
+
*
|
59 |
+
* @return string the last name.
|
60 |
+
*/
|
61 |
+
public function getLastName();
|
62 |
+
|
63 |
+
/**
|
64 |
+
* The email address of the user who is loading the config iframe.
|
65 |
+
*
|
66 |
+
* @return string the email address.
|
67 |
+
*/
|
68 |
+
public function getEmail();
|
69 |
+
|
70 |
+
/**
|
71 |
+
* The 2-letter ISO code (ISO 639-1) for the language of the user who is loading the config iframe.
|
72 |
+
*
|
73 |
+
* @return string the language ISO code.
|
74 |
+
*/
|
75 |
+
public function getLanguageIsoCode();
|
76 |
+
|
77 |
+
/**
|
78 |
+
* The 2-letter ISO code (ISO 639-1) for the language of the shop the account belongs to.
|
79 |
+
*
|
80 |
+
* @return string the language ISO code.
|
81 |
+
*/
|
82 |
+
public function getLanguageIsoCodeShop();
|
83 |
+
|
84 |
+
/**
|
85 |
+
* Unique identifier for the e-commerce installation.
|
86 |
+
* This identifier is used to link accounts together that are created on the same installation.
|
87 |
+
*
|
88 |
+
* @return string the identifier.
|
89 |
+
*/
|
90 |
+
public function getUniqueId();
|
91 |
+
|
92 |
+
/**
|
93 |
+
* The version number of the platform the e-commerce installation is running on.
|
94 |
+
*
|
95 |
+
* @return string the platform version.
|
96 |
+
*/
|
97 |
+
public function getVersionPlatform();
|
98 |
+
|
99 |
+
/**
|
100 |
+
* The version number of the Nosto module/extension running on the e-commerce installation.
|
101 |
+
*
|
102 |
+
* @return string the module version.
|
103 |
+
*/
|
104 |
+
public function getVersionModule();
|
105 |
+
|
106 |
+
/**
|
107 |
+
* An absolute URL for any product page in the shop the account is linked to, with the nostodebug GET parameter
|
108 |
+
* enabled. e.g. http://myshop.com/products/product123?nostodebug=true
|
109 |
+
* This is used in the config iframe to allow the user to quickly preview the recommendations on the given page.
|
110 |
+
*
|
111 |
+
* @return string the url.
|
112 |
+
*/
|
113 |
+
public function getPreviewUrlProduct();
|
114 |
+
|
115 |
+
/**
|
116 |
+
* An absolute URL for any category page in the shop the account is linked to, with the nostodebug GET parameter
|
117 |
+
* enabled. e.g. http://myshop.com/products/category123?nostodebug=true
|
118 |
+
* This is used in the config iframe to allow the user to quickly preview the recommendations on the given page.
|
119 |
+
*
|
120 |
+
* @return string the url.
|
121 |
+
*/
|
122 |
+
public function getPreviewUrlCategory();
|
123 |
+
|
124 |
+
/**
|
125 |
+
* An absolute URL for the search page in the shop the account is linked to, with the nostodebug GET parameter
|
126 |
+
* enabled. e.g. http://myshop.com/search?query=red?nostodebug=true
|
127 |
+
* This is used in the config iframe to allow the user to quickly preview the recommendations on the given page.
|
128 |
+
*
|
129 |
+
* @return string the url.
|
130 |
+
*/
|
131 |
+
public function getPreviewUrlSearch();
|
132 |
+
|
133 |
+
/**
|
134 |
+
* An absolute URL for the cart page in the shop the account is linked to, with the nostodebug GET parameter
|
135 |
+
* enabled. e.g. http://myshop.com/cart?nostodebug=true
|
136 |
+
* This is used in the config iframe to allow the user to quickly preview the recommendations on the given page.
|
137 |
+
*
|
138 |
+
* @return string the url.
|
139 |
+
*/
|
140 |
+
public function getPreviewUrlCart();
|
141 |
+
|
142 |
+
/**
|
143 |
+
* An absolute URL for the front page in the shop the account is linked to, with the nostodebug GET parameter
|
144 |
+
* enabled. e.g. http://myshop.com?nostodebug=true
|
145 |
+
* This is used in the config iframe to allow the user to quickly preview the recommendations on the given page.
|
146 |
+
*
|
147 |
+
* @return string the url.
|
148 |
+
*/
|
149 |
+
public function getPreviewUrlFront();
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Returns the name of the shop context where Nosto is installed or about to be installed in.
|
153 |
+
*
|
154 |
+
* @return string the name.
|
155 |
+
*/
|
156 |
+
public function getShopName();
|
157 |
+
}
|
lib/nosto/php-sdk/src/interfaces/account/NostoAccountMetaDataInterface.php
ADDED
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Interface for the meta data model used when creating new Nosto accounts.
|
38 |
+
*/
|
39 |
+
interface NostoAccountMetaDataInterface
|
40 |
+
{
|
41 |
+
/**
|
42 |
+
* The shops name for which the account is to be created for.
|
43 |
+
*
|
44 |
+
* @return string the name.
|
45 |
+
*/
|
46 |
+
public function getTitle();
|
47 |
+
|
48 |
+
/**
|
49 |
+
* The name of the account to create.
|
50 |
+
* This has to follow the pattern of "[platform name]-[8 character lowercase alpha numeric string]".
|
51 |
+
*
|
52 |
+
* @return string the account name.
|
53 |
+
*/
|
54 |
+
public function getName();
|
55 |
+
|
56 |
+
/**
|
57 |
+
* The name of the platform the account is used on.
|
58 |
+
* A list of valid platform names is issued by Nosto.
|
59 |
+
*
|
60 |
+
* @return string the platform names.
|
61 |
+
*/
|
62 |
+
public function getPlatform();
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Absolute url to the front page of the shop for which the account is created for.
|
66 |
+
*
|
67 |
+
* @return string the url.
|
68 |
+
*/
|
69 |
+
public function getFrontPageUrl();
|
70 |
+
|
71 |
+
/**
|
72 |
+
* The 3-letter ISO code (ISO 4217) for the currency used by the shop for which the account is created for.
|
73 |
+
*
|
74 |
+
* @return string the currency ISO code.
|
75 |
+
*/
|
76 |
+
public function getCurrencyCode();
|
77 |
+
|
78 |
+
/**
|
79 |
+
* The 2-letter ISO code (ISO 639-1) for the language used by the shop for which the account is created for.
|
80 |
+
*
|
81 |
+
* @return string the language ISO code.
|
82 |
+
*/
|
83 |
+
public function getLanguageCode();
|
84 |
+
|
85 |
+
/**
|
86 |
+
* The 2-letter ISO code (ISO 639-1) for the language of the account owner who is creating the account.
|
87 |
+
*
|
88 |
+
* @return string the language ISO code.
|
89 |
+
*/
|
90 |
+
public function getOwnerLanguageCode();
|
91 |
+
|
92 |
+
/**
|
93 |
+
* Meta data model for the account owner who is creating the account.
|
94 |
+
*
|
95 |
+
* @return NostoAccountMetaDataOwnerInterface the meta data model.
|
96 |
+
*/
|
97 |
+
public function getOwner();
|
98 |
+
|
99 |
+
/**
|
100 |
+
* Meta data model for the account billing details.
|
101 |
+
*
|
102 |
+
* @return NostoAccountMetaDataBillingDetailsInterface the meta data model.
|
103 |
+
*/
|
104 |
+
public function getBillingDetails();
|
105 |
+
|
106 |
+
/**
|
107 |
+
* The API token used to identify an account creation.
|
108 |
+
* This token is platform specific and issued by Nosto.
|
109 |
+
*
|
110 |
+
* @return string the API token.
|
111 |
+
*/
|
112 |
+
public function getSignUpApiToken();
|
113 |
+
}
|
lib/nosto/php-sdk/src/interfaces/account/NostoAccountMetaDataOwnerInterface.php
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Interface for the account owner details.
|
38 |
+
* This is used by the NostoAccountMetaDataInterface meta data model when creating new Nosto accounts.
|
39 |
+
*/
|
40 |
+
interface NostoAccountMetaDataOwnerInterface
|
41 |
+
{
|
42 |
+
/**
|
43 |
+
* The first name of the account owner.
|
44 |
+
*
|
45 |
+
* @return string the first name.
|
46 |
+
*/
|
47 |
+
public function getFirstName();
|
48 |
+
|
49 |
+
/**
|
50 |
+
* The last name of the account owner.
|
51 |
+
*
|
52 |
+
* @return string the last name.
|
53 |
+
*/
|
54 |
+
public function getLastName();
|
55 |
+
|
56 |
+
/**
|
57 |
+
* The email address of the account owner.
|
58 |
+
*
|
59 |
+
* @return string the email address.
|
60 |
+
*/
|
61 |
+
public function getEmail();
|
62 |
+
}
|
lib/nosto/php-sdk/src/interfaces/order/NostoOrderBuyerInterface.php
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Interface for user information meta data of an order.
|
38 |
+
* This is used by the NostoOrderInterface meta data model when sending order confirmation API requests.
|
39 |
+
*/
|
40 |
+
interface NostoOrderBuyerInterface
|
41 |
+
{
|
42 |
+
/**
|
43 |
+
* Gets the first name of the user who placed the order.
|
44 |
+
*
|
45 |
+
* @return string the first name.
|
46 |
+
*/
|
47 |
+
public function getFirstName();
|
48 |
+
|
49 |
+
/**
|
50 |
+
* Gets the last name of the user who placed the order.
|
51 |
+
*
|
52 |
+
* @return string the last name.
|
53 |
+
*/
|
54 |
+
public function getLastName();
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Gets the email address of the user who placed the order.
|
58 |
+
*
|
59 |
+
* @return string the email address.
|
60 |
+
*/
|
61 |
+
public function getEmail();
|
62 |
+
}
|
lib/nosto/php-sdk/src/interfaces/order/NostoOrderInterface.php
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Interface for the meta data of an placed order.
|
38 |
+
* This is used when making order confirmation API requests and order history exports to Nosto.
|
39 |
+
*/
|
40 |
+
interface NostoOrderInterface
|
41 |
+
{
|
42 |
+
/**
|
43 |
+
* The unique order number identifying the order.
|
44 |
+
*
|
45 |
+
* @return string|int the order number.
|
46 |
+
*/
|
47 |
+
public function getOrderNumber();
|
48 |
+
|
49 |
+
/**
|
50 |
+
* The date when the order was placed, formatted according to "Y-m-d".
|
51 |
+
*
|
52 |
+
* @return string the creation date.
|
53 |
+
*/
|
54 |
+
public function getCreatedDate();
|
55 |
+
|
56 |
+
/**
|
57 |
+
* The payment provider used for placing the order, formatted according to "[provider name] [provider version]".
|
58 |
+
*
|
59 |
+
* @return string the payment provider.
|
60 |
+
*/
|
61 |
+
public function getPaymentProvider();
|
62 |
+
|
63 |
+
/**
|
64 |
+
* The buyer info of the user who placed the order.
|
65 |
+
*
|
66 |
+
* @return NostoOrderBuyerInterface the meta data model.
|
67 |
+
*/
|
68 |
+
public function getBuyerInfo();
|
69 |
+
|
70 |
+
/**
|
71 |
+
* The purchased items which were included in the order.
|
72 |
+
*
|
73 |
+
* @return NostoOrderPurchasedItemInterface[] the meta data models.
|
74 |
+
*/
|
75 |
+
public function getPurchasedItems();
|
76 |
+
}
|
lib/nosto/php-sdk/src/interfaces/order/NostoOrderPurchasedItemInterface.php
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
4 |
+
* All rights reserved.
|
5 |
+
*
|
6 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
7 |
+
* are permitted provided that the following conditions are met:
|
8 |
+
*
|
9 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
10 |
+
* this list of conditions and the following disclaimer.
|
11 |
+
*
|
12 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
13 |
+
* this list of conditions and the following disclaimer in the documentation
|
14 |
+
* and/or other materials provided with the distribution.
|
15 |
+
*
|
16 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
17 |
+
* may be used to endorse or promote products derived from this software without
|
18 |
+
* specific prior written permission.
|
19 |
+
*
|
20 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
21 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
22 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
23 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
24 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
25 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
26 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
27 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
28 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30 |
+
*
|
31 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
32 |
+
* @copyright 2015 Nosto Solutions Ltd
|
33 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
34 |
+
*/
|
35 |
+
|
36 |
+
/**
|
37 |
+
* Interface for an purchased item in an order.
|
38 |
+
* This is used by the NostoOrderInterface meta data model when sending order confirmation API requests.
|
39 |
+
*
|
40 |
+
* The purchased item should also be used for shipping costs, discounts or other similar data.
|
41 |
+
*/
|
42 |
+
interface NostoOrderPurchasedItemInterface
|
43 |
+
{
|
44 |
+
/**
|
45 |
+
* The unique identifier of the purchased item.
|
46 |
+
* If this item is for discounts or shipping cost, the id can be 0.
|
47 |
+
*
|
48 |
+
* @return string|int
|
49 |
+
*/
|
50 |
+
public function getProductId();
|
51 |
+
|
52 |
+
/**
|
53 |
+
* The quantity of the item included in the order.
|
54 |
+
*
|
55 |
+
* @return int the quantity.
|
56 |
+
*/
|
57 |
+
public function getQuantity();
|
58 |
+
|
59 |
+
/**
|
60 |
+
* The name of the item included in the order.
|
61 |
+
*
|
62 |
+
* @return string the name.
|
63 |
+
*/
|
64 |
+
public function getName();
|
65 |
+
|
66 |
+
/**
|
67 |
+
* The unit price of the item included in the order, formatted according to "99.99".
|
68 |
+
*
|
69 |
+
* @return float the unit price.
|
70 |
+
*/
|
71 |
+
public function getUnitPrice();
|
72 |
+
|
73 |
+
/**
|
74 |
+
* The 3-letter ISO code (ISO 4217) for the currency the item was purchased in.
|
75 |
+
*
|
76 |
+
* @return string the currency ISO code.
|
77 |
+
*/
|
78 |
+
public function getCurrencyCode();
|
79 |
+
}
|
lib/nosto/php-sdk/src/js/NostoIframe.min.js
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
if("undefined"==typeof Nosto)var Nosto={};Nosto.iframe=function(a){function b(a){if(a.origin===decodeURIComponent(j.origin)&&"[Nosto]"===(""+a.data).substr(0,7)){var b=(""+a.data).substr(7),d=JSON.parse(b);if("object"==typeof d&&d.type)switch(d.type){case g:c(j.urls.createAccount,{data:{email:d.params.email},success:function(a){var b=JSON.parse(a.target.response);if(!b.redirect_url)throw new Error("Nosto: failed to handle account creation.");f().src=b.redirect_url}});break;case h:c(j.urls.connectAccount,{success:function(a){var b=JSON.parse(a.target.response);if(!b.redirect_url)throw new Error("Nosto: failed to handle account connection.");b.success&&b.success===!0?window.location.href=b.redirect_url:f().src=b.redirect_url}});break;case i:c(j.urls.deleteAccount,{success:function(a){var b=JSON.parse(a.target.response);if(!b.redirect_url)throw new Error("Nosto: failed to handle account deletion.");f().src=b.redirect_url}});break;default:throw new Error("Nosto: invalid postMessage `type`.")}}}function c(a,b){var c=d({method:"POST",async:!0,data:{}},b);d(c.data,j.xhrParams);var f=e(c.data),g=new XMLHttpRequest;"function"==typeof c.success&&g.addEventListener("load",c.success,!1),"function"==typeof c.error&&g.addEventListener("error",c.error,!1),g.open(c.method,decodeURIComponent(a),c.async),g.setRequestHeader("X-Requested-With","XMLHttpRequest"),g.setRequestHeader("Content-Type","application/x-www-form-urlencoded"),g.send(f)}function d(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}function e(a){var b="";for(var c in a)a.hasOwnProperty(c)&&(""!==b&&(b+="&"),b+=encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b}function f(){return document.getElementById(j.iframeId)}var g="newAccount",h="connectAccount",i="removeAccount",j={origin:"https://my.nosto.com",iframeId:"nosto_iframe",urls:{createAccount:"",connectAccount:"",deleteAccount:""},xhrParams:{}};d(j,a),window.addEventListener("message",b,!1)};
|
lib/nosto/php-sdk/src/js/src/NostoIframe.js
ADDED
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Copyright (c) 2015, Nosto Solutions Ltd
|
3 |
+
* All rights reserved.
|
4 |
+
*
|
5 |
+
* Redistribution and use in source and binary forms, with or without modification,
|
6 |
+
* are permitted provided that the following conditions are met:
|
7 |
+
*
|
8 |
+
* 1. Redistributions of source code must retain the above copyright notice,
|
9 |
+
* this list of conditions and the following disclaimer.
|
10 |
+
*
|
11 |
+
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
12 |
+
* this list of conditions and the following disclaimer in the documentation
|
13 |
+
* and/or other materials provided with the distribution.
|
14 |
+
*
|
15 |
+
* 3. Neither the name of the copyright holder nor the names of its contributors
|
16 |
+
* may be used to endorse or promote products derived from this software without
|
17 |
+
* specific prior written permission.
|
18 |
+
*
|
19 |
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
20 |
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
21 |
+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
22 |
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
23 |
+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
24 |
+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
25 |
+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
26 |
+
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
27 |
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
28 |
+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29 |
+
*
|
30 |
+
* @author Nosto Solutions Ltd <contact@nosto.com>
|
31 |
+
* @copyright 2015 Nosto Solutions Ltd
|
32 |
+
* @license http://opensource.org/licenses/BSD-3-Clause BSD 3-Clause
|
33 |
+
*/
|
34 |
+
|
35 |
+
// Define the "Nosto" namespace if not already defined.
|
36 |
+
if (typeof Nosto === "undefined") {
|
37 |
+
var Nosto = {};
|
38 |
+
}
|
39 |
+
|
40 |
+
/**
|
41 |
+
* Nosto iframe API.
|
42 |
+
*
|
43 |
+
* @param {Object} options
|
44 |
+
*/
|
45 |
+
Nosto.iframe = function(options) {
|
46 |
+
var TYPE_NEW_ACCOUNT = "newAccount",
|
47 |
+
TYPE_CONNECT_ACCOUNT = "connectAccount",
|
48 |
+
TYPE_REMOVE_ACCOUNT = "removeAccount";
|
49 |
+
|
50 |
+
/**
|
51 |
+
* @type {Object}
|
52 |
+
*/
|
53 |
+
var settings = {
|
54 |
+
origin: "https://my.nosto.com",
|
55 |
+
iframeId: "nosto_iframe",
|
56 |
+
urls: {
|
57 |
+
createAccount: "",
|
58 |
+
connectAccount: "",
|
59 |
+
deleteAccount: ""
|
60 |
+
},
|
61 |
+
xhrParams: {}
|
62 |
+
};
|
63 |
+
|
64 |
+
/**
|
65 |
+
* Window.postMessage() event handler for catching messages from nosto.
|
66 |
+
*
|
67 |
+
* Supported messages must come from nosto.com and be formatted according
|
68 |
+
* to the following example:
|
69 |
+
*
|
70 |
+
* '[Nosto]{ "type": "the message action", "params": {} }'
|
71 |
+
*
|
72 |
+
* @param {Object} event
|
73 |
+
*/
|
74 |
+
function receiveMessage(event)
|
75 |
+
{
|
76 |
+
// Check the origin to prevent cross-site scripting.
|
77 |
+
if (event.origin !== decodeURIComponent(settings.origin)) {
|
78 |
+
return;
|
79 |
+
}
|
80 |
+
// If the message does not start with "[Nosto]", then it is not for us.
|
81 |
+
if ((""+event.data).substr(0, 7) !== "[Nosto]") {
|
82 |
+
return;
|
83 |
+
}
|
84 |
+
|
85 |
+
var json = (""+event.data).substr(7);
|
86 |
+
var data = JSON.parse(json);
|
87 |
+
if (typeof data === "object" && data.type) {
|
88 |
+
switch (data.type) {
|
89 |
+
case TYPE_NEW_ACCOUNT:
|
90 |
+
xhr(settings.urls.createAccount, {
|
91 |
+
data: {email: data.params.email},
|
92 |
+
success: function (e) {
|
93 |
+
/** @type {{success: Boolean}, {redirect_url: String}} response */
|
94 |
+
var response = JSON.parse(e.target.response);
|
95 |
+
if (response.redirect_url) {
|
96 |
+
getIframeElement().src = response.redirect_url;
|
97 |
+
} else {
|
98 |
+
throw new Error("Nosto: failed to handle account creation.");
|
99 |
+
}
|
100 |
+
}
|
101 |
+
});
|
102 |
+
break;
|
103 |
+
|
104 |
+
case TYPE_CONNECT_ACCOUNT:
|
105 |
+
xhr(settings.urls.connectAccount, {
|
106 |
+
success: function (e) {
|
107 |
+
/** @type {{success: Boolean}, {redirect_url: String}} response */
|
108 |
+
var response = JSON.parse(e.target.response);
|
109 |
+
if (response.redirect_url) {
|
110 |
+
if (response.success && response.success === true) {
|
111 |
+
window.location.href = response.redirect_url;
|
112 |
+
} else {
|
113 |
+
getIframeElement().src = response.redirect_url;
|
114 |
+
}
|
115 |
+
} else {
|
116 |
+
throw new Error("Nosto: failed to handle account connection.");
|
117 |
+
}
|
118 |
+
}
|
119 |
+
});
|
120 |
+
break;
|
121 |
+
|
122 |
+
case TYPE_REMOVE_ACCOUNT:
|
123 |
+
xhr(settings.urls.deleteAccount, {
|
124 |
+
success: function (e) {
|
125 |
+
/** @type {{success: Boolean}, {redirect_url: String}} response */
|
126 |
+
var response = JSON.parse(e.target.response);
|
127 |
+
if (response.redirect_url) {
|
128 |
+
getIframeElement().src = response.redirect_url;
|
129 |
+
} else {
|
130 |
+
throw new Error("Nosto: failed to handle account deletion.");
|
131 |
+
}
|
132 |
+
}
|
133 |
+
});
|
134 |
+
break;
|
135 |
+
|
136 |
+
default:
|
137 |
+
throw new Error("Nosto: invalid postMessage `type`.");
|
138 |
+
}
|
139 |
+
}
|
140 |
+
}
|
141 |
+
|
142 |
+
/**
|
143 |
+
* Creates a new XMLHttpRequest.
|
144 |
+
*
|
145 |
+
* Usage example:
|
146 |
+
*
|
147 |
+
* xhr("http://localhost/target.html", {
|
148 |
+
* "method": "POST",
|
149 |
+
* "data": {"key": "value"},
|
150 |
+
* "success": function (e) { // handle success request },
|
151 |
+
* "error": function (e) { // handle failure request }
|
152 |
+
* });
|
153 |
+
*
|
154 |
+
* @param {String} url the url to call.
|
155 |
+
* @param {Object} params optional params.
|
156 |
+
*/
|
157 |
+
function xhr(url, params) {
|
158 |
+
var options = extendObject({
|
159 |
+
method: "POST",
|
160 |
+
async: true,
|
161 |
+
data: {}
|
162 |
+
}, params);
|
163 |
+
|
164 |
+
extendObject(options.data, settings.xhrParams);
|
165 |
+
var payload = buildParams(options.data);
|
166 |
+
|
167 |
+
var oReq = new XMLHttpRequest();
|
168 |
+
if (typeof options.success === "function") {
|
169 |
+
oReq.addEventListener("load", options.success, false);
|
170 |
+
}
|
171 |
+
if (typeof options.error === "function") {
|
172 |
+
oReq.addEventListener("error", options.error, false);
|
173 |
+
}
|
174 |
+
oReq.open(options.method, decodeURIComponent(url), options.async);
|
175 |
+
oReq.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
176 |
+
oReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
|
177 |
+
oReq.send(payload);
|
178 |
+
}
|
179 |
+
|
180 |
+
/**
|
181 |
+
* Extends a literal object with data from the other object.
|
182 |
+
*
|
183 |
+
* @param {Object} obj1 the object to extend.
|
184 |
+
* @param {Object} obj2 the object to extend from.
|
185 |
+
* @returns {Object}
|
186 |
+
*/
|
187 |
+
function extendObject(obj1, obj2) {
|
188 |
+
for (var key in obj2) {
|
189 |
+
if (obj2.hasOwnProperty(key)) {
|
190 |
+
obj1[key] = obj2[key];
|
191 |
+
}
|
192 |
+
}
|
193 |
+
return obj1;
|
194 |
+
}
|
195 |
+
|
196 |
+
/**
|
197 |
+
* Builds a query string based on params.
|
198 |
+
*
|
199 |
+
* @param {Object} params the params to turn into a query string.
|
200 |
+
* @returns {string} the built query string.
|
201 |
+
*/
|
202 |
+
function buildParams(params) {
|
203 |
+
var queryString = "";
|
204 |
+
for (var key in params) {
|
205 |
+
if (params.hasOwnProperty(key)) {
|
206 |
+
if (queryString !== "") {
|
207 |
+
queryString += "&";
|
208 |
+
}
|
209 |
+
queryString += encodeURIComponent(key)+"="+encodeURIComponent(params[key]);
|
210 |
+
}
|
211 |
+
}
|
212 |
+
return queryString;
|
213 |
+
}
|
214 |
+
|
215 |
+
/**
|
216 |
+
* Returns the iframe html element associated with this iframe API.
|
217 |
+
*
|
218 |
+
* @returns {HTMLElement} the element.
|
219 |
+
*/
|
220 |
+
function getIframeElement()
|
221 |
+
{
|
222 |
+
return document.getElementById(settings.iframeId);
|
223 |
+
}
|
224 |
+
|
225 |
+
// Configure the iframe API.
|
226 |
+
extendObject(settings, options);
|
227 |
+
|
228 |
+
// Register event handler for window.postMessage() messages from nosto.
|
229 |
+
window.addEventListener("message", receiveMessage, false);
|
230 |
+
};
|
lib/nosto/php-sdk/src/libs/phpseclib/crypt/NostoCryptAES.php
ADDED
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Pure-PHP implementation of AES.
|
4 |
+
*
|
5 |
+
* Uses mcrypt, if available/possible, and an internal implementation, otherwise.
|
6 |
+
*
|
7 |
+
* PHP versions 5
|
8 |
+
*
|
9 |
+
* If {@link NostoCryptAES::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
|
10 |
+
* {@link NostoCryptAES::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's
|
11 |
+
* 136-bits it'll be null-padded to 192-bits and 192 bits will be the key length until
|
12 |
+
* {@link NostoCryptAES::setKey() setKey()} is called, again, at which point, it'll be recalculated.
|
13 |
+
*
|
14 |
+
* Since NostoCryptAES extends NostoCryptRijndael, some functions are available to be called that, in the context of
|
15 |
+
* AES, don't make a whole lot of sense. {@link NostoCryptAES::setBlockLength() setBlockLength()}, for instance.
|
16 |
+
* Calling that function, however possible, won't do anything (AES has a fixed block length whereas Rijndael has a
|
17 |
+
* variable one).
|
18 |
+
*
|
19 |
+
* Here's a short example of how to use this library:
|
20 |
+
* <code>
|
21 |
+
* <?php
|
22 |
+
*
|
23 |
+
* $aes = new NostoCryptAES();
|
24 |
+
*
|
25 |
+
* $aes->setKey('abcdefghijklmnop');
|
26 |
+
*
|
27 |
+
* $size = 10 * 1024;
|
28 |
+
* $plaintext = '';
|
29 |
+
* for ($i = 0; $i < $size; $i++) {
|
30 |
+
* $plaintext.= 'a';
|
31 |
+
* }
|
32 |
+
*
|
33 |
+
* echo $aes->decrypt($aes->encrypt($plaintext));
|
34 |
+
* ?>
|
35 |
+
* </code>
|
36 |
+
*
|
37 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
38 |
+
* of this software and associated documentation files (the "Software"), to deal
|
39 |
+
* in the Software without restriction, including without limitation the rights
|
40 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
41 |
+
* copies of the Software, and to permit persons to whom the Software is
|
42 |
+
* furnished to do so, subject to the following conditions:
|
43 |
+
*
|
44 |
+
* The above copyright notice and this permission notice shall be included in
|
45 |
+
* all copies or substantial portions of the Software.
|
46 |
+
*
|
47 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
48 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
49 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
50 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
51 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
52 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
53 |
+
* THE SOFTWARE.
|
54 |
+
*
|
55 |
+
* @category Crypt
|
56 |
+
* @package NostoCryptAES
|
57 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
58 |
+
* @copyright MMVIII Jim Wigginton
|
59 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
60 |
+
* @link http://phpseclib.sourceforge.net
|
61 |
+
*/
|
62 |
+
|
63 |
+
/**
|
64 |
+
* Encrypt / decrypt using the Counter mode.
|
65 |
+
*
|
66 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
67 |
+
*
|
68 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
69 |
+
*/
|
70 |
+
if (!defined('CRYPT_AES_MODE_CTR')) {
|
71 |
+
define('CRYPT_AES_MODE_CTR', CRYPT_MODE_CTR);
|
72 |
+
}
|
73 |
+
/**
|
74 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
75 |
+
*
|
76 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
77 |
+
*/
|
78 |
+
if (!defined('CRYPT_AES_MODE_ECB')) {
|
79 |
+
define('CRYPT_AES_MODE_ECB', CRYPT_MODE_ECB);
|
80 |
+
}
|
81 |
+
/**
|
82 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
83 |
+
*
|
84 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
85 |
+
*/
|
86 |
+
if (!defined('CRYPT_AES_MODE_CBC')) {
|
87 |
+
define('CRYPT_AES_MODE_CBC', CRYPT_MODE_CBC);
|
88 |
+
}
|
89 |
+
/**
|
90 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
91 |
+
*
|
92 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
93 |
+
*/
|
94 |
+
if (!defined('CRYPT_AES_MODE_CFB')) {
|
95 |
+
define('CRYPT_AES_MODE_CFB', CRYPT_MODE_CFB);
|
96 |
+
}
|
97 |
+
/**
|
98 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
99 |
+
*
|
100 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
101 |
+
*/
|
102 |
+
if (!defined('CRYPT_AES_MODE_OFB')) {
|
103 |
+
define('CRYPT_AES_MODE_OFB', CRYPT_MODE_OFB);
|
104 |
+
}
|
105 |
+
|
106 |
+
/**
|
107 |
+
* Toggles the internal implementation
|
108 |
+
*/
|
109 |
+
if (!defined('CRYPT_AES_MODE_INTERNAL')) {
|
110 |
+
define('CRYPT_AES_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
|
111 |
+
}
|
112 |
+
/**
|
113 |
+
* Toggles the mcrypt implementation
|
114 |
+
*/
|
115 |
+
if (!defined('CRYPT_AES_MODE_MCRYPT')) {
|
116 |
+
define('CRYPT_AES_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
117 |
+
}
|
118 |
+
|
119 |
+
/**
|
120 |
+
* Pure-PHP implementation of AES.
|
121 |
+
*
|
122 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
123 |
+
* @version 0.1.0
|
124 |
+
* @package CryptAES
|
125 |
+
*/
|
126 |
+
class NostoCryptAES extends NostoCryptRijndael
|
127 |
+
{
|
128 |
+
/**
|
129 |
+
* The namespace used by the cipher for its constants.
|
130 |
+
*
|
131 |
+
* @see NostoCryptBase::const_namespace
|
132 |
+
* @var String
|
133 |
+
*/
|
134 |
+
public $constNamespace = 'AES';
|
135 |
+
|
136 |
+
/**
|
137 |
+
* Default Constructor.
|
138 |
+
*
|
139 |
+
* Determines whether or not the mcrypt extension should be used.
|
140 |
+
*
|
141 |
+
* $mode could be:
|
142 |
+
*
|
143 |
+
* - CRYPT_AES_MODE_ECB
|
144 |
+
*
|
145 |
+
* - CRYPT_AES_MODE_CBC
|
146 |
+
*
|
147 |
+
* - CRYPT_AES_MODE_CTR
|
148 |
+
*
|
149 |
+
* - CRYPT_AES_MODE_CFB
|
150 |
+
*
|
151 |
+
* - CRYPT_AES_MODE_OFB
|
152 |
+
*
|
153 |
+
* If not explicitly set, CRYPT_AES_MODE_CBC will be used.
|
154 |
+
*
|
155 |
+
* @see NostoCryptRijndael::__construct()
|
156 |
+
* @see NostoCryptBase::__construct()
|
157 |
+
* @param optional Integer $mode
|
158 |
+
*/
|
159 |
+
public function __construct($mode = CRYPT_AES_MODE_CBC)
|
160 |
+
{
|
161 |
+
parent::__construct($mode);
|
162 |
+
}
|
163 |
+
|
164 |
+
/**
|
165 |
+
* Dummy function
|
166 |
+
*
|
167 |
+
* Since CryptAES extends CryptRijndael, this function is, technically, available, but it does not do anything.
|
168 |
+
*
|
169 |
+
* @see NostoCryptRijndael::setBlockLength()
|
170 |
+
* @param Integer $length
|
171 |
+
*/
|
172 |
+
public function setBlockLength($length)
|
173 |
+
{
|
174 |
+
}
|
175 |
+
}
|
lib/nosto/php-sdk/src/libs/phpseclib/crypt/NostoCryptBase.php
ADDED
@@ -0,0 +1,2016 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Base Class for all NostoCrypt* cipher classes
|
4 |
+
*
|
5 |
+
* PHP versions 5
|
6 |
+
*
|
7 |
+
* Internally for phpseclib developers:
|
8 |
+
* If you plan to add a new cipher class, please note following rules:
|
9 |
+
*
|
10 |
+
* - The new Crypt* cipher class should extend NostoCryptBase
|
11 |
+
*
|
12 |
+
* - Following methods are then required to be overridden/overloaded:
|
13 |
+
*
|
14 |
+
* - encryptBlock()
|
15 |
+
*
|
16 |
+
* - decryptBlock()
|
17 |
+
*
|
18 |
+
* - setupKey()
|
19 |
+
*
|
20 |
+
* - All other methods are optional to be overridden/overloaded
|
21 |
+
*
|
22 |
+
* - Look at the source code of the current ciphers how they extend NostoCryptBase
|
23 |
+
* and take one of them as a start up for the new cipher class.
|
24 |
+
*
|
25 |
+
* - Please read all the other comments/notes/hints here also for each class var/method
|
26 |
+
*
|
27 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
28 |
+
* of this software and associated documentation files (the "Software"), to deal
|
29 |
+
* in the Software without restriction, including without limitation the rights
|
30 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
31 |
+
* copies of the Software, and to permit persons to whom the Software is
|
32 |
+
* furnished to do so, subject to the following conditions:
|
33 |
+
*
|
34 |
+
* The above copyright notice and this permission notice shall be included in
|
35 |
+
* all copies or substantial portions of the Software.
|
36 |
+
*
|
37 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
38 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
39 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
40 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
41 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
42 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
43 |
+
* THE SOFTWARE.
|
44 |
+
*
|
45 |
+
* @category Crypt
|
46 |
+
* @package NostoCryptBase
|
47 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
48 |
+
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
49 |
+
* @copyright MMVII Jim Wigginton
|
50 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
51 |
+
* @version 1.0.1
|
52 |
+
* @link http://phpseclib.sourceforge.net
|
53 |
+
*/
|
54 |
+
|
55 |
+
/**
|
56 |
+
* Encrypt / decrypt using the Counter mode.
|
57 |
+
*
|
58 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
59 |
+
*
|
60 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
61 |
+
*/
|
62 |
+
if (!defined('CRYPT_MODE_CTR')) {
|
63 |
+
define('CRYPT_MODE_CTR', -1);
|
64 |
+
}
|
65 |
+
/**
|
66 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
67 |
+
*
|
68 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
69 |
+
*/
|
70 |
+
if (!defined('CRYPT_MODE_ECB')) {
|
71 |
+
define('CRYPT_MODE_ECB', 1);
|
72 |
+
}
|
73 |
+
/**
|
74 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
75 |
+
*
|
76 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
77 |
+
*/
|
78 |
+
if (!defined('CRYPT_MODE_CBC')) {
|
79 |
+
define('CRYPT_MODE_CBC', 2);
|
80 |
+
}
|
81 |
+
/**
|
82 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
83 |
+
*
|
84 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
85 |
+
*/
|
86 |
+
if (!defined('CRYPT_MODE_CFB')) {
|
87 |
+
define('CRYPT_MODE_CFB', 3);
|
88 |
+
}
|
89 |
+
/**
|
90 |
+
* Encrypt / decrypt using the Output Feedback mode.
|
91 |
+
*
|
92 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
93 |
+
*/
|
94 |
+
if (!defined('CRYPT_MODE_OFB')) {
|
95 |
+
define('CRYPT_MODE_OFB', 4);
|
96 |
+
}
|
97 |
+
/**
|
98 |
+
* Encrypt / decrypt using streaming mode.
|
99 |
+
*
|
100 |
+
*/
|
101 |
+
if (!defined('CRYPT_MODE_STREAM')) {
|
102 |
+
define('CRYPT_MODE_STREAM', 5);
|
103 |
+
}
|
104 |
+
|
105 |
+
/**
|
106 |
+
* Base value for the internal implementation $engine switch
|
107 |
+
*/
|
108 |
+
if (!defined('CRYPT_MODE_INTERNAL')) {
|
109 |
+
define('CRYPT_MODE_INTERNAL', 1);
|
110 |
+
}
|
111 |
+
/**
|
112 |
+
* Base value for the mcrypt implementation $engine switch
|
113 |
+
*/
|
114 |
+
if (!defined('CRYPT_MODE_MCRYPT')) {
|
115 |
+
define('CRYPT_MODE_MCRYPT', 2);
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* NostoUndefinedMethodException
|
120 |
+
*
|
121 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
122 |
+
* @version 0.3.5
|
123 |
+
* @package NostoCryptBase
|
124 |
+
*/
|
125 |
+
class NostoUndefinedMethodException extends Exception
|
126 |
+
{
|
127 |
+
}
|
128 |
+
|
129 |
+
/**
|
130 |
+
* NostoInvalidLengthException
|
131 |
+
*
|
132 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
133 |
+
* @version 0.3.5
|
134 |
+
* @package NostoCryptBase
|
135 |
+
*/
|
136 |
+
class NostoInvalidLengthException extends Exception
|
137 |
+
{
|
138 |
+
}
|
139 |
+
|
140 |
+
/**
|
141 |
+
* NostoInvalidPaddingException
|
142 |
+
*
|
143 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
144 |
+
* @version 0.3.5
|
145 |
+
* @package NostoCryptBase
|
146 |
+
*/
|
147 |
+
class NostoInvalidPaddingException extends Exception
|
148 |
+
{
|
149 |
+
}
|
150 |
+
|
151 |
+
/**
|
152 |
+
* Base Class for all Crypt* cipher classes
|
153 |
+
*
|
154 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
155 |
+
* @author Hans-Juergen Petrich <petrich@tronic-media.com>
|
156 |
+
* @version 1.0.0
|
157 |
+
* @package NostoCryptBase
|
158 |
+
*/
|
159 |
+
abstract class NostoCryptBase
|
160 |
+
{
|
161 |
+
/**
|
162 |
+
* The Encryption Mode
|
163 |
+
*
|
164 |
+
* @see NostoCryptBase::NostoCryptBase()
|
165 |
+
* @var Integer
|
166 |
+
*/
|
167 |
+
public $mode;
|
168 |
+
|
169 |
+
/**
|
170 |
+
* The Block Length of the block cipher
|
171 |
+
*
|
172 |
+
* @var Integer
|
173 |
+
*/
|
174 |
+
public $blockSize = 16;
|
175 |
+
|
176 |
+
/**
|
177 |
+
* The Key
|
178 |
+
*
|
179 |
+
* @see NostoCryptBase::setKey()
|
180 |
+
* @var String
|
181 |
+
*/
|
182 |
+
public $key = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
183 |
+
|
184 |
+
/**
|
185 |
+
* The Initialization Vector
|
186 |
+
*
|
187 |
+
* @see NostoCryptBase::setIV()
|
188 |
+
* @var String
|
189 |
+
*/
|
190 |
+
public $iv;
|
191 |
+
|
192 |
+
/**
|
193 |
+
* A "sliding" Initialization Vector
|
194 |
+
*
|
195 |
+
* @see NostoCryptBase::enableContinuousBuffer()
|
196 |
+
* @see NostoCryptBase::clearBuffers()
|
197 |
+
* @var String
|
198 |
+
*/
|
199 |
+
public $encryptIV;
|
200 |
+
|
201 |
+
/**
|
202 |
+
* A "sliding" Initialization Vector
|
203 |
+
*
|
204 |
+
* @see NostoCryptBase::enableContinuousBuffer()
|
205 |
+
* @see NostoCryptBase::clearBuffers()
|
206 |
+
* @var String
|
207 |
+
*/
|
208 |
+
public $decryptIV;
|
209 |
+
|
210 |
+
/**
|
211 |
+
* Continuous Buffer status
|
212 |
+
*
|
213 |
+
* @see NostoCryptBase::enableContinuousBuffer()
|
214 |
+
* @var Boolean
|
215 |
+
*/
|
216 |
+
public $continuousBuffer = false;
|
217 |
+
|
218 |
+
/**
|
219 |
+
* Encryption buffer for CTR, OFB and CFB modes
|
220 |
+
*
|
221 |
+
* @see NostoCryptBase::encrypt()
|
222 |
+
* @see NostoCryptBase::clearBuffers()
|
223 |
+
* @var Array
|
224 |
+
*/
|
225 |
+
public $enBuffer;
|
226 |
+
|
227 |
+
/**
|
228 |
+
* Decryption buffer for CTR, OFB and CFB modes
|
229 |
+
*
|
230 |
+
* @see NostoCryptBase::decrypt()
|
231 |
+
* @see NostoCryptBase::clearBuffers()
|
232 |
+
* @var Array
|
233 |
+
*/
|
234 |
+
public $deBuffer;
|
235 |
+
|
236 |
+
/**
|
237 |
+
* mcrypt resource for encryption
|
238 |
+
*
|
239 |
+
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
240 |
+
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
241 |
+
*
|
242 |
+
* @see NostoCryptBase::encrypt()
|
243 |
+
* @var Resource
|
244 |
+
*/
|
245 |
+
public $enMcrypt;
|
246 |
+
|
247 |
+
/**
|
248 |
+
* mcrypt resource for decryption
|
249 |
+
*
|
250 |
+
* The mcrypt resource can be recreated every time something needs to be created or it can be created just once.
|
251 |
+
* Since mcrypt operates in continuous mode, by default, it'll need to be recreated when in non-continuous mode.
|
252 |
+
*
|
253 |
+
* @see NostoCryptBase::decrypt()
|
254 |
+
* @var Resource
|
255 |
+
*/
|
256 |
+
public $deMcrypt;
|
257 |
+
|
258 |
+
/**
|
259 |
+
* Does the enMcrypt resource need to be (re)initialized?
|
260 |
+
*
|
261 |
+
* @see CryptTwofish::setKey()
|
262 |
+
* @see CryptTwofish::setIV()
|
263 |
+
* @var Boolean
|
264 |
+
*/
|
265 |
+
public $enChanged = true;
|
266 |
+
|
267 |
+
/**
|
268 |
+
* Does the deMcrypt resource need to be (re)initialized?
|
269 |
+
*
|
270 |
+
* @see CryptTwofish::setKey()
|
271 |
+
* @see CryptTwofish::setIV()
|
272 |
+
* @var Boolean
|
273 |
+
*/
|
274 |
+
public $deChanged = true;
|
275 |
+
|
276 |
+
/**
|
277 |
+
* mcrypt resource for CFB mode
|
278 |
+
*
|
279 |
+
* mcrypt's CFB mode, in (and only in) buffered context,
|
280 |
+
* is broken, so phpseclib implements the CFB mode by it self,
|
281 |
+
* even when the mcrypt php extension is available.
|
282 |
+
*
|
283 |
+
* In order to do the CFB-mode work (fast) phpseclib
|
284 |
+
* use a separate ECB-mode mcrypt resource.
|
285 |
+
*
|
286 |
+
* @link http://phpseclib.sourceforge.net/cfb-demo.phps
|
287 |
+
* @see NostoCryptBase::encrypt()
|
288 |
+
* @see NostoCryptBase::decrypt()
|
289 |
+
* @see NostoCryptBase::setupMcrypt()
|
290 |
+
* @var Resource
|
291 |
+
*/
|
292 |
+
public $ecb;
|
293 |
+
|
294 |
+
/**
|
295 |
+
* Optimizing value while CFB-encrypting
|
296 |
+
*
|
297 |
+
* Only relevant if $continuousBuffer enabled
|
298 |
+
* and $engine == CRYPT_MODE_MCRYPT
|
299 |
+
*
|
300 |
+
* It's faster to re-init $enMcrypt if
|
301 |
+
* $buffer bytes > $cfbInitLen than
|
302 |
+
* using the $ecb resource furthermore.
|
303 |
+
*
|
304 |
+
* This value depends of the chosen cipher
|
305 |
+
* and the time it would be needed for it's
|
306 |
+
* initialization [by mcrypt_generic_init()]
|
307 |
+
* which, typically, depends on the complexity
|
308 |
+
* on its internally Key-expanding algorithm.
|
309 |
+
*
|
310 |
+
* @see NostoCryptBase::encrypt()
|
311 |
+
* @var Integer
|
312 |
+
*/
|
313 |
+
public $cfbInitLen = 600;
|
314 |
+
|
315 |
+
/**
|
316 |
+
* Does internal cipher state need to be (re)initialized?
|
317 |
+
*
|
318 |
+
* @see setKey()
|
319 |
+
* @see setIV()
|
320 |
+
* @see disableContinuousBuffer()
|
321 |
+
* @var Boolean
|
322 |
+
*/
|
323 |
+
public $changed = true;
|
324 |
+
|
325 |
+
/**
|
326 |
+
* Padding status
|
327 |
+
*
|
328 |
+
* @see NostoCryptBase::enablePadding()
|
329 |
+
* @var Boolean
|
330 |
+
*/
|
331 |
+
public $padding = true;
|
332 |
+
|
333 |
+
/**
|
334 |
+
* Is the mode one that is paddable?
|
335 |
+
*
|
336 |
+
* @see NostoCryptBase::NostoCryptBase()
|
337 |
+
* @var Boolean
|
338 |
+
*/
|
339 |
+
public $paddable = false;
|
340 |
+
|
341 |
+
/**
|
342 |
+
* Holds which crypt engine internaly should be use,
|
343 |
+
* which will be determined automatically on __construct()
|
344 |
+
*
|
345 |
+
* Currently available $engines are:
|
346 |
+
* - CRYPT_MODE_MCRYPT (fast, php-extension: mcrypt, extension_loaded('mcrypt') required)
|
347 |
+
* - CRYPT_MODE_INTERNAL (slower, pure php-engine, no php-extension required)
|
348 |
+
*
|
349 |
+
* In the pipeline... maybe. But currently not available:
|
350 |
+
* - CRYPT_MODE_OPENSSL (very fast, php-extension: openssl, extension_loaded('openssl') required)
|
351 |
+
*
|
352 |
+
* If possible, CRYPT_MODE_MCRYPT will be used for each cipher.
|
353 |
+
* Otherwise CRYPT_MODE_INTERNAL
|
354 |
+
*
|
355 |
+
* @see NostoCryptBase::encrypt()
|
356 |
+
* @see NostoCryptBase::decrypt()
|
357 |
+
* @var Integer
|
358 |
+
*/
|
359 |
+
public $engine;
|
360 |
+
|
361 |
+
/**
|
362 |
+
* The mcrypt specific name of the cipher
|
363 |
+
*
|
364 |
+
* Only used if $engine == CRYPT_MODE_MCRYPT
|
365 |
+
*
|
366 |
+
* @link http://www.php.net/mcrypt_module_open
|
367 |
+
* @link http://www.php.net/mcrypt_list_algorithms
|
368 |
+
* @see NostoCryptBase::setupMcrypt()
|
369 |
+
* @var String
|
370 |
+
*/
|
371 |
+
public $cipherNameMcrypt;
|
372 |
+
|
373 |
+
/**
|
374 |
+
* The default password keySize used by setPassword()
|
375 |
+
*
|
376 |
+
* @see NostoCryptBase::setPassword()
|
377 |
+
* @var Integer
|
378 |
+
*/
|
379 |
+
public $passwordKeySize = 32;
|
380 |
+
|
381 |
+
/**
|
382 |
+
* The default salt used by setPassword()
|
383 |
+
*
|
384 |
+
* @see NostoCryptBase::setPassword()
|
385 |
+
* @var String
|
386 |
+
*/
|
387 |
+
public $passwordDefaultSalt = 'phpseclib/salt';
|
388 |
+
|
389 |
+
/**
|
390 |
+
* The namespace used by the cipher for its constants.
|
391 |
+
*
|
392 |
+
* ie: AES.php is using CRYPT_AES_MODE_* for its constants
|
393 |
+
* so $constNamespace is AES
|
394 |
+
*
|
395 |
+
* DES.php is using CRYPT_DES_MODE_* for its constants
|
396 |
+
* so $constNamespace is DES... and so on
|
397 |
+
*
|
398 |
+
* All CRYPT_<$constNamespace>_MODE_* are aliases of
|
399 |
+
* the generic CRYPT_MODE_* constants, so both could be used
|
400 |
+
* for each cipher.
|
401 |
+
*
|
402 |
+
* Example:
|
403 |
+
* $aes = new CryptAES(CRYPT_AES_MODE_CFB); // $aes will operate in cfb mode
|
404 |
+
* $aes = new CryptAES(CRYPT_MODE_CFB); // identical
|
405 |
+
*
|
406 |
+
* @see NostoCryptBase::NostoCryptBase()
|
407 |
+
* @var String
|
408 |
+
*/
|
409 |
+
public $constNamespace;
|
410 |
+
|
411 |
+
/**
|
412 |
+
* The name of the performance-optimized callback function
|
413 |
+
*
|
414 |
+
* Used by encrypt() / decrypt()
|
415 |
+
* only if $engine == CRYPT_MODE_INTERNAL
|
416 |
+
*
|
417 |
+
* @see NostoCryptBase::encrypt()
|
418 |
+
* @see NostoCryptBase::decrypt()
|
419 |
+
* @see NostoCryptBase::setupInlineCrypt()
|
420 |
+
* @see useInlineCrypt::$use_inline_crypt
|
421 |
+
* @var Callback
|
422 |
+
*/
|
423 |
+
public $inlineCrypt;
|
424 |
+
|
425 |
+
/**
|
426 |
+
* Holds whether performance-optimized $inlineCrypt() can/should be used.
|
427 |
+
*
|
428 |
+
* @see NostoCryptBase::encrypt()
|
429 |
+
* @see NostoCryptBase::decrypt()
|
430 |
+
* @see NostoCryptBase::inlineCrypt
|
431 |
+
* @var mixed
|
432 |
+
*/
|
433 |
+
public $useInlineCrypt;
|
434 |
+
|
435 |
+
/**
|
436 |
+
* Default Constructor.
|
437 |
+
*
|
438 |
+
* Determines whether or not the mcrypt extension should be used.
|
439 |
+
*
|
440 |
+
* $mode could be:
|
441 |
+
*
|
442 |
+
* - CRYPT_MODE_ECB
|
443 |
+
*
|
444 |
+
* - CRYPT_MODE_CBC
|
445 |
+
*
|
446 |
+
* - CRYPT_MODE_CTR
|
447 |
+
*
|
448 |
+
* - CRYPT_MODE_CFB
|
449 |
+
*
|
450 |
+
* - CRYPT_MODE_OFB
|
451 |
+
*
|
452 |
+
* (or the alias constants of the chosen cipher, for example for AES: CRYPT_AES_MODE_ECB or CRYPT_AES_MODE_CBC ...)
|
453 |
+
*
|
454 |
+
* If not explicitly set, CRYPT_MODE_CBC will be used.
|
455 |
+
*
|
456 |
+
* @param optional Integer $mode
|
457 |
+
*/
|
458 |
+
public function __construct($mode = CRYPT_MODE_CBC)
|
459 |
+
{
|
460 |
+
$constCryptMode = 'CRYPT_'.$this->constNamespace.'_MODE';
|
461 |
+
|
462 |
+
// Determining the availability of mcrypt support for the cipher
|
463 |
+
if (!defined($constCryptMode)) {
|
464 |
+
switch (true) {
|
465 |
+
case extension_loaded('mcrypt') && in_array($this->cipherNameMcrypt, mcrypt_list_algorithms()):
|
466 |
+
define($constCryptMode, CRYPT_MODE_MCRYPT);
|
467 |
+
break;
|
468 |
+
default:
|
469 |
+
define($constCryptMode, CRYPT_MODE_INTERNAL);
|
470 |
+
}
|
471 |
+
}
|
472 |
+
|
473 |
+
// Determining which internal $engine should be used.
|
474 |
+
// The fastest possible first.
|
475 |
+
switch (true) {
|
476 |
+
// The cipher module has no mcrypt-engine support at all so we force CRYPT_MODE_INTERNAL
|
477 |
+
case empty($this->cipherNameMcrypt):
|
478 |
+
$this->engine = CRYPT_MODE_INTERNAL;
|
479 |
+
break;
|
480 |
+
case constant($constCryptMode) == CRYPT_MODE_MCRYPT:
|
481 |
+
$this->engine = CRYPT_MODE_MCRYPT;
|
482 |
+
break;
|
483 |
+
default:
|
484 |
+
$this->engine = CRYPT_MODE_INTERNAL;
|
485 |
+
}
|
486 |
+
|
487 |
+
// $mode dependent settings
|
488 |
+
switch ($mode) {
|
489 |
+
case CRYPT_MODE_ECB:
|
490 |
+
$this->paddable = true;
|
491 |
+
$this->mode = $mode;
|
492 |
+
break;
|
493 |
+
case CRYPT_MODE_CTR:
|
494 |
+
case CRYPT_MODE_CFB:
|
495 |
+
case CRYPT_MODE_OFB:
|
496 |
+
case CRYPT_MODE_STREAM:
|
497 |
+
$this->mode = $mode;
|
498 |
+
break;
|
499 |
+
case CRYPT_MODE_CBC:
|
500 |
+
default:
|
501 |
+
$this->paddable = true;
|
502 |
+
$this->mode = CRYPT_MODE_CBC;
|
503 |
+
}
|
504 |
+
|
505 |
+
// Determining whether inline encrypting can be used by the cipher
|
506 |
+
if ($this->useInlineCrypt !== false && function_exists('create_function')) {
|
507 |
+
$this->useInlineCrypt = true;
|
508 |
+
}
|
509 |
+
}
|
510 |
+
|
511 |
+
/**
|
512 |
+
* Sets the initialization vector. (optional)
|
513 |
+
*
|
514 |
+
* SetIV is not required when CRYPT_MODE_ECB (or ie for AES: CRYPT_AES_MODE_ECB) is being used.
|
515 |
+
* If not explicitly set, it'll be assumed to be all zero's.
|
516 |
+
*
|
517 |
+
* Note: Could, but not must, extend by the child Crypt* class
|
518 |
+
*
|
519 |
+
* @param String $iv
|
520 |
+
*/
|
521 |
+
public function setIV($iv)
|
522 |
+
{
|
523 |
+
if ($this->mode == CRYPT_MODE_ECB) {
|
524 |
+
return;
|
525 |
+
}
|
526 |
+
|
527 |
+
$this->iv = $iv;
|
528 |
+
$this->changed = true;
|
529 |
+
}
|
530 |
+
|
531 |
+
/**
|
532 |
+
* Gets the initialization vector.
|
533 |
+
*
|
534 |
+
* @return String
|
535 |
+
*/
|
536 |
+
public function getIV()
|
537 |
+
{
|
538 |
+
return $this->iv;
|
539 |
+
}
|
540 |
+
|
541 |
+
/**
|
542 |
+
* Sets the key.
|
543 |
+
*
|
544 |
+
* The min/max length(s) of the key depends on the cipher which is used.
|
545 |
+
* If the key not fits the length(s) of the cipher it will padded with null bytes
|
546 |
+
* up to the closest valid key length. If the key is more than max length,
|
547 |
+
* we trim the excess bits.
|
548 |
+
*
|
549 |
+
* If the key is not explicitly set, it'll be assumed to be all null bytes.
|
550 |
+
*
|
551 |
+
* Note: Could, but not must, extend by the child Crypt* class
|
552 |
+
*
|
553 |
+
* @param String $key
|
554 |
+
*/
|
555 |
+
public function setKey($key)
|
556 |
+
{
|
557 |
+
$this->key = $key;
|
558 |
+
$this->changed = true;
|
559 |
+
}
|
560 |
+
|
561 |
+
/**
|
562 |
+
* Sets the password.
|
563 |
+
*
|
564 |
+
* Depending on what $method is set to, setPassword()'s (optional) parameters are as follows:
|
565 |
+
* {@link http://en.wikipedia.org/wiki/PBKDF2 pbkdf2}:
|
566 |
+
* $hash, $salt, $count, $dk_len
|
567 |
+
*
|
568 |
+
* Where $hash (default = sha1) currently supports the following hashes: see: Crypt/Hash.php
|
569 |
+
*
|
570 |
+
* Note: Could, but not must, extend by the child Crypt* class
|
571 |
+
*
|
572 |
+
* @see Crypt/Hash.php
|
573 |
+
* @param String $password
|
574 |
+
* @param optional String $method
|
575 |
+
*/
|
576 |
+
public function setPassword($password, $method = 'pbkdf2')
|
577 |
+
{
|
578 |
+
// DISABLED DUE TO MISSING "CryptHash" METHOD (WE ARE NOT USING THIS ANYWAYS)
|
579 |
+
// $key = '';
|
580 |
+
//
|
581 |
+
// switch ($method)
|
582 |
+
// {
|
583 |
+
// default: // 'pbkdf2'
|
584 |
+
// $func_args = func_get_args();
|
585 |
+
//
|
586 |
+
// // Hash function
|
587 |
+
// $hash = isset($func_args[2]) ? $func_args[2] : 'sha1';
|
588 |
+
//
|
589 |
+
// // WPA and WPA2 use the SSID as the salt
|
590 |
+
// $salt = isset($func_args[3]) ? $func_args[3] : $this->passwordDefaultSalt;
|
591 |
+
//
|
592 |
+
// // RFC2898#section-4.2 uses 1,000 iterations by default
|
593 |
+
// // WPA and WPA2 use 4,096.
|
594 |
+
// $count = isset($func_args[4]) ? $func_args[4] : 1000;
|
595 |
+
//
|
596 |
+
// // Key length
|
597 |
+
// $dk_len = isset($func_args[5]) ? $func_args[5] : $this->passwordKeySize;
|
598 |
+
//
|
599 |
+
// // Determining if php[>=5.5.0]'s hash_pbkdf2() function avail- and usable
|
600 |
+
// switch (true)
|
601 |
+
// {
|
602 |
+
// case !function_exists('hash_pbkdf2'):
|
603 |
+
// case !function_exists('hash_algos'):
|
604 |
+
// case !in_array($hash, hash_algos()):
|
605 |
+
// $i = 1;
|
606 |
+
// $key_len = strlen($key);
|
607 |
+
// while ($key_len < $dk_len)
|
608 |
+
// {
|
609 |
+
// $hmac = new CryptHash();
|
610 |
+
// $hmac->setHash($hash);
|
611 |
+
// $hmac->setKey($password);
|
612 |
+
// $f = $u = $hmac->hash($salt.pack('N', $i++));
|
613 |
+
// for ($j = 2; $j <= $count; ++$j)
|
614 |
+
// {
|
615 |
+
// $u = $hmac->hash($u);
|
616 |
+
// $f ^= $u;
|
617 |
+
// }
|
618 |
+
// $key .= $f;
|
619 |
+
// $key_len = strlen($key);
|
620 |
+
// }
|
621 |
+
// $key = substr($key, 0, $dk_len);
|
622 |
+
// break;
|
623 |
+
// default:
|
624 |
+
// $key = hash_pbkdf2($hash, $password, $salt, $count, $dk_len, true);
|
625 |
+
// }
|
626 |
+
// }
|
627 |
+
//
|
628 |
+
// $this->setKey($key);
|
629 |
+
}
|
630 |
+
|
631 |
+
/**
|
632 |
+
* Encrypts a message.
|
633 |
+
*
|
634 |
+
* $plaintext will be padded with additional bytes such that it's length is a multiple of the block size. Other
|
635 |
+
* cipher implementations may or may not pad in the same manner. Other common approaches to padding and the reasons
|
636 |
+
* why it's necessary are discussed in the following
|
637 |
+
* URL:
|
638 |
+
*
|
639 |
+
* {@link http://www.di-mgt.com.au/cryptopad.html http://www.di-mgt.com.au/cryptopad.html}
|
640 |
+
*
|
641 |
+
* An alternative to padding is to, separately, send the length of the file. This is what SSH, in fact, does.
|
642 |
+
* strlen($plaintext) will still need to be a multiple of the block size, however, arbitrary values can be added to
|
643 |
+
* make it that length.
|
644 |
+
*
|
645 |
+
* Note: Could, but not must, extend by the child Crypt* class
|
646 |
+
*
|
647 |
+
* @see NostoCryptBase::decrypt()
|
648 |
+
* @param String $plaintext
|
649 |
+
* @return String $ciphertext
|
650 |
+
*/
|
651 |
+
public function encrypt($plaintext)
|
652 |
+
{
|
653 |
+
if ($this->engine == CRYPT_MODE_MCRYPT) {
|
654 |
+
if ($this->changed) {
|
655 |
+
$this->setupMcrypt();
|
656 |
+
$this->changed = false;
|
657 |
+
}
|
658 |
+
if ($this->enChanged) {
|
659 |
+
mcrypt_generic_init($this->enMcrypt, $this->key, $this->encryptIV);
|
660 |
+
$this->enChanged = false;
|
661 |
+
}
|
662 |
+
|
663 |
+
// re: {@link http://phpseclib.sourceforge.net/cfb-demo.phps}
|
664 |
+
// using mcrypt's default handing of CFB the above would output two different things. using phpseclib's
|
665 |
+
// rewritten CFB implementation the above outputs the same thing twice.
|
666 |
+
if ($this->mode == CRYPT_MODE_CFB && $this->continuousBuffer) {
|
667 |
+
$blockSize = $this->blockSize;
|
668 |
+
$iv = & $this->encryptIV;
|
669 |
+
$pos = & $this->enBuffer['pos'];
|
670 |
+
$len = strlen($plaintext);
|
671 |
+
$ciphertext = '';
|
672 |
+
$i = 0;
|
673 |
+
if ($pos) {
|
674 |
+
$origPos = $pos;
|
675 |
+
$max = $blockSize - $pos;
|
676 |
+
if ($len >= $max) {
|
677 |
+
$i = $max;
|
678 |
+
$len -= $max;
|
679 |
+
$pos = 0;
|
680 |
+
} else {
|
681 |
+
$i = $len;
|
682 |
+
$pos += $len;
|
683 |
+
$len = 0;
|
684 |
+
}
|
685 |
+
$ciphertext = substr($iv, $origPos) ^ $plaintext;
|
686 |
+
$iv = substr_replace($iv, $ciphertext, $origPos, $i);
|
687 |
+
$this->enBuffer['enmcrypt_init'] = true;
|
688 |
+
}
|
689 |
+
if ($len >= $blockSize) {
|
690 |
+
if ($this->enBuffer['enmcrypt_init'] === false || $len > $this->cfbInitLen) {
|
691 |
+
if ($this->enBuffer['enmcrypt_init'] === true) {
|
692 |
+
mcrypt_generic_init($this->enMcrypt, $this->key, $iv);
|
693 |
+
$this->enBuffer['enmcrypt_init'] = false;
|
694 |
+
}
|
695 |
+
$ciphertext .= mcrypt_generic(
|
696 |
+
$this->enMcrypt,
|
697 |
+
substr($plaintext, $i, $len - $len % $blockSize)
|
698 |
+
);
|
699 |
+
$iv = substr($ciphertext, -$blockSize);
|
700 |
+
$len %= $blockSize;
|
701 |
+
} else {
|
702 |
+
while ($len >= $blockSize) {
|
703 |
+
$iv = mcrypt_generic($this->ecb, $iv) ^ substr($plaintext, $i, $blockSize);
|
704 |
+
$ciphertext .= $iv;
|
705 |
+
$len -= $blockSize;
|
706 |
+
$i += $blockSize;
|
707 |
+
}
|
708 |
+
}
|
709 |
+
}
|
710 |
+
|
711 |
+
if ($len) {
|
712 |
+
$iv = mcrypt_generic($this->ecb, $iv);
|
713 |
+
$block = $iv ^ substr($plaintext, -$len);
|
714 |
+
$iv = substr_replace($iv, $block, 0, $len);
|
715 |
+
$ciphertext .= $block;
|
716 |
+
$pos = $len;
|
717 |
+
}
|
718 |
+
return $ciphertext;
|
719 |
+
}
|
720 |
+
|
721 |
+
if ($this->paddable) {
|
722 |
+
$plaintext = $this->pad($plaintext);
|
723 |
+
}
|
724 |
+
|
725 |
+
$ciphertext = mcrypt_generic($this->enMcrypt, $plaintext);
|
726 |
+
|
727 |
+
if (!$this->continuousBuffer) {
|
728 |
+
mcrypt_generic_init($this->enMcrypt, $this->key, $this->encryptIV);
|
729 |
+
}
|
730 |
+
|
731 |
+
return $ciphertext;
|
732 |
+
}
|
733 |
+
|
734 |
+
if ($this->changed) {
|
735 |
+
$this->setup();
|
736 |
+
$this->changed = false;
|
737 |
+
}
|
738 |
+
if ($this->useInlineCrypt) {
|
739 |
+
$inline = $this->inlineCrypt;
|
740 |
+
return $inline('encrypt', $this, $plaintext);
|
741 |
+
}
|
742 |
+
if ($this->paddable) {
|
743 |
+
$plaintext = $this->pad($plaintext);
|
744 |
+
}
|
745 |
+
|
746 |
+
$buffer = & $this->enBuffer;
|
747 |
+
$blockSize = $this->blockSize;
|
748 |
+
$ciphertext = '';
|
749 |
+
$plaintext_len = strlen($plaintext);
|
750 |
+
switch ($this->mode) {
|
751 |
+
case CRYPT_MODE_ECB:
|
752 |
+
for ($i = 0; $i < $plaintext_len; $i += $blockSize) {
|
753 |
+
$ciphertext .= $this->encryptBlock(substr($plaintext, $i, $blockSize));
|
754 |
+
}
|
755 |
+
break;
|
756 |
+
case CRYPT_MODE_CBC:
|
757 |
+
$xor = $this->encryptIV;
|
758 |
+
for ($i = 0; $i < $plaintext_len; $i += $blockSize) {
|
759 |
+
$block = substr($plaintext, $i, $blockSize);
|
760 |
+
$block = $this->encryptBlock($block ^ $xor);
|
761 |
+
$xor = $block;
|
762 |
+
$ciphertext .= $block;
|
763 |
+
}
|
764 |
+
if ($this->continuousBuffer) {
|
765 |
+
$this->encryptIV = $xor;
|
766 |
+
}
|
767 |
+
break;
|
768 |
+
case CRYPT_MODE_CTR:
|
769 |
+
$xor = $this->encryptIV;
|
770 |
+
$key = '';
|
771 |
+
if (strlen($buffer['encrypted'])) {
|
772 |
+
for ($i = 0; $i < $plaintext_len; $i += $blockSize) {
|
773 |
+
$block = substr($plaintext, $i, $blockSize);
|
774 |
+
if (strlen($block) > strlen($buffer['encrypted'])) {
|
775 |
+
$buffer['encrypted'] .= $this->encryptBlock($this->generateXor($xor, $blockSize));
|
776 |
+
}
|
777 |
+
$key = $this->stringShift($buffer['encrypted'], $blockSize);
|
778 |
+
$ciphertext .= $block ^ $key;
|
779 |
+
}
|
780 |
+
} else {
|
781 |
+
for ($i = 0; $i < $plaintext_len; $i += $blockSize) {
|
782 |
+
$block = substr($plaintext, $i, $blockSize);
|
783 |
+
$key = $this->encryptBlock($this->generateXor($xor, $blockSize));
|
784 |
+
$ciphertext .= $block ^ $key;
|
785 |
+
}
|
786 |
+
}
|
787 |
+
if ($this->continuousBuffer) {
|
788 |
+
$this->encryptIV = $xor;
|
789 |
+
if ($start = strlen($plaintext) % $blockSize) {
|
790 |
+
$buffer['encrypted'] = substr($key, $start).$buffer['encrypted'];
|
791 |
+
}
|
792 |
+
}
|
793 |
+
break;
|
794 |
+
case CRYPT_MODE_CFB:
|
795 |
+
// cfb loosely routines inspired by openssl's:
|
796 |
+
// {@link http://cvs.openssl.org/fileview?f=openssl/crypto/modes/cfb128.c&v=1.3.2.2.2.1}
|
797 |
+
if ($this->continuousBuffer) {
|
798 |
+
$iv = & $this->encryptIV;
|
799 |
+
$pos = & $buffer['pos'];
|
800 |
+
} else {
|
801 |
+
$iv = $this->encryptIV;
|
802 |
+
$pos = 0;
|
803 |
+
}
|
804 |
+
$len = strlen($plaintext);
|
805 |
+
$i = 0;
|
806 |
+
if ($pos) {
|
807 |
+
$origPos = $pos;
|
808 |
+
$max = $blockSize - $pos;
|
809 |
+
if ($len >= $max) {
|
810 |
+
$i = $max;
|
811 |
+
$len -= $max;
|
812 |
+
$pos = 0;
|
813 |
+
} else {
|
814 |
+
$i = $len;
|
815 |
+
$pos += $len;
|
816 |
+
$len = 0;
|
817 |
+
}
|
818 |
+
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
|
819 |
+
$ciphertext = substr($iv, $origPos) ^ $plaintext;
|
820 |
+
$iv = substr_replace($iv, $ciphertext, $origPos, $i);
|
821 |
+
}
|
822 |
+
while ($len >= $blockSize) {
|
823 |
+
$iv = $this->encryptBlock($iv) ^ substr($plaintext, $i, $blockSize);
|
824 |
+
$ciphertext .= $iv;
|
825 |
+
$len -= $blockSize;
|
826 |
+
$i += $blockSize;
|
827 |
+
}
|
828 |
+
if ($len) {
|
829 |
+
$iv = $this->encryptBlock($iv);
|
830 |
+
$block = $iv ^ substr($plaintext, $i);
|
831 |
+
$iv = substr_replace($iv, $block, 0, $len);
|
832 |
+
$ciphertext .= $block;
|
833 |
+
$pos = $len;
|
834 |
+
}
|
835 |
+
break;
|
836 |
+
case CRYPT_MODE_OFB:
|
837 |
+
$xor = $this->encryptIV;
|
838 |
+
$key = '';
|
839 |
+
if (strlen($buffer['xor'])) {
|
840 |
+
for ($i = 0; $i < $plaintext_len; $i += $blockSize) {
|
841 |
+
$block = substr($plaintext, $i, $blockSize);
|
842 |
+
if (strlen($block) > strlen($buffer['xor'])) {
|
843 |
+
$xor = $this->encryptBlock($xor);
|
844 |
+
$buffer['xor'] .= $xor;
|
845 |
+
}
|
846 |
+
$key = $this->stringShift($buffer['xor'], $blockSize);
|
847 |
+
$ciphertext .= $block ^ $key;
|
848 |
+
}
|
849 |
+
} else {
|
850 |
+
for ($i = 0; $i < $plaintext_len; $i += $blockSize) {
|
851 |
+
$xor = $this->encryptBlock($xor);
|
852 |
+
$ciphertext .= substr($plaintext, $i, $blockSize) ^ $xor;
|
853 |
+
}
|
854 |
+
$key = $xor;
|
855 |
+
}
|
856 |
+
if ($this->continuousBuffer) {
|
857 |
+
$this->encryptIV = $xor;
|
858 |
+
if ($start = strlen($plaintext) % $blockSize) {
|
859 |
+
$buffer['xor'] = substr($key, $start).$buffer['xor'];
|
860 |
+
}
|
861 |
+
}
|
862 |
+
break;
|
863 |
+
case CRYPT_MODE_STREAM:
|
864 |
+
$ciphertext = $this->encryptBlock($plaintext);
|
865 |
+
break;
|
866 |
+
}
|
867 |
+
|
868 |
+
return $ciphertext;
|
869 |
+
}
|
870 |
+
|
871 |
+
/**
|
872 |
+
* Decrypts a message.
|
873 |
+
*
|
874 |
+
* If strlen($ciphertext) is not a multiple of the block size, null bytes will be added to the end of the string
|
875 |
+
* until it is.
|
876 |
+
*
|
877 |
+
* Note: Could, but not must, extend by the child Crypt* class
|
878 |
+
*
|
879 |
+
* @see NostoCryptBase::encrypt()
|
880 |
+
* @param String $ciphertext
|
881 |
+
* @return String $plaintext
|
882 |
+
*/
|
883 |
+
public function decrypt($ciphertext)
|
884 |
+
{
|
885 |
+
if ($this->engine == CRYPT_MODE_MCRYPT) {
|
886 |
+
$block_size = $this->blockSize;
|
887 |
+
if ($this->changed) {
|
888 |
+
$this->setupMcrypt();
|
889 |
+
$this->changed = false;
|
890 |
+
}
|
891 |
+
if ($this->deChanged) {
|
892 |
+
mcrypt_generic_init($this->deMcrypt, $this->key, $this->decryptIV);
|
893 |
+
$this->deChanged = false;
|
894 |
+
}
|
895 |
+
|
896 |
+
if ($this->mode == CRYPT_MODE_CFB && $this->continuousBuffer) {
|
897 |
+
$iv = & $this->decryptIV;
|
898 |
+
$pos = & $this->deBuffer['pos'];
|
899 |
+
$len = strlen($ciphertext);
|
900 |
+
$plaintext = '';
|
901 |
+
$i = 0;
|
902 |
+
if ($pos) {
|
903 |
+
$orig_pos = $pos;
|
904 |
+
$max = $block_size - $pos;
|
905 |
+
if ($len >= $max) {
|
906 |
+
$i = $max;
|
907 |
+
$len -= $max;
|
908 |
+
$pos = 0;
|
909 |
+
} else {
|
910 |
+
$i = $len;
|
911 |
+
$pos += $len;
|
912 |
+
$len = 0;
|
913 |
+
}
|
914 |
+
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
|
915 |
+
$plaintext = substr($iv, $orig_pos) ^ $ciphertext;
|
916 |
+
$iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i);
|
917 |
+
}
|
918 |
+
if ($len >= $block_size) {
|
919 |
+
$cb = substr($ciphertext, $i, $len - $len % $block_size);
|
920 |
+
$plaintext .= mcrypt_generic($this->ecb, $iv.$cb) ^ $cb;
|
921 |
+
$iv = substr($cb, -$block_size);
|
922 |
+
$len %= $block_size;
|
923 |
+
}
|
924 |
+
if ($len) {
|
925 |
+
$iv = mcrypt_generic($this->ecb, $iv);
|
926 |
+
$plaintext .= $iv ^ substr($ciphertext, -$len);
|
927 |
+
$iv = substr_replace($iv, substr($ciphertext, -$len), 0, $len);
|
928 |
+
$pos = $len;
|
929 |
+
}
|
930 |
+
|
931 |
+
return $plaintext;
|
932 |
+
}
|
933 |
+
|
934 |
+
if ($this->paddable) {
|
935 |
+
// we pad with chr(0) since that's what mcrypt_generic does. to quote from
|
936 |
+
// {@link http://www.php.net/function.mcrypt-generic}:
|
937 |
+
// "The data is padded with "\0" to make sure the length of the data is n * blocksize."
|
938 |
+
$ciphertext = str_pad(
|
939 |
+
$ciphertext,
|
940 |
+
strlen($ciphertext) + ($block_size - strlen($ciphertext) % $block_size) % $block_size,
|
941 |
+
chr(0)
|
942 |
+
);
|
943 |
+
}
|
944 |
+
|
945 |
+
$plaintext = mdecrypt_generic($this->deMcrypt, $ciphertext);
|
946 |
+
|
947 |
+
if (!$this->continuousBuffer) {
|
948 |
+
mcrypt_generic_init($this->deMcrypt, $this->key, $this->decryptIV);
|
949 |
+
}
|
950 |
+
|
951 |
+
return $this->paddable ? $this->unpad($plaintext) : $plaintext;
|
952 |
+
}
|
953 |
+
|
954 |
+
if ($this->changed) {
|
955 |
+
$this->setup();
|
956 |
+
$this->changed = false;
|
957 |
+
}
|
958 |
+
if ($this->useInlineCrypt) {
|
959 |
+
$inline = $this->inlineCrypt;
|
960 |
+
return $inline('decrypt', $this, $ciphertext);
|
961 |
+
}
|
962 |
+
|
963 |
+
$block_size = $this->blockSize;
|
964 |
+
if ($this->paddable) {
|
965 |
+
// we pad with chr(0) since that's what mcrypt_generic does [...]
|
966 |
+
$ciphertext = str_pad(
|
967 |
+
$ciphertext,
|
968 |
+
strlen($ciphertext) + ($block_size - strlen($ciphertext) % $block_size) % $block_size,
|
969 |
+
chr(0)
|
970 |
+
);
|
971 |
+
}
|
972 |
+
|
973 |
+
$buffer = & $this->deBuffer;
|
974 |
+
$plaintext = '';
|
975 |
+
$cipher_text_len = strlen($ciphertext);
|
976 |
+
switch ($this->mode) {
|
977 |
+
case CRYPT_MODE_ECB:
|
978 |
+
for ($i = 0; $i < $cipher_text_len; $i += $block_size) {
|
979 |
+
$plaintext .= $this->decryptBlock(substr($ciphertext, $i, $block_size));
|
980 |
+
}
|
981 |
+
break;
|
982 |
+
case CRYPT_MODE_CBC:
|
983 |
+
$xor = $this->decryptIV;
|
984 |
+
for ($i = 0; $i < $cipher_text_len; $i += $block_size) {
|
985 |
+
$block = substr($ciphertext, $i, $block_size);
|
986 |
+
$plaintext .= $this->decryptBlock($block) ^ $xor;
|
987 |
+
$xor = $block;
|
988 |
+
}
|
989 |
+
if ($this->continuousBuffer) {
|
990 |
+
$this->decryptIV = $xor;
|
991 |
+
}
|
992 |
+
break;
|
993 |
+
case CRYPT_MODE_CTR:
|
994 |
+
$xor = $this->decryptIV;
|
995 |
+
$key = '';
|
996 |
+
if (strlen($buffer['ciphertext'])) {
|
997 |
+
for ($i = 0; $i < $cipher_text_len; $i += $block_size) {
|
998 |
+
$block = substr($ciphertext, $i, $block_size);
|
999 |
+
if (strlen($block) > strlen($buffer['ciphertext'])) {
|
1000 |
+
$buffer['ciphertext'] .= $this->encryptBlock($this->generateXor($xor, $block_size));
|
1001 |
+
}
|
1002 |
+
$key = $this->stringShift($buffer['ciphertext'], $block_size);
|
1003 |
+
$plaintext .= $block ^ $key;
|
1004 |
+
}
|
1005 |
+
} else {
|
1006 |
+
for ($i = 0; $i < $cipher_text_len; $i += $block_size) {
|
1007 |
+
$block = substr($ciphertext, $i, $block_size);
|
1008 |
+
$key = $this->encryptBlock($this->generateXor($xor, $block_size));
|
1009 |
+
$plaintext .= $block ^ $key;
|
1010 |
+
}
|
1011 |
+
}
|
1012 |
+
if ($this->continuousBuffer) {
|
1013 |
+
$this->decryptIV = $xor;
|
1014 |
+
if ($start = strlen($ciphertext) % $block_size) {
|
1015 |
+
$buffer['ciphertext'] = substr($key, $start).$buffer['ciphertext'];
|
1016 |
+
}
|
1017 |
+
}
|
1018 |
+
break;
|
1019 |
+
case CRYPT_MODE_CFB:
|
1020 |
+
if ($this->continuousBuffer) {
|
1021 |
+
$iv = & $this->decryptIV;
|
1022 |
+
$pos = & $buffer['pos'];
|
1023 |
+
} else {
|
1024 |
+
$iv = $this->decryptIV;
|
1025 |
+
$pos = 0;
|
1026 |
+
}
|
1027 |
+
$len = strlen($ciphertext);
|
1028 |
+
$i = 0;
|
1029 |
+
if ($pos) {
|
1030 |
+
$orig_pos = $pos;
|
1031 |
+
$max = $block_size - $pos;
|
1032 |
+
if ($len >= $max) {
|
1033 |
+
$i = $max;
|
1034 |
+
$len -= $max;
|
1035 |
+
$pos = 0;
|
1036 |
+
} else {
|
1037 |
+
$i = $len;
|
1038 |
+
$pos += $len;
|
1039 |
+
$len = 0;
|
1040 |
+
}
|
1041 |
+
// ie. $i = min($max, $len), $len-= $i, $pos+= $i, $pos%= $blocksize
|
1042 |
+
$plaintext = substr($iv, $orig_pos) ^ $ciphertext;
|
1043 |
+
$iv = substr_replace($iv, substr($ciphertext, 0, $i), $orig_pos, $i);
|
1044 |
+
}
|
1045 |
+
while ($len >= $block_size) {
|
1046 |
+
$iv = $this->encryptBlock($iv);
|
1047 |
+
$cb = substr($ciphertext, $i, $block_size);
|
1048 |
+
$plaintext .= $iv ^ $cb;
|
1049 |
+
$iv = $cb;
|
1050 |
+
$len -= $block_size;
|
1051 |
+
$i += $block_size;
|
1052 |
+
}
|
1053 |
+
if ($len) {
|
1054 |
+
$iv = $this->encryptBlock($iv);
|
1055 |
+
$plaintext .= $iv ^ substr($ciphertext, $i);
|
1056 |
+
$iv = substr_replace($iv, substr($ciphertext, $i), 0, $len);
|
1057 |
+
$pos = $len;
|
1058 |
+
}
|
1059 |
+
break;
|
1060 |
+
case CRYPT_MODE_OFB:
|
1061 |
+
$xor = $this->decryptIV;
|
1062 |
+
$key = '';
|
1063 |
+
if (strlen($buffer['xor'])) {
|
1064 |
+
for ($i = 0; $i < $cipher_text_len; $i += $block_size) {
|
1065 |
+
$block = substr($ciphertext, $i, $block_size);
|
1066 |
+
if (strlen($block) > strlen($buffer['xor'])) {
|
1067 |
+
$xor = $this->encryptBlock($xor);
|
1068 |
+
$buffer['xor'] .= $xor;
|
1069 |
+
}
|
1070 |
+
$key = $this->stringShift($buffer['xor'], $block_size);
|
1071 |
+
$plaintext .= $block ^ $key;
|
1072 |
+
}
|
1073 |
+
} else {
|
1074 |
+
for ($i = 0; $i < $cipher_text_len; $i += $block_size) {
|
1075 |
+
$xor = $this->encryptBlock($xor);
|
1076 |
+
$plaintext .= substr($ciphertext, $i, $block_size) ^ $xor;
|
1077 |
+
}
|
1078 |
+
$key = $xor;
|
1079 |
+
}
|
1080 |
+
if ($this->continuousBuffer) {
|
1081 |
+
$this->decryptIV = $xor;
|
1082 |
+
if ($start = strlen($ciphertext) % $block_size) {
|
1083 |
+
$buffer['xor'] = substr($key, $start).$buffer['xor'];
|
1084 |
+
}
|
1085 |
+
}
|
1086 |
+
break;
|
1087 |
+
case CRYPT_MODE_STREAM:
|
1088 |
+
$plaintext = $this->decryptBlock($ciphertext);
|
1089 |
+
break;
|
1090 |
+
}
|
1091 |
+
return $this->paddable ? $this->unpad($plaintext) : $plaintext;
|
1092 |
+
}
|
1093 |
+
|
1094 |
+
/**
|
1095 |
+
* Pad "packets".
|
1096 |
+
*
|
1097 |
+
* Block ciphers working by encrypting between their specified [$this->]blockSize at a time
|
1098 |
+
* If you ever need to encrypt or decrypt something that isn't of the proper length, it becomes necessary to
|
1099 |
+
* pad the input so that it is of the proper length.
|
1100 |
+
*
|
1101 |
+
* Padding is enabled by default. Sometimes, however, it is undesirable to pad strings. Such is the case in SSH,
|
1102 |
+
* where "packets" are padded with random bytes before being encrypted. Un-pad these packets and you risk stripping
|
1103 |
+
* away characters that should not be stripped away. (SSH knows how many bytes are added because the length is
|
1104 |
+
* transmitted separately)
|
1105 |
+
*
|
1106 |
+
* @see NostoCryptBase::disablePadding()
|
1107 |
+
*/
|
1108 |
+
public function enablePadding()
|
1109 |
+
{
|
1110 |
+
$this->padding = true;
|
1111 |
+
}
|
1112 |
+
|
1113 |
+
/**
|
1114 |
+
* Do not pad packets.
|
1115 |
+
*
|
1116 |
+
* @see NostoCryptBase::enablePadding()
|
1117 |
+
*/
|
1118 |
+
public function disablePadding()
|
1119 |
+
{
|
1120 |
+
$this->padding = false;
|
1121 |
+
}
|
1122 |
+
|
1123 |
+
/**
|
1124 |
+
* Treat consecutive "packets" as if they are a continuous buffer.
|
1125 |
+
*
|
1126 |
+
* Say you have a 32-byte plaintext $plaintext. Using the default behavior, the two following code snippets
|
1127 |
+
* will yield different outputs:
|
1128 |
+
*
|
1129 |
+
* <code>
|
1130 |
+
* echo $rijndael->encrypt(substr($plaintext, 0, 16));
|
1131 |
+
* echo $rijndael->encrypt(substr($plaintext, 16, 16));
|
1132 |
+
* </code>
|
1133 |
+
* <code>
|
1134 |
+
* echo $rijndael->encrypt($plaintext);
|
1135 |
+
* </code>
|
1136 |
+
*
|
1137 |
+
* The solution is to enable the continuous buffer. Although this will resolve the above discrepancy, it creates
|
1138 |
+
* another, as demonstrated with the following:
|
1139 |
+
*
|
1140 |
+
* <code>
|
1141 |
+
* $rijndael->encrypt(substr($plaintext, 0, 16));
|
1142 |
+
* echo $rijndael->decrypt($rijndael->encrypt(substr($plaintext, 16, 16)));
|
1143 |
+
* </code>
|
1144 |
+
* <code>
|
1145 |
+
* echo $rijndael->decrypt($rijndael->encrypt(substr($plaintext, 16, 16)));
|
1146 |
+
* </code>
|
1147 |
+
*
|
1148 |
+
* With the continuous buffer disabled, these would yield the same output. With it enabled, they yield different
|
1149 |
+
* outputs. The reason is due to the fact that the initialization vector's change after every encryption /
|
1150 |
+
* decryption round when the continuous buffer is enabled. When it's disabled, they remain constant.
|
1151 |
+
*
|
1152 |
+
* Put another way, when the continuous buffer is enabled, the state of the Crypt*() object changes after each
|
1153 |
+
* encryption / decryption round, whereas otherwise, it'd remain constant. For this reason, it's recommended that
|
1154 |
+
* continuous buffers not be used. They do offer better security and are, in fact, sometimes required
|
1155 |
+
* (SSH uses them), however, they are also less intuitive and more likely to cause you problems.
|
1156 |
+
*
|
1157 |
+
* Note: Could, but not must, extend by the child Crypt* class
|
1158 |
+
*
|
1159 |
+
* @see NostoCryptBase::disableContinuousBuffer()
|
1160 |
+
*/
|
1161 |
+
public function enableContinuousBuffer()
|
1162 |
+
{
|
1163 |
+
if ($this->mode == CRYPT_MODE_ECB) {
|
1164 |
+
return;
|
1165 |
+
}
|
1166 |
+
|
1167 |
+
$this->continuousBuffer = true;
|
1168 |
+
}
|
1169 |
+
|
1170 |
+
/**
|
1171 |
+
* Treat consecutive packets as if they are a discontinuous buffer.
|
1172 |
+
*
|
1173 |
+
* The default behavior.
|
1174 |
+
*
|
1175 |
+
* Note: Could, but not must, extend by the child Crypt* class
|
1176 |
+
*
|
1177 |
+
* @see NostoCryptBase::enableContinuousBuffer()
|
1178 |
+
*/
|
1179 |
+
public function disableContinuousBuffer()
|
1180 |
+
{
|
1181 |
+
if ($this->mode == CRYPT_MODE_ECB) {
|
1182 |
+
return;
|
1183 |
+
}
|
1184 |
+
if (!$this->continuousBuffer) {
|
1185 |
+
return;
|
1186 |
+
}
|
1187 |
+
|
1188 |
+
$this->continuousBuffer = false;
|
1189 |
+
$this->changed = true;
|
1190 |
+
}
|
1191 |
+
|
1192 |
+
/**
|
1193 |
+
* Encrypts a block
|
1194 |
+
*
|
1195 |
+
* Note: Must extend by the child Crypt* class
|
1196 |
+
*
|
1197 |
+
* @param String $in
|
1198 |
+
* @return String
|
1199 |
+
* @throws NostoUndefinedMethodException
|
1200 |
+
*/
|
1201 |
+
public function encryptBlock($in)
|
1202 |
+
{
|
1203 |
+
throw new NostoUndefinedMethodException(__METHOD__.'() must extend by class '.get_class($this));
|
1204 |
+
}
|
1205 |
+
|
1206 |
+
/**
|
1207 |
+
* Decrypts a block
|
1208 |
+
*
|
1209 |
+
* Note: Must extend by the child Crypt* class
|
1210 |
+
*
|
1211 |
+
* @param String $in
|
1212 |
+
* @return String
|
1213 |
+
* @throws NostoUndefinedMethodException
|
1214 |
+
*/
|
1215 |
+
public function decryptBlock($in)
|
1216 |
+
{
|
1217 |
+
throw new NostoUndefinedMethodException(__METHOD__.'() must extend by class '.get_class($this));
|
1218 |
+
}
|
1219 |
+
|
1220 |
+
/**
|
1221 |
+
* Setup the key (expansion)
|
1222 |
+
*
|
1223 |
+
* Only used if $engine == CRYPT_MODE_INTERNAL
|
1224 |
+
*
|
1225 |
+
* Note: Must extend by the child Crypt* class
|
1226 |
+
*
|
1227 |
+
* @see NostoCryptBase::setup()
|
1228 |
+
* @throws NostoUndefinedMethodException
|
1229 |
+
*/
|
1230 |
+
public function setupKey()
|
1231 |
+
{
|
1232 |
+
throw new NostoUndefinedMethodException(__METHOD__.'() must extend by class '.get_class($this));
|
1233 |
+
}
|
1234 |
+
|
1235 |
+
/**
|
1236 |
+
* Setup the CRYPT_MODE_INTERNAL $engine
|
1237 |
+
*
|
1238 |
+
* (re)init, if necessary, the internal cipher $engine and flush all $buffers
|
1239 |
+
* Used (only) if $engine == CRYPT_MODE_INTERNAL
|
1240 |
+
*
|
1241 |
+
* _setup() will be called each time if $changed === true
|
1242 |
+
* typically this happens when using one or more of following public methods:
|
1243 |
+
*
|
1244 |
+
* - setKey()
|
1245 |
+
*
|
1246 |
+
* - setIV()
|
1247 |
+
*
|
1248 |
+
* - disableContinuousBuffer()
|
1249 |
+
*
|
1250 |
+
* - First run of encrypt() / decrypt() with no init-settings
|
1251 |
+
*
|
1252 |
+
* Internally: _setup() is called always before(!) en/decryption.
|
1253 |
+
*
|
1254 |
+
* Note: Could, but not must, extend by the child Crypt* class
|
1255 |
+
*
|
1256 |
+
* @see setKey()
|
1257 |
+
* @see setIV()
|
1258 |
+
* @see disableContinuousBuffer()
|
1259 |
+
*/
|
1260 |
+
public function setup()
|
1261 |
+
{
|
1262 |
+
$this->clearBuffers();
|
1263 |
+
$this->setupKey();
|
1264 |
+
|
1265 |
+
if ($this->useInlineCrypt) {
|
1266 |
+
$this->setupInlineCrypt();
|
1267 |
+
}
|
1268 |
+
}
|
1269 |
+
|
1270 |
+
/**
|
1271 |
+
* Setup the CRYPT_MODE_MCRYPT $engine
|
1272 |
+
*
|
1273 |
+
* (re)init, if necessary, the (ext)mcrypt resources and flush all $buffers
|
1274 |
+
* Used (only) if $engine = CRYPT_MODE_MCRYPT
|
1275 |
+
*
|
1276 |
+
* _setupMcrypt() will be called each time if $changed === true
|
1277 |
+
* typically this happens when using one or more of following public methods:
|
1278 |
+
*
|
1279 |
+
* - setKey()
|
1280 |
+
*
|
1281 |
+
* - setIV()
|
1282 |
+
*
|
1283 |
+
* - disableContinuousBuffer()
|
1284 |
+
*
|
1285 |
+
* - First run of encrypt() / decrypt()
|
1286 |
+
*
|
1287 |
+
*
|
1288 |
+
* Note: Could, but not must, extend by the child Crypt* class
|
1289 |
+
*
|
1290 |
+
* @see setKey()
|
1291 |
+
* @see setIV()
|
1292 |
+
* @see disableContinuousBuffer()
|
1293 |
+
*/
|
1294 |
+
public function setupMcrypt()
|
1295 |
+
{
|
1296 |
+
$this->clearBuffers();
|
1297 |
+
$this->enChanged = $this->deChanged = true;
|
1298 |
+
|
1299 |
+
if (!isset($this->enMcrypt)) {
|
1300 |
+
static $mcrypt_modes = array(
|
1301 |
+
CRYPT_MODE_CTR => 'ctr',
|
1302 |
+
CRYPT_MODE_ECB => MCRYPT_MODE_ECB,
|
1303 |
+
CRYPT_MODE_CBC => MCRYPT_MODE_CBC,
|
1304 |
+
CRYPT_MODE_CFB => 'ncfb',
|
1305 |
+
CRYPT_MODE_OFB => MCRYPT_MODE_NOFB,
|
1306 |
+
CRYPT_MODE_STREAM => MCRYPT_MODE_STREAM,
|
1307 |
+
);
|
1308 |
+
|
1309 |
+
$this->deMcrypt = mcrypt_module_open($this->cipherNameMcrypt, '', $mcrypt_modes[$this->mode], '');
|
1310 |
+
$this->enMcrypt = mcrypt_module_open($this->cipherNameMcrypt, '', $mcrypt_modes[$this->mode], '');
|
1311 |
+
|
1312 |
+
// we need the $ecb mcrypt resource (only) in MODE_CFB with enableContinuousBuffer()
|
1313 |
+
// to workaround mcrypt's broken ncfb implementation in buffered mode
|
1314 |
+
// see: {@link http://phpseclib.sourceforge.net/cfb-demo.phps}
|
1315 |
+
if ($this->mode == CRYPT_MODE_CFB) {
|
1316 |
+
$this->ecb = mcrypt_module_open($this->cipherNameMcrypt, '', MCRYPT_MODE_ECB, '');
|
1317 |
+
}
|
1318 |
+
|
1319 |
+
} // else should mcrypt_generic_deinit be called?
|
1320 |
+
|
1321 |
+
if ($this->mode == CRYPT_MODE_CFB) {
|
1322 |
+
mcrypt_generic_init($this->ecb, $this->key, str_repeat("\0", $this->blockSize));
|
1323 |
+
}
|
1324 |
+
}
|
1325 |
+
|
1326 |
+
/**
|
1327 |
+
* Pads a string
|
1328 |
+
*
|
1329 |
+
* Pads a string using the RSA PKCS padding standards so that its length is a multiple of the block size.
|
1330 |
+
* $this->blockSize - (strlen($text) % $this->blockSize) bytes are added, each of which is equal to
|
1331 |
+
* chr($this->blockSize - (strlen($text) % $this->blockSize)
|
1332 |
+
*
|
1333 |
+
* If padding is disabled and $text is not a multiple of the block size, the string will be padded regardless
|
1334 |
+
* and padding will, hence forth, be enabled.
|
1335 |
+
*
|
1336 |
+
* @see NostoCryptBase::unpad()
|
1337 |
+
* @param String $text
|
1338 |
+
* @return String
|
1339 |
+
* @throws NostoInvalidLengthException
|
1340 |
+
*/
|
1341 |
+
public function pad($text)
|
1342 |
+
{
|
1343 |
+
$length = strlen($text);
|
1344 |
+
|
1345 |
+
if (!$this->padding) {
|
1346 |
+
if ($length % $this->blockSize == 0) {
|
1347 |
+
return $text;
|
1348 |
+
} else {
|
1349 |
+
throw new NostoInvalidLengthException(
|
1350 |
+
"The plaintext length ($length) is not a multiple of the block size ({$this->blockSize})"
|
1351 |
+
);
|
1352 |
+
}
|
1353 |
+
}
|
1354 |
+
|
1355 |
+
$pad = $this->blockSize - ($length % $this->blockSize);
|
1356 |
+
|
1357 |
+
return str_pad($text, $length + $pad, chr($pad));
|
1358 |
+
}
|
1359 |
+
|
1360 |
+
/**
|
1361 |
+
* Un-pads a string.
|
1362 |
+
*
|
1363 |
+
* If padding is enabled and the reported padding length is invalid the encryption key will be assumed to be wrong
|
1364 |
+
* and false will be returned.
|
1365 |
+
*
|
1366 |
+
* @see NostoCryptBase::pad()
|
1367 |
+
* @param String $text
|
1368 |
+
* @return String
|
1369 |
+
* @throws NostoInvalidPaddingException
|
1370 |
+
*/
|
1371 |
+
public function unpad($text)
|
1372 |
+
{
|
1373 |
+
if (!$this->padding) {
|
1374 |
+
return $text;
|
1375 |
+
}
|
1376 |
+
|
1377 |
+
$length = ord($text[strlen($text) - 1]);
|
1378 |
+
|
1379 |
+
if (!$length || $length > $this->blockSize) {
|
1380 |
+
throw new NostoInvalidPaddingException("An illegal padding character ($length) has been detected");
|
1381 |
+
}
|
1382 |
+
|
1383 |
+
return substr($text, 0, -$length);
|
1384 |
+
}
|
1385 |
+
|
1386 |
+
/**
|
1387 |
+
* Clears internal buffers
|
1388 |
+
*
|
1389 |
+
* Clearing/resetting the internal buffers is done everytime
|
1390 |
+
* after disableContinuousBuffer() or on cipher $engine (re)init
|
1391 |
+
* ie after setKey() or setIV()
|
1392 |
+
*
|
1393 |
+
* Note: Could, but not must, extend by the child Crypt* class
|
1394 |
+
*/
|
1395 |
+
public function clearBuffers()
|
1396 |
+
{
|
1397 |
+
$this->enBuffer = array('encrypted' => '', 'xor' => '', 'pos' => 0, 'enmcrypt_init' => true);
|
1398 |
+
$this->deBuffer = array('ciphertext' => '', 'xor' => '', 'pos' => 0, 'demcrypt_init' => true);
|
1399 |
+
|
1400 |
+
// mcrypt's handling of invalid's $iv:
|
1401 |
+
// $this->encryptIV = $this->decryptIV =
|
1402 |
+
// strlen($this->iv) == $this->blockSize ? $this->iv : str_repeat("\0", $this->blockSize);
|
1403 |
+
$this->encryptIV = $this->decryptIV = str_pad(substr($this->iv, 0, $this->blockSize), $this->blockSize, "\0");
|
1404 |
+
}
|
1405 |
+
|
1406 |
+
/**
|
1407 |
+
* String Shift
|
1408 |
+
*
|
1409 |
+
* Inspired by array_shift
|
1410 |
+
*
|
1411 |
+
* @param String $string
|
1412 |
+
* @param optional Integer $index
|
1413 |
+
* @return String
|
1414 |
+
*/
|
1415 |
+
public function stringShift(&$string, $index = 1)
|
1416 |
+
{
|
1417 |
+
$substr = substr($string, 0, $index);
|
1418 |
+
$string = substr($string, $index);
|
1419 |
+
return $substr;
|
1420 |
+
}
|
1421 |
+
|
1422 |
+
/**
|
1423 |
+
* Generate CTR XOR encryption key
|
1424 |
+
*
|
1425 |
+
* Encrypt the output of this and XOR it against the ciphertext / plaintext to get the
|
1426 |
+
* plaintext / ciphertext in CTR mode.
|
1427 |
+
*
|
1428 |
+
* @see NostoCryptBase::decrypt()
|
1429 |
+
* @see NostoCryptBase::encrypt()
|
1430 |
+
* @param String $iv
|
1431 |
+
* @param Integer $length
|
1432 |
+
* @return String $xor
|
1433 |
+
*/
|
1434 |
+
public function generateXor(&$iv, $length)
|
1435 |
+
{
|
1436 |
+
$xor = '';
|
1437 |
+
$count = 0;
|
1438 |
+
$block_size = $this->blockSize;
|
1439 |
+
$num_blocks = floor(($length + ($block_size - 1)) / $block_size);
|
1440 |
+
for ($i = 0; $i < $num_blocks; $i++) {
|
1441 |
+
$xor .= $iv;
|
1442 |
+
for ($j = 4; $j <= $block_size; $j += 4) {
|
1443 |
+
$temp = substr($iv, -$j, 4);
|
1444 |
+
switch ($temp) {
|
1445 |
+
case "\xFF\xFF\xFF\xFF":
|
1446 |
+
$iv = substr_replace($iv, "\x00\x00\x00\x00", -$j, 4);
|
1447 |
+
break;
|
1448 |
+
case "\x7F\xFF\xFF\xFF":
|
1449 |
+
$iv = substr_replace($iv, "\x80\x00\x00\x00", -$j, 4);
|
1450 |
+
break 2;
|
1451 |
+
default:
|
1452 |
+
extract(unpack('Ncount', $temp));
|
1453 |
+
$iv = substr_replace($iv, pack('N', $count + 1), -$j, 4);
|
1454 |
+
break 2;
|
1455 |
+
}
|
1456 |
+
}
|
1457 |
+
}
|
1458 |
+
|
1459 |
+
return $xor;
|
1460 |
+
}
|
1461 |
+
|
1462 |
+
/**
|
1463 |
+
* Setup the performance-optimized function for de/encrypt()
|
1464 |
+
*
|
1465 |
+
* Stores the created (or existing) callback function-name
|
1466 |
+
* in $this->inlineCrypt
|
1467 |
+
*
|
1468 |
+
* Internally for phpseclib developers:
|
1469 |
+
*
|
1470 |
+
* _setupInlineCrypt() would be called only if:
|
1471 |
+
*
|
1472 |
+
* - $engine == CRYPT_MODE_INTERNAL and
|
1473 |
+
*
|
1474 |
+
* - $useInlineCrypt === true
|
1475 |
+
*
|
1476 |
+
* - each time on _setup(), after(!) setupKey()
|
1477 |
+
*
|
1478 |
+
*
|
1479 |
+
* This ensures that _setupInlineCrypt() has allways a
|
1480 |
+
* full ready2go initializated internal cipher $engine state
|
1481 |
+
* where, for example, the keys allready expanded,
|
1482 |
+
* keys/blockSize calculated and such.
|
1483 |
+
*
|
1484 |
+
* It is, each time if called, the responsibility of _setupInlineCrypt():
|
1485 |
+
*
|
1486 |
+
* - to set $this->inlineCrypt to a valid and fully working callback function
|
1487 |
+
* as a (faster) replacement for encrypt() / decrypt()
|
1488 |
+
*
|
1489 |
+
* - NOT to create unlimited callback functions (for memory reasons!)
|
1490 |
+
* no matter how often _setupInlineCrypt() would be called. At some
|
1491 |
+
* point of amount they must be generic re-useable.
|
1492 |
+
*
|
1493 |
+
* - the code of _setupInlineCrypt() it self,
|
1494 |
+
* and the generated callback code,
|
1495 |
+
* must be, in following order:
|
1496 |
+
* - 100% safe
|
1497 |
+
* - 100% compatible to encrypt()/decrypt()
|
1498 |
+
* - using only php5+ features/lang-constructs/php-extensions if
|
1499 |
+
* compatibility (down to php4) or fallback is provided
|
1500 |
+
* - readable/maintainable/understandable/commented and... not-cryptic-styled-code :-)
|
1501 |
+
* - >= 10% faster than encrypt()/decrypt() [which is, by the way,
|
1502 |
+
* the reason for the existence of _setupInlineCrypt() :-)]
|
1503 |
+
* - memory-nice
|
1504 |
+
* - short (as good as possible)
|
1505 |
+
*
|
1506 |
+
* Note: - _setupInlineCrypt() is using _createInlineCryptFunction() to create the full callback function code.
|
1507 |
+
* - In case of using inline crypting, _setupInlineCrypt() must extend by the child Crypt* class.
|
1508 |
+
* - The following variable names are reserved:
|
1509 |
+
* - $_* (all variable names prefixed with an underscore)
|
1510 |
+
* - $self (object reference to it self. Do not use $this, but $self instead)
|
1511 |
+
* - $in (the content of $in has to en/decrypt by the generated code)
|
1512 |
+
* - The callback function should not use the 'return' statement, but en/decrypt'ing the content of $in only
|
1513 |
+
*
|
1514 |
+
*
|
1515 |
+
* @see NostoCryptBase::setup()
|
1516 |
+
* @see NostoCryptBase::createInlineCryptFunction()
|
1517 |
+
* @see NostoCryptBase::encrypt()
|
1518 |
+
* @see NostoCryptBase::decrypt()
|
1519 |
+
*/
|
1520 |
+
public function setupInlineCrypt()
|
1521 |
+
{
|
1522 |
+
// If a Crypt* class providing inline crypting it must extend _setupInlineCrypt()
|
1523 |
+
|
1524 |
+
// If, for any reason, an extending NostoCryptBase() Crypt* class
|
1525 |
+
// not using inline crypting then it must be ensured that: $this->useInlineCrypt = false
|
1526 |
+
// ie in the class var declaration of $useInlineCrypt in general for the Crypt* class,
|
1527 |
+
// in the constructor at object instance-time
|
1528 |
+
// or, if it's runtime-specific, at runtime
|
1529 |
+
|
1530 |
+
$this->useInlineCrypt = false;
|
1531 |
+
}
|
1532 |
+
|
1533 |
+
/**
|
1534 |
+
* Creates the performance-optimized function for en/decrypt()
|
1535 |
+
*
|
1536 |
+
* Internally for phpseclib developers:
|
1537 |
+
*
|
1538 |
+
* _createInlineCryptFunction():
|
1539 |
+
*
|
1540 |
+
* - merge the $cipher_code [setup'ed by _setupInlineCrypt()]
|
1541 |
+
* with the current [$this->]mode of operation code
|
1542 |
+
*
|
1543 |
+
* - create the $inline function, which called by encrypt() / decrypt()
|
1544 |
+
* as its replacement to speed up the en/decryption operations.
|
1545 |
+
*
|
1546 |
+
* - return the name of the created $inline callback function
|
1547 |
+
*
|
1548 |
+
* - used to speed up en/decryption
|
1549 |
+
*
|
1550 |
+
*
|
1551 |
+
*
|
1552 |
+
* The main reason why can speed up things [up to 50%] this way are:
|
1553 |
+
*
|
1554 |
+
* - using variables more effective then regular.
|
1555 |
+
* (ie no use of expensive arrays but integers $k_0, $k_1 ...
|
1556 |
+
* or even, for example, the pure $key[] values hardcoded)
|
1557 |
+
*
|
1558 |
+
* - avoiding 1000's of function calls of ie encryptBlock()
|
1559 |
+
* but inlining the crypt operations.
|
1560 |
+
* in the mode of operation for() loop.
|
1561 |
+
*
|
1562 |
+
* - full loop unroll the (sometimes key-dependent) rounds
|
1563 |
+
* avoiding this way ++$i counters and runtime-if's etc...
|
1564 |
+
*
|
1565 |
+
* The basic code architectur of the generated $inline en/decrypt()
|
1566 |
+
* lambda function, in pseudo php, is:
|
1567 |
+
*
|
1568 |
+
* <code>
|
1569 |
+
* +----------------------------------------------------------------------------------------------+
|
1570 |
+
* | callback $inline = create_function: |
|
1571 |
+
* | lambda_function_0001_crypt_ECB($action, $text) |
|
1572 |
+
* | { |
|
1573 |
+
* | INSERT PHP CODE OF: |
|
1574 |
+
* | $cipher_code['init_crypt']; // general init code. |
|
1575 |
+
* | // ie: $sbox'es declarations used for |
|
1576 |
+
* | // encrypt and decrypt'ing. |
|
1577 |
+
* | |
|
1578 |
+
* | switch ($action) { |
|
1579 |
+
* | case 'encrypt': |
|
1580 |
+
* | INSERT PHP CODE OF: |
|
1581 |
+
* | $cipher_code['init_encrypt']; // encrypt sepcific init code. |
|
1582 |
+
* | ie: specified $key or $box |
|
1583 |
+
* | declarations for encrypt'ing. |
|
1584 |
+
* | |
|
1585 |
+
* | foreach ($ciphertext) { |
|
1586 |
+
* | $in = $blockSize of $ciphertext; |
|
1587 |
+
* | |
|
1588 |
+
* | INSERT PHP CODE OF: |
|
1589 |
+
* | $cipher_code['encrypt_block']; // encrypt's (string) $in, which is always: |
|
1590 |
+
* | // strlen($in) == $this->blockSize |
|
1591 |
+
* | // here comes the cipher algorithm in action |
|
1592 |
+
* | // for encryption. |
|
1593 |
+
* | // $cipher_code['encrypt_block'] has to |
|
1594 |
+
* | // encrypt the content of the $in variable |
|
1595 |
+
* | |
|
1596 |
+
* | $plaintext .= $in; |
|
1597 |
+
* | } |
|
1598 |
+
* | return $plaintext; |
|
1599 |
+
* | |
|
1600 |
+
* | case 'decrypt': |
|
1601 |
+
* | INSERT PHP CODE OF: |
|
1602 |
+
* | $cipher_code['init_decrypt']; // decrypt sepcific init code |
|
1603 |
+
* | ie: specified $key or $box |
|
1604 |
+
* | declarations for decrypt'ing. |
|
1605 |
+
* | foreach ($plaintext) { |
|
1606 |
+
* | $in = $blockSize of $plaintext; |
|
1607 |
+
* | |
|
1608 |
+
* | INSERT PHP CODE OF: |
|
1609 |
+
* | $cipher_code['decrypt_block']; // decrypt's (string) $in, which is always |
|
1610 |
+
* | // strlen($in) == $this->blockSize |
|
1611 |
+
* | // here comes the cipher algorithm in action |
|
1612 |
+
* | // for decryption. |
|
1613 |
+
* | // $cipher_code['decrypt_block'] has to |
|
1614 |
+
* | // decrypt the content of the $in variable |
|
1615 |
+
* | $ciphertext .= $in; |
|
1616 |
+
* | } |
|
1617 |
+
* | return $ciphertext; |
|
1618 |
+
* | } |
|
1619 |
+
* | } |
|
1620 |
+
* +----------------------------------------------------------------------------------------------+
|
1621 |
+
* </code>
|
1622 |
+
*
|
1623 |
+
* See also the Crypt*::setupInlineCrypt()'s for
|
1624 |
+
* productive inline $cipher_code's how they works.
|
1625 |
+
*
|
1626 |
+
* Structure of:
|
1627 |
+
* <code>
|
1628 |
+
* $cipher_code = array(
|
1629 |
+
* 'init_crypt' => (string) '', // optional
|
1630 |
+
* 'init_encrypt' => (string) '', // optional
|
1631 |
+
* 'init_decrypt' => (string) '', // optional
|
1632 |
+
* 'encrypt_block' => (string) '', // required
|
1633 |
+
* 'decrypt_block' => (string) '' // required
|
1634 |
+
* );
|
1635 |
+
* </code>
|
1636 |
+
*
|
1637 |
+
* @see NostoCryptBase::setupInlineCrypt()
|
1638 |
+
* @see NostoCryptBase::encrypt()
|
1639 |
+
* @see NostoCryptBase::decrypt()
|
1640 |
+
* @param Array $cipher_code
|
1641 |
+
* @return String (the name of the created callback function)
|
1642 |
+
*/
|
1643 |
+
public function createInlineCryptFunction($cipher_code)
|
1644 |
+
{
|
1645 |
+
$block_size = $this->blockSize;
|
1646 |
+
|
1647 |
+
// optional
|
1648 |
+
$init_crypt = isset($cipher_code['init_crypt']) ? $cipher_code['init_crypt'] : '';
|
1649 |
+
$init_encrypt = isset($cipher_code['init_encrypt']) ? $cipher_code['init_encrypt'] : '';
|
1650 |
+
$init_decrypt = isset($cipher_code['init_decrypt']) ? $cipher_code['init_decrypt'] : '';
|
1651 |
+
// required
|
1652 |
+
$encrypt_block = $cipher_code['encrypt_block'];
|
1653 |
+
$decrypt_block = $cipher_code['decrypt_block'];
|
1654 |
+
|
1655 |
+
// Generating mode of operation inline code,
|
1656 |
+
// merged with the $cipher_code algorithm
|
1657 |
+
// for encrypt- and decryption.
|
1658 |
+
switch ($this->mode) {
|
1659 |
+
case CRYPT_MODE_ECB:
|
1660 |
+
$encrypt = $init_encrypt.'
|
1661 |
+
$_ciphertext = "";
|
1662 |
+
$_text = $self->pad($_text);
|
1663 |
+
$_plaintext_len = strlen($_text);
|
1664 |
+
|
1665 |
+
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
1666 |
+
$in = substr($_text, $_i, '.$block_size.');
|
1667 |
+
'.$encrypt_block.'
|
1668 |
+
$_ciphertext.= $in;
|
1669 |
+
}
|
1670 |
+
|
1671 |
+
return $_ciphertext;
|
1672 |
+
';
|
1673 |
+
|
1674 |
+
$decrypt = $init_decrypt.'
|
1675 |
+
$_plaintext = "";
|
1676 |
+
$_text = str_pad($_text, strlen($_text) + ('.$block_size.' - strlen($_text) % '.$block_size.') % '.$block_size.', chr(0));
|
1677 |
+
$_ciphertext_len = strlen($_text);
|
1678 |
+
|
1679 |
+
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
1680 |
+
$in = substr($_text, $_i, '.$block_size.');
|
1681 |
+
'.$decrypt_block.'
|
1682 |
+
$_plaintext.= $in;
|
1683 |
+
}
|
1684 |
+
|
1685 |
+
return $self->unpad($_plaintext);
|
1686 |
+
';
|
1687 |
+
break;
|
1688 |
+
case CRYPT_MODE_CTR:
|
1689 |
+
$encrypt = $init_encrypt.'
|
1690 |
+
$_ciphertext = "";
|
1691 |
+
$_plaintext_len = strlen($_text);
|
1692 |
+
$_xor = $self->encryptIV;
|
1693 |
+
$_buffer = &$self->enBuffer;
|
1694 |
+
|
1695 |
+
if (strlen($_buffer["encrypted"])) {
|
1696 |
+
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
1697 |
+
$_block = substr($_text, $_i, '.$block_size.');
|
1698 |
+
if (strlen($_block) > strlen($_buffer["encrypted"])) {
|
1699 |
+
$in = $self->generateXor($_xor, '.$block_size.');
|
1700 |
+
'.$encrypt_block.'
|
1701 |
+
$_buffer["encrypted"].= $in;
|
1702 |
+
}
|
1703 |
+
$_key = $self->stringShift($_buffer["encrypted"], '.$block_size.');
|
1704 |
+
$_ciphertext.= $_block ^ $_key;
|
1705 |
+
}
|
1706 |
+
} else {
|
1707 |
+
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
1708 |
+
$_block = substr($_text, $_i, '.$block_size.');
|
1709 |
+
$in = $self->generateXor($_xor, '.$block_size.');
|
1710 |
+
'.$encrypt_block.'
|
1711 |
+
$_key = $in;
|
1712 |
+
$_ciphertext.= $_block ^ $_key;
|
1713 |
+
}
|
1714 |
+
}
|
1715 |
+
if ($self->continuousBuffer) {
|
1716 |
+
$self->encryptIV = $_xor;
|
1717 |
+
if ($_start = $_plaintext_len % '.$block_size.') {
|
1718 |
+
$_buffer["encrypted"] = substr($_key, $_start) . $_buffer["encrypted"];
|
1719 |
+
}
|
1720 |
+
}
|
1721 |
+
|
1722 |
+
return $_ciphertext;
|
1723 |
+
';
|
1724 |
+
|
1725 |
+
$decrypt = $init_encrypt.'
|
1726 |
+
$_plaintext = "";
|
1727 |
+
$_ciphertext_len = strlen($_text);
|
1728 |
+
$_xor = $self->decryptIV;
|
1729 |
+
$_buffer = &$self->deBuffer;
|
1730 |
+
|
1731 |
+
if (strlen($_buffer["ciphertext"])) {
|
1732 |
+
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
1733 |
+
$_block = substr($_text, $_i, '.$block_size.');
|
1734 |
+
if (strlen($_block) > strlen($_buffer["ciphertext"])) {
|
1735 |
+
$in = $self->generateXor($_xor, '.$block_size.');
|
1736 |
+
'.$encrypt_block.'
|
1737 |
+
$_buffer["ciphertext"].= $in;
|
1738 |
+
}
|
1739 |
+
$_key = $self->stringShift($_buffer["ciphertext"], '.$block_size.');
|
1740 |
+
$_plaintext.= $_block ^ $_key;
|
1741 |
+
}
|
1742 |
+
} else {
|
1743 |
+
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
1744 |
+
$_block = substr($_text, $_i, '.$block_size.');
|
1745 |
+
$in = $self->generateXor($_xor, '.$block_size.');
|
1746 |
+
'.$encrypt_block.'
|
1747 |
+
$_key = $in;
|
1748 |
+
$_plaintext.= $_block ^ $_key;
|
1749 |
+
}
|
1750 |
+
}
|
1751 |
+
if ($self->continuousBuffer) {
|
1752 |
+
$self->decryptIV = $_xor;
|
1753 |
+
if ($_start = $_ciphertext_len % '.$block_size.') {
|
1754 |
+
$_buffer["ciphertext"] = substr($_key, $_start) . $_buffer["ciphertext"];
|
1755 |
+
}
|
1756 |
+
}
|
1757 |
+
|
1758 |
+
return $_plaintext;
|
1759 |
+
';
|
1760 |
+
break;
|
1761 |
+
case CRYPT_MODE_CFB:
|
1762 |
+
$encrypt = $init_encrypt.'
|
1763 |
+
$_ciphertext = "";
|
1764 |
+
$_buffer = &$self->enBuffer;
|
1765 |
+
|
1766 |
+
if ($self->continuousBuffer) {
|
1767 |
+
$_iv = &$self->encryptIV;
|
1768 |
+
$_pos = &$_buffer["pos"];
|
1769 |
+
} else {
|
1770 |
+
$_iv = $self->encryptIV;
|
1771 |
+
$_pos = 0;
|
1772 |
+
}
|
1773 |
+
$_len = strlen($_text);
|
1774 |
+
$_i = 0;
|
1775 |
+
if ($_pos) {
|
1776 |
+
$_orig_pos = $_pos;
|
1777 |
+
$_max = '.$block_size.' - $_pos;
|
1778 |
+
if ($_len >= $_max) {
|
1779 |
+
$_i = $_max;
|
1780 |
+
$_len-= $_max;
|
1781 |
+
$_pos = 0;
|
1782 |
+
} else {
|
1783 |
+
$_i = $_len;
|
1784 |
+
$_pos+= $_len;
|
1785 |
+
$_len = 0;
|
1786 |
+
}
|
1787 |
+
$_ciphertext = substr($_iv, $_orig_pos) ^ $_text;
|
1788 |
+
$_iv = substr_replace($_iv, $_ciphertext, $_orig_pos, $_i);
|
1789 |
+
}
|
1790 |
+
while ($_len >= '.$block_size.') {
|
1791 |
+
$in = $_iv;
|
1792 |
+
'.$encrypt_block.';
|
1793 |
+
$_iv = $in ^ substr($_text, $_i, '.$block_size.');
|
1794 |
+
$_ciphertext.= $_iv;
|
1795 |
+
$_len-= '.$block_size.';
|
1796 |
+
$_i+= '.$block_size.';
|
1797 |
+
}
|
1798 |
+
if ($_len) {
|
1799 |
+
$in = $_iv;
|
1800 |
+
'.$encrypt_block.'
|
1801 |
+
$_iv = $in;
|
1802 |
+
$_block = $_iv ^ substr($_text, $_i);
|
1803 |
+
$_iv = substr_replace($_iv, $_block, 0, $_len);
|
1804 |
+
$_ciphertext.= $_block;
|
1805 |
+
$_pos = $_len;
|
1806 |
+
}
|
1807 |
+
return $_ciphertext;
|
1808 |
+
';
|
1809 |
+
|
1810 |
+
$decrypt = $init_encrypt.'
|
1811 |
+
$_plaintext = "";
|
1812 |
+
$_buffer = &$self->deBuffer;
|
1813 |
+
|
1814 |
+
if ($self->continuousBuffer) {
|
1815 |
+
$_iv = &$self->decryptIV;
|
1816 |
+
$_pos = &$_buffer["pos"];
|
1817 |
+
} else {
|
1818 |
+
$_iv = $self->decryptIV;
|
1819 |
+
$_pos = 0;
|
1820 |
+
}
|
1821 |
+
$_len = strlen($_text);
|
1822 |
+
$_i = 0;
|
1823 |
+
if ($_pos) {
|
1824 |
+
$_orig_pos = $_pos;
|
1825 |
+
$_max = '.$block_size.' - $_pos;
|
1826 |
+
if ($_len >= $_max) {
|
1827 |
+
$_i = $_max;
|
1828 |
+
$_len-= $_max;
|
1829 |
+
$_pos = 0;
|
1830 |
+
} else {
|
1831 |
+
$_i = $_len;
|
1832 |
+
$_pos+= $_len;
|
1833 |
+
$_len = 0;
|
1834 |
+
}
|
1835 |
+
$_plaintext = substr($_iv, $_orig_pos) ^ $_text;
|
1836 |
+
$_iv = substr_replace($_iv, substr($_text, 0, $_i), $_orig_pos, $_i);
|
1837 |
+
}
|
1838 |
+
while ($_len >= '.$block_size.') {
|
1839 |
+
$in = $_iv;
|
1840 |
+
'.$encrypt_block.'
|
1841 |
+
$_iv = $in;
|
1842 |
+
$cb = substr($_text, $_i, '.$block_size.');
|
1843 |
+
$_plaintext.= $_iv ^ $cb;
|
1844 |
+
$_iv = $cb;
|
1845 |
+
$_len-= '.$block_size.';
|
1846 |
+
$_i+= '.$block_size.';
|
1847 |
+
}
|
1848 |
+
if ($_len) {
|
1849 |
+
$in = $_iv;
|
1850 |
+
'.$encrypt_block.'
|
1851 |
+
$_iv = $in;
|
1852 |
+
$_plaintext.= $_iv ^ substr($_text, $_i);
|
1853 |
+
$_iv = substr_replace($_iv, substr($_text, $_i), 0, $_len);
|
1854 |
+
$_pos = $_len;
|
1855 |
+
}
|
1856 |
+
|
1857 |
+
return $_plaintext;
|
1858 |
+
';
|
1859 |
+
break;
|
1860 |
+
case CRYPT_MODE_OFB:
|
1861 |
+
$encrypt = $init_encrypt.'
|
1862 |
+
$_ciphertext = "";
|
1863 |
+
$_plaintext_len = strlen($_text);
|
1864 |
+
$_xor = $self->encryptIV;
|
1865 |
+
$_buffer = &$self->enBuffer;
|
1866 |
+
|
1867 |
+
if (strlen($_buffer["xor"])) {
|
1868 |
+
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
1869 |
+
$_block = substr($_text, $_i, '.$block_size.');
|
1870 |
+
if (strlen($_block) > strlen($_buffer["xor"])) {
|
1871 |
+
$in = $_xor;
|
1872 |
+
'.$encrypt_block.'
|
1873 |
+
$_xor = $in;
|
1874 |
+
$_buffer["xor"].= $_xor;
|
1875 |
+
}
|
1876 |
+
$_key = $self->stringShift($_buffer["xor"], '.$block_size.');
|
1877 |
+
$_ciphertext.= $_block ^ $_key;
|
1878 |
+
}
|
1879 |
+
} else {
|
1880 |
+
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
1881 |
+
$in = $_xor;
|
1882 |
+
'.$encrypt_block.'
|
1883 |
+
$_xor = $in;
|
1884 |
+
$_ciphertext.= substr($_text, $_i, '.$block_size.') ^ $_xor;
|
1885 |
+
}
|
1886 |
+
$_key = $_xor;
|
1887 |
+
}
|
1888 |
+
if ($self->continuousBuffer) {
|
1889 |
+
$self->encryptIV = $_xor;
|
1890 |
+
if ($_start = $_plaintext_len % '.$block_size.') {
|
1891 |
+
$_buffer["xor"] = substr($_key, $_start) . $_buffer["xor"];
|
1892 |
+
}
|
1893 |
+
}
|
1894 |
+
return $_ciphertext;
|
1895 |
+
';
|
1896 |
+
|
1897 |
+
$decrypt = $init_encrypt.'
|
1898 |
+
$_plaintext = "";
|
1899 |
+
$_ciphertext_len = strlen($_text);
|
1900 |
+
$_xor = $self->decryptIV;
|
1901 |
+
$_buffer = &$self->deBuffer;
|
1902 |
+
|
1903 |
+
if (strlen($_buffer["xor"])) {
|
1904 |
+
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
1905 |
+
$_block = substr($_text, $_i, '.$block_size.');
|
1906 |
+
if (strlen($_block) > strlen($_buffer["xor"])) {
|
1907 |
+
$in = $_xor;
|
1908 |
+
'.$encrypt_block.'
|
1909 |
+
$_xor = $in;
|
1910 |
+
$_buffer["xor"].= $_xor;
|
1911 |
+
}
|
1912 |
+
$_key = $self->stringShift($_buffer["xor"], '.$block_size.');
|
1913 |
+
$_plaintext.= $_block ^ $_key;
|
1914 |
+
}
|
1915 |
+
} else {
|
1916 |
+
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
1917 |
+
$in = $_xor;
|
1918 |
+
'.$encrypt_block.'
|
1919 |
+
$_xor = $in;
|
1920 |
+
$_plaintext.= substr($_text, $_i, '.$block_size.') ^ $_xor;
|
1921 |
+
}
|
1922 |
+
$_key = $_xor;
|
1923 |
+
}
|
1924 |
+
if ($self->continuousBuffer) {
|
1925 |
+
$self->decryptIV = $_xor;
|
1926 |
+
if ($_start = $_ciphertext_len % '.$block_size.') {
|
1927 |
+
$_buffer["xor"] = substr($_key, $_start) . $_buffer["xor"];
|
1928 |
+
}
|
1929 |
+
}
|
1930 |
+
return $_plaintext;
|
1931 |
+
';
|
1932 |
+
break;
|
1933 |
+
case CRYPT_MODE_STREAM:
|
1934 |
+
$encrypt = $init_encrypt.'
|
1935 |
+
$_ciphertext = "";
|
1936 |
+
'.$encrypt_block.'
|
1937 |
+
return $_ciphertext;
|
1938 |
+
';
|
1939 |
+
$decrypt = $init_decrypt.'
|
1940 |
+
$_plaintext = "";
|
1941 |
+
'.$decrypt_block.'
|
1942 |
+
return $_plaintext;
|
1943 |
+
';
|
1944 |
+
break;
|
1945 |
+
// case CRYPT_MODE_CBC:
|
1946 |
+
default:
|
1947 |
+
$encrypt = $init_encrypt.'
|
1948 |
+
$_ciphertext = "";
|
1949 |
+
$_text = $self->pad($_text);
|
1950 |
+
$_plaintext_len = strlen($_text);
|
1951 |
+
|
1952 |
+
$in = $self->encryptIV;
|
1953 |
+
|
1954 |
+
for ($_i = 0; $_i < $_plaintext_len; $_i+= '.$block_size.') {
|
1955 |
+
$in = substr($_text, $_i, '.$block_size.') ^ $in;
|
1956 |
+
'.$encrypt_block.'
|
1957 |
+
$_ciphertext.= $in;
|
1958 |
+
}
|
1959 |
+
|
1960 |
+
if ($self->continuousBuffer) {
|
1961 |
+
$self->encryptIV = $in;
|
1962 |
+
}
|
1963 |
+
|
1964 |
+
return $_ciphertext;
|
1965 |
+
';
|
1966 |
+
|
1967 |
+
$decrypt = $init_decrypt.'
|
1968 |
+
$_plaintext = "";
|
1969 |
+
$_text = str_pad($_text, strlen($_text) + ('.$block_size.' - strlen($_text) % '.$block_size.') % '.$block_size.', chr(0));
|
1970 |
+
$_ciphertext_len = strlen($_text);
|
1971 |
+
|
1972 |
+
$_iv = $self->decryptIV;
|
1973 |
+
|
1974 |
+
for ($_i = 0; $_i < $_ciphertext_len; $_i+= '.$block_size.') {
|
1975 |
+
$in = $_block = substr($_text, $_i, '.$block_size.');
|
1976 |
+
'.$decrypt_block.'
|
1977 |
+
$_plaintext.= $in ^ $_iv;
|
1978 |
+
$_iv = $_block;
|
1979 |
+
}
|
1980 |
+
|
1981 |
+
if ($self->continuousBuffer) {
|
1982 |
+
$self->decryptIV = $_iv;
|
1983 |
+
}
|
1984 |
+
|
1985 |
+
return $self->unpad($_plaintext);
|
1986 |
+
';
|
1987 |
+
break;
|
1988 |
+
}
|
1989 |
+
|
1990 |
+
// Create the $inline function and return its name as string. Ready to run!
|
1991 |
+
return create_function(
|
1992 |
+
'$_action, &$self, $_text',
|
1993 |
+
$init_crypt.'if ($_action == "encrypt") { '.$encrypt.' } else { '.$decrypt.' }'
|
1994 |
+
);
|
1995 |
+
}
|
1996 |
+
|
1997 |
+
/**
|
1998 |
+
* Holds the lambda_functions table (classwide)
|
1999 |
+
*
|
2000 |
+
* Each name of the lambda function, created from
|
2001 |
+
* _setupInlineCrypt() && _createInlineCryptFunction()
|
2002 |
+
* is stored, classwide (!), here for reusing.
|
2003 |
+
*
|
2004 |
+
* The string-based index of $function is a classwide
|
2005 |
+
* uniqe value representing, at least, the $mode of
|
2006 |
+
* operation (or more... depends of the optimizing level)
|
2007 |
+
* for which $mode the lambda function was created.
|
2008 |
+
*
|
2009 |
+
* @return &Array
|
2010 |
+
*/
|
2011 |
+
public function &getLambdaFunctions()
|
2012 |
+
{
|
2013 |
+
static $functions = array();
|
2014 |
+
return $functions;
|
2015 |
+
}
|
2016 |
+
}
|
lib/nosto/php-sdk/src/libs/phpseclib/crypt/NostoCryptRandom.php
ADDED
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Random string generator
|
4 |
+
*
|
5 |
+
* The idea behind this function is that it can be easily replaced with your own crypt_random_string()
|
6 |
+
* function. eg. maybe you have a better source of entropy for creating the initial states or whatever.
|
7 |
+
*
|
8 |
+
* PHP versions 5
|
9 |
+
*
|
10 |
+
* Here's a short example of how to use this library:
|
11 |
+
* <code>
|
12 |
+
* <?php
|
13 |
+
* include NostoCryptRandom.php';
|
14 |
+
*
|
15 |
+
* echo bin2hex(NostoCryptRandom::getRandomString(16));
|
16 |
+
* ?>
|
17 |
+
* </code>
|
18 |
+
*
|
19 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
20 |
+
* of this software and associated documentation files (the "Software"), to deal
|
21 |
+
* in the Software without restriction, including without limitation the rights
|
22 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
23 |
+
* copies of the Software, and to permit persons to whom the Software is
|
24 |
+
* furnished to do so, subject to the following conditions:
|
25 |
+
*
|
26 |
+
* The above copyright notice and this permission notice shall be included in
|
27 |
+
* all copies or substantial portions of the Software.
|
28 |
+
*
|
29 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
30 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
31 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
32 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
33 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
34 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
35 |
+
* THE SOFTWARE.
|
36 |
+
*
|
37 |
+
* @category Crypt
|
38 |
+
* @package Crypt_Random
|
39 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
40 |
+
* @copyright 2007 Jim Wigginton
|
41 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
42 |
+
* @link http://phpseclib.sourceforge.net
|
43 |
+
*/
|
44 |
+
|
45 |
+
/**
|
46 |
+
* Class representation of the original phpseclib implementation with a few modifications:
|
47 |
+
*
|
48 |
+
* - additional error checking
|
49 |
+
* - openssl_random_pseudo_bytes() output is required to be cryptographically strong
|
50 |
+
* - mcrypt_create_iv() is preferred method on Linux
|
51 |
+
* - Only AES cipher is available when generating pure-PHP CSPRNG
|
52 |
+
*/
|
53 |
+
class NostoCryptRandom
|
54 |
+
{
|
55 |
+
/**
|
56 |
+
* Returns a cryptographically string random string.
|
57 |
+
*
|
58 |
+
* @param int $length the length of the string to generate.
|
59 |
+
* @return string the generated random string.
|
60 |
+
*/
|
61 |
+
public static function getRandomString($length)
|
62 |
+
{
|
63 |
+
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
64 |
+
/*
|
65 |
+
* Prior to PHP 5.3 this would call rand() on win, hence the function_exists('class_alias') call.
|
66 |
+
* Function class_alias was introduced in PHP 5.3.
|
67 |
+
*/
|
68 |
+
if (function_exists('mcrypt_create_iv') && function_exists('class_alias')) {
|
69 |
+
$rnd = mcrypt_create_iv($length);
|
70 |
+
if ($rnd !== false) {
|
71 |
+
return $rnd;
|
72 |
+
}
|
73 |
+
}
|
74 |
+
/*
|
75 |
+
* Function openssl_random_pseudo_bytes was introduced in PHP 5.3.0 but prior to PHP 5.3.4 there was a
|
76 |
+
* "possible blocking behavior". As of 5.3.4 openssl_random_pseudo_bytes and mcrypt_create_iv do the exact
|
77 |
+
* same thing on Windows. ie. they both call php_win32_get_random_bytes().
|
78 |
+
*
|
79 |
+
* @link http://php.net/ChangeLog-5.php#5.3.4
|
80 |
+
* @link https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/ext/openssl/openssl.c#L5008
|
81 |
+
* @link https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/ext/mcrypt/mcrypt.c#L1392
|
82 |
+
* @link https://github.com/php/php-src/blob/7014a0eb6d1611151a286c0ff4f2238f92c120d6/win32/winutil.c#L80
|
83 |
+
*/
|
84 |
+
if (function_exists('openssl_random_pseudo_bytes') && version_compare(PHP_VERSION, '5.3.4', '>=')) {
|
85 |
+
$strong = null;
|
86 |
+
$rnd = openssl_random_pseudo_bytes($length, $strong);
|
87 |
+
if ($strong) {
|
88 |
+
return $rnd;
|
89 |
+
}
|
90 |
+
}
|
91 |
+
} else {
|
92 |
+
if (function_exists('mcrypt_create_iv')) {
|
93 |
+
$rnd = mcrypt_create_iv($length, MCRYPT_DEV_URANDOM);
|
94 |
+
if ($rnd !== false) {
|
95 |
+
return $rnd;
|
96 |
+
}
|
97 |
+
}
|
98 |
+
if (function_exists('openssl_random_pseudo_bytes')) {
|
99 |
+
$strong = null;
|
100 |
+
$rnd = openssl_random_pseudo_bytes($length, $strong);
|
101 |
+
if ($strong) {
|
102 |
+
return $rnd;
|
103 |
+
}
|
104 |
+
}
|
105 |
+
if (file_exists('/dev/urandom') && is_readable('/dev/urandom')) {
|
106 |
+
if (($fp = @fopen('/dev/urandom', 'rb')) !== false) {
|
107 |
+
if (function_exists('stream_set_read_buffer')) {
|
108 |
+
stream_set_read_buffer($fp, 0);
|
109 |
+
}
|
110 |
+
$rnd = fread($fp, $length);
|
111 |
+
fclose($fp);
|
112 |
+
if ($rnd !== false) {
|
113 |
+
return $rnd;
|
114 |
+
}
|
115 |
+
}
|
116 |
+
}
|
117 |
+
}
|
118 |
+
/*
|
119 |
+
* At this point we have no choice but to use a pure-PHP CSPRNG.
|
120 |
+
*
|
121 |
+
* Cascade entropy across multiple PHP instances by fixing the session and collecting all environmental
|
122 |
+
* variables, including the previous session data and the current session data.
|
123 |
+
*
|
124 |
+
* Function mt_rand seeds itself by looking at the PID and the time, both of which are (relatively) easy to
|
125 |
+
* guess. linux uses mouse clicks, keyboard timings, etc, as entropy sources, but PHP isn't low level enough to
|
126 |
+
* be able to use those as sources and on a web server there's not likely going to be a ton of keyboard or mouse
|
127 |
+
* action. Web servers do have one thing that we can use, however, a ton of people visiting the website.
|
128 |
+
* Obviously you don't want to base your seeding solely on parameters a potential attacker sends but (1) not
|
129 |
+
* everything in $_SERVER is controlled by the user and (2) this isn't just looking at the data sent by the
|
130 |
+
* current user - it's based on the data sent by all users. One user requests the page and a hash of their info
|
131 |
+
* is saved. Another user visits the page and the serialization of their data is utilized along with the server
|
132 |
+
* environment stuff and a hash of the previous http request data (which itself utilizes a hash of the session
|
133 |
+
* data before that). Certainly an attacker should be assumed to have full control over his own http requests.
|
134 |
+
* He, however, is not going to have control over all users http requests.
|
135 |
+
*/
|
136 |
+
|
137 |
+
// Save old session data.
|
138 |
+
$old_session_id = session_id();
|
139 |
+
$old_use_cookies = ini_get('session.use_cookies');
|
140 |
+
$old_session_cache_limiter = session_cache_limiter();
|
141 |
+
$_OLD_SESSION = isset($_SESSION) ? $_SESSION : false;
|
142 |
+
if ($old_session_id != '') {
|
143 |
+
session_write_close();
|
144 |
+
}
|
145 |
+
|
146 |
+
session_id(1);
|
147 |
+
ini_set('session.use_cookies', 0);
|
148 |
+
session_cache_limiter('');
|
149 |
+
session_start();
|
150 |
+
|
151 |
+
$v = $seed = $_SESSION['seed'] = pack(
|
152 |
+
'H*',
|
153 |
+
sha1(
|
154 |
+
serialize($_SERVER).
|
155 |
+
serialize($_POST).
|
156 |
+
serialize($_GET).
|
157 |
+
serialize($_COOKIE).
|
158 |
+
serialize($GLOBALS).
|
159 |
+
serialize($_SESSION).
|
160 |
+
serialize($_OLD_SESSION)
|
161 |
+
)
|
162 |
+
);
|
163 |
+
if (!isset($_SESSION['count'])) {
|
164 |
+
$_SESSION['count'] = 0;
|
165 |
+
}
|
166 |
+
$_SESSION['count']++;
|
167 |
+
|
168 |
+
session_write_close();
|
169 |
+
|
170 |
+
// Restore old session data.
|
171 |
+
if ($old_session_id != '') {
|
172 |
+
session_id($old_session_id);
|
173 |
+
session_start();
|
174 |
+
ini_set('session.use_cookies', $old_use_cookies);
|
175 |
+
session_cache_limiter($old_session_cache_limiter);
|
176 |
+
} else {
|
177 |
+
if ($_OLD_SESSION !== false) {
|
178 |
+
$_SESSION = $_OLD_SESSION;
|
179 |
+
unset($_OLD_SESSION);
|
180 |
+
} else {
|
181 |
+
unset($_SESSION);
|
182 |
+
}
|
183 |
+
}
|
184 |
+
|
185 |
+
/*
|
186 |
+
* In SSH2 a shared secret and an exchange hash are generated through the key exchange process.
|
187 |
+
* The IV client to server is the hash of that "nonce" with the letter A and for the encryption key it's the
|
188 |
+
* letter C. If the hash doesn't produce enough a key or an IV that's long enough concatenate successive hashes
|
189 |
+
* of the original hash and the current hash.
|
190 |
+
*
|
191 |
+
* @link http://tools.ietf.org/html/rfc4253#section-7.2
|
192 |
+
*/
|
193 |
+
|
194 |
+
$key = pack('H*', sha1($seed.'A'));
|
195 |
+
$iv = pack('H*', sha1($seed.'C'));
|
196 |
+
|
197 |
+
/*
|
198 |
+
* Ciphers are used as per the nist.gov.
|
199 |
+
*
|
200 |
+
* @link http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator#Designs_based_on_cryptographic_primitives
|
201 |
+
*/
|
202 |
+
$crypt = new NostoCryptAES(CRYPT_AES_MODE_CTR);
|
203 |
+
$crypt->setKey($key);
|
204 |
+
$crypt->setIV($iv);
|
205 |
+
$crypt->enableContinuousBuffer();
|
206 |
+
|
207 |
+
/*
|
208 |
+
* The following is based off of ANSI X9.31.
|
209 |
+
* OpenSSL uses that same standard for it's random numbers.
|
210 |
+
*
|
211 |
+
* @link http://csrc.nist.gov/groups/STM/cavp/documents/rng/931rngext.pdf
|
212 |
+
* @link http://www.opensource.apple.com/source/OpenSSL/OpenSSL-38/openssl/fips-1.0/rand/fips_rand.c
|
213 |
+
*/
|
214 |
+
$rnd = '';
|
215 |
+
while (strlen($rnd) < $length) {
|
216 |
+
$i = $crypt->encrypt(microtime()); // strlen(microtime()) == 21
|
217 |
+
$r = $crypt->encrypt($i ^ $v); // strlen($v) == 20
|
218 |
+
$v = $crypt->encrypt($r ^ $i); // strlen($r) == 20
|
219 |
+
$rnd .= $r;
|
220 |
+
}
|
221 |
+
return substr($rnd, 0, $length);
|
222 |
+
}
|
223 |
+
}
|
lib/nosto/php-sdk/src/libs/phpseclib/crypt/NostoCryptRijndael.php
ADDED
@@ -0,0 +1,3638 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Pure-PHP implementation of Rijndael.
|
4 |
+
*
|
5 |
+
* Uses mcrypt, if available/possible, and an internal implementation, otherwise.
|
6 |
+
*
|
7 |
+
* PHP versions 5
|
8 |
+
*
|
9 |
+
* If {@link NostoCryptRijndael::setBlockLength() setBlockLength()} isn't called, it'll be assumed to be 128 bits. If
|
10 |
+
* {@link NostoCryptRijndael::setKeyLength() setKeyLength()} isn't called, it'll be calculated from
|
11 |
+
* {@link NostoCryptRijndael::setKey() setKey()}. ie. if the key is 128-bits, the key length will be 128-bits. If it's
|
12 |
+
* 136-bits it'll be null-padded to 192-bits and 192 bits will be the key length until
|
13 |
+
* {@link NostoCryptRijndael::setKey() setKey()} is called, again, at which point, it'll be recalculated.
|
14 |
+
*
|
15 |
+
* Not all Rijndael implementations may support 160-bits or 224-bits as the block length / key length. mcrypt, for
|
16 |
+
* example, does not. AES, itself, only supports block lengths of 128 and key lengths of 128, 192, and 256.
|
17 |
+
* {@link http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf#page=10 Rijndael-ammended.pdf#page=10} defines
|
18 |
+
* the algorithm for block lengths of 192 and 256 but not for block lengths / key lengths of 160 and 224. Indeed, 160
|
19 |
+
* and 224 are first defined as valid key / block lengths in
|
20 |
+
* {@link http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf#page=44 Rijndael-ammended.pdf#page=44}:
|
21 |
+
* Extensions: Other block and Cipher Key lengths.
|
22 |
+
* Note: Use of 160/224-bit Keys must be explicitly set by setKeyLength(160) respectively setKeyLength(224).
|
23 |
+
*
|
24 |
+
* {@internal The variable names are the same as those in
|
25 |
+
* {@link http://www.csrc.nist.gov/publications/fips/fips197/fips-197.pdf#page=10 fips-197.pdf#page=10}.}}
|
26 |
+
*
|
27 |
+
* Here's a short example of how to use this library:
|
28 |
+
* <code>
|
29 |
+
* <?php
|
30 |
+
* $rijndael = new NostoCryptRijndael();
|
31 |
+
*
|
32 |
+
* $rijndael->setKey('abcdefghijklmnop');
|
33 |
+
*
|
34 |
+
* $size = 10 * 1024;
|
35 |
+
* $plaintext = '';
|
36 |
+
* for ($i = 0; $i < $size; $i++) {
|
37 |
+
* $plaintext.= 'a';
|
38 |
+
* }
|
39 |
+
*
|
40 |
+
* echo $rijndael->decrypt($rijndael->encrypt($plaintext));
|
41 |
+
* ?>
|
42 |
+
* </code>
|
43 |
+
*
|
44 |
+
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
|
45 |
+
* of this software and associated documentation files (the "Software"), to deal
|
46 |
+
* in the Software without restriction, including without limitation the rights
|
47 |
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
48 |
+
* copies of the Software, and to permit persons to whom the Software is
|
49 |
+
* furnished to do so, subject to the following conditions:
|
50 |
+
*
|
51 |
+
* The above copyright notice and this permission notice shall be included in
|
52 |
+
* all copies or substantial portions of the Software.
|
53 |
+
*
|
54 |
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
55 |
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
56 |
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
57 |
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
58 |
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
59 |
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
60 |
+
* THE SOFTWARE.
|
61 |
+
*
|
62 |
+
* @category Crypt
|
63 |
+
* @package NostoCryptRijndael
|
64 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
65 |
+
* @copyright MMVIII Jim Wigginton
|
66 |
+
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
67 |
+
* @link http://phpseclib.sourceforge.net
|
68 |
+
*/
|
69 |
+
|
70 |
+
/**
|
71 |
+
* Encrypt / decrypt using the Counter mode.
|
72 |
+
*
|
73 |
+
* Set to -1 since that's what Crypt/Random.php uses to index the CTR mode.
|
74 |
+
*
|
75 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29
|
76 |
+
*/
|
77 |
+
if (!defined('CRYPT_RIJNDAEL_MODE_CTR')) {
|
78 |
+
define('CRYPT_RIJNDAEL_MODE_CTR', CRYPT_MODE_CTR);
|
79 |
+
}
|
80 |
+
/**
|
81 |
+
* Encrypt / decrypt using the Electronic Code Book mode.
|
82 |
+
*
|
83 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Electronic_codebook_.28ECB.29
|
84 |
+
*/
|
85 |
+
if (!defined('CRYPT_RIJNDAEL_MODE_ECB')) {
|
86 |
+
define('CRYPT_RIJNDAEL_MODE_ECB', CRYPT_MODE_ECB);
|
87 |
+
}
|
88 |
+
/**
|
89 |
+
* Encrypt / decrypt using the Code Book Chaining mode.
|
90 |
+
*
|
91 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29
|
92 |
+
*/
|
93 |
+
if (!defined('CRYPT_RIJNDAEL_MODE_CBC')) {
|
94 |
+
define('CRYPT_RIJNDAEL_MODE_CBC', CRYPT_MODE_CBC);
|
95 |
+
}
|
96 |
+
/**
|
97 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
98 |
+
*
|
99 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher_feedback_.28CFB.29
|
100 |
+
*/
|
101 |
+
if (!defined('CRYPT_RIJNDAEL_MODE_CFB')) {
|
102 |
+
define('CRYPT_RIJNDAEL_MODE_CFB', CRYPT_MODE_CFB);
|
103 |
+
}
|
104 |
+
/**
|
105 |
+
* Encrypt / decrypt using the Cipher Feedback mode.
|
106 |
+
*
|
107 |
+
* @link http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Output_feedback_.28OFB.29
|
108 |
+
*/
|
109 |
+
if (!defined('CRYPT_RIJNDAEL_MODE_OFB')) {
|
110 |
+
define('CRYPT_RIJNDAEL_MODE_OFB', CRYPT_MODE_OFB);
|
111 |
+
}
|
112 |
+
|
113 |
+
/**
|
114 |
+
* Toggles the internal implementation
|
115 |
+
*/
|
116 |
+
if (!defined('CRYPT_RIJNDAEL_MODE_INTERNAL')) {
|
117 |
+
define('CRYPT_RIJNDAEL_MODE_INTERNAL', CRYPT_MODE_INTERNAL);
|
118 |
+
}
|
119 |
+
/**
|
120 |
+
* Toggles the mcrypt implementation
|
121 |
+
*/
|
122 |
+
if (!defined('CRYPT_RIJNDAEL_MODE_MCRYPT')) {
|
123 |
+
define('CRYPT_RIJNDAEL_MODE_MCRYPT', CRYPT_MODE_MCRYPT);
|
124 |
+
}
|
125 |
+
|
126 |
+
/**
|
127 |
+
* Pure-PHP implementation of Rijndael.
|
128 |
+
*
|
129 |
+
* @author Jim Wigginton <terrafrost@php.net>
|
130 |
+
* @version 0.1.0
|
131 |
+
* @package NostoCryptRijndael
|
132 |
+
*/
|
133 |
+
class NostoCryptRijndael extends NostoCryptBase
|
134 |
+
{
|
135 |
+
/**
|
136 |
+
* The default password keySize used by setPassword()
|
137 |
+
*
|
138 |
+
* @see NostoCryptBase::passwordKeySize
|
139 |
+
* @see NostoCryptBase::setPassword()
|
140 |
+
* @var Integer
|
141 |
+
*/
|
142 |
+
public $passwordKeySize = 16;
|
143 |
+
|
144 |
+
/**
|
145 |
+
* The namespace used by the cipher for its constants.
|
146 |
+
*
|
147 |
+
* @see NostoCryptBase::constNamespace
|
148 |
+
* @var String
|
149 |
+
*/
|
150 |
+
public $constNamespace = 'RIJNDAEL';
|
151 |
+
|
152 |
+
/**
|
153 |
+
* The mcrypt specific name of the cipher
|
154 |
+
*
|
155 |
+
* Mcrypt is usable for 128/192/256-bit $blockSize/$keySize. For 160/224 not.
|
156 |
+
* NostoCryptRijndael determines automatically whether mcrypt is usable
|
157 |
+
* or not for the current $blockSize/$keySize.
|
158 |
+
* In case of, $cipherNameMcrypt will be set dynamically at run time accordingly.
|
159 |
+
*
|
160 |
+
* @see NostoCryptBase::cipherNameMcrypt
|
161 |
+
* @see NostoCryptBase::engine
|
162 |
+
* @see setupEngine()
|
163 |
+
* @var String
|
164 |
+
*/
|
165 |
+
public $cipherNameMcrypt = 'rijndael-128';
|
166 |
+
|
167 |
+
/**
|
168 |
+
* The default salt used by setPassword()
|
169 |
+
*
|
170 |
+
* @see NostoCryptBase::passwordDefaultSalt
|
171 |
+
* @see NostoCryptBase::setPassword()
|
172 |
+
* @var String
|
173 |
+
*/
|
174 |
+
public $passwordDefaultSalt = 'phpseclib';
|
175 |
+
|
176 |
+
/**
|
177 |
+
* Has the key length explicitly been set or should it be derived from the key, itself?
|
178 |
+
*
|
179 |
+
* @see setKeyLength()
|
180 |
+
* @var Boolean
|
181 |
+
*/
|
182 |
+
public $explicitKeyLength = false;
|
183 |
+
|
184 |
+
/**
|
185 |
+
* The Key Schedule
|
186 |
+
*
|
187 |
+
* @see setup()
|
188 |
+
* @var Array
|
189 |
+
*/
|
190 |
+
public $w;
|
191 |
+
|
192 |
+
/**
|
193 |
+
* The Inverse Key Schedule
|
194 |
+
*
|
195 |
+
* @see setup()
|
196 |
+
* @var Array
|
197 |
+
*/
|
198 |
+
public $dw;
|
199 |
+
|
200 |
+
/**
|
201 |
+
* The Block Length divided by 32
|
202 |
+
*
|
203 |
+
* @see setBlockLength()
|
204 |
+
* @var Integer
|
205 |
+
* @internal The max value is 256 / 32 = 8, the min value is 128 / 32 = 4. Exists in conjunction with $blockSize
|
206 |
+
* because the encryption / decryption / key schedule creation requires this number and not $blockSize. We could
|
207 |
+
* derive this from $blockSize or vice versa, but that'd mean we'd have to do multiple shift operations, so in
|
208 |
+
* lieu of that, we'll just pre-compute it once.
|
209 |
+
*
|
210 |
+
*/
|
211 |
+
public $nb = 4;
|
212 |
+
|
213 |
+
/**
|
214 |
+
* The Key Length
|
215 |
+
*
|
216 |
+
* @see setKeyLength()
|
217 |
+
* @var Integer
|
218 |
+
* @internal The max value is 256 / 8 = 32, the min value is 128 / 8 = 16. Exists in conjunction with $Nk
|
219 |
+
* because the encryption / decryption / key schedule creation requires this number and not $keySize. We could
|
220 |
+
* derive this from $keySize or vice versa, but that'd mean we'd have to do multiple shift operations, so in lieu
|
221 |
+
* of that, we'll just pre-compute it once.
|
222 |
+
*/
|
223 |
+
public $keySize = 16;
|
224 |
+
|
225 |
+
/**
|
226 |
+
* The Key Length divided by 32
|
227 |
+
*
|
228 |
+
* @see setKeyLength()
|
229 |
+
* @var Integer
|
230 |
+
* @internal The max value is 256 / 32 = 8, the min value is 128 / 32 = 4
|
231 |
+
*/
|
232 |
+
public $nk = 4;
|
233 |
+
|
234 |
+
/**
|
235 |
+
* The Number of Rounds
|
236 |
+
*
|
237 |
+
* @var Integer
|
238 |
+
* @internal The max value is 14, the min value is 10.
|
239 |
+
*/
|
240 |
+
public $nr;
|
241 |
+
|
242 |
+
/**
|
243 |
+
* Shift offsets
|
244 |
+
*
|
245 |
+
* @var Array
|
246 |
+
*/
|
247 |
+
public $c;
|
248 |
+
|
249 |
+
/**
|
250 |
+
* Holds the last used key- and blockSize information
|
251 |
+
*
|
252 |
+
* @var Array
|
253 |
+
*/
|
254 |
+
public $kl;
|
255 |
+
|
256 |
+
/**
|
257 |
+
* Precomputed mixColumns table
|
258 |
+
*
|
259 |
+
* According to <http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf#page=19> (section 5.2.1),
|
260 |
+
* precomputed tables can be used in the mixColumns phase. in that example, they're assigned t0...t3, so
|
261 |
+
* those are the names we'll use.
|
262 |
+
*
|
263 |
+
* @see NostoCryptRijndael:encryptBlock()
|
264 |
+
* @see NostoCryptRijndael:decryptBlock()
|
265 |
+
* @var Array
|
266 |
+
*/
|
267 |
+
public $t0 = array(
|
268 |
+
0xC66363A5,
|
269 |
+
0xF87C7C84,
|
270 |
+
0xEE777799,
|
271 |
+
0xF67B7B8D,
|
272 |
+
0xFFF2F20D,
|
273 |
+
0xD66B6BBD,
|
274 |
+
0xDE6F6FB1,
|
275 |
+
0x91C5C554,
|
276 |
+
0x60303050,
|
277 |
+
0x02010103,
|
278 |
+
0xCE6767A9,
|
279 |
+
0x562B2B7D,
|
280 |
+
0xE7FEFE19,
|
281 |
+
0xB5D7D762,
|
282 |
+
0x4DABABE6,
|
283 |
+
0xEC76769A,
|
284 |
+
0x8FCACA45,
|
285 |
+
0x1F82829D,
|
286 |
+
0x89C9C940,
|
287 |
+
0xFA7D7D87,
|
288 |
+
0xEFFAFA15,
|
289 |
+
0xB25959EB,
|
290 |
+
0x8E4747C9,
|
291 |
+
0xFBF0F00B,
|
292 |
+
0x41ADADEC,
|
293 |
+
0xB3D4D467,
|
294 |
+
0x5FA2A2FD,
|
295 |
+
0x45AFAFEA,
|
296 |
+
0x239C9CBF,
|
297 |
+
0x53A4A4F7,
|
298 |
+
0xE4727296,
|
299 |
+
0x9BC0C05B,
|
300 |
+
0x75B7B7C2,
|
301 |
+
0xE1FDFD1C,
|
302 |
+
0x3D9393AE,
|
303 |
+
0x4C26266A,
|
304 |
+
0x6C36365A,
|
305 |
+
0x7E3F3F41,
|
306 |
+
0xF5F7F702,
|
307 |
+
0x83CCCC4F,
|
308 |
+
0x6834345C,
|
309 |
+
0x51A5A5F4,
|
310 |
+
0xD1E5E534,
|
311 |
+
0xF9F1F108,
|
312 |
+
0xE2717193,
|
313 |
+
0xABD8D873,
|
314 |
+
0x62313153,
|
315 |
+
0x2A15153F,
|
316 |
+
0x0804040C,
|
317 |
+
0x95C7C752,
|
318 |
+
0x46232365,
|
319 |
+
0x9DC3C35E,
|
320 |
+
0x30181828,
|
321 |
+
0x379696A1,
|
322 |
+
0x0A05050F,
|
323 |
+
0x2F9A9AB5,
|
324 |
+
0x0E070709,
|
325 |
+
0x24121236,
|
326 |
+
0x1B80809B,
|
327 |
+
0xDFE2E23D,
|
328 |
+
0xCDEBEB26,
|
329 |
+
0x4E272769,
|
330 |
+
0x7FB2B2CD,
|
331 |
+
0xEA75759F,
|
332 |
+
0x1209091B,
|
333 |
+
0x1D83839E,
|
334 |
+
0x582C2C74,
|
335 |
+
0x341A1A2E,
|
336 |
+
0x361B1B2D,
|
337 |
+
0xDC6E6EB2,
|
338 |
+
0xB45A5AEE,
|
339 |
+
0x5BA0A0FB,
|
340 |
+
0xA45252F6,
|
341 |
+
0x763B3B4D,
|
342 |
+
0xB7D6D661,
|
343 |
+
0x7DB3B3CE,
|
344 |
+
0x5229297B,
|
345 |
+
0xDDE3E33E,
|
346 |
+
0x5E2F2F71,
|
347 |
+
0x13848497,
|
348 |
+
0xA65353F5,
|
349 |
+
0xB9D1D168,
|
350 |
+
0x00000000,
|
351 |
+
0xC1EDED2C,
|
352 |
+
0x40202060,
|
353 |
+
0xE3FCFC1F,
|
354 |
+
0x79B1B1C8,
|
355 |
+
0xB65B5BED,
|
356 |
+
0xD46A6ABE,
|
357 |
+
0x8DCBCB46,
|
358 |
+
0x67BEBED9,
|
359 |
+
0x7239394B,
|
360 |
+
0x944A4ADE,
|
361 |
+
0x984C4CD4,
|
362 |
+
0xB05858E8,
|
363 |
+
0x85CFCF4A,
|
364 |
+
0xBBD0D06B,
|
365 |
+
0xC5EFEF2A,
|
366 |
+
0x4FAAAAE5,
|
367 |
+
0xEDFBFB16,
|
368 |
+
0x864343C5,
|
369 |
+
0x9A4D4DD7,
|
370 |
+
0x66333355,
|
371 |
+
0x11858594,
|
372 |
+
0x8A4545CF,
|
373 |
+
0xE9F9F910,
|
374 |
+
0x04020206,
|
375 |
+
0xFE7F7F81,
|
376 |
+
0xA05050F0,
|
377 |
+
0x783C3C44,
|
378 |
+
0x259F9FBA,
|
379 |
+
0x4BA8A8E3,
|
380 |
+
0xA25151F3,
|
381 |
+
0x5DA3A3FE,
|
382 |
+
0x804040C0,
|
383 |
+
0x058F8F8A,
|
384 |
+
0x3F9292AD,
|
385 |
+
0x219D9DBC,
|
386 |
+
0x70383848,
|
387 |
+
0xF1F5F504,
|
388 |
+
0x63BCBCDF,
|
389 |
+
0x77B6B6C1,
|
390 |
+
0xAFDADA75,
|
391 |
+
0x42212163,
|
392 |
+
0x20101030,
|
393 |
+
0xE5FFFF1A,
|
394 |
+
0xFDF3F30E,
|
395 |
+
0xBFD2D26D,
|
396 |
+
0x81CDCD4C,
|
397 |
+
0x180C0C14,
|
398 |
+
0x26131335,
|
399 |
+
0xC3ECEC2F,
|
400 |
+
0xBE5F5FE1,
|
401 |
+
0x359797A2,
|
402 |
+
0x884444CC,
|
403 |
+
0x2E171739,
|
404 |
+
0x93C4C457,
|
405 |
+
0x55A7A7F2,
|
406 |
+
0xFC7E7E82,
|
407 |
+
0x7A3D3D47,
|
408 |
+
0xC86464AC,
|
409 |
+
0xBA5D5DE7,
|
410 |
+
0x3219192B,
|
411 |
+
0xE6737395,
|
412 |
+
0xC06060A0,
|
413 |
+
0x19818198,
|
414 |
+
0x9E4F4FD1,
|
415 |
+
0xA3DCDC7F,
|
416 |
+
0x44222266,
|
417 |
+
0x542A2A7E,
|
418 |
+
0x3B9090AB,
|
419 |
+
0x0B888883,
|
420 |
+
0x8C4646CA,
|
421 |
+
0xC7EEEE29,
|
422 |
+
0x6BB8B8D3,
|
423 |
+
0x2814143C,
|
424 |
+
0xA7DEDE79,
|
425 |
+
0xBC5E5EE2,
|
426 |
+
0x160B0B1D,
|
427 |
+
0xADDBDB76,
|
428 |
+
0xDBE0E03B,
|
429 |
+
0x64323256,
|
430 |
+
0x743A3A4E,
|
431 |
+
0x140A0A1E,
|
432 |
+
0x924949DB,
|
433 |
+
0x0C06060A,
|
434 |
+
0x4824246C,
|
435 |
+
0xB85C5CE4,
|
436 |
+
0x9FC2C25D,
|
437 |
+
0xBDD3D36E,
|
438 |
+
0x43ACACEF,
|
439 |
+
0xC46262A6,
|
440 |
+
0x399191A8,
|
441 |
+
0x319595A4,
|
442 |
+
0xD3E4E437,
|
443 |
+
0xF279798B,
|
444 |
+
0xD5E7E732,
|
445 |
+
0x8BC8C843,
|
446 |
+
0x6E373759,
|
447 |
+
0xDA6D6DB7,
|
448 |
+
0x018D8D8C,
|
449 |
+
0xB1D5D564,
|
450 |
+
0x9C4E4ED2,
|
451 |
+
0x49A9A9E0,
|
452 |
+
0xD86C6CB4,
|
453 |
+
0xAC5656FA,
|
454 |
+
0xF3F4F407,
|
455 |
+
0xCFEAEA25,
|
456 |
+
0xCA6565AF,
|
457 |
+
0xF47A7A8E,
|
458 |
+
0x47AEAEE9,
|
459 |
+
0x10080818,
|
460 |
+
0x6FBABAD5,
|
461 |
+
0xF0787888,
|
462 |
+
0x4A25256F,
|
463 |
+
0x5C2E2E72,
|
464 |
+
0x381C1C24,
|
465 |
+
0x57A6A6F1,
|
466 |
+
0x73B4B4C7,
|
467 |
+
0x97C6C651,
|
468 |
+
0xCBE8E823,
|
469 |
+
0xA1DDDD7C,
|
470 |
+
0xE874749C,
|
471 |
+
0x3E1F1F21,
|
472 |
+
0x964B4BDD,
|
473 |
+
0x61BDBDDC,
|
474 |
+
0x0D8B8B86,
|
475 |
+
0x0F8A8A85,
|
476 |
+
0xE0707090,
|
477 |
+
0x7C3E3E42,
|
478 |
+
0x71B5B5C4,
|
479 |
+
0xCC6666AA,
|
480 |
+
0x904848D8,
|
481 |
+
0x06030305,
|
482 |
+
0xF7F6F601,
|
483 |
+
0x1C0E0E12,
|
484 |
+
0xC26161A3,
|
485 |
+
0x6A35355F,
|
486 |
+
0xAE5757F9,
|
487 |
+
0x69B9B9D0,
|
488 |
+
0x17868691,
|
489 |
+
0x99C1C158,
|
490 |
+
0x3A1D1D27,
|
491 |
+
0x279E9EB9,
|
492 |
+
0xD9E1E138,
|
493 |
+
0xEBF8F813,
|
494 |
+
0x2B9898B3,
|
495 |
+
0x22111133,
|
496 |
+
0xD26969BB,
|
497 |
+
0xA9D9D970,
|
498 |
+
0x078E8E89,
|
499 |
+
0x339494A7,
|
500 |
+
0x2D9B9BB6,
|
501 |
+
0x3C1E1E22,
|
502 |
+
0x15878792,
|
503 |
+
0xC9E9E920,
|
504 |
+
0x87CECE49,
|
505 |
+
0xAA5555FF,
|
506 |
+
0x50282878,
|
507 |
+
0xA5DFDF7A,
|
508 |
+
0x038C8C8F,
|
509 |
+
0x59A1A1F8,
|
510 |
+
0x09898980,
|
511 |
+
0x1A0D0D17,
|
512 |
+
0x65BFBFDA,
|
513 |
+
0xD7E6E631,
|
514 |
+
0x844242C6,
|
515 |
+
0xD06868B8,
|
516 |
+
0x824141C3,
|
517 |
+
0x299999B0,
|
518 |
+
0x5A2D2D77,
|
519 |
+
0x1E0F0F11,
|
520 |
+
0x7BB0B0CB,
|
521 |
+
0xA85454FC,
|
522 |
+
0x6DBBBBD6,
|
523 |
+
0x2C16163A
|
524 |
+
);
|
525 |
+
|
526 |
+
/**
|
527 |
+
* Precomputed mixColumns table
|
528 |
+
*
|
529 |
+
* @see NostoCryptRijndael:encryptBlock()
|
530 |
+
* @see NostoCryptRijndael:decryptBlock()
|
531 |
+
* @var Array
|
532 |
+
*/
|
533 |
+
public $t1 = array(
|
534 |
+
0xA5C66363,
|
535 |
+
0x84F87C7C,
|
536 |
+
0x99EE7777,
|
537 |
+
0x8DF67B7B,
|
538 |
+
0x0DFFF2F2,
|
539 |
+
0xBDD66B6B,
|
540 |
+
0xB1DE6F6F,
|
541 |
+
0x5491C5C5,
|
542 |
+
0x50603030,
|
543 |
+
0x03020101,
|
544 |
+
0xA9CE6767,
|
545 |
+
0x7D562B2B,
|
546 |
+
0x19E7FEFE,
|
547 |
+
0x62B5D7D7,
|
548 |
+
0xE64DABAB,
|
549 |
+
0x9AEC7676,
|
550 |
+
0x458FCACA,
|
551 |
+
0x9D1F8282,
|
552 |
+
0x4089C9C9,
|
553 |
+
0x87FA7D7D,
|
554 |
+
0x15EFFAFA,
|
555 |
+
0xEBB25959,
|
556 |
+
0xC98E4747,
|
557 |
+
0x0BFBF0F0,
|
558 |
+
0xEC41ADAD,
|
559 |
+
0x67B3D4D4,
|
560 |
+
0xFD5FA2A2,
|
561 |
+
0xEA45AFAF,
|
562 |
+
0xBF239C9C,
|
563 |
+
0xF753A4A4,
|
564 |
+
0x96E47272,
|
565 |
+
0x5B9BC0C0,
|
566 |
+
0xC275B7B7,
|
567 |
+
0x1CE1FDFD,
|
568 |
+
0xAE3D9393,
|
569 |
+
0x6A4C2626,
|
570 |
+
0x5A6C3636,
|
571 |
+
0x417E3F3F,
|
572 |
+
0x02F5F7F7,
|
573 |
+
0x4F83CCCC,
|
574 |
+
0x5C683434,
|
575 |
+
0xF451A5A5,
|
576 |
+
0x34D1E5E5,
|
577 |
+
0x08F9F1F1,
|
578 |
+
0x93E27171,
|
579 |
+
0x73ABD8D8,
|
580 |
+
0x53623131,
|
581 |
+
0x3F2A1515,
|
582 |
+
0x0C080404,
|
583 |
+
0x5295C7C7,
|
584 |
+
0x65462323,
|
585 |
+
0x5E9DC3C3,
|
586 |
+
0x28301818,
|
587 |
+
0xA1379696,
|
588 |
+
0x0F0A0505,
|
589 |
+
0xB52F9A9A,
|
590 |
+
0x090E0707,
|
591 |
+
0x36241212,
|
592 |
+
0x9B1B8080,
|
593 |
+
0x3DDFE2E2,
|
594 |
+
0x26CDEBEB,
|
595 |
+
0x694E2727,
|
596 |
+
0xCD7FB2B2,
|
597 |
+
0x9FEA7575,
|
598 |
+
0x1B120909,
|
599 |
+
0x9E1D8383,
|
600 |
+
0x74582C2C,
|
601 |
+
0x2E341A1A,
|
602 |
+
0x2D361B1B,
|
603 |
+
0xB2DC6E6E,
|
604 |
+
0xEEB45A5A,
|
605 |
+
0xFB5BA0A0,
|
606 |
+
0xF6A45252,
|
607 |
+
0x4D763B3B,
|
608 |
+
0x61B7D6D6,
|
609 |
+
0xCE7DB3B3,
|
610 |
+
0x7B522929,
|
611 |
+
0x3EDDE3E3,
|
612 |
+
0x715E2F2F,
|
613 |
+
0x97138484,
|
614 |
+
0xF5A65353,
|
615 |
+
0x68B9D1D1,
|
616 |
+
0x00000000,
|
617 |
+
0x2CC1EDED,
|
618 |
+
0x60402020,
|
619 |
+
0x1FE3FCFC,
|
620 |
+
0xC879B1B1,
|
621 |
+
0xEDB65B5B,
|
622 |
+
0xBED46A6A,
|
623 |
+
0x468DCBCB,
|
624 |
+
0xD967BEBE,
|
625 |
+
0x4B723939,
|
626 |
+
0xDE944A4A,
|
627 |
+
0xD4984C4C,
|
628 |
+
0xE8B05858,
|
629 |
+
0x4A85CFCF,
|
630 |
+
0x6BBBD0D0,
|
631 |
+
0x2AC5EFEF,
|
632 |
+
0xE54FAAAA,
|
633 |
+
0x16EDFBFB,
|
634 |
+
0xC5864343,
|
635 |
+
0xD79A4D4D,
|
636 |
+
0x55663333,
|
637 |
+
0x94118585,
|
638 |
+
0xCF8A4545,
|
639 |
+
0x10E9F9F9,
|
640 |
+
0x06040202,
|
641 |
+
0x81FE7F7F,
|
642 |
+
0xF0A05050,
|
643 |
+
0x44783C3C,
|
644 |
+
0xBA259F9F,
|
645 |
+
0xE34BA8A8,
|
646 |
+
0xF3A25151,
|
647 |
+
0xFE5DA3A3,
|
648 |
+
0xC0804040,
|
649 |
+
0x8A058F8F,
|
650 |
+
0xAD3F9292,
|
651 |
+
0xBC219D9D,
|
652 |
+
0x48703838,
|
653 |
+
0x04F1F5F5,
|
654 |
+
0xDF63BCBC,
|
655 |
+
0xC177B6B6,
|
656 |
+
0x75AFDADA,
|
657 |
+
0x63422121,
|
658 |
+
0x30201010,
|
659 |
+
0x1AE5FFFF,
|
660 |
+
0x0EFDF3F3,
|
661 |
+
0x6DBFD2D2,
|
662 |
+
0x4C81CDCD,
|
663 |
+
0x14180C0C,
|
664 |
+
0x35261313,
|
665 |
+
0x2FC3ECEC,
|
666 |
+
0xE1BE5F5F,
|
667 |
+
0xA2359797,
|
668 |
+
0xCC884444,
|
669 |
+
0x392E1717,
|
670 |
+
0x5793C4C4,
|
671 |
+
0xF255A7A7,
|
672 |
+
0x82FC7E7E,
|
673 |
+
0x477A3D3D,
|
674 |
+
0xACC86464,
|
675 |
+
0xE7BA5D5D,
|
676 |
+
0x2B321919,
|
677 |
+
0x95E67373,
|
678 |
+
0xA0C06060,
|
679 |
+
0x98198181,
|
680 |
+
0xD19E4F4F,
|
681 |
+
0x7FA3DCDC,
|
682 |
+
0x66442222,
|
683 |
+
0x7E542A2A,
|
684 |
+
0xAB3B9090,
|
685 |
+
0x830B8888,
|
686 |
+
0xCA8C4646,
|
687 |
+
0x29C7EEEE,
|
688 |
+
0xD36BB8B8,
|
689 |
+
0x3C281414,
|
690 |
+
0x79A7DEDE,
|
691 |
+
0xE2BC5E5E,
|
692 |
+
0x1D160B0B,
|
693 |
+
0x76ADDBDB,
|
694 |
+
0x3BDBE0E0,
|
695 |
+
0x56643232,
|
696 |
+
0x4E743A3A,
|
697 |
+
0x1E140A0A,
|
698 |
+
0xDB924949,
|
699 |
+
0x0A0C0606,
|
700 |
+
0x6C482424,
|
701 |
+
0xE4B85C5C,
|
702 |
+
0x5D9FC2C2,
|
703 |
+
0x6EBDD3D3,
|
704 |
+
0xEF43ACAC,
|
705 |
+
0xA6C46262,
|
706 |
+
0xA8399191,
|
707 |
+
0xA4319595,
|
708 |
+
0x37D3E4E4,
|
709 |
+
0x8BF27979,
|
710 |
+
0x32D5E7E7,
|
711 |
+
0x438BC8C8,
|
712 |
+
0x596E3737,
|
713 |
+
0xB7DA6D6D,
|
714 |
+
0x8C018D8D,
|
715 |
+
0x64B1D5D5,
|
716 |
+
0xD29C4E4E,
|
717 |
+
0xE049A9A9,
|
718 |
+
0xB4D86C6C,
|
719 |
+
0xFAAC5656,
|
720 |
+
0x07F3F4F4,
|
721 |
+
0x25CFEAEA,
|
722 |
+
0xAFCA6565,
|
723 |
+
0x8EF47A7A,
|
724 |
+
0xE947AEAE,
|
725 |
+
0x18100808,
|
726 |
+
0xD56FBABA,
|
727 |
+
0x88F07878,
|
728 |
+
0x6F4A2525,
|
729 |
+
0x725C2E2E,
|
730 |
+
0x24381C1C,
|
731 |
+
0xF157A6A6,
|
732 |
+
0xC773B4B4,
|
733 |
+
0x5197C6C6,
|
734 |
+
0x23CBE8E8,
|
735 |
+
0x7CA1DDDD,
|
736 |
+
0x9CE87474,
|
737 |
+
0x213E1F1F,
|
738 |
+
0xDD964B4B,
|
739 |
+
0xDC61BDBD,
|
740 |
+
0x860D8B8B,
|
741 |
+
0x850F8A8A,
|
742 |
+
0x90E07070,
|
743 |
+
0x427C3E3E,
|
744 |
+
0xC471B5B5,
|
745 |
+
0xAACC6666,
|
746 |
+
0xD8904848,
|
747 |
+
0x05060303,
|
748 |
+
0x01F7F6F6,
|
749 |
+
0x121C0E0E,
|
750 |
+
0xA3C26161,
|
751 |
+
0x5F6A3535,
|
752 |
+
0xF9AE5757,
|
753 |
+
0xD069B9B9,
|
754 |
+
0x91178686,
|
755 |
+
0x5899C1C1,
|
756 |
+
0x273A1D1D,
|
757 |
+
0xB9279E9E,
|
758 |
+
0x38D9E1E1,
|
759 |
+
0x13EBF8F8,
|
760 |
+
0xB32B9898,
|
761 |
+
0x33221111,
|
762 |
+
0xBBD26969,
|
763 |
+
0x70A9D9D9,
|
764 |
+
0x89078E8E,
|
765 |
+
0xA7339494,
|
766 |
+
0xB62D9B9B,
|
767 |
+
0x223C1E1E,
|
768 |
+
0x92158787,
|
769 |
+
0x20C9E9E9,
|
770 |
+
0x4987CECE,
|
771 |
+
0xFFAA5555,
|
772 |
+
0x78502828,
|
773 |
+
0x7AA5DFDF,
|
774 |
+
0x8F038C8C,
|
775 |
+
0xF859A1A1,
|
776 |
+
0x80098989,
|
777 |
+
0x171A0D0D,
|
778 |
+
0xDA65BFBF,
|
779 |
+
0x31D7E6E6,
|
780 |
+
0xC6844242,
|
781 |
+
0xB8D06868,
|
782 |
+
0xC3824141,
|
783 |
+
0xB0299999,
|
784 |
+
0x775A2D2D,
|
785 |
+
0x111E0F0F,
|
786 |
+
0xCB7BB0B0,
|
787 |
+
0xFCA85454,
|
788 |
+
0xD66DBBBB,
|
789 |
+
0x3A2C1616
|
790 |
+
);
|
791 |
+
|
792 |
+
/**
|
793 |
+
* Precomputed mixColumns table
|
794 |
+
*
|
795 |
+
* @see NostoCryptRijndael:encryptBlock()
|
796 |
+
* @see NostoCryptRijndael:decryptBlock()
|
797 |
+
* @var Array
|
798 |
+
*/
|
799 |
+
public $t2 = array(
|
800 |
+
0x63A5C663,
|
801 |
+
0x7C84F87C,
|
802 |
+
0x7799EE77,
|
803 |
+
0x7B8DF67B,
|
804 |
+
0xF20DFFF2,
|
805 |
+
0x6BBDD66B,
|
806 |
+
0x6FB1DE6F,
|
807 |
+
0xC55491C5,
|
808 |
+
0x30506030,
|
809 |
+
0x01030201,
|
810 |
+
0x67A9CE67,
|
811 |
+
0x2B7D562B,
|
812 |
+
0xFE19E7FE,
|
813 |
+
0xD762B5D7,
|
814 |
+
0xABE64DAB,
|
815 |
+
0x769AEC76,
|
816 |
+
0xCA458FCA,
|
817 |
+
0x829D1F82,
|
818 |
+
0xC94089C9,
|
819 |
+
0x7D87FA7D,
|
820 |
+
0xFA15EFFA,
|
821 |
+
0x59EBB259,
|
822 |
+
0x47C98E47,
|
823 |
+
0xF00BFBF0,
|
824 |
+
0xADEC41AD,
|
825 |
+
0xD467B3D4,
|
826 |
+
0xA2FD5FA2,
|
827 |
+
0xAFEA45AF,
|
828 |
+
0x9CBF239C,
|
829 |
+
0xA4F753A4,
|
830 |
+
0x7296E472,
|
831 |
+
0xC05B9BC0,
|
832 |
+
0xB7C275B7,
|
833 |
+
0xFD1CE1FD,
|
834 |
+
0x93AE3D93,
|
835 |
+
0x266A4C26,
|
836 |
+
0x365A6C36,
|
837 |
+
0x3F417E3F,
|
838 |
+
0xF702F5F7,
|
839 |
+
0xCC4F83CC,
|
840 |
+
0x345C6834,
|
841 |
+
0xA5F451A5,
|
842 |
+
0xE534D1E5,
|
843 |
+
0xF108F9F1,
|
844 |
+
0x7193E271,
|
845 |
+
0xD873ABD8,
|
846 |
+
0x31536231,
|
847 |
+
0x153F2A15,
|
848 |
+
0x040C0804,
|
849 |
+
0xC75295C7,
|
850 |
+
0x23654623,
|
851 |
+
0xC35E9DC3,
|
852 |
+
0x18283018,
|
853 |
+
0x96A13796,
|
854 |
+
0x050F0A05,
|
855 |
+
0x9AB52F9A,
|
856 |
+
0x07090E07,
|
857 |
+
0x12362412,
|
858 |
+
0x809B1B80,
|
859 |
+
0xE23DDFE2,
|
860 |
+
0xEB26CDEB,
|
861 |
+
0x27694E27,
|
862 |
+
0xB2CD7FB2,
|
863 |
+
0x759FEA75,
|
864 |
+
0x091B1209,
|
865 |
+
0x839E1D83,
|
866 |
+
0x2C74582C,
|
867 |
+
0x1A2E341A,
|
868 |
+
0x1B2D361B,
|
869 |
+
0x6EB2DC6E,
|
870 |
+
0x5AEEB45A,
|
871 |
+
0xA0FB5BA0,
|
872 |
+
0x52F6A452,
|
873 |
+
0x3B4D763B,
|
874 |
+
0xD661B7D6,
|
875 |
+
0xB3CE7DB3,
|
876 |
+
0x297B5229,
|
877 |
+
0xE33EDDE3,
|
878 |
+
0x2F715E2F,
|
879 |
+
0x84971384,
|
880 |
+
0x53F5A653,
|
881 |
+
0xD168B9D1,
|
882 |
+
0x00000000,
|
883 |
+
0xED2CC1ED,
|
884 |
+
0x20604020,
|
885 |
+
0xFC1FE3FC,
|
886 |
+
0xB1C879B1,
|
887 |
+
0x5BEDB65B,
|
888 |
+
0x6ABED46A,
|
889 |
+
0xCB468DCB,
|
890 |
+
0xBED967BE,
|
891 |
+
0x394B7239,
|
892 |
+
0x4ADE944A,
|
893 |
+
0x4CD4984C,
|
894 |
+
0x58E8B058,
|
895 |
+
0xCF4A85CF,
|
896 |
+
0xD06BBBD0,
|
897 |
+
0xEF2AC5EF,
|
898 |
+
0xAAE54FAA,
|
899 |
+
0xFB16EDFB,
|
900 |
+
0x43C58643,
|
901 |
+
0x4DD79A4D,
|
902 |
+
0x33556633,
|
903 |
+
0x85941185,
|
904 |
+
0x45CF8A45,
|
905 |
+
0xF910E9F9,
|
906 |
+
0x02060402,
|
907 |
+
0x7F81FE7F,
|
908 |
+
0x50F0A050,
|
909 |
+
0x3C44783C,
|
910 |
+
0x9FBA259F,
|
911 |
+
0xA8E34BA8,
|
912 |
+
0x51F3A251,
|
913 |
+
0xA3FE5DA3,
|
914 |
+
0x40C08040,
|
915 |
+
0x8F8A058F,
|
916 |
+
0x92AD3F92,
|
917 |
+
0x9DBC219D,
|
918 |
+
0x38487038,
|
919 |
+
0xF504F1F5,
|
920 |
+
0xBCDF63BC,
|
921 |
+
0xB6C177B6,
|
922 |
+
0xDA75AFDA,
|
923 |
+
0x21634221,
|
924 |
+
0x10302010,
|
925 |
+
0xFF1AE5FF,
|
926 |
+
0xF30EFDF3,
|
927 |
+
0xD26DBFD2,
|
928 |
+
0xCD4C81CD,
|
929 |
+
0x0C14180C,
|
930 |
+
0x13352613,
|
931 |
+
0xEC2FC3EC,
|
932 |
+
0x5FE1BE5F,
|
933 |
+
0x97A23597,
|
934 |
+
0x44CC8844,
|
935 |
+
0x17392E17,
|
936 |
+
0xC45793C4,
|
937 |
+
0xA7F255A7,
|
938 |
+
0x7E82FC7E,
|
939 |
+
0x3D477A3D,
|
940 |
+
0x64ACC864,
|
941 |
+
0x5DE7BA5D,
|
942 |
+
0x192B3219,
|
943 |
+
0x7395E673,
|
944 |
+
0x60A0C060,
|
945 |
+
0x81981981,
|
946 |
+
0x4FD19E4F,
|
947 |
+
0xDC7FA3DC,
|
948 |
+
0x22664422,
|
949 |
+
0x2A7E542A,
|
950 |
+
0x90AB3B90,
|
951 |
+
0x88830B88,
|
952 |
+
0x46CA8C46,
|
953 |
+
0xEE29C7EE,
|
954 |
+
0xB8D36BB8,
|
955 |
+
0x143C2814,
|
956 |
+
0xDE79A7DE,
|
957 |
+
0x5EE2BC5E,
|
958 |
+
0x0B1D160B,
|
959 |
+
0xDB76ADDB,
|
960 |
+
0xE03BDBE0,
|
961 |
+
0x32566432,
|
962 |
+
0x3A4E743A,
|
963 |
+
0x0A1E140A,
|
964 |
+
0x49DB9249,
|
965 |
+
0x060A0C06,
|
966 |
+
0x246C4824,
|
967 |
+
0x5CE4B85C,
|
968 |
+
0xC25D9FC2,
|
969 |
+
0xD36EBDD3,
|
970 |
+
0xACEF43AC,
|
971 |
+
0x62A6C462,
|
972 |
+
0x91A83991,
|
973 |
+
0x95A43195,
|
974 |
+
0xE437D3E4,
|
975 |
+
0x798BF279,
|
976 |
+
0xE732D5E7,
|
977 |
+
0xC8438BC8,
|
978 |
+
0x37596E37,
|
979 |
+
0x6DB7DA6D,
|
980 |
+
0x8D8C018D,
|
981 |
+
0xD564B1D5,
|
982 |
+
0x4ED29C4E,
|
983 |
+
0xA9E049A9,
|
984 |
+
0x6CB4D86C,
|
985 |
+
0x56FAAC56,
|
986 |
+
0xF407F3F4,
|
987 |
+
0xEA25CFEA,
|
988 |
+
0x65AFCA65,
|
989 |
+
0x7A8EF47A,
|
990 |
+
0xAEE947AE,
|
991 |
+
0x08181008,
|
992 |
+
0xBAD56FBA,
|
993 |
+
0x7888F078,
|
994 |
+
0x256F4A25,
|
995 |
+
0x2E725C2E,
|
996 |
+
0x1C24381C,
|
997 |
+
0xA6F157A6,
|
998 |
+
0xB4C773B4,
|
999 |
+
0xC65197C6,
|
1000 |
+
0xE823CBE8,
|
1001 |
+
0xDD7CA1DD,
|
1002 |
+
0x749CE874,
|
1003 |
+
0x1F213E1F,
|
1004 |
+
0x4BDD964B,
|
1005 |
+
0xBDDC61BD,
|
1006 |
+
0x8B860D8B,
|
1007 |
+
0x8A850F8A,
|
1008 |
+
0x7090E070,
|
1009 |
+
0x3E427C3E,
|
1010 |
+
0xB5C471B5,
|
1011 |
+
0x66AACC66,
|
1012 |
+
0x48D89048,
|
1013 |
+
0x03050603,
|
1014 |
+
0xF601F7F6,
|
1015 |
+
0x0E121C0E,
|
1016 |
+
0x61A3C261,
|
1017 |
+
0x355F6A35,
|
1018 |
+
0x57F9AE57,
|
1019 |
+
0xB9D069B9,
|
1020 |
+
0x86911786,
|
1021 |
+
0xC15899C1,
|
1022 |
+
0x1D273A1D,
|
1023 |
+
0x9EB9279E,
|
1024 |
+
0xE138D9E1,
|
1025 |
+
0xF813EBF8,
|
1026 |
+
0x98B32B98,
|
1027 |
+
0x11332211,
|
1028 |
+
0x69BBD269,
|
1029 |
+
0xD970A9D9,
|
1030 |
+
0x8E89078E,
|
1031 |
+
0x94A73394,
|
1032 |
+
0x9BB62D9B,
|
1033 |
+
0x1E223C1E,
|
1034 |
+
0x87921587,
|
1035 |
+
0xE920C9E9,
|
1036 |
+
0xCE4987CE,
|
1037 |
+
0x55FFAA55,
|
1038 |
+
0x28785028,
|
1039 |
+
0xDF7AA5DF,
|
1040 |
+
0x8C8F038C,
|
1041 |
+
0xA1F859A1,
|
1042 |
+
0x89800989,
|
1043 |
+
0x0D171A0D,
|
1044 |
+
0xBFDA65BF,
|
1045 |
+
0xE631D7E6,
|
1046 |
+
0x42C68442,
|
1047 |
+
0x68B8D068,
|
1048 |
+
0x41C38241,
|
1049 |
+
0x99B02999,
|
1050 |
+
0x2D775A2D,
|
1051 |
+
0x0F111E0F,
|
1052 |
+
0xB0CB7BB0,
|
1053 |
+
0x54FCA854,
|
1054 |
+
0xBBD66DBB,
|
1055 |
+
0x163A2C16
|
1056 |
+
);
|
1057 |
+
|
1058 |
+
/**
|
1059 |
+
* Precomputed mixColumns table
|
1060 |
+
*
|
1061 |
+
* @see NostoCryptRijndael:encryptBlock()
|
1062 |
+
* @see NostoCryptRijndael:decryptBlock()
|
1063 |
+
* @var Array
|
1064 |
+
*/
|
1065 |
+
public $t3 = array(
|
1066 |
+
0x6363A5C6,
|
1067 |
+
0x7C7C84F8,
|
1068 |
+
0x777799EE,
|
1069 |
+
0x7B7B8DF6,
|
1070 |
+
0xF2F20DFF,
|
1071 |
+
0x6B6BBDD6,
|
1072 |
+
0x6F6FB1DE,
|
1073 |
+
0xC5C55491,
|
1074 |
+
0x30305060,
|
1075 |
+
0x01010302,
|
1076 |
+
0x6767A9CE,
|
1077 |
+
0x2B2B7D56,
|
1078 |
+
0xFEFE19E7,
|
1079 |
+
0xD7D762B5,
|
1080 |
+
0xABABE64D,
|
1081 |
+
0x76769AEC,
|
1082 |
+
0xCACA458F,
|
1083 |
+
0x82829D1F,
|
1084 |
+
0xC9C94089,
|
1085 |
+
0x7D7D87FA,
|
1086 |
+
0xFAFA15EF,
|
1087 |
+
0x5959EBB2,
|
1088 |
+
0x4747C98E,
|
1089 |
+
0xF0F00BFB,
|
1090 |
+
0xADADEC41,
|
1091 |
+
0xD4D467B3,
|
1092 |
+
0xA2A2FD5F,
|
1093 |
+
0xAFAFEA45,
|
1094 |
+
0x9C9CBF23,
|
1095 |
+
0xA4A4F753,
|
1096 |
+
0x727296E4,
|
1097 |
+
0xC0C05B9B,
|
1098 |
+
0xB7B7C275,
|
1099 |
+
0xFDFD1CE1,
|
1100 |
+
0x9393AE3D,
|
1101 |
+
0x26266A4C,
|
1102 |
+
0x36365A6C,
|
1103 |
+
0x3F3F417E,
|
1104 |
+
0xF7F702F5,
|
1105 |
+
0xCCCC4F83,
|
1106 |
+
0x34345C68,
|
1107 |
+
0xA5A5F451,
|
1108 |
+
0xE5E534D1,
|
1109 |
+
0xF1F108F9,
|
1110 |
+
0x717193E2,
|
1111 |
+
0xD8D873AB,
|
1112 |
+
0x31315362,
|
1113 |
+
0x15153F2A,
|
1114 |
+
0x04040C08,
|
1115 |
+
0xC7C75295,
|
1116 |
+
0x23236546,
|
1117 |
+
0xC3C35E9D,
|
1118 |
+
0x18182830,
|
1119 |
+
0x9696A137,
|
1120 |
+
0x05050F0A,
|
1121 |
+
0x9A9AB52F,
|
1122 |
+
0x0707090E,
|
1123 |
+
0x12123624,
|
1124 |
+
0x80809B1B,
|
1125 |
+
0xE2E23DDF,
|
1126 |
+
0xEBEB26CD,
|
1127 |
+
0x2727694E,
|
1128 |
+
0xB2B2CD7F,
|
1129 |
+
0x75759FEA,
|
1130 |
+
0x09091B12,
|
1131 |
+
0x83839E1D,
|
1132 |
+
0x2C2C7458,
|
1133 |
+
0x1A1A2E34,
|
1134 |
+
0x1B1B2D36,
|
1135 |
+
0x6E6EB2DC,
|
1136 |
+
0x5A5AEEB4,
|
1137 |
+
0xA0A0FB5B,
|
1138 |
+
0x5252F6A4,
|
1139 |
+
0x3B3B4D76,
|
1140 |
+
0xD6D661B7,
|
1141 |
+
0xB3B3CE7D,
|
1142 |
+
0x29297B52,
|
1143 |
+
0xE3E33EDD,
|
1144 |
+
0x2F2F715E,
|
1145 |
+
0x84849713,
|
1146 |
+
0x5353F5A6,
|
1147 |
+
0xD1D168B9,
|
1148 |
+
0x00000000,
|
1149 |
+
0xEDED2CC1,
|
1150 |
+
0x20206040,
|
1151 |
+
0xFCFC1FE3,
|
1152 |
+
0xB1B1C879,
|
1153 |
+
0x5B5BEDB6,
|
1154 |
+
0x6A6ABED4,
|
1155 |
+
0xCBCB468D,
|
1156 |
+
0xBEBED967,
|
1157 |
+
0x39394B72,
|
1158 |
+
0x4A4ADE94,
|
1159 |
+
0x4C4CD498,
|
1160 |
+
0x5858E8B0,
|
1161 |
+
0xCFCF4A85,
|
1162 |
+
0xD0D06BBB,
|
1163 |
+
0xEFEF2AC5,
|
1164 |
+
0xAAAAE54F,
|
1165 |
+
0xFBFB16ED,
|
1166 |
+
0x4343C586,
|
1167 |
+
0x4D4DD79A,
|
1168 |
+
0x33335566,
|
1169 |
+
0x85859411,
|
1170 |
+
0x4545CF8A,
|
1171 |
+
0xF9F910E9,
|
1172 |
+
0x02020604,
|
1173 |
+
0x7F7F81FE,
|
1174 |
+
0x5050F0A0,
|
1175 |
+
0x3C3C4478,
|
1176 |
+
0x9F9FBA25,
|
1177 |
+
0xA8A8E34B,
|
1178 |
+
0x5151F3A2,
|
1179 |
+
0xA3A3FE5D,
|
1180 |
+
0x4040C080,
|
1181 |
+
0x8F8F8A05,
|
1182 |
+
0x9292AD3F,
|
1183 |
+
0x9D9DBC21,
|
1184 |
+
0x38384870,
|
1185 |
+
0xF5F504F1,
|
1186 |
+
0xBCBCDF63,
|
1187 |
+
0xB6B6C177,
|
1188 |
+
0xDADA75AF,
|
1189 |
+
0x21216342,
|
1190 |
+
0x10103020,
|
1191 |
+
0xFFFF1AE5,
|
1192 |
+
0xF3F30EFD,
|
1193 |
+
0xD2D26DBF,
|
1194 |
+
0xCDCD4C81,
|
1195 |
+
0x0C0C1418,
|
1196 |
+
0x13133526,
|
1197 |
+
0xECEC2FC3,
|
1198 |
+
0x5F5FE1BE,
|
1199 |
+
0x9797A235,
|
1200 |
+
0x4444CC88,
|
1201 |
+
0x1717392E,
|
1202 |
+
0xC4C45793,
|
1203 |
+
0xA7A7F255,
|
1204 |
+
0x7E7E82FC,
|
1205 |
+
0x3D3D477A,
|
1206 |
+
0x6464ACC8,
|
1207 |
+
0x5D5DE7BA,
|
1208 |
+
0x19192B32,
|
1209 |
+
0x737395E6,
|
1210 |
+
0x6060A0C0,
|
1211 |
+
0x81819819,
|
1212 |
+
0x4F4FD19E,
|
1213 |
+
0xDCDC7FA3,
|
1214 |
+
0x22226644,
|
1215 |
+
0x2A2A7E54,
|
1216 |
+
0x9090AB3B,
|
1217 |
+
0x8888830B,
|
1218 |
+
0x4646CA8C,
|
1219 |
+
0xEEEE29C7,
|
1220 |
+
0xB8B8D36B,
|
1221 |
+
0x14143C28,
|
1222 |
+
0xDEDE79A7,
|
1223 |
+
0x5E5EE2BC,
|
1224 |
+
0x0B0B1D16,
|
1225 |
+
0xDBDB76AD,
|
1226 |
+
0xE0E03BDB,
|
1227 |
+
0x32325664,
|
1228 |
+
0x3A3A4E74,
|
1229 |
+
0x0A0A1E14,
|
1230 |
+
0x4949DB92,
|
1231 |
+
0x06060A0C,
|
1232 |
+
0x24246C48,
|
1233 |
+
0x5C5CE4B8,
|
1234 |
+
0xC2C25D9F,
|
1235 |
+
0xD3D36EBD,
|
1236 |
+
0xACACEF43,
|
1237 |
+
0x6262A6C4,
|
1238 |
+
0x9191A839,
|
1239 |
+
0x9595A431,
|
1240 |
+
0xE4E437D3,
|
1241 |
+
0x79798BF2,
|
1242 |
+
0xE7E732D5,
|
1243 |
+
0xC8C8438B,
|
1244 |
+
0x3737596E,
|
1245 |
+
0x6D6DB7DA,
|
1246 |
+
0x8D8D8C01,
|
1247 |
+
0xD5D564B1,
|
1248 |
+
0x4E4ED29C,
|
1249 |
+
0xA9A9E049,
|
1250 |
+
0x6C6CB4D8,
|
1251 |
+
0x5656FAAC,
|
1252 |
+
0xF4F407F3,
|
1253 |
+
0xEAEA25CF,
|
1254 |
+
0x6565AFCA,
|
1255 |
+
0x7A7A8EF4,
|
1256 |
+
0xAEAEE947,
|
1257 |
+
0x08081810,
|
1258 |
+
0xBABAD56F,
|
1259 |
+
0x787888F0,
|
1260 |
+
0x25256F4A,
|
1261 |
+
0x2E2E725C,
|
1262 |
+
0x1C1C2438,
|
1263 |
+
0xA6A6F157,
|
1264 |
+
0xB4B4C773,
|
1265 |
+
0xC6C65197,
|
1266 |
+
0xE8E823CB,
|
1267 |
+
0xDDDD7CA1,
|
1268 |
+
0x74749CE8,
|
1269 |
+
0x1F1F213E,
|
1270 |
+
0x4B4BDD96,
|
1271 |
+
0xBDBDDC61,
|
1272 |
+
0x8B8B860D,
|
1273 |
+
0x8A8A850F,
|
1274 |
+
0x707090E0,
|
1275 |
+
0x3E3E427C,
|
1276 |
+
0xB5B5C471,
|
1277 |
+
0x6666AACC,
|
1278 |
+
0x4848D890,
|
1279 |
+
0x03030506,
|
1280 |
+
0xF6F601F7,
|
1281 |
+
0x0E0E121C,
|
1282 |
+
0x6161A3C2,
|
1283 |
+
0x35355F6A,
|
1284 |
+
0x5757F9AE,
|
1285 |
+
0xB9B9D069,
|
1286 |
+
0x86869117,
|
1287 |
+
0xC1C15899,
|
1288 |
+
0x1D1D273A,
|
1289 |
+
0x9E9EB927,
|
1290 |
+
0xE1E138D9,
|
1291 |
+
0xF8F813EB,
|
1292 |
+
0x9898B32B,
|
1293 |
+
0x11113322,
|
1294 |
+
0x6969BBD2,
|
1295 |
+
0xD9D970A9,
|
1296 |
+
0x8E8E8907,
|
1297 |
+
0x9494A733,
|
1298 |
+
0x9B9BB62D,
|
1299 |
+
0x1E1E223C,
|
1300 |
+
0x87879215,
|
1301 |
+
0xE9E920C9,
|
1302 |
+
0xCECE4987,
|
1303 |
+
0x5555FFAA,
|
1304 |
+
0x28287850,
|
1305 |
+
0xDFDF7AA5,
|
1306 |
+
0x8C8C8F03,
|
1307 |
+
0xA1A1F859,
|
1308 |
+
0x89898009,
|
1309 |
+
0x0D0D171A,
|
1310 |
+
0xBFBFDA65,
|
1311 |
+
0xE6E631D7,
|
1312 |
+
0x4242C684,
|
1313 |
+
0x6868B8D0,
|
1314 |
+
0x4141C382,
|
1315 |
+
0x9999B029,
|
1316 |
+
0x2D2D775A,
|
1317 |
+
0x0F0F111E,
|
1318 |
+
0xB0B0CB7B,
|
1319 |
+
0x5454FCA8,
|
1320 |
+
0xBBBBD66D,
|
1321 |
+
0x16163A2C
|
1322 |
+
);
|
1323 |
+
|
1324 |
+
/**
|
1325 |
+
* Precomputed invMixColumns table
|
1326 |
+
*
|
1327 |
+
* @see NostoCryptRijndael:encryptBlock()
|
1328 |
+
* @see NostoCryptRijndael:decryptBlock()
|
1329 |
+
* @var Array
|
1330 |
+
*/
|
1331 |
+
public $dt0 = array(
|
1332 |
+
0x51F4A750,
|
1333 |
+
0x7E416553,
|
1334 |
+
0x1A17A4C3,
|
1335 |
+
0x3A275E96,
|
1336 |
+
0x3BAB6BCB,
|
1337 |
+
0x1F9D45F1,
|
1338 |
+
0xACFA58AB,
|
1339 |
+
0x4BE30393,
|
1340 |
+
0x2030FA55,
|
1341 |
+
0xAD766DF6,
|
1342 |
+
0x88CC7691,
|
1343 |
+
0xF5024C25,
|
1344 |
+
0x4FE5D7FC,
|
1345 |
+
0xC52ACBD7,
|
1346 |
+
0x26354480,
|
1347 |
+
0xB562A38F,
|
1348 |
+
0xDEB15A49,
|
1349 |
+
0x25BA1B67,
|
1350 |
+
0x45EA0E98,
|
1351 |
+
0x5DFEC0E1,
|
1352 |
+
0xC32F7502,
|
1353 |
+
0x814CF012,
|
1354 |
+
0x8D4697A3,
|
1355 |
+
0x6BD3F9C6,
|
1356 |
+
0x038F5FE7,
|
1357 |
+
0x15929C95,
|
1358 |
+
0xBF6D7AEB,
|
1359 |
+
0x955259DA,
|
1360 |
+
0xD4BE832D,
|
1361 |
+
0x587421D3,
|
1362 |
+
0x49E06929,
|
1363 |
+
0x8EC9C844,
|
1364 |
+
0x75C2896A,
|
1365 |
+
0xF48E7978,
|
1366 |
+
0x99583E6B,
|
1367 |
+
0x27B971DD,
|
1368 |
+
0xBEE14FB6,
|
1369 |
+
0xF088AD17,
|
1370 |
+
0xC920AC66,
|
1371 |
+
0x7DCE3AB4,
|
1372 |
+
0x63DF4A18,
|
1373 |
+
0xE51A3182,
|
1374 |
+
0x97513360,
|
1375 |
+
0x62537F45,
|
1376 |
+
0xB16477E0,
|
1377 |
+
0xBB6BAE84,
|
1378 |
+
0xFE81A01C,
|
1379 |
+
0xF9082B94,
|
1380 |
+
0x70486858,
|
1381 |
+
0x8F45FD19,
|
1382 |
+
0x94DE6C87,
|
1383 |
+
0x527BF8B7,
|
1384 |
+
0xAB73D323,
|
1385 |
+
0x724B02E2,
|
1386 |
+
0xE31F8F57,
|
1387 |
+
0x6655AB2A,
|
1388 |
+
0xB2EB2807,
|
1389 |
+
0x2FB5C203,
|
1390 |
+
0x86C57B9A,
|
1391 |
+
0xD33708A5,
|
1392 |
+
0x302887F2,
|
1393 |
+
0x23BFA5B2,
|
1394 |
+
0x02036ABA,
|
1395 |
+
0xED16825C,
|
1396 |
+
0x8ACF1C2B,
|
1397 |
+
0xA779B492,
|
1398 |
+
0xF307F2F0,
|
1399 |
+
0x4E69E2A1,
|
1400 |
+
0x65DAF4CD,
|
1401 |
+
0x0605BED5,
|
1402 |
+
0xD134621F,
|
1403 |
+
0xC4A6FE8A,
|
1404 |
+
0x342E539D,
|
1405 |
+
0xA2F355A0,
|
1406 |
+
0x058AE132,
|
1407 |
+
0xA4F6EB75,
|
1408 |
+
0x0B83EC39,
|
1409 |
+
0x4060EFAA,
|
1410 |
+
0x5E719F06,
|
1411 |
+
0xBD6E1051,
|
1412 |
+
0x3E218AF9,
|
1413 |
+
0x96DD063D,
|
1414 |
+
0xDD3E05AE,
|
1415 |
+
0x4DE6BD46,
|
1416 |
+
0x91548DB5,
|
1417 |
+
0x71C45D05,
|
1418 |
+
0x0406D46F,
|
1419 |
+
0x605015FF,
|
1420 |
+
0x1998FB24,
|
1421 |
+
0xD6BDE997,
|
1422 |
+
0x894043CC,
|
1423 |
+
0x67D99E77,
|
1424 |
+
0xB0E842BD,
|
1425 |
+
0x07898B88,
|
1426 |
+
0xE7195B38,
|
1427 |
+
0x79C8EEDB,
|
1428 |
+
0xA17C0A47,
|
1429 |
+
0x7C420FE9,
|
1430 |
+
0xF8841EC9,
|
1431 |
+
0x00000000,
|
1432 |
+
0x09808683,
|
1433 |
+
0x322BED48,
|
1434 |
+
0x1E1170AC,
|
1435 |
+
0x6C5A724E,
|
1436 |
+
0xFD0EFFFB,
|
1437 |
+
0x0F853856,
|
1438 |
+
0x3DAED51E,
|
1439 |
+
0x362D3927,
|
1440 |
+
0x0A0FD964,
|
1441 |
+
0x685CA621,
|
1442 |
+
0x9B5B54D1,
|
1443 |
+
0x24362E3A,
|
1444 |
+
0x0C0A67B1,
|
1445 |
+
0x9357E70F,
|
1446 |
+
0xB4EE96D2,
|
1447 |
+
0x1B9B919E,
|
1448 |
+
0x80C0C54F,
|
1449 |
+
0x61DC20A2,
|
1450 |
+
0x5A774B69,
|
1451 |
+
0x1C121A16,
|
1452 |
+
0xE293BA0A,
|
1453 |
+
0xC0A02AE5,
|
1454 |
+
0x3C22E043,
|
1455 |
+
0x121B171D,
|
1456 |
+
0x0E090D0B,
|
1457 |
+
0xF28BC7AD,
|
1458 |
+
0x2DB6A8B9,
|
1459 |
+
0x141EA9C8,
|
1460 |
+
0x57F11985,
|
1461 |
+
0xAF75074C,
|
1462 |
+
0xEE99DDBB,
|
1463 |
+
0xA37F60FD,
|
1464 |
+
0xF701269F,
|
1465 |
+
0x5C72F5BC,
|
1466 |
+
0x44663BC5,
|
1467 |
+
0x5BFB7E34,
|
1468 |
+
0x8B432976,
|
1469 |
+
0xCB23C6DC,
|
1470 |
+
0xB6EDFC68,
|
1471 |
+
0xB8E4F163,
|
1472 |
+
0xD731DCCA,
|
1473 |
+
0x42638510,
|
1474 |
+
0x13972240,
|
1475 |
+
0x84C61120,
|
1476 |
+
0x854A247D,
|
1477 |
+
0xD2BB3DF8,
|
1478 |
+
0xAEF93211,
|
1479 |
+
0xC729A16D,
|
1480 |
+
0x1D9E2F4B,
|
1481 |
+
0xDCB230F3,
|
1482 |
+
0x0D8652EC,
|
1483 |
+
0x77C1E3D0,
|
1484 |
+
0x2BB3166C,
|
1485 |
+
0xA970B999,
|
1486 |
+
0x119448FA,
|
1487 |
+
0x47E96422,
|
1488 |
+
0xA8FC8CC4,
|
1489 |
+
0xA0F03F1A,
|
1490 |
+
0x567D2CD8,
|
1491 |
+
0x223390EF,
|
1492 |
+
0x87494EC7,
|
1493 |
+
0xD938D1C1,
|
1494 |
+
0x8CCAA2FE,
|
1495 |
+
0x98D40B36,
|
1496 |
+
0xA6F581CF,
|
1497 |
+
0xA57ADE28,
|
1498 |
+
0xDAB78E26,
|
1499 |
+
0x3FADBFA4,
|
1500 |
+
0x2C3A9DE4,
|
1501 |
+
0x5078920D,
|
1502 |
+
0x6A5FCC9B,
|
1503 |
+
0x547E4662,
|
1504 |
+
0xF68D13C2,
|
1505 |
+
0x90D8B8E8,
|
1506 |
+
0x2E39F75E,
|
1507 |
+
0x82C3AFF5,
|
1508 |
+
0x9F5D80BE,
|
1509 |
+
0x69D0937C,
|
1510 |
+
0x6FD52DA9,
|
1511 |
+
0xCF2512B3,
|
1512 |
+
0xC8AC993B,
|
1513 |
+
0x10187DA7,
|
1514 |
+
0xE89C636E,
|
1515 |
+
0xDB3BBB7B,
|
1516 |
+
0xCD267809,
|
1517 |
+
0x6E5918F4,
|
1518 |
+
0xEC9AB701,
|
1519 |
+
0x834F9AA8,
|
1520 |
+
0xE6956E65,
|
1521 |
+
0xAAFFE67E,
|
1522 |
+
0x21BCCF08,
|
1523 |
+
0xEF15E8E6,
|
1524 |
+
0xBAE79BD9,
|
1525 |
+
0x4A6F36CE,
|
1526 |
+
0xEA9F09D4,
|
1527 |
+
0x29B07CD6,
|
1528 |
+
0x31A4B2AF,
|
1529 |
+
0x2A3F2331,
|
1530 |
+
0xC6A59430,
|
1531 |
+
0x35A266C0,
|
1532 |
+
0x744EBC37,
|
1533 |
+
0xFC82CAA6,
|
1534 |
+
0xE090D0B0,
|
1535 |
+
0x33A7D815,
|
1536 |
+
0xF104984A,
|
1537 |
+
0x41ECDAF7,
|
1538 |
+
0x7FCD500E,
|
1539 |
+
0x1791F62F,
|
1540 |
+
0x764DD68D,
|
1541 |
+
0x43EFB04D,
|
1542 |
+
0xCCAA4D54,
|
1543 |
+
0xE49604DF,
|
1544 |
+
0x9ED1B5E3,
|
1545 |
+
0x4C6A881B,
|
1546 |
+
0xC12C1FB8,
|
1547 |
+
0x4665517F,
|
1548 |
+
0x9D5EEA04,
|
1549 |
+
0x018C355D,
|
1550 |
+
0xFA877473,
|
1551 |
+
0xFB0B412E,
|
1552 |
+
0xB3671D5A,
|
1553 |
+
0x92DBD252,
|
1554 |
+
0xE9105633,
|
1555 |
+
0x6DD64713,
|
1556 |
+
0x9AD7618C,
|
1557 |
+
0x37A10C7A,
|
1558 |
+
0x59F8148E,
|
1559 |
+
0xEB133C89,
|
1560 |
+
0xCEA927EE,
|
1561 |
+
0xB761C935,
|
1562 |
+
0xE11CE5ED,
|
1563 |
+
0x7A47B13C,
|
1564 |
+
0x9CD2DF59,
|
1565 |
+
0x55F2733F,
|
1566 |
+
0x1814CE79,
|
1567 |
+
0x73C737BF,
|
1568 |
+
0x53F7CDEA,
|
1569 |
+
0x5FFDAA5B,
|
1570 |
+
0xDF3D6F14,
|
1571 |
+
0x7844DB86,
|
1572 |
+
0xCAAFF381,
|
1573 |
+
0xB968C43E,
|
1574 |
+
0x3824342C,
|
1575 |
+
0xC2A3405F,
|
1576 |
+
0x161DC372,
|
1577 |
+
0xBCE2250C,
|
1578 |
+
0x283C498B,
|
1579 |
+
0xFF0D9541,
|
1580 |
+
0x39A80171,
|
1581 |
+
0x080CB3DE,
|
1582 |
+
0xD8B4E49C,
|
1583 |
+
0x6456C190,
|
1584 |
+
0x7BCB8461,
|
1585 |
+
0xD532B670,
|
1586 |
+
0x486C5C74,
|
1587 |
+
0xD0B85742
|
1588 |
+
);
|
1589 |
+
|
1590 |
+
/**
|
1591 |
+
* Precomputed invMixColumns table
|
1592 |
+
*
|
1593 |
+
* @see NostoCryptRijndael:encryptBlock()
|
1594 |
+
* @see NostoCryptRijndael:decryptBlock()
|
1595 |
+
* @var Array
|
1596 |
+
*/
|
1597 |
+
public $dt1 = array(
|
1598 |
+
0x5051F4A7,
|
1599 |
+
0x537E4165,
|
1600 |
+
0xC31A17A4,
|
1601 |
+
0x963A275E,
|
1602 |
+
0xCB3BAB6B,
|
1603 |
+
0xF11F9D45,
|
1604 |
+
0xABACFA58,
|
1605 |
+
0x934BE303,
|
1606 |
+
0x552030FA,
|
1607 |
+
0xF6AD766D,
|
1608 |
+
0x9188CC76,
|
1609 |
+
0x25F5024C,
|
1610 |
+
0xFC4FE5D7,
|
1611 |
+
0xD7C52ACB,
|
1612 |
+
0x80263544,
|
1613 |
+
0x8FB562A3,
|
1614 |
+
0x49DEB15A,
|
1615 |
+
0x6725BA1B,
|
1616 |
+
0x9845EA0E,
|
1617 |
+
0xE15DFEC0,
|
1618 |
+
0x02C32F75,
|
1619 |
+
0x12814CF0,
|
1620 |
+
0xA38D4697,
|
1621 |
+
0xC66BD3F9,
|
1622 |
+
0xE7038F5F,
|
1623 |
+
0x9515929C,
|
1624 |
+
0xEBBF6D7A,
|
1625 |
+
0xDA955259,
|
1626 |
+
0x2DD4BE83,
|
1627 |
+
0xD3587421,
|
1628 |
+
0x2949E069,
|
1629 |
+
0x448EC9C8,
|
1630 |
+
0x6A75C289,
|
1631 |
+
0x78F48E79,
|
1632 |
+
0x6B99583E,
|
1633 |
+
0xDD27B971,
|
1634 |
+
0xB6BEE14F,
|
1635 |
+
0x17F088AD,
|
1636 |
+
0x66C920AC,
|
1637 |
+
0xB47DCE3A,
|
1638 |
+
0x1863DF4A,
|
1639 |
+
0x82E51A31,
|
1640 |
+
0x60975133,
|
1641 |
+
0x4562537F,
|
1642 |
+
0xE0B16477,
|
1643 |
+
0x84BB6BAE,
|
1644 |
+
0x1CFE81A0,
|
1645 |
+
0x94F9082B,
|
1646 |
+
0x58704868,
|
1647 |
+
0x198F45FD,
|
1648 |
+
0x8794DE6C,
|
1649 |
+
0xB7527BF8,
|
1650 |
+
0x23AB73D3,
|
1651 |
+
0xE2724B02,
|
1652 |
+
0x57E31F8F,
|
1653 |
+
0x2A6655AB,
|
1654 |
+
0x07B2EB28,
|
1655 |
+
0x032FB5C2,
|
1656 |
+
0x9A86C57B,
|
1657 |
+
0xA5D33708,
|
1658 |
+
0xF2302887,
|
1659 |
+
0xB223BFA5,
|
1660 |
+
0xBA02036A,
|
1661 |
+
0x5CED1682,
|
1662 |
+
0x2B8ACF1C,
|
1663 |
+
0x92A779B4,
|
1664 |
+
0xF0F307F2,
|
1665 |
+
0xA14E69E2,
|
1666 |
+
0xCD65DAF4,
|
1667 |
+
0xD50605BE,
|
1668 |
+
0x1FD13462,
|
1669 |
+
0x8AC4A6FE,
|
1670 |
+
0x9D342E53,
|
1671 |
+
0xA0A2F355,
|
1672 |
+
0x32058AE1,
|
1673 |
+
0x75A4F6EB,
|
1674 |
+
0x390B83EC,
|
1675 |
+
0xAA4060EF,
|
1676 |
+
0x065E719F,
|
1677 |
+
0x51BD6E10,
|
1678 |
+
0xF93E218A,
|
1679 |
+
0x3D96DD06,
|
1680 |
+
0xAEDD3E05,
|
1681 |
+
0x464DE6BD,
|
1682 |
+
0xB591548D,
|
1683 |
+
0x0571C45D,
|
1684 |
+
0x6F0406D4,
|
1685 |
+
0xFF605015,
|
1686 |
+
0x241998FB,
|
1687 |
+
0x97D6BDE9,
|
1688 |
+
0xCC894043,
|
1689 |
+
0x7767D99E,
|
1690 |
+
0xBDB0E842,
|
1691 |
+
0x8807898B,
|
1692 |
+
0x38E7195B,
|
1693 |
+
0xDB79C8EE,
|
1694 |
+
0x47A17C0A,
|
1695 |
+
0xE97C420F,
|
1696 |
+
0xC9F8841E,
|
1697 |
+
0x00000000,
|
1698 |
+
0x83098086,
|
1699 |
+
0x48322BED,
|
1700 |
+
0xAC1E1170,
|
1701 |
+
0x4E6C5A72,
|
1702 |
+
0xFBFD0EFF,
|
1703 |
+
0x560F8538,
|
1704 |
+
0x1E3DAED5,
|
1705 |
+
0x27362D39,
|
1706 |
+
0x640A0FD9,
|
1707 |
+
0x21685CA6,
|
1708 |
+
0xD19B5B54,
|
1709 |
+
0x3A24362E,
|
1710 |
+
0xB10C0A67,
|
1711 |
+
0x0F9357E7,
|
1712 |
+
0xD2B4EE96,
|
1713 |
+
0x9E1B9B91,
|
1714 |
+
0x4F80C0C5,
|
1715 |
+
0xA261DC20,
|
1716 |
+
0x695A774B,
|
1717 |
+
0x161C121A,
|
1718 |
+
0x0AE293BA,
|
1719 |
+
0xE5C0A02A,
|
1720 |
+
0x433C22E0,
|
1721 |
+
0x1D121B17,
|
1722 |
+
0x0B0E090D,
|
1723 |
+
0xADF28BC7,
|
1724 |
+
0xB92DB6A8,
|
1725 |
+
0xC8141EA9,
|
1726 |
+
0x8557F119,
|
1727 |
+
0x4CAF7507,
|
1728 |
+
0xBBEE99DD,
|
1729 |
+
0xFDA37F60,
|
1730 |
+
0x9FF70126,
|
1731 |
+
0xBC5C72F5,
|
1732 |
+
0xC544663B,
|
1733 |
+
0x345BFB7E,
|
1734 |
+
0x768B4329,
|
1735 |
+
0xDCCB23C6,
|
1736 |
+
0x68B6EDFC,
|
1737 |
+
0x63B8E4F1,
|
1738 |
+
0xCAD731DC,
|
1739 |
+
0x10426385,
|
1740 |
+
0x40139722,
|
1741 |
+
0x2084C611,
|
1742 |
+
0x7D854A24,
|
1743 |
+
0xF8D2BB3D,
|
1744 |
+
0x11AEF932,
|
1745 |
+
0x6DC729A1,
|
1746 |
+
0x4B1D9E2F,
|
1747 |
+
0xF3DCB230,
|
1748 |
+
0xEC0D8652,
|
1749 |
+
0xD077C1E3,
|
1750 |
+
0x6C2BB316,
|
1751 |
+
0x99A970B9,
|
1752 |
+
0xFA119448,
|
1753 |
+
0x2247E964,
|
1754 |
+
0xC4A8FC8C,
|
1755 |
+
0x1AA0F03F,
|
1756 |
+
0xD8567D2C,
|
1757 |
+
0xEF223390,
|
1758 |
+
0xC787494E,
|
1759 |
+
0xC1D938D1,
|
1760 |
+
0xFE8CCAA2,
|
1761 |
+
0x3698D40B,
|
1762 |
+
0xCFA6F581,
|
1763 |
+
0x28A57ADE,
|
1764 |
+
0x26DAB78E,
|
1765 |
+
0xA43FADBF,
|
1766 |
+
0xE42C3A9D,
|
1767 |
+
0x0D507892,
|
1768 |
+
0x9B6A5FCC,
|
1769 |
+
0x62547E46,
|
1770 |
+
0xC2F68D13,
|
1771 |
+
0xE890D8B8,
|
1772 |
+
0x5E2E39F7,
|
1773 |
+
0xF582C3AF,
|
1774 |
+
0xBE9F5D80,
|
1775 |
+
0x7C69D093,
|
1776 |
+
0xA96FD52D,
|
1777 |
+
0xB3CF2512,
|
1778 |
+
0x3BC8AC99,
|
1779 |
+
0xA710187D,
|
1780 |
+
0x6EE89C63,
|
1781 |
+
0x7BDB3BBB,
|
1782 |
+
0x09CD2678,
|
1783 |
+
0xF46E5918,
|
1784 |
+
0x01EC9AB7,
|
1785 |
+
0xA8834F9A,
|
1786 |
+
0x65E6956E,
|
1787 |
+
0x7EAAFFE6,
|
1788 |
+
0x0821BCCF,
|
1789 |
+
0xE6EF15E8,
|
1790 |
+
0xD9BAE79B,
|
1791 |
+
0xCE4A6F36,
|
1792 |
+
0xD4EA9F09,
|
1793 |
+
0xD629B07C,
|
1794 |
+
0xAF31A4B2,
|
1795 |
+
0x312A3F23,
|
1796 |
+
0x30C6A594,
|
1797 |
+
0xC035A266,
|
1798 |
+
0x37744EBC,
|
1799 |
+
0xA6FC82CA,
|
1800 |
+
0xB0E090D0,
|
1801 |
+
0x1533A7D8,
|
1802 |
+
0x4AF10498,
|
1803 |
+
0xF741ECDA,
|
1804 |
+
0x0E7FCD50,
|
1805 |
+
0x2F1791F6,
|
1806 |
+
0x8D764DD6,
|
1807 |
+
0x4D43EFB0,
|
1808 |
+
0x54CCAA4D,
|
1809 |
+
0xDFE49604,
|
1810 |
+
0xE39ED1B5,
|
1811 |
+
0x1B4C6A88,
|
1812 |
+
0xB8C12C1F,
|
1813 |
+
0x7F466551,
|
1814 |
+
0x049D5EEA,
|
1815 |
+
0x5D018C35,
|
1816 |
+
0x73FA8774,
|
1817 |
+
0x2EFB0B41,
|
1818 |
+
0x5AB3671D,
|
1819 |
+
0x5292DBD2,
|
1820 |
+
0x33E91056,
|
1821 |
+
0x136DD647,
|
1822 |
+
0x8C9AD761,
|
1823 |
+
0x7A37A10C,
|
1824 |
+
0x8E59F814,
|
1825 |
+
0x89EB133C,
|
1826 |
+
0xEECEA927,
|
1827 |
+
0x35B761C9,
|
1828 |
+
0xEDE11CE5,
|
1829 |
+
0x3C7A47B1,
|
1830 |
+
0x599CD2DF,
|
1831 |
+
0x3F55F273,
|
1832 |
+
0x791814CE,
|
1833 |
+
0xBF73C737,
|
1834 |
+
0xEA53F7CD,
|
1835 |
+
0x5B5FFDAA,
|
1836 |
+
0x14DF3D6F,
|
1837 |
+
0x867844DB,
|
1838 |
+
0x81CAAFF3,
|
1839 |
+
0x3EB968C4,
|
1840 |
+
0x2C382434,
|
1841 |
+
0x5FC2A340,
|
1842 |
+
0x72161DC3,
|
1843 |
+
0x0CBCE225,
|
1844 |
+
0x8B283C49,
|
1845 |
+
0x41FF0D95,
|
1846 |
+
0x7139A801,
|
1847 |
+
0xDE080CB3,
|
1848 |
+
0x9CD8B4E4,
|
1849 |
+
0x906456C1,
|
1850 |
+
0x617BCB84,
|
1851 |
+
0x70D532B6,
|
1852 |
+
0x74486C5C,
|
1853 |
+
0x42D0B857
|
1854 |
+
);
|
1855 |
+
|
1856 |
+
/**
|
1857 |
+
* Precomputed invMixColumns table
|
1858 |
+
*
|
1859 |
+
* @see NostoCryptRijndael:encryptBlock()
|
1860 |
+
* @see NostoCryptRijndael:decryptBlock()
|
1861 |
+
* @var Array
|
1862 |
+
*/
|
1863 |
+
public $dt2 = array(
|
1864 |
+
0xA75051F4,
|
1865 |
+
0x65537E41,
|
1866 |
+
0xA4C31A17,
|
1867 |
+
0x5E963A27,
|
1868 |
+
0x6BCB3BAB,
|
1869 |
+
0x45F11F9D,
|
1870 |
+
0x58ABACFA,
|
1871 |
+
0x03934BE3,
|
1872 |
+
0xFA552030,
|
1873 |
+
0x6DF6AD76,
|
1874 |
+
0x769188CC,
|
1875 |
+
0x4C25F502,
|
1876 |
+
0xD7FC4FE5,
|
1877 |
+
0xCBD7C52A,
|
1878 |
+
0x44802635,
|
1879 |
+
0xA38FB562,
|
1880 |
+
0x5A49DEB1,
|
1881 |
+
0x1B6725BA,
|
1882 |
+
0x0E9845EA,
|
1883 |
+
0xC0E15DFE,
|
1884 |
+
0x7502C32F,
|
1885 |
+
0xF012814C,
|
1886 |
+
0x97A38D46,
|
1887 |
+
0xF9C66BD3,
|
1888 |
+
0x5FE7038F,
|
1889 |
+
0x9C951592,
|
1890 |
+
0x7AEBBF6D,
|
1891 |
+
0x59DA9552,
|
1892 |
+
0x832DD4BE,
|
1893 |
+
0x21D35874,
|
1894 |
+
0x692949E0,
|
1895 |
+
0xC8448EC9,
|
1896 |
+
0x896A75C2,
|
1897 |
+
0x7978F48E,
|
1898 |
+
0x3E6B9958,
|
1899 |
+
0x71DD27B9,
|
1900 |
+
0x4FB6BEE1,
|
1901 |
+
0xAD17F088,
|
1902 |
+
0xAC66C920,
|
1903 |
+
0x3AB47DCE,
|
1904 |
+
0x4A1863DF,
|
1905 |
+
0x3182E51A,
|
1906 |
+
0x33609751,
|
1907 |
+
0x7F456253,
|
1908 |
+
0x77E0B164,
|
1909 |
+
0xAE84BB6B,
|
1910 |
+
0xA01CFE81,
|
1911 |
+
0x2B94F908,
|
1912 |
+
0x68587048,
|
1913 |
+
0xFD198F45,
|
1914 |
+
0x6C8794DE,
|
1915 |
+
0xF8B7527B,
|
1916 |
+
0xD323AB73,
|
1917 |
+
0x02E2724B,
|
1918 |
+
0x8F57E31F,
|
1919 |
+
0xAB2A6655,
|
1920 |
+
0x2807B2EB,
|
1921 |
+
0xC2032FB5,
|
1922 |
+
0x7B9A86C5,
|
1923 |
+
0x08A5D337,
|
1924 |
+
0x87F23028,
|
1925 |
+
0xA5B223BF,
|
1926 |
+
0x6ABA0203,
|
1927 |
+
0x825CED16,
|
1928 |
+
0x1C2B8ACF,
|
1929 |
+
0xB492A779,
|
1930 |
+
0xF2F0F307,
|
1931 |
+
0xE2A14E69,
|
1932 |
+
0xF4CD65DA,
|
1933 |
+
0xBED50605,
|
1934 |
+
0x621FD134,
|
1935 |
+
0xFE8AC4A6,
|
1936 |
+
0x539D342E,
|
1937 |
+
0x55A0A2F3,
|
1938 |
+
0xE132058A,
|
1939 |
+
0xEB75A4F6,
|
1940 |
+
0xEC390B83,
|
1941 |
+
0xEFAA4060,
|
1942 |
+
0x9F065E71,
|
1943 |
+
0x1051BD6E,
|
1944 |
+
0x8AF93E21,
|
1945 |
+
0x063D96DD,
|
1946 |
+
0x05AEDD3E,
|
1947 |
+
0xBD464DE6,
|
1948 |
+
0x8DB59154,
|
1949 |
+
0x5D0571C4,
|
1950 |
+
0xD46F0406,
|
1951 |
+
0x15FF6050,
|
1952 |
+
0xFB241998,
|
1953 |
+
0xE997D6BD,
|
1954 |
+
0x43CC8940,
|
1955 |
+
0x9E7767D9,
|
1956 |
+
0x42BDB0E8,
|
1957 |
+
0x8B880789,
|
1958 |
+
0x5B38E719,
|
1959 |
+
0xEEDB79C8,
|
1960 |
+
0x0A47A17C,
|
1961 |
+
0x0FE97C42,
|
1962 |
+
0x1EC9F884,
|
1963 |
+
0x00000000,
|
1964 |
+
0x86830980,
|
1965 |
+
0xED48322B,
|
1966 |
+
0x70AC1E11,
|
1967 |
+
0x724E6C5A,
|
1968 |
+
0xFFFBFD0E,
|
1969 |
+
0x38560F85,
|
1970 |
+
0xD51E3DAE,
|
1971 |
+
0x3927362D,
|
1972 |
+
0xD9640A0F,
|
1973 |
+
0xA621685C,
|
1974 |
+
0x54D19B5B,
|
1975 |
+
0x2E3A2436,
|
1976 |
+
0x67B10C0A,
|
1977 |
+
0xE70F9357,
|
1978 |
+
0x96D2B4EE,
|
1979 |
+
0x919E1B9B,
|
1980 |
+
0xC54F80C0,
|
1981 |
+
0x20A261DC,
|
1982 |
+
0x4B695A77,
|
1983 |
+
0x1A161C12,
|
1984 |
+
0xBA0AE293,
|
1985 |
+
0x2AE5C0A0,
|
1986 |
+
0xE0433C22,
|
1987 |
+
0x171D121B,
|
1988 |
+
0x0D0B0E09,
|
1989 |
+
0xC7ADF28B,
|
1990 |
+
0xA8B92DB6,
|
1991 |
+
0xA9C8141E,
|
1992 |
+
0x198557F1,
|
1993 |
+
0x074CAF75,
|
1994 |
+
0xDDBBEE99,
|
1995 |
+
0x60FDA37F,
|
1996 |
+
0x269FF701,
|
1997 |
+
0xF5BC5C72,
|
1998 |
+
0x3BC54466,
|
1999 |
+
0x7E345BFB,
|
2000 |
+
0x29768B43,
|
2001 |
+
0xC6DCCB23,
|
2002 |
+
0xFC68B6ED,
|
2003 |
+
0xF163B8E4,
|
2004 |
+
0xDCCAD731,
|
2005 |
+
0x85104263,
|
2006 |
+
0x22401397,
|
2007 |
+
0x112084C6,
|
2008 |
+
0x247D854A,
|
2009 |
+
0x3DF8D2BB,
|
2010 |
+
0x3211AEF9,
|
2011 |
+
0xA16DC729,
|
2012 |
+
0x2F4B1D9E,
|
2013 |
+
0x30F3DCB2,
|
2014 |
+
0x52EC0D86,
|
2015 |
+
0xE3D077C1,
|
2016 |
+
0x166C2BB3,
|
2017 |
+
0xB999A970,
|
2018 |
+
0x48FA1194,
|
2019 |
+
0x642247E9,
|
2020 |
+
0x8CC4A8FC,
|
2021 |
+
0x3F1AA0F0,
|
2022 |
+
0x2CD8567D,
|
2023 |
+
0x90EF2233,
|
2024 |
+
0x4EC78749,
|
2025 |
+
0xD1C1D938,
|
2026 |
+
0xA2FE8CCA,
|
2027 |
+
0x0B3698D4,
|
2028 |
+
0x81CFA6F5,
|
2029 |
+
0xDE28A57A,
|
2030 |
+
0x8E26DAB7,
|
2031 |
+
0xBFA43FAD,
|
2032 |
+
0x9DE42C3A,
|
2033 |
+
0x920D5078,
|
2034 |
+
0xCC9B6A5F,
|
2035 |
+
0x4662547E,
|
2036 |
+
0x13C2F68D,
|
2037 |
+
0xB8E890D8,
|
2038 |
+
0xF75E2E39,
|
2039 |
+
0xAFF582C3,
|
2040 |
+
0x80BE9F5D,
|
2041 |
+
0x937C69D0,
|
2042 |
+
0x2DA96FD5,
|
2043 |
+
0x12B3CF25,
|
2044 |
+
0x993BC8AC,
|
2045 |
+
0x7DA71018,
|
2046 |
+
0x636EE89C,
|
2047 |
+
0xBB7BDB3B,
|
2048 |
+
0x7809CD26,
|
2049 |
+
0x18F46E59,
|
2050 |
+
0xB701EC9A,
|
2051 |
+
0x9AA8834F,
|
2052 |
+
0x6E65E695,
|
2053 |
+
0xE67EAAFF,
|
2054 |
+
0xCF0821BC,
|
2055 |
+
0xE8E6EF15,
|
2056 |
+
0x9BD9BAE7,
|
2057 |
+
0x36CE4A6F,
|
2058 |
+
0x09D4EA9F,
|
2059 |
+
0x7CD629B0,
|
2060 |
+
0xB2AF31A4,
|
2061 |
+
0x23312A3F,
|
2062 |
+
0x9430C6A5,
|
2063 |
+
0x66C035A2,
|
2064 |
+
0xBC37744E,
|
2065 |
+
0xCAA6FC82,
|
2066 |
+
0xD0B0E090,
|
2067 |
+
0xD81533A7,
|
2068 |
+
0x984AF104,
|
2069 |
+
0xDAF741EC,
|
2070 |
+
0x500E7FCD,
|
2071 |
+
0xF62F1791,
|
2072 |
+
0xD68D764D,
|
2073 |
+
0xB04D43EF,
|
2074 |
+
0x4D54CCAA,
|
2075 |
+
0x04DFE496,
|
2076 |
+
0xB5E39ED1,
|
2077 |
+
0x881B4C6A,
|
2078 |
+
0x1FB8C12C,
|
2079 |
+
0x517F4665,
|
2080 |
+
0xEA049D5E,
|
2081 |
+
0x355D018C,
|
2082 |
+
0x7473FA87,
|
2083 |
+
0x412EFB0B,
|
2084 |
+
0x1D5AB367,
|
2085 |
+
0xD25292DB,
|
2086 |
+
0x5633E910,
|
2087 |
+
0x47136DD6,
|
2088 |
+
0x618C9AD7,
|
2089 |
+
0x0C7A37A1,
|
2090 |
+
0x148E59F8,
|
2091 |
+
0x3C89EB13,
|
2092 |
+
0x27EECEA9,
|
2093 |
+
0xC935B761,
|
2094 |
+
0xE5EDE11C,
|
2095 |
+
0xB13C7A47,
|
2096 |
+
0xDF599CD2,
|
2097 |
+
0x733F55F2,
|
2098 |
+
0xCE791814,
|
2099 |
+
0x37BF73C7,
|
2100 |
+
0xCDEA53F7,
|
2101 |
+
0xAA5B5FFD,
|
2102 |
+
0x6F14DF3D,
|
2103 |
+
0xDB867844,
|
2104 |
+
0xF381CAAF,
|
2105 |
+
0xC43EB968,
|
2106 |
+
0x342C3824,
|
2107 |
+
0x405FC2A3,
|
2108 |
+
0xC372161D,
|
2109 |
+
0x250CBCE2,
|
2110 |
+
0x498B283C,
|
2111 |
+
0x9541FF0D,
|
2112 |
+
0x017139A8,
|
2113 |
+
0xB3DE080C,
|
2114 |
+
0xE49CD8B4,
|
2115 |
+
0xC1906456,
|
2116 |
+
0x84617BCB,
|
2117 |
+
0xB670D532,
|
2118 |
+
0x5C74486C,
|
2119 |
+
0x5742D0B8
|
2120 |
+
);
|
2121 |
+
|
2122 |
+
/**
|
2123 |
+
* Precomputed invMixColumns table
|
2124 |
+
*
|
2125 |
+
* @see NostoCryptRijndael:encryptBlock()
|
2126 |
+
* @see NostoCryptRijndael:decryptBlock()
|
2127 |
+
* @var Array
|
2128 |
+
*/
|
2129 |
+
public $dt3 = array(
|
2130 |
+
0xF4A75051,
|
2131 |
+
0x4165537E,
|
2132 |
+
0x17A4C31A,
|
2133 |
+
0x275E963A,
|
2134 |
+
0xAB6BCB3B,
|
2135 |
+
0x9D45F11F,
|
2136 |
+
0xFA58ABAC,
|
2137 |
+
0xE303934B,
|
2138 |
+
0x30FA5520,
|
2139 |
+
0x766DF6AD,
|
2140 |
+
0xCC769188,
|
2141 |
+
0x024C25F5,
|
2142 |
+
0xE5D7FC4F,
|
2143 |
+
0x2ACBD7C5,
|
2144 |
+
0x35448026,
|
2145 |
+
0x62A38FB5,
|
2146 |
+
0xB15A49DE,
|
2147 |
+
0xBA1B6725,
|
2148 |
+
0xEA0E9845,
|
2149 |
+
0xFEC0E15D,
|
2150 |
+
0x2F7502C3,
|
2151 |
+
0x4CF01281,
|
2152 |
+
0x4697A38D,
|
2153 |
+
0xD3F9C66B,
|
2154 |
+
0x8F5FE703,
|
2155 |
+
0x929C9515,
|
2156 |
+
0x6D7AEBBF,
|
2157 |
+
0x5259DA95,
|
2158 |
+
0xBE832DD4,
|
2159 |
+
0x7421D358,
|
2160 |
+
0xE0692949,
|
2161 |
+
0xC9C8448E,
|
2162 |
+
0xC2896A75,
|
2163 |
+
0x8E7978F4,
|
2164 |
+
0x583E6B99,
|
2165 |
+
0xB971DD27,
|
2166 |
+
0xE14FB6BE,
|
2167 |
+
0x88AD17F0,
|
2168 |
+
0x20AC66C9,
|
2169 |
+
0xCE3AB47D,
|
2170 |
+
0xDF4A1863,
|
2171 |
+
0x1A3182E5,
|
2172 |
+
0x51336097,
|
2173 |
+
0x537F4562,
|
2174 |
+
0x6477E0B1,
|
2175 |
+
0x6BAE84BB,
|
2176 |
+
0x81A01CFE,
|
2177 |
+
0x082B94F9,
|
2178 |
+
0x48685870,
|
2179 |
+
0x45FD198F,
|
2180 |
+
0xDE6C8794,
|
2181 |
+
0x7BF8B752,
|
2182 |
+
0x73D323AB,
|
2183 |
+
0x4B02E272,
|
2184 |
+
0x1F8F57E3,
|
2185 |
+
0x55AB2A66,
|
2186 |
+
0xEB2807B2,
|
2187 |
+
0xB5C2032F,
|
2188 |
+
0xC57B9A86,
|
2189 |
+
0x3708A5D3,
|
2190 |
+
0x2887F230,
|
2191 |
+
0xBFA5B223,
|
2192 |
+
0x036ABA02,
|
2193 |
+
0x16825CED,
|
2194 |
+
0xCF1C2B8A,
|
2195 |
+
0x79B492A7,
|
2196 |
+
0x07F2F0F3,
|
2197 |
+
0x69E2A14E,
|
2198 |
+
0xDAF4CD65,
|
2199 |
+
0x05BED506,
|
2200 |
+
0x34621FD1,
|
2201 |
+
0xA6FE8AC4,
|
2202 |
+
0x2E539D34,
|
2203 |
+
0xF355A0A2,
|
2204 |
+
0x8AE13205,
|
2205 |
+
0xF6EB75A4,
|
2206 |
+
0x83EC390B,
|
2207 |
+
0x60EFAA40,
|
2208 |
+
0x719F065E,
|
2209 |
+
0x6E1051BD,
|
2210 |
+
0x218AF93E,
|
2211 |
+
0xDD063D96,
|
2212 |
+
0x3E05AEDD,
|
2213 |
+
0xE6BD464D,
|
2214 |
+
0x548DB591,
|
2215 |
+
0xC45D0571,
|
2216 |
+
0x06D46F04,
|
2217 |
+
0x5015FF60,
|
2218 |
+
0x98FB2419,
|
2219 |
+
0xBDE997D6,
|
2220 |
+
0x4043CC89,
|
2221 |
+
0xD99E7767,
|
2222 |
+
0xE842BDB0,
|
2223 |
+
0x898B8807,
|
2224 |
+
0x195B38E7,
|
2225 |
+
0xC8EEDB79,
|
2226 |
+
0x7C0A47A1,
|
2227 |
+
0x420FE97C,
|
2228 |
+
0x841EC9F8,
|
2229 |
+
0x00000000,
|
2230 |
+
0x80868309,
|
2231 |
+
0x2BED4832,
|
2232 |
+
0x1170AC1E,
|
2233 |
+
0x5A724E6C,
|
2234 |
+
0x0EFFFBFD,
|
2235 |
+
0x8538560F,
|
2236 |
+
0xAED51E3D,
|
2237 |
+
0x2D392736,
|
2238 |
+
0x0FD9640A,
|
2239 |
+
0x5CA62168,
|
2240 |
+
0x5B54D19B,
|
2241 |
+
0x362E3A24,
|
2242 |
+
0x0A67B10C,
|
2243 |
+
0x57E70F93,
|
2244 |
+
0xEE96D2B4,
|
2245 |
+
0x9B919E1B,
|
2246 |
+
0xC0C54F80,
|
2247 |
+
0xDC20A261,
|
2248 |
+
0x774B695A,
|
2249 |
+
0x121A161C,
|
2250 |
+
0x93BA0AE2,
|
2251 |
+
0xA02AE5C0,
|
2252 |
+
0x22E0433C,
|
2253 |
+
0x1B171D12,
|
2254 |
+
0x090D0B0E,
|
2255 |
+
0x8BC7ADF2,
|
2256 |
+
0xB6A8B92D,
|
2257 |
+
0x1EA9C814,
|
2258 |
+
0xF1198557,
|
2259 |
+
0x75074CAF,
|
2260 |
+
0x99DDBBEE,
|
2261 |
+
0x7F60FDA3,
|
2262 |
+
0x01269FF7,
|
2263 |
+
0x72F5BC5C,
|
2264 |
+
0x663BC544,
|
2265 |
+
0xFB7E345B,
|
2266 |
+
0x4329768B,
|
2267 |
+
0x23C6DCCB,
|
2268 |
+
0xEDFC68B6,
|
2269 |
+
0xE4F163B8,
|
2270 |
+
0x31DCCAD7,
|
2271 |
+
0x63851042,
|
2272 |
+
0x97224013,
|
2273 |
+
0xC6112084,
|
2274 |
+
0x4A247D85,
|
2275 |
+
0xBB3DF8D2,
|
2276 |
+
0xF93211AE,
|
2277 |
+
0x29A16DC7,
|
2278 |
+
0x9E2F4B1D,
|
2279 |
+
0xB230F3DC,
|
2280 |
+
0x8652EC0D,
|
2281 |
+
0xC1E3D077,
|
2282 |
+
0xB3166C2B,
|
2283 |
+
0x70B999A9,
|
2284 |
+
0x9448FA11,
|
2285 |
+
0xE9642247,
|
2286 |
+
0xFC8CC4A8,
|
2287 |
+
0xF03F1AA0,
|
2288 |
+
0x7D2CD856,
|
2289 |
+
0x3390EF22,
|
2290 |
+
0x494EC787,
|
2291 |
+
0x38D1C1D9,
|
2292 |
+
0xCAA2FE8C,
|
2293 |
+
0xD40B3698,
|
2294 |
+
0xF581CFA6,
|
2295 |
+
0x7ADE28A5,
|
2296 |
+
0xB78E26DA,
|
2297 |
+
0xADBFA43F,
|
2298 |
+
0x3A9DE42C,
|
2299 |
+
0x78920D50,
|
2300 |
+
0x5FCC9B6A,
|
2301 |
+
0x7E466254,
|
2302 |
+
0x8D13C2F6,
|
2303 |
+
0xD8B8E890,
|
2304 |
+
0x39F75E2E,
|
2305 |
+
0xC3AFF582,
|
2306 |
+
0x5D80BE9F,
|
2307 |
+
0xD0937C69,
|
2308 |
+
0xD52DA96F,
|
2309 |
+
0x2512B3CF,
|
2310 |
+
0xAC993BC8,
|
2311 |
+
0x187DA710,
|
2312 |
+
0x9C636EE8,
|
2313 |
+
0x3BBB7BDB,
|
2314 |
+
0x267809CD,
|
2315 |
+
0x5918F46E,
|
2316 |
+
0x9AB701EC,
|
2317 |
+
0x4F9AA883,
|
2318 |
+
0x956E65E6,
|
2319 |
+
0xFFE67EAA,
|
2320 |
+
0xBCCF0821,
|
2321 |
+
0x15E8E6EF,
|
2322 |
+
0xE79BD9BA,
|
2323 |
+
0x6F36CE4A,
|
2324 |
+
0x9F09D4EA,
|
2325 |
+
0xB07CD629,
|
2326 |
+
0xA4B2AF31,
|
2327 |
+
0x3F23312A,
|
2328 |
+
0xA59430C6,
|
2329 |
+
0xA266C035,
|
2330 |
+
0x4EBC3774,
|
2331 |
+
0x82CAA6FC,
|
2332 |
+
0x90D0B0E0,
|
2333 |
+
0xA7D81533,
|
2334 |
+
0x04984AF1,
|
2335 |
+
0xECDAF741,
|
2336 |
+
0xCD500E7F,
|
2337 |
+
0x91F62F17,
|
2338 |
+
0x4DD68D76,
|
2339 |
+
0xEFB04D43,
|
2340 |
+
0xAA4D54CC,
|
2341 |
+
0x9604DFE4,
|
2342 |
+
0xD1B5E39E,
|
2343 |
+
0x6A881B4C,
|
2344 |
+
0x2C1FB8C1,
|
2345 |
+
0x65517F46,
|
2346 |
+
0x5EEA049D,
|
2347 |
+
0x8C355D01,
|
2348 |
+
0x877473FA,
|
2349 |
+
0x0B412EFB,
|
2350 |
+
0x671D5AB3,
|
2351 |
+
0xDBD25292,
|
2352 |
+
0x105633E9,
|
2353 |
+
0xD647136D,
|
2354 |
+
0xD7618C9A,
|
2355 |
+
0xA10C7A37,
|
2356 |
+
0xF8148E59,
|
2357 |
+
0x133C89EB,
|
2358 |
+
0xA927EECE,
|
2359 |
+
0x61C935B7,
|
2360 |
+
0x1CE5EDE1,
|
2361 |
+
0x47B13C7A,
|
2362 |
+
0xD2DF599C,
|
2363 |
+
0xF2733F55,
|
2364 |
+
0x14CE7918,
|
2365 |
+
0xC737BF73,
|
2366 |
+
0xF7CDEA53,
|
2367 |
+
0xFDAA5B5F,
|
2368 |
+
0x3D6F14DF,
|
2369 |
+
0x44DB8678,
|
2370 |
+
0xAFF381CA,
|
2371 |
+
0x68C43EB9,
|
2372 |
+
0x24342C38,
|
2373 |
+
0xA3405FC2,
|
2374 |
+
0x1DC37216,
|
2375 |
+
0xE2250CBC,
|
2376 |
+
0x3C498B28,
|
2377 |
+
0x0D9541FF,
|
2378 |
+
0xA8017139,
|
2379 |
+
0x0CB3DE08,
|
2380 |
+
0xB4E49CD8,
|
2381 |
+
0x56C19064,
|
2382 |
+
0xCB84617B,
|
2383 |
+
0x32B670D5,
|
2384 |
+
0x6C5C7448,
|
2385 |
+
0xB85742D0
|
2386 |
+
);
|
2387 |
+
|
2388 |
+
/**
|
2389 |
+
* The SubByte S-Box
|
2390 |
+
*
|
2391 |
+
* @see NostoCryptRijndael::encryptBlock()
|
2392 |
+
* @var Array
|
2393 |
+
*/
|
2394 |
+
public $sbox = array(
|
2395 |
+
0x63,
|
2396 |
+
0x7C,
|
2397 |
+
0x77,
|
2398 |
+
0x7B,
|
2399 |
+
0xF2,
|
2400 |
+
0x6B,
|
2401 |
+
0x6F,
|
2402 |
+
0xC5,
|
2403 |
+
0x30,
|
2404 |
+
0x01,
|
2405 |
+
0x67,
|
2406 |
+
0x2B,
|
2407 |
+
0xFE,
|
2408 |
+
0xD7,
|
2409 |
+
0xAB,
|
2410 |
+
0x76,
|
2411 |
+
0xCA,
|
2412 |
+
0x82,
|
2413 |
+
0xC9,
|
2414 |
+
0x7D,
|
2415 |
+
0xFA,
|
2416 |
+
0x59,
|
2417 |
+
0x47,
|
2418 |
+
0xF0,
|
2419 |
+
0xAD,
|
2420 |
+
0xD4,
|
2421 |
+
0xA2,
|
2422 |
+
0xAF,
|
2423 |
+
0x9C,
|
2424 |
+
0xA4,
|
2425 |
+
0x72,
|
2426 |
+
0xC0,
|
2427 |
+
0xB7,
|
2428 |
+
0xFD,
|
2429 |
+
0x93,
|
2430 |
+
0x26,
|
2431 |
+
0x36,
|
2432 |
+
0x3F,
|
2433 |
+
0xF7,
|
2434 |
+
0xCC,
|
2435 |
+
0x34,
|
2436 |
+
0xA5,
|
2437 |
+
0xE5,
|
2438 |
+
0xF1,
|
2439 |
+
0x71,
|
2440 |
+
0xD8,
|
2441 |
+
0x31,
|
2442 |
+
0x15,
|
2443 |
+
0x04,
|
2444 |
+
0xC7,
|
2445 |
+
0x23,
|
2446 |
+
0xC3,
|
2447 |
+
0x18,
|
2448 |
+
0x96,
|
2449 |
+
0x05,
|
2450 |
+
0x9A,
|
2451 |
+
0x07,
|
2452 |
+
0x12,
|
2453 |
+
0x80,
|
2454 |
+
0xE2,
|
2455 |
+
0xEB,
|
2456 |
+
0x27,
|
2457 |
+
0xB2,
|
2458 |
+
0x75,
|
2459 |
+
0x09,
|
2460 |
+
0x83,
|
2461 |
+
0x2C,
|
2462 |
+
0x1A,
|
2463 |
+
0x1B,
|
2464 |
+
0x6E,
|
2465 |
+
0x5A,
|
2466 |
+
0xA0,
|
2467 |
+
0x52,
|
2468 |
+
0x3B,
|
2469 |
+
0xD6,
|
2470 |
+
0xB3,
|
2471 |
+
0x29,
|
2472 |
+
0xE3,
|
2473 |
+
0x2F,
|
2474 |
+
0x84,
|
2475 |
+
0x53,
|
2476 |
+
0xD1,
|
2477 |
+
0x00,
|
2478 |
+
0xED,
|
2479 |
+
0x20,
|
2480 |
+
0xFC,
|
2481 |
+
0xB1,
|
2482 |
+
0x5B,
|
2483 |
+
0x6A,
|
2484 |
+
0xCB,
|
2485 |
+
0xBE,
|
2486 |
+
0x39,
|
2487 |
+
0x4A,
|
2488 |
+
0x4C,
|
2489 |
+
0x58,
|
2490 |
+
0xCF,
|
2491 |
+
0xD0,
|
2492 |
+
0xEF,
|
2493 |
+
0xAA,
|
2494 |
+
0xFB,
|
2495 |
+
0x43,
|
2496 |
+
0x4D,
|
2497 |
+
0x33,
|
2498 |
+
0x85,
|
2499 |
+
0x45,
|
2500 |
+
0xF9,
|
2501 |
+
0x02,
|
2502 |
+
0x7F,
|
2503 |
+
0x50,
|
2504 |
+
0x3C,
|
2505 |
+
0x9F,
|
2506 |
+
0xA8,
|
2507 |
+
0x51,
|
2508 |
+
0xA3,
|
2509 |
+
0x40,
|
2510 |
+
0x8F,
|
2511 |
+
0x92,
|
2512 |
+
0x9D,
|
2513 |
+
0x38,
|
2514 |
+
0xF5,
|
2515 |
+
0xBC,
|
2516 |
+
0xB6,
|
2517 |
+
0xDA,
|
2518 |
+
0x21,
|
2519 |
+
0x10,
|
2520 |
+
0xFF,
|
2521 |
+
0xF3,
|
2522 |
+
0xD2,
|
2523 |
+
0xCD,
|
2524 |
+
0x0C,
|
2525 |
+
0x13,
|
2526 |
+
0xEC,
|
2527 |
+
0x5F,
|
2528 |
+
0x97,
|
2529 |
+
0x44,
|
2530 |
+
0x17,
|
2531 |
+
0xC4,
|
2532 |
+
0xA7,
|
2533 |
+
0x7E,
|
2534 |
+
0x3D,
|
2535 |
+
0x64,
|
2536 |
+
0x5D,
|
2537 |
+
0x19,
|
2538 |
+
0x73,
|
2539 |
+
0x60,
|
2540 |
+
0x81,
|
2541 |
+
0x4F,
|
2542 |
+
0xDC,
|
2543 |
+
0x22,
|
2544 |
+
0x2A,
|
2545 |
+
0x90,
|
2546 |
+
0x88,
|
2547 |
+
0x46,
|
2548 |
+
0xEE,
|
2549 |
+
0xB8,
|
2550 |
+
0x14,
|
2551 |
+
0xDE,
|
2552 |
+
0x5E,
|
2553 |
+
0x0B,
|
2554 |
+
0xDB,
|
2555 |
+
0xE0,
|
2556 |
+
0x32,
|
2557 |
+
0x3A,
|
2558 |
+
0x0A,
|
2559 |
+
0x49,
|
2560 |
+
0x06,
|
2561 |
+
0x24,
|
2562 |
+
0x5C,
|
2563 |
+
0xC2,
|
2564 |
+
0xD3,
|
2565 |
+
0xAC,
|
2566 |
+
0x62,
|
2567 |
+
0x91,
|
2568 |
+
0x95,
|
2569 |
+
0xE4,
|
2570 |
+
0x79,
|
2571 |
+
0xE7,
|
2572 |
+
0xC8,
|
2573 |
+
0x37,
|
2574 |
+
0x6D,
|
2575 |
+
0x8D,
|
2576 |
+
0xD5,
|
2577 |
+
0x4E,
|
2578 |
+
0xA9,
|
2579 |
+
0x6C,
|
2580 |
+
0x56,
|
2581 |
+
0xF4,
|
2582 |
+
0xEA,
|
2583 |
+
0x65,
|
2584 |
+
0x7A,
|
2585 |
+
0xAE,
|
2586 |
+
0x08,
|
2587 |
+
0xBA,
|
2588 |
+
0x78,
|
2589 |
+
0x25,
|
2590 |
+
0x2E,
|
2591 |
+
0x1C,
|
2592 |
+
0xA6,
|
2593 |
+
0xB4,
|
2594 |
+
0xC6,
|
2595 |
+
0xE8,
|
2596 |
+
0xDD,
|
2597 |
+
0x74,
|
2598 |
+
0x1F,
|
2599 |
+
0x4B,
|
2600 |
+
0xBD,
|
2601 |
+
0x8B,
|
2602 |
+
0x8A,
|
2603 |
+
0x70,
|
2604 |
+
0x3E,
|
2605 |
+
0xB5,
|
2606 |
+
0x66,
|
2607 |
+
0x48,
|
2608 |
+
0x03,
|
2609 |
+
0xF6,
|
2610 |
+
0x0E,
|
2611 |
+
0x61,
|
2612 |
+
0x35,
|
2613 |
+
0x57,
|
2614 |
+
0xB9,
|
2615 |
+
0x86,
|
2616 |
+
0xC1,
|
2617 |
+
0x1D,
|
2618 |
+
0x9E,
|
2619 |
+
0xE1,
|
2620 |
+
0xF8,
|
2621 |
+
0x98,
|
2622 |
+
0x11,
|
2623 |
+
0x69,
|
2624 |
+
0xD9,
|
2625 |
+
0x8E,
|
2626 |
+
0x94,
|
2627 |
+
0x9B,
|
2628 |
+
0x1E,
|
2629 |
+
0x87,
|
2630 |
+
0xE9,
|
2631 |
+
0xCE,
|
2632 |
+
0x55,
|
2633 |
+
0x28,
|
2634 |
+
0xDF,
|
2635 |
+
0x8C,
|
2636 |
+
0xA1,
|
2637 |
+
0x89,
|
2638 |
+
0x0D,
|
2639 |
+
0xBF,
|
2640 |
+
0xE6,
|
2641 |
+
0x42,
|
2642 |
+
0x68,
|
2643 |
+
0x41,
|
2644 |
+
0x99,
|
2645 |
+
0x2D,
|
2646 |
+
0x0F,
|
2647 |
+
0xB0,
|
2648 |
+
0x54,
|
2649 |
+
0xBB,
|
2650 |
+
0x16
|
2651 |
+
);
|
2652 |
+
|
2653 |
+
/**
|
2654 |
+
* The inverse SubByte S-Box
|
2655 |
+
*
|
2656 |
+
* @see NostoCryptRijndael::decryptBlock()
|
2657 |
+
* @var Array
|
2658 |
+
*/
|
2659 |
+
public $isbox = array(
|
2660 |
+
0x52,
|
2661 |
+
0x09,
|
2662 |
+
0x6A,
|
2663 |
+
0xD5,
|
2664 |
+
0x30,
|
2665 |
+
0x36,
|
2666 |
+
0xA5,
|
2667 |
+
0x38,
|
2668 |
+
0xBF,
|
2669 |
+
0x40,
|
2670 |
+
0xA3,
|
2671 |
+
0x9E,
|
2672 |
+
0x81,
|
2673 |
+
0xF3,
|
2674 |
+
0xD7,
|
2675 |
+
0xFB,
|
2676 |
+
0x7C,
|
2677 |
+
0xE3,
|
2678 |
+
0x39,
|
2679 |
+
0x82,
|
2680 |
+
0x9B,
|
2681 |
+
0x2F,
|
2682 |
+
0xFF,
|
2683 |
+
0x87,
|
2684 |
+
0x34,
|
2685 |
+
0x8E,
|
2686 |
+
0x43,
|
2687 |
+
0x44,
|
2688 |
+
0xC4,
|
2689 |
+
0xDE,
|
2690 |
+
0xE9,
|
2691 |
+
0xCB,
|
2692 |
+
0x54,
|
2693 |
+
0x7B,
|
2694 |
+
0x94,
|
2695 |
+
0x32,
|
2696 |
+
0xA6,
|
2697 |
+
0xC2,
|
2698 |
+
0x23,
|
2699 |
+
0x3D,
|
2700 |
+
0xEE,
|
2701 |
+
0x4C,
|
2702 |
+
0x95,
|
2703 |
+
0x0B,
|
2704 |
+
0x42,
|
2705 |
+
0xFA,
|
2706 |
+
0xC3,
|
2707 |
+
0x4E,
|
2708 |
+
0x08,
|
2709 |
+
0x2E,
|
2710 |
+
0xA1,
|
2711 |
+
0x66,
|
2712 |
+
0x28,
|
2713 |
+
0xD9,
|
2714 |
+
0x24,
|
2715 |
+
0xB2,
|
2716 |
+
0x76,
|
2717 |
+
0x5B,
|
2718 |
+
0xA2,
|
2719 |
+
0x49,
|
2720 |
+
0x6D,
|
2721 |
+
0x8B,
|
2722 |
+
0xD1,
|
2723 |
+
0x25,
|
2724 |
+
0x72,
|
2725 |
+
0xF8,
|
2726 |
+
0xF6,
|
2727 |
+
0x64,
|
2728 |
+
0x86,
|
2729 |
+
0x68,
|
2730 |
+
0x98,
|
2731 |
+
0x16,
|
2732 |
+
0xD4,
|
2733 |
+
0xA4,
|
2734 |
+
0x5C,
|
2735 |
+
0xCC,
|
2736 |
+
0x5D,
|
2737 |
+
0x65,
|
2738 |
+
0xB6,
|
2739 |
+
0x92,
|
2740 |
+
0x6C,
|
2741 |
+
0x70,
|
2742 |
+
0x48,
|
2743 |
+
0x50,
|
2744 |
+
0xFD,
|
2745 |
+
0xED,
|
2746 |
+
0xB9,
|
2747 |
+
0xDA,
|
2748 |
+
0x5E,
|
2749 |
+
0x15,
|
2750 |
+
0x46,
|
2751 |
+
0x57,
|
2752 |
+
0xA7,
|
2753 |
+
0x8D,
|
2754 |
+
0x9D,
|
2755 |
+
0x84,
|
2756 |
+
0x90,
|
2757 |
+
0xD8,
|
2758 |
+
0xAB,
|
2759 |
+
0x00,
|
2760 |
+
0x8C,
|
2761 |
+
0xBC,
|
2762 |
+
0xD3,
|
2763 |
+
0x0A,
|
2764 |
+
0xF7,
|
2765 |
+
0xE4,
|
2766 |
+
0x58,
|
2767 |
+
0x05,
|
2768 |
+
0xB8,
|
2769 |
+
0xB3,
|
2770 |
+
0x45,
|
2771 |
+
0x06,
|
2772 |
+
0xD0,
|
2773 |
+
0x2C,
|
2774 |
+
0x1E,
|
2775 |
+
0x8F,
|
2776 |
+
0xCA,
|
2777 |
+
0x3F,
|
2778 |
+
0x0F,
|
2779 |
+
0x02,
|
2780 |
+
0xC1,
|
2781 |
+
0xAF,
|
2782 |
+
0xBD,
|
2783 |
+
0x03,
|
2784 |
+
0x01,
|
2785 |
+
0x13,
|
2786 |
+
0x8A,
|
2787 |
+
0x6B,
|
2788 |
+
0x3A,
|
2789 |
+
0x91,
|
2790 |
+
0x11,
|
2791 |
+
0x41,
|
2792 |
+
0x4F,
|
2793 |
+
0x67,
|
2794 |
+
0xDC,
|
2795 |
+
0xEA,
|
2796 |
+
0x97,
|
2797 |
+
0xF2,
|
2798 |
+
0xCF,
|
2799 |
+
0xCE,
|
2800 |
+
0xF0,
|
2801 |
+
0xB4,
|
2802 |
+
0xE6,
|
2803 |
+
0x73,
|
2804 |
+
0x96,
|
2805 |
+
0xAC,
|
2806 |
+
0x74,
|
2807 |
+
0x22,
|
2808 |
+
0xE7,
|
2809 |
+
0xAD,
|
2810 |
+
0x35,
|
2811 |
+
0x85,
|
2812 |
+
0xE2,
|
2813 |
+
0xF9,
|
2814 |
+
0x37,
|
2815 |
+
0xE8,
|
2816 |
+
0x1C,
|
2817 |
+
0x75,
|
2818 |
+
0xDF,
|
2819 |
+
0x6E,
|
2820 |
+
0x47,
|
2821 |
+
0xF1,
|
2822 |
+
0x1A,
|
2823 |
+
0x71,
|
2824 |
+
0x1D,
|
2825 |
+
0x29,
|
2826 |
+
0xC5,
|
2827 |
+
0x89,
|
2828 |
+
0x6F,
|
2829 |
+
0xB7,
|
2830 |
+
0x62,
|
2831 |
+
0x0E,
|
2832 |
+
0xAA,
|
2833 |
+
0x18,
|
2834 |
+
0xBE,
|
2835 |
+
0x1B,
|
2836 |
+
0xFC,
|
2837 |
+
0x56,
|
2838 |
+
0x3E,
|
2839 |
+
0x4B,
|
2840 |
+
0xC6,
|
2841 |
+
0xD2,
|
2842 |
+
0x79,
|
2843 |
+
0x20,
|
2844 |
+
0x9A,
|
2845 |
+
0xDB,
|
2846 |
+
0xC0,
|
2847 |
+
0xFE,
|
2848 |
+
0x78,
|
2849 |
+
0xCD,
|
2850 |
+
0x5A,
|
2851 |
+
0xF4,
|
2852 |
+
0x1F,
|
2853 |
+
0xDD,
|
2854 |
+
0xA8,
|
2855 |
+
0x33,
|
2856 |
+
0x88,
|
2857 |
+
0x07,
|
2858 |
+
0xC7,
|
2859 |
+
0x31,
|
2860 |
+
0xB1,
|
2861 |
+
0x12,
|
2862 |
+
0x10,
|
2863 |
+
0x59,
|
2864 |
+
0x27,
|
2865 |
+
0x80,
|
2866 |
+
0xEC,
|
2867 |
+
0x5F,
|
2868 |
+
0x60,
|
2869 |
+
0x51,
|
2870 |
+
0x7F,
|
2871 |
+
0xA9,
|
2872 |
+
0x19,
|
2873 |
+
0xB5,
|
2874 |
+
0x4A,
|
2875 |
+
0x0D,
|
2876 |
+
0x2D,
|
2877 |
+
0xE5,
|
2878 |
+
0x7A,
|
2879 |
+
0x9F,
|
2880 |
+
0x93,
|
2881 |
+
0xC9,
|
2882 |
+
0x9C,
|
2883 |
+
0xEF,
|
2884 |
+
0xA0,
|
2885 |
+
0xE0,
|
2886 |
+
0x3B,
|
2887 |
+
0x4D,
|
2888 |
+
0xAE,
|
2889 |
+
0x2A,
|
2890 |
+
0xF5,
|
2891 |
+
0xB0,
|
2892 |
+
0xC8,
|
2893 |
+
0xEB,
|
2894 |
+
0xBB,
|
2895 |
+
0x3C,
|
2896 |
+
0x83,
|
2897 |
+
0x53,
|
2898 |
+
0x99,
|
2899 |
+
0x61,
|
2900 |
+
0x17,
|
2901 |
+
0x2B,
|
2902 |
+
0x04,
|
2903 |
+
0x7E,
|
2904 |
+
0xBA,
|
2905 |
+
0x77,
|
2906 |
+
0xD6,
|
2907 |
+
0x26,
|
2908 |
+
0xE1,
|
2909 |
+
0x69,
|
2910 |
+
0x14,
|
2911 |
+
0x63,
|
2912 |
+
0x55,
|
2913 |
+
0x21,
|
2914 |
+
0x0C,
|
2915 |
+
0x7D
|
2916 |
+
);
|
2917 |
+
|
2918 |
+
/**
|
2919 |
+
* Default Constructor.
|
2920 |
+
*
|
2921 |
+
* Determines whether or not the mcrypt extension should be used.
|
2922 |
+
*
|
2923 |
+
* $mode could be:
|
2924 |
+
*
|
2925 |
+
* - CRYPT_RIJNDAEL_MODE_ECB
|
2926 |
+
*
|
2927 |
+
* - CRYPT_RIJNDAEL_MODE_CBC
|
2928 |
+
*
|
2929 |
+
* - CRYPT_RIJNDAEL_MODE_CTR
|
2930 |
+
*
|
2931 |
+
* - CRYPT_RIJNDAEL_MODE_CFB
|
2932 |
+
*
|
2933 |
+
* - CRYPT_RIJNDAEL_MODE_OFB
|
2934 |
+
*
|
2935 |
+
* If not explicitly set, CRYPT_RIJNDAEL_MODE_CBC will be used.
|
2936 |
+
*
|
2937 |
+
* @see NostoCryptBase::NostoCryptBase()
|
2938 |
+
* @param optional Integer $mode
|
2939 |
+
*/
|
2940 |
+
public function __construct($mode = CRYPT_RIJNDAEL_MODE_CBC)
|
2941 |
+
{
|
2942 |
+
parent::__construct($mode);
|
2943 |
+
}
|
2944 |
+
|
2945 |
+
/**
|
2946 |
+
* Sets the key.
|
2947 |
+
*
|
2948 |
+
* Keys can be of any length. Rijndael, itself, requires the use of a key that's between 128-bits and 256-bits
|
2949 |
+
* long and whose length is a multiple of 32. If the key is less than 256-bits and the key length isn't set, we
|
2950 |
+
* round the length up to the closest valid key length, padding $key with null bytes. If the key is more than
|
2951 |
+
* 256-bits, we trim the excess bits.
|
2952 |
+
*
|
2953 |
+
* If the key is not explicitly set, it'll be assumed to be all null bytes.
|
2954 |
+
*
|
2955 |
+
* Note: 160/224-bit keys must explicitly be set by setKeyLength(), otherwise they will be round/pad up to 192/256
|
2956 |
+
* bits.
|
2957 |
+
*
|
2958 |
+
* @see NostoCryptBase:setKey()
|
2959 |
+
* @see setKeyLength()
|
2960 |
+
* @param String $key
|
2961 |
+
*/
|
2962 |
+
public function setKey($key)
|
2963 |
+
{
|
2964 |
+
parent::setKey($key);
|
2965 |
+
|
2966 |
+
if (!$this->explicitKeyLength) {
|
2967 |
+
$length = strlen($key);
|
2968 |
+
switch (true) {
|
2969 |
+
case $length <= 16:
|
2970 |
+
$this->keySize = 16;
|
2971 |
+
break;
|
2972 |
+
case $length <= 24:
|
2973 |
+
$this->keySize = 24;
|
2974 |
+
break;
|
2975 |
+
default:
|
2976 |
+
$this->keySize = 32;
|
2977 |
+
}
|
2978 |
+
$this->setupEngine();
|
2979 |
+
}
|
2980 |
+
}
|
2981 |
+
|
2982 |
+
/**
|
2983 |
+
* Sets the key length
|
2984 |
+
*
|
2985 |
+
* Valid key lengths are 128, 160, 192, 224, and 256. If the length is less than 128, it will be rounded up to
|
2986 |
+
* 128. If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.
|
2987 |
+
*
|
2988 |
+
* Note: phpseclib extends Rijndael (and AES) for using 160- and 224-bit keys but they are officially not defined
|
2989 |
+
* and the most (if not all) implementations are not able using 160/224-bit keys but round/pad them up to
|
2990 |
+
* 192/256 bits as, for example, mcrypt will do.
|
2991 |
+
*
|
2992 |
+
* That said, if you want be compatible with other Rijndael and AES implementations,
|
2993 |
+
* you should not setKeyLength(160) or setKeyLength(224).
|
2994 |
+
*
|
2995 |
+
* Additional: In case of 160- and 224-bit keys, phpseclib will/can, for that reason, not use
|
2996 |
+
* the mcrypt php extension, even if available.
|
2997 |
+
* This results then in slower encryption.
|
2998 |
+
*
|
2999 |
+
* @param Integer $length
|
3000 |
+
*/
|
3001 |
+
public function setKeyLength($length)
|
3002 |
+
{
|
3003 |
+
switch (true) {
|
3004 |
+
case $length == 160:
|
3005 |
+
$this->keySize = 20;
|
3006 |
+
break;
|
3007 |
+
case $length == 224:
|
3008 |
+
$this->keySize = 28;
|
3009 |
+
break;
|
3010 |
+
case $length <= 128:
|
3011 |
+
$this->keySize = 16;
|
3012 |
+
break;
|
3013 |
+
case $length <= 192:
|
3014 |
+
$this->keySize = 24;
|
3015 |
+
break;
|
3016 |
+
default:
|
3017 |
+
$this->keySize = 32;
|
3018 |
+
}
|
3019 |
+
|
3020 |
+
$this->explicitKeyLength = true;
|
3021 |
+
$this->changed = true;
|
3022 |
+
$this->setupEngine();
|
3023 |
+
}
|
3024 |
+
|
3025 |
+
/**
|
3026 |
+
* Sets the block length
|
3027 |
+
*
|
3028 |
+
* Valid block lengths are 128, 160, 192, 224, and 256. If the length is less than 128, it will be rounded up to
|
3029 |
+
* 128. If the length is greater than 128 and invalid, it will be rounded down to the closest valid amount.
|
3030 |
+
*
|
3031 |
+
* @param Integer $length
|
3032 |
+
*/
|
3033 |
+
public function setBlockLength($length)
|
3034 |
+
{
|
3035 |
+
$length >>= 5;
|
3036 |
+
if ($length > 8) {
|
3037 |
+
$length = 8;
|
3038 |
+
} elseif ($length < 4) {
|
3039 |
+
$length = 4;
|
3040 |
+
}
|
3041 |
+
$this->nb = $length;
|
3042 |
+
$this->blockSize = $length << 2;
|
3043 |
+
$this->changed = true;
|
3044 |
+
$this->setupEngine();
|
3045 |
+
}
|
3046 |
+
|
3047 |
+
/**
|
3048 |
+
* Setup the fastest possible $engine
|
3049 |
+
*
|
3050 |
+
* Determines if the mcrypt (MODE_MCRYPT) $engine available
|
3051 |
+
* and usable for the current $blockSize and $keySize.
|
3052 |
+
*
|
3053 |
+
* If not, the slower MODE_INTERNAL $engine will be set.
|
3054 |
+
*
|
3055 |
+
* @see setKey()
|
3056 |
+
* @see setKeyLength()
|
3057 |
+
* @see setBlockLength()
|
3058 |
+
*/
|
3059 |
+
public function setupEngine()
|
3060 |
+
{
|
3061 |
+
if (constant('CRYPT_'.$this->constNamespace.'_MODE') == CRYPT_MODE_INTERNAL) {
|
3062 |
+
// No mcrypt support at all for rijndael
|
3063 |
+
return;
|
3064 |
+
}
|
3065 |
+
|
3066 |
+
// The required mcrypt module name for the current $blockSize of rijndael
|
3067 |
+
$cipherNameMcrypt = 'rijndael-'.($this->blockSize << 3);
|
3068 |
+
|
3069 |
+
// Determining the availability/usability of $cipherNameMcrypt
|
3070 |
+
switch (true) {
|
3071 |
+
case $this->keySize % 8: // mcrypt is not usable for 160/224-bit keys, only for 128/192/256-bit keys
|
3072 |
+
case !in_array(
|
3073 |
+
$cipherNameMcrypt,
|
3074 |
+
mcrypt_list_algorithms()
|
3075 |
+
): // $cipherNameMcrypt is not available for the current $blockSize
|
3076 |
+
$engine = CRYPT_MODE_INTERNAL;
|
3077 |
+
break;
|
3078 |
+
default:
|
3079 |
+
$engine = CRYPT_MODE_MCRYPT;
|
3080 |
+
}
|
3081 |
+
|
3082 |
+
if ($this->engine == $engine && $this->cipherNameMcrypt == $cipherNameMcrypt) {
|
3083 |
+
// already set, so we not unnecessary close $this->enMcrypt/deMcrypt/ecb
|
3084 |
+
return;
|
3085 |
+
}
|
3086 |
+
|
3087 |
+
// Set the $engine
|
3088 |
+
$this->engine = $engine;
|
3089 |
+
$this->cipherNameMcrypt = $cipherNameMcrypt;
|
3090 |
+
|
3091 |
+
if ($this->enMcrypt) {
|
3092 |
+
// Closing the current mcrypt resource(s). _mcryptSetup() will, if needed,
|
3093 |
+
// (re)open them with the module named in $this->cipherNameMcrypt
|
3094 |
+
mcrypt_module_close($this->enMcrypt);
|
3095 |
+
mcrypt_module_close($this->deMcrypt);
|
3096 |
+
$this->enMcrypt = null;
|
3097 |
+
$this->deMcrypt = null;
|
3098 |
+
|
3099 |
+
if ($this->ecb) {
|
3100 |
+
mcrypt_module_close($this->ecb);
|
3101 |
+
$this->ecb = null;
|
3102 |
+
}
|
3103 |
+
}
|
3104 |
+
}
|
3105 |
+
|
3106 |
+
/**
|
3107 |
+
* Setup the CRYPT_MODE_MCRYPT $engine
|
3108 |
+
*
|
3109 |
+
* @see NostoCryptBase::setupMcrypt()
|
3110 |
+
*/
|
3111 |
+
public function setupMcrypt()
|
3112 |
+
{
|
3113 |
+
$this->key = str_pad(substr($this->key, 0, $this->keySize), $this->keySize, "\0");
|
3114 |
+
parent::setupMcrypt();
|
3115 |
+
}
|
3116 |
+
|
3117 |
+
/**
|
3118 |
+
* Encrypts a block
|
3119 |
+
*
|
3120 |
+
* @param String $in
|
3121 |
+
* @return String
|
3122 |
+
*/
|
3123 |
+
public function encryptBlock($in)
|
3124 |
+
{
|
3125 |
+
static $t0, $t1, $t2, $t3, $sbox;
|
3126 |
+
if (!$t0) {
|
3127 |
+
for ($i = 0; $i < 256; ++$i) {
|
3128 |
+
$t0[] = (int)$this->t0[$i];
|
3129 |
+
$t1[] = (int)$this->t1[$i];
|
3130 |
+
$t2[] = (int)$this->t2[$i];
|
3131 |
+
$t3[] = (int)$this->t3[$i];
|
3132 |
+
$sbox[] = (int)$this->sbox[$i];
|
3133 |
+
}
|
3134 |
+
}
|
3135 |
+
|
3136 |
+
$state = array();
|
3137 |
+
$words = unpack('N*', $in);
|
3138 |
+
|
3139 |
+
$c = $this->c;
|
3140 |
+
$w = $this->w;
|
3141 |
+
$nb = $this->nb;
|
3142 |
+
$nr = $this->nr;
|
3143 |
+
|
3144 |
+
// addRoundKey
|
3145 |
+
$i = -1;
|
3146 |
+
foreach ($words as $word) {
|
3147 |
+
$state[] = $word ^ $w[0][++$i];
|
3148 |
+
}
|
3149 |
+
|
3150 |
+
// fips-197.pdf#page=19, "Figure 5. Pseudo Code for the Cipher", states that this loop has four components -
|
3151 |
+
// subBytes, shiftRows, mixColumns, and addRoundKey. fips-197.pdf#page=30, "Implementation Suggestions Regarding
|
3152 |
+
// Various Platforms" suggests that performs enhanced implementations are described in Rijndael-ammended.pdf.
|
3153 |
+
// Rijndael-ammended.pdf#page=20, "Implementation aspects / 32-bit processor", discusses such an optimization.
|
3154 |
+
// Unfortunately, the description given there is not quite correct. Per aes.spec.v316.pdf#page=19 [1],
|
3155 |
+
// equation (7.4.7) is supposed to use addition instead of subtraction, so we'll do that here, as well.
|
3156 |
+
|
3157 |
+
// [1] http://fp.gladman.plus.com/cryptography_technology/rijndael/aes.spec.v316.pdf
|
3158 |
+
$temp = array();
|
3159 |
+
for ($round = 1; $round < $nr; ++$round) {
|
3160 |
+
$i = 0; // $c[0] == 0
|
3161 |
+
$j = $c[1];
|
3162 |
+
$k = $c[2];
|
3163 |
+
$l = $c[3];
|
3164 |
+
|
3165 |
+
while ($i < $nb) {
|
3166 |
+
$temp[$i] = $t0[$state[$i] >> 24 & 0x000000FF] ^
|
3167 |
+
$t1[$state[$j] >> 16 & 0x000000FF] ^
|
3168 |
+
$t2[$state[$k] >> 8 & 0x000000FF] ^
|
3169 |
+
$t3[$state[$l] & 0x000000FF] ^
|
3170 |
+
$w[$round][$i];
|
3171 |
+
++$i;
|
3172 |
+
$j = ($j + 1) % $nb;
|
3173 |
+
$k = ($k + 1) % $nb;
|
3174 |
+
$l = ($l + 1) % $nb;
|
3175 |
+
}
|
3176 |
+
$state = $temp;
|
3177 |
+
}
|
3178 |
+
|
3179 |
+
// subWord
|
3180 |
+
for ($i = 0; $i < $nb; ++$i) {
|
3181 |
+
$state[$i] = $sbox[$state[$i] & 0x000000FF] |
|
3182 |
+
($sbox[$state[$i] >> 8 & 0x000000FF] << 8) |
|
3183 |
+
($sbox[$state[$i] >> 16 & 0x000000FF] << 16) |
|
3184 |
+
($sbox[$state[$i] >> 24 & 0x000000FF] << 24);
|
3185 |
+
}
|
3186 |
+
|
3187 |
+
// shiftRows + addRoundKey
|
3188 |
+
$i = 0; // $c[0] == 0
|
3189 |
+
$j = $c[1];
|
3190 |
+
$k = $c[2];
|
3191 |
+
$l = $c[3];
|
3192 |
+
while ($i < $nb) {
|
3193 |
+
$temp[$i] = ($state[$i] & 0xFF000000) ^
|
3194 |
+
($state[$j] & 0x00FF0000) ^
|
3195 |
+
($state[$k] & 0x0000FF00) ^
|
3196 |
+
($state[$l] & 0x000000FF) ^
|
3197 |
+
$w[$nr][$i];
|
3198 |
+
++$i;
|
3199 |
+
$j = ($j + 1) % $nb;
|
3200 |
+
$k = ($k + 1) % $nb;
|
3201 |
+
$l = ($l + 1) % $nb;
|
3202 |
+
}
|
3203 |
+
|
3204 |
+
switch ($nb) {
|
3205 |
+
case 8:
|
3206 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5], $temp[6], $temp[7]);
|
3207 |
+
case 7:
|
3208 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5], $temp[6]);
|
3209 |
+
case 6:
|
3210 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5]);
|
3211 |
+
case 5:
|
3212 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4]);
|
3213 |
+
default:
|
3214 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3]);
|
3215 |
+
}
|
3216 |
+
}
|
3217 |
+
|
3218 |
+
/**
|
3219 |
+
* Decrypts a block
|
3220 |
+
*
|
3221 |
+
* @param String $in
|
3222 |
+
* @return String
|
3223 |
+
*/
|
3224 |
+
public function decryptBlock($in)
|
3225 |
+
{
|
3226 |
+
static $dt0, $dt1, $dt2, $dt3, $isbox;
|
3227 |
+
if (!$dt0) {
|
3228 |
+
for ($i = 0; $i < 256; ++$i) {
|
3229 |
+
$dt0[] = (int)$this->dt0[$i];
|
3230 |
+
$dt1[] = (int)$this->dt1[$i];
|
3231 |
+
$dt2[] = (int)$this->dt2[$i];
|
3232 |
+
$dt3[] = (int)$this->dt3[$i];
|
3233 |
+
$isbox[] = (int)$this->isbox[$i];
|
3234 |
+
}
|
3235 |
+
}
|
3236 |
+
|
3237 |
+
$state = array();
|
3238 |
+
$words = unpack('N*', $in);
|
3239 |
+
|
3240 |
+
$c = $this->c;
|
3241 |
+
$dw = $this->dw;
|
3242 |
+
$nb = $this->nb;
|
3243 |
+
$nr = $this->nr;
|
3244 |
+
|
3245 |
+
// addRoundKey
|
3246 |
+
$i = -1;
|
3247 |
+
foreach ($words as $word) {
|
3248 |
+
$state[] = $word ^ $dw[$nr][++$i];
|
3249 |
+
}
|
3250 |
+
|
3251 |
+
$temp = array();
|
3252 |
+
for ($round = $nr - 1; $round > 0; --$round) {
|
3253 |
+
$i = 0; // $c[0] == 0
|
3254 |
+
$j = $nb - $c[1];
|
3255 |
+
$k = $nb - $c[2];
|
3256 |
+
$l = $nb - $c[3];
|
3257 |
+
|
3258 |
+
while ($i < $nb) {
|
3259 |
+
$temp[$i] = $dt0[$state[$i] >> 24 & 0x000000FF] ^
|
3260 |
+
$dt1[$state[$j] >> 16 & 0x000000FF] ^
|
3261 |
+
$dt2[$state[$k] >> 8 & 0x000000FF] ^
|
3262 |
+
$dt3[$state[$l] & 0x000000FF] ^
|
3263 |
+
$dw[$round][$i];
|
3264 |
+
++$i;
|
3265 |
+
$j = ($j + 1) % $nb;
|
3266 |
+
$k = ($k + 1) % $nb;
|
3267 |
+
$l = ($l + 1) % $nb;
|
3268 |
+
}
|
3269 |
+
$state = $temp;
|
3270 |
+
}
|
3271 |
+
|
3272 |
+
// invShiftRows + invSubWord + addRoundKey
|
3273 |
+
$i = 0; // $c[0] == 0
|
3274 |
+
$j = $nb - $c[1];
|
3275 |
+
$k = $nb - $c[2];
|
3276 |
+
$l = $nb - $c[3];
|
3277 |
+
|
3278 |
+
while ($i < $nb) {
|
3279 |
+
$word = ($state[$i] & 0xFF000000) |
|
3280 |
+
($state[$j] & 0x00FF0000) |
|
3281 |
+
($state[$k] & 0x0000FF00) |
|
3282 |
+
($state[$l] & 0x000000FF);
|
3283 |
+
|
3284 |
+
$temp[$i] = $dw[0][$i] ^ ($isbox[$word & 0x000000FF] |
|
3285 |
+
($isbox[$word >> 8 & 0x000000FF] << 8) |
|
3286 |
+
($isbox[$word >> 16 & 0x000000FF] << 16) |
|
3287 |
+
($isbox[$word >> 24 & 0x000000FF] << 24));
|
3288 |
+
++$i;
|
3289 |
+
$j = ($j + 1) % $nb;
|
3290 |
+
$k = ($k + 1) % $nb;
|
3291 |
+
$l = ($l + 1) % $nb;
|
3292 |
+
}
|
3293 |
+
|
3294 |
+
switch ($nb) {
|
3295 |
+
case 8:
|
3296 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5], $temp[6], $temp[7]);
|
3297 |
+
case 7:
|
3298 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5], $temp[6]);
|
3299 |
+
case 6:
|
3300 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4], $temp[5]);
|
3301 |
+
case 5:
|
3302 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3], $temp[4]);
|
3303 |
+
default:
|
3304 |
+
return pack('N*', $temp[0], $temp[1], $temp[2], $temp[3]);
|
3305 |
+
}
|
3306 |
+
}
|
3307 |
+
|
3308 |
+
/**
|
3309 |
+
* Setup the key (expansion)
|
3310 |
+
*
|
3311 |
+
* @see NostoCryptBase::setupKey()
|
3312 |
+
*/
|
3313 |
+
public function setupKey()
|
3314 |
+
{
|
3315 |
+
// Each number in $rcon is equal to the previous number multiplied by two in Rijndael's finite field.
|
3316 |
+
// See http://en.wikipedia.org/wiki/Finite_field_arithmetic#Multiplicative_inverse
|
3317 |
+
static $rcon = array(
|
3318 |
+
0,
|
3319 |
+
0x01000000,
|
3320 |
+
0x02000000,
|
3321 |
+
0x04000000,
|
3322 |
+
0x08000000,
|
3323 |
+
0x10000000,
|
3324 |
+
0x20000000,
|
3325 |
+
0x40000000,
|
3326 |
+
0x80000000,
|
3327 |
+
0x1B000000,
|
3328 |
+
0x36000000,
|
3329 |
+
0x6C000000,
|
3330 |
+
0xD8000000,
|
3331 |
+
0xAB000000,
|
3332 |
+
0x4D000000,
|
3333 |
+
0x9A000000,
|
3334 |
+
0x2F000000,
|
3335 |
+
0x5E000000,
|
3336 |
+
0xBC000000,
|
3337 |
+
0x63000000,
|
3338 |
+
0xC6000000,
|
3339 |
+
0x97000000,
|
3340 |
+
0x35000000,
|
3341 |
+
0x6A000000,
|
3342 |
+
0xD4000000,
|
3343 |
+
0xB3000000,
|
3344 |
+
0x7D000000,
|
3345 |
+
0xFA000000,
|
3346 |
+
0xEF000000,
|
3347 |
+
0xC5000000,
|
3348 |
+
0x91000000
|
3349 |
+
);
|
3350 |
+
|
3351 |
+
$this->key = str_pad(substr($this->key, 0, $this->keySize), $this->keySize, "\0");
|
3352 |
+
|
3353 |
+
if (isset($this->kl['key'])
|
3354 |
+
&& $this->key === $this->kl['key']
|
3355 |
+
&& $this->keySize === $this->kl['keySize']
|
3356 |
+
&& $this->blockSize === $this->kl['blockSize']
|
3357 |
+
) {
|
3358 |
+
// already expanded
|
3359 |
+
return;
|
3360 |
+
}
|
3361 |
+
$this->kl = array('key' => $this->key, 'keySize' => $this->keySize, 'blockSize' => $this->blockSize);
|
3362 |
+
|
3363 |
+
$this->nk = $this->keySize >> 2;
|
3364 |
+
// see Rijndael-ammended.pdf#page=44
|
3365 |
+
$this->nr = max($this->nk, $this->nb) + 6;
|
3366 |
+
|
3367 |
+
// shift offsets for Nb = 5, 7 are defined in Rijndael-ammended.pdf#page=44,
|
3368 |
+
// "Table 8: Shift offsets in Shiftrow for the alternative block lengths"
|
3369 |
+
// shift offsets for Nb = 4, 6, 8 are defined in Rijndael-ammended.pdf#page=14,
|
3370 |
+
// "Table 2: Shift offsets for different block lengths"
|
3371 |
+
switch ($this->nb) {
|
3372 |
+
case 4:
|
3373 |
+
case 5:
|
3374 |
+
case 6:
|
3375 |
+
$this->c = array(0, 1, 2, 3);
|
3376 |
+
break;
|
3377 |
+
case 7:
|
3378 |
+
$this->c = array(0, 1, 2, 4);
|
3379 |
+
break;
|
3380 |
+
case 8:
|
3381 |
+
$this->c = array(0, 1, 3, 4);
|
3382 |
+
}
|
3383 |
+
|
3384 |
+
$w = array_values(unpack('N*words', $this->key));
|
3385 |
+
|
3386 |
+
$length = $this->nb * ($this->nr + 1);
|
3387 |
+
for ($i = $this->nk; $i < $length; $i++) {
|
3388 |
+
$temp = $w[$i - 1];
|
3389 |
+
if ($i % $this->nk == 0) {
|
3390 |
+
// according to <http://php.net/language.types.integer>, "the size of an integer is platform-dependent".
|
3391 |
+
// on a 32-bit machine, it's 32-bits, and on a 64-bit machine, it's 64-bits. on a 32-bit machine,
|
3392 |
+
// 0xFFFFFFFF << 8 == 0xFFFFFF00, but on a 64-bit machine, it equals 0xFFFFFFFF00. as such, doing 'and'
|
3393 |
+
// with 0xFFFFFFFF (or 0xFFFFFF00) on a 32-bit machine is unnecessary, but on a 64-bit machine, it is.
|
3394 |
+
$temp = (($temp << 8) & 0xFFFFFF00) | (($temp >> 24) & 0x000000FF); // rotWord
|
3395 |
+
$temp = $this->subWord($temp) ^ $rcon[(int)($i / $this->nk)];
|
3396 |
+
} elseif ($this->nk > 6 && $i % $this->nk == 4) {
|
3397 |
+
$temp = $this->subWord($temp);
|
3398 |
+
}
|
3399 |
+
|
3400 |
+
$w[$i] = $w[$i - $this->nk] ^ $temp;
|
3401 |
+
}
|
3402 |
+
|
3403 |
+
// convert the key schedule from a vector of $Nb * ($Nr + 1) length to a matrix with $Nr + 1 rows and $Nb
|
3404 |
+
// columns and generate the inverse key schedule. more specifically,
|
3405 |
+
// according to <http://csrc.nist.gov/archive/aes/rijndael/Rijndael-ammended.pdf#page=23> (section 5.3.3),
|
3406 |
+
// "The key expansion for the Inverse Cipher is defined as follows:
|
3407 |
+
// 1. Apply the Key Expansion.
|
3408 |
+
// 2. Apply InvMixColumn to all Round Keys except the first and the last one."
|
3409 |
+
// also, see fips-197.pdf#page=27, "5.3.5 Equivalent Inverse Cipher"
|
3410 |
+
$temp = $this->w = $this->dw = array();
|
3411 |
+
for ($i = $row = $col = 0; $i < $length; $i++, $col++) {
|
3412 |
+
if ($col == $this->nb) {
|
3413 |
+
if ($row == 0) {
|
3414 |
+
$this->dw[0] = $this->w[0];
|
3415 |
+
} else {
|
3416 |
+
// subWord + invMixColumn + invSubWord = invMixColumn
|
3417 |
+
$j = 0;
|
3418 |
+
while ($j < $this->nb) {
|
3419 |
+
$dw = $this->subWord($this->w[$row][$j]);
|
3420 |
+
$temp[$j] = $this->dt0[$dw >> 24 & 0x000000FF] ^
|
3421 |
+
$this->dt1[$dw >> 16 & 0x000000FF] ^
|
3422 |
+
$this->dt2[$dw >> 8 & 0x000000FF] ^
|
3423 |
+
$this->dt3[$dw & 0x000000FF];
|
3424 |
+
$j++;
|
3425 |
+
}
|
3426 |
+
$this->dw[$row] = $temp;
|
3427 |
+
}
|
3428 |
+
|
3429 |
+
$col = 0;
|
3430 |
+
$row++;
|
3431 |
+
}
|
3432 |
+
$this->w[$row][$col] = $w[$i];
|
3433 |
+
}
|
3434 |
+
|
3435 |
+
$this->dw[$row] = $this->w[$row];
|
3436 |
+
|
3437 |
+
// In case of $this->useInlineCrypt === true we have to use 1-dim key arrays (both ascending)
|
3438 |
+
if ($this->useInlineCrypt) {
|
3439 |
+
$this->dw = array_reverse($this->dw);
|
3440 |
+
$w = array_pop($this->w);
|
3441 |
+
$dw = array_pop($this->dw);
|
3442 |
+
foreach ($this->w as $r => $wr) {
|
3443 |
+
foreach ($wr as $c => $wc) {
|
3444 |
+
$w[] = $wc;
|
3445 |
+
$dw[] = $this->dw[$r][$c];
|
3446 |
+
}
|
3447 |
+
}
|
3448 |
+
$this->w = $w;
|
3449 |
+
$this->dw = $dw;
|
3450 |
+
}
|
3451 |
+
}
|
3452 |
+
|
3453 |
+
/**
|
3454 |
+
* Performs S-Box substitutions
|
3455 |
+
*
|
3456 |
+
* @param Integer $word
|
3457 |
+
* @return Integer
|
3458 |
+
*/
|
3459 |
+
public function subWord($word)
|
3460 |
+
{
|
3461 |
+
$sbox = $this->sbox;
|
3462 |
+
|
3463 |
+
return $sbox[$word & 0x000000FF] |
|
3464 |
+
($sbox[$word >> 8 & 0x000000FF] << 8) |
|
3465 |
+
($sbox[$word >> 16 & 0x000000FF] << 16) |
|
3466 |
+
($sbox[$word >> 24 & 0x000000FF] << 24);
|
3467 |
+
}
|
3468 |
+
|
3469 |
+
/**
|
3470 |
+
* Setup the performance-optimized function for de/encrypt()
|
3471 |
+
*
|
3472 |
+
* @see NostoCryptBase::setupInlineCrypt()
|
3473 |
+
*/
|
3474 |
+
public function setupInlineCrypt()
|
3475 |
+
{
|
3476 |
+
// Note: _setupInlineCrypt() will be called only if $this->changed === true
|
3477 |
+
// So here we are not under the same heavy timing-stress as we are in _de/encryptBlock() or de/encrypt().
|
3478 |
+
// However...the here generated function- $code, stored as php callback in $this->inlineCrypt, must work as fast
|
3479 |
+
// as even possible.
|
3480 |
+
|
3481 |
+
$lambda_functions =& NostoCryptRijndael::getLambdaFunctions();
|
3482 |
+
$w = array();
|
3483 |
+
$dw = array();
|
3484 |
+
|
3485 |
+
// The first 10 generated $lambda_functions will use the key-words hardcoded for better performance.
|
3486 |
+
// For memory reason we limit those ultra-optimized functions.
|
3487 |
+
// After that, we use pure (extracted) integer vars for the key-words which is faster than accessing them via
|
3488 |
+
// array.
|
3489 |
+
if (count($lambda_functions) < 10) {
|
3490 |
+
$w = $this->w;
|
3491 |
+
$dw = $this->dw;
|
3492 |
+
$init_encrypt = '';
|
3493 |
+
$init_decrypt = '';
|
3494 |
+
} else {
|
3495 |
+
for ($i = 0, $cw = count($this->w); $i < $cw; ++$i) {
|
3496 |
+
$w[] = '$w['.$i.']';
|
3497 |
+
$dw[] = '$dw['.$i.']';
|
3498 |
+
}
|
3499 |
+
$init_encrypt = '$w = $self->w;';
|
3500 |
+
$init_decrypt = '$dw = $self->dw;';
|
3501 |
+
}
|
3502 |
+
|
3503 |
+
$code_hash = md5(str_pad("NostoCryptRijndael, {$this->mode}, {$this->blockSize}, ", 32, "\0").implode(',', $w));
|
3504 |
+
|
3505 |
+
if (!isset($lambda_functions[$code_hash])) {
|
3506 |
+
$nr = $this->nr;
|
3507 |
+
$nb = $this->nb;
|
3508 |
+
$c = $this->c;
|
3509 |
+
|
3510 |
+
// Generating encrypt code:
|
3511 |
+
$init_encrypt .= '
|
3512 |
+
static $t0, $t1, $t2, $t3, $sbox;
|
3513 |
+
if (!$t0) {
|
3514 |
+
for ($i = 0; $i < 256; ++$i) {
|
3515 |
+
$t0[$i] = (int)$self->t0[$i];
|
3516 |
+
$t1[$i] = (int)$self->t1[$i];
|
3517 |
+
$t2[$i] = (int)$self->t2[$i];
|
3518 |
+
$t3[$i] = (int)$self->t3[$i];
|
3519 |
+
$sbox[$i] = (int)$self->sbox[$i];
|
3520 |
+
}
|
3521 |
+
}
|
3522 |
+
';
|
3523 |
+
|
3524 |
+
$s = 'e';
|
3525 |
+
$e = 's';
|
3526 |
+
$wc = $nb - 1;
|
3527 |
+
|
3528 |
+
// Pre-round: addRoundKey
|
3529 |
+
$encrypt_block = '$in = unpack("N*", $in);'."\n";
|
3530 |
+
for ($i = 0; $i < $nb; ++$i) {
|
3531 |
+
$encrypt_block .= '$s'.$i.' = $in['.($i + 1).'] ^ '.$w[++$wc].";\n";
|
3532 |
+
}
|
3533 |
+
|
3534 |
+
// Main-rounds: shiftRows + subWord + mixColumns + addRoundKey
|
3535 |
+
for ($round = 1; $round < $nr; ++$round) {
|
3536 |
+
list($s, $e) = array($e, $s);
|
3537 |
+
for ($i = 0; $i < $nb; ++$i) {
|
3538 |
+
$encrypt_block .=
|
3539 |
+
'$'.$e.$i.' =
|
3540 |
+
$t0[($'.$s.$i.' >> 24) & 0xff] ^
|
3541 |
+
$t1[($'.$s.(($i + $c[1]) % $nb).' >> 16) & 0xff] ^
|
3542 |
+
$t2[($'.$s.(($i + $c[2]) % $nb).' >> 8) & 0xff] ^
|
3543 |
+
$t3[ $'.$s.(($i + $c[3]) % $nb).' & 0xff] ^
|
3544 |
+
'.$w[++$wc].";\n";
|
3545 |
+
}
|
3546 |
+
}
|
3547 |
+
|
3548 |
+
// Final-round: subWord + shiftRows + addRoundKey
|
3549 |
+
for ($i = 0; $i < $nb; ++$i) {
|
3550 |
+
$encrypt_block .=
|
3551 |
+
'$'.$e.$i.' =
|
3552 |
+
$sbox[ $'.$e.$i.' & 0xff] |
|
3553 |
+
($sbox[($'.$e.$i.' >> 8) & 0xff] << 8) |
|
3554 |
+
($sbox[($'.$e.$i.' >> 16) & 0xff] << 16) |
|
3555 |
+
($sbox[($'.$e.$i.' >> 24) & 0xff] << 24);'."\n";
|
3556 |
+
}
|
3557 |
+
$encrypt_block .= '$in = pack("N*"'."\n";
|
3558 |
+
for ($i = 0; $i < $nb; ++$i) {
|
3559 |
+
$encrypt_block .= ',
|
3560 |
+
($'.$e.$i.' & 0xFF000000) ^
|
3561 |
+
($'.$e.(($i + $c[1]) % $nb).' & 0x00FF0000) ^
|
3562 |
+
($'.$e.(($i + $c[2]) % $nb).' & 0x0000FF00) ^
|
3563 |
+
($'.$e.(($i + $c[3]) % $nb).' & 0x000000FF) ^
|
3564 |
+
'.$w[$i]."\n";
|
3565 |
+
}
|
3566 |
+
$encrypt_block .= ');';
|
3567 |
+
|
3568 |
+
// Generating decrypt code:
|
3569 |
+
$init_decrypt .= '
|
3570 |
+
static $dt0, $dt1, $dt2, $dt3, $isbox;
|
3571 |
+
if (!$dt0) {
|
3572 |
+
for ($i = 0; $i < 256; ++$i) {
|
3573 |
+
$dt0[$i] = (int)$self->dt0[$i];
|
3574 |
+
$dt1[$i] = (int)$self->dt1[$i];
|
3575 |
+
$dt2[$i] = (int)$self->dt2[$i];
|
3576 |
+
$dt3[$i] = (int)$self->dt3[$i];
|
3577 |
+
$isbox[$i] = (int)$self->isbox[$i];
|
3578 |
+
}
|
3579 |
+
}
|
3580 |
+
';
|
3581 |
+
|
3582 |
+
$s = 'e';
|
3583 |
+
$e = 's';
|
3584 |
+
$wc = $nb - 1;
|
3585 |
+
|
3586 |
+
// Pre-round: addRoundKey
|
3587 |
+
$decrypt_block = '$in = unpack("N*", $in);'."\n";
|
3588 |
+
for ($i = 0; $i < $nb; ++$i) {
|
3589 |
+
$decrypt_block .= '$s'.$i.' = $in['.($i + 1).'] ^ '.$dw[++$wc].';'."\n";
|
3590 |
+
}
|
3591 |
+
|
3592 |
+
// Main-rounds: shiftRows + subWord + mixColumns + addRoundKey
|
3593 |
+
for ($round = 1; $round < $nr; ++$round) {
|
3594 |
+
list($s, $e) = array($e, $s);
|
3595 |
+
for ($i = 0; $i < $nb; ++$i) {
|
3596 |
+
$decrypt_block .=
|
3597 |
+
'$'.$e.$i.' =
|
3598 |
+
$dt0[($'.$s.$i.' >> 24) & 0xff] ^
|
3599 |
+
$dt1[($'.$s.(($nb + $i - $c[1]) % $nb).' >> 16) & 0xff] ^
|
3600 |
+
$dt2[($'.$s.(($nb + $i - $c[2]) % $nb).' >> 8) & 0xff] ^
|
3601 |
+
$dt3[ $'.$s.(($nb + $i - $c[3]) % $nb).' & 0xff] ^
|
3602 |
+
'.$dw[++$wc].";\n";
|
3603 |
+
}
|
3604 |
+
}
|
3605 |
+
|
3606 |
+
// Finalround: subWord + shiftRows + addRoundKey
|
3607 |
+
for ($i = 0; $i < $nb; ++$i) {
|
3608 |
+
$decrypt_block .=
|
3609 |
+
'$'.$e.$i.' =
|
3610 |
+
$isbox[ $'.$e.$i.' & 0xff] |
|
3611 |
+
($isbox[($'.$e.$i.' >> 8) & 0xff] << 8) |
|
3612 |
+
($isbox[($'.$e.$i.' >> 16) & 0xff] << 16) |
|
3613 |
+
($isbox[($'.$e.$i.' >> 24) & 0xff] << 24);'."\n";
|
3614 |
+
}
|
3615 |
+
$decrypt_block .= '$in = pack("N*"'."\n";
|
3616 |
+
for ($i = 0; $i < $nb; ++$i) {
|
3617 |
+
$decrypt_block .= ',
|
3618 |
+
($'.$e.$i.' & 0xFF000000) ^
|
3619 |
+
($'.$e.(($nb + $i - $c[1]) % $nb).' & 0x00FF0000) ^
|
3620 |
+
($'.$e.(($nb + $i - $c[2]) % $nb).' & 0x0000FF00) ^
|
3621 |
+
($'.$e.(($nb + $i - $c[3]) % $nb).' & 0x000000FF) ^
|
3622 |
+
'.$dw[$i]."\n";
|
3623 |
+
}
|
3624 |
+
$decrypt_block .= ');';
|
3625 |
+
|
3626 |
+
$lambda_functions[$code_hash] = $this->createInlineCryptFunction(
|
3627 |
+
array(
|
3628 |
+
'init_crypt' => '',
|
3629 |
+
'init_encrypt' => $init_encrypt,
|
3630 |
+
'init_decrypt' => $init_decrypt,
|
3631 |
+
'encrypt_block' => $encrypt_block,
|
3632 |
+
'decrypt_block' => $decrypt_block
|
3633 |
+
)
|
3634 |
+
);
|
3635 |
+
}
|
3636 |
+
$this->inlineCrypt = $lambda_functions[$code_hash];
|
3637 |
+
}
|
3638 |
+
}
|
package.xml
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<package>
|
3 |
+
<name>Nosto_Tagging</name>
|
4 |
+
<version>2.2.0</version>
|
5 |
+
<stability>stable</stability>
|
6 |
+
<license uri="http://opensource.org/licenses/osl-3.0.php">Open Software License (OSL)</license>
|
7 |
+
<channel>community</channel>
|
8 |
+
<extends/>
|
9 |
+
<summary>Personalization for Magento</summary>
|
10 |
+
<description>Increase your conversion rate and average order value by delivering your customers personalized product recommendations throughout their shopping journey.</description>
|
11 |
+
<notes>* Change product re-crawl to send both id and url for products that have been added/modified</notes>
|
12 |
+
<authors><author><name>Nosto</name><user>nosto</user><email>magento@nosto.com</email></author></authors>
|
13 |
+
<date>2015-04-15</date>
|
14 |
+
<time>11:09:51</time>
|
15 |
+
<contents><target name="magecommunity"><dir name="Nosto"><dir name="Tagging"><dir name="Block"><dir name="Adminhtml"><file name="Iframe.php" hash="158340d20d1a01a0863f24278198c2e5"/><file name="Wizard.php" hash="f98931a1a6e327c0d05e43b73063f672"/></dir><file name="Cart.php" hash="feb9b5d1c84d2301c9f74613559dceb7"/><file name="Category.php" hash="177a5d8d9f1ba9e246d149c228c3aec8"/><file name="Customer.php" hash="d35777ca399244e4fb441456320f8ad7"/><file name="Element.php" hash="e5b12bb118b92eb7075ff7a6e16e0eba"/><file name="Embed.php" hash="e8b628b6bc49fb865697552300d08526"/><file name="Meta.php" hash="1f761e731214b7572ef139d9e0577ea1"/><file name="Order.php" hash="1666d552e61768cfd35860b9472feced"/><file name="Product.php" hash="261cd58ad94daa82d1cf2188179278c0"/></dir><dir name="Helper"><file name="Account.php" hash="afd5f7e1bc61a5ab450e0483db371370"/><file name="Customer.php" hash="92da4f0ae6c2aef635b837635cd74238"/><file name="Data.php" hash="b138748cea6b7c4ccda41e7f2ef1f1cb"/><file name="Date.php" hash="1a108a4ec8169b73411b6c11b86a1d80"/><file name="Oauth.php" hash="08f096ef785d64225ec71d7e2e99f534"/><file name="Price.php" hash="4c21321d10f40c6f985bd934b174a17c"/><file name="Url.php" hash="289294904d246c56e4de96798927a7f6"/></dir><dir name="Model"><dir name="Container"><file name="Cart.php" hash="20d2936693361999575f1e6ac56f2e40"/><file name="Customer.php" hash="b03bca89845b6c939521add8df1f7e9a"/></dir><file name="Customer.php" hash="6d992a43a75f29836ed1450e130df560"/><dir name="Meta"><dir name="Account"><file name="Billing.php" hash="d09b6b6ddc543201ec9485db9bb0a260"/><file name="Iframe.php" hash="f26a7ef337d86cb83c687ba2e0beb45b"/><file name="Owner.php" hash="801c33bbf04bcfbe133654770909d1df"/></dir><file name="Account.php" hash="c01a324111528339ddd71f0046b95ecc"/><file name="Oauth.php" hash="761b0dd6cede8122c715d077b010b927"/><dir name="Order"><file name="Buyer.php" hash="633c6de58a46128bb594d6580d3ffa46"/><file name="Item.php" hash="86baa577302a4791fa68981b06c2957c"/></dir><file name="Order.php" hash="7f041ef68a1f0652b4e2f92d0ef1c46b"/><file name="Product.php" hash="81bc01d556456090f1d094177fb81adb"/></dir><file name="Observer.php" hash="87bfc436fd2c2d05dd80f1caa2d92b22"/><dir name="Resource"><dir name="Customer"><file name="Collection.php" hash="0c99b46d5108a6fe31cad1190d8ef47c"/></dir><file name="Customer.php" hash="f92e4e5334b5e3493e8f04664b20f105"/><file name="Setup.php" hash="506b08bcb10cbe74e95812c5f646429f"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="NostoController.php" hash="4e7918941aa664562bb6129eef685f32"/></dir><file name="ExportController.php" hash="5c4d78762f631c759559af9e356b7f86"/><file name="OauthController.php" hash="e57a2578535e711ce1bdcb78e3fa1983"/></dir><dir name="etc"><file name="adminhtml.xml" hash="70f3a22856ec6cb31749a92ed4461b6b"/><file name="cache.xml" hash="e874fbbf2eb89b325deb1a62afbcfb4d"/><file name="config.xml" hash="2760929c5b6f165c6483b199513d76a2"/></dir><dir name="sql"><dir name="tagging_setup"><file name="mysql4-install-1.2.0.php" hash="3cbc52834c44870859562eec7969b9fd"/><file name="mysql4-upgrade-1.1.7-1.2.0.php" hash="0d8eb7990461a9d4b74b479120067aeb"/></dir></dir></dir></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="nostotagging"><file name="iframe.phtml" hash="c81931adf855a4893e0cf2dc60c390cb"/><file name="wizard.phtml" hash="3f92e94e5ee3d3cd9906a6b0942a3a1b"/></dir></dir><dir name="layout"><file name="nostotagging.xml" hash="5f77c6921f67d08484c6d510b4706c29"/></dir></dir></dir></dir><dir name="frontend"><dir name="base"><dir name="default"><dir name="template"><dir name="nostotagging"><file name="cart.phtml" hash="c3d560050239066c73b1ec935048dbee"/><dir name="category"><file name="view.phtml" hash="fc09e2770ad6281ec96c8e92accc01f1"/></dir><file name="category.phtml" hash="81f36742cb4e3adbf9f692cc8f0ea8a8"/><file name="customer.phtml" hash="e9bc92bb7f7df989cc706c7eaee3614a"/><file name="element.phtml" hash="e1d38981789e632a3607ccf2e171f0cb"/><file name="embed.phtml" hash="9193ddd1ae373b68c53f8364f511b0a5"/><file name="meta.phtml" hash="c1b862a4993503fae420fb0eba194b00"/><file name="order.phtml" hash="7d65566ba4ee709dab7f2114340742af"/><file name="product.phtml" hash="412b7bd9ed43981f056132ea37719aab"/></dir></dir><dir name="layout"><file name="nostotagging.xml" hash="0ff843226af2cf96cac80764034ac15c"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Nosto_Tagging.xml" hash="1705cb7e6db28388662ef52882d61701"/></dir></target><target name="magelib"><dir name="nosto"><dir name="php-sdk"><dir name="src"><dir name="classes"><file name="Nosto.php" hash="80254fcb3fcda48a25cc3d4585b5f6ac"/><file name="NostoAccount.php" hash="17e77036cb2c068678cbe06d5f9b9086"/><file name="NostoCipher.php" hash="a3d7d148311aa0319387c0918e5e26dc"/><file name="NostoDotEnv.php" hash="90b23c1b02095c9368372f1d5346c3f9"/><file name="NostoException.php" hash="c4610fb70278d01bd85bc83b8e74df30"/><file name="NostoMessage.php" hash="5933eadd2ad08427010b0bf16657266b"/><file name="NostoOrderConfirmation.php" hash="5f6ea05fe40211433f5cd354244c3513"/><file name="NostoProductReCrawl.php" hash="adf49008cea0004c5a1f82b4bebdfbaa"/><file name="NostoXhrResponse.php" hash="a65d1d16b4a027c27ecc3c137fc07f63"/><dir name="api"><file name="NostoApiRequest.php" hash="a4960738a0ee3504a44168947057cd88"/><file name="NostoApiToken.php" hash="ca42b406a88735ac1565bf13efdf8a04"/></dir><dir name="export"><file name="NostoExportCollection.php" hash="fb539cc4ab9441b3b8529d1a8e5dae2e"/><file name="NostoExportOrderCollection.php" hash="c34cccb2d0593c31b54eeb541478aa0b"/><file name="NostoExportProductCollection.php" hash="4d461dddf9f89b7f51c82cb3e5a02530"/><file name="NostoExporter.php" hash="8d3f095c99662fc34c0a671799a1378e"/></dir><dir name="helper"><file name="NostoHelper.php" hash="f4ca6c78e047fec93c32b7eb822b0692"/><file name="NostoHelperDate.php" hash="081a2d8bfec710f2baa52192a99a2658"/><file name="NostoHelperIframe.php" hash="1364153a359dcfdf22f7376aba66da47"/><file name="NostoHelperPrice.php" hash="ee9f217dc1b8e0fc679fb56ca3fd3ca1"/></dir><dir name="http"><file name="NostoHttpRequest.php" hash="442e18206374924719d24c2e9c0b1fd3"/><file name="NostoHttpRequestAdapter.php" hash="1a76cc5ceba3caae37c73390a2096c98"/><file name="NostoHttpRequestAdapterCurl.php" hash="d3947393b19b50eb9871546dc2057b25"/><file name="NostoHttpRequestAdapterSocket.php" hash="3a3dfbb13b51d1abb14215df253d7d64"/><file name="NostoHttpResponse.php" hash="5c993520d4375103bca2b580a35987eb"/></dir><dir name="oauth"><file name="NostoOAuthClient.php" hash="d5b832ea8eca0fa8fdc05d27077b504b"/><file name="NostoOAuthToken.php" hash="f81c1c1e5c4fc2010162d8f69de2cb33"/></dir></dir><file name="config.inc.php" hash="f586713798d3e731b2dffd2da7e15861"/><dir name="interfaces"><file name="NostoOAuthClientMetaDataInterface.php" hash="75a82417bfc27cd82e41ea9810d31428"/><file name="NostoProductInterface.php" hash="110aabc704bed12ddacc304d6d1e1529"/><dir name="account"><file name="NostoAccountInterface.php" hash="5655c43db9e1e0a8e1fd23753ec5ef06"/><file name="NostoAccountMetaDataBillingDetailsInterface.php" hash="ef31f0c3b41591fd76f85a25021f0fe4"/><file name="NostoAccountMetaDataIframeInterface.php" hash="c739e6a3ef39a308df6852361f2fd1d7"/><file name="NostoAccountMetaDataInterface.php" hash="7395de56fb4e3a1831bc5f7cfeffed8d"/><file name="NostoAccountMetaDataOwnerInterface.php" hash="4c037b8cb1b529c16c91f25cce2b0ed7"/></dir><dir name="order"><file name="NostoOrderBuyerInterface.php" hash="890884e45bcca61f96f0f98cda40b6c1"/><file name="NostoOrderInterface.php" hash="d2d5d0770a383acd6004722ef376fcb5"/><file name="NostoOrderPurchasedItemInterface.php" hash="e33b94290465eea80d614db35144b75a"/></dir></dir><dir name="js"><file name="NostoIframe.min.js" hash="b4508aed29b641e6ad3d1062a54c209f"/><dir name="src"><file name="NostoIframe.js" hash="e9962928ba1cf0ff205e21a0d469f4d8"/></dir></dir><dir name="libs"><dir name="phpseclib"><dir name="crypt"><file name="NostoCryptAES.php" hash="7f16ec6fa7eefa011a27acf4506a3b57"/><file name="NostoCryptBase.php" hash="c78432d428ad8a70be832f91261d4c42"/><file name="NostoCryptRandom.php" hash="eb21a56b9cf6e6ef0b220620dd4d0ebe"/><file name="NostoCryptRijndael.php" hash="9c728d06c0249f8bc24a7c61606ccc89"/></dir></dir></dir><file name=".env.example" hash="ec9fd4d90a792e2c98b10ff8fe7ae984"/></dir></dir></dir></target><target name="mage"><dir name="js"><dir name="nosto"><file name="NostoIframe.min.js" hash="b4508aed29b641e6ad3d1062a54c209f"/><file name="iframeresizer.min.js" hash="163b065c9dd702dc364913a951b81fee"/><file name="nostotagging-config.js" hash="0119fb333233f1f0fa70f4167fb014ef"/></dir></dir></target></contents>
|
16 |
+
<compatible/>
|
17 |
+
<dependencies><required><php><min>5.2.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0.0</min><max>1.9.1.0</max></package></required></dependencies>
|
18 |
+
</package>
|