From 5173409687e0b83c75f143b3b84deac978e6180f Mon Sep 17 00:00:00 2001 From: Omar Gonzalez Date: Sun, 17 Aug 2014 16:06:57 -0700 Subject: [PATCH] Fixes #1247 Thread prefix error --- admin/modules/config/thread_prefixes.php | 6 +- editpost.php | 2 +- forumdisplay.php | 5 +- inc/datahandlers/post.php | 94 ++++++++++-------------- inc/functions.php | 4 +- inc/functions_online.php | 2 +- printthread.php | 2 +- search.php | 2 +- sendthread.php | 2 +- showthread.php | 7 +- usercp.php | 6 +- 11 files changed, 61 insertions(+), 71 deletions(-) diff --git a/admin/modules/config/thread_prefixes.php b/admin/modules/config/thread_prefixes.php index 66be60dd75..7f376a60a4 100644 --- a/admin/modules/config/thread_prefixes.php +++ b/admin/modules/config/thread_prefixes.php @@ -229,7 +229,7 @@ function checkAction(id) if($mybb->input['action'] == 'edit_prefix') { $prefix = build_prefixes($mybb->input['pid']); - if(!$prefix['pid']) + if(empty($prefix['pid'])) { flash_message($lang->error_invalid_prefix, 'error'); admin_redirect('index.php?module=config-thread_prefixes'); @@ -462,7 +462,7 @@ function checkAction(id) if($mybb->input['action'] == 'delete_prefix') { $prefix = build_prefixes($mybb->input['pid']); - if(!$prefix['pid']) + if(empty($prefix['pid'])) { flash_message($lang->error_invalid_thread_prefix, 'error'); admin_redirect('index.php?module=config-thread_prefixes'); @@ -512,7 +512,7 @@ function checkAction(id) $table->construct_header($lang->controls, array('class' => 'align_center', 'colspan' => 2)); $prefixes = build_prefixes(); - if($prefixes) + if(!empty($prefixes)) { foreach($prefixes as $prefix) { diff --git a/editpost.php b/editpost.php index 48cad38091..cb4652f4f3 100644 --- a/editpost.php +++ b/editpost.php @@ -82,7 +82,7 @@ if($thread['prefix']) { $threadprefixes = build_prefixes(); - if(isset($threadprefixes[$thread['prefix']])) + if(!empty($threadprefixes[$thread['prefix']])) { $breadcrumbprefix = $threadprefixes[$thread['prefix']]['displaystyle'].' '; } diff --git a/forumdisplay.php b/forumdisplay.php index f5976313e3..5b2e96fa01 100644 --- a/forumdisplay.php +++ b/forumdisplay.php @@ -1026,7 +1026,10 @@ if($thread['prefix'] != 0) { $threadprefix = build_prefixes($thread['prefix']); - $thread['threadprefix'] = $threadprefix['displaystyle'].' '; + if(!empty($threadprefix)) + { + $thread['threadprefix'] = $threadprefix['displaystyle'].' '; + } } $thread['subject'] = $parser->parse_badwords($thread['subject']); diff --git a/inc/datahandlers/post.php b/inc/datahandlers/post.php index a3ecb20037..835f9487a9 100644 --- a/inc/datahandlers/post.php +++ b/inc/datahandlers/post.php @@ -625,6 +625,8 @@ function verify_prefix() { $prefix = &$this->data['prefix']; + $prefix_cache = build_prefixes(); + // If a valid prefix isn't supplied, don't assign one. if(empty($prefix)) { @@ -632,13 +634,14 @@ function verify_prefix() } else { - $verification = build_prefixes($prefix); - if(!$verification) + $prefix_cache = build_prefixes($prefix); + + if(empty($prefix_cache)) { $this->set_error('invalid_prefix'); return false; } - if($verification['groups'] != "-1") + if($prefix_cache['groups'] != "-1") { if(!empty($this->data['edit_uid'])) { @@ -649,32 +652,17 @@ function verify_prefix() { $user = get_user($this->data['uid']); } - $groups = array($user['usergroup']); - if(!empty($user['additionalgroups'])) - { - $groups = array_merge($groups, explode(',', $user['additionalgroups'])); - } - $prefix_groups = explode(",", $verification['groups']); - $valid_group = false; - foreach($groups as $group) - { - if(in_array($group, $prefix_groups)) - { - $valid_group = true; - break; - } - } - if(!$valid_group) + if(!is_member($prefix_cache['groups'], array('usergroup' => $user['usergroup'], 'additionalgroups' => $user['additionalgroups']))) { $this->set_error('invalid_prefix'); return false; } } - if($verification['forums'] != "-1") + if($prefix_cache['forums'] != "-1") { // Decide whether this prefix can be used in our forum - $forums = explode(",", $verification['forums']); + $forums = explode(",", $prefix_cache['forums']); if(!in_array($this->data['fid'], $forums)) { @@ -689,55 +677,51 @@ function verify_prefix() if($forum['requireprefix'] == 1) { - $required_cache = build_prefixes(); - $num_prefixes = 0; + $num_prefixes = false; // Go through each of our prefixes and decide if there are any possible prefixes to use. - foreach($required_cache as $required) + if(!empty($this->data['edit_uid'])) { - if($required['forums'] != "-1") - { - // Decide whether this prefix can be used in our forum - $forums = explode(",", $required['forums']); + // Post is being edited + $user = get_user($this->data['edit_uid']); + } + else + { + $user = get_user($this->data['uid']); + } - if(!in_array($forum['fid'], $forums)) - { - continue; - } - } - if($required['groups'] != "-1") + $prefix_cache = build_prefixes(); + + if(!empty($prefix_cache)) + { + foreach($prefix_cache as $required) { - if(!empty($this->data['edit_uid'])) + if($required['forums'] != "-1") { - // Post is being edited - $user = get_user($this->data['edit_uid']); - } - else - { - $user = get_user($this->data['uid']); - } - $groups = array($user['usergroup']); - if(!empty($user['additionalgroups'])) - { - $groups = array_merge($groups, explode(',', $user['additionalgroups'])); + // Decide whether this prefix can be used in our forum + $forums = explode(",", $required['forums']); + + if(!in_array($forum['fid'], $forums)) + { + continue; + } } - $prefix_groups = explode(",", $required['groups']); - foreach($groups as $group) + if($required['groups'] != "-1") { - if(in_array($group, $prefix_groups)) + if(!is_member($required['groups'], array('usergroup' => $user['usergroup'], 'additionalgroups' => $user['additionalgroups']))) { - ++$num_prefixes; + $num_prefixes = true; } } - } - else - { - ++$num_prefixes; + else + { + $num_prefixes = true; + } } } - if($prefix == 0 && $num_prefixes > 0) + if($prefix == 0 && $num_prefixes) { $this->set_error('require_prefix'); return false; diff --git a/inc/functions.php b/inc/functions.php index e885dfbbb3..d23169505a 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -3181,7 +3181,7 @@ function build_prefix_select($fid, $selected_pid=0, $multiple=0) } $prefix_cache = build_prefixes(0); - if(!$prefix_cache) + if(empty($prefix_cache)) { return false; // We've got no prefixes to show } @@ -3292,7 +3292,7 @@ function build_forum_prefix_select($fid, $selected_pid=0) $fid = (int)$fid; $prefix_cache = build_prefixes(0); - if(!$prefix_cache) + if(empty($prefix_cache)) { return false; // We've got no prefixes to show } diff --git a/inc/functions_online.php b/inc/functions_online.php index a3afa8059f..09a890988e 100644 --- a/inc/functions_online.php +++ b/inc/functions_online.php @@ -653,7 +653,7 @@ function build_friendly_wol_location($user_activity) while($thread = $db->fetch_array($query)) { $thread['threadprefix'] = ''; - if($thread['prefix'] && isset($threadprefixes[$thread['prefix']])) + if($thread['prefix'] && !empty($threadprefixes[$thread['prefix']])) { $thread['threadprefix'] = $threadprefixes[$thread['prefix']]['displaystyle']; } diff --git a/printthread.php b/printthread.php index b549ffa3e1..db2f48e072 100644 --- a/printthread.php +++ b/printthread.php @@ -34,7 +34,7 @@ if($thread['prefix']) { $threadprefix = build_prefixes($thread['prefix']); - if(isset($threadprefix)) + if(!empty($threadprefix)) { $thread['threadprefix'] = $threadprefix['prefix']; $thread['displaystyle'] = $threadprefix['displaystyle']; diff --git a/search.php b/search.php index 3e16674902..71d3240952 100644 --- a/search.php +++ b/search.php @@ -343,7 +343,7 @@ while($thread = $db->fetch_array($query)) { $thread['threadprefix'] = ''; - if($thread['prefix'] && isset($threadprefixes[$thread['prefix']])) + if($thread['prefix'] && !empty($threadprefixes[$thread['prefix']])) { $thread['threadprefix'] = $threadprefixes[$thread['prefix']]['displaystyle']; } diff --git a/sendthread.php b/sendthread.php index a36f4339bf..524aa3fae0 100644 --- a/sendthread.php +++ b/sendthread.php @@ -37,7 +37,7 @@ if($thread['prefix']) { $threadprefix = build_prefixes($thread['prefix']); - if(isset($threadprefix['displaystyle'])) + if(!empty($threadprefix['displaystyle'])) { $breadcrumbprefix = $threadprefix['displaystyle'].' '; } diff --git a/showthread.php b/showthread.php index 9440b54fe5..2f78d76bd9 100644 --- a/showthread.php +++ b/showthread.php @@ -71,7 +71,7 @@ { $threadprefix = build_prefixes($thread['prefix']); - if($threadprefix['prefix']) + if(!empty($threadprefix['prefix'])) { $thread['threadprefix'] = $threadprefix['prefix'].' '; $thread['displayprefix'] = $threadprefix['displaystyle'].' '; @@ -1126,7 +1126,10 @@ if($similar_thread['prefix'] != 0) { $prefix = build_prefixes($similar_thread['prefix']); - $similar_thread['threadprefix'] = $prefix['displaystyle'].' '; + if(!empty($prefix)) + { + $similar_thread['threadprefix'] = $prefix['displaystyle'].' '; + } } $similar_thread['subject'] = $parser->parse_badwords($similar_thread['subject']); diff --git a/usercp.php b/usercp.php index 4ea777e8c7..3f2dd0ebbd 100644 --- a/usercp.php +++ b/usercp.php @@ -1624,7 +1624,7 @@ $thread['threadprefix'] = ''; // If this thread has a prefix, insert a space between prefix and subject - if($thread['prefix'] != 0 && isset($threadprefixes[$thread['prefix']])) + if($thread['prefix'] != 0 && !empty($threadprefixes[$thread['prefix']])) { $thread['threadprefix'] = $threadprefixes[$thread['prefix']]['displaystyle'].' '; } @@ -3869,7 +3869,7 @@ $thread['lastpostlink'] = get_thread_link($thread['tid'], 0, "lastpost"); // If this thread has a prefix... - if($thread['prefix'] != 0 && isset($threadprefixes[$thread['prefix']])) + if($thread['prefix'] != 0 && !empty($threadprefixes[$thread['prefix']])) { $thread['displayprefix'] = $threadprefixes[$thread['prefix']]['displaystyle'].' '; } @@ -4050,7 +4050,7 @@ // If this thread has a prefix... if($thread['prefix'] != 0) { - if(isset($threadprefixes[$thread['prefix']])) + if(!empty($threadprefixes[$thread['prefix']])) { $thread['displayprefix'] = $threadprefixes[$thread['prefix']]['displaystyle'].' '; }