1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Modules\CallHome; |
3
|
|
|
|
4
|
|
|
use Redaxscript\Filter; |
5
|
|
|
use Redaxscript\Head; |
6
|
|
|
use Redaxscript\Module; |
7
|
|
|
use Redaxscript\Reader; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* provide version updates and news |
11
|
|
|
* |
12
|
|
|
* @since 2.2.0 |
13
|
|
|
* |
14
|
|
|
* @package Redaxscript |
15
|
|
|
* @category Modules |
16
|
|
|
* @author Henry Ruhs |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
class CallHome extends Module\Metadata |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* array of the module |
23
|
|
|
* |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
protected static $_moduleArray = |
28
|
|
|
[ |
29
|
|
|
'name' => 'Call Home', |
30
|
|
|
'alias' => 'CallHome', |
31
|
|
|
'author' => 'Redaxmedia', |
32
|
|
|
'description' => 'Provide version updates and news', |
33
|
|
|
'version' => '4.3.0' |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* renderStart |
38
|
|
|
* |
39
|
|
|
* @since 3.0.0 |
40
|
|
|
*/ |
41
|
|
|
|
42
|
|
|
public function renderStart() : void |
43
|
|
|
{ |
44
|
|
|
if ($this->_registry->get('loggedIn') === $this->_registry->get('token') && $this->_registry->get('firstParameter') === 'admin') |
45
|
|
|
{ |
46
|
|
|
$script = Head\Script::getInstance(); |
47
|
|
|
$script |
48
|
|
|
->init('foot') |
49
|
|
|
->appendFile( |
50
|
|
|
[ |
51
|
|
|
'https://google-analytics.com/analytics.js', |
52
|
|
|
'modules/CallHome/assets/scripts/init.js', |
53
|
|
|
'modules/CallHome/dist/scripts/call-home.min.js' |
54
|
|
|
]); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* adminNotification |
60
|
|
|
* |
61
|
|
|
* @since 4.3.0 |
62
|
|
|
* |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
|
|
|
66
|
|
|
public function adminNotification() : array |
67
|
|
|
{ |
68
|
|
|
$reader = new Reader(); |
69
|
|
|
$reader->init( |
70
|
|
|
[ |
71
|
|
|
'curl' => |
72
|
|
|
[ |
73
|
|
|
CURLOPT_TIMEOUT_MS => 500 |
74
|
|
|
] |
75
|
|
|
]); |
76
|
|
|
$aliasFilter = new Filter\Alias(); |
77
|
|
|
$version = $aliasFilter->sanitize($this->_language->get('_package')['version']); |
78
|
|
|
|
79
|
|
|
/* load result */ |
80
|
|
|
|
81
|
|
|
$urlVersion = 'https://service.redaxscript.com/version/' . $version; |
82
|
|
|
$urlNews = 'https://service.redaxscript.com/news/' . $version; |
83
|
|
|
$versionArray = $reader->loadJSON($urlVersion)->getArray(); |
84
|
|
|
$newsArray = $reader->loadJSON($urlNews)->getArray(); |
85
|
|
|
|
86
|
|
|
/* process version */ |
87
|
|
|
|
88
|
|
|
foreach ($versionArray as $version) |
|
|
|
|
89
|
|
|
{ |
90
|
|
|
foreach ($version as $type => $message) |
91
|
|
|
{ |
92
|
|
|
$this->setNotification($type, $message); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/* process news */ |
97
|
|
|
|
98
|
|
|
foreach ($newsArray as $news) |
|
|
|
|
99
|
|
|
{ |
100
|
|
|
foreach ($news as $type => $message) |
101
|
|
|
{ |
102
|
|
|
$this->setNotification($type, $message); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
return $this->getNotificationArray(); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.