-
Notifications
You must be signed in to change notification settings - Fork 0
/
covidpress.php
70 lines (55 loc) · 2.04 KB
/
covidpress.php
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
<?php
/*
Plugin Name: COVIDPress
Plugin URI: https://github.com/gassius/covidpress
Description: Allow display current COVID-19 related information to your visitors, to help to stop the virus.
Version: 0.1.0
Author: Carlos González Rico
Author URI: https://github.com/gassius/
License: GPLv3
*/
namespace COVIDPress;
require_once(__DIR__.'/lib/DataSources/euodpCOVID19.php');
require_once(__DIR__.'/lib/DataSources/EMMNewsBrief.php');
use COVIDPress\DataSources\euodpCOVID19;
use COVIDPress\DataSources\EMMNewsBrief;
class COVIDPressPlugin {
protected $simplexmlAvailable = true;
public function __construct()
{
$this->simplexmlAvailable = extension_loaded('simplexml');
add_action('admin_menu', [ $this, 'initAdminSettings' ] );
add_action('wp_footer', array($this,'displayCOVIDpressAdvisor'), 11);
}
public function initAdminSettings() {
$settingsPage = add_options_page('COVIDPress', 'COVIDPress', 'manage_options', 'COVIDPressOptions', [$this,'displaySettingsPage']);
}
public function displaySettingsPage() {
include_once __DIR__ .'/includes/templates/settings.php';
}
public function displayCOVIDpressAdvisor() {
if ( is_admin() ) {
return;
}
$this->loadAdvisorIncludes();
include_once __DIR__ .'/includes/templates/advisor.php';
}
public function loadAdvisorIncludes() {
wp_enqueue_script('COVIDPressAdvisorScript', plugin_dir_url( __FILE__ ) . 'includes/js/covidpress.js', [], false, true );
wp_enqueue_style('COVIDPressAdvisorStyles', plugin_dir_url( __FILE__ ) . 'includes/styles/advisor.css', []);
}
public function getData() : Array
{
$euodpCOVID19 = new euodpCOVID19();
return $euodpCOVID19->getDataByContinent('Europe');
}
public function getNews() : Array
{
if($this->simplexmlAvailable) {
$EMMNewsBrief = new EMMNewsBrief('en');
return $EMMNewsBrief->getNews(3);
}
return [];
}
}
$COVIDPressPlugin = new COVIDPressPlugin();