[ Index ]
 

Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/includes/classes/ -> class.phpbb.php (source)

   1  <?php
   2  /** 

   3   * phpBB Class.

   4   *

   5   * This class is used to interact with phpBB forum

   6   *

   7   * @package classes

   8   * @copyright Copyright 2003-2006 Zen Cart Development Team

   9   * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0

  10   * @version $Id: class.phpbb.php 4824 2006-10-23 21:01:28Z drbyte $

  11   */
  12  
  13  if (!defined('IS_ADMIN_FLAG')) {
  14    die('Illegal Access');
  15  }
  16  
  17    class phpBB extends base {
  18        var $debug = false;
  19        var $db_phpbb;
  20        var $phpBB=array();
  21        var $dir_phpbb=''; 
  22  
  23      function phpBB() {
  24        $this->debug= (defined('PHPBB_DEBUG_MODE') && strtoupper(PHPBB_DEBUG_MODE)=='ON') ? (defined('PHPBB_DEBUG_IP') && (PHPBB_DEBUG_IP == '' || PHPBB_DEBUG_IP == $_SERVER['REMOTE_ADDR'] || strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE, $_SERVER['REMOTE_ADDR'])) ? true : false ) : false;
  25        $this->phpBB = Array();
  26        $this->phpBB['installed']=false;
  27        if (PHPBB_LINKS_ENABLED =='true') {  // if disabled in Zen Cart admin, don't do any checks for phpBB
  28          $this->get_phpBB_info();
  29        
  30  //        global $db;

  31  //        $this->db_phpbb = $db;

  32  
  33          $this->db_phpbb = new queryFactory();
  34          $connect_status = $this->db_phpbb->connect($this->phpBB['dbhost'], $this->phpBB['dbuser'], $this->phpBB['dbpasswd'], $this->phpBB['dbname'], USE_PCONNECT, false);
  35  
  36          $this->check_connect();
  37          $this->set_status();
  38        } elseif ($this->debug==true) {
  39          echo "phpBB connection disabled in Admin<br>";
  40        }
  41        if ($this->debug==true) echo '<br /><br /><strong>YOU CAN IGNORE THE FOLLOWING "Cannot send session cache limited - headers already sent..." errors, as they are a result of the above debug output.</strong><br><br>';
  42      }
  43  
  44      function get_phpBB_info() {
  45        $this->phpBB['db_installed']=false;
  46        $this->phpBB['files_installed']=false;
  47        $this->phpBB['phpbb_path']='';
  48        $this->phpBB['phpbb_url']='';
  49  
  50        //@TODO: $cleaned = preg_replace('/\//',DIRECTORY_SEPARATOR,$string);

  51  
  52        $this->dir_phpbb = str_replace(array('\\', '//'), '/', DIR_WS_PHPBB ); // convert slashes

  53  
  54        if (substr($this->dir_phpbb,-1)!='/') $this->dir_phpbb .= '/'; // ensure has a trailing slash

  55        if ($this->debug==true) echo 'dir='.$this->dir_phpbb.'<br>';
  56  
  57        //check if file exists

  58        if (@file_exists($this->dir_phpbb . 'config.php')) {
  59          $this->phpBB['files_installed'] = true;
  60          if ($this->debug==true) echo "files_installed = true<br>";
  61          // if exists, also store it for future use

  62          $this->phpBB['phpbb_path'] = $this->dir_phpbb;
  63          if ($this->debug==true) echo 'phpbb_path='. $this->dir_phpbb . '<br><br>';
  64  
  65         // find phpbb table prefix without including file:

  66          $lines = array();
  67          $lines = @file($this->phpBB['phpbb_path']. 'config.php');
  68          foreach($lines as $line) { // read the configure.php file for specific variables
  69            if ($this->debug==true && strlen($line)>3 && substr($line,0,2)!='//' && !strstr($line,'$dbpasswd')) echo 'CONFIG.PHP-->'.$line.'<br>';
  70            if (substr($line,0,1)!='$') continue;
  71            if (substr_count($line,'"')>1) $delim='"';
  72            if (substr_count($line,"'")>1) $delim="'"; // determine whether single or double quotes used in this line.

  73            $def_string=array();
  74            $def_string=explode($delim,trim($line));
  75            if (substr($line,0,7)=='$dbhost') $this->phpBB['dbhost'] = $def_string[1];
  76            if (substr($line,0,7)=='$dbname') $this->phpBB['dbname'] = $def_string[1];
  77            if (substr($line,0,7)=='$dbuser') $this->phpBB['dbuser'] = $def_string[1];
  78            if (substr($line,0,9)=='$dbpasswd') $this->phpBB['dbpasswd'] = $def_string[1];
  79            if (substr($line,0,13)=='$table_prefix') $this->phpBB['table_prefix'] = $def_string[1];
  80          }//end foreach $line

  81         // find phpbb table-names without INCLUDEing file:

  82          if (@file_exists($this->phpBB['phpbb_path'] . 'includes/constants.php')) {
  83            $lines = array();
  84            $lines = @file($this->phpBB['phpbb_path']. 'includes/constants.php');
  85            if (is_array($lines)) {
  86              foreach($lines as $line) { // read the configure.php file for specific variables
  87                if (substr_count($line,'define(')<1) continue;
  88                if ($this->debug==true && strlen($line)>3 && substr($line,0,1)!='/') echo 'CONSTANTS.PHP-->'.$line.'<br>';
  89                if (substr_count($line,'"')>1) $delim='"';
  90                if (substr_count($line,"'")>1) $delim="'"; // determine whether single or double quotes used in this line.

  91                $def_string=array();
  92                $def_string=explode($delim,$line);
  93                if ($def_string[1]=='USERS_TABLE')      $this->phpBB['users_table'] = $this->phpBB['table_prefix'] . $def_string[3];
  94                if ($def_string[1]=='USER_GROUP_TABLE') $this->phpBB['user_group_table'] = $this->phpBB['table_prefix'] . $def_string[3];
  95                if ($def_string[1]=='GROUPS_TABLE')     $this->phpBB['groups_table'] = $this->phpBB['table_prefix'] . $def_string[3];
  96                if ($def_string[1]=='CONFIG_TABLE')     $this->phpBB['config_table'] = $this->phpBB['table_prefix'] . $def_string[3];
  97              }//end foreach of $line

  98            }
  99          } else {
 100            $this->phpBB['files_installed'] = false;
 101          }
 102          if ($this->debug==true) {
 103            echo 'prefix='.$this->phpBB['table_prefix'].'<br>';
 104            echo 'dbname='.$this->phpBB['dbname'].'<br>';
 105            echo 'dbuser='.$this->phpBB['dbuser'].'<br>';
 106            echo 'dbhost='.$this->phpBB['dbhost'].'<br>';
 107            echo 'dbpasswd='.$this->phpBB['dbpasswd'].'<br>';
 108            echo 'users_table='.$this->phpBB['users_table'].'<br>';
 109            echo 'user_group_table='.$this->phpBB['user_group_table'].'<br>';
 110            echo 'groups_table='.$this->phpBB['groups_table'].'<br>';
 111            echo 'config_table='.$this->phpBB['config_table'].'<br>';
 112          }
 113  
 114        }//endif @file_exists

 115      }
 116  
 117      function check_connect() {
 118          // check if tables exist in database

 119          if ($this->phpBB['dbname']!='' && $this->phpBB['dbuser'] !='' && $this->phpBB['dbhost'] !='' && $this->phpBB['config_table']!='' && $this->phpBB['users_table'] !='' && $this->phpBB['user_group_table'] !='' && $this->phpBB['groups_table']!='') {
 120            if ($this->dbname == DB_DATABASE) {
 121              $this->phpBB['db_installed'] = $this->table_exists_zen($this->phpBB['users_table']);
 122              $this->phpBB['db_installed_config'] = $this->table_exists_zen($this->phpBB['config_table']);
 123              if ($this->debug==true) echo "db_installed -- in ZC Database = ".$this->phpBB['db_installed']."<br>";
 124              } else {
 125              $this->phpBB['db_installed'] = $this->table_exists_phpbb($this->phpBB['users_table']);
 126              $this->phpBB['db_installed_config'] = $this->table_exists_phpbb($this->phpBB['config_table']);
 127              if ($this->debug==true) echo "db_installed -- in separate database = ".$this->phpBB['db_installed']."<br>";
 128            }
 129          }
 130      }
 131  
 132      function set_status() {
 133        //calculate the path from root of server for absolute path info

 134        $script_filename = $_SERVER['PATH_TRANSLATED'];
 135        if (empty($script_filename)) $script_filename = $_SERVER['SCRIPT_FILENAME'];
 136        $script_filename = str_replace(array('\\', '//'), '/', $script_filename);  //convert slashes

 137  
 138        if ($this->debug==true) echo "script-filename=".$script_filename.'<br>';
 139        if ($this->debug==true) echo "link_enabled_admin_status=".PHPBB_LINKS_ENABLED.'<br>';
 140  
 141        if ( ($this->phpBB['db_installed']) && ($this->phpBB['files_installed'])  && (PHPBB_LINKS_ENABLED=='true')) {
 142         //good so far. now let's check for relative path access so we can successfully "include" the config.php file when needed.

 143          if ($this->debug==true) echo "ok, now let's check relative paths<br>";
 144          if ($this->debug==true) echo 'docroot='.$_SERVER['DOCUMENT_ROOT'].'<br>';
 145          if ($this->debug==true) echo 'phpself='.$_SERVER['PHP_SELF'].'<br>';
 146          $this->phpBB['phpbb_url'] = str_replace(array($_SERVER['DOCUMENT_ROOT'],substr($script_filename,0,strpos($script_filename,$_SERVER['PHP_SELF']))),'',$this->phpBB['phpbb_path']);
 147          $this->phpBB['installed'] = true;
 148          if ($this->debug==true) echo 'URL='.$this->phpBB['phpbb_url'].'<br>';
 149          //if neither of the relative paths validate, the function still returns false for 'installed'.

 150        }
 151        if ($this->debug==true && $this->phpBB['installed']==false) echo "FAILURE: phpBB NOT activated<br><br>";
 152       // will use $phpBB->phpBB['installed'] to check for suitability of calling phpBB in the future.

 153      }
 154  
 155  
 156      function table_exists_zen($table_name) {
 157        global $db;
 158      // Check to see if the requested Zen Cart table exists

 159        $sql = "SHOW TABLES like '".$table_name."'";
 160        $tables = $db->Execute($sql);
 161  //echo 'tables_found = '. $tables->RecordCount() .'<br>';

 162        if ($tables->RecordCount() > 0) {
 163          $found_table = true;
 164        }
 165        return $found_table;
 166      }
 167      function table_exists_phpbb($table_name) {
 168      // Check to see if the requested PHPBB table exists, regardless of which database it's set to use

 169        $sql = "SHOW TABLES like '".$table_name."'";
 170        $tables = $this->db_phpbb->Execute($sql);
 171        //echo 'tables_found = '. $tables->RecordCount() .'<br>';

 172        if ($tables->RecordCount() > 0) {
 173          $found_table = true;
 174        }
 175        return $found_table;
 176      }
 177  
 178      function phpbb_create_account($nick, $password, $email_address) {
 179        if ($this->phpBB['installed'] != true || !zen_not_null($password) || !zen_not_null($email_address) || !zen_not_null($nick)) return false;
 180        if ($this->phpbb_check_for_duplicate_email($email_address) == 'already_exists') {
 181  //        $this->phpbb_change_email($old_email, $email_address);

 182        } else {
 183          $sql = "select max(user_id) as total from " . $this->phpBB['users_table'];
 184          $phpbb_users = $this->db_phpbb->Execute($sql);
 185          $user_id = ($phpbb_users->fields['total'] + 1);
 186          $sql = "insert into " . $this->phpBB['users_table'] . "
 187                  (user_id, username, user_password, user_email, user_regdate)
 188                  values
 189                  ('" . (int)$user_id . "', '" . $nick . "', '" . md5($password) . "', '" . $email_address . "', '" . time() ."')";
 190          $this->db_phpbb->Execute($sql);
 191  //could do a check here to see if Insert_ID() matches $user_id...

 192  
 193  
 194  // @TODO: MySQL5

 195  
 196          $sql = "INSERT INTO " . $this->phpBB['groups_table'] . " (group_name, group_description, group_single_user, group_moderator)
 197                  VALUES (0, 'Personal User', 1, 0)";
 198          $this->db_phpbb->Execute($sql);
 199          $group_id = $this->db_phpbb->Insert_ID();
 200          $sql = "INSERT INTO " . $this->phpBB['user_group_table'] . " (user_id, group_id, user_pending)
 201                  VALUES ($user_id, $group_id, 0)";
 202          $this->db_phpbb->Execute($sql);
 203          //might optionally send an extra email welcoming them to the phpBB forum, reminding them of their nickname?

 204        }
 205      }
 206  
 207      function phpbb_check_for_duplicate_nick($nick='') {
 208        if ($this->phpBB['installed'] != true || empty($nick)) return false;
 209        $status='';
 210        $sql = "select * from " . $this->phpBB['users_table'] . " where username = '" . $nick . "'";
 211        //echo $sql;

 212        $phpbb_users = $this->db_phpbb->Execute($sql);
 213        //echo "count=".$phpbb_users->RecordCount();

 214        if ($phpbb_users->RecordCount() > 0 ) {
 215          $status='already_exists';
 216        }
 217        return $status;
 218      }
 219  
 220      function phpbb_check_for_duplicate_email($email_address) {
 221        if ($this->phpBB['installed'] != true) return false;
 222        $status='';
 223        $sql = "select * from " . $this->phpBB['users_table'] . " where user_email = '" . $email_address . "'";
 224        $phpbb_users = $this->db_phpbb->Execute($sql);
 225        if ($phpbb_users->RecordCount() > 0 ) {
 226          $status='already_exists';
 227        }
 228        return $status;
 229      }
 230  
 231      function phpbb_change_password($nick, $newpassword) {
 232        if ($this->phpBB['installed'] != true || !zen_not_null($nick) || $nick == '') return false;
 233          $sql = "update " . $this->phpBB['users_table'] . " set user_password='" . MD5($newpassword) . "'
 234                  where username = '" . $nick . "'";
 235          $phpbb_users = $this->db_phpbb->Execute($sql);
 236      }
 237  
 238      function phpbb_change_email($old_email, $email_address) {
 239      // before utilizing this function, we should do an MD5 password validation first

 240        if ($this->phpBB['installed'] != true || !zen_not_null($email_address) || $email_address == '') return false;
 241          $sql = "update " . $this->phpBB['users_table'] . " set user_email='" . $email_address . "'
 242                  where user_email = '" . $old_email . "'";
 243          $phpbb_users = $this->db_phpbb->Execute($sql);
 244      }
 245  
 246      function phpbb_change_nick($old_nick, $new_nick) {
 247      // before utilizing this function, we should do an MD5 password validation first

 248        if ($this->phpBB['installed'] != true || !zen_not_null($nick) || $nick == '') return false;
 249          $sql = "update " . $this->phpBB['users_table'] . " set username='" . $new_nick . "'
 250                  where username = '" . $old_nick . "'";
 251          $phpbb_users = $this->db_phpbb->Execute($sql);
 252      }
 253  
 254    }
 255  ?>


Généré le : Mon Nov 26 16:45:43 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics