Customizing SMF > SMF Coding Discussion

FlashChat integration (number of users on button)

<< < (2/5) > >>

Suki:
So, the chat count do work? if so, there should be easy to include your image, we just need a check on that var if it has 1 or more as it's value.

dooie:
Sorry Suki,

No the Chat count does not work, that is the issue I have.
I can not find where $context['num_chat'] is located in any of the files? Could this be the missing variable?
I found all the other variables in Modifications.english.php but I can not find ['num_chat'] anywhere.

Here are the FlashChat variables in Modifications.english.php

--- Code: ---// --- Begin FlashChat Integration ---
$txt['fc_chat'] = 'Chat';
$txt['fc_flashchat'] = 'FlashChat';
$txt['fc_flashchat_settings'] = 'FlashChat Integration Settings';
$txt['fc_in_chat'] = 'in Chat';
$txt['fc_not_found'] = 'FlashChat does not appear to be installed!';
$txt['fc_no_guests'] = 'Sorry, guests aren\'t allowed to use the chat!';
$txt['fc_private_room'] = '<i>private room</i>';
$txt['fc_users_online'] = 'Users currently in chat';
// For 'Who's Online' page
$txt['whoall_chat'] = 'In the <a href="' . $boardurl . '?action=chat">Chatroom</a>';

// Settings for admin panel
$txt['fc_height2'] = 'Height';
$txt['fc_config'] = 'FlashChat Configuration';
$txt['fc_inForum'] = 'Display chat window "inside" forum?';
$txt['fc_newWindow'] = 'Open chat in new window?';
$txt['fc_showUsers'] = 'Display Users in Chat at top of forum?';
$txt['fc_showUserCount'] = 'Show number of users on Chat button?';
$txt['fc_size_desc'] = 'The height and width must me in px (eg. 600 for 600 pixels)! If no value is set it will default to 80% x 400px';
$txt['fc_width'] = 'Width';
// --- End FlashChat Integration ---
--- End code ---

The Chat button menu code in Subs.php is;

--- Code: ---//Start FlashChat integration
'chat' => array(
    'title' => $txt['fc_chat'],
    'href' => $scripturl . '?action=chat"', (!empty($modSettings['fc_newWindow']) ? ' target="_blank"' : ''), '>', $txt['fc_chat'], (!empty($modSettings['fc_showUserCount']) && !empty($context['num_chat']) ? ' [<strong>' . $context['num_chat'] . ' ' . ($context['num_chat'] == 1 ? $txt['user'] : $txt['users']) . '</strong>]' : ''),
    'show' => !$user_info['is_guest'],
         'sub_buttons' => array(
    ),
),
//End FlashChat integration
--- End code ---

The Chat count and Flashing icon worked in the previous version of SMF 1.1.1 that I was running with this code;

--- Code: --- // FlashChat!
global $modSettings;
$flashy_image = '<img src="{url_to_image}" alt="Flashy" border="0" />';
if ($context['user']['is_logged'])
echo ($current_action == 'chat' || $context['browser']['is_ie4']) ? '<td class="maintab_active_' . $first . '">&nbsp;</td>' : '' , '
<td valign="top" class="maintab_' , $current_action == 'chat' ? 'active_back' : 'back' , '">
<a href="', $scripturl, '?action=chat"', (!empty($modSettings['fc_newWindow']) ? ' target="_blank"' : ''), '>', $txt['fc_chat'], (!empty($modSettings['fc_showUserCount']) && !empty($context['num_chat']) ? ' [<strong>' . $context['num_chat'] . ' ' . ($context['num_chat'] == 1 ? $txt['user'] : $txt['users']) . '</strong>]&nbsp;' . $flashy_image : ''), '</a>
</td>' , $current_action == 'chat' ? '<td class="maintab_active_' . $last . '">&nbsp;</td>' : '';
--- End code ---

With the changes in SMF 2.0.2, I am totally lost?
Any idea's?

Cheers.

Suki:
That var is defined on the very same file via a query:


--- Code: ---// --- Begin FlashChat Integration ---
    // Only bother grabbing the data if we need it (ie. we're on the board
    // index, or the information will be shown at the top of the forum).
    // !!! $modSettings['fc_showUserCount'] just needs the count, not the whole query!
   if (!empty($modSettings['fc_showUsers']) || !empty($modSettings['fc_showUserCount']) || (empty($context['current_action']) || $context['current_action'] == 'boardindex' || $context['current_action'] == 'forum'))
    {
        global $boarddir, $db_prefix, $db_name;
        global $request, $fc_prefix, $context, $smcFunc, $link, $scripturl, $row;
        // Get the FlashChat database config (for the prefix)
        include($boarddir . '/chat/inc/config.srv.php');
        // Get the proper database prefix (including database name)
        $fc_prefix = is_numeric(substr($GLOBALS['fc_config']['db']['pref'], 0, 1)) ? $db_name . '.' . $GLOBALS['fc_config']['db']['pref'] : '`' . $db_name . '`.' . $GLOBALS['fc_config']['db']['pref'];
       
        // Load all the users currently in the chat
        $request = $smcFunc['db_query']('' , '
            SELECT
                fc.userid, fc.state, fc.color, fc.lang, fc.roomid,
                fr.name AS roomName, fr.ispublic,
                mem.real_name, mem.member_name, mem.show_online, mg.online_color,
                mg.id_group, mg.group_name
            FROM {$fc_prefix}connections AS fc
                LEFT JOIN {$db_prefix}members AS mem ON (mem.id_member = fc.userid)
                LEFT JOIN {$db_prefix}membergroups AS mg ON (mg.id_group = IF(mem.id_group = 0, mem.id_post_group, mem.id_group))
                LEFT JOIN {$fc_prefix}rooms AS fr ON (fc.roomid = fr.id)
            WHERE fc.userid IS NOT NULL
                AND mem.id_member != 0
            ORDER BY mem.real_name ASC');

           
        $context['users_chat'] = array();
        $context['list_users_chat'] = array();
        $context['num_chat'] = $smcFunc['db_num_rows']($request);
       
        // Loop through all users in chat
        while ($row = $smcFunc['db_fetch_assoc']($request))
        {
            // Does their membergroup have a colour?
            if (!empty($row['online_color']))
                $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['userid'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
            else
                $link = '<a href="' . $scripturl . '?action=profile;u=' . $row['userid'] . '">' . $row['real_name'] . '</a>';

            // Add them to the 'Users Online' list
            $context['users_chat'][$row['member_name']] = array(
                'id' => $row['userid'],
                'username' => $row['member_name'],
                'name' => $row['real_name'],
                'group' => $row['id_group'],
                'href' => $scripturl . '?action=profile;u=' . $row['userid'],
                'link' => $link,
                'chat' => array(
                    'color' => $row['color'],
                    'lang' => $row['lang'],
                    'room' => array(
                        'id' => $row['roomid'],
                        'name' => $row['roomName'],
                        'public' => ($row['ispublic'] == 'y' ? true : false),
                    ),
                ),
            );
           
            $context['list_users_chat'][$row['member_name']] = $link . ' (' . ($row['ispublic'] != 'y' ? $txt['fc_private_room'] : $row['roomName']) . ')';
           
            // Groups online
            if (!isset($context['online_groups'][$row['id_group']]))
                $context['online_groups'][$row['id_group']] = array(
                    'id' => $row['id_group'],
                    'name' => $row['group_name'],
                    'color' => $row['online_color']
                );
        }
       $smcFunc['db_free_result'];
    }
    // --- End FlashChat Integration ---

--- End code ---

I don't know how that mod works, apparently it only performs the query if you are on the BoardIndex with no action.

Is there any error on your error log?

dooie:
I just did a test in Chat with two users in chat and no errors in the log.

Cheers.

Suki:
Are you viewing the chat box on the BoardIndex?

find this line:

if (!empty($modSettings['fc_showUsers']) || !empty($modSettings['fc_showUserCount']) || (empty($context['current_action']) || $context['current_action'] == 'boardindex' || $context['current_action'] == 'forum'))

and change it with:

// if (!empty($modSettings['fc_showUsers']) || !empty($modSettings['fc_showUserCount']) || (empty($context['current_action']) || $context['current_action'] == 'boardindex' || $context['current_action'] == 'forum'))

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version