Skip to content

Commit 2f29161

Browse files
refactor: extract plugin_get_rows_per_page helper to DRY filter boilerplate
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
1 parent 8727ab9 commit 2f29161

5 files changed

Lines changed: 27 additions & 40 deletions

File tree

notify_lists.php

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,11 +1047,7 @@ function hosts($header_label) {
10471047
// ================= input validation =================
10481048

10491049
// if the number of rows is -1, set it to the default
1050-
if (get_request_var('rows') == -1) {
1051-
$rows = read_config_option('num_rows_table');
1052-
} else {
1053-
$rows = get_request_var('rows');
1054-
}
1050+
$rows = plugin_get_rows_per_page();
10551051

10561052
html_start_box(__('Associated Devices', 'thold') . ' ' . html_escape($header_label), '100%', false, '3', 'center', '');
10571053

@@ -1375,11 +1371,7 @@ function tholds($header_label) {
13751371
}
13761372

13771373
// if the number of rows is -1, set it to the default
1378-
if (get_request_var('rows') == -1) {
1379-
$rows = read_config_option('num_rows_table');
1380-
} else {
1381-
$rows = get_request_var('rows');
1382-
}
1374+
$rows = plugin_get_rows_per_page();
13831375

13841376
$sql_where = '';
13851377

@@ -1724,11 +1716,7 @@ function templates($header_label) {
17241716
thold_template_request_validation();
17251717

17261718
// if the number of rows is -1, set it to the default
1727-
if (get_request_var('rows') == -1) {
1728-
$rows = read_config_option('num_rows_table');
1729-
} else {
1730-
$rows = get_request_var('rows');
1731-
}
1719+
$rows = plugin_get_rows_per_page();
17321720

17331721
$sql_where = '';
17341722
$sql_order = get_order_string();
@@ -2069,11 +2057,7 @@ function lists() {
20692057
// ================= input validation =================
20702058

20712059
// if the number of rows is -1, set it to the default
2072-
if (get_request_var('rows') == -1) {
2073-
$rows = read_config_option('num_rows_table');
2074-
} else {
2075-
$rows = get_request_var('rows');
2076-
}
2060+
$rows = plugin_get_rows_per_page();
20772061

20782062
html_start_box(__('Notification Lists', 'thold'), '100%', false, '3', 'center', 'notify_lists.php?action=edit');
20792063

thold.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,7 @@ function list_tholds() {
585585
include($config['base_path'] . '/plugins/thold/includes/arrays.php');
586586

587587
// if the number of rows is -1, set it to the default
588-
if (get_request_var('rows') == -1) {
589-
$rows = read_config_option('num_rows_table');
590-
} else {
591-
$rows = get_request_var('rows');
592-
}
588+
$rows = plugin_get_rows_per_page();
593589

594590
top_header();
595591

thold_functions.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,25 @@
5454
*
5555
* @return - the sanitized search string
5656
*/
57+
58+
/**
59+
* plugin_get_rows_per_page - resolve rows-per-page from request vars
60+
*
61+
* @return int
62+
*/
63+
function plugin_get_rows_per_page() {
64+
$rows = get_request_var('rows');
65+
66+
if ($rows == -1) {
67+
return read_config_option('num_rows_table');
68+
} elseif ($rows == -2) {
69+
return 999999;
70+
}
71+
72+
return $rows;
73+
}
74+
75+
5776
function sanitize_thold_sort_string($string) {
5877
static $drop_char_match = ['^', '$', '<', '>', '`', '\'', '"', '|', '?', '+', '[', ']', '{', '}', '#', ';', '!', '=', '*'];
5978
static $drop_char_replace = [' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '];

thold_graph.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -922,11 +922,7 @@ function hosts() {
922922
// ================= input validation =================
923923

924924
// if the number of rows is -1, set it to the default
925-
if (get_request_var('rows') == -1) {
926-
$rows = read_config_option('num_rows_table');
927-
} else {
928-
$rows = get_request_var('rows');
929-
}
925+
$rows = plugin_get_rows_per_page();
930926

931927
html_start_box(__('Device Status', 'thold'), '100%', false, '3', 'center', '');
932928
form_host_filter();
@@ -1426,11 +1422,7 @@ function thold_show_log() {
14261422
thold_validate_log_vars();
14271423

14281424
// if the number of rows is -1, set it to the default
1429-
if (get_request_var('rows') == -1) {
1430-
$rows = read_config_option('num_rows_table');
1431-
} else {
1432-
$rows = get_request_var('rows');
1433-
}
1425+
$rows = plugin_get_rows_per_page();
14341426

14351427
$days = read_config_option('thold_log_storage');
14361428

thold_templates.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,11 +2133,7 @@ function templates() {
21332133
template_request_validation();
21342134

21352135
// if the number of rows is -1, set it to the default
2136-
if (get_request_var('rows') == -1) {
2137-
$rows = read_config_option('num_rows_table');
2138-
} else {
2139-
$rows = get_request_var('rows');
2140-
}
2136+
$rows = plugin_get_rows_per_page();
21412137

21422138
html_start_box(__('Threshold Templates', 'thold'), '100%', false, '3', 'center', 'thold_templates.php?action=add');
21432139

0 commit comments

Comments
 (0)