IPBWI
[ class tree: IPBWI ] [ index: IPBWI ] [ all elements ]

Source for file ipbwi.inc.php

Documentation is available at ipbwi.inc.php

  1. <?php
  2.     /**
  3.      * @desc            This file loads all IPBWI functions. Include this file to your
  4.      *                      php-scripts and load the ipbwi-class to use the functions.
  5.      * @author            Matthias Reuter ($LastChangedBy: matthias $)
  6.      * @version            $LastChangedDate: 2009-08-26 19:49:26 +0200 (Mi, 26 Aug 2009) $
  7.      * @package            IPBWI
  8.      * @copyright        2007-2010 IPBWI development team
  9.      * @link            http://ipbwi.com
  10.      * @since            2.0
  11.      * @license            http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License
  12.      */
  13.     // load config file
  14.     require_once('config.inc.php');
  15.     // check if PHP version is 5 or higher
  16.     if(version_compare(PHP_VERSION,'5.0.0','<')){
  17.         die('<p>ERROR: You need PHP 5 or higher to use IPBWI. Your current version is '.PHP_VERSION.'</p>');
  18.     }
  19.     // check if board path is set
  20.     if(!defined('ipbwi_BOARD_PATH'|| ipbwi_BOARD_PATH == ''){
  21.         die('<p>ERROR: You have to define a board\'s path in your IPBWI config file.</p>');
  22.     }
  23.     // check if ipbwi path is set
  24.     if(!defined('ipbwi_ROOT_PATH'|| ipbwi_ROOT_PATH == ''){
  25.         die('<p>ERROR: You have to define the root path of your IPBWI installation in your IPBWI config file.</p>');
  26.     }
  27.     class ipbwi {
  28.         const                 VERSION            '3.005';
  29.         const                 TITLE            'IPBWI';
  30.         const                 PROJECT_LEADER    'Matthias Reuter';
  31.         const                 DEV_TEAM        'Matthias Reuter';
  32.         const                 WEBSITE            'http://ipbwi.com/';
  33.         const                 DOCS            'http://docs.ipbwi.com/';
  34.         private static        $lang            ipbwi_LANG;
  35.         private static        $libLang        array();
  36.         protected static    $ips            null;
  37.         protected            $common            = array();
  38.         private static         $systemMessage    array();
  39.         protected             $board            = array();
  40.         public                $DBlog            = null;
  41.         /**
  42.          * @desc            Load's requested libraries dynamicly
  43.          * @param    string    $name library-name
  44.          * @return            class object of the requested library
  45.          * @author            Matthias Reuter
  46.          * @since            2.0
  47.          * @ignore
  48.          */
  49.         public function __get($name){
  50.             if(file_exists(ipbwi_ROOT_PATH.'lib/'.$name.'.inc.php')){
  51.                 require_once(ipbwi_ROOT_PATH.'lib/'.$name.'.inc.php');
  52.                 $classname 'ipbwi_'.$name;
  53.                 $this->$name new $classname($this);
  54.                 return $this->$name;
  55.             }else{
  56.                 die('Class '.$name.' could not be loaded (tried to load class-file '.ipbwi_ROOT_PATH.'lib/'.$name.'.inc.php'.')');
  57.             }
  58.         }
  59.         /**
  60.          * @desc            Loads and checks different vars when class is initiating
  61.          * @author            Matthias Reuter
  62.          * @since            2.0
  63.          * @ignore
  64.          */
  65.         public function __construct(){
  66.             // check for DB prefix
  67.             if(ipbwi_DB_prefix == ''){
  68.                 define('ipbwi_DB_prefix','ipbwi_');
  69.             }
  70.             if(defined('ipbwi_LANG')){
  71.                 self::setLang(ipbwi_LANG);
  72.             }else{
  73.                 self::setLang('en');
  74.             }
  75.             
  76.             // initialize IP.board Interface
  77.             require_once(ipbwi_ROOT_PATH.'lib/ips_wrapper.inc.php');
  78.             if(!defined('IPBWI_INCORRECT_BOARD_PATH')){
  79.                 $this->ips_wrapper new ipbwi_ips_wrapper();
  80.                 
  81.                 // retrieve common vars
  82.                 $this->board                    = $this->ips_wrapper->settings;
  83.                 //$this->board['version']        = &$this->ipbwi->ips_wrapper->version;
  84.                 //$this->board['version_long']    = &$this->ipbwi->ips_wrapper->vn_full;
  85.                 $this->board['url']                str_replace('?','',$this->ips_wrapper->settings['board_url']).'/';
  86.                 $this->board['name']            $this->ips_wrapper->settings['board_name'];
  87.                 $this->board['basedir']            ipbwi_BOARD_PATH;
  88.                 $this->board['upload_dir']        $this->ips_wrapper->settings['upload_dir'].'/';
  89.                 $this->board['upload_url']        $this->ips_wrapper->settings['upload_url'].'/';
  90.                 $this->board['home_name']        $this->ips_wrapper->settings['home_name'];
  91.                 $this->board['home_url']        $this->ips_wrapper->settings['home_url'].'/';
  92.                 $this->board['emo_url']            str_replace('<#EMO_DIR#>','default',$this->ips_wrapper->settings['emoticons_url']).'/';
  93.             }
  94.         }
  95.         public function __destruct({
  96.         }
  97.         /**
  98.          * @desc            Set's current SDK language
  99.          * @param    string    $lang language-name
  100.          * @return            true if language was loaded, otherwise false
  101.          * @author            Matthias Reuter
  102.          * @since            2.0
  103.          */
  104.         public static function setLang($lang){
  105.             $libLang array();
  106.             if(file_exists(ipbwi_ROOT_PATH.'lib/lang/'.$lang.'.inc.php')){
  107.                 if(include(ipbwi_ROOT_PATH.'lib/lang/'.$lang.'.inc.php')){
  108. //                    ipbwi_OVERWRITE_LOCAL
  109. //                    ipbwi_OVERWRITE_CHARSET
  110.                     if(ipbwi_UTF8){
  111.                         $encoding 'UTF-8';
  112.                     }
  113.                     if(defined('ipbwi_OVERWRITE_LOCAL'&& ipbwi_OVERWRITE_LOCAL !== false){
  114.                         $local ipbwi_OVERWRITE_LOCAL;
  115.                     }
  116.                     if(defined('ipbwi_OVERWRITE_ENCODING'&& ipbwi_OVERWRITE_ENCODING !== false){
  117.                         $encoding ipbwi_OVERWRITE_ENCODING;
  118.                     }
  119.                     setlocale(LC_ALL"$local.$encoding");
  120.  
  121.                     // Change $this->lang,
  122.                     self::$lang        $lang;
  123.                     self::$libLang    $libLang;
  124.                     return true;
  125.                 }else{
  126.                     // Can't include it. Return false.
  127.                     self::addSystemMessage('Error','Language-File <strong>'.$lang.'</strong> exists, but can\'t be loaded');
  128.                     return false;
  129.                 }
  130.             }else{
  131.                 // Doesn't exist. Invalid Language.
  132.                 self::addSystemMessage('Error','Language-File <strong>'.$lang.'</strong> does not exist.');
  133.                 return false;
  134.             }
  135.         }
  136.         /**
  137.          * @desc            gets the language-var from actual requested native language-bit
  138.          * @param    string    $var language-var-name
  139.          * @return            native language bit or error msg
  140.          * @author            Matthias Reuter
  141.          * @since            2.0
  142.          */
  143.         public function getLibLang($var=false){
  144.             if(isset($var)){
  145.                 if(isset(self::$libLang[$var])){
  146.                     if(defined('ipbwi_OVERWRITE_ENCODING'&& ipbwi_OVERWRITE_ENCODING != ''){
  147.                         return iconv('ISO-8859-1',ipbwi_OVERWRITE_ENCODING,self::$libLang[$var]);
  148.                     }else{
  149.                         return self::$libLang[$var];
  150.                     }
  151.                 }else{
  152.                     return 'The requested libLang <strong>'.$var.'</strong> is not defined.';
  153.                 }
  154.             }else{
  155.                 return self::libLang;
  156.             }
  157.         }
  158.         /**
  159.          * @desc            gets the requested board-var
  160.          * @param    string    $var board-var-name
  161.          * @return            board-var-value, returns false if not exists
  162.          * @author            Matthias Reuter
  163.          * @since            2.0
  164.          */
  165.         public function getBoardVar($var){
  166.             if(isset($this->board[$var])){
  167.                 return $this->board[$var];
  168.             }else{
  169.                 return false;
  170.             }
  171.         }
  172.         /**
  173.          * @desc            informations about the current IPBWI and PHP installation
  174.          * @return    string    HTML-code including the informations
  175.          * @author            Matthias Reuter
  176.          * @since            2.0
  177.          */
  178.         public function sysInfo(){
  179.             if($this->member->isAdmin()){
  180.                 ob_start();
  181.                 phpinfo();
  182.                 $phpinfo ob_get_clean();
  183.                 return '
  184.                 <div class="center">
  185.                     <table border="0" cellpadding="3" width="600">
  186.                         <tr class="h"><td><h1 class="p">'.self::TITLE.'</h1></td></tr>
  187.                     </table><br />
  188.                     <table border="0" cellpadding="3" width="600">
  189.                         <tr><td class="e">Default Language:</td><td class="v">'.ipbwi_LANG.'</td></tr>
  190.                         <tr><td class="e">Current Language:</td><td class="v">'.self::$lang.'</td></tr>
  191.                         <tr><td class="e">IPBWI Version:</td><td class="v">'.self::VERSION.'</td></tr>
  192.                         <tr><td class="e">IPBWI Website:</td><td class="v">'.self::WEBSITE.'</td></tr>
  193.                         <tr><td class="e">Project Leader:</td><td class="v">'.self::PROJECT_LEADER.'</td></tr>
  194.                         <tr><td class="e">Development Team:</td><td class="v">'.self::DEV_TEAM.'</td></tr>
  195.                     </table><br />
  196.                 </div>
  197.                 <div class="center">
  198.                     <table border="0" cellpadding="3" width="600">
  199.                         <tr class="h"><td><h1 class="p">Invision Power Board</h1></td></tr>
  200.                     </table><br />
  201.                     <table border="0" cellpadding="3" width="600">
  202.                         <tr><td class="e">Version</td><td class="v">'.$this->getBoardVar('version').'</td></tr>
  203.                         <tr><td class="e">Detailed Version</td><td class="v">'.$this->getBoardVar('version_long').'</td></tr>
  204.                         <tr><td class="e">URL</td><td class="v">'.$this->getBoardVar('url').'</td></tr>
  205.                         <tr><td class="e">Name</td><td class="v">'.$this->getBoardVar('name').'</td></tr>
  206.                         <tr><td class="e">Description</td><td class="v">'.$this->getBoardVar('desc').'</td></tr>
  207.                         <tr><td class="e">Base Directory</td><td class="v">'.$this->getBoardVar('basedir').'</td></tr>
  208.                         <tr><td class="e">Upload Directory</td><td class="v">'.$this->getBoardVar('upload_dir').'</td></tr>
  209.                         <tr><td class="e">Upload URL</td><td class="v">'.$this->getBoardVar('upload_url').'</td></tr>
  210.                         <tr><td class="e">Home Name</td><td class="v">'.$this->getBoardVar('home_name').'</td></tr>
  211.                         <tr><td class="e">Home URL</td><td class="v">'.$this->getBoardVar('home_url').'</td></tr>
  212.                     </table><br />
  213.                 </div>
  214.                 '.$phpinfo;
  215.             }else{
  216.                 $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>');
  217.                 return false;
  218.             }
  219.         }
  220.         /**
  221.          * @desc            adds a system message
  222.          * @param    string    $level Message-Level, common levels: Notice, Error, Hidden
  223.          * @param    string    $message Message-Content
  224.          * @return    bool    this function always returns true
  225.          * @author            Matthias Reuter
  226.          * @since            2.0
  227.          */
  228.         public static function addSystemMessage($level,$message,$location=false){
  229.             self::$systemMessage[$level][array(
  230.                 'message' => $message,
  231.                 'location' => $location
  232.             );
  233.             return true;
  234.         }
  235.         /**
  236.          * @desc            prints system messages
  237.          * @param    string    $level Message-Level, common levels: Notice, Error, Hidden
  238.          * @return    true    HTML-Code containing requested messages
  239.          * @author            Matthias Reuter
  240.          * @since            2.0
  241.          */
  242.         public function printSystemMessages($level=false,$simple=false){
  243.             if($simple === true){
  244.                 $output '';
  245.                 foreach(self::$systemMessage as $k => $levels){
  246.                     if(($k == 'Hidden' && $this->member->isAdmin()) || $k != 'Hidden'){
  247.                         $i 1;
  248.                         foreach($levels as $m){
  249.                             $output .= '<strong>'.$this->getLibLang('sysMsg_'.$k).'</strong> '.$m['message'].(($i count($levels'<br />' ''));
  250.                             $i++;
  251.                         }
  252.                     }
  253.                 }
  254.             }else{
  255.                 $output '<div class="center"><table border="0" cellpadding="3">';
  256.                 // specific message-level requested, print only this
  257.                 if(isset($level&& is_string($level&& is_array(self::$systemMessage&& count(self::$systemMessage[$level]0){
  258.                     if($level == 'Hidden' && !$this->member->isAdmin()){
  259.                         return false;
  260.                     }elseif($this->member->isAdmin()){
  261.                         $hLocation '<th>Location</th>';
  262.                     }else{
  263.                         $hLocation false;
  264.                     }
  265.                     $output .= '<tr class="h"><th colspan="2">IPBWI '.$level.'s</th>'.$hLocation.'</tr>';
  266.                     $i 1;
  267.                     foreach(self::$systemMessage[$levelas $m){
  268.                         if($this->member->isAdmin()){
  269.                             $location '<td class="v">'.$m['location'].'</td>';
  270.                         }else{
  271.                             $location false;
  272.                         }
  273.                         $output .= '<tr><td class="e">'.$this->getLibLang('sysMsg_'.$level).' #'.$i.':</td><td class="v">'.$m['message'].'</td>'.$location.'</tr>';
  274.                         $i++;
  275.                     }
  276.                 }elseif(is_array(self::$systemMessage&& count(self::$systemMessage0){
  277.                     // print all messages
  278.                     $i 1;
  279.                     foreach(self::$systemMessage as $k => $levels){
  280.                         if(($k == 'Hidden' && $this->member->isAdmin()) || $k != 'Hidden'){
  281.                             if($this->member->isAdmin()){
  282.                                 $hLocation '<th>Location</th>';
  283.                             }else{
  284.                                 $hLocation '';
  285.                             }
  286.                             $output .= '<tr class="h"><th colspan="2">IPBWI '.$k.'s</th>'.$hLocation.'</tr>';
  287.                             $location    '';
  288.                             foreach($levels as $m){
  289.                                 if($this->member->isAdmin()){
  290.                                     $location '<td class="v">'.$m['location'].'</td>';
  291.                                 }
  292.                                 $output .= '<tr><td class="e">'.$this->getLibLang('sysMsg_'.$k).' #'.$i.':</td><td class="v">'.$m['message'].'</td>'.$location.'</tr>';
  293.                                 $i++;
  294.                             }
  295.                             $i 1;
  296.                         }
  297.                     }
  298.                 }else{
  299.                     return false;
  300.                 }
  301.                 $output .= '</table><br /></div>';
  302.             }
  303.             return $output;
  304.         }
  305.         /**
  306.          * @desc            filtering html-strings, e.g. for db-queries
  307.          * @param    string    $var html-string
  308.          * @return            proper and safe string
  309.          * @author            Matthias Reuter
  310.          * @since            2.0
  311.          */
  312.         public function makeSafe($var){
  313.             $var stripslashes($var);
  314.             $var trim($var);
  315.             $search array(
  316.                 '!',
  317.                 ' & ',
  318.                 '&#032;',
  319.                 "<br />\n",
  320.             );
  321.             $replace array(
  322.                 '&#33;',
  323.                 ' &amp; ',
  324.                 ' ',
  325.                 '<br />',
  326.             );
  327.             $var str_replace($search,$replace,$var);
  328.             $search array(
  329.                 '/\\\$/'// replace $-var
  330.             );
  331.             $replace array(
  332.                 '&#036;',
  333.             );
  334.             $var preg_replace($search,$replace,$var);
  335.             if(defined('ipbwi_OVERWRITE_ENCODING'&& ipbwi_OVERWRITE_ENCODING != ''){
  336.                 $var iconv(ipbwi_OVERWRITE_ENCODING,'ISO-8859-1',$var);
  337.             }elseif(ipbwi_UTF8){
  338.                 $var iconv('UTF-8','ISO-8859-1',$var);
  339.             }
  340.             $var addslashes($var);
  341.  
  342.             return $var;
  343.         }
  344.         /**
  345.          * @desc            filtering HTML strings
  346.          * @param    string    $var html-string
  347.          * @return            proper XHTML string
  348.          * @author            Matthias Reuter
  349.          * @since            2.0
  350.          */
  351.         public function properXHTML($var){
  352.             $search array(
  353.                 '<#EMO_DIR#>/',
  354.                 ' border="0"',
  355.                 ' target="_blank"',
  356.                 ' & '
  357.             );
  358.             $replace array(
  359.                 $this->skin->emoDir(),
  360.                 '',
  361.                 '',
  362.                 ' &amp; '
  363.             );
  364.             $var str_replace($search,$replace,$var);
  365. /*
  366.             $search = array(
  367.                 '/ emoid=\"(.*)\"/U',
  368.             );
  369.             $replace = array(
  370.                 '',
  371.             );
  372.             $var = preg_replace($search,$replace,$var);
  373. */
  374.             if(defined('ipbwi_OVERWRITE_ENCODING'&& ipbwi_OVERWRITE_ENCODING != ''){
  375.                 $var iconv('ISO-8859-1',ipbwi_OVERWRITE_ENCODING,$var);
  376.             }elseif(ipbwi_UTF8){
  377.                 $var iconv('ISO-8859-1','UTF-8',$var);
  378.             }
  379.             return $var;
  380.         }
  381.         /**
  382.          * @desc            Returns textual/timestamp offsetted date by board
  383.          *                      and by member offset and DST setting.
  384.          * @param    int        $timeStamp Numeric representation of the time beeing formatted
  385.          * @param    string    $dateFormat strftime() compliant format (see PHP manual)
  386.          * @param    int        $noBoard true = Offset with Board Time firstly, default = false
  387.          * @param    int        $noMember true = Bypass member's time offset and DST, default = false
  388.          * @return    string    formatted, localized date
  389.          * @author            Matthias Reuter
  390.          * @author            Cow <khlo@global-centre.com>
  391.          * @since            2.0
  392.          */
  393.         public function date($timeStamp false$dateFormat '%A, %d. %B %Y @ %T'$noBoard false$noMember false){
  394.             $info $this->member->info();
  395.             // If theres no timestamp make it current time using time()
  396.             if(!$timeStamp){
  397.                 $timeStamp time();
  398.             }
  399.             // Offset with Board Time firstly, if enabled
  400.             // Also Check no member offset
  401.             if(!$noBoard){
  402.                 if(!$noMember && empty($info['time_offset'])){
  403.                     $timeStamp $timeStamp ($this->ips_wrapper->settings['time_offset'3600);
  404.                 }
  405.             }
  406.             // Board Time Adjust
  407.             if($this->ips_wrapper->settings['time_adjust']){
  408.                 $timeStamp $timeStamp ($this->ips_wrapper->settings['time_adjust'60);
  409.             }
  410.             // If member has set an indiviual offset in the User CP
  411.             // because they may be in a totally different country
  412.             // using DST or whatever we can make those times affect it
  413.             // across the whole website as well :D
  414.             if($this->member->isLoggedIn(&& !$noMember){
  415.                 if($info['time_offset']){
  416.                     $timeStamp $timeStamp ($info['time_offset'3600);
  417.                 }
  418.                 if($info['dst_in_use']){
  419.                     $timeStamp $timeStamp 3600;
  420.                 }
  421.             }
  422.             if($dateFormat){
  423.                 $timeStamp strftime($dateFormat$timeStamp);
  424.             }
  425.             return $timeStamp;
  426.         }
  427.     }
  428.  
  429.     // start class
  430.     if(empty($ipbwi)){
  431.         $ipbwi new ipbwi();
  432.     }else{
  433.         die('<p>Error: You have to include and load IPBWI once only.</p>');
  434.     }
  435. ?>

Documentation generated on Sat, 23 Oct 2010 23:35:53 +0200 by phpDocumentor 1.4.3