Issues (2407)

administration/controller/blog/setting.php (4 issues)

1
<?php
2
3
/* 	Divine CMS - Open source CMS for widespread use.
4
    Copyright (c) 2019 Mykola Burakov ([email protected])
5
6
    See SOURCE.txt for other and additional information.
7
8
    This file is part of Divine CMS.
9
10
    This program is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
15
    This program is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
    GNU General Public License for more details.
19
20
    You should have received a copy of the GNU General Public License
21
    along with this program. If not, see <http://www.gnu.org/licenses/>. */
22
23
class ControllerBlogSetting extends \Divine\Engine\Core\Controller
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
24
{
25
    private $error = array();
26
27
    public function index()
0 ignored issues
show
Expected 2 blank lines before function; 1 found
Loading history...
28
    {
29
        $this->load->language('blog/setting');
30
31
        $this->document->setTitle($this->language->get('heading_title'));
32
33
        $this->load->model('setting/setting');
34
35
        if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
36
            $this->model_setting_setting->editSetting('configblog', $this->request->post);
37
38
            $this->session->data['success'] = $this->language->get('text_success');
39
40
            $this->response->redirect($this->url->link('blog/setting', 'token=' . $this->session->data['token'], true));
41
        }
42
43
44
45
        $data['heading_title'] = $this->language->get('heading_title');
0 ignored issues
show
Comprehensibility Best Practice introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.
Loading history...
46
        $data['text_edit'] = $this->language->get('text_edit');
47
        $data['text_yes'] = $this->language->get('text_yes');
48
        $data['text_no'] = $this->language->get('text_no');
49
        $data['text_article'] = $this->language->get('text_article');
50
        $data['text_review'] = $this->language->get('text_review');
51
        $data['entry_article_limit'] = $this->language->get('entry_article_limit');
52
        $data['entry_article_description_length'] = $this->language->get('entry_article_description_length');
53
        $data['entry_limit_admin'] = $this->language->get('entry_limit_admin');
54
        $data['entry_article_count'] = $this->language->get('entry_article_count');
55
        $data['entry_blog_menu'] = $this->language->get('entry_blog_menu');
56
        $data['entry_article_download'] = $this->language->get('entry_article_download');
57
        $data['entry_review'] = $this->language->get('entry_review');
58
        $data['entry_review_guest'] = $this->language->get('entry_review_guest');
59
        $data['entry_review_mail'] = $this->language->get('entry_review_mail');
60
        $data['entry_image_category'] = $this->language->get('entry_image_category');
61
        $data['entry_image_article'] = $this->language->get('entry_image_article');
62
        $data['entry_image_related'] = $this->language->get('entry_image_related');
63
        $data['entry_width'] = $this->language->get('entry_width');
64
        $data['entry_height'] = $this->language->get('entry_height');
65
        $data['entry_name'] = $this->language->get('entry_name');
66
        $data['entry_html_h1'] = $this->language->get('entry_html_h1');
67
        $data['entry_meta_title'] = $this->language->get('entry_meta_title');
68
        $data['entry_meta_description'] = $this->language->get('entry_meta_description');
69
        $data['help_comment'] = $this->language->get('help_comment');
70
        $data['help_article_limit'] = $this->language->get('help_article_limit');
71
        $data['help_article_description_length'] = $this->language->get('help_article_description_length');
72
        $data['help_limit_admin'] = $this->language->get('help_limit_admin');
73
        $data['help_article_count'] = $this->language->get('help_article_count');
74
        $data['help_blog_menu'] = $this->language->get('help_blog_menu');
75
        $data['help_review'] = $this->language->get('help_review');
76
        $data['help_review_guest'] = $this->language->get('help_review_guest');
77
        $data['help_review_mail'] = $this->language->get('help_review_mail');
78
        $data['button_save'] = $this->language->get('button_save');
79
        $data['button_cancel'] = $this->language->get('button_cancel');
80
        $data['tab_general'] = $this->language->get('tab_general');
81
        $data['tab_option'] = $this->language->get('tab_option');
82
        $data['tab_image'] = $this->language->get('tab_image');
83
84
85
        
86
        if (isset($this->error['warning'])) {
87
            $data['error_warning'] = $this->error['warning'];
88
        } else {
89
            $data['error_warning'] = '';
90
        }
91
92
        if (isset($this->error['image_category'])) {
93
            $data['error_image_category'] = $this->error['image_category'];
94
        } else {
95
            $data['error_image_category'] = '';
96
        }
97
98
        if (isset($this->error['image_article'])) {
99
            $data['error_image_article'] = $this->error['image_article'];
100
        } else {
101
            $data['error_image_article'] = '';
102
        }
103
104
        if (isset($this->error['image_related'])) {
105
            $data['error_image_related'] = $this->error['image_related'];
106
        } else {
107
            $data['error_image_related'] = '';
108
        }
109
110
        if (isset($this->error['article_limit'])) {
111
            $data['error_article_limit'] = $this->error['article_limit'];
112
        } else {
113
            $data['error_article_limit'] = '';
114
        }
115
116
        if (isset($this->error['article_description_length'])) {
117
            $data['error_article_description_length'] = $this->error['article_description_length'];
118
        } else {
119
            $data['error_article_description_length'] = '';
120
        }
121
122
        if (isset($this->error['limit_admin'])) {
123
            $data['error_limit_admin'] = $this->error['limit_admin'];
124
        } else {
125
            $data['error_limit_admin'] = '';
126
        }
127
128
        $data['breadcrumbs'] = array();
129
130
        $data['breadcrumbs'][] = array(
131
            'text' => $this->language->get('text_home'),
132
            'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
133
        );
134
135
        $data['breadcrumbs'][] = array(
136
            'text' => $this->language->get('heading_title'),
137
            'href' => $this->url->link('blog/setting', 'token=' . $this->session->data['token'], true)
138
        );
139
140
        if (isset($this->session->data['success'])) {
141
            $data['success'] = $this->session->data['success'];
142
143
            unset($this->session->data['success']);
144
        } else {
145
            $data['success'] = '';
146
        }
147
148
        $data['action'] = $this->url->link('blog/setting', 'token=' . $this->session->data['token'], true);
149
150
        $data['cancel'] = $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true);
