Skip to content

Commit

Permalink
remove db_array() from codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
Spine committed May 6, 2021
1 parent d613024 commit 657f560
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 40 deletions.
17 changes: 0 additions & 17 deletions classes/db_mysql.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@
throw new Exception('Mysqli Extension not loaded.');
}

function enum_boolean($bool) {
return $bool == true ? '1' : '0';
}

//Handles escaping
function db_string($String, $DisableWildcards = false) {
global $DB;
Expand All @@ -135,19 +131,6 @@ function db_string($String, $DisableWildcards = false) {
return $String;
}

function db_array($Array, $DontEscape = [], $Quote = false) {
foreach ($Array as $Key => $Val) {
if (!in_array($Key, $DontEscape)) {
if ($Quote) {
$Array[$Key] = '\''.db_string(trim($Val)).'\'';
} else {
$Array[$Key] = db_string(trim($Val));
}
}
}
return $Array;
}

class DB_MYSQL_Exception extends Exception {}

//TODO: revisit access levels once Drone is replaced by ZeRobot
Expand Down
1 change: 0 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
<properties>
<property name="forbiddenFunctions" type="array" extend="true">
<element key="db_string" value="null"/>
<element key="db_array" value="null"/>
<element key="each" value="null"/>
<element key="eval" value="null"/>
<element key="extract" value="null"/>
Expand Down
36 changes: 14 additions & 22 deletions sections/tools/managers/referral_alter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
error(403);
}

$P = db_array($_POST);
$ReferralManager = new \Gazelle\Manager\Referral;
$ReferralManager = new Gazelle\Manager\Referral;

if ($_POST['submit'] == 'Delete') {
if (!is_number($_POST['id']) || $_POST['id'] == '') {
$id = (int)$_POST['id'];
if (!$id) {
error(0);
}

$ReferralManager->deleteAccount($_POST['id']);
$ReferralManager->deleteAccount($id);
} else {
$Val->SetFields('site', '1', 'string', 'The site must be set, and has a max length of 30 characters', ['maxlength' => 30]);
$Val->SetFields('url', '1', 'string', 'The URL must be set, and has a max length of 30 characters', ['maxlength' => 30]);
Expand All @@ -22,29 +21,22 @@
$Val->SetFields('active', '1', 'checkbox', '');
$Err = $Val->ValidateForm($_POST);

if (substr($P['url'], -1) !== '/') {
$P['url'] .= '/';
if (substr($_POST['url'], -1) !== '/') {
$_POST['url'] .= '/';
}

if ($_POST['submit'] == 'Create') {
$ReferralManager->createAccount($P['site'], $P['url'], $P['user'], $P['password'],
$P['active'] == 'on' ? 1 : 0, $P['type'], $P['cookie']);
} elseif ($_POST['submit'] == 'Edit') {
if (!is_number($_POST['id']) || $_POST['id'] == '') {
error(0);
}

$account = $ReferralManager->getAccount($P['id']);
if ($account == null) {
if ($_POST['submit'] === 'Create') {
$ReferralManager->createAccount($_POST['site'], $_POST['url'], $_POST['user'], $_POST['password'],
$_POST['active'] == 'on' ? 1 : 0, $_POST['type'], $_POST['cookie']);
} elseif ($_POST['submit'] === 'Edit') {
$id = (int)$_POST['id'];
if (!$id || !$ReferralManager->getAccount($id)) {
error(0);
}

$P['cookie'] = str_replace('\\"', '"', $P['cookie']);
$P['password'] = str_replace('\\"', '"', $P['password']);
$ReferralManager->updateAccount($P['id'], $P['site'], $P['url'], $P['user'],
$P['password'], $P['active'] == 'on' ? 1 : 0, $P['type'], $P['cookie']);
$ReferralManager->updateAccount($_POST['id'], $_POST['site'], $_POST['url'], $_POST['user'],
$_POST['password'], $_POST['active'] == 'on' ? 1 : 0, $_POST['type'], $_POST['cookie']);
}
}

header('Location: tools.php?action=referral_accounts');
?>

0 comments on commit 657f560

Please sign in to comment.