1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Connect_Adminhtml_Extension_CustomController extends Mage_Adminhtml_Controller_Action
35: {
36: 37: 38: 39:
40: public function indexAction()
41: {
42: $this->_title($this->__('System'))
43: ->_title($this->__('Magento Connect'))
44: ->_title($this->__('Package Extensions'));
45:
46: $this->_forward('edit');
47: }
48:
49: 50: 51: 52:
53: public function editAction()
54: {
55: $this->_title($this->__('System'))
56: ->_title($this->__('Magento Connect'))
57: ->_title($this->__('Package Extensions'))
58: ->_title($this->__('Edit Extension'));
59:
60: $this->loadLayout();
61: $this->_setActiveMenu('system/extension/custom');
62: $this->renderLayout();
63: }
64:
65: 66: 67: 68:
69: public function resetAction()
70: {
71: Mage::getSingleton('connect/session')->unsCustomExtensionPackageFormData();
72: $this->_redirect('*/*/edit');
73: }
74:
75: 76: 77: 78:
79: public function loadAction()
80: {
81: $packageName = base64_decode(strtr($this->getRequest()->getParam('id'), '-_,', '+/='));
82: if ($packageName) {
83: $session = Mage::getSingleton('connect/session');
84: try {
85: $data = Mage::helper('connect')->loadLocalPackage($packageName);
86: if (!$data) {
87: Mage::throwException(Mage::helper('connect')->__('Failed to load the package data.'));
88: }
89: $data = array_merge($data, array('file_name' => $packageName));
90: $session->setCustomExtensionPackageFormData($data);
91: $session->addSuccess(
92: Mage::helper('connect')->__('The package %s data has been loaded.', $packageName)
93: );
94: } catch (Exception $e) {
95: $session->addError($e->getMessage());
96: }
97: }
98: $this->_redirect('*/*/edit');
99: }
100:
101: 102: 103: 104:
105: public function saveAction()
106: {
107: $session = Mage::getSingleton('connect/session');
108: $p = $this->getRequest()->getPost();
109:
110: if (!empty($p['_create'])) {
111: $create = true;
112: unset($p['_create']);
113: }
114:
115: if ($p['file_name'] == '') {
116: $p['file_name'] = $p['name'];
117: }
118:
119: $session->setCustomExtensionPackageFormData($p);
120: try {
121: $ext = Mage::getModel('connect/extension');
122:
123: $ext->setData($p);
124: if ($ext->savePackage()) {
125: $session->addSuccess(Mage::helper('connect')->__('The package data has been saved.'));
126: } else {
127: $session->addError(Mage::helper('connect')->__('There was a problem saving package data'));
128: $this->_redirect('*/*/edit');
129: }
130: if (empty($create)) {
131: $this->_redirect('*/*/edit');
132: } else {
133: $this->_forward('create');
134: }
135: } catch (Mage_Core_Exception $e){
136: $session->addError($e->getMessage());
137: $this->_redirect('*/*');
138: } catch (Exception $e){
139: $session->addException($e, Mage::helper('connect')->__('Failed to save the package.'));
140: $this->_redirect('*/*');
141: }
142: }
143:
144: 145: 146: 147:
148: public function createAction()
149: {
150: $session = Mage::getSingleton('connect/session');
151: try {
152: $p = $this->getRequest()->getPost();
153: $session->setCustomExtensionPackageFormData($p);
154: $ext = Mage::getModel('connect/extension');
155: $ext->setData($p);
156: $packageVersion = $this->getRequest()->getPost('version_ids');
157: if (is_array($packageVersion)) {
158: if (in_array(Mage_Connect_Package::PACKAGE_VERSION_2X, $packageVersion)) {
159: $ext->createPackage();
160: }
161: if (in_array(Mage_Connect_Package::PACKAGE_VERSION_1X, $packageVersion)) {
162: $ext->createPackageV1x();
163: }
164: }
165: $this->_redirect('*/*');
166: } catch(Mage_Core_Exception $e){
167: $session->addError($e->getMessage());
168: $this->_redirect('*/*');
169: } catch(Exception $e){
170: $session->addException($e, Mage::helper('connect')->__('Failed to create the package.'));
171: $this->_redirect('*/*');
172: }
173: }
174:
175: 176: 177: 178:
179: public function loadtabAction()
180: {
181: $this->loadLayout();
182: $this->renderLayout();
183: }
184:
185: 186: 187: 188:
189: public function gridAction()
190: {
191: $this->loadLayout();
192: $this->renderLayout();
193: }
194:
195: 196: 197: 198: 199:
200: protected function _isAllowed()
201: {
202: return Mage::getSingleton('admin/session')->isAllowed('system/extensions/custom');
203: }
204: }
205: