1: <?php
2: namespace Opencart\Admin\Controller\Common;
3: /**
4: * Class Notification
5: *
6: * @package Opencart\Admin\Controller\Startup
7: */
8: class Notification extends \Opencart\System\Engine\Controller {
9: /**
10: * Index
11: *
12: * @return void
13: */
14: public function index(): void {
15: if (empty($this->request->cookie['notification'])) {
16: $curl = curl_init();
17:
18: // Gets the latest information from opencart.com about news, updates and security.
19: curl_setopt($curl, CURLOPT_URL, OPENCART_SERVER . 'index.php?route=api/notification');
20: curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
21: curl_setopt($curl, CURLOPT_HEADER, false);
22: curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
23: curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
24: curl_setopt($curl, CURLOPT_TIMEOUT, 30);
25:
26: $response = curl_exec($curl);
27:
28: curl_close($curl);
29:
30: if ($response) {
31: $notification = json_decode($response, true);
32: } else {
33: $notification = '';
34: }
35:
36: if (isset($notification['notification'])) {
37: $this->load->model('tool/notification');
38: foreach ($notification['notifications'] as $result) {
39: $notification_info = $this->model_tool_notification->addNotification($result['notification_id']);
40:
41: if (!$notification_info) {
42: $this->model_tool_notification->addNotification($result);
43: }
44: }
45: }
46:
47: // Only grab the
48: $option = [
49: 'expires' => time() + 3600 * 24 * 7,
50: 'path' => $this->config->get('session_path'),
51: 'secure' => $this->request->server['HTTPS'],
52: 'httponly' => false,
53: 'SameSite' => $this->config->get('config_session_samesite')
54: ];
55:
56: setcookie('notification', '1', $option);
57: }
58: }
59: }
60: