Fix multiple PHP warnings

This commit is contained in:
markjcrane
2025-11-01 19:58:21 -06:00
parent a675660473
commit bf5bb4f642
41 changed files with 539 additions and 442 deletions

View File

@@ -120,7 +120,7 @@
}
//validate the username and password
$auth = new authentication;
$auth = new authentication(['settings' => $settings]);
$result = $auth->validate();
//if not authorized

View File

@@ -739,11 +739,11 @@ class database {
* <p><b>Note:</b><br>
* Table name must be sanitized. Otherwise, a warning will be
* emitted and false will be returned.</p>
* @param type $table_name Sanitized name of the table to search for.
* @param string $table_name Sanitized name of the table to search for.
* @return boolean Returns <i>true</i> if the table exists and <i>false</i> if it does not.
* @depends connect()
*/
public function table_exists ($table_name) {
public function table_exists (string $table_name) {
if (self::sanitize($table_name) != $table_name) {
trigger_error('Table Name must be sanitized', E_USER_WARNING);
return false;
@@ -793,12 +793,12 @@ class database {
* <p><b>Note:</b><br>
* Tables and Column names must be sanitized. Otherwise, a warning will be
* emitted and false will be returned.</p>
* @param type $table_name Sanitized name of the table to search for.
* @param type $column_name Sanitized name of the column to search for.
* @param string $table_name Sanitized name of the table to search for.
* @param string $column_name Sanitized name of the column to search for.
* @return boolean Returns <i>true</i> if the column exists and <i>false</i> if it does not.
* @depends connect()
*/
public function column_exists ($table_name, $column_name) {
public function column_exists (string $table_name, string $column_name) {
//sanitize the table name
if (self::sanitize($table_name) != $table_name) {
trigger_error('Table Name must be sanitized', E_USER_WARNING);
@@ -955,7 +955,7 @@ class database {
if (is_array($this->where)) {
foreach($this->where as $row) {
//sanitize the name
$array['name'] = self::sanitize($array['name']);
$row['name'] = self::sanitize($row['name']);
//validate the operator
switch ($row['operator']) {
@@ -1997,7 +1997,7 @@ class database {
foreach ($field_value as $sub_row) {
//build the delete array
if ($action == 'delete' && $sub_row['checked'] == 'true') {
if ($sub_row['checked'] == 'true') {
//delete the child data
$delete_array[$child_name][$y][$child_key_name] = $sub_row[$child_key_name];

View File

@@ -411,7 +411,7 @@ class domains {
if (is_array($uuids) && @sizeof($uuids) != 0) {
$sql = "select * from v_".$this->table." ";
$sql .= "where ".$this->name."_uuid in (".implode(', ', $uuids).") ";
$rows = $this->database->select($sql, $parameters, 'all');
$rows = $this->database->select($sql, null, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
$x = 0;
foreach ($rows as $row) {

View File

@@ -57,6 +57,10 @@
public $read_confirmation;
public $error;
public $response;
public $headers;
public $content_type;
public $reply_to;
public $date;
/**
* Set in the constructor. Must be a database object and cannot be null.
@@ -554,19 +558,19 @@
$this->recipients = explode(';', $this->recipients); // convert to array of addresses
}
foreach ($this->recipients as $this->recipient) {
if (is_array($this->recipient)) { // check if each recipient has multiple fields
if ($this->recipient["address"] != '' && valid_email($this->recipient["address"])) { // check if valid address
switch ($this->recipient["delivery"]) {
case "cc" : $mail->AddCC($this->recipient["address"], ($this->recipient["name"]) ? $this->recipient["name"] : $this->recipient["address"]); break;
case "bcc" : $mail->AddBCC($this->recipient["address"], ($this->recipient["name"]) ? $this->recipient["name"] : $this->recipient["address"]); break;
default : $mail->AddAddress($this->recipient["address"], ($this->recipient["name"]) ? $this->recipient["name"] : $this->recipient["address"]);
foreach ($this->recipients as $recipient) {
if (is_array($recipient)) { // check if each recipient has multiple fields
if ($recipient["address"] != '' && valid_email($recipient["address"])) { // check if valid address
switch ($recipient["delivery"]) {
case "cc" : $mail->AddCC($recipient["address"], ($recipient["name"]) ? $recipient["name"] : $recipient["address"]); break;
case "bcc" : $mail->AddBCC($recipient["address"], ($recipient["name"]) ? $recipient["name"] : $recipient["address"]); break;
default : $mail->AddAddress($recipient["address"], ($recipient["name"]) ? $recipient["name"] : $recipient["address"]);
}
$address_found = true;
}
}
else if ($this->recipient != '' && valid_email($this->recipient)) { // check if recipient value is simply (only) an address
$mail->AddAddress($this->recipient);
else if ($recipient != '' && valid_email($recipient)) { // check if recipient value is simply (only) an address
$mail->AddAddress($recipient);
$address_found = true;
}
}

View File

@@ -52,8 +52,9 @@ class file {
* Glob search for a list of files
* @var string $dir this is the directory to scan
* @var boolean $recursive get the sub directories
* @return array list of files or an empty array if not found
*/
public function glob($dir, $recursive) {
public function glob($dir, $recursive): array {
$files = [];
if ($dir != '' || $dir != '/') {
$tree = glob(rtrim($dir, '/') . '/*');
@@ -69,12 +70,6 @@ class file {
}
}
}
else {
$files[] = $file;
}
}
else {
$files[] = $file;
}
return $files;
}

View File

@@ -785,16 +785,16 @@
$menu_tags = '';
switch ($menu_item_category) {
case "internal":
$menu_tags = "href='".PROJECT_PATH.$submenu_item_link."'";
$menu_tags = "href='".PROJECT_PATH.$menu_item_link."'";
break;
case "external":
if (substr($submenu_item_link, 0,1) == "/") {
$submenu_item_link = PROJECT_PATH.$submenu_item_link;
if (substr($menu_item_link, 0,1) == "/") {
$menu_item_link = PROJECT_PATH.$menu_item_link;
}
$menu_tags = "href='".$submenu_item_link."' target='_blank'";
$menu_tags = "href='".$menu_item_link."' target='_blank'";
break;
case "email":
$menu_tags = "href='mailto:".$submenu_item_link."'";
$menu_tags = "href='mailto:".$menu_item_link."'";
break;
}
@@ -805,11 +805,11 @@
$menu_html .= "<a $menu_tags style='padding: 0px 0px; border-style: none; background: none;'><h2 align='center' style=''>".$menu_item_title."</h2></a>\n";
}
else {
if ($submenu_item_link == "/login.php" || $submenu_item_link == "/users/signup.php") {
if ($menu_item_link == "/login.php" || $menu_item_link == "/users/signup.php") {
//hide login and sign-up when the user is logged in
}
else {
if (empty($submenu_item_link)) {
if (empty($menu_item_link)) {
$menu_html .= "<h2 align='center' style=''>".$menu_item_title."</h2>\n";
}
else {

View File

@@ -36,13 +36,13 @@
public $data_types;
//class constructor
public function __construct() {
public function __construct($setting_array) {
//includes files
require dirname(__DIR__, 2) . "/resources/require.php";
//connect to the database
$this->database = database::new();
//open a database connection
$this->database = $setting_array['database'] ?? database::new();
//get the list of installed apps from the core and mod directories
$config_list = glob($_SERVER["DOCUMENT_ROOT"] . PROJECT_PATH . "/*/*/app_config.php");
@@ -122,7 +122,7 @@
$this->database->beginTransaction();
//execute the sql query
try {
$this->database->query($sql);
$this->database->execute($sql, null);
} catch (PDOException $error) {
echo "error: " . $error->getMessage() . " sql: $sql<br/>";
}
@@ -138,7 +138,7 @@
return true;
}
}
return $false;
return false;
}
//check if a column exists
@@ -208,7 +208,7 @@
//database table exists alternate
private function db_table_exists_alternate($db_type, $table_name) {
$sql = "select count(*) from $table_name ";
$result = $this->database->query($sql);
$result = $this->database->execute($sql, null);
if ($result > 0) {
return true; //table exists
} else {
@@ -282,7 +282,7 @@
return true;
}
}
return $false;
return false;
}
//database column exists
@@ -839,7 +839,7 @@
foreach ($update_array as $sql) {
if (strlen(trim($sql))) {
try {
$this->database->db->query(trim($sql));
$this->database->execute(trim($sql), null);
if ($format == "text") {
$response .= " $sql;\n";
}

View File

@@ -94,7 +94,7 @@ class sounds {
if (is_array($sound_files) && @sizeof($sound_files) != 0) {
foreach ($sound_files as $value) {
if (substr($value, 0, 71) == "\$\${sounds_dir}/\${default_language}/\${default_dialect}/\${default_voice}/") {
$value = substr($var, 71);
$value = substr($value, 71);
}
$array['sounds'][$x]['name'] = $value;
$array['sounds'][$x]['value'] = $value;

View File

@@ -295,7 +295,7 @@ class text {
}
}
}
if(empty($append) && array_key_exists($comment, $lang_label) && array_key_exists($comment[$lang_label], $lang_code)) {
if(empty($append) && array_key_exists($comment[$lang_label], $lang_code)) {
$append = " //$comment[$lang_label][$lang_code]";
}
fwrite($lang_file, "\$text['$lang_label']['$target_lang'$spacer] = \"".$this->escape_str($value)."\";$append\n");

View File

@@ -35,7 +35,7 @@
private $default_tone_label;
private $database;
/**
/**
* called when the object is created
*/
public function __construct(array $setting_array = []) {
@@ -47,6 +47,11 @@
$this->database = $setting_array['database'] ?? database::new();
}
/**
* tones_list function
*
* @return array
*/
public function tones_list() {
//get the tones
$sql = "select * from v_vars ";
@@ -68,6 +73,6 @@
unset($sql, $tones, $tone);
//return the tones
return $tone_list ?? '';
return $tone_list ?? [];
}
}

View File

@@ -1,9 +1,14 @@
<?php
/**
* xml class
*/
class xml {
/**
* Escapes xml special characters to html entities and sanitze switch special chars.
* @param mixed $string
* @return void
*/
static function sanitize($string) {
$string = preg_replace('/\$\{[^}]+\}/', '', $string);