Fix many notices in admin_attach_cp.php

This commit is contained in:
Yuriy Pikhtarev 2017-02-12 15:56:46 +03:00
commit 8262cf769e
No known key found for this signature in database
GPG key ID: 3A9B5A757B48ECC6
2 changed files with 98 additions and 73 deletions

View file

@ -24,11 +24,12 @@
*/ */
/** /**
* All Attachment Functions only needed in Admin * Set/change quotas
*/ *
* @param $mode
/** * @param $id
* Set/Change Quotas * @param $quota_type
* @param int $quota_limit_id
*/ */
function process_quota_settings($mode, $id, $quota_type, $quota_limit_id = 0) function process_quota_settings($mode, $id, $quota_type, $quota_limit_id = 0)
{ {
@ -38,28 +39,21 @@ function process_quota_settings($mode, $id, $quota_type, $quota_limit_id = 0)
if ($mode == 'user') { if ($mode == 'user') {
if (!$quota_limit_id) { if (!$quota_limit_id) {
$sql = 'DELETE FROM ' . BB_QUOTA . " $sql = 'DELETE FROM ' . BB_QUOTA . " WHERE user_id = $id AND quota_type = $quota_type";
WHERE user_id = $id
AND quota_type = $quota_type";
} else { } else {
// Check if user is already entered // Check if user is already entered
$sql = 'SELECT user_id $sql = 'SELECT user_id FROM ' . BB_QUOTA . " WHERE user_id = $id AND quota_type = $quota_type";
FROM ' . BB_QUOTA . " if (!$result = DB()->sql_query($sql)) {
WHERE user_id = $id
AND quota_type = $quota_type";
if (!($result = DB()->sql_query($sql))) {
bb_die('Could not get entry #1'); bb_die('Could not get entry #1');
} }
if (DB()->num_rows($result) == 0) { if (DB()->num_rows($result) == 0) {
$sql_ary = array( $sql_ary = [
'user_id' => (int)$id, 'user_id' => (int)$id,
'group_id' => 0, 'group_id' => 0,
'quota_type' => (int)$quota_type, 'quota_type' => (int)$quota_type,
'quota_limit_id' => (int)$quota_limit_id 'quota_limit_id' => (int)$quota_limit_id
); ];
$sql = 'INSERT INTO ' . BB_QUOTA . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary); $sql = 'INSERT INTO ' . BB_QUOTA . ' ' . attach_mod_sql_build_array('INSERT', $sql_ary);
} else { } else {
$sql = 'UPDATE ' . BB_QUOTA . " $sql = 'UPDATE ' . BB_QUOTA . "
@ -75,21 +69,14 @@ function process_quota_settings($mode, $id, $quota_type, $quota_limit_id = 0)
} }
} elseif ($mode == 'group') { } elseif ($mode == 'group') {
if (!$quota_limit_id) { if (!$quota_limit_id) {
$sql = 'DELETE FROM ' . BB_QUOTA . " $sql = 'DELETE FROM ' . BB_QUOTA . " WHERE group_id = $id AND quota_type = $quota_type";
WHERE group_id = $id if (!$result = DB()->sql_query($sql)) {
AND quota_type = $quota_type";
if (!($result = DB()->sql_query($sql))) {
bb_die('Unable to delete quota settings'); bb_die('Unable to delete quota settings');
} }
} else { } else {
// Check if user is already entered // Check if user is already entered
$sql = 'SELECT group_id $sql = 'SELECT group_id FROM ' . BB_QUOTA . " WHERE group_id = $id AND quota_type = $quota_type";
FROM ' . BB_QUOTA . " if (!$result = DB()->sql_query($sql)) {
WHERE group_id = $id
AND quota_type = $quota_type";
if (!($result = DB()->sql_query($sql))) {
bb_die('Could not get entry #2'); bb_die('Could not get entry #2');
} }
@ -109,7 +96,13 @@ function process_quota_settings($mode, $id, $quota_type, $quota_limit_id = 0)
} }
/** /**
* sort multi-dimensional Array * Sort multi-dimensional array
*
* @param $sort_array
* @param $key
* @param $sort_order
* @param int $pre_string_sort
* @return mixed
*/ */
function sort_multi_array($sort_array, $key, $sort_order, $pre_string_sort = 0) function sort_multi_array($sort_array, $key, $sort_order, $pre_string_sort = 0)
{ {
@ -125,16 +118,20 @@ function sort_multi_array($sort_array, $key, $sort_order, $pre_string_sort = 0)
$num_iterations = $last_element - $i; $num_iterations = $last_element - $i;
for ($j = 0; $j < $num_iterations; $j++) { for ($j = 0; $j < $num_iterations; $j++) {
$next = 0;
// do checks based on key // do checks based on key
$switch = false; $switch = false;
if (!$string_sort) { if (!$string_sort) {
if (($sort_order == 'DESC' && intval(@$sort_array[$j][$key]) < intval(@$sort_array[$j + 1][$key])) || ($sort_order == 'ASC' && intval(@$sort_array[$j][$key]) > intval(@$sort_array[$j + 1][$key]))) { if (
($sort_order == 'DESC' && intval(@$sort_array[$j][$key]) < intval(@$sort_array[$j + 1][$key])) ||
($sort_order == 'ASC' && intval(@$sort_array[$j][$key]) > intval(@$sort_array[$j + 1][$key]))
) {
$switch = true; $switch = true;
} }
} else { } else {
if (($sort_order == 'DESC' && strcasecmp(@$sort_array[$j][$key], @$sort_array[$j + 1][$key]) < 0) || ($sort_order == 'ASC' && strcasecmp(@$sort_array[$j][$key], @$sort_array[$j + 1][$key]) > 0)) { if (
($sort_order == 'DESC' && strcasecmp(@$sort_array[$j][$key], @$sort_array[$j + 1][$key]) < 0) ||
($sort_order == 'ASC' && strcasecmp(@$sort_array[$j][$key], @$sort_array[$j + 1][$key]) > 0)
) {
$switch = true; $switch = true;
} }
} }
@ -151,47 +148,67 @@ function sort_multi_array($sort_array, $key, $sort_order, $pre_string_sort = 0)
} }
/** /**
* Returns the filesize of the upload directory in human readable format * Returns size of the upload directory in human readable format
*
* @return string
*/ */
function get_formatted_dirsize() function get_formatted_dirsize()
{ {
global $attach_config, $upload_dir, $lang; global $lang, $upload_dir;
$upload_dir_size = 0; $upload_dir_size = 0;
if ($dirname = @opendir($upload_dir)) { if ($dirname = opendir($upload_dir)) {
while ($file = @readdir($dirname)) { while ($file = readdir($dirname)) {
if ($file != 'index.php' && $file != '.htaccess' && !is_dir($upload_dir . '/' . $file) && !is_link($upload_dir . '/' . $file)) { if (
$upload_dir_size += @filesize($upload_dir . '/' . $file); $file != 'index.php' &&
$file != '.htaccess' &&
!is_dir($upload_dir . '/' . $file) &&
!is_link($upload_dir . '/' . $file)
) {
$upload_dir_size += filesize($upload_dir . '/' . $file);
} }
} }
@closedir($dirname); closedir($dirname);
} else { } else {
$upload_dir_size = $lang['NOT_AVAILABLE']; return $lang['NOT_AVAILABLE'];
return $upload_dir_size;
} }
return humn_size($upload_dir_size); return humn_size($upload_dir_size);
} }
/* /**
* Build SQL-Statement for the search feature * Build SQL statement for the search feature
*/ *
* @param $order_by
* @param $total_rows
* @return array
*/
function search_attachments($order_by, &$total_rows) function search_attachments($order_by, &$total_rows)
{ {
global $lang; global $lang;
$where_sql = array(); $where_sql = [];
// Get submitted Vars $search_vars = [
$search_vars = array('search_keyword_fname', 'search_keyword_comment', 'search_author', 'search_size_smaller', 'search_size_greater', 'search_count_smaller', 'search_count_greater', 'search_days_greater', 'search_forum', 'search_cat'); 'search_keyword_fname',
'search_keyword_comment',
'search_author',
'search_size_smaller',
'search_size_greater',
'search_count_smaller',
'search_count_greater',
'search_days_greater',
'search_forum',
];
for ($i = 0; $i < sizeof($search_vars); $i++) { for ($i = 0; $i < sizeof($search_vars); $i++) {
$$search_vars[$i] = get_var($search_vars[$i], ''); $var = $search_vars[$i];
$$var = get_var($var, null);
} }
// Author name search // Author name search
if ($search_author != '') { if (isset($search_author)) {
// Bring in line with 2.0.x expected username // Bring in line with 2.0.x expected username
$search_author = addslashes(html_entity_decode($search_author)); $search_author = addslashes(html_entity_decode($search_author));
$search_author = stripslashes(clean_username($search_author)); $search_author = stripslashes(clean_username($search_author));
@ -201,7 +218,6 @@ function search_attachments($order_by, &$total_rows)
// We need the post_id's, because we want to query the Attachment Table // We need the post_id's, because we want to query the Attachment Table
$sql = 'SELECT user_id FROM ' . BB_USERS . " WHERE username LIKE '$search_author'"; $sql = 'SELECT user_id FROM ' . BB_USERS . " WHERE username LIKE '$search_author'";
if (!($result = DB()->sql_query($sql))) { if (!($result = DB()->sql_query($sql))) {
bb_die('Could not obtain list of matching users (searching for: ' . $search_author . ')'); bb_die('Could not obtain list of matching users (searching for: ' . $search_author . ')');
} }
@ -221,46 +237,44 @@ function search_attachments($order_by, &$total_rows)
} }
// Search Keyword // Search Keyword
if ($search_keyword_fname != '') { if (isset($search_keyword_fname)) {
$match_word = str_replace('*', '%', $search_keyword_fname); $match_word = str_replace('*', '%', $search_keyword_fname);
$where_sql[] = " (a.real_filename LIKE '" . attach_mod_sql_escape($match_word) . "') "; $where_sql[] = " (a.real_filename LIKE '" . attach_mod_sql_escape($match_word) . "') ";
} }
if ($search_keyword_comment != '') { if (isset($search_keyword_comment)) {
$match_word = str_replace('*', '%', $search_keyword_comment); $match_word = str_replace('*', '%', $search_keyword_comment);
$where_sql[] = " (a.comment LIKE '" . attach_mod_sql_escape($match_word) . "') "; $where_sql[] = " (a.comment LIKE '" . attach_mod_sql_escape($match_word) . "') ";
} }
// Search Download Count // Search Download Count
if ($search_count_smaller != '' || $search_count_greater != '') { if (isset($search_count_smaller) || isset($search_count_greater)) {
if ($search_count_smaller != '') { if (!is_null($search_count_smaller)) {
$where_sql[] = ' (a.download_count < ' . (int)$search_count_smaller . ') '; $where_sql[] = ' (a.download_count < ' . (int)$search_count_smaller . ') ';
} elseif ($search_count_greater != '') { } elseif (!is_null($search_count_greater)) {
$where_sql[] = ' (a.download_count > ' . (int)$search_count_greater . ') '; $where_sql[] = ' (a.download_count > ' . (int)$search_count_greater . ') ';
} }
} }
// Search Filesize // Search Filesize
if ($search_size_smaller != '' || $search_size_greater != '') { if (isset($search_size_smaller) || isset($search_size_greater)) {
if ($search_size_smaller != '') { if (!is_null($search_size_smaller)) {
$where_sql[] = ' (a.filesize < ' . (int)$search_size_smaller . ') '; $where_sql[] = ' (a.filesize < ' . (int)$search_size_smaller . ') ';
} elseif ($search_size_greater != '') { } elseif (!is_null($search_size_greater)) {
$where_sql[] = ' (a.filesize > ' . (int)$search_size_greater . ') '; $where_sql[] = ' (a.filesize > ' . (int)$search_size_greater . ') ';
} }
} }
// Search Attachment Time // Search Attachment Time
if ($search_days_greater != '') { if (isset($search_days_greater)) {
$where_sql[] = ' (a.filetime < ' . (TIMENOW - ((int)$search_days_greater * 86400)) . ') '; $where_sql[] = ' (a.filetime < ' . (TIMENOW - ((int)$search_days_greater * 86400)) . ') ';
} }
// Search Forum // Search Forum
if ($search_forum) { if (isset($search_forum)) {
$where_sql[] = ' (p.forum_id = ' . intval($search_forum) . ') '; $where_sql[] = ' (p.forum_id = ' . intval($search_forum) . ') ';
} }
// Search Cat... nope... sorry :(
$sql = 'SELECT a.*, t.post_id, p.post_time, p.topic_id $sql = 'SELECT a.*, t.post_id, p.post_time, p.topic_id
FROM ' . BB_ATTACHMENTS . ' t, ' . BB_ATTACHMENTS_DESC . ' a, ' . BB_POSTS . ' p WHERE '; FROM ' . BB_ATTACHMENTS . ' t, ' . BB_ATTACHMENTS_DESC . ' a, ' . BB_POSTS . ' p WHERE ';
@ -297,14 +311,19 @@ function search_attachments($order_by, &$total_rows)
} }
/** /**
* perform LIMIT statement on arrays * Perform limit statement on arrays
*
* @param $array
* @param $start
* @param $pagelimit
* @return array
*/ */
function limit_array($array, $start, $pagelimit) function limit_array($array, $start, $pagelimit)
{ {
// array from start - start+pagelimit // array from start - start+pagelimit
$limit = (sizeof($array) < ($start + $pagelimit)) ? sizeof($array) : $start + $pagelimit; $limit = (sizeof($array) < ($start + $pagelimit)) ? sizeof($array) : $start + $pagelimit;
$limit_array = array(); $limit_array = [];
for ($i = $start; $i < $limit; $i++) { for ($i = $start; $i < $limit; $i++) {
$limit_array[] = $array[$i]; $limit_array[] = $array[$i];

View file

@ -492,22 +492,28 @@ function _set_var(&$result, $var, $type, $multibyte = false)
} }
/** /**
* get_var
*
* Used to get passed variable * Used to get passed variable
*
* @param $var_name
* @param $default
* @param bool $multibyte
* @return array
*/ */
function get_var($var_name, $default, $multibyte = false) function get_var($var_name, $default, $multibyte = false)
{ {
$request_var = (isset($_POST[$var_name])) ? $_POST : $_GET; if (
!isset($_REQUEST[$var_name]) ||
if (!isset($request_var[$var_name]) || (is_array($request_var[$var_name]) && !is_array($default)) || (is_array($default) && !is_array($request_var[$var_name]))) { (is_array($_REQUEST[$var_name]) && !is_array($default)) ||
return (is_array($default)) ? array() : $default; (is_array($default) && !is_array($_REQUEST[$var_name]))
) {
return (is_array($default)) ? [] : $default;
} }
$var = $request_var[$var_name]; $var = $_REQUEST[$var_name];
if (!is_array($default)) { if (!is_array($default)) {
$type = gettype($default); $type = gettype($default);
$key_type = null;
} else { } else {
list($key_type, $type) = each($default); list($key_type, $type) = each($default);
$type = gettype($type); $type = gettype($type);
@ -516,7 +522,7 @@ function get_var($var_name, $default, $multibyte = false)
if (is_array($var)) { if (is_array($var)) {
$_var = $var; $_var = $var;
$var = array(); $var = [];
foreach ($_var as $k => $v) { foreach ($_var as $k => $v) {
if (is_array($v)) { if (is_array($v)) {