Skip to content

Commit

Permalink
Merge pull request #1252 from Sama34/fix-1247
Browse files Browse the repository at this point in the history
Fixes #1247 Thread prefix error
  • Loading branch information
Starpaul20 committed Aug 19, 2014
2 parents 5b41c28 + 5173409 commit 6ba34f4
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 71 deletions.
6 changes: 3 additions & 3 deletions admin/modules/config/thread_prefixes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion editpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'].' ';
}
Expand Down
5 changes: 4 additions & 1 deletion forumdisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
94 changes: 39 additions & 55 deletions inc/datahandlers/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -625,20 +625,23 @@ 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))
{
$prefix = 0;
}
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']))
{
Expand All @@ -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))
{
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions inc/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion inc/functions_online.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down
2 changes: 1 addition & 1 deletion printthread.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion search.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down
2 changes: 1 addition & 1 deletion sendthread.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
if($thread['prefix'])
{
$threadprefix = build_prefixes($thread['prefix']);
if(isset($threadprefix['displaystyle']))
if(!empty($threadprefix['displaystyle']))
{
$breadcrumbprefix = $threadprefix['displaystyle'].' ';
}
Expand Down
7 changes: 5 additions & 2 deletions showthread.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
{
$threadprefix = build_prefixes($thread['prefix']);

if($threadprefix['prefix'])
if(!empty($threadprefix['prefix']))
{
$thread['threadprefix'] = $threadprefix['prefix'].' ';
$thread['displayprefix'] = $threadprefix['displaystyle'].' ';
Expand Down Expand Up @@ -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']);
Expand Down
6 changes: 3 additions & 3 deletions usercp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'].' ';
}
Expand Down Expand Up @@ -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'].' ';
}
Expand Down Expand Up @@ -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'].' ';
}
Expand Down

0 comments on commit 6ba34f4

Please sign in to comment.