151
152
        $data['token'] = $this->session->data['token'];
153
        
154
        if (isset($this->request->post['configblog_article_limit'])) {
155
            $data['configblog_article_limit'] = $this->request->post['configblog_article_limit'];
156
        } else {
157
            $data['configblog_article_limit'] = $this->config->get('configblog_article_limit');
158
        }
159
160
        if (isset($this->request->post['configblog_article_description_length'])) {
161
            $data['configblog_article_description_length'] = $this->request->post['configblog_article_description_length'];
162
        } else {
163
            $data['configblog_article_description_length'] = $this->config->get('configblog_article_description_length');
164
        }
165
166
        if (isset($this->request->post['configblog_limit_admin'])) {
167
            $data['configblog_limit_admin'] = $this->request->post['configblog_limit_admin'];
168
        } else {
169
            $data['configblog_limit_admin'] = $this->config->get('configblog_limit_admin');
170
        }
171
172
        if (isset($this->request->post['configblog_article_count'])) {
173
            $data['configblog_article_count'] = $this->request->post['configblog_article_count'];
174
        } else {
175
            $data['configblog_article_count'] = $this->config->get('configblog_article_count');
176
        }
177
        
178
        if (isset($this->request->post['configblog_blog_menu'])) {
179
            $data['configblog_blog_menu'] = $this->request->post['configblog_blog_menu'];
180
        } else {
181
            $data['configblog_blog_menu'] = $this->config->get('configblog_blog_menu');
182
        }
183
        
184
        if (isset($this->request->post['configblogarticle_download'])) {
185
            $data['configblog_article_download'] = $this->request->post['configblog_article_download'];
186
        } else {
187
            $data['configblog_article_download'] = $this->config->get('configblog_article_download');
188
        }
189
190
        if (isset($this->request->post['configblog_review_status'])) {
191
            $data['configblog_review_status'] = $this->request->post['configblog_review_status'];
192
        } else {
193
            $data['configblog_review_status'] = $this->config->get('configblog_review_status');
194
        }
195
196
        if (isset($this->request->post['configblog_review_guest'])) {
197
            $data['configblog_review_guest'] = $this->request->post['configblog_review_guest'];
198
        } else {
199
            $data['configblog_review_guest'] = $this->config->get('configblog_review_guest');
200
        }
201
202
        if (isset($this->request->post['configblog_review_mail'])) {
203
            $data['configblog_review_mail'] = $this->request->post['configblog_review_mail'];
204
        } else {
205
            $data['configblog_review_mail'] = $this->config->get('configblog_review_mail');
206
        }
207
208
        if (isset($this->request->post['configblog_image_category_width'])) {
209
            $data['configblog_image_category_width'] = $this->request->post['configblog_image_category_width'];
210
        } else {
211
            $data['configblog_image_category_width'] = $this->config->get('configblog_image_category_width');
212
        }
213
214
        if (isset($this->request->post['configblog_image_category_height'])) {
215
            $data['configblog_image_category_height'] = $this->request->post['configblog_image_category_height'];
216
        } else {
217
            $data['configblog_image_category_height'] = $this->config->get('configblog_image_category_height');
218
        }
219
220
        if (isset($this->request->post['configblog_image_article_width'])) {
221
            $data['configblog_image_article_width'] = $this->request->post['configblog_image_article_width'];
222
        } else {
223
            $data['configblog_image_article_width'] = $this->config->get('configblog_image_article_width');
224
        }
225
226
        if (isset($this->request->post['configblog_image_article_height'])) {
227
            $data['configblog_image_article_height'] = $this->request->post['configblog_image_article_height'];
228
        } else {
229
            $data['configblog_image_article_height'] = $this->config->get('configblog_image_article_height');
230
        }
231
232
        if (isset($this->request->post['configblog_image_related_width'])) {
233
            $data['configblog_image_related_width'] = $this->request->post['configblog_image_related_width'];
234
        } else {
235
            $data['configblog_image_related_width'] = $this->config->get('configblog_image_related_width');
236
        }
237
238
        if (isset($this->request->post['configblog_image_related_height'])) {
239
            $data['configblog_image_related_height'] = $this->request->post['configblog_image_related_height'];
240
        } else {
241
            $data['configblog_image_related_height'] = $this->config->get('configblog_image_related_height');
242
        }
243
        
244
        if (isset($this->request->post['configblog_name'])) {
245
            $data['configblog_name'] = $this->request->post['configblog_name'];
246
        } else {
247
            $data['configblog_name'] = $this->config->get('configblog_name');
248
        }
249
        
250
        if (isset($this->request->post['configblog_html_h1'])) {
251
            $data['configblog_html_h1'] = $this->request->post['configblog_html_h1'];
252
        } else {
253
            $data['configblog_html_h1'] = $this->config->get('configblog_html_h1');
254
        }
255
        
256
        if (isset($this->request->post['configblog_meta_title'])) {
257
            $data['configblog_meta_title'] = $this->request->post['configblog_meta_title'];
258
        } else {
259
            $data['configblog_meta_title'] = $this->config->get('configblog_meta_title');
260
        }
261
262
        if (isset($this->request->post['configblog_meta_description'])) {
263
            $data['configblog_meta_description'] = $this->request->post['configblog_meta_description'];
264
        } else {
265
            $data['configblog_meta_description'] = $this->config->get('configblog_meta_description');
266
        }
267
268
        $data['header'] = $this->load->controller('common/header');
269
        $data['column'] = $this->load->controller('common/column_left');
270
        $data['footer'] = $this->load->controller('common/footer');
271
272
        $this->response->setOutput($this->load->view('blog/setting', $data));
273
    }
274
275
    protected function validate()
276
    {
277
        if (!$this->user->hasPermission('modify', 'setting/setting')) {
278
            $this->error['warning'] = $this->language->get('error_permission');
279
        }
280
281
        if (!$this->request->post['configblog_image_category_width'] || !$this->request->post['configblog_image_category_height']) {
282
            $this->error['image_category'] = $this->language->get('error_image_category');
283
        }
284
285
        if (!$this->request->post['configblog_image_article_width'] || !$this->request->post['configblog_image_article_height']) {
286
            $this->error['image_article'] = $this->language->get('error_image_article');
287
        }
288
289
        if (!$this->request->post['configblog_image_related_width'] || !$this->request->post['configblog_image_related_height']) {
290
            $this->error['image_related'] = $this->language->get('error_image_related');
291
        }
292
293
        if (!$this->request->post['configblog_article_limit']) {
294
            $this->error['article_limit'] = $this->language->get('error_limit');
295
        }
296
297
        if (!$this->request->post['configblog_article_description_length']) {
298
            $this->error['article_description_length'] = $this->language->get('error_limit');
299
        }
300
301
        if (!$this->request->post['configblog_limit_admin']) {
302
            $this->error['limit_admin'] = $this->language->get('error_limit');
303
        }
304
305
        if ($this->error && !isset($this->error['warning'])) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->error of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
306
            $this->error['warning'] = $this->language->get('error_warning');
307
        }
308
309
        return !$this->error;
310
    }
311
}
312