Jump to content


Ipb Kit (work In Progress)


  • You cannot reply to this topic
6 replies to this topic

#1 Guest_xrepins_*

  • Guests

Posted 31 March 2006 - 10:12 PM

TRY THIS SNIPPET AT YOUR OWN RISK - THE IPB SDK DEVELOPMENT SEEMS TO HAVE STOPPED ... THEREFORE NO SUPPORT IS OFFERED



What is the IPB KIT?
The IPB Kit (IBK) is a collection of snippets and chunks, to be used IN CONJUNCTION WITH the IPBSDK class, to integrate your Etomite pages with your Invision Power Board database.

Terms of Use:
Frankly, I don't mind at all how you use it, extend it, etc. In fact, I welcome people extending it. However, I do insist that it isn't used by Etomite forkers to include within their own versions. This condition is absolute.

This is very much a work in progress, and in actual fact, I'm posting it here now more as a gauage of interest than anything else. I'll have to keep it topic based I'm afraid as it's quite convoluted.

Part One: The IBK Driver Snippet
This snippet is the main interface to the IPBSDK. It is called only by other snippets to connect with the IPBSDK and retrieve its functions.

Snippet Name Ibk_Driver

Snippet Code
/*----------------------------------------------------------------
 * SNIPPET_TITLE: Ipb_Kit_Driver
 * DESCRIPTION: IPBSDK Integration Driver Snippet
 *
 * RETURN: bool 1 Logged In | 0 Not Logged In
 *
 * Author: Maz
 *
 * LICENSE: Free for use with non-forked versions of Etomite CMS
 *--------------------------------------------------------------*/

//----------------------------------------------------
// Absolute path pointer to IPBSDK class file.
//----------------------------------------------------
$ibk_sdkpath = "/home/diectory/public_html/classes/class-ipbsdk.php";

//----------------------------------------------------
// IPB Group IDs to validate against.
//----------------------------------------------------
$ibk_authgroups = array(3,4);


if(!isset($GLOBALS['IPBLoggedIn']))
{
	include_once $ibk_sdkpath;
	$SDK =& new IPBSDK();
	
	$GLOBALS['SDK'] = $SDK;
	
	if ($GLOBALS['SDK']->is_loggedin())
	{
  if(!isset($GLOBALS['SDKMemberInfo']))
  {
 	 $GLOBALS['SDKMemberInfo'] = $GLOBALS['SDK']->get_info();
  }
		
  $group = $GLOBALS['SDKMemberInfo']['mgroup'];
  
  //----------------------------------------------------
  // Match IPBSDK group against authgroups array
  //----------------------------------------------------
  if(in_array($group, $ibk_authgroups))
  {
 	 $GLOBALS['IPBLoggedIn'] = 1;
 	 return 1;
  }
  else
  {
 	 $GLOBALS['IPBLoggedIn'] = 0;
 	 return 0;
  }
	}
	else
	{
  $GLOBALS['IPBLoggedIn'] = 0;
  return 0;
	}
}
else
{
	return $GLOBALS['IPBLoggedIn'];
}

Explantion: There are two user configurable settings here:

$ibk_sdkpath
Should be the absolute path to your IPBSDK file.

