Customizing SMF > Tips and Tricks

[TUT] Create sweet chat rooms for your SMF using SimplePortal

(1/3) > >>

Mick.:
Chat room for SMF
I will show you how to create multiple chat rooms for your SMF installation. I've never been a big fan of the normal side block shoutbox. Instead, lets use the same shoutbox blocks but add them onto custom pages with a category to different rooms and who's in it.

Lets create 5 shout boxes, 5 custom PHP pages, 5 'Bottom" shoutbox blocks, 1 HTML "Right" block.

Demo: http://idesign360.com/community/index.php/page,page235.html

I've created 5 chat rooms for demo purposes.
-Entertainment
-Sports
-News
-Weather
-Teen Talk

You can create yours to suit your needs and as many as you wish.

Lets create 5 new shout boxes.
admin---->simpleportal--->shoutbox--->add shoutbox.

create as many as want. I made these...
-Entertainment
-Sports
-News
-Weather
-Teen Talk

Height: 300px  Shouts to display: 6   (I used 6 simply because i hate scroll bars).

Create 5 custom PHP pages and name them the same as your shoutboxes. That way is less confusing.
-Entertainment
-Sports
-News
-Weather
-Teen Talk

Tick no title and no body at the bottom.

Lets add the chat room title and some guts...

--- Code: ---echo '
    <br />
          <font color="#605e5e" font size="6" face="tahoma">Entertainment</font>
<hr />
      <br />';

global $context, $settings, $txt;

if (empty($context['SPortal']['page']['style']['no_title']))
{
echo '
<h3 class="', $context['SPortal']['page']['style']['title']['class'], '"', !empty($context['SPortal']['page']['style']['title']['style']) ? ' style="' . $context['SPortal']['page']['style']['title']['style'] . '"' : '', '><span class="left"></span>
', $context['SPortal']['page']['title'], '
</h3>';
}

if (!empty($settings['display_who_viewing']))
{
echo '
<p id="whoisviewing" class="smalltext">';

// Show just numbers...?
if ($settings['display_who_viewing'] == 1)
echo count($context['view_members']), ' ', count($context['view_members']) == 1 ? $txt['who_member'] : $txt['members'];
// Or show the actual people viewing the page?
else
echo empty($context['view_members_list']) ? '0 ' . $txt['members'] : implode(', ', $context['view_members_list']) . ((empty($context['view_num_hidden']) || $context['can_moderate_forum']) ? '' : ' (+ ' . $context['view_num_hidden'] . ' ' . $txt['hidden'] . ')');

// Now show how many guests are here too.
echo $txt['who_viewing_page'], '
</p>';
}
--- End code ---

You can change the color, size and font to suit your needs on line 3.  Repeat this process to the other custom pages and name them accordingly.

Lets create the shout box blocks and show them in our new custom pages.
-create 'bottom' shout box.
-advanced options,.... tick the custom page where your shout box block want to appear.
-Tick no title and no body.
-Save


In Themes/default/languages/SPortal.english.php

Add at the very end:

--- Code: ---$txt['who_viewing_page'] = ' are in this chat room.';
--- End code ---


In sourcedir/PortalPages.php

Find:
   
--- Code: ---global $smcFunc, $context, $txt, $scripturl, $sourcedir, $user_info;
--- End code ---

Replace with:
       
--- Code: --- global $smcFunc, $context, $txt, $scripturl, $sourcedir, $user_info, $settings;
--- End code ---


Find:
       
--- Code: --- $context['page_title'] = $context['SPortal']['page']['title'];
--- End code ---

Replace with:
       
--- Code: ---  if (!empty($settings['display_who_viewing']))
{
// Start out with no one at all viewing it.
$context['view_members'] = array();
$context['view_members_list'] = array();
$context['view_num_hidden'] = 0;

// Search for members who have this topic set in their GET data.
$request = $smcFunc['db_query']('', '
SELECT
lo.id_member, lo.log_time, lo.url, mem.real_name, mem.member_name, mem.show_online,
mg.online_color, mg.id_group, mg.group_name
FROM {db_prefix}log_online AS lo
LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lo.id_member)
LEFT JOIN {db_prefix}membergroups AS mg ON (mg.id_group = CASE WHEN mem.id_group = {int:reg_id_group} THEN mem.id_post_group ELSE mem.id_group END)
WHERE INSTR(lo.url, {string:in_url_string}) > 0 OR lo.session = {string:session}',
array(
'reg_id_group' => 0,
'in_url_string' => 's:4:"page";',
'session' => $user_info['is_guest'] ? 'ip' . $user_info['ip'] : session_id(),
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
if (empty($row['id_member']))
continue;
if (!preg_match('~s:4:"page";s:\d+:"([^"]+)";~', $row['url'], $match) || $match[1] != $page_id)
continue;

if (!empty($row['online_color']))
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '" style="color: ' . $row['online_color'] . ';">' . $row['real_name'] . '</a>';
else
$link = '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>';

$is_buddy = in_array($row['id_member'], $user_info['buddies']);
if ($is_buddy)
$link = '<strong>' . $link . '</strong>';

// Add them both to the list and to the more detailed list.
if (!empty($row['show_online']) || allowedTo('moderate_forum'))
$context['view_members_list'][$row['log_time'] . $row['member_name']] = empty($row['show_online']) ? '<em>' . $link . '</em>' : $link;
$context['view_members'][$row['log_time'] . $row['member_name']] = array(
'id' => $row['id_member'],
'username' => $row['member_name'],
'name' => $row['real_name'],
'group' => $row['id_group'],
'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
'link' => $link,
'is_buddy' => $is_buddy,
'hidden' => empty($row['show_online']),
);

if (empty($row['show_online']))
$context['view_num_hidden']++;
}

// The number of guests is equal to the rows minus the ones we actually used ;).
$context['view_num_guests'] = $smcFunc['db_num_rows']($request) - count($context['view_members']);
$smcFunc['db_free_result']($request);

// Sort the list.
krsort($context['view_members']);
krsort($context['view_members_list']);
}

$context['page_title'] = $context['SPortal']['page']['title'];
--- End code ---



Now lets add the category block.
-Create a 'Right' HTML block and name it: "Chatroom Categories".
Lets add the code.

--- Code: ---<br />
<font color="#605e5e" font size="6" face="tahoma">Categories</font>
<hr />
<br />
<ul class="reset">
    <li><strong><a href="http://idesign360.com/community/index.php/page,page235.html">Entertainment</a></strong></li>
    <li><strong><a href="http://idesign360.com/community/index.php/page,page596.html">News</a></strong></li>
    <li><strong><a href="http://idesign360.com/community/index.php/page,page4259.html">Sports</a></strong></li>
    <li><strong><a href="http://idesign360.com/community/index.php/page,page1845.html">Weather</a></strong></li>
    <li><strong><a href="http://idesign360.com/community/index.php/page,page4319.html">Teen Talk</a></strong</li>
</ul>

--- End code ---

For demo purposes, im using my links. Change them with your own.
-Not collapsible
-Advanced options, select all your custom pages.
-Tick: No title no body

Now lets create a direct link and add it to your forum menu.
Open:
Sources/Subs.php

Near the bottom of the file, youll find the menu buttons.

Find:

--- Code: --- 'search' => array(
'title' => $txt['search'],
'href' => $scripturl . '?action=search',
'show' => false,
'sub_buttons' => array(
),
),
--- End code ---

Add after:


--- Code: --- 'chat' => array(
'title' => 'Chat Rooms',
'href' => 'http://idesign360.com/community/index.php/page,page2862.html',
'show' => true,
'sub_buttons' => array(
),
),
--- End code ---
Replaced the URL with whichever chatroom you want to use as the landing page.

Thats it.  Have fun.

Mick.:
Grafitus over at simpleportal has a mod to show users on custom pages. I stripped it down to show these users in chat only.

Also the the first post above is re-written to PHP pages instead of HTML.   


It now show users in-chat. There Wolla! Now you have a reliable chatroom in your SMF installation.


Have fun.

watchhorse:
Is there a way to show at the forumindex how many members there are in the chatroom?

Mick.:

--- Quote from: watchhorse on March 06, 2012, 04:05:28 PM ---Is there a way to show at the forumindex how many members there are in the chatroom?

--- End quote ---
only if you create ONE chat room.

Founder 2008:
Excellently!  :)

Navigation

[0] Message Index

[#] Next page

Go to full version