Difference between revisions of "PhpBB integration"

From Mibbit Wiki
Jump to: navigation, search
(mibbit.php)
m (removed synirc)
 
(19 intermediate revisions by 8 users not shown)
Line 1: Line 1:
 +
{{Wikify|date=December 2009}}
 +
 
This MOD for [http://www.phpbb.com/ phpBB2/phpBB3]  uses username as the nickname for the user. However a Guest nickname is used if the nickname contains characters that are not valid within IRC.
 
This MOD for [http://www.phpbb.com/ phpBB2/phpBB3]  uses username as the nickname for the user. However a Guest nickname is used if the nickname contains characters that are not valid within IRC.
  
Line 6: Line 8:
 
<code><pre style="width:90%;max-height:300px;overflow:auto">FIND
 
<code><pre style="width:90%;max-height:300px;overflow:auto">FIND
 
===mibbit.php===
 
===mibbit.php===
<code><pre style="width:90%;max-height:300px;overflow:auto">
+
This file goes to the root of your phpBB installation. Remember to change the channel and server!
<?php
+
 
 +
<code><pre style="width:90%;max-height:300px;overflow:auto"><?php
  
 
define('IN_PHPBB', true);
 
define('IN_PHPBB', true);
 
$phpbb_root_path = './';
 
$phpbb_root_path = './';
// set this as the path to your phpBB installation
 
 
include($phpbb_root_path . 'extension.inc');
 
include($phpbb_root_path . 'extension.inc');
 
include($phpbb_root_path . 'common.'.$phpEx);
 
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . '/includes/functions_user.'.$phpEx);
 
 
  
 
//
 
//
 
// Start session management
 
// Start session management
 
//
 
//
$user->session_begin();
+
$userdata = session_pagestart($user_ip, PAGE_INDEX);
$auth->acl($user->data);
+
init_userprefs($userdata);
$userdata = $user->data;
 
 
 
 
//
 
//
 
// End session management
 
// End session management
Line 30: Line 28:
 
function is_valid_nickname($nickname)
 
function is_valid_nickname($nickname)
 
{
 
{
        if($nickname != '')
+
if($nickname != '')
        {
+
{
                for($i = 0, $maxi = strlen($nickname); $i < $maxi; $i++)
+
for($i = 0, $maxi = strlen($nickname); $i < $maxi; $i++)
                {
+
{
                        $code = ord($nickname[$i]);
+
$code = ord($nickname[$i]);
                        if( !(($i > 0 && ( $code == 45 || ($code >= 48 && $code <= 57) )) || ($code >= 65 && $code <= 125)) ) break;
+
if( !(($i > 0 && ( $code == 45 || ($code >= 48 && $code <= 57) )) || ($code >= 65 && $code <= 125)) ) break;
                }
+
}
                return ($i == $maxi);
+
return ($i == $maxi);
        }
+
}
 
}
 
}
  
if($user->data['user_id'] != ANONYMOUS)
+
if($userdata['session_logged_in'])
 
{
 
{
        $nickname = is_valid_nickname($user->data['username']) ? $user->data['username'] : '';
+
$nickname = is_valid_nickname($userdata['username']) ? $userdata['username'] : '';
 
}
 
}
 
else
 
else
 
{
 
{
        $nickname = '';
+
$nickname = '';
 
}
 
}
  
 
if( !is_valid_nickname($nickname) )
 
if( !is_valid_nickname($nickname) )
 
{
 
{
        $nickname = 'CoTGuest_'.chr(mt_rand(65, 90)).chr(mt_rand(97, 122)).chr(mt_rand(97, 122));
+
$nickname = 'Guest_'.chr(mt_rand(65, 90)).chr(mt_rand(97, 122)).chr(mt_rand(97, 122));
 
}
 
}
  
$uri = 'http://embed.mibbit.com/?nick='.$nickname
+
$uri = 'http://widget.mibbit.com/?nick='.$nickname
        .'&chatOutputShowTimes=true'
+
.'&amp;chatOutputShowTimes=true'
        .'&server=de.quakenet.org:6667' // replace server and port with matching information
+
.'&amp;server=irc.server.net:6667' // replace irc.server.net and 6667 (port) with matching information
        .'&chatOutputShowTimes=true'
+
.'&amp;channel=%23yourChan'; // replace yourChan with the name of your channel
        .'&needSendButton=false'
 
        .'&userListFontSize=12'
 
        .'&noServerTab=false'
 
        .'&channel=%23cot-guild.org'; // replace channel with the name of your channel
 
  
 
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 
<html>
 
<html>
  <head>
+
<head>
        <title>IRC</title>
+
<title>IRC</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
+
<meta http-equiv="content-type" content="text/html; charset=utf-8">
        <style type="text/css">
+
<style type="text/css">
                html,body,iframe { border: 0; height: 100%; margin: 0; overflow: hidden; padding: 0; }
+
html,body,iframe { border: 0; height: 100%; margin: 0; overflow: hidden; padding: 0; }
                iframe { height: 100%; width: 100%; }
+
iframe { height: 100%; width: 100%; }
        </style>
+
</style>
  </head>
+
</head>
  <body>
+
<body>
    <iframe src="<?php echo $uri; ?>" frameborder="0"><h1><a href="<?php echo $uri; ?>">Open IRC channel</a></h1></iframe>
+
<iframe src="<?php echo $uri; ?>" frameborder="0"><h1><a href="<?php echo $uri; ?>">Open IRC channel</a></h1></iframe>
  </body>
 
</html></code>
 
 
 
<h1><a href="<?php echo $uri; ?>">Open IRC channel</a></h1></iframe>
 
  </body>
 
</html></code>
 
 
 
<h1><a href="<?php echo $uri; ?>">Open IRC channel</a></h1></iframe>
 
 
</body>
 
</body>
 
</html></pre></code>
 
</html></pre></code>
Line 89: Line 75:
  
 
== phpBB3 Integration==
 
== phpBB3 Integration==
 +
 
===Editing styles/subsilver2/template/overall_header.php===
 
===Editing styles/subsilver2/template/overall_header.php===
 
<code><pre style="width:90%;max-height:300px;overflow:auto">FIND
 
<code><pre style="width:90%;max-height:300px;overflow:auto">FIND
Line 104: Line 91:
 
<?php
 
<?php
  
 +
$phpEx = 'php'; // Added to define the variable as the appropriate extension, no extension.inc file in phpBB3
 
define('IN_PHPBB', true);
 
define('IN_PHPBB', true);
$phpbb_root_path = './';
+
$phpbb_root_path = '/rootpath/directory/'; // set this as the path to your phpBB installation
// set this as the path to your phpBB installation
+
// include($phpbb_root_path . 'extension.inc'); // This is no longer valid. phpBB3 no longer utilizes extension.inc
include($phpbb_root_path . 'extension.inc');
 
 
include($phpbb_root_path . 'common.'.$phpEx);
 
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . '/includes/functions_user.'.$phpEx);
+
include($phpbb_root_path . 'includes/functions_user.'.$phpEx);
  
  
Line 150: Line 137:
 
}
 
}
  
