1: | <?php
2: | namespace Opencart\Admin\Controller\Extension;
3: | /**
4: | * Class Currency
5: | *
6: | * @package Opencart\Admin\Controller\Extension
7: | */
8: | class Currency extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return void
13: | */
14: | public function index(): void {
15: | $this->response->setOutput($this->getList());
16: | }
17: |
18: | /**
19: | * Get List
20: | *
21: | * @return string
22: | */
23: | public function getList(): string {
24: | $this->load->language('extension/currency');
25: |
26: | $available = [];
27: |
28: | $results = glob(DIR_EXTENSION . '*/admin/controller/currency/*.php');
29: |
30: | foreach ($results as $result) {
31: | $available[] = basename($result, '.php');
32: | }
33: |
34: | $installed = [];
35: |
36: | $this->load->model('setting/extension');
37: |
38: | $extensions = $this->model_setting_extension->getExtensionsByType('currency');
39: |
40: | foreach ($extensions as $extension) {
41: | if (in_array($extension['code'], $available)) {
42: | $installed[] = $extension['code'];
43: | } else {
44: | $this->model_setting_extension->uninstall('currency', $extension['code']);
45: | }
46: | }
47: |
48: | $data['extensions'] = [];
49: |
50: | if ($results) {
51: | foreach ($results as $result) {
52: | $path = substr($result, strlen(DIR_EXTENSION));
53: |
54: | $extension = substr($path, 0, strpos($path, '/'));
55: |
56: | $code = basename($result, '.php');
57: |
58: | $this->load->language('extension/' . $extension . '/currency/' . $code, $code);
59: |
60: | $data['extensions'][] = [
61: | 'name' => $this->language->get($code . '_heading_title') . ($code == $this->config->get('config_currency') ? $this->language->get('text_default') : ''),
62: | 'status' => $this->config->get('currency_' . $code . '_status') ? $this->language->get('text_enabled') : $this->language->get('text_disabled'),
63: | 'install' => $this->url->link('extension/currency.install', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
64: | 'uninstall' => $this->url->link('extension/currency.uninstall', 'user_token=' . $this->session->data['user_token'] . '&extension=' . $extension . '&code=' . $code),
65: | 'installed' => in_array($code, $installed),
66: | 'edit' => $this->url->link('extension/' . $extension . '/currency/' . $code, 'user_token=' . $this->session->data['user_token'])
67: | ];
68: | }
69: | }
70: |
71: | $data['promotion'] = $this->load->controller('marketplace/promotion');
72: |
73: | return $this->load->view('extension/currency', $data);
74: | }
75: |
76: | /**
77: | * Install
78: | *
79: | * @return void
80: | */
81: | public function install(): void {
82: | $this->load->language('extension/currency');
83: |
84: | $json = [];
85: |
86: | if (isset($this->request->get['extension'])) {
87: | $extension = basename($this->request->get['extension']);
88: | } else {
89: | $extension = '';
90: | }
91: |
92: | if (isset($this->request->get['code'])) {
93: | $code = basename($this->request->get['code']);
94: | } else {
95: | $code = '';
96: | }
97: |
98: | if (!$this->user->hasPermission('modify', 'extension/currency')) {
99: | $json['error'] = $this->language->get('error_permission');
100: | }
101: |
102: | if (!is_file(DIR_EXTENSION . $extension . '/admin/controller/currency/' . $code . '.php')) {
103: | $json['error'] = $this->language->get('error_extension');
104: | }
105: |
106: | if (!$json) {
107: | $this->load->model('setting/extension');
108: |
109: | $this->model_setting_extension->install('currency', $extension, $code);
110: |
111: | $this->load->model('user/user_group');
112: |
113: | $this->model_user_user_group->addPermission($this->user->getGroupId(), 'access', 'extension/' . $extension . '/currency/' . $code);
114: | $this->model_user_user_group->addPermission($this->user->getGroupId(), 'modify', 'extension/' . $extension . '/currency/' . $code);
115: |
116: | $namespace = str_replace(['_', '/'], ['', '\\'], ucwords($extension, '_/'));
117: |
118: | // Register controllers, models and system extension folders
119: | $this->autoloader->register('Opencart\Admin\Controller\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/controller/');
120: | $this->autoloader->register('Opencart\Admin\Model\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/admin/model/');
121: | $this->autoloader->register('Opencart\System\Extension\\' . $namespace, DIR_EXTENSION . $extension . '/system/');
122: |
123: | // Template directory
124: | $this->template->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/view/template/');
125: |
126: | // Language directory
127: | $this->language->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/admin/language/');
128: |
129: | // Config directory
130: | $this->config->addPath('extension/' . $extension, DIR_EXTENSION . $extension . '/system/config/');
131: |
132: | // Call install method if it exists
133: | $this->load->controller('extension/' . $extension . '/currency/' . $code . '.install');
134: |
135: | $json['success'] = $this->language->get('text_success');
136: | }
137: |
138: | $this->response->addHeader('Content-Type: application/json');
139: | $this->response->setOutput(json_encode($json));
140: | }
141: |
142: | /**
143: | * Uninstall
144: | *
145: | * @return void
146: | */
147: | public function uninstall(): void {
148: | $this->load->language('extension/currency');
149: |
150: | $json = [];
151: |
152: | if (!$this->user->hasPermission('modify', 'extension/currency')) {
153: | $json['error'] = $this->language->get('error_permission');
154: | }
155: |
156: | if (!$json) {
157: | $this->load->model('setting/extension');
158: |
159: | $this->model_setting_extension->uninstall('currency', $this->request->get['code']);
160: |
161: | // Call uninstall method if it exists
162: | $this->load->controller('extension/' . $this->request->get['extension'] . '/currency/' . $this->request->get['code'] . '.uninstall');
163: |
164: | $json['success'] = $this->language->get('text_success');
165: | }
166: |
167: | $this->response->addHeader('Content-Type: application/json');
168: | $this->response->setOutput(json_encode($json));
169: | }
170: | }
171: |

OpenCart API API documentation generated by ApiGen dev-master