Source for file ipbwi.inc.php
Documentation is available at ipbwi.inc.php
* @desc This file loads all IPBWI functions. Include this file to your
* php-scripts and load the ipbwi-class to use the functions.
* @author Matthias Reuter ($LastChangedBy: matthias $)
* @version $LastChangedDate: 2009-08-26 19:49:26 +0200 (Mi, 26 Aug 2009) $
* @copyright 2007-2010 IPBWI development team
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
require_once('config.inc.php');
// check if PHP version is 5 or higher
die('<p>ERROR: You need PHP 5 or higher to use IPBWI. Your current version is '. PHP_VERSION. '</p>');
// check if board path is set
if(!defined('ipbwi_BOARD_PATH') || ipbwi_BOARD_PATH == ''){
die('<p>ERROR: You have to define a board\'s path in your IPBWI config file.</p>');
// check if ipbwi path is set
if(!defined('ipbwi_ROOT_PATH') || ipbwi_ROOT_PATH == ''){
die('<p>ERROR: You have to define the root path of your IPBWI installation in your IPBWI config file.</p>');
const PROJECT_LEADER = 'Matthias Reuter';
const DEV_TEAM = 'Matthias Reuter';
const WEBSITE = 'http://ipbwi.com/';
const DOCS = 'http://docs.ipbwi.com/';
private static $lang = ipbwi_LANG;
private static $libLang = array();
protected static $ips = null;
private static $systemMessage = array();
* @desc Load's requested libraries dynamicly
* @param string $name library-name
* @return class object of the requested library
* @author Matthias Reuter
public function __get($name){
if(file_exists(ipbwi_ROOT_PATH. 'lib/'. $name. '.inc.php')){
require_once(ipbwi_ROOT_PATH. 'lib/'. $name. '.inc.php');
$classname = 'ipbwi_'. $name;
$this->$name = new $classname($this);
die('Class '. $name. ' could not be loaded (tried to load class-file '. ipbwi_ROOT_PATH. 'lib/'. $name. '.inc.php'. ')');
* @desc Loads and checks different vars when class is initiating
* @author Matthias Reuter
public function __construct(){
if(ipbwi_DB_prefix == ''){
define('ipbwi_DB_prefix','ipbwi_');
self::setLang(ipbwi_LANG);
// initialize IP.board Interface
require_once(ipbwi_ROOT_PATH. 'lib/ips_wrapper.inc.php');
if(!defined('IPBWI_INCORRECT_BOARD_PATH')){
$this->board = $this->ips_wrapper->settings;
//$this->board['version'] = &$this->ipbwi->ips_wrapper->version;
//$this->board['version_long'] = &$this->ipbwi->ips_wrapper->vn_full;
$this->board['url'] = str_replace('?','',$this->ips_wrapper->settings['board_url']). '/';
$this->board['name'] = $this->ips_wrapper->settings['board_name'];
$this->board['basedir'] = ipbwi_BOARD_PATH;
$this->board['upload_dir'] = $this->ips_wrapper->settings['upload_dir']. '/';
$this->board['upload_url'] = $this->ips_wrapper->settings['upload_url']. '/';
$this->board['home_name'] = $this->ips_wrapper->settings['home_name'];
$this->board['home_url'] = $this->ips_wrapper->settings['home_url']. '/';
$this->board['emo_url'] = str_replace('<#EMO_DIR#>','default',$this->ips_wrapper->settings['emoticons_url']). '/';
* @desc Set's current SDK language
* @param string $lang language-name
* @return true if language was loaded, otherwise false
* @author Matthias Reuter
public static function setLang($lang){
if(file_exists(ipbwi_ROOT_PATH. 'lib/lang/'. $lang. '.inc.php')){
if(include(ipbwi_ROOT_PATH. 'lib/lang/'. $lang. '.inc.php')){
// ipbwi_OVERWRITE_CHARSET
if(defined('ipbwi_OVERWRITE_LOCAL') && ipbwi_OVERWRITE_LOCAL !== false){
$local = ipbwi_OVERWRITE_LOCAL;
if(defined('ipbwi_OVERWRITE_ENCODING') && ipbwi_OVERWRITE_ENCODING !== false){
$encoding = ipbwi_OVERWRITE_ENCODING;
self::$libLang = $libLang;
// Can't include it. Return false.
self::addSystemMessage('Error','Language-File <strong>'. $lang. '</strong> exists, but can\'t be loaded');
// Doesn't exist. Invalid Language.
self::addSystemMessage('Error','Language-File <strong>'. $lang. '</strong> does not exist.');
* @desc gets the language-var from actual requested native language-bit
* @param string $var language-var-name
* @return native language bit or error msg
* @author Matthias Reuter
if(isset (self::$libLang[$var])){
if(defined('ipbwi_OVERWRITE_ENCODING') && ipbwi_OVERWRITE_ENCODING != ''){
return iconv('ISO-8859-1',ipbwi_OVERWRITE_ENCODING,self::$libLang[$var]);
return self::$libLang[$var];
return 'The requested libLang <strong>'. $var. '</strong> is not defined.';
* @desc gets the requested board-var
* @param string $var board-var-name
* @return board-var-value, returns false if not exists
* @author Matthias Reuter
if(isset ($this->board[$var])){
return $this->board[$var];
* @desc informations about the current IPBWI and PHP installation
* @return string HTML-code including the informations
* @author Matthias Reuter
if($this->member->isAdmin()){
<table border="0" cellpadding="3" width="600">
<tr class="h"><td><h1 class="p">'. self::TITLE. '</h1></td></tr>
<table border="0" cellpadding="3" width="600">
<tr><td class="e">Default Language:</td><td class="v">'. ipbwi_LANG. '</td></tr>
<tr><td class="e">Current Language:</td><td class="v">'. self::$lang. '</td></tr>
<tr><td class="e">IPBWI Version:</td><td class="v">'. self::VERSION. '</td></tr>
<tr><td class="e">IPBWI Website:</td><td class="v">'. self::WEBSITE. '</td></tr>
<tr><td class="e">Project Leader:</td><td class="v">'. self::PROJECT_LEADER. '</td></tr>
<tr><td class="e">Development Team:</td><td class="v">'. self::DEV_TEAM. '</td></tr>
<table border="0" cellpadding="3" width="600">
<tr class="h"><td><h1 class="p">Invision Power Board</h1></td></tr>
<table border="0" cellpadding="3" width="600">
<tr><td class="e">Version</td><td class="v">'. $this->getBoardVar('version'). '</td></tr>
<tr><td class="e">Detailed Version</td><td class="v">'. $this->getBoardVar('version_long'). '</td></tr>
<tr><td class="e">URL</td><td class="v">'. $this->getBoardVar('url'). '</td></tr>
<tr><td class="e">Name</td><td class="v">'. $this->getBoardVar('name'). '</td></tr>
<tr><td class="e">Description</td><td class="v">'. $this->getBoardVar('desc'). '</td></tr>
<tr><td class="e">Base Directory</td><td class="v">'. $this->getBoardVar('basedir'). '</td></tr>
<tr><td class="e">Upload Directory</td><td class="v">'. $this->getBoardVar('upload_dir'). '</td></tr>
<tr><td class="e">Upload URL</td><td class="v">'. $this->getBoardVar('upload_url'). '</td></tr>
<tr><td class="e">Home Name</td><td class="v">'. $this->getBoardVar('home_name'). '</td></tr>
<tr><td class="e">Home URL</td><td class="v">'. $this->getBoardVar('home_url'). '</td></tr>
$this->addSystemMessage('Error',$this->getLibLang('noAdmin'),'Located in file <strong>'.__FILE__. '</strong> at class <strong>'.__CLASS__. '</strong> in function <strong>'.__FUNCTION__. '</strong> on line #<strong>'.__LINE__. '</strong>');
* @desc adds a system message
* @param string $level Message-Level, common levels: Notice, Error, Hidden
* @param string $message Message-Content
* @return bool this function always returns true
* @author Matthias Reuter
self::$systemMessage[$level][] = array(
* @desc prints system messages
* @param string $level Message-Level, common levels: Notice, Error, Hidden
* @return true HTML-Code containing requested messages
* @author Matthias Reuter
foreach(self::$systemMessage as $k => $levels){
if(($k == 'Hidden' && $this->member->isAdmin()) || $k != 'Hidden'){
$output .= '<strong>'. $this->getLibLang('sysMsg_'. $k). '</strong> '. $m['message']. (($i < count($levels) ? '<br />' : ''));
$output = '<div class="center"><table border="0" cellpadding="3">';
// specific message-level requested, print only this
if(isset ($level) && is_string($level) && is_array(self::$systemMessage) && count(self::$systemMessage[$level]) > 0){
if($level == 'Hidden' && !$this->member->isAdmin()){
}elseif($this->member->isAdmin()){
$hLocation = '<th>Location</th>';
$output .= '<tr class="h"><th colspan="2">IPBWI '. $level. 's</th>'. $hLocation. '</tr>';
foreach(self::$systemMessage[$level] as $m){
if($this->member->isAdmin()){
$location = '<td class="v">'. $m['location']. '</td>';
$output .= '<tr><td class="e">'. $this->getLibLang('sysMsg_'. $level). ' #'. $i. ':</td><td class="v">'. $m['message']. '</td>'. $location. '</tr>';
}elseif(is_array(self::$systemMessage) && count(self::$systemMessage) > 0){
foreach(self::$systemMessage as $k => $levels){
if(($k == 'Hidden' && $this->member->isAdmin()) || $k != 'Hidden'){
if($this->member->isAdmin()){
$hLocation = '<th>Location</th>';
$output .= '<tr class="h"><th colspan="2">IPBWI '. $k. 's</th>'. $hLocation. '</tr>';
if($this->member->isAdmin()){
$location = '<td class="v">'. $m['location']. '</td>';
$output .= '<tr><td class="e">'. $this->getLibLang('sysMsg_'. $k). ' #'. $i. ':</td><td class="v">'. $m['message']. '</td>'. $location. '</tr>';
$output .= '</table><br /></div>';
* @desc filtering html-strings, e.g. for db-queries
* @param string $var html-string
* @return proper and safe string
* @author Matthias Reuter
'/\\\$/', // replace $-var
if(defined('ipbwi_OVERWRITE_ENCODING') && ipbwi_OVERWRITE_ENCODING != ''){
$var = iconv(ipbwi_OVERWRITE_ENCODING,'ISO-8859-1',$var);
$var = iconv('UTF-8','ISO-8859-1',$var);
* @desc filtering HTML strings
* @param string $var html-string
* @return proper XHTML string
* @author Matthias Reuter
$var = preg_replace($search,$replace,$var);
if(defined('ipbwi_OVERWRITE_ENCODING') && ipbwi_OVERWRITE_ENCODING != ''){
$var = iconv('ISO-8859-1',ipbwi_OVERWRITE_ENCODING,$var);
$var = iconv('ISO-8859-1','UTF-8',$var);
* @desc Returns textual/timestamp offsetted date by board
* and by member offset and DST setting.
* @param int $timeStamp Numeric representation of the time beeing formatted
* @param string $dateFormat strftime() compliant format (see PHP manual)
* @param int $noBoard true = Offset with Board Time firstly, default = false
* @param int $noMember true = Bypass member's time offset and DST, default = false
* @return string formatted, localized date
* @author Matthias Reuter
* @author Cow <khlo@global-centre.com>
public function date($timeStamp = false, $dateFormat = '%A, %d. %B %Y @ %T', $noBoard = false, $noMember = false){
$info = $this->member->info();
// If theres no timestamp make it current time using time()
// Offset with Board Time firstly, if enabled
// Also Check no member offset
if(!$noMember && empty($info['time_offset'])){
$timeStamp = $timeStamp + ($this->ips_wrapper->settings['time_offset'] * 3600);
if($this->ips_wrapper->settings['time_adjust']){
$timeStamp = $timeStamp + ($this->ips_wrapper->settings['time_adjust'] * 60);
// If member has set an indiviual offset in the User CP
// because they may be in a totally different country
// using DST or whatever we can make those times affect it
// across the whole website as well :D
if($this->member->isLoggedIn() && !$noMember){
if($info['time_offset']){
$timeStamp = $timeStamp + ($info['time_offset'] * 3600);
$timeStamp = $timeStamp - 3600;
$timeStamp = strftime($dateFormat, $timeStamp);
die('<p>Error: You have to include and load IPBWI once only.</p>');
|