$uri = 'http://embed.mibbit.com/?nick='.$nickname
+
$uri = 'http://widget.mibbit.com/?nick='.$nickname
        .'&chatOutputShowTimes=true'
+
         .'&server=irc.sorcery.net%3A6667' // replace server and port with matching information
         .'&server=de.quakenet.org:6667' // replace server and port with matching information
 
        .'&chatOutputShowTimes=true'
 
        .'&needSendButton=false'
 
        .'&userListFontSize=12'
 
 
         .'&noServerTab=false'
 
         .'&noServerTab=false'
         .'&channel=%23cot-guild.org'; // replace channel with the name of your channel
+
         .'&channel=%23chat'; // replace channel with the name of your channel. '%23' is the '#' before most irc channel names.
  
 
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
Line 171: Line 154:
 
   <body>
 
   <body>
 
     <iframe src="<?php echo $uri; ?>" frameborder="0"><h1><a href="<?php echo $uri; ?>">Open IRC channel</a></h1></iframe>
 
     <iframe src="<?php echo $uri; ?>" frameborder="0"><h1><a href="<?php echo $uri; ?>">Open IRC channel</a></h1></iframe>
  </body>
+
 
 +
<h1><a href="<?php echo $uri; ?>">Open IRC channel</a></h1>
 +
</body>
 
</html>
 
</html>
 +
 
</pre></code>
 
</pre></code>
  
Line 187: Line 173:
  
 
<code><nowiki>$nickname = is_valid_nickname($userdata['irc_nickname']) ? $userdata['irc_nickname'] : $userdata['username'];</nowiki></code>
 
<code><nowiki>$nickname = is_valid_nickname($userdata['irc_nickname']) ? $userdata['irc_nickname'] : $userdata['username'];</nowiki></code>
 +
 +
[[Category:How To]]
 +
[[Category:Code]]
 +
{{DEFAULTSORT:Phpbb Integration}}

Latest revision as of 16:58, 10 March 2010


This MOD for phpBB2/phpBB3 uses username as the nickname for the user. However a Guest nickname is used if the nickname contains characters that are not valid within IRC.

phpBB2 Integration

Editing templates/subSilver/overall_header.php

FIND
===mibbit.php===
This file goes to the root of your phpBB installation. Remember to change the channel and server!

<code><pre style="width:90%;max-height:300px;overflow:auto"><?php

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//

