editionguard_drm - Version 1.0.0.0

Version Notes

Initial release.

Download this release

Release Info

Developer EditionGuard
Extension editionguard_drm
Version 1.0.0.0
Comparing to
See all releases


Version 1.0.0.0

app/code/community/Editionguard/Editionguard/Block/Downloadable/Adminhtml/Catalog/Product/Edit/Tab/Downloadable/Links.php ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EditionGuard
4
+ *
5
+ * This source file is proprietary property of EditionGuard. Any reuse or
6
+ * distribution of any part of this file without prior consent is prohibited.
7
+ *
8
+ * @category EditionGuard
9
+ * @package Editionguard_Editionguard
10
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
11
+ */
12
+ class Editionguard_Editionguard_Block_Downloadable_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Links
13
+ extends Mage_Downloadable_Block_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Links
14
+ {
15
+
16
+ /**
17
+ * Class constructor
18
+ *
19
+ */
20
+ public function __construct()
21
+ {
22
+ parent::__construct();
23
+ $this->setTemplate('editionguard/downloadable/product/edit/downloadable/links.phtml');
24
+ }
25
+
26
+ /**
27
+ * Return array of links
28
+ *
29
+ * @return array
30
+ */
31
+ public function getLinkData()
32
+ {
33
+ $linkArr = array();
34
+ $links = $this->getProduct()->getTypeInstance(true)->getLinks($this->getProduct());
35
+ $priceWebsiteScope = $this->getIsPriceWebsiteScope();
36
+ foreach ($links as $item) {
37
+ $tmpLinkItem = array(
38
+ 'link_id' => $item->getId(),
39
+ 'title' => $item->getTitle(),
40
+ 'price' => $this->getCanReadPrice() ? $this->getPriceValue($item->getPrice()) : '',
41
+ 'number_of_downloads' => $item->getNumberOfDownloads(),
42
+ 'is_shareable' => $item->getIsShareable(),
43
+ 'use_editionguard' => $item->getUseEditionguard(),
44
+ 'link_url' => $item->getLinkUrl(),
45
+ 'link_type' => $item->getLinkType(),
46
+ 'sample_file' => $item->getSampleFile(),
47
+ 'sample_url' => $item->getSampleUrl(),
48
+ 'sample_type' => $item->getSampleType(),
49
+ 'sort_order' => $item->getSortOrder(),
50
+ );
51
+ $file = Mage::helper('downloadable/file')->getFilePath(
52
+ Mage_Downloadable_Model_Link::getBasePath(), $item->getLinkFile()
53
+ );
54
+
55
+ if ($item->getLinkFile() && !is_file($file)) {
56
+ Mage::helper('core/file_storage_database')->saveFileToFilesystem($file);
57
+ }
58
+
59
+ if ($item->getLinkFile() && is_file($file)) {
60
+ $name = '<a href="'
61
+ . $this->getUrl('*/downloadable_product_edit/link', array(
62
+ 'id' => $item->getId(),
63
+ '_secure' => true
64
+ )) . '">' . Mage::helper('downloadable/file')->getFileFromPathFile($item->getLinkFile()) . '</a>';
65
+ $tmpLinkItem['file_save'] = array(
66
+ array(
67
+ 'file' => $item->getLinkFile(),
68
+ 'name' => $name,
69
+ 'size' => filesize($file),
70
+ 'status' => 'old'
71
+ ));
72
+ }
73
+ $sampleFile = Mage::helper('downloadable/file')->getFilePath(
74
+ Mage_Downloadable_Model_Link::getBaseSamplePath(), $item->getSampleFile()
75
+ );
76
+ if ($item->getSampleFile() && is_file($sampleFile)) {
77
+ $tmpLinkItem['sample_file_save'] = array(
78
+ array(
79
+ 'file' => $item->getSampleFile(),
80
+ 'name' => Mage::helper('downloadable/file')->getFileFromPathFile($item->getSampleFile()),
81
+ 'size' => filesize($sampleFile),
82
+ 'status' => 'old'
83
+ ));
84
+ }
85
+ if ($item->getNumberOfDownloads() == '0') {
86
+ $tmpLinkItem['is_unlimited'] = ' checked="checked"';
87
+ }
88
+ if ($this->getProduct()->getStoreId() && $item->getStoreTitle()) {
89
+ $tmpLinkItem['store_title'] = $item->getStoreTitle();
90
+ }
91
+ if ($this->getProduct()->getStoreId() && $priceWebsiteScope) {
92
+ $tmpLinkItem['website_price'] = $item->getWebsitePrice();
93
+ }
94
+ $linkArr[] = new Varien_Object($tmpLinkItem);
95
+ }
96
+ return $linkArr;
97
+ }
98
+ }
app/code/community/Editionguard/Editionguard/Block/Downloadable/Customer/Products/List.php ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EditionGuard
4
+ *
5
+ * This source file is proprietary property of EditionGuard. Any reuse or
6
+ * distribution of any part of this file without prior consent is prohibited.
7
+ *
8
+ * @category EditionGuard
9
+ * @package Editionguard_Editionguard
10
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
11
+ */
12
+ class Editionguard_Editionguard_Block_Downloadable_Customer_Products_List extends Mage_Downloadable_Block_Customer_Products_List
13
+ {
14
+ /**
15
+ * Return number of left downloads or unlimited
16
+ *
17
+ * @return string
18
+ */
19
+ public function getRemainingDownloads($item)
20
+ {
21
+ if (Mage::helper('editionguard')->getUseEditionguard($item))
22
+ {
23
+ // EditionGuard downloads are unlimited
24
+ return Mage::helper('downloadable')->__('Unlimited');
25
+ }
26
+ else
27
+ {
28
+ return parent::getRemainingDownloads($item);
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Return url to download link
34
+ *
35
+ * @param Mage_Downloadable_Model_Link_Purchased_Item $item
36
+ * @return string
37
+ */
38
+ public function getDownloadUrl($item)
39
+ {
40
+ if (Mage::helper('editionguard')->getUseEditionguard($item))
41
+ {
42
+ return Mage::helper('editionguard')->getDownloadUrl($item->getOrderItemId(), $item->getEditionguardResource());
43
+ }
44
+ else
45
+ {
46
+ return parent::getDownloadUrl($item);
47
+ }
48
+ }
49
+ }
app/code/community/Editionguard/Editionguard/Helper/Data.php ADDED
@@ -0,0 +1,230 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EditionGuard
4
+ *
5
+ * This source file is proprietary property of EditionGuard. Any reuse or
6
+ * distribution of any part of this file without prior consent is prohibited.
7
+ *
8
+ * @category EditionGuard
9
+ * @package Editionguard_Editionguard
10
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
11
+ */
12
+ class Editionguard_Editionguard_Helper_Data extends Mage_Core_Helper_Data
13
+ {
14
+ const API_PACKAGE_URL = 'http://www.editionguard.com/api/package';
15
+ const API_SET_STATUS_URL = 'http://www.editionguard.com/api/set_status';
16
+ const API_DELETE_URL = 'http://www.editionguard.com/api/delete';
17
+ const API_LINK_URL = 'http://acs4.editionguard.com/fulfillment/URLLink.acsm';
18
+ const LINK_EDITIONGUARD_YES = 1;
19
+ const LINK_EDITIONGUARD_NO = 0;
20
+ const LINK_EDITIONGUARD_CONFIG = 2;
21
+ const XML_PATH_CONFIG_USE_EDITIONGUARD = 'catalog/downloadable/editionguard';
22
+ const XML_PATH_CONFIG_EDITIONGUARD_EMAIL = 'editionguard/settings/email';
23
+ const XML_PATH_CONFIG_EDITIONGUARD_DISTRIBUTERID = 'editionguard/settings/distributerid';
24
+ const XML_PATH_CONFIG_EDITIONGUARD_SECRET = 'editionguard/settings/sharedsecret';
25
+
26
+ /**
27
+ * Given a URL and parameters, makes a request to the editionguard API using the
28
+ * currently configured credentials.
29
+ *
30
+ * @param string $request_url
31
+ * @param array $params
32
+ *
33
+ * @return Varien_Simplexml_Element object containing the result
34
+ * @throws Exception on failure
35
+ */
36
+ protected function _sendEditionguardApiRequest($request_url, array $params, $file = null)
37
+ {
38
+ $secret = Mage::getStoreConfig(Editionguard_Editionguard_Helper_Data::XML_PATH_CONFIG_EDITIONGUARD_SECRET);
39
+ $email = Mage::getStoreConfig(Editionguard_Editionguard_Helper_Data::XML_PATH_CONFIG_EDITIONGUARD_EMAIL);
40
+ $nonce = rand(1000000, 999999999);
41
+ $hash = hash_hmac("sha1", $nonce.$email, base64_decode($secret));
42
+
43
+ $httpClient = new Varien_Http_Client();
44
+ $params['email'] = $email;
45
+ $params['nonce'] = $nonce;
46
+ $params['hash'] = $hash;
47
+
48
+ $httpClient->setUri($request_url)
49
+ ->setParameterPost($params)
50
+ ->setConfig(array('timeout' => 30));
51
+
52
+ if ($file && is_array($file))
53
+ {
54
+ $httpClient->setFileUpload(
55
+ $file['filename'],
56
+ $file['formname'],
57
+ $file['data'],
58
+ $file['type']
59
+ );
60
+ }
61
+
62
+ $response = $httpClient->request('POST');
63
+
64
+ // TODO: Handle non 200 responses
65
+ // - Follow 3**
66
+ // - Give errors on 4** and 5**
67
+
68
+ try {
69
+ $body = $response->getBody();
70
+ } catch (Zend_Http_Exception $e) {
71
+ // HACK: EditionGuard currently sends the response raw, even though
72
+ // the header indicates that it is chunked. Just grab the raw body
73
+ // and use it.
74
+ $body = $response->getRawBody();
75
+ }
76
+
77
+ try {
78
+ $xml = new Varien_Simplexml_Element("<root>".$body."</root>");
79
+ } catch (Exception $e) {
80
+ // Not valid XML. Treat like a raw error
81
+ throw new Editionguard_Editionguard_Model_Exception("Error: \"$body\" while uploading file to EditionGuard");
82
+ }
83
+
84
+ if (isset($xml->error))
85
+ {
86
+ $error_data = $xml->error->getAttribute('data');
87
+ if (preg_match('~([a-zA-Z0-9_]*) (.*)~', $error_data, $matches))
88
+ {
89
+ $error_type = $matches[1];
90
+ $error_url = $matches[2];
91
+ // TODO: Map any documented error codes to more meaningful messages
92
+ // TODO: Use a custom exception type
93
+ throw new Editionguard_Editionguard_Model_Exception("Error: $error_type while uploading file to EditionGuard", $error_type, $error_url);
94
+ }
95
+ else
96
+ {
97
+ // TODO: Use a custom exception type
98
+ throw new Editionguard_Editionguard_Model_Exception("Unknown error while uploading file to EditionGuard");
99
+ }
100
+ }
101
+
102
+ return $xml;
103
+ }
104
+
105
+ /**
106
+ * Sends a file to Editionguard for DRM handling
107
+ *
108
+ * Use a null resourceid to upload a new file
109
+ *
110
+ * @return string - Unique ID for the file in Editionguard
111
+ */
112
+ public function sendToEditionguard($resourceid, $title, $filename, $filedata, $filetype = null)
113
+ {
114
+ $params = array(
115
+ 'title'=>$title,
116
+ 'author'=>'',
117
+ 'publisher'=>'',
118
+ );
119
+ if ($resourceid)
120
+ {
121
+ $params['resource_id'] = $resourceid;
122
+ }
123
+ $xml = $this->_sendEditionguardApiRequest(Editionguard_Editionguard_Helper_Data::API_PACKAGE_URL,
124
+ $params,
125
+ array(
126
+ 'filename'=>$filename,
127
+ 'formname'=>'file',
128
+ 'data'=>$filedata,
129
+ 'type'=>$filetype,
130
+ )
131
+ );
132
+
133
+ if (!isset($xml->resourceItemInfo))
134
+ {
135
+ // Unknown response type. Assume it's a raw error.
136
+ throw new Exception("Error: \"$body\" while uploading file to EditionGuard");
137
+ }
138
+
139
+ return array(
140
+ 'resource'=>$xml->resourceItemInfo->resource,
141
+ 'src'=>$xml->resourceItemInfo->src,
142
+ );
143
+ }
144
+
145
+ /**
146
+ * Changes the status of an Editionguard resource
147
+ */
148
+ public function setResourceActive($resourceid, $active = true)
149
+ {
150
+ $xml = $this->_sendEditionguardApiRequest(Editionguard_Editionguard_Helper_Data::API_SET_STATUS_URL, array(
151
+ 'resource_id'=>$resourceid,
152
+ 'status'=>$active ? 'active' : 'inactive',
153
+ ));
154
+
155
+ // Setting to inactive is currently returning deleted. Setting to active should
156
+ // return a distributionrights object
157
+ if (!isset($xml->response) || (!isset($xml->response->distributionRights) && !isset($xml->response->deleted)))
158
+ {
159
+ // Unknown response type. Assume it's a raw error.
160
+ throw new Exception("Error: \"{$xml->innerXml()}\" while uploading file to EditionGuard");
161
+ }
162
+
163
+ return true;
164
+ }
165
+
166
+ /**
167
+ * Deletes an Editionguard resource
168
+ */
169
+ public function deleteResource($resourceid)
170
+ {
171
+ $xml = $this->_sendEditionguardApiRequest(Editionguard_Editionguard_Helper_Data::API_DELETE_URL, array(
172
+ 'resource_id'=>$resourceid,
173
+ ));
174
+
175
+ // NOTE: We get a blank response if the file had already been deleted. There's no sense
176
+ // dying over this, so we're going to skip this verification process, even though it would
177
+ // normally be a good thing.
178
+ // if (!isset($xml->response) || !isset($xml->response->deleted) || !$xml->response->deleted)
179
+ // {
180
+ // // Unknown response type. Assume it's a raw error.
181
+ // throw new Exception("Error: \"{$xml->innerXml()}\" while uploading file to EditionGuard");
182
+ // }
183
+
184
+ return true;
185
+ }
186
+
187
+ /**
188
+ * Builds a link to a file managed by Editionguard
189
+ *
190
+ * @return string - Unique download URL for this purchase
191
+ */
192
+ public function getDownloadUrl($order_item_id, $resource)
193
+ {
194
+ $dateval=time();
195
+ $sharedSecret = Mage::getStoreConfig(Editionguard_Editionguard_Helper_Data::XML_PATH_CONFIG_EDITIONGUARD_SECRET);
196
+ $transactionId = $order_item_id;
197
+ $resourceId = $resource;
198
+ $linkURL = Editionguard_Editionguard_Helper_Data::API_LINK_URL;
199
+ $orderSource = Mage::getStoreConfig(Editionguard_Editionguard_Helper_Data::XML_PATH_CONFIG_EDITIONGUARD_EMAIL);
200
+
201
+ // Create download URL
202
+ $URL = "action=enterorder&ordersource=".urlencode($orderSource)."&orderid=".urlencode($transactionId)."&resid=".urlencode("$resourceId")."&dateval=".urlencode($dateval)."&gblver=4";
203
+
204
+ // Digitaly sign the request
205
+ $URL = $linkURL."?".$URL."&auth=".hash_hmac("sha1", $URL, base64_decode($sharedSecret));
206
+
207
+ return $URL;
208
+ }
209
+
210
+
211
+ /**
212
+ * Check is link DRM protected by EditionGuard or not
213
+ *
214
+ * @param Mage_Downloadable_Model_Link | Mage_Downloadable_Model_Link_Purchased_Item $link
215
+ * @return bool
216
+ */
217
+ public function getUseEditionguard($link)
218
+ {
219
+ $editionguard = false;
220
+ switch ($link->getUseEditionguard()) {
221
+ case Editionguard_Editionguard_Helper_Data::LINK_EDITIONGUARD_YES:
222
+ case Editionguard_Editionguard_Helper_Data::LINK_EDITIONGUARD_NO:
223
+ $editionguard = (bool) $link->getUseEditionguard();
224
+ break;
225
+ case Editionguard_Editionguard_Helper_Data::LINK_EDITIONGUARD_CONFIG:
226
+ $editionguard = (bool) Mage::getStoreConfigFlag(Editionguard_Editionguard_Helper_Data::XML_PATH_CONFIG_USE_EDITIONGUARD);
227
+ }
228
+ return $editionguard;
229
+ }
230
+ }
app/code/community/Editionguard/Editionguard/Model/Downloadable/Link.php ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EditionGuard
4
+ *
5
+ * This source file is proprietary property of EditionGuard. Any reuse or
6
+ * distribution of any part of this file without prior consent is prohibited.
7
+ *
8
+ * @category EditionGuard
9
+ * @package Editionguard_Editionguard
10
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
11
+ */
12
+ class Editionguard_Editionguard_Model_Downloadable_Link extends Mage_Downloadable_Model_Link
13
+ {
14
+ protected $_addingEditionguard = false;
15
+ protected $_removingEditionguard = false;
16
+ protected $_changingLinkFile = false;
17
+ protected $_loading = false;
18
+
19
+ /**
20
+ * Called prior to saving. Used to upload the file to EditionGuard for DRM
21
+ *
22
+ * @return Mage_Downloadable_Model_Link
23
+ */
24
+ protected function _beforeSave()
25
+ {
26
+ $new = !$this->getLinkId();
27
+ $add_editionguard = $this->_addingEditionguard;
28
+ $remove_editionguard = $this->_removingEditionguard;
29
+ $new_file = $this->_changingLinkFile;
30
+
31
+ $this->_ensureOrigData();
32
+
33
+ if ($new || $add_editionguard || $new_file)
34
+ {
35
+ // The file is new to editionguard.
36
+ if (Mage::helper('editionguard')->getUseEditionguard($this))
37
+ {
38
+ // If enabling editionguard, we need to do this before updating the
39
+ // file. Otherwise the system will give errors.
40
+ if ($this->getEditionguardResource() && $add_editionguard)
41
+ {
42
+ // had a resource, now re-enabling editionguard handling.
43
+ try {
44
+ $editionguard = Mage::helper('editionguard')->setResourceActive(
45
+ $this->getEditionguardResource(),
46
+ true
47
+ );
48
+ } catch (Editionguard_Editionguard_Model_Exception $e) {
49
+ // Skip an error code that's getting returned right now in a non-error case
50
+ if ($e->getCode() != 'E_ADEPT_INTERNAL')
51
+ {
52
+ // Got an error from EditionGuard. Can't save. Pass it on.
53
+ throw $e;
54
+ }
55
+ }
56
+ }
57
+
58
+ // Add or update the file
59
+ if ($new || $new_file || !$this->getEditionguardResource())
60
+ {
61
+ // We don't have it already
62
+ try {
63
+ // Upload the file to EditionGuard.
64
+ $filepath = Mage_Downloadable_Model_Link::getBasePath() . $this->getLinkFile();
65
+ $filedata = file_get_contents($filepath);
66
+ $editionguard = Mage::helper('editionguard')->sendToEditionguard(
67
+ $this->getEditionguardResource(),
68
+ $this->getTitle(),
69
+ basename($this->getLinkFile()),
70
+ $filedata
71
+ );
72
+
73
+ // Remember the response information
74
+ $this->setEditionguardResource($editionguard['resource']);
75
+ $this->setEditionguardSrc($editionguard['src']);
76
+
77
+ } catch (Editionguard_Editionguard_Model_Exception $e) {
78
+ // Got an error from EditionGuard. Can't save. Pass it on.
79
+ throw $e;
80
+ }
81
+ }
82
+ }
83
+ }
84
+
85
+ if ($this->getEditionguardResource() && $remove_editionguard)
86
+ {
87
+ // had a resource, now removing editionguard handling. Disable editionguard on the file.
88
+ try {
89
+ $editionguard = Mage::helper('editionguard')->setResourceActive(
90
+ $this->getEditionguardResource(),
91
+ false
92
+ );
93
+ } catch (Editionguard_Editionguard_Model_Exception $e) {
94
+ // Skip an error code that's getting returned right now in a non-error case
95
+ if ($e->getCode() != 'E_ADEPT_INTERNAL')
96
+ {
97
+ // Got an error from EditionGuard. Can't save. Pass it on.
98
+ throw $e;
99
+ }
100
+ }
101
+ }
102
+ return parent::_beforeSave();
103
+ }
104
+
105
+ /**
106
+ * Called prior to saving. Used to upload the file to EditionGuard for DRM
107
+ *
108
+ * @return Mage_Downloadable_Model_Link
109
+ */
110
+ protected function _beforeDelete()
111
+ {
112
+ $this->_ensureOrigData();
113
+
114
+ if ($this->getEditionguardResource())
115
+ {
116
+ // Had a resource. Delete it.
117
+ try {
118
+ $editionguard = Mage::helper('editionguard')->deleteResource(
119
+ $this->getEditionguardResource()
120
+ );
121
+ } catch (Editionguard_Editionguard_Model_Exception $e) {
122
+ // Got an error from EditionGuard. Can't save. Pass it on.
123
+ throw $e;
124
+ }
125
+ }
126
+ return parent::_beforeDelete();
127
+ }
128
+
129
+ protected function _beforeLoad($id, $field = null)
130
+ {
131
+ $this->_loading = true;
132
+ return parent::_beforeLoad($id, $field);
133
+ }
134
+
135
+ protected function _afterLoad()
136
+ {
137
+ $this->_loading = false;
138
+ return parent::_afterLoad();
139
+ }
140
+
141
+ public function setData($key, $value=null)
142
+ {
143
+ if (!$this->_loading && is_array($key))
144
+ {
145
+ if (isset($key['use_editionguard']))
146
+ {
147
+ $use_editionguard = $key['use_editionguard'];
148
+ unset($key['use_editionguard']);
149
+ }
150
+ if (isset($key['link_file']))
151
+ {
152
+ $link_file = $key['link_file'];
153
+ unset($key['link_file']);
154
+ }
155
+ parent::setData($key, $value);
156
+ if (isset($use_editionguard))
157
+ {
158
+ $this->setUseEditionguard($use_editionguard);
159
+ }
160
+ if (isset($link_file))
161
+ {
162
+ $this->setLinkFile($link_file);
163
+ }
164
+ return $this;
165
+ }
166
+
167
+ return parent::setData($key, $value);
168
+ }
169
+
170
+ public function setUseEditionguard($v)
171
+ {
172
+ $this->_ensureOrigData();
173
+
174
+ if ($v && $v != $this->getOrigData('use_editionguard'))
175
+ {
176
+ $this->_addingEditionguard = true;
177
+ $this->_removingEditionguard = false;
178
+ }
179
+ else if (!$v && $v != $this->getOrigData('use_editionguard'))
180
+ {
181
+ $this->_addingEditionguard = false;
182
+ $this->_removingEditionguard = true;
183
+ }
184
+ return $this->setData('use_editionguard', $v);
185
+ }
186
+
187
+ public function setLinkFile($v)
188
+ {
189
+ $this->_ensureOrigData();
190
+
191
+ if ($v && $v != $this->getOrigData('link_file'))
192
+ {
193
+ // Magento may re-upload, resulting in a file name change in some cases even though
194
+ // the file contents are not actually changing. Skip over any changes to only
195
+ // the path.
196
+ $this->_changingLinkFile = true;
197
+ }
198
+ return $this->setData('link_file', $v);
199
+ }
200
+
201
+ protected function _ensureOrigData()
202
+ {
203
+ // Magento doesn't always load the object. We need to delay load it to get the old values.
204
+ if ($this->getLinkId() && !$this->getOrigData())
205
+ {
206
+ // we could have original data, but don't. Load it now.
207
+ $old_link = Mage::getModel('downloadable/link')->load($this->getLinkId());
208
+ $this->_origData = $old_link->getOrigData();
209
+ $this->set = $old_link->getOrigData();
210
+
211
+ // Make sure that we have all the data we'll need to do our job
212
+ if (!$this->hasEditionguardResource())
213
+ {
214
+ $this->setEditionguardResource($this->getOrigData('editionguard_resource'));
215
+ }
216
+ if (!$this->hasEditionguardSrc())
217
+ {
218
+ $this->setEditionguardSrc($this->getOrigData('editionguard_src'));
219
+ }
220
+
221
+ }
222
+ }
223
+ }
app/code/community/Editionguard/Editionguard/Model/Exception.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EditionGuard
4
+ *
5
+ * This source file is proprietary property of EditionGuard. Any reuse or
6
+ * distribution of any part of this file without prior consent is prohibited.
7
+ *
8
+ * @category EditionGuard
9
+ * @package Editionguard_Editionguard
10
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
11
+ */
12
+ class Editionguard_Editionguard_Model_Exception extends Mage_Core_Exception
13
+ {
14
+ public function __construct($exception, $code = null, $url = null)
15
+ {
16
+ parent::__construct($exception);
17
+ $this->_code = $code;
18
+ }
19
+ }
app/code/community/Editionguard/Editionguard/Model/Mysql4/Editionguard.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EditionGuard
4
+ *
5
+ * This source file is proprietary property of EditionGuard. Any reuse or
6
+ * distribution of any part of this file without prior consent is prohibited.
7
+ *
8
+ * @category EditionGuard
9
+ * @package Editionguard_Editionguard
10
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
11
+ */
12
+
13
+ class Editionguard_Editionguard_Model_Mysql4_Editionguard extends Mage_Core_Model_Mysql4_Abstract
14
+ {
15
+ public function _construct()
16
+ {
17
+ $this->_init('editionguard/editionguard', 'id');
18
+ }
19
+ }
app/code/community/Editionguard/Editionguard/Model/Mysql4/Editionguard/Collection.php ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EditionGuard
4
+ *
5
+ * This source file is proprietary property of EditionGuard. Any reuse or
6
+ * distribution of any part of this file without prior consent is prohibited.
7
+ *
8
+ * @category EditionGuard
9
+ * @package Editionguard_Editionguard
10
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
11
+ */
12
+
13
+ class Editionguard_Editionguard_Model_Mysql4_Editionguard_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
14
+ {
15
+ public function _construct()
16
+ {
17
+ parent::_construct();
18
+ $this->_init('editionguard/editionguard');
19
+ }
20
+ }
app/code/community/Editionguard/Editionguard/Model/Resource/Downloadable/Link.php ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EditionGuard
4
+ *
5
+ * This source file is proprietary property of EditionGuard. Any reuse or
6
+ * distribution of any part of this file without prior consent is prohibited.
7
+ *
8
+ * @category EditionGuard
9
+ * @package Editionguard_Editionguard
10
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
11
+ */
12
+ class Editionguard_Editionguard_Model_Resource_Downloadable_Link extends Mage_Downloadable_Model_Resource_Link
13
+ {
14
+ /**
15
+ * Delete data by item(s)
16
+ *
17
+ * @param Mage_Downloadable_Model_Link|array|int $items
18
+ * @return Mage_Downloadable_Model_Resource_Link
19
+ */
20
+ public function deleteItems($items)
21
+ {
22
+ // The original code tries to short circut the normal delete process, which prevents
23
+ // this module from being able to also remove the file from editionguard. To avoid
24
+ // this, read in and delete each item in a loop. This is slightly slower than a raw
25
+ // query, but it lets us hook the behavior better.
26
+ foreach ($items as $item)
27
+ {
28
+ $link = Mage::getModel('downloadable/link')->load($item);
29
+ $link->delete();
30
+ }
31
+
32
+ // It's safe to call the parent, just in case it ever does something more.
33
+ return parent::deleteItems($items);
34
+ }
35
+ }
app/code/community/Editionguard/Editionguard/Model/Resource/Eav/Mysql4/Setup.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EditionGuard
4
+ *
5
+ * This source file is proprietary property of EditionGuard. Any reuse or
6
+ * distribution of any part of this file without prior consent is prohibited.
7
+ *
8
+ * @category EditionGuard
9
+ * @package Editionguard_Editionguard
10
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
11
+ */
12
+ class Editionguard_Editionguard_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
13
+ {
14
+ }
app/code/community/Editionguard/Editionguard/controllers/DownloadController.php ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EditionGuard
4
+ *
5
+ * This source file is proprietary property of EditionGuard. Any reuse or
6
+ * distribution of any part of this file without prior consent is prohibited.
7
+ *
8
+ * @category EditionGuard
9
+ * @package Editionguard_Editionguard
10
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
11
+ */
12
+ require_once('Mage/Downloadable/controllers/DownloadController.php');
13
+ class Editionguard_Editionguard_DownloadController extends Mage_Downloadable_DownloadController
14
+ {
15
+ /**
16
+ * Download link action
17
+ */
18
+ public function linkAction()
19
+ {
20
+ $id = $this->getRequest()->getParam('id', 0);
21
+ $linkPurchasedItem = Mage::getModel('downloadable/link_purchased_item')->load($id, 'link_hash');
22
+ if (! $linkPurchasedItem->getId() ) {
23
+ $this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__("Requested link does not exist."));
24
+ return $this->_redirect('*/customer/products');
25
+ }
26
+
27
+ // Use the original behavior if not using editionguard
28
+ if (!Mage::helper('editionguard')->getUseEditionguard($linkPurchasedItem))
29
+ {
30
+ return parent::linkAction();
31
+ }
32
+
33
+ if (!Mage::helper('downloadable')->getIsShareable($linkPurchasedItem)) {
34
+ $customerId = $this->_getCustomerSession()->getCustomerId();
35
+ if (!$customerId) {
36
+ $product = Mage::getModel('catalog/product')->load($linkPurchasedItem->getProductId());
37
+ if ($product->getId()) {
38
+ $notice = Mage::helper('downloadable')->__(
39
+ 'Please log in to download your product or purchase <a href="%s">%s</a>.',
40
+ $product->getProductUrl(), $product->getName()
41
+ );
42
+ } else {
43
+ $notice = Mage::helper('downloadable')->__('Please log in to download your product.');
44
+ }
45
+ $this->_getCustomerSession()->addNotice($notice);
46
+ $this->_getCustomerSession()->authenticate($this);
47
+ $this->_getCustomerSession()->setBeforeAuthUrl(Mage::getUrl('downloadable/customer/products/'),
48
+ array('_secure' => true)
49
+ );
50
+ return ;
51
+ }
52
+ $linkPurchased = Mage::getModel('downloadable/link_purchased')->load($linkPurchasedItem->getPurchasedId());
53
+ if ($linkPurchased->getCustomerId() != $customerId) {
54
+ $this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__("Requested link does not exist."));
55
+ return $this->_redirect('*/customer/products');
56
+ }
57
+ }
58
+ $downloadsLeft = $linkPurchasedItem->getNumberOfDownloadsBought()
59
+ - $linkPurchasedItem->getNumberOfDownloadsUsed();
60
+
61
+ $status = $linkPurchasedItem->getStatus();
62
+ if ($status == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_AVAILABLE
63
+ && ($downloadsLeft || $linkPurchasedItem->getNumberOfDownloadsBought() == 0)
64
+ ) {
65
+ $resource = '';
66
+ $resourceType = '';
67
+ if ($linkPurchasedItem->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_URL) {
68
+ $resource = $linkPurchasedItem->getLinkUrl();
69
+ $resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_URL;
70
+ } elseif ($linkPurchasedItem->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
71
+ $resource = Mage::helper('downloadable/file')->getFilePath(
72
+ Mage_Downloadable_Model_Link::getBasePath(), $linkPurchasedItem->getLinkFile()
73
+ );
74
+ $resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_FILE;
75
+ }
76
+ try {
77
+
78
+ $editionguard_url = Mage::helper('editionguard')->getDownloadUrl($linkPurchasedItem->getOrderItemId(), $linkPurchasedItem->getEditionguardResource());
79
+
80
+ $linkPurchasedItem->setNumberOfDownloadsUsed($linkPurchasedItem->getNumberOfDownloadsUsed() + 1);
81
+
82
+ if ($linkPurchasedItem->getNumberOfDownloadsBought() != 0 && !($downloadsLeft - 1)) {
83
+ $linkPurchasedItem->setStatus(Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED);
84
+ }
85
+ $linkPurchasedItem->save();
86
+
87
+ return $this->_redirectUrl($editionguard_url, array('_direct'=>true));
88
+ }
89
+ catch (Exception $e) {
90
+ $this->_getCustomerSession()->addError(
91
+ Mage::helper('downloadable')->__('An error occurred while getting the requested content. Please contact the store owner.')
92
+ );
93
+ }
94
+ } elseif ($status == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_EXPIRED) {
95
+ $this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__('The link has expired.'));
96
+ } elseif ($status == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING
97
+ || $status == Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PAYMENT_REVIEW
98
+ ) {
99
+ $this->_getCustomerSession()->addNotice(Mage::helper('downloadable')->__('The link is not available.'));
100
+ } else {
101
+ $this->_getCustomerSession()->addError(
102
+ Mage::helper('downloadable')->__('An error occurred while getting the requested content. Please contact the store owner.')
103
+ );
104
+ }
105
+ return $this->_redirect('*/customer/products');
106
+ }
107
+
108
+ }
app/code/community/Editionguard/Editionguard/etc/config.xml ADDED
@@ -0,0 +1,170 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * EditionGuard
5
+ *
6
+ * This source file is proprietary property of EditionGuard. Any reuse or
7
+ * distribution of any part of this file without prior consent is prohibited.
8
+ *
9
+ * @category EditionGuard
10
+ * @package Editionguard_Editionguard
11
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
12
+ */
13
+ -->
14
+ <config>
15
+ <modules>
16
+ <Editionguard_Editionguard>
17
+ <version>1.0.0.0</version>
18
+ </Editionguard_Editionguard>
19
+ </modules>
20
+ <frontend>
21
+ <routers>
22
+ <editionguard>
23
+ <use>standard</use>
24
+ <args>
25
+ <module>Editionguard_Editionguard</module>
26
+ <frontName>editionguard</frontName>
27
+ </args>
28
+ </editionguard>
29
+ <downloadable>
30
+ <use>standard</use>
31
+ <args>
32
+ <modules>
33
+ <Editionguard_Editionguard before="Mage_Downloadable">Editionguard_Editionguard</Editionguard_Editionguard>
34
+ </modules>
35
+ <frontName>downloadable</frontName>
36
+ </args>
37
+ </downloadable>
38
+ </routers>
39
+ <secure_url>
40
+ <editionguard>/editionguard/customer/</editionguard>
41
+ </secure_url>
42
+ </frontend>
43
+ <admin>
44
+ <routers>
45
+ <editionguard>
46
+ <use>admin</use>
47
+ <args>
48
+ <module>Editionguard_Editionguard</module>
49
+ <frontName>editionguard</frontName>
50
+ </args>
51
+ </editionguard>
52
+ <adminhtml>
53
+ <args>
54
+ <modules>
55
+ <editionguard after="Mage_Adminhtml">Editionguard_Editionguard</editionguard>
56
+ </modules>
57
+ </args>
58
+ </adminhtml>
59
+ </routers>
60
+ </admin>
61
+ <default>
62
+ <default>
63
+ <editionguard>
64
+ <settings>
65
+ <email></email>
66
+ <distributerid></distributerid>
67
+ <sharedsecret></sharedsecret>
68
+ </settings>
69
+ </editionguard>
70
+ <catalog>
71
+ <downloadable>
72
+ <editionguard>1</editionguard>
73
+ </downloadable>
74
+ </catalog>
75
+ </default>
76
+ </default>
77
+ <adminhtml>
78
+ <acl>
79
+ <resources>
80
+ <admin>
81
+ <children>
82
+ <system>
83
+ <children>
84
+ <config>
85
+ <children>
86
+ <editionguard translate="title" module="core">
87
+ <title>EditionGuard</title>
88
+ <sort_order>60</sort_order>
89
+ </editionguard>
90
+ </children>
91
+ </config>
92
+ </children>
93
+ </system>
94
+ </children>
95
+ </admin>
96
+ </resources>
97
+ </acl>
98
+ </adminhtml>
99
+ <global>
100
+ <fieldsets>
101
+ <downloadable_sales_copy_link>
102
+ <use_editionguard>
103
+ <to_purchased>*</to_purchased>
104
+ </use_editionguard>
105
+ <editionguard_resource>
106
+ <to_purchased>*</to_purchased>
107
+ </editionguard_resource>
108
+ <editionguard_src>
109
+ <to_purchased>*</to_purchased>
110
+ </editionguard_src>
111
+ </downloadable_sales_copy_link>
112
+ </fieldsets>
113
+ <models>
114
+ <editionguard>
115
+ <class>Editionguard_Editionguard_Model</class>
116
+ <resourceModel>editionguard_mysql4</resourceModel>
117
+ </editionguard>
118
+ <editionguard_mysql4>
119
+ <class>Editionguard_Editionguard_Model_Mysql4</class>
120
+ </editionguard_mysql4>
121
+ <downloadable>
122
+ <rewrite>
123
+ <link>Editionguard_Editionguard_Model_Downloadable_Link</link>
124
+ <resource_link>Editionguard_Editionguard_Model_Resource_Downloadable_Link</resource_link>
125
+ </rewrite>
126
+ </downloadable>
127
+ <downloadable_resource>
128
+ <rewrite>
129
+ <link>Editionguard_Editionguard_Model_Resource_Downloadable_Link</link>
130
+ </rewrite>
131
+ </downloadable_resource>
132
+ </models>
133
+ <resources>
134
+ <editionguard_setup>
135
+ <setup>
136
+ <module>Editionguard_Editionguard</module>
137
+ <class>Editionguard_Editionguard_Model_Resource_Eav_Mysql4_Setup</class>
138
+ </setup>
139
+ <connection>
140
+ <use>core_setup</use>
141
+ </connection>
142
+ </editionguard_setup>
143
+ <editionguard_write>
144
+ <connection>
145
+ <use>core_write</use>
146
+ </connection>
147
+ </editionguard_write>
148
+ <editionguard_read>
149
+ <connection>
150
+ <use>core_read</use>
151
+ </connection>
152
+ </editionguard_read>
153
+ </resources>
154
+ <blocks>
155
+ <editionguard>
156
+ <class>Editionguard_Editionguard_Block</class>
157
+ </editionguard>
158
+ <downloadable>
159
+ <rewrite>
160
+ <adminhtml_catalog_product_edit_tab_downloadable_links>Editionguard_Editionguard_Block_Downloadable_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Links</adminhtml_catalog_product_edit_tab_downloadable_links>
161
+ </rewrite>
162
+ </downloadable>
163
+ </blocks>
164
+ <helpers>
165
+ <editionguard>
166
+ <class>Editionguard_Editionguard_Helper</class>
167
+ </editionguard>
168
+ </helpers>
169
+ </global>
170
+ </config>
app/code/community/Editionguard/Editionguard/etc/system.xml ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * EditionGuard
5
+ *
6
+ * This source file is proprietary property of EditionGuard. Any reuse or
7
+ * distribution of any part of this file without prior consent is prohibited.
8
+ *
9
+ * @category EditionGuard
10
+ * @package Editionguard_Editionguard
11
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
12
+ */
13
+ -->
14
+ <config>
15
+ <tabs>
16
+ <editionguard translate="label" module="editionguard">
17
+ <label>EditionGuard</label>
18
+ <sort_order>100</sort_order>
19
+ </editionguard>
20
+ </tabs>
21
+ <sections>
22
+ <editionguard translate="label" module="editionguard">
23
+ <label>Settings</label>
24
+ <tab>editionguard</tab>
25
+ <frontend_type>text</frontend_type>
26
+ <sort_order>10</sort_order>
27
+ <show_in_default>1</show_in_default>
28
+ <show_in_website>0</show_in_website>
29
+ <show_in_store>0</show_in_store>
30
+ <groups>
31
+ <settings translate="label">
32
+ <label>EditionGuard Settings</label>
33
+ <frontend_type>text</frontend_type>
34
+ <sort_order>1</sort_order>
35
+ <show_in_default>1</show_in_default>
36
+ <show_in_website>1</show_in_website>
37
+ <show_in_store>1</show_in_store>
38
+ <fields>
39
+ <email translate="label,comment">
40
+ <label>Email</label>
41
+ <comment><![CDATA[The email address associated with your EditionGuard account]]></comment>
42
+ <frontend_type>text</frontend_type>
43
+ <sort_order>10</sort_order>
44
+ <show_in_default>1</show_in_default>
45
+ <show_in_website>0</show_in_website>
46
+ <show_in_store>0</show_in_store>
47
+ </email>
48
+ <distributerid translate="label,comment">
49
+ <label>Distributor Id</label>
50
+ <comment><![CDATA[Your EditionGuard Distributor Id]]></comment>
51
+ <frontend_type>text</frontend_type>
52
+ <sort_order>20</sort_order>
53
+ <show_in_default>1</show_in_default>
54
+ <show_in_website>0</show_in_website>
55
+ <show_in_store>0</show_in_store>
56
+ </distributerid>
57
+ <sharedsecret translate="label,comment">
58
+ <label>Shared Secret</label>
59
+ <comment><![CDATA[The shared secret for your EditionGuard API access]]></comment>
60
+ <frontend_type>text</frontend_type>
61
+ <sort_order>30</sort_order>
62
+ <show_in_default>1</show_in_default>
63
+ <show_in_website>0</show_in_website>
64
+ <show_in_store>0</show_in_store>
65
+ </sharedsecret>
66
+ </fields>
67
+ </settings>
68
+ </groups>
69
+ </editionguard>
70
+ <catalog>
71
+ <groups>
72
+ <downloadable>
73
+ <fields>
74
+ <editionguard translate="label">
75
+ <label>Use EditionGuard DRM</label>
76
+ <frontend_type>select</frontend_type>
77
+ <source_model>adminhtml/system_config_source_yesno</source_model>
78
+ <sort_order>350</sort_order>
79
+ <show_in_default>1</show_in_default>
80
+ <show_in_website>1</show_in_website>
81
+ <show_in_store>0</show_in_store>
82
+ </editionguard>
83
+ </fields>
84
+ </downloadable>
85
+ </groups>
86
+ </catalog>
87
+ </sections>
88
+ </config>
app/code/community/Editionguard/Editionguard/sql/editionguard_setup/install-1.0.0.0.php ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EditionGuard
4
+ *
5
+ * This source file is proprietary property of EditionGuard. Any reuse or
6
+ * distribution of any part of this file without prior consent is prohibited.
7
+ *
8
+ * @category EditionGuard
9
+ * @package Editionguard_Editionguard
10
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
11
+ */
12
+
13
+
14
+ $installer = $this;
15
+
16
+ $installer->startSetup();
17
+
18
+ // Add the columns to the downloadable/link table
19
+ $installer->getConnection()->addColumn(
20
+ $installer->getTable('downloadable/link'),
21
+ 'use_editionguard',
22
+ array(
23
+ 'TYPE' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
24
+ 'UNSIGNED' => true,
25
+ 'NULLABLE' => false,
26
+ 'DEFAULT' => '0',
27
+ 'COMMENT' => 'Editionguard flag'
28
+ )
29
+ );
30
+
31
+ $installer->getConnection()->addColumn(
32
+ $installer->getTable('downloadable/link'),
33
+ 'editionguard_resource',
34
+ array(
35
+ 'TYPE' => Varien_Db_Ddl_Table::TYPE_TEXT,
36
+ 'LENGTH' => 255,
37
+ 'COMMENT' => 'Editionguard unique resource ID'
38
+ )
39
+ );
40
+
41
+ $installer->getConnection()->addColumn(
42
+ $installer->getTable('downloadable/link'),
43
+ 'editionguard_src',
44
+ array(
45
+ 'TYPE' => Varien_Db_Ddl_Table::TYPE_TEXT,
46
+ 'LENGTH' => 255,
47
+ 'COMMENT' => 'Editionguard content source URL'
48
+ )
49
+ );
50
+
51
+
52
+ // Add the columns to the downloadable/link_purchased_item table
53
+ $installer->getConnection()->addColumn(
54
+ $installer->getTable('downloadable/link_purchased_item'),
55
+ 'use_editionguard',
56
+ array(
57
+ 'TYPE' => Varien_Db_Ddl_Table::TYPE_SMALLINT,
58
+ 'UNSIGNED' => true,
59
+ 'NULLABLE' => false,
60
+ 'DEFAULT' => '0',
61
+ 'COMMENT' => 'Editionguard flag'
62
+ )
63
+ );
64
+
65
+ $installer->getConnection()->addColumn(
66
+ $installer->getTable('downloadable/link_purchased_item'),
67
+ 'editionguard_resource',
68
+ array(
69
+ 'TYPE' => Varien_Db_Ddl_Table::TYPE_TEXT,
70
+ 'LENGTH' => 255,
71
+ 'COMMENT' => 'Editionguard unique resource ID'
72
+ )
73
+ );
74
+
75
+ $installer->getConnection()->addColumn(
76
+ $installer->getTable('downloadable/link_purchased_item'),
77
+ 'editionguard_src',
78
+ array(
79
+ 'TYPE' => Varien_Db_Ddl_Table::TYPE_TEXT,
80
+ 'LENGTH' => 255,
81
+ 'COMMENT' => 'Editionguard content source URL'
82
+ )
83
+ );
84
+
85
+ $installer->endSetup();
app/design/adminhtml/default/default/template/editionguard/downloadable/product/edit/downloadable/links.phtml ADDED
@@ -0,0 +1,421 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EditionGuard
4
+ *
5
+ * This source file is proprietary property of EditionGuard. Any reuse or
6
+ * distribution of any part of this file without prior consent is prohibited.
7
+ *
8
+ * @category EditionGuard
9
+ * @package Editionguard_Editionguard
10
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
11
+ */
12
+ ?>
13
+ <?php
14
+
15
+ /**
16
+ * @see Editionguard_Editionguard_Block_Downloadable_Adminhtml_Catalog_Product_Edit_Tab_Downloadable_Links
17
+ */
18
+ ?>
19
+ <?php $_product = $this->getProduct()?>
20
+ <div class="fieldset">
21
+ <table cellspacing="0" class="form-list">
22
+ <tbody>
23
+ <tr class="headings">
24
+ <td class="label"><label for="name"><?php echo Mage::helper('downloadable')->__('Title')?></label>
25
+ </td>
26
+ <td class="value">
27
+ <input type="text" class="input-text" id="downloadable_links_title" name="product[links_title]" value="<?php echo $_product->getId()?$_product->getLinksTitle():$this->getLinksTitle() ?>" <?php echo ($_product->getStoreId() && $this->getUsedDefault())?'disabled="disabled"':'' ?> />
28
+ </td>
29
+ <td class="scope-label"><?php if (!Mage::app()->isSingleStoreMode()): ?>[STORE VIEW]<?php endif; ?></td>
30
+ <td class="value use-default">
31
+ <?php if($_product->getStoreId()): ?>
32
+ <input id="link_title_default" type="checkbox" name="use_default[]" value="links_title" onclick="toggleValueElements(this, this.parentNode.parentNode)" <?php echo $this->getUsedDefault()?'checked="checked"':'' ?> />
33
+ <label class="normal" for="link_title_default"><?php echo Mage::helper('downloadable')->__('Use Default Value'); ?></label>
34
+ <?php endif; ?>
35
+ </td>
36
+ </tr>
37
+ </tbody>
38
+ </table>
39
+ <br />
40
+ <table cellspacing="0" class="form-list">
41
+ <tbody>
42
+ <tr class="headings">
43
+ <td class="label"><label for="name"><?php echo Mage::helper('downloadable')->__('Links can be purchased separately')?></label>
44
+ </td>
45
+ <td class="value">
46
+ <?php echo $this->getPurchasedSeparatelySelect()?>
47
+ </td>
48
+ <td class="scope-label"><?php if (!Mage::app()->isSingleStoreMode()): ?>[GLOBAL]<?php endif; ?></td>
49
+ <td><small>&nbsp;</small></td>
50
+ </tr>
51
+ </tbody>
52
+ </table>
53
+ <br />
54
+ <div class="grid">
55
+ <div class="hor-scroll">
56
+ <table cellspacing="0" class="data border">
57
+ <col width="33%" />
58
+ <col />
59
+ <col />
60
+ <col />
61
+ <col />
62
+ <col width="1" />
63
+ <col width="1" />
64
+ <col width="1" />
65
+ <col width="1" />
66
+ <thead>
67
+ <tr class="headings">
68
+ <th><?php echo Mage::helper('downloadable')->__('Title')?> <span class="required">*</span></th>
69
+ <?php if ($this->getCanReadPrice() !== false) : ?>
70
+ <th><?php echo Mage::helper('downloadable')->__('Price')?></th>
71
+ <?php endif; ?>
72
+ <th><span class="nobr"><?php echo Mage::helper('downloadable')->__('Max. Downloads')?></span></th>
73
+ <th><?php echo Mage::helper('downloadable')->__('Shareable')?></th>
74
+ <th><?php echo Mage::helper('downloadable')->__('EditionGuard')?></th>
75
+ <th><?php echo Mage::helper('downloadable')->__('Sample')?></th>
76
+ <th><?php echo Mage::helper('downloadable')->__('File')?></th>
77
+ <th><span class="nobr"><?php echo Mage::helper('downloadable')->__('Sort Order')?></span></th>
78
+ <th>&nbsp;</th>
79
+ </tr>
80
+ </thead>
81
+ <tfoot>
82
+ <tr>
83
+ <td colspan="9" class="a-right"><?php echo $this->getAddButtonHtml()?>&nbsp;<?php echo $this->getUploadButtonHtml() ?></td>
84
+ </tr>
85
+ </tfoot>
86
+ <tbody id="link_items_body">
87
+ </tbody>
88
+ </table>
89
+ <div><small><?php echo Mage::helper('downloadable')->__('Alphanumeric, dash and underscore characters are recommended for filenames. Improper characters are replaced with \'_\'.')?></small></div>
90
+ </div>
91
+ </div>
92
+ </div>
93
+
94
+ <script type="text/javascript">
95
+ //<![CDATA[
96
+ var linkTemplate = '<tr>'+
97
+ '<td>'+
98
+ '<input type="hidden" class="__delete__" name="downloadable[link][{{id}}][is_delete]" value="" />'+
99
+ '<input type="hidden" name="downloadable[link][{{id}}][link_id]" value="{{link_id}}" />'+
100
+ '<input type="text" class="required-entry input-text" name="downloadable[link][{{id}}][title]" value="{{title}}" />'+
101
+ '<?php echo $_product->getStoreId()?'<input type="checkbox" id="downloadable_link_{{id}}_title" name="downloadable[link][{{id}}][use_default_title]" value="1" /><label class="normal" for="downloadable_link_{{id}}_title">Use Default Value</label>':'' ?>'+
102
+ '</td>'+
103
+ <?php if ($this->getCanReadPrice() !== false) : ?>
104
+ '<td class="input-price">'+
105
+ '<input type="text" id="downloadable_link_{{id}}_price_value" class="input-text validate-number link-prices<?php if ($this->getCanEditPrice() === false) : ?> disabled<?php endif; ?>" name="downloadable[link][{{id}}][price]" value="{{price}}"<?php if ($this->getCanEditPrice() === false) : ?> disabled="disabled"<?php endif; ?> /> ' +
106
+ '<label>[<?php echo Mage::app()->getStore($_product->getStoreId())->getBaseCurrencyCode() ?>]</label>' +
107
+ <?php if ($_product->getStoreId() && $this->getIsPriceWebsiteScope()) : ?>
108
+ '<br /><input type="checkbox" id="downloadable_link_{{id}}_price" name="downloadable[link][{{id}}][use_default_price]" value="1"<?php if ($this->getCanEditPrice() === false) : ?> disabled="disabled"<?php endif; ?> /> <label for="downloadable_link_{{id}}_price">Use Default Value</label>' +
109
+ <?php endif; ?>
110
+ '</td>' +
111
+ <?php else : ?>
112
+ '<input type="hidden" id="downloadable_link_{{id}}_price_value" class="link-prices" name="downloadable[link][{{id}}][price]" value="0" />' +
113
+ <?php if ($_product->getStoreId() && $this->getIsPriceWebsiteScope()) : ?>
114
+ '<input type="hidden" id="downloadable_link_{{id}}_price" name="downloadable[link][{{id}}][use_default_price]" value="1" />' +
115
+ <?php endif; ?>
116
+ <?php endif; ?>
117
+ '<td><input type="text" id="downloadable_link_{{id}}_downloads" name="downloadable[link][{{id}}][number_of_downloads]" class="input-text downloads" value="{{number_of_downloads}}" />'+
118
+ '<p><input type="checkbox" class="checkbox" id="downloadable_link_{{id}}_is_unlimited" name="downloadable[link][{{id}}][is_unlimited]" value="1" {{is_unlimited}} /> <label for="downloadable_link_{{id}}_is_unlimited">Unlimited</label></p></td>'+
119
+ '<td class="a-center">'+
120
+ '<select id="downloadable_link _{{id}}_shareable" name="downloadable[link][{{id}}][is_shareable]">'+
121
+ '<option value="1">Yes</option>'+
122
+ '<option value="0">No</option>'+
123
+ '<option value="2" selected="selected">Use config</option>'+
124
+ '</select>'+
125
+ '</td>'+
126
+ '<td class="a-center">'+
127
+ '<input type="hidden" id="downloadable_link _{{id}}_old_use_editionguard" class="old_use_editionguard" name="downloadable[link][{{id}}][old_use_editionguard]" value="{{use_editionguard}}" />'+
128
+ '<select id="downloadable_link _{{id}}_editionguard" class="use_editionguard" name="downloadable[link][{{id}}][use_editionguard]">'+
129
+ '<option value="1">Yes</option>'+
130
+ '<option value="0">No</option>'+
131
+ '<option value="2" selected="selected">Use config</option>'+
132
+ '</select>'+
133
+ '</td>'+
134
+ '<td>'+
135
+ '<div class="files">'+
136
+ '<div class="row">'+
137
+ '<label for="downloadable_link_{{id}}_sample_file_type"><input type="radio" class="radio" id="downloadable_link_{{id}}_sample_file_type" name="downloadable[link][{{id}}][sample][type]" value="file"{{sample_file_checked}} /> File:</label>'+
138
+ '<input type="hidden" id="downloadable_link_{{id}}_sample_file_save" name="downloadable[link][{{id}}][sample][file]" value="{{sample_file_save}}" />'+
139
+ '<div id="downloadable_link_{{id}}_sample_file" class="uploader">'+
140
+ '<div id="downloadable_link_{{id}}_sample_file-old" class="file-row-info"></div>'+
141
+ '<div id="downloadable_link_{{id}}_sample_file-new" class="file-row-info"></div>'+
142
+ '<div class="buttons">'+
143
+ '<div id="downloadable_link_{{id}}_sample_file-install-flash" style="display:none">'+
144
+ '<?php echo $this->jsQuoteEscape(Mage::helper('media')->__('This content requires last version of Adobe Flash Player. <a href="%s">Get Flash</a>', 'http://www.adobe.com/go/getflash/')) ?>'+
145
+ '</div>'+
146
+ '</div>'+
147
+ '<div class="clear"></div>'+
148
+ '</div>'+
149
+ '</div>'+
150
+ '<div class="row">'+
151
+ '<label for="downloadable_link_{{id}}_sample_url_type"><input type="radio" class="radio" id="downloadable_link_{{id}}_sample_url_type" name="downloadable[link][{{id}}][sample][type]" value="url"{{sample_url_checked}} /> URL:</label><input type="text" class="input-text" name="downloadable[link][{{id}}][sample][url]" value="{{sample_url}}" />'+
152
+ '</div>'+
153
+ '<div>'+
154
+ '<span id="downloadable_link_{{id}}_sample_container"></span>'+
155
+ '</div>'+
156
+ '</div>'+
157
+ '</td>'+
158
+ '<td>'+
159
+ '<div class="files">'+
160
+ '<div class="row">'+
161
+ '<label for="downloadable_link_{{id}}_file_type"><input type="radio" class="radio validate-one-required-by-name" id="downloadable_link_{{id}}_file_type" name="downloadable[link][{{id}}][type]" value="file"{{file_checked}} /> File:</label>'+
162
+ '<input type="hidden" class="validate-downloadable-file" id="downloadable_link_{{id}}_file_save" name="downloadable[link][{{id}}][file]" value="{{file_save}}" />'+
163
+ '<div id="downloadable_link_{{id}}_file" class="uploader">'+
164
+ '<div id="downloadable_link_{{id}}_file-old" class="file-row-info"></div>'+
165
+ '<div id="downloadable_link_{{id}}_file-new" class="file-row-info new-file"></div>'+
166
+ '<div class="buttons">'+
167
+ '<div id="downloadable_link_{{id}}_file-install-flash" style="display:none">'+
168
+ '<?php echo $this->jsQuoteEscape(Mage::helper('media')->__('This content requires last version of Adobe Flash Player. <a href="%s">Get Flash</a>', 'http://www.adobe.com/go/getflash/')) ?>'+
169
+ '</div>'+
170
+ '</div>'+
171
+ '<div class="clear"></div>'+
172
+ '</div>'+
173
+ '</div>'+
174
+ '<div class="row">'+
175
+ '<label for="downloadable_link_{{id}}_url_type"><input type="radio" class="radio validate-one-required-by-name" id="downloadable_link_{{id}}_url_type" name="downloadable[link][{{id}}][type]" value="url"{{url_checked}} /> URL:</label><input type="text" class="validate-downloadable-url input-text" name="downloadable[link][{{id}}][link_url]" value="{{link_url}}" />'+
176
+ '</div>'+
177
+ '<div>'+
178
+ '<span id="downloadable_link_{{id}}_link_container"></span>'+
179
+ '</div>'+
180
+ '</div>'+
181
+ '</td>'+
182
+ '<td class="a-center"><input type="text" name="downloadable[link][{{id}}][sort_order]" value="{{sort_order}}" class="input-text sort" /></td>'+
183
+ '<td>'+
184
+ '<button id="downloadable_link_{{id}}_delete_button" type="button" class="scalable delete icon-btn delete-link-item"><span><?php echo Mage::helper('downloadable')->__('Delete'); ?></span></button>'+
185
+ '</td>'+
186
+ '</tr>';
187
+
188
+ var linkItems = {
189
+ tbody : $('link_items_body'),
190
+ templateSyntax : /(^|.|\r|\n)({{(\w+)}})/,
191
+ templateText : linkTemplate,
192
+ itemCount : 0,
193
+ add : function(data) {
194
+ alertAlreadyDisplayed = false;
195
+ this.template = new Template(this.templateText, this.templateSyntax);
196
+
197
+ if(!data.link_id){
198
+ data = {};
199
+ data.link_id = 0;
200
+ data.link_type = 'file';
201
+ data.sample_type = 'none';
202
+ data.number_of_downloads = '<?php echo $this->getConfigMaxDownloads() ?>';
203
+ }
204
+
205
+ data.id = this.itemCount;
206
+
207
+ if (data.link_type == 'url') {
208
+ data.url_checked = ' checked="checked"';
209
+ } else if (data.link_type == 'file') {
210
+ data.file_checked = ' checked="checked"';
211
+ }
212
+ if (data.sample_type == 'url') {
213
+ data.sample_url_checked = ' checked="checked"';
214
+ } else if (data.sample_type == 'file') {
215
+ data.sample_file_checked = ' checked="checked"';
216
+ }
217
+
218
+ Element.insert(this.tbody, {'bottom':this.template.evaluate(data)});
219
+
220
+ scopeTitle = $('downloadable_link_'+data.id+'_title');
221
+ if (scopeTitle) {
222
+ Event.observe(scopeTitle, 'click', function(event){
223
+ scopeElm = $(Event.findElement(event, 'input'));
224
+ titleField = scopeElm.up(0).down('input[type="text"]');
225
+ if (scopeElm.checked == true) {
226
+ titleField.disabled = true;
227
+ } else {
228
+ titleField.disabled = false;
229
+ }
230
+ });
231
+ }
232
+ if (!data.store_title && scopeTitle) {
233
+ scopeTitle.up(0).down('input[type="text"]').disabled = true;
234
+ scopeTitle.checked = true;
235
+ }
236
+
237
+ scopePrice = $('downloadable_link_'+data.id+'_price');
238
+ if (scopePrice) {
239
+ Event.observe(scopePrice, 'click', function(event){
240
+ scopeElm = $(Event.findElement(event, 'input'));
241
+ priceField = scopeElm.up(0).down('input[type="text"]');
242
+ if (scopeElm.checked == true) {
243
+ priceField.disabled = true;
244
+ } else {
245
+ priceField.disabled = false;
246
+ }
247
+ });
248
+ }
249
+ if (!data.website_price && scopePrice) {
250
+ scopePrice.up(0).down('input[type="text"]').disabled = true;
251
+ scopePrice.checked = true;
252
+ }
253
+ downloadsElm = $('downloadable_link_'+data.id+'_downloads');
254
+ isUnlimitedElm = $('downloadable_link_'+data.id+'_is_unlimited');
255
+ if (data.is_unlimited) {
256
+ downloadsElm.disabled = true;
257
+ }
258
+ Event.observe(isUnlimitedElm, 'click', function(event){
259
+ elm = Event.element(event);
260
+ elm.up('td').down('input[type="text"].downloads').disabled = elm.checked;
261
+ });
262
+
263
+ if (data.is_shareable) {
264
+ options = $('downloadable_link _'+data.id+'_shareable').options;
265
+ for (var i=0; i < options.length; i++) {
266
+ if (options[i].value == data.is_shareable) {
267
+ options[i].selected = true;
268
+ }
269
+ }
270
+ }
271
+
272
+ if (data.use_editionguard) {
273
+ options = $('downloadable_link _'+data.id+'_editionguard').options;
274
+ for (var i=0; i < options.length; i++) {
275
+ if (options[i].value == data.use_editionguard) {
276
+ options[i].selected = true;
277
+ }
278
+ }
279
+ }
280
+
281
+ sampleUrl = $('downloadable_link_'+data.id+'_sample_url_type');
282
+ linkUrl = $('downloadable_link_'+data.id+'_url_type');
283
+
284
+ if (!data.file_save) {
285
+ data.file_save = [];
286
+ }
287
+ if (!data.sample_file_save) {
288
+ data.sample_file_save = [];
289
+ }
290
+
291
+ // link sample file
292
+ new Downloadable.FileUploader(
293
+ 'linkssample',
294
+ 'linkssample_'+data.id,
295
+ sampleUrl.up('td'),
296
+ 'downloadable[link]['+data.id+'][sample]',
297
+ data.sample_file_save,
298
+ 'downloadable_link_'+data.id+'_sample_file',
299
+ <?php echo $this->getConfigJson('link_samples') ?>
300
+ );
301
+ // link file
302
+ new Downloadable.FileUploader(
303
+ 'links',
304
+ 'links_'+data.id,
305
+ linkUrl.up('td'),
306
+ 'downloadable[link]['+data.id+']',
307
+ data.file_save,
308
+ 'downloadable_link_'+data.id+'_file',
309
+ <?php echo $this->getConfigJson() ?>
310
+ );
311
+
312
+ linkFile = $('downloadable_link_'+data.id+'_file_type');
313
+ linkFile.advaiceContainer = 'downloadable_link_'+data.id+'_link_container';
314
+ linkUrl.advaiceContainer = 'downloadable_link_'+data.id+'_link_container';
315
+ $('downloadable_link_'+data.id+'_file_save').advaiceContainer = 'downloadable_link_'+data.id+'_link_container';
316
+
317
+ sampleFile = $('downloadable_link_'+data.id+'_sample_file_type');
318
+
319
+ this.itemCount++;
320
+ this.togglePriceFields();
321
+ this.bindRemoveButtons();
322
+ this.bindEditionguardSelect();
323
+ },
324
+ remove : function(event){
325
+ var element = $(Event.findElement(event, 'tr'));
326
+ var use_editionguard = element.down('select.use_editionguard').value != 0;
327
+ var old_use_editionguard = element.down('input[type="hidden"].old_use_editionguard').value != 0;
328
+ if (!old_use_editionguard || !use_editionguard || confirm("This file is managed by Editionguard. If you delete it, previous customers will no longer be able to download their file. This cannot be undone.\n\nAre you sure?"))
329
+ {
330
+ alertAlreadyDisplayed = false;
331
+ if(element){
332
+ element.down('input[type="hidden"].__delete__').value = '1';
333
+ Element.select(element, 'div.flex').each(function(elm){
334
+ elm.remove();
335
+ });
336
+ element.addClassName('no-display');
337
+ element.addClassName('ignore-validate');
338
+ element.hide();
339
+ }
340
+ }
341
+ },
342
+ editionguardSelect : function(event){
343
+ var element = $(Event.findElement(event, 'tr'));
344
+ var use_editionguard = element.down('select.use_editionguard').value == 1;
345
+ var old_use_editionguard = element.down('input[type="hidden"].old_use_editionguard').value != 0;
346
+ if (old_use_editionguard && !use_editionguard && !confirm("This file is managed by Editionguard. If you disable it, previous customers will no longer be able to download their file.\n\nAre you sure?"))
347
+ {
348
+ element.down('select.use_editionguard').value = element.down('input[type="hidden"].old_use_editionguard').value;
349
+ return false;
350
+ }
351
+
352
+ return true;
353
+ },
354
+ bindRemoveButtons : function(){
355
+ var buttons = $$('tbody#link_items_body .delete-link-item');
356
+ for(var i=0;i<buttons.length;i++){
357
+ if(!$(buttons[i]).binded && !$(buttons[i]).hasClassName('disabled')){
358
+ $(buttons[i]).binded = true;
359
+ Event.observe(buttons[i], 'click', this.remove.bind(this));
360
+ }
361
+ }
362
+ },
363
+ bindEditionguardSelect : function(){
364
+ var selects = $$('tbody#link_items_body select.use_editionguard');
365
+ for(var i=0;i<selects.length;i++){
366
+ if(!$(selects[i]).binded && !$(selects[i]).hasClassName('disabled')){
367
+ $(selects[i]).binded = true;
368
+ Event.observe(selects[i], 'change', this.editionguardSelect.bind(this));
369
+ }
370
+ }
371
+ },
372
+ togglePriceFields : function(){
373
+ var toogleTo = $('downloadable_link_purchase_type').value;
374
+ var disableFlag = true;
375
+ if (toogleTo == '1') {
376
+ disableFlag = false;
377
+ }
378
+ $$('.link-prices[type="text"]').each(function(elm){
379
+ var flag = disableFlag;
380
+ if (elm.hasClassName('disabled')) {
381
+ flag = true;
382
+ }
383
+ elm.disabled = flag;
384
+ });
385
+ }
386
+ }
387
+
388
+ linkItems.bindRemoveButtons();
389
+ linkItems.bindEditionguardSelect();
390
+
391
+ if ($('downloadable_link_purchase_type')) {
392
+ Event.observe('downloadable_link_purchase_type', 'change', linkItems.togglePriceFields.bind());
393
+ }
394
+
395
+ if($('add_link_item')) {
396
+ Event.observe('add_link_item', 'click', linkItems.add.bind(linkItems));
397
+ }
398
+
399
+ <?php foreach ($this->getLinkData() as $item): ?>
400
+ linkItems.add(<?php echo $item->toJson()?>);
401
+ <?php endforeach; ?>
402
+
403
+ Validation.addAllThese([
404
+ ['validate-downloadable-link-sample-file', 'Please specify File.', function(v,element) {
405
+ fileSaveElm = element.up('div').next('input[type="hidden"]');
406
+ if (element.checked && (fileSaveElm.value == '' || fileSaveElm.value == '[]')) {
407
+ return false;
408
+ }
409
+ return true;
410
+ }]
411
+ ]);
412
+ Validation.addAllThese([
413
+ ['validate-downloadable-link-sample-url', 'Please specify Sample URL.', function(v,element) {
414
+ if (element.checked && element.up('p').down('input[type="text"]').value == '') {
415
+ return false;
416
+ }
417
+ return true;
418
+ }]
419
+ ]);
420
+ //]]>
421
+ </script>
app/etc/modules/Editionguard_Editionguard.xml ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <!--
3
+ /**
4
+ * EditionGuard
5
+ *
6
+ * This source file is proprietary property of EditionGuard. Any reuse or
7
+ * distribution of any part of this file without prior consent is prohibited.
8
+ *
9
+ * @category EditionGuard
10
+ * @package Editionguard_Editionguard
11
+ * @copyright Copyright (c) 2012 EditionGuard. All rights Reserved.
12
+ */
13
+ -->
14
+ <config>
15
+ <modules>
16
+ <Editionguard_Editionguard>
17
+ <active>true</active>
18
+ <codePool>community</codePool>
19
+ </Editionguard_Editionguard>
20
+ </modules>
21
+ </config>
package.xml ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0"?>
2
+ <package>
3
+ <name>editionguard_drm</name>
4
+ <version>1.0.0.0</version>
5
+ <stability>stable</stability>
6
+ <license>New BSD</license>
7
+ <channel>community</channel>
8
+ <extends/>
9
+ <summary>This extension is used to integrate Magento with EditionGuard, a cost-effective Adobe DRM service for eBooks.</summary>
10
+ <description>This extension will allow you to create eBooks protected with the industry standard Adobe Content Server 4 DRM through the EditionGuard APIs. Through the admin interface, you will be able to manage your DRM enabled eBooks and put them up for sale as Downloadable Products. Your clients will then be able to purchase your eBooks, download them securely on the frontend and open them in Adobe Digital Editions.</description>
11
+ <notes>Initial release.</notes>
12
+ <authors><author><name>EditionGuard</name><user>EditionGuard</user><email>support@editionguard.com</email></author></authors>
13
+ <date>2012-10-15</date>
14
+ <time>01:26:13</time>
15
+ <contents><target name="magecommunity"><dir><dir name="Editionguard"><dir name="Editionguard"><dir name="Block"><dir name="Downloadable"><dir name="Adminhtml"><dir name="Catalog"><dir name="Product"><dir name="Edit"><dir name="Tab"><dir name="Downloadable"><file name="Links.php" hash="d5cc57710639854da0b3af6924195b8c"/></dir></dir></dir></dir></dir></dir><dir name="Customer"><dir name="Products"><file name="List.php" hash="5b46f7d767d2976b3a03d0aac3599c76"/></dir></dir></dir></dir><dir name="Helper"><file name="Data.php" hash="ae7497261a9e9e5490e4ab580dfa645b"/></dir><dir name="Model"><dir name="Downloadable"><file name="Link.php" hash="90c14f16cbfc68012fc2e522d0b106c0"/></dir><file name="Exception.php" hash="18afd5abedb9a0413481ea5255a89a53"/><dir name="Mysql4"><dir name="Editionguard"><file name="Collection.php" hash="de7c2d9c3aa413612a6473dafdf2f779"/></dir><file name="Editionguard.php" hash="adaa5e0d1718f506e89c657420c4d31a"/></dir><dir name="Resource"><dir name="Downloadable"><file name="Link.php" hash="cfc4b1417f2fd0adf93daf15b24681e1"/></dir><dir name="Eav"><dir name="Mysql4"><file name="Setup.php" hash="ff76c3213b9b428220578ba48a667365"/></dir></dir></dir></dir><dir name="controllers"><file name="DownloadController.php" hash="22ef464060c9ffb33b9f031e9ece1752"/></dir><dir name="etc"><file name="config.xml" hash="75cff1d36221ef4fb96fb77afe2cc3c5"/><file name="system.xml" hash="68627dce272876b4b8e76511937d21b4"/></dir><dir name="sql"><dir name="editionguard_setup"><file name="install-1.0.0.0.php" hash="9e9ccd8e5fb5f5f63b32fa6ccea92ce6"/></dir></dir></dir></dir></dir></target><target name="magedesign"><dir><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="template"><dir name="editionguard"><dir name="downloadable"><dir name="product"><dir name="edit"><dir name="downloadable"><file name="links.phtml" hash="f2d9b8635fd3ea05e23f62ee5e916782"/></dir></dir></dir></dir></dir></dir></dir></dir></dir></dir></target><target name="mageetc"><dir><dir name="modules"><file name="Editionguard_Editionguard.xml" hash="1d6aac7609bf2b57392b64213f3722ca"/></dir></dir></target></contents>
16
+ <compatible/>
17
+ <dependencies><required><php><min>5.2.17</min><max>6.0.0</max></php></required></dependencies>
18
+ </package>