1: | <?php
2: | namespace Opencart\Admin\Controller\Extension\Opencart\Module;
3: | /**
4: | * Class Blog
5: | *
6: | * @package Opencart\Admin\Controller\Extension\Opencart\Module
7: | */
8: | class Blog extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return void
13: | */
14: | public function index(): void {
15: | $this->load->language('extension/opencart/module/blog');
16: |
17: | $this->document->setTitle($this->language->get('heading_title'));
18: |
19: | $data['breadcrumbs'] = [];
20: |
21: | $data['breadcrumbs'][] = [
22: | 'text' => $this->language->get('text_home'),
23: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
24: | ];
25: |
26: | $data['breadcrumbs'][] = [
27: | 'text' => $this->language->get('text_extension'),
28: | 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module')
29: | ];
30: |
31: | if (!isset($this->request->get['module_id'])) {
32: | $data['breadcrumbs'][] = [
33: | 'text' => $this->language->get('heading_title'),
34: | 'href' => $this->url->link('extension/opencart/module/blog', 'user_token=' . $this->session->data['user_token'])
35: | ];
36: | } else {
37: | $data['breadcrumbs'][] = [
38: | 'text' => $this->language->get('heading_title'),
39: | 'href' => $this->url->link('extension/opencart/module/blog', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'])
40: | ];
41: | }
42: |
43: | if (!isset($this->request->get['module_id'])) {
44: | $data['save'] = $this->url->link('extension/opencart/module/blog.save', 'user_token=' . $this->session->data['user_token']);
45: | } else {
46: | $data['save'] = $this->url->link('extension/opencart/module/blog.save', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id']);
47: | }
48: |
49: | $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module');
50: |
51: | if (isset($this->request->get['module_id'])) {
52: | $this->load->model('setting/module');
53: |
54: | $module_info = $this->model_setting_module->getModule($this->request->get['module_id']);
55: | }
56: |
57: | if (isset($module_info['name'])) {
58: | $data['name'] = $module_info['name'];
59: | } else {
60: | $data['name'] = '';
61: | }
62: |
63: | if (isset($module_info['limit'])) {
64: | $data['limit'] = $module_info['limit'];
65: | } else {
66: | $data['limit'] = 5;
67: | }
68: |
69: | if (isset($module_info['width'])) {
70: | $data['width'] = $module_info['width'];
71: | } else {
72: | $data['width'] = 200;
73: | }
74: |
75: | if (isset($module_info['height'])) {
76: | $data['height'] = $module_info['height'];
77: | } else {
78: | $data['height'] = 200;
79: | }
80: |
81: | if (isset($module_info['order'])) {
82: | $data['order'] = $module_info['order'];
83: | } else {
84: | $data['order'] = 'DESC';
85: | }
86: |
87: | if (isset($module_info['order_by'])) {
88: | $data['order_by'] = $module_info['order_by'];
89: | } else {
90: | $data['order_by'] = 'a.date_added';
91: | }
92: |
93: | if (isset($module_info['status'])) {
94: | $data['status'] = $module_info['status'];
95: | } else {
96: | $data['status'] = '';
97: | }
98: |
99: | if (isset($this->request->get['module_id'])) {
100: | $data['module_id'] = (int)$this->request->get['module_id'];
101: | } else {
102: | $data['module_id'] = 0;
103: | }
104: |
105: | $data['user_token'] = $this->session->data['user_token'];
106: |
107: | $data['header'] = $this->load->controller('common/header');
108: | $data['column_left'] = $this->load->controller('common/column_left');
109: | $data['footer'] = $this->load->controller('common/footer');
110: |
111: | $this->response->setOutput($this->load->view('extension/opencart/module/blog', $data));
112: | }
113: |
114: | /**
115: | * Save
116: | *
117: | * @return void
118: | */
119: | public function save(): void {
120: | $this->load->language('extension/opencart/module/blog');
121: |
122: | $json = [];
123: |
124: | if (!$this->user->hasPermission('modify', 'extension/opencart/module/blog')) {
125: | $json['error']['warning'] = $this->language->get('error_permission');
126: | }
127: |
128: | if ((oc_strlen($this->request->post['name']) < 3) || (oc_strlen($this->request->post['name']) > 64)) {
129: | $json['error']['name'] = $this->language->get('error_name');
130: | }
131: |
132: | if (!$this->request->post['width']) {
133: | $json['error']['width'] = $this->language->get('error_width');
134: | }
135: |
136: | if (!$this->request->post['height']) {
137: | $json['error']['height'] = $this->language->get('error_height');
138: | }
139: |
140: | if (!$json) {
141: | $this->load->model('setting/module');
142: |
143: | if (!$this->request->post['module_id']) {
144: | $json['module_id'] = $this->model_setting_module->addModule('opencart.blog', $this->request->post);
145: | } else {
146: | $this->model_setting_module->editModule($this->request->post['module_id'], $this->request->post);
147: | }
148: |
149: | $json['success'] = $this->language->get('text_success');
150: | }
151: |
152: | $this->response->addHeader('Content-Type: application/json');
153: | $this->response->setOutput(json_encode($json));
154: | }
155: | }
156: |

OpenCart API API documentation generated by ApiGen dev-master