00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 require_once 'Mage/Adminhtml/controllers/Catalog/ProductController.php';
00028
00029
00030
00031
00032
00033
00034
00035
00036 class Mage_Downloadable_Product_EditController extends Mage_Adminhtml_Catalog_ProductController
00037 {
00038
00039
00040
00041
00042
00043 protected function _construct()
00044 {
00045 $this->setUsedModuleName('Mage_Downloadable');
00046 }
00047
00048
00049
00050
00051
00052 public function formAction()
00053 {
00054 $this->_initProduct();
00055 $this->getResponse()->setBody(
00056 $this->getLayout()->createBlock('downloadable/adminhtml_catalog_product_edit_tab_downloadable', 'admin.product.downloadable.information')
00057 ->toHtml()
00058 );
00059 }
00060
00061
00062
00063
00064
00065
00066
00067 protected function _processDownload($resource, $resourceType)
00068 {
00069 $helper = Mage::helper('downloadable/download');
00070
00071
00072 $helper->setResource($resource, $resourceType);
00073
00074 $fileName = $helper->getFilename();
00075 $contentType = $helper->getContentType();
00076
00077 $this->getResponse()
00078 ->setHttpResponseCode(200)
00079 ->setHeader('Pragma', 'public', true)
00080 ->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true)
00081 ->setHeader('Content-type', $contentType, true);
00082
00083 if ($fileSize = $helper->getFilesize()) {
00084 $this->getResponse()
00085 ->setHeader('Content-Length', $fileSize);
00086 }
00087
00088 if ($contentDisposition = $helper->getContentDisposition()) {
00089 $this->getResponse()
00090 ->setHeader('Content-Disposition', $contentDisposition . '; filename='.$fileName);
00091 }
00092
00093 $this->getResponse()
00094 ->clearBody();
00095 $this->getResponse()
00096 ->sendHeaders();
00097
00098 $helper->output();
00099 }
00100
00101
00102
00103
00104
00105 public function linkAction()
00106 {
00107 $linkId = $this->getRequest()->getParam('id', 0);
00108 $link = Mage::getModel('downloadable/link')->load($linkId);
00109 if ($link->getId()) {
00110 $resource = '';
00111 $resourceType = '';
00112 if ($link->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_URL) {
00113 $resource = $link->getLinkUrl();
00114 $resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_URL;
00115 } elseif ($link->getLinkType() == Mage_Downloadable_Helper_Download::LINK_TYPE_FILE) {
00116 $resource = Mage::helper('downloadable/file')->getFilePath(
00117 Mage_Downloadable_Model_Link::getBasePath(), $link->getLinkFile()
00118 );
00119 $resourceType = Mage_Downloadable_Helper_Download::LINK_TYPE_FILE;
00120 }
00121 try {
00122 $this->_processDownload($resource, $resourceType);
00123 } catch (Mage_Core_Exception $e) {
00124 $this->_getCustomerSession()->addError(Mage::helper('downloadable')->__('Sorry, there was an error getting requested content'));
00125 }
00126 }
00127 }
00128
00129 }