Skip to content

Commit 4781a40

Browse files
committed
QA: Make some simplification of callbacks and redirects
* This should make the code a bit more readable.
1 parent 7acbe9d commit 4781a40

File tree

4 files changed

+31
-48
lines changed

4 files changed

+31
-48
lines changed

display.php

+3-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
function display_information() {
28-
global $config, $sql_where, $login_opts, $panels, $registry, $trend_timespans;
28+
global $config, $sql_where, $callbackPage, $redirectPage, $panels, $registry, $trend_timespans;
2929

3030
include_once($config['base_path'] . '/plugins/intropage/include/functions.php');
3131
include_once($config['base_path'] . '/plugins/intropage/include/database.php');
@@ -225,10 +225,7 @@ function display_information() {
225225
if (cacti_sizeof($dashboards)) {
226226
foreach ($dashboards as $dbid => $db_name) {
227227
print "<li><a class='tab pic" . ($dbid == $dashboard_id ? " selected'" : "'") .
228-
" href='" . html_escape($config['url_path'] .
229-
($login_opts == 4 ? 'plugins/intropage/intropage.php?':'index.php?') .
230-
'dashboard_id=' . $dbid . '&header=false') .
231-
"'>" . html_escape($db_name) . '</a></li>';
228+
" href='" . html_escape("$redirectPage?dashboard_id=$dbid&header=false") . "'>" . html_escape($db_name) . '</a></li>';
232229
}
233230
}
234231

@@ -246,7 +243,7 @@ function display_information() {
246243
print "<a href='#' class='pic' id='switch_copytext' title='" . __esc('Disable panel move/enable copy text from panel', 'intropage') . "'><i class='intro_glyph fa fa-clone'></i></a>";
247244
print '&nbsp; &nbsp; ';
248245

249-
print '<a class="pic" href="' . html_escape($config['url_path'] . ($login_opts == 4 ? 'plugins/intropage/intropage.php?':'index.php?') . 'action=configure') . '"><i class="intro_glyph fa fa-cog"></i></a>';
246+
print '<a class="pic" href="' . html_escape("$redirectPage?action=configure") . '"><i class="intro_glyph fa fa-cog"></i></a>';
250247
print '&nbsp; &nbsp; ';
251248

252249
intropage_addpanel_select($dashboard_id);

include/functions.php

+10-32
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ function intropage_action_settings() {
185185
}
186186

187187
function intropage_actions() {
188-
global $login_opts, $config;
188+
global $callbackPage, $redirectPage, $config;
189189

190190
$actionvar = get_filter_request_var('intropage_action', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-z0-9_-]+)$/')));
191191

@@ -243,11 +243,7 @@ function intropage_actions() {
243243

244244
raise_message('dashboard_removed', __('Dashboard has been removed', 'intropage'), MESSAGE_LEVEL_INFO);
245245

246-
if ($login_opts == 4) {
247-
header('Location: ' . html_escape($config['url_path']) . 'plugins/intropage/intropage.php?header=false&dashboard_id=' . $dashboard_id);
248-
} else {
249-
header('Location: ' . html_escape($config['url_path']) . 'index.php?header=false&dashboard_id=' . $dashboard_id);
250-
}
246+
header('Location: ' . html_escape("$redirectPage?header=false&dashboard_id=$dashboard_id"));
251247

252248
exit;
253249
}
@@ -267,11 +263,7 @@ function intropage_actions() {
267263

268264
raise_message('dashboard_added', __('Dashboard has been added', 'intropage'), MESSAGE_LEVEL_INFO);
269265

270-
if ($login_opts == 4) {
271-
header('Location: ' . html_escape($config['url_path']) . 'plugins/intropage/intropage.php?header=false&dashboard_id=' . $dashboard_id);
272-
} else {
273-
header('Location: ' . html_escape($config['url_path']) . 'index.php?header=false&dashboard_id=' . $dashboard_id);
274-
}
266+
header('Location: ' . html_escape("$recirectPage?header=false&dashboard_id=$dashboard_id"));
275267

276268
exit;
277269
}
@@ -492,11 +484,7 @@ function intropage_actions() {
492484

493485
raise_message('dashboard_added', __('Dashboard has been added, please wait few poller cycle for data', 'intropage'), MESSAGE_LEVEL_INFO);
494486

495-
if ($login_opts == 4) {
496-
header('Location: ' . html_escape($config['url_path']) . 'plugins/intropage/intropage.php?header=false&dashboard_id=' . $new_dashboard_id);
497-
} else {
498-
header('Location: ' . html_escape($config['url_path']) . 'index.php?header=false&dashboard_id=' . $new_dashboard_id);
499-
}
487+
header('Location: ' . html_escape("$redirectPage?header=false&dashboard_id=$new_dashboard_id"));
500488

501489
exit;
502490

@@ -509,7 +497,7 @@ function intropage_actions() {
509497
}
510498

511499
function intropage_actions_timespan() {
512-
global $login_opts, $config;
500+
global $config;
513501

514502
$actionvar = get_filter_request_var('intropage_action_timespan', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^([a-z0-9_-]+)$/')));
515503

@@ -1706,7 +1694,7 @@ function ntp_time($host) {
17061694
return ($timestamp);
17071695
}
17081696
function intropage_graph_button($data) {
1709-
global $config, $login_opts;
1697+
global $config, $callbackPage, $redirectPage;
17101698

17111699
if (is_panel_allowed('favourite_graph')) {
17121700
$local_graph_id = $data[1]['local_graph_id'];
@@ -1732,11 +1720,7 @@ function intropage_graph_button($data) {
17321720
}
17331721
}
17341722

1735-
if ($login_opts == 4) {
1736-
print '<a class="iconLink" href="' . html_escape($config['url_path']) . 'plugins/intropage/intropage.php?intropage_action=favgraph&graph_id=' . $local_graph_id . '">' . $fav . '</a><br/>';
1737-
} else {
1738-
print '<a class="iconLink" href="' . html_escape($config['url_path']) . 'index.php?intropage_action=favgraph&graph_id=' . $local_graph_id . '">' . $fav . '</a><br/>';
1739-
}
1723+
print '<a class="iconLink" href="' . html_escape("$redirectPage?intropage_action=favgraph&graph_id=$local_graph_id") . '">' . $fav . '</a><br/>';
17401724
}
17411725
}
17421726

@@ -1763,7 +1747,7 @@ function get_login_opts($refresh = false) {
17631747
}
17641748

17651749
function intropage_configure_panel() {
1766-
global $config, $login_opts, $trend_timespans, $intropage_intervals;
1750+
global $config, $callbackPage, $redirectPage, $trend_timespans, $intropage_intervals;
17671751

17681752
$dashboards = array_rekey(
17691753
db_fetch_assoc_prepared('SELECT dashboard_id, name
@@ -1776,13 +1760,7 @@ function intropage_configure_panel() {
17761760

17771761
print '<div>';
17781762

1779-
if ($login_opts == 4) {
1780-
$pageName = $config['url_path'] . 'plugins/intropage/intropage.php';
1781-
} else {
1782-
$pageName = 'index.php';
1783-
}
1784-
1785-
form_start($pageName);
1763+
form_start($callbackPage);
17861764

17871765
html_start_box(__('Dashboard Names', 'intropage'), '100%', '', '3', 'center', '');
17881766

@@ -1949,7 +1927,7 @@ function intropage_configure_panel() {
19491927

19501928
form_hidden_box('save_settings', 0, 1);
19511929

1952-
form_save_button($pageName, 'save');
1930+
form_save_button($callbackPage, 'save');
19531931

19541932
form_end();
19551933

include/intropage.js

+10-9
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ $(function() {
3535
resizeCharts();
3636
}).trigger('orientationchange');
3737

38+
callbackPage = urlPath + 'plugins/intropage/intropage.php';
3839
if (pageName == 'index.php') {
39-
intropage_page = urlPath + pageName;
40+
redirectPage = urlPath + pageName;
4041
} else {
41-
intropage_page = urlPath + 'plugins/intropage/intropage.php';
42+
redirectPage = urlPath + 'plugins/intropage/intropage.php';
4243
}
4344

4445
initPage();
@@ -109,9 +110,9 @@ function addPanel() {
109110
};
110111

111112
if (typeof postUrl == 'function') {
112-
postUrl({ url: intropage_page }, post);
113+
postUrl({ url: callbackPage }, post);
113114
} else {
114-
$.post(intropage_page, post).done(function(data) {
115+
$.post(callbackPage, post).done(function(data) {
115116
$('#main').html(data);
116117
applySkin();
117118
initPage();
@@ -135,9 +136,9 @@ function actionPanel() {
135136
};
136137

137138
if (typeof postUrl == 'function') {
138-
postUrl({ url: intropage_page }, post);
139+
postUrl({ url: callbackPage }, post);
139140
} else {
140-
$.post(intropage_page, post).done(function(data) {
141+
$.post(callbackPage, post).done(function(data) {
141142
$('#main').html(data);
142143
applySkin();
143144
initPage();
@@ -162,9 +163,9 @@ function timeSpan() {
162163
};
163164

164165
if (typeof postUrl == 'function') {
165-
postUrl({ url: intropage_page }, post);
166+
postUrl({ url: callbackPage }, post);
166167
} else {
167-
$.post(intropage_page, post).done(function(data) {
168+
$.post(callbackPage, post).done(function(data) {
168169
$('#main').html(data);
169170
applySkin();
170171
initPage();
@@ -275,7 +276,7 @@ function initPage() {
275276
xdata.push($(this).attr('id'));
276277
});
277278

278-
$.get(intropage_page, { xdata:xdata, intropage_action:'order' });
279+
$.get(callbackPage, { xdata:xdata, intropage_action:'order' });
279280
}
280281
});
281282

intropage.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,17 @@
3030
include_once($config['base_path'] . '/plugins/intropage/include/functions.php');
3131
include_once($config['base_path'] . '/plugins/intropage/display.php');
3232

33-
global $panels, $registry, $login_opts;
33+
global $panels, $registry, $login_opts, $callbackPage, $redirectPage;
3434

3535
$login_opts = get_login_opts(true);
3636

37+
$callbackPage = $config['url_path'] . 'plugins/intropage/intropage.php';
38+
if ($login_opts == 4) {
39+
$redirectPage = $config['url_path'] . 'plugins/intropage/intropage.php';
40+
} else {
41+
$redirectPage = 'index.php';
42+
}
43+
3744
$panels = initialize_panel_library();
3845

3946
process_page_request_variables();

0 commit comments

Comments
 (0)