Skip to content

Commit

Permalink
Use constants in place of class constants (#2342)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdwebdesign authored Sep 9, 2022
2 parents eb83420 + d12ef01 commit 9485353
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
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

0 comments on commit 9485353

Please sign in to comment.