Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use constants in place of class constants #2342

Merged
merged 1 commit into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,22 @@

switch ($_GET['list']) {
case 'black':
$_POST['type'] = ListType::blacklist;
$_POST['type'] = LISTTYPE_BLACKLIST;

break;

case 'regex_black':
$_POST['type'] = ListType::regex_blacklist;
$_POST['type'] = LISTTYPE_REGEX_BLACKLIST;

break;

case 'white':
$_POST['type'] = ListType::whitelist;
$_POST['type'] = LISTTYPE_WHITELIST;

break;

case 'regex_white':
$_POST['type'] = ListType::regex_whitelist;
$_POST['type'] = LISTTYPE_REGEX_WHITELIST;

break;

Expand Down
16 changes: 6 additions & 10 deletions scripts/pi-hole/php/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
* Please see LICENSE file for your rights under this license
*/

// List Type Constants
const LISTTYPE_WHITELIST = 0;
const LISTTYPE_BLACKLIST = 1;
const LISTTYPE_REGEX_WHITELIST = 2;
const LISTTYPE_REGEX_BLACKLIST = 3;

function getGravityDBFilename()
{
// Get possible non-standard location of FTL's database
Expand Down Expand Up @@ -278,13 +284,3 @@ function remove_from_table($db, $table, $domains, $returnnum = false, $type = -1

return 'Success, removed '.$num.' domain'.$plural;
}

if (!class_exists('ListType')) {
class ListType
{
public const whitelist = 0;
public const blacklist = 1;
public const regex_whitelist = 2;
public const regex_blacklist = 3;
}
}
6 changes: 3 additions & 3 deletions scripts/pi-hole/php/groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ function verify_ID_array($arr)
array_push($groups, $gres['group_id']);
}
$res['groups'] = $groups;
if ($res['type'] === ListType::whitelist || $res['type'] === ListType::blacklist) {
if ($res['type'] === LISTTYPE_WHITELIST || $res['type'] === LISTTYPE_BLACKLIST) {
// Convert domain name to international form
// Skip this for the root zone `.`
if ($res['domain'] != '.') {
Expand Down Expand Up @@ -571,9 +571,9 @@ function verify_ID_array($arr)
if (isset($_POST['type'])) {
$type = intval($_POST['type']);
} elseif (isset($_POST['list']) && $_POST['list'] === 'white') {
$type = ListType::whitelist;
$type = LISTTYPE_WHITELIST;
} elseif (isset($_POST['list']) && $_POST['list'] === 'black') {
$type = ListType::blacklist;
$type = LISTTYPE_BLACKLIST;
}

if (!$insert_stmt->bindValue(':type', $type, SQLITE3_TEXT)
Expand Down
14 changes: 7 additions & 7 deletions scripts/pi-hole/php/teleporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,13 @@ function archive_insert_into_table($file, $table, $flush = false, $wildcardstyle
$type = null;
if ($table === 'whitelist') {
$table = 'domainlist';
$type = ListType::whitelist;
$type = LISTTYPE_WHITELIST;
} elseif ($table === 'blacklist') {
$table = 'domainlist';
$type = ListType::blacklist;
$type = LISTTYPE_BLACKLIST;
} elseif ($table === 'regex_blacklist') {
$table = 'domainlist';
$type = ListType::regex_blacklist;
$type = LISTTYPE_REGEX_BLACKLIST;
} elseif ($table === 'domain_audit') {
$table = 'domain_audit';
$type = -1; // -1 -> not used inside add_to_table()
Expand Down Expand Up @@ -578,10 +578,10 @@ function noun($num)
exit('cannot open/create '.htmlentities($archive_file_name)."<br>\nPHP user: ".exec('whoami')."\n");
}

archive_add_table('whitelist.exact.json', 'domainlist', ListType::whitelist);
archive_add_table('whitelist.regex.json', 'domainlist', ListType::regex_whitelist);
archive_add_table('blacklist.exact.json', 'domainlist', ListType::blacklist);
archive_add_table('blacklist.regex.json', 'domainlist', ListType::regex_blacklist);
archive_add_table('whitelist.exact.json', 'domainlist', LISTTYPE_WHITELIST);
archive_add_table('whitelist.regex.json', 'domainlist', LISTTYPE_REGEX_WHITELIST);
archive_add_table('blacklist.exact.json', 'domainlist', LISTTYPE_BLACKLIST);
archive_add_table('blacklist.regex.json', 'domainlist', LISTTYPE_REGEX_BLACKLIST);
archive_add_table('adlist.json', 'adlist');
archive_add_table('domain_audit.json', 'domain_audit');
archive_add_table('group.json', 'group');
Expand Down