-
Notifications
You must be signed in to change notification settings - Fork 19
Wrapper
You can embed the Character Browser into your existing site or forums. You'll need to be familiar with PHP in order to do so. The rest of this article assumes you are knowledgeable of php.
Note: This is still under development so you'll possibly run into some issues. You're merging CharBrowser's php, html, css and javascript with your own pages code, so naming collisions are very likely to happen. Some of those collisions might require alteration to your site, or to CharBrowser. As they occur please let me know by posting here.
This is the demo charbrowser wrapped in the MQEmulator.net header/footer.
You install the same way as you would for a standard implementation. In fact, the users can simultaneously access the installation directy, with its native header and footer, while also being able to visit your wrapper script. E.G., they could visit this character from either of these URLS:
http://mysite.com/charbrowser/character.php?char=Athrogate
http://mysite.com/wrapped.php?page=character&char=Athrogate
You don't want to have a dozen different wrapper scripts pointing to the various pages in charbrowser, e.g. key_wrapper.php => charbrowser/keys.php, character_wrapper.php => charbrowser/characters.php. So instead you can specify which specific page to run using the 'page' GET parameter passed to index.php.
So, instead of linking to ./charbrowser/character.php?char=Athrogate, you can link to ./charbrowser/index.php?page=character&char=Athrogate. The charbrowser index.php script will parse the page parameter, and source in the target page with an include. In short, every part of the charbrowser tool can be viewed by accessing index.php; it's a focal point.
The valid values for 'page' are all the php script names in the root directory, e.g. 'keys' would point to 'keys.php'.
With this functionality you can now create your own PHP script, in another directory, and within it, do an include for charbrowsers index.php and all the charbrowser functionality will be available in your script:
include('charbrowser/index.php');
The front end HTML needs to be able to locate the project files so it can load the images and css from the charbrowser directory. CharBrowser can't do this automatically because it can't determine where your wrapper script is in relation to the CharBrowser install. Because of this you need to set charbrowser_root_url with the root URL to your charbrowser installation:
$charbrowser_root_url = "http://mysite.com/charbrowser/";
You will be outputting your own headers so you need to inform charbrowser that it should display the simple headers. That is done by setting the charbrowser_simple_header variable before you do your include:
$charbrowser_simple_header = true;
You need to inform charbrowser that it is being wrapped using the charbrowser_wrapped variable before you do your include:
$charbrowser_wrapped = true;
You can set the following value to true or false to override any permissions in config.php. If its false, it will use the config.php settings. If it is true, it will display all elements of every character. The intent of this is for you to use this variable to inherit your sites admin privledges. So when you wrap you use your sites architecture to grab a true/false for if this is a super user and set this variable equal to that value:
$charbrowser_is_admin_page = true;
For example, if you are wrapping CharBrowser in your PHPBB installation, you could do something like the following to give admins elevated privs when viewing character:
$charbrowser_is_admin_page = ( $userdata['user_level'] == ADMIN );
Above and below the include of the charbrowser index.php script you should implement your own sites header and footer. See the full example below.
This example is a phpbb implementation. The opening section prints the PHPBB header. The middle sets up the charbrowser variables and then includes the index script. The closing prints the PHPBB footer.
In this example charbrowser would be installed at http://mysite.com/charbrowser/ the forums would be installed at http://mysite.com/forums/ and the below script would be in the site root: http://mysite.com/cb_wrapper.php
<?php
//-----------------------------------------------
// PHPBB HEADER IMPLEMENTATION
//-----------------------------------------------
define('IN_PHPBB', true);
$phpbb_root_path = './forums/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
define('SHOW_ONLINE', true);
$page_title = 'Character Browser';
//FORUM HEADER
include($phpbb_root_path . 'includes/page_header.php');
//-----------------------------------------------
//CHARBROWSER IMPLEMENTATION START
//-----------------------------------------------
//url to the actual location of the charbrowser install
//this directory cant be hidden from the users and needs to be
//public viewable and accessible from a web browser
$charbrowser_root_url = "http://mysite.com/charbrowser/";
//turn the simple headers on (removes the <html>, <body>, etc.)
$charbrowser_simple_header = true;
//flag to let charbrowser know that it's being wrapped
//in a forum or other structure's header/footer
$charbrowser_wrapped = true;
//if this page is only viewable by an admin you can set
//this value to true, which will override all the display
//permissions in config.php. This effectively makes charbrowser
//inherit your sites account permissions. You could even modulate
//value with a conditional val. For example if your site has a
//fuction IsAdmin() that returns a true/false for if the
//current user is an admin, you could do:
//$charbrowser_is_admin_page = IsAdmin();
$charbrowser_is_admin_page = false;
//fire off the rendering of charbrowser using the relative
//path to the charbrowser's index.php
include('charbrowser/index.php');
//-----------------------------------------------
//CHARBROWSER IMPLEMENTATION FINISH
//-----------------------------------------------
//-----------------------------------------------
// PHPBB FOOTER IMPLEMENTATION
//-----------------------------------------------
include($phpbb_root_path . 'includes/page_tail.php');
?>
Contact
Live Demo: http://charbrowser.mqemulator.net/
Project forums: http://mqemulator.net/forum2/viewforum.php?f=20
Contact me: mqemulator@gmail.com