Exemplo n.º 1
0
function integrate_display_chars_messages(&$output, &$message, $counter)
{
    global $memberContext, $smcFunc, $txt, $scripturl, $board_info, $user_profile, $modSettings;
    $output['id_character'] = $message['id_character'];
    // This is where it gets nasty. The original code pulls a reference to
    // memberContext to save memory. But that doesn't work so well when
    // we have characters, so we have to break the reference and replace it
    // with a copy-by-value.
    if (!empty($output['member']['id'])) {
        unset($output['member']);
        $output['member'] = $memberContext[$message['id_member']];
        // Now replace the values we need into the new version.
        if (!empty($output['member']['characters'][$message['id_character']])) {
            $character = $output['member']['characters'][$message['id_character']];
            if (!empty($character['char_sheet'])) {
                $output['member']['char_sheet_url'] = $scripturl . '?action=profile;u=' . $message['id_member'] . ';area=characters;char=' . $output['id_character'] . ';sa=sheet';
            }
            if (!empty($character['avatar'])) {
                $output['member']['avatar'] = ['name' => $character['avatar'], 'image' => '<img class="avatar" src="' . $character['avatar'] . '" alt="">', 'href' => $character['avatar'], 'url' => $character['avatar']];
            } else {
                $output['member']['avatar'] = ['name' => '', 'image' => '<img class="avatar" src="' . $modSettings['avatar_url'] . '/default.png" alt="">', 'href' => $modSettings['avatar_url'] . '/default.png', 'url' => $modSettings['avatar_url'] . '/default.png'];
            }
            // We need to fix display of badges and everything - for reasons
            // of online behaviour we can't trust what we might have now.
            // In any case this lets us handle multiple badges.
            if (!empty($character['is_main'])) {
                // We use the main account groups for this.
                $group_list = array_merge([$user_profile[$message['id_member']]['id_group']], !empty($user_profile[$message['id_member']]['additional_groups']) ? explode(',', $user_profile[$message['id_member']]['additional_groups']) : []);
            } else {
                // We use the character's group(s)
                $group_list = array_merge([$character['main_char_group']], !empty($character['char_groups']) ? explode(',', $character['char_groups']) : []);
            }
            $group_info = get_labels_and_badges($group_list);
            $output['member']['username_color'] = '<span ' . (!empty($group_info['color']) ? 'style="color:' . $group_info['color'] . ';"' : '') . '>' . $character['character_name'] . '</span>';
            $output['member']['name_color'] = '<span ' . (!empty($group_info['color']) ? 'style="color:' . $group_info['color'] . ';"' : '') . '>' . $character['character_name'] . '</span>';
            $output['member']['group'] = $group_info['title'];
            $output['member']['group_color'] = $group_info['color'];
            $output['member']['group_icons'] = $group_info['badges'];
            $output['member']['link_color'] = '<a href="' . $scripturl . '?action=profile;u=' . $message['id_member'] . ';area=characters;char=' . $output['id_character'] . '"' . (!empty($group_info['color']) ? ' style="color:' . $group_info['color'] . ';"' : '') . '>' . $character['character_name'] . '</a>';
            $output['member']['href'] = $scripturl . '?action=profile;u=' . $message['id_member'] . ';area=characters;char=' . $output['id_character'];
            $output['member']['link'] = '<a href="' . $scripturl . '?action=profile;u=' . $message['id_member'] . ';area=characters;char=' . $output['id_character'] . '">' . $character['character_name'] . '</a>';
            $output['member']['signature'] = $character['sig_parsed'];
            $output['member']['posts'] = comma_format($character['posts']);
            $is_online = $message['id_character'] == $output['member']['current_character'];
            $output['member']['online'] = ['is_online' => $is_online, 'text' => $smcFunc['htmlspecialchars']($txt[$is_online ? 'online' : 'offline']), 'member_online_text' => sprintf($txt[$is_online ? 'member_is_online' : 'member_is_offline'], $smcFunc['htmlspecialchars']($character['character_name'])), 'href' => $scripturl . '?action=pm;sa=send;u=' . $message['id_member'], 'link' => '<a href="' . $scripturl . '?action=pm;sa=send;u=' . $message['id_member'] . '">' . $txt[$is_online ? 'online' : 'offline'] . '</a>', 'label' => $txt[$is_online ? 'online' : 'offline']];
            $output['member']['title'] = !empty($character['char_title']) ? parse_bbc($character['char_title'], false) : '';
        }
    }
    // Now we indicate whether we can potentially migrate this to another character.
    // But that requires us having characters to migrate to, and follow the OOC/IC rules.
    $output['can_switch_char'] = false;
    if ($board_info['in_character']) {
        if (!empty($output['member']['characters'])) {
            $output['possible_characters'] = [];
            foreach ($output['member']['characters'] as $char_id => $char) {
                // We can't switch to the character that already posted it.
                if ($char_id == $message['id_character']) {
                    continue;
                }
                // You can't switch it to a main character.
                if ($char['is_main']) {
                    continue;
                }
                $output['possible_characters'][$char_id] = $char['character_name'];
            }
            if (!empty($output['possible_characters'])) {
                asort($output['possible_characters']);
            }
        }
        $output['can_switch_char'] = !empty($output['possible_characters']) && $output['can_modify'];
        if (!$output['can_switch_char']) {
            unset($output['possible_characters']);
        }
    }
}
Exemplo n.º 2
0
function CharacterSheetList()
{
    global $context, $txt, $smcFunc;
    loadLanguage('Profile');
    $context['group_id'] = isset($_GET['group']) ? (int) $_GET['group'] : 0;
    if (empty($context['group_id'])) {
        redirectexit('action=characters');
    }
    $context['sub_template'] = 'character_sheet_list';
    $sort = ['last_active' => ['asc' => 'chars.last_active ASC', 'desc' => 'chars.last_active DESC'], 'name' => ['asc' => 'chars.character_name ASC', 'desc' => 'chars.character_name DESC']];
    $context['sort_by'] = isset($_GET['sort'], $sort[$_GET['sort']]) ? $_GET['sort'] : 'last_active';
    $context['sort_order'] = isset($_GET['dir']) && !empty($_GET['sort']) && ($_GET['dir'] == 'asc' || $_GET['dir'] == 'desc') ? $_GET['dir'] : 'desc';
    $context['characters'] = [];
    $request = $smcFunc['db_query']('', '
		SELECT chars.id_character, chars.id_member, chars.character_name,
			chars.date_created, chars.last_active, chars.avatar, chars.posts,
			chars.main_char_group, chars.char_groups, chars.char_title, chars.retired
		FROM {db_prefix}characters AS chars
		WHERE chars.char_sheet != 0
			AND main_char_group = {int:group}
		ORDER BY {raw:sort}', ['group' => $context['group_id'], 'sort' => $sort[$context['sort_by']][$context['sort_order']]]);
    while ($row = $smcFunc['db_fetch_assoc']($request)) {
        $row['group_list'] = array_merge((array) $row['main_char_group'], explode(',', $row['char_groups']));
        $row['groups'] = get_labels_and_badges($row['group_list']);
        $context['characters'][] = $row;
    }
    $smcFunc['db_free_result']($request);
}