$ibk_authgroups = array(3,4);
An array of groups which are allowed to login. (Usually this might be just the "Member" and "Admin" group. However, you may have other groups, such as "Customers", etc.

Edited by Dean, 01 May 2007 - 08:22 AM.
added warning


#2 Guest_xrepins_*

  • Guests

Posted 31 March 2006 - 10:22 PM

Part 2: The Login Handler

Snippet Name: Ibk_LoginHandler

Description:
There's nothing Einsteinesque here really. We're passing the contents of a login form chunk and using the IPBSDK Login function to validate the credentials.

/*----------------------------------------------------------------
* SNIPPET_TITLE: Ibk_LoginHandler
* DESCRIPTION: Handles IPBSDK Login
*
* RETURN: Chunk
*
* Author: Maz
*
* LICENSE: Free for use with non-forked versions of Etomite CMS
*--------------------------------------------------------------*/

if($etomite->runSnippet('Ibk_Driver')==false)
{
	if(!isset($_POST['btn_submit']))
	{
  $docid = isset($_GET['docid']) ? $_GET['docid'] : "[~".$etomite->config['site_start']."~]";
  return str_replace("{DOCID}", $docid, $etomite->getChunk('Ibk_LoginForm'));
	}
	else
	{
  $username = $_POST['txt_name'];
  $password = $_POST['txt_password'];
  $doc = $_POST['docid'];
  
  if($login=$GLOBALS['SDK']->login($username, $password))
  {
 	 $GLOBALS['SDKMemberInfo']=$login;
 	 header("Location: ".$doc);
  }
  else
  {
 	 return $etomite->getChunk('LoginError').str_replace("{DOCID}", $docid, $etomite->getChunk('Ibk_LoginForm'));
  }
	}
}
else
{
	return "<p>You are already logged in!</p>";
}

return $etomite->getChunk('LoginError').str_replace("{DOCID}", $docid, $etomite->getChunk('Ibk_LoginForm'));


#3 Guest_xrepins_*

  • Guests

Posted 31 March 2006 - 10:32 PM

Part 3: Authorisation Display Choice

Snippet Name: Ibk_AuthChoice

Description:
Determines which chunk to display, based on whether the user is logged in or logged out. This is the snippet which must be included where you want your login form to appear.

if($etomite->runSnippet('Ibk_Driver')==false)
{
	return str_replace("{DOCID}", "[~".$etomite->documentIdentifier."~]", $etomite->getChunk('Ibk_LoggedOut'));
}
else
{
	$output = $etomite->getChunk('Ibk_LoggedIn');
	if(!isset($GLOBALS['SDKMemberInfo']))
	{
  $GLOBALS['SDKMemberInfo'] = $GLOBALS['SDK']->get_info();
	}
    return $output;
}

Add [!Ibk_AuthChoice!] to your template or page where you want the login/logged_in form to appear.

Edited by xrepins, 31 March 2006 - 10:34 PM.


#4 Guest_xrepins_*

  • Guests

Posted 31 March 2006 - 10:55 PM

Part 4: Logout Handler

Snippet Name: ibk_LogoutHandler

Description:
Interface to the IPBSDK Logout Function.

/*----------------------------------------------------------------
* SNIPPET_TITLE: Ibk_LogoutHandler
* DESCRIPTION: Handles IPBSDK Logout
*
* RETURN: void
*
* Author: Maz
*
* LICENSE: Free for use with non-forked versions of Etomite CMS
*--------------------------------------------------------------*/

if($etomite->runSnippet('Ibk_Driver')==true)
{
	$GLOBALS['SDK']->logout();
}


#5 Guest_xrepins_*

  • Guests

Posted 31 March 2006 - 11:09 PM

Part 5: Logged In Chunk

Chunk Title: Ibk_LoggedIn

Description:
Displays a section to the user when logged in. You should add your own content here, based on your own needs.

This sample merely shows a logout link, pointing to the page with an id of 21. (That page has the following content only)

[!Ibk_LogoutHandler!]

<p><a href="[~21~]" title="Log Out">Logout</a></p>

Edited by xrepins, 31 March 2006 - 11:09 PM.


#6 Dean

    Loves Etomite Forums!

  • Admin
  • 4,758 posts
  • Gender:Male

Posted 17 April 2006 - 01:55 PM

Missing Part

Snippet Name: Ibk_LoginForm

<form action="[~22~]" method="post">
<p>Username: <input type="text" name="txt_name" /></p>
<p>Password: <input type="password" name="txt_password" /></p>
<p><input type="Submit" value="Login" name="btn_submit" /><input type="hidden" name="docid" value="[~1~]"/></p>
</form>

Where [~22~] is the Page similar to [~21~] (above) that has [!Ibk_LoginHandler!] call on it.
Where [~1~] is listed, it is where you will get redirected to upon logging in.

#7 drewster4590

    Etomite Forum Newbie

  • Member
  • 6 posts

Posted 04 May 2006 - 03:22 AM

How would you go about showing the user name, avatar, and other information about the member along with the log out link?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users