SimplePortal

Customization => Custom Coding => Topic started by: Mick. on March 21, 2012, 12:57:25 PM

Title: [TUT] Creating sweet chat rooms for your SMF using SimplePortal
Post by: Mick. on March 21, 2012, 12:57:25 PM
(http://www.bluedevilcustoms.com/community/images/chatroom.png)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://www.bluedevilcustoms.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: [Select]
echo'
    <br />
          <font color="#605e5e"><font size="6" face="tahoma">Entertainment</font></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:
Code: [Select]
$txt['who_viewing_page'] = ' are in this chat room.';

In sourcedir/PortalPages.php

Find:
   
Code: [Select]
global $smcFunc, $context, $txt, $scripturl, $sourcedir, $user_info;
Replace with:
       
Code: [Select]
global $smcFunc, $context, $txt, $scripturl, $sourcedir, $user_info, $settings;

Find:
       
Code: [Select]
$context['page_title'] = $context['SPortal']['page']['title'];
Replace with:
       
Code: [Select]
  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.
Code: [Select]
<br />
<font color="#605e5e"><font size="6" face="tahoma">Categories</font></font>
<hr \>
<br \>
<ul>
    <li><strong><a href="http://www.bluedevilcustoms.com/community/index.php/page,page235.html">Entertainment</a></strong></li>
    <li><strong><a href="http://www.bluedevilcustoms.com/community/index.php/page,page596.html">News</a></strong></li>
    <li><strong><a href="http://www.bluedevilcustoms.com/community/index.php/page,page4259.html">Sports</a></strong></li>
    <li><strong><a href="http://www.bluedevilcustoms.com/community/index.php/page,page1845.html">Weather</a></strong></li>
    <li><strong><a href="http://www.bluedevilcustoms.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:
Code: [Select]
'search' => array(
'title' => $txt['search'],
'href' => $scripturl . '?action=search',
'show' => false,
'sub_buttons' => array(
),
),

Add after:

Code: [Select]
'chat' => array(
'title' => 'Chat Rooms',
'href' => 'http://www.bluedevilcustoms.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] Creating sweet chat rooms for your SMF using SimplePortal
Post by: [SiNaN] on March 21, 2012, 01:24:24 PM
Good. You could also try improving this code:

http://simpleportal.net/index.php?topic=10732.msg55637#msg55637
Title: Re: [TUT] Creating sweet chat rooms for your SMF using SimplePortal
Post by: Mick. on March 21, 2012, 03:02:59 PM
Well hell lol....

I'll take a look. Looks cool. By looking at the pic I'd rather have the categories listed instead of drop downs.  Lol I hate drop downs .  Hahahaha
Title: Re: [TUT] Creating sweet chat rooms for your SMF using SimplePortal
Post by: AngelinaBelle on March 22, 2012, 03:48:05 PM
That's a nice tutorial.  Are you back to using SimplePortal again?
Title: Re: [TUT] Creating sweet chat rooms for your SMF using SimplePortal
Post by: Mick. on March 23, 2012, 07:59:38 AM
That's a nice tutorial.  Are you back to using SimplePortal again?
All my sites use SP :nervous-happy: but one.
Title: Re: [TUT] Creating sweet chat rooms for your SMF using SimplePortal
Post by: Saffzuk on July 31, 2012, 12:36:22 PM
I have used this and it works perfectly with SMF 2.0.2 and SP 2.3.5  :nervous-happy:
Title: Re: [TUT] Creating sweet chat rooms for your SMF using SimplePortal
Post by: mlthmp on June 25, 2013, 07:07:49 PM
I know this is an older topic, but does anyone know how to make this work with 2.0.4 and SP 2.3.5 ? Whenever I try to make the php pages I get " Database error in block code. Please check the code. "
SimplePortal 2.3.8 © 2008-2024, SimplePortal