Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Mick. on January 22, 2012, 07:09:48 PM

Title: [TUT] Create sweet chat rooms for your SMF using SimplePortal
Post by: Mick. on January 22, 2012, 07:09:48 PM
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...

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>';
}


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:
$txt['who_viewing_page'] = ' are in this chat room.';


In sourcedir/PortalPages.php

Find:
   global $smcFunc, $context, $txt, $scripturl, $sourcedir, $user_info;

Replace with:
        global $smcFunc, $context, $txt, $scripturl, $sourcedir, $user_info, $settings;


Find:
        $context['page_title'] = $context['SPortal']['page']['title'];

Replace with:
          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'];




Now lets add the category block.
-Create a 'Right' HTML block and name it: "Chatroom Categories".
Lets add the 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>


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:
'search' => array(
'title' => $txt['search'],
'href' => $scripturl . '?action=search',
'show' => false,
'sub_buttons' => array(
),
),


Add after:

'chat' => array(
'title' => 'Chat Rooms',
'href' => 'http://idesign360.com/community/index.php/page,page2862.html',
'show' => true,
'sub_buttons' => array(
),
),

Replaced the URL with whichever chatroom you want to use as the landing page.

Thats it.  Have fun.
Title: Re: [TUT] Create sweet chat rooms for your SMF using SimplePortal
Post by: Mick. on January 24, 2012, 05:19:22 PM
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.
Title: Re: [TUT] Create sweet chat rooms for your SMF using SimplePortal
Post by: 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?
Title: Re: [TUT] Create sweet chat rooms for your SMF using SimplePortal
Post by: Mick. on March 21, 2012, 12:36:17 PM
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?
only if you create ONE chat room.
Title: Re: [TUT] Create sweet chat rooms for your SMF using SimplePortal
Post by: Founder 2008 on March 24, 2012, 08:22:32 PM
Excellently!  :)
Title: Re: [TUT] Create sweet chat rooms for your SMF using SimplePortal
Post by: Mick. on March 26, 2012, 09:57:23 AM
Quote from: Čarobnjak on March 24, 2012, 08:22:32 PM
Excellently!  :)
and the best thing is, no need to chase down bugs. This is a very reliable way for chat ;)
Title: Re: [TUT] Create sweet chat rooms for your SMF using SimplePortal
Post by: enik on March 27, 2012, 09:25:11 PM
Good tip thanks for share  ;)

Regards enik...
Title: Re: [TUT] Create sweet chat rooms for your SMF using SimplePortal
Post by: Biology Forums on March 28, 2012, 09:01:11 PM
Great idea, thanks for sharing it.
Title: Re: [TUT] Create sweet chat rooms for your SMF using SimplePortal
Post by: tMicky on September 17, 2012, 05:36:49 PM
Excellent tutorial.

Thank you :)
Title: Re: [TUT] Create sweet chat rooms for your SMF using SimplePortal
Post by: mlthmp on June 19, 2013, 11:27:06 PM
Old topic I know, but does anyone know how to make this work with 2 0 4 ?

*EDIT*

For example, when I try and create the custom PHP page; I get the following error upon trying to save,


"Database error in block code. Please check the code."
Title: Re: [TUT] Create sweet chat rooms for your SMF using SimplePortal
Post by: Biology Forums on June 20, 2013, 10:34:42 AM
This is cool, I never knew you could create multiple shoutboxes with SimplePortal.