Completed
Branchmaster (dec762)
created

CallHome::renderStart()   A

↳ Parent: CallHome

Complexity

Conditions 3
Paths 2

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 12
Code Lines 8

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 2
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Redaxscript\Modules\CallHome;
3
4
use Redaxscript\Filter;
5
use Redaxscript\Head;
6
use Redaxscript\Language;
7
use Redaxscript\Module;
8
use Redaxscript\Reader;
9
use Redaxscript\Registry;
10
11
/**
12
 * provide version and news updates
13
 *
14
 * @since 2.2.0
15
 *
16
 * @package Redaxscript
17
 * @category Modules
18
 * @author Henry Ruhs
19
 */
20
21
class CallHome extends Module
22
{
23
	/**
24
	 * array of the module
25
	 *
26
	 * @var array
27
	 */
28
29
	protected static $_moduleArray =
30
	[
31
		'name' => 'Call home',
32
		'alias' => 'CallHome',
33
		'author' => 'Redaxmedia',
34
		'description' => 'Provide version and news updates',
35
		'version' => '3.0.0'
36
	];
37
38
	/**
39
	 * renderStart
40
	 *
41
	 * @since 3.0.0
42
	 */
43
44
	public static function renderStart()
45
	{
46
		if (Registry::get('loggedIn') === Registry::get('token') && Registry::get('firstParameter') === 'admin')
47
		{
48
			$script = Head\Script::getInstance();
49
			$script
50
				->init('foot')
51
				->appendFile('//google-analytics.com/analytics.js')
52
				->appendFile('modules/CallHome/assets/scripts/init.js')
53
				->appendFile('modules/CallHome/assets/scripts/call_home.js');
54
		}
55
	}
56
57
	/**
58
	 * adminPanelNotification
59
	 *
60
	 * @since 3.0.0
61
	 *
62
	 * @return array
63
	 */
64
65
	public static function adminPanelNotification()
66
	{
67
		$output = [];
68
		$reader = new Reader();
69
		$aliasFilter = new Filter\Alias();
70
		$version = $aliasFilter->sanitize(Language::get('version', '_package'));
71
72
		/* load result */
73
74
		$urlVersion = 'http://service.redaxscript.com/version/' . $version;
75
		$urlNews = 'http://service.redaxscript.com/news/' . $version;
76
		$resultVersion = $reader->loadJSON($urlVersion)->getArray();
77
		$resultNews = $reader->loadJSON($urlNews)->getArray();
78
79
		/* merge as needed */
80
81
		if (is_array($resultVersion))
82
		{
83
			$output = array_merge_recursive($output, $resultVersion);
84
		}
85
		if (is_array($resultNews))
86
		{
87
			$output = array_merge_recursive($output, $resultNews);
88
		}
89
		return $output;
90
	}
91
}
92