-
Notifications
You must be signed in to change notification settings - Fork 0
/
ukmdashboard.php
260 lines (224 loc) · 6.76 KB
/
ukmdashboard.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
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
<?php
/*
Plugin Name: UKM Dashboard
Plugin URI: http://www.ukm-norge.no
Description: Modifiserer Wordpress admin index for å inkludere eget WP-dashboard
Author: UKM Norge / M Mandal
Version: 2.0
Author URI: http://mariusmandal.no
*/
use UKMNorge\Wordpress\Modul;
require_once('UKM/Autoloader.php');
class UKMwp_dashboard extends Modul
{
public static $action = 'dashboard';
public static $path_plugin = null;
public static function hook()
{
add_action('admin_init', ['UKMwp_dashboard', 'admin_init']);
add_action('admin_enqueue_scripts', ['UKMwp_dashboard', 'scripts_and_styles']);
add_action('user_admin_menu', ['UKMwp_dashboard', 'meny']);
}
/**
* Sjekker om dashboard er aktivert, eller om wordpress er oppdatert siden
* sist override, og dermed krever en ny modifisering av wp-admin/index.php
*
* @return void
*/
public static function admin_init()
{
global $wp_version;
$wpdash_version = get_site_option('ukmwp_dash_version');
// If WP is updated, rewrite wp-admin/index.php
if ($wp_version != $wpdash_version) {
static::doUpdateIndexFile();
}
}
/**
* Legg til menyelementer
*
* @return void
*/
public static function meny()
{
$support = add_submenu_page(
'index.php',
'Brukerstøtte',
'Brukerstøtte',
'subscriber',
'UKMwpd_support',
['UKMwp_dashboard', 'renderSupport']
);
add_action(
'admin_print_styles-' . $support,
['UKMwp_dashboard', 'support_scripts_and_styles']
);
}
/**
* Render brukerstøtte-siden
*
* @return void
*/
public static function renderSupport()
{
static::include('controller/support.controller.php');
}
/**
* Script og styles for support-siden (kontakt)
*
* @return void
*/
public static function support_scripts_and_styles()
{
wp_enqueue_style(
'UKMwp_dashboard_css',
static::getPluginUrl() . 'css/UKMwp_dashboard.css'
);
wp_enqueue_script('WPbootstrap3_js');
wp_enqueue_style('WPbootstrap3_css');
}
/**
* Scripts og styles som trengs for de ulike dashboardene
*
* @return void
*/
public static function scripts_and_styles()
{
wp_register_style(
'UKMwp_dash_css',
static::getPluginUrl() . 'css/UKMwp_dash.css'
);
$screen = get_current_screen();
/**
* ALLE DASHBOARD
*/
if (in_array($screen->base, ['dashboard', 'dashboard-network', 'dashboard-user'])) {
wp_enqueue_style('UKMwp_dash_css');
wp_enqueue_style('UKMwp_innhold_style');
wp_enqueue_script('WPbootstrap3_js');
wp_enqueue_style('WPbootstrap3_css');
/**
* STANDARD-DASHBOARD
*/
if ($screen->base == 'dashboard') {
wp_enqueue_style(
'UKMwp_dashboard_css',
static::getPluginUrl() . 'css/UKMwp_dashboard.css'
);
wp_enqueue_script(
'GOOGLEchart',
'https://www.google.com/jsapi'
);
wp_enqueue_script('jquery');
wp_enqueue_script(
'jqueryGoogleUI',
'//ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js'
);
wp_enqueue_script(
'pushtofront',
static::getPluginUrl() . '/js/pushtofront.jquery.js'
);
wp_enqueue_script(
'blogvalg',
static::getPluginUrl() . '/js/blogvalg.jquery.js'
);
wp_enqueue_media();
wp_enqueue_style('UKMresources_tabs');
wp_enqueue_script(
'UKMWPdash_profil',
static::getPluginUrl() . '/js/profil.jquery.js'
);
}
/**
* NETTVERK-DASHBOARD
*/
if ($screen->base == 'dashboard-network') {
wp_enqueue_style(
'UKMwp_network_dashboard_css',
static::getPluginUrl() . 'css/UKMwp_network_dashboard.css'
);
wp_enqueue_script(
'UKMwp_network_dashboard_timagojs',
static::getPluginUrl() . 'js/timeago.jquery.js'
);
wp_enqueue_script(
'UKMwp_network_dashboard_fastlivefilterjs',
static::getPluginUrl() . 'js/fastlivefilter.jquery.js'
);
wp_enqueue_script(
'UKMwp_network_dashboard_js',
static::getPluginUrl() . 'js/wp_network_dashboard.js'
);
}
/**
* USER-DASHBOARD
*/
if ($screen->base == 'dashboard-user') {
wp_enqueue_style(
'UKMWPdash_tribute_css',
static::getPluginUrl() . '/css/tribute.css'
);
wp_enqueue_script(
'UKMWPdash_tribute_js',
static::getPluginUrl() . '/js/tribute.min.js'
);
}
}
}
/**
* Skriv over wp-admin/index.php med våre modifikasjoner
*
*/
// Will re-write wp-admin/index.php to use custom dashboard
public static function doUpdateIndexFile()
{
global $wp_version;
// UPDATE STANDARD DASHBOARD
$admind_path = ABSPATH . 'wp-admin/index.php';
$admind_content = file_get_contents($admind_path);
require_once(ABSPATH . 'wp-admin/includes/dashboard.php');
$admind_dash_orig = "ABSPATH . 'wp-admin/includes/dashboard.php'";
$admind_dash_ukm = "'" . plugin_dir_path(__FILE__) . 'wp_dashboard.php' . "'";
$admind_content = str_replace($admind_dash_orig, $admind_dash_ukm, $admind_content);
if (!is_writable($admind_path))
static::update_error('File not writeable');
$fp = fopen($admind_path, 'w');
if (!$fp)
static::update_error('File open denied');
if (!fwrite($fp, $admind_content))
static::update_error('File write error');
fclose($fp);
// UPDATE NETWORK DASHBOARD
$admind_path = ABSPATH . 'wp-admin/network/index.php';
$admind_content = file_get_contents($admind_path);
$admind_dash_orig = "ABSPATH . 'wp-admin/includes/dashboard.php'";
$admind_dash_ukm = "'" . plugin_dir_path(__FILE__) . 'wp_network_dashboard.php' . "'";
$admind_content = str_replace($admind_dash_orig, $admind_dash_ukm, $admind_content);
if (!is_writable($admind_path))
static::update_error('File not writeable');
$fp = fopen($admind_path, 'w');
if (!$fp)
static::update_error('File open denied');
if (!fwrite($fp, $admind_content))
static::update_error('File write error');
fclose($fp);
update_site_option('ukmwp_dash_version', $wp_version);
}
public static function update_error($source = 'ukjent')
{
require_once('UKM/mail.class.php');
$mail = new UKMmail();
->subject('WORDPRESS UPDATE ERROR!')
->text(
'<h3>Under oppdatering av wordpress feilet oppdateringen av index.php, '
. 'som medfører at UKM-dashboardet ikke lenger er tilgjengelig.</h3>'
. '<p style="font-weight:bold;color:#ff0000;">Dette må fikses ASAP!</p>'
. '<p><strong>Feilkilde: </strong>' . $source . '</p>'
. '<p><em>Funksjonalitet for dette ligger i UKMwp_dashboard.git, filen ukmdashboard.php</em></p>'
)
->ok();
}
}
UKMwp_dashboard::init( __DIR__ );
UKMwp_dashboard::hook();