oct_blogarticle.php
21.4 KB
1
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
<?php
/**
* @copyright OCTemplates
* @support https://octemplates.net/
* @license LICENSE.txt
*/
class ControllerOCTemplatesBlogOCTBlogArticle extends Controller {
private $error = [];
public function index() {
if (!$this->config->get('oct_blogsettings_status')) {
$this->response->redirect($this->url->link('common/home', '', true));
}
$oct_deals_data = $this->config->get('theme_oct_deals_data');
if ($this->registry->has('oct_mobiledetect')) {
if ($this->oct_mobiledetect->isMobile() && !$this->oct_mobiledetect->isTablet()) {
$data['oct_isMobile'] = $this->oct_mobiledetect->isMobile();
}
if ($this->oct_mobiledetect->isTablet()) {
$data['oct_isTablet'] = $this->oct_mobiledetect->isTablet();
}
}
$oct_blogsettings_data = $this->config->get('oct_blogsettings_data');
$this->load->language('octemplates/blog/oct_blogarticle');
$data['breadcrumbs'] = [];
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home')
];
$this->load->model('octemplates/blog/oct_blogcategory');
if (isset($this->request->get['blog_path'])) {
$path = '';
$parts = explode('_', (string)$this->request->get['blog_path']);
$blogcategory_id = (int)array_pop($parts);
foreach ($parts as $path_id) {
if (!$path) {
$path = $path_id;
} else {
$path .= '_' . $path_id;
}
$category_info = $this->model_octemplates_blog_oct_blogcategory->getBlogCategory($path_id);
if ($category_info) {
$data['breadcrumbs'][] = [
'text' => $category_info['name'],
'href' => $this->url->link('octemplates/blog/oct_blogcategory', 'blog_path=' . $path)
];
}
}
// Set the last category breadcrumb
$category_info = $this->model_octemplates_blog_oct_blogcategory->getBlogCategory($blogcategory_id);
if ($category_info) {
$url = '';
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = [
'text' => $category_info['name'],
'href' => $this->url->link('octemplates/blog/oct_blogcategory', 'blog_path=' . $this->request->get['blog_path'] . $url)
];
}
}
if (isset($this->request->get['search']) || isset($this->request->get['tag'])) {
$url = '';
if (isset($this->request->get['search'])) {
$url .= '&search=' . $this->request->get['search'];
}
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . $this->request->get['tag'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
}
if (isset($this->request->get['blogarticle_id'])) {
$blogarticle_id = (int)$this->request->get['blogarticle_id'];
} else {
$blogarticle_id = 0;
}
$this->load->model('octemplates/blog/oct_blogarticle');
$article_info = $this->model_octemplates_blog_oct_blogarticle->getArticle($blogarticle_id);
if ($article_info) {
$url = '';
if (isset($this->request->get['blog_path'])) {
$url .= '&blog_path=' . $this->request->get['blog_path'];
}
if (isset($this->request->get['search'])) {
$url .= '&search=' . $this->request->get['search'];
}
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . $this->request->get['tag'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = [
'text' => $article_info['name'],
'href' => $this->url->link('octemplates/blog/oct_blogarticle', $url . '&blogarticle_id=' . $this->request->get['blogarticle_id'])
];
$this->document->setTitle($article_info['meta_title']);
$this->document->setDescription($article_info['meta_description']);
$this->document->setKeywords($article_info['meta_keyword']);
$this->document->addLink($this->url->link('octemplates/blog/oct_blogarticle', 'blogarticle_id=' . $this->request->get['blogarticle_id']), 'canonical');
$data['heading_title'] = $article_info['name'];
$this->load->model('catalog/review');
$data['blogarticle_id'] = (int)$this->request->get['blogarticle_id'];
$data['description'] = str_replace("<img", "<img class='img-fluid'", html_entity_decode($article_info['description'], ENT_QUOTES, 'UTF-8'));
$data['date_added'] = $this->load->controller('octemplates/main/oct_functions/OctDateTime', array($article_info['date_added'], 1));
$this->load->model('tool/image');
if ($article_info['image'] && (isset($oct_blogsettings_data['show_main_image']) && $oct_blogsettings_data['show_main_image'])) {
$data['thumb'] = $this->model_tool_image->resize($article_info['image'], $oct_blogsettings_data['article_width'], $oct_blogsettings_data['article_height']);
} else {
$data['thumb'] = '';
}
$data['thumb_width'] = $oct_blogsettings_data['article_width'];
$data['thumb_height'] = $oct_blogsettings_data['article_height'];
if (isset($oct_deals_data['preload_images']) && $oct_deals_data['preload_images'] && !empty($data['thumb'])) {
$this->document->setOCTPreload($data['thumb']);
}
$data['images'] = [];
$results = $this->model_octemplates_blog_oct_blogarticle->getArticleImages($this->request->get['blogarticle_id']);
foreach ($results as $result) {
if (isset($result['image']) && !empty($result['image']) && $result['image'] && file_exists(DIR_IMAGE . $result['image'])) {
$data['images'][] = [
'thumb' => $this->model_tool_image->resize($result['image'], $oct_blogsettings_data['article_dop_width'], $oct_blogsettings_data['article_dop_height']),
'thumb_width' => $oct_blogsettings_data['article_dop_width'],
'thumb_height' => $oct_blogsettings_data['article_dop_height'],
'popup' => $this->model_tool_image->resize($result['image'], $oct_blogsettings_data['article_width'], $oct_blogsettings_data['article_height']),
'popup_width' => $oct_blogsettings_data['article_width'],
'popup_height' => $oct_blogsettings_data['article_height'],
];
}
}
if (!empty($data['images'])) {
$this->document->addScript('catalog/view/theme/oct_deals/js/fancybox/jquery.fancybox.min.js');
$this->document->addStyle('catalog/view/theme/oct_deals/js/fancybox/jquery.fancybox.min.css');
}
$data['review_status'] = false;
if (isset($oct_blogsettings_data['comments']) && $oct_blogsettings_data['comments'] == 'on') {
$review_status = $this->config->get('config_review_status');
if ($this->config->get('config_review_guest') || $this->customer->isLogged()) {
$review_guest = true;
} else {
$review_guest = false;
}
if ($review_status && $review_guest) {
$data['review_status'] = true;
}
}
if ($this->customer->isLogged()) {
$data['customer_name'] = $this->customer->getFirstName() . ' ' . $this->customer->getLastName();
} else {
$data['customer_name'] = '';
}
$data['comments_total'] = sprintf($this->language->get('text_reviews'), (int)$article_info['comments_total']);
$data['comments_viewed'] = sprintf($this->language->get('text_viewed'), (int)$article_info['viewed']);
// Captcha
if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('review', (array)$this->config->get('config_captcha_page'))) {
$data['captcha'] = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha'));
} else {
$data['captcha'] = '';
}
$data['articles'] = [];
$artusle_results = $this->model_octemplates_blog_oct_blogarticle->getArticleRelated($this->request->get['blogarticle_id']);
foreach ($artusle_results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $oct_blogsettings_data['dop_article_width'], $oct_blogsettings_data['dop_article_height']);
} else {
$image = $this->model_tool_image->resize('placeholder.png', $oct_blogsettings_data['dop_article_width'], $oct_blogsettings_data['dop_article_height']);
}
// Get categories
$blog_category_badge = $this->model_octemplates_blog_oct_blogcategory->getBlogCategoryBadges($result['blogarticle_id']);
$description = !empty(trim(strip_tags($result['shot_description']))) ? $result['shot_description'] : $result['description'];
$data['articles'][] = [
'blogarticle_id' => $result['blogarticle_id'],
'thumb' => $image,
'width' => $oct_blogsettings_data['dop_article_width'],
'height' => $oct_blogsettings_data['dop_article_height'],
'name' => $result['name'],
'blog_categories' => $blog_category_badge,
'description' => utf8_substr(trim(strip_tags(html_entity_decode($description, ENT_QUOTES, 'UTF-8'))), 0, $oct_blogsettings_data['description_length']) . '..',
'date_added' => $this->load->controller('octemplates/main/oct_functions/OctDateTime', array($result['date_added'], 0)),
'href' => $this->url->link('octemplates/blog/oct_blogarticle', 'blogarticle_id=' . $result['blogarticle_id'])
];
}
$data['oct_popup_view_status'] = $this->config->get('oct_popup_view_status');
$data['products'] = [];
$product_results = $this->model_octemplates_blog_oct_blogarticle->getArticleRelatedProduct($this->request->get['blogarticle_id']);
$oct_product_stickers = [];
if ($this->config->get('oct_stickers_status')) {
$oct_stickers = $this->config->get('oct_stickers_data');
$data['oct_sticker_you_save'] = false;
if ($oct_stickers) {
$data['oct_sticker_you_save'] = isset($oct_stickers['stickers']['special']['persent']) ? true : false;
}
$this->load->model('octemplates/stickers/oct_stickers');
}
foreach ($product_results as $result) {
if (isset($oct_stickers) && $oct_stickers) {
$oct_stickers_data = $this->model_octemplates_stickers_oct_stickers->getOCTStickers($result);
$oct_product_stickers = [];
if ($oct_stickers_data) {
$oct_product_stickers = $oct_stickers_data['stickers'];
}
}
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $oct_blogsettings_data['product_width'], $oct_blogsettings_data['product_height']);
} else {
$image = $this->model_tool_image->resize('placeholder.png', $oct_blogsettings_data['product_width'], $oct_blogsettings_data['product_height']);
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
} else {
$tax = false;
}
if ($this->config->get('config_review_status')) {
$rating = (int)$result['rating'];
} else {
$rating = false;
}
if ($result['quantity'] <= 0) {
$stock = $result['stock_status'];
} else {
$stock = false;
}
$can_buy = true;
if ($result['quantity'] <= 0 && !$this->config->get('config_stock_checkout')) {
$can_buy = false;
} elseif ($result['quantity'] <= 0 && $this->config->get('config_stock_checkout')) {
$can_buy = true;
}
$oct_grayscale = ($this->config->get('theme_oct_deals_no_quantity_grayscale') && !$can_buy) ? true : false;
$oct_atributes = false;
$data['products'][] = [
'product_id' => $result['product_id'],
'thumb' => $image,
'width' => $oct_blogsettings_data['product_width'],
'height' => $oct_blogsettings_data['product_height'],
'name' => $result['name'],
'oct_model' => $this->config->get('theme_oct_deals_data_model') ? $result['model'] : '',
'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config->get('config_theme') . '_product_description_length')) . '..',
'price' => $price,
'special' => $special,
'stock' => $stock,
'can_buy' => $can_buy,
'oct_grayscale' => $oct_grayscale,
'oct_atributes' => $oct_atributes,
'oct_stickers' => $oct_product_stickers,
'you_save' => $result['you_save'],
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'rating' => $rating,
'reviews' => $result['reviews'],
'quantity' => $result['quantity'] <= 0 ? true : false,
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']),
'quantity_show' => $can_buy ? 1 : 0
];
}
$data['products'] = $this->load->controller('octemplates/module/oct_products_modules', $data);
$data['tags'] = [];
if ($article_info['tag']) {
$tags = explode(',', $article_info['tag']);
foreach ($tags as $tag) {
$data['tags'][] = [
'tag' => trim($tag),
'href' => $this->url->link('octemplates/blog/oct_blogsearch', 'tag=' . trim($tag))
];
}
}
if (isset($oct_deals_data['open_graph']) && $oct_deals_data['open_graph']) {
$site_link = $this->request->server['HTTPS'] ? HTTPS_SERVER : HTTP_SERVER;
$config_logo = file_exists(DIR_IMAGE . $this->config->get('config_logo')) ? $this->config->get('config_logo') : 'catalog/opencart-logo.png';
$oct_ogimage = $article_info['image'] ? $article_info['image'] : $config_logo;
$blog_article_image = $site_link . 'image/' . $oct_ogimage;
$image_info = getimagesize(DIR_IMAGE . $oct_ogimage);
$image_width = $image_info[0];
$image_height = $image_info[1];
$mime_type = isset($image_info['mime']) ? $image_info['mime'] : '';
$this->document->setOCTOpenGraph('og:title', htmlspecialchars(strip_tags(str_replace("\r", " ", str_replace("\n", " ", str_replace("\\", "/", str_replace("\"", "", (isset($oct_seo_title) && $oct_seo_title) ? $oct_seo_title : $article_info['meta_title'])))))));
$this->document->setOCTOpenGraph('og:description', htmlspecialchars(strip_tags(str_replace("\r", " ", str_replace("\n", " ", str_replace("\\", "/", str_replace("\"", "", (isset($oct_seo_description) && $oct_seo_description && empty($article_info['meta_description'])) ? $oct_seo_description : $article_info['meta_description'])))))));
$this->document->setOCTOpenGraph('og:site_name', htmlspecialchars(strip_tags(str_replace("\r", " ", str_replace("\n", " ", str_replace("\\", "/", str_replace("\"", "", $this->config->get('config_name'))))))));
$this->document->setOCTOpenGraph('og:url', $this->url->link('octemplates/blog/oct_blogarticle', 'blogarticle_id=' . $this->request->get['blogarticle_id']));
$this->document->setOCTOpenGraph('og:image', str_replace(" ", "%20", $blog_article_image));
if (isset($mime_type) && $mime_type) {
$this->document->setOCTOpenGraph('og:image:type', $mime_type);
}
if (isset($image_width) && $image_width) {
$this->document->setOCTOpenGraph('og:image:width', $image_width);
}
if (isset($image_height) && $image_height) {
$this->document->setOCTOpenGraph('og:image:height', $image_height);
}
$this->document->setOCTOpenGraph('og:image:alt', htmlspecialchars(strip_tags(str_replace("\r", " ", str_replace("\n", " ", str_replace("\\", "/", str_replace("\"", "", $data['heading_title'])))))));
$this->document->setOCTOpenGraph('og:type', 'article');
}
$this->model_octemplates_blog_oct_blogarticle->updateViewed($this->request->get['blogarticle_id']);
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$oct_data['breadcrumbs'] = $data['breadcrumbs'];
$data['oct_breadcrumbs'] = $this->load->controller('octemplates/main/oct_functions/octBreadcrumbs', $oct_data);
$this->response->setOutput($this->load->view('octemplates/blog/oct_blogarticle', $data));
} else {
$url = '';
if (isset($this->request->get['blog_path'])) {
$url .= '&blog_path=' . $this->request->get['blog_path'];
}
if (isset($this->request->get['search'])) {
$url .= '&search=' . $this->request->get['search'];
}
if (isset($this->request->get['tag'])) {
$url .= '&tag=' . $this->request->get['tag'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['limit'])) {
$url .= '&limit=' . $this->request->get['limit'];
}
$data['breadcrumbs'][] = [
'text' => $this->language->get('text_error'),
'href' => $this->url->link('octemplates/blog/oct_blogarticle', $url . '&blogarticle_id=' . $blogarticle_id)
];
$this->document->setTitle($this->language->get('text_error'));
$data['continue'] = $this->url->link('common/home');
$this->response->addHeader($this->request->server['SERVER_PROTOCOL'] . ' 404 Not Found');
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$oct_data['breadcrumbs'] = $data['breadcrumbs'];
$data['oct_breadcrumbs'] = $this->load->controller('octemplates/main/oct_functions/octBreadcrumbs', $oct_data);
$this->response->setOutput($this->load->view('error/not_found', $data));
}
}
public function comment() {
$this->load->language('octemplates/blog/oct_blogarticle');
$this->load->model('octemplates/blog/oct_blogcomment');
if (isset($this->request->get['page'])) {
$page = (int)$this->request->get['page'];
} else {
$page = 1;
}
$data['comments'] = [];
$review_total = $this->model_octemplates_blog_oct_blogcomment->getTotalCommentsByArticleId($this->request->get['blogarticle_id']);
$results = $this->model_octemplates_blog_oct_blogcomment->getCommentsByArticleId($this->request->get['blogarticle_id'], ($page - 1) * 5, 5);
foreach ($results as $result) {
$data['comments'][] = [
'author' => $result['author'],
'text' => nl2br($result['text']),
'admin_text' => nl2br($result['admin_text']),
'date_added' => $this->load->controller('octemplates/main/oct_functions/OctDateTime', array($result['date_added'], 1))
];
}
$pagination = new Pagination();
$pagination->total = $review_total;
$pagination->page = $page;
$pagination->limit = 5;
$pagination->url = $this->url->link('octemplates/blog/oct_blogarticle/comment', 'blogarticle_id=' . $this->request->get['blogarticle_id'] . '&page={page}');
$data['pagination'] = $pagination->render();
$data['results'] = sprintf($this->language->get('text_pagination'), ($review_total) ? (($page - 1) * 5) + 1 : 0, ((($page - 1) * 5) > ($review_total - 5)) ? $review_total : ((($page - 1) * 5) + 5), $review_total, ceil($review_total / 5));
$this->response->setOutput($this->load->view('octemplates/blog/oct_blogcomment', $data));
}
public function write() {
$this->load->language('octemplates/blog/oct_blogarticle');
$json = [];
if ($this->request->server['REQUEST_METHOD'] == 'POST') {
if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 25)) {
$json['error']['name'] = $this->language->get('error_name');
}
if ((utf8_strlen($this->request->post['text']) < 25) || (utf8_strlen($this->request->post['text']) > 1000)) {
$json['error']['text'] = $this->language->get('error_text');
}
// Captcha
if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('review', (array)$this->config->get('config_captcha_page'))) {
$captcha = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha') . '/validate');
if ($captcha) {
$json['error']['captcha'] = $captcha;
}
}
if (!isset($json['error'])) {
$this->load->model('octemplates/blog/oct_blogcomment');
$this->model_octemplates_blog_oct_blogcomment->addComment($this->request->get['blogarticle_id'], $this->request->post);
$json['success'] = $this->language->get('text_success');
}
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}