function is_valid_nickname($nickname)
{
	if($nickname != '')
	{
		for($i = 0, $maxi = strlen($nickname); $i < $maxi; $i++)
		{
			$code = ord($nickname[$i]);
			if( !(($i > 0 && ( $code == 45 || ($code >= 48 && $code <= 57) )) || ($code >= 65 && $code <= 125)) ) break;
		}
		return ($i == $maxi);
	}
}

if($userdata['session_logged_in'])
{
	$nickname = is_valid_nickname($userdata['username']) ? $userdata['username'] : '';
}
else
{
	$nickname = '';
}

if( !is_valid_nickname($nickname) )
{
	$nickname = 'Guest_'.chr(mt_rand(65, 90)).chr(mt_rand(97, 122)).chr(mt_rand(97, 122));
}

$uri = 'http://widget.mibbit.com/?nick='.$nickname
	.'&chatOutputShowTimes=true'
	.'&server=irc.server.net:6667' // replace irc.server.net and 6667 (port) with matching information
	.'&channel=%23yourChan'; // replace yourChan with the name of your channel

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>IRC</title>
		<meta http-equiv="content-type" content="text/html; charset=utf-8">
		<style type="text/css">
html,body,iframe { border: 0; height: 100%; margin: 0; overflow: hidden; padding: 0; }
iframe { height: 100%; width: 100%; }
		</style>
	</head>
	<body>
		<iframe src="<?php echo $uri; ?>" frameborder="0"><h1><a href="<?php echo $uri; ?>">Open IRC channel</a></h1></iframe>
	</body>
</html>


phpBB3 Integration

Editing styles/subsilver2/template/overall_header.php

FIND
====
<!-- IF S_USER_LOGGED_IN -->   <a href="{U_PROFILE}"><img src="{T_THEME_PATH}/images/icon_mini_profile.gif" width="12" height="13" alt="*" /> {L_PROFILE}</a><!-- ENDIF -->

INLINE, BEFORE ADD
==================
<!-- IF S_USER_LOGGED_IN -->   <a href="mibbit.php">IRC</a><!-- ENDIF -->


mibbit.php

<?php

$phpEx = 'php'; // Added to define the variable as the appropriate extension, no extension.inc file in phpBB3
define('IN_PHPBB', true);
$phpbb_root_path = '/rootpath/directory/'; // set this as the path to your phpBB installation
// include($phpbb_root_path . 'extension.inc'); // This is no longer valid. phpBB3 no longer utilizes extension.inc
include($phpbb_root_path . 'common.'.$phpEx);
include($phpbb_root_path . 'includes/functions_user.'.$phpEx);


//
// Start session management
//
$user->session_begin();
$auth->acl($user->data);
$userdata = $user->data;

//
// End session management
//

function is_valid_nickname($nickname)
{
        if($nickname != '')
        {
                for($i = 0, $maxi = strlen($nickname); $i < $maxi; $i++)
                {
                        $code = ord($nickname[$i]);
                        if( !(($i > 0 && ( $code == 45 || ($code >= 48 && $code <= 57) )) || ($code >= 65 && $code <= 125)) ) break;
                }
                return ($i == $maxi);
        }
}

if($user->data['user_id'] != ANONYMOUS)
{
        $nickname = is_valid_nickname($user->data['username']) ? $user->data['username'] : '';
}
else
{
        $nickname = '';
}

if( !is_valid_nickname($nickname) )
{
        $nickname = 'CoTGuest_'.chr(mt_rand(65, 90)).chr(mt_rand(97, 122)).chr(mt_rand(97, 122));
}

$uri = 'http://widget.mibbit.com/?nick='.$nickname
        .'&server=irc.sorcery.net%3A6667' // replace server and port with matching information
        .'&noServerTab=false'
        .'&channel=%23chat'; // replace channel with the name of your channel. '%23' is the '#' before most irc channel names.

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
   <head>
        <title>IRC</title>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <style type="text/css">
                html,body,iframe { border: 0; height: 100%; margin: 0; overflow: hidden; padding: 0; }
                iframe { height: 100%; width: 100%; }
        </style>
   </head>
   <body>
     <iframe src="<?php echo $uri; ?>" frameborder="0"><h1><a href="<?php echo $uri; ?>">Open IRC channel</a></h1></iframe>

<h1><a href="<?php echo $uri; ?>">Open IRC channel</a></h1>
	</body>
</html>

Customizing

If you add a new profile field or already have a MOD in your forum that allows you to use a valid IRC nickname, you may easily modify the nickname line:

$nickname = is_valid_nickname($userdata['username']) ? $userdata['username'] : '';

To:

$nickname = is_valid_nickname($userdata['username']) ? $userdata['username'] : $userdata['irc_nickname'];

Where 'irc_nickname' is the name of the profile field. You may also switch things around if you prefer IRC nickname over the forum username:

$nickname = is_valid_nickname($userdata['irc_nickname']) ? $userdata['irc_nickname'] : $userdata['username'];