[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 class.phpbb.php

Zen Cart 源代码 class.phpbb.php




下载文件

文件名: class.phpbb.php
文件类型: PHP文件
文件大小: 15.2 KiB
MD5: 84d2f8183d2bad9f2b286816bae9de78

class.phpbb.php - 关闭高亮
  1. <?php
  2. /**
  3.  * phpBB3 Class.
  4.  *
  5.  * This class is used to interact with phpBB3 forum
  6.  *
  7.  * @package classes
  8.  * @copyright Copyright 2003-2014 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 14689 2009-10-26 17:06:43Z drbyte Modified in v1.5.4 $
  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.       var $groupId = 2;
  23.  
  24.     function phpBB() {
  25.       $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;
  26.       $this->phpBB = Array();
  27.       $this->phpBB['installed'] = false;
  28.       if (PHPBB_LINKS_ENABLED =='true') {  // if disabled in Zen Cart admin, don't do any checks for phpBB
  29.         $this->get_phpBB_info();
  30.  
  31.         $this->db_phpbb = new queryFactory();
  32.         $connect_status = $this->db_phpbb->connect($this->phpBB['dbhost'], $this->phpBB['dbuser'], $this->phpBB['dbpasswd'], $this->phpBB['dbname'], USE_PCONNECT, false);
  33.  
  34.         $this->check_connect();
  35.         $this->set_status();
  36.       } elseif ($this->debug==true) {
  37.         echo "phpBB connection disabled in Admin<br>";
  38.       }
  39.       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>';
  40.     }
  41.  
  42.     function get_phpBB_info() {
  43.       $this->phpBB['db_installed'] = false;
  44.       $this->phpBB['files_installed'] = false;
  45.       $this->phpBB['phpbb_path']='';
  46.       $this->phpBB['phpbb_url']='';
  47.  
  48.       //@TODO: $cleaned = preg_replace('/\//',DIRECTORY_SEPARATOR,$string);
  49.  
  50.       $this->dir_phpbb = str_replace(array('\\', '//'), '/', DIR_WS_PHPBB ); // convert slashes
  51.  
  52.       if (substr($this->dir_phpbb,-1)!='/') $this->dir_phpbb .= '/'; // ensure has a trailing slash
  53.       if ($this->debug==true) echo 'dir='.$this->dir_phpbb.'<br>';
  54.  
  55.       //check if file exists
  56.       if (@file_exists($this->dir_phpbb . 'config.php')) {
  57.         $this->phpBB['files_installed'] = true;
  58.         if ($this->debug==true) echo "files_installed = true<br>";
  59.         // if exists, also store it for future use
  60.         $this->phpBB['phpbb_path'] = $this->dir_phpbb;
  61.         if ($this->debug==true) echo 'phpbb_path='. $this->dir_phpbb . '<br><br>';
  62.  
  63.        // find phpbb table prefix without including file:
  64.         $lines = array();
  65.         $lines = @file($this->phpBB['phpbb_path']. 'config.php');
  66.         foreach($lines as $line) { // read the configure.php file for specific variables
  67.           if ($this->debug==true && strlen($line)>3 && substr($line,0,2)!='//' && !strstr($line,'$dbpasswd')) echo 'CONFIG.PHP-->'.$line.'<br>';
  68.           if (substr($line,0,1)!='$') continue;
  69.           if (substr_count($line,'"')>1) $delim='"';
  70.           if (substr_count($line,"'")>1) $delim="'"; // determine whether single or double quotes used in this line.
  71.           $def_string=array();
  72.           $def_string=explode($delim,trim($line));
  73.           if (substr($line,0,7)=='$dbhost') $this->phpBB['dbhost'] = ($def_string[1] == '' ? 'localhost' : $def_string[1]);
  74.           if (substr($line,0,7)=='$dbname') $this->phpBB['dbname'] = $def_string[1];
  75.           if (substr($line,0,7)=='$dbuser') $this->phpBB['dbuser'] = $def_string[1];
  76.           if (substr($line,0,9)=='$dbpasswd') $this->phpBB['dbpasswd'] = $def_string[1];
  77.           if (substr($line,0,13)=='$table_prefix') $this->phpBB['table_prefix'] = $def_string[1];
  78.         }//end foreach $line
  79.        // find phpbb table-names without INCLUDEing file:
  80.         if (@file_exists($this->phpBB['phpbb_path'] . 'includes/constants.php')) {
  81.           $lines = array();
  82.           $lines = @file($this->phpBB['phpbb_path']. 'includes/constants.php');
  83.           if (is_array($lines)) {
  84.             foreach($lines as $line) { // read the configure.php file for specific variables
  85.               if (substr_count($line,'define(')<1) continue;
  86.               if ($this->debug==true && strlen($line)>3 && substr($line,0,1)!='/') echo 'CONSTANTS.PHP-->'.$line.'<br>';
  87.               if (substr_count($line,'"')>1) $delim='"';
  88.               if (substr_count($line,"'")>1) $delim="'"; // determine whether single or double quotes used in this line.
  89.               $def_string=array();
  90.               $def_string=explode($delim,$line);
  91.               if ($def_string[1]=='USERS_TABLE')      $this->phpBB['users_table'] = $this->phpBB['table_prefix'] . $def_string[3];
  92.               if ($def_string[1]=='USER_GROUP_TABLE') $this->phpBB['user_group_table'] = $this->phpBB['table_prefix'] . $def_string[3];
  93.               if ($def_string[1]=='GROUPS_TABLE')     $this->phpBB['groups_table'] = $this->phpBB['table_prefix'] . $def_string[3];
  94.               if ($def_string[1]=='CONFIG_TABLE')     $this->phpBB['config_table'] = $this->phpBB['table_prefix'] . $def_string[3];
  95.             }//end foreach of $line
  96.           }
  97.         } else {
  98.           $this->phpBB['files_installed'] = false;
  99.         }
  100.         if ($this->debug==true) {
  101.           echo 'prefix='.$this->phpBB['table_prefix'].'<br>';
  102.           echo 'dbname='.$this->phpBB['dbname'].'<br>';
  103.           echo 'dbuser='.$this->phpBB['dbuser'].'<br>';
  104.           echo 'dbhost='.$this->phpBB['dbhost'].'<br>';
  105.           echo 'dbpasswd='.$this->phpBB['dbpasswd'].'<br>';
  106.           echo 'users_table='.$this->phpBB['users_table'].'<br>';
  107.           echo 'user_group_table='.$this->phpBB['user_group_table'].'<br>';
  108.           echo 'groups_table='.$this->phpBB['groups_table'].'<br>';
  109.           echo 'config_table='.$this->phpBB['config_table'].'<br>';
  110.         }
  111.  
  112.       }//endif @file_exists
  113.     }
  114.  
  115.     function check_connect() {
  116.         // check if tables exist in database
  117.         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']!='') {
  118.           if ($this->phpBB['dbname'] == DB_DATABASE) {
  119.             $this->phpBB['db_installed'] = $this->table_exists_zen($this->phpBB['users_table']);
  120.             $this->phpBB['db_installed_config'] = $this->table_exists_zen($this->phpBB['config_table']);
  121.             if ($this->debug==true) echo "db_installed -- in ZC Database = ".$this->phpBB['db_installed']."<br>";
  122.             } else {
  123.             $this->phpBB['db_installed'] = $this->table_exists_phpbb($this->phpBB['users_table']);
  124.             $this->phpBB['db_installed_config'] = $this->table_exists_phpbb($this->phpBB['config_table']);
  125.             if ($this->debug==true) echo "db_installed -- in separate database = ".$this->phpBB['db_installed']."<br>";
  126.           }
  127.         }
  128.     }
  129.  
  130.     function set_status() {
  131.       //calculate the path from root of server for absolute path info
  132.       $script_filename = $_SERVER['PATH_TRANSLATED'];
  133.       if (empty($script_filename)) $script_filename = $_SERVER['SCRIPT_FILENAME'];
  134.       $script_filename = str_replace(array('\\', '//'), '/', $script_filename);  //convert slashes
  135.  
  136.       if ($this->debug==true) echo "script-filename=".$script_filename.'<br>';
  137.       if ($this->debug==true) echo "link_enabled_admin_status=".PHPBB_LINKS_ENABLED.'<br>';
  138.  
  139.       if ( ($this->phpBB['db_installed']) && ($this->phpBB['files_installed'])  && (PHPBB_LINKS_ENABLED=='true')) {
  140.        //good so far. now let's check for relative path access so we can successfully "include" the config.php file when needed.
  141.         if ($this->debug==true) echo "ok, now let's check relative paths<br>";
  142.         if ($this->debug==true) echo 'docroot='.$_SERVER['DOCUMENT_ROOT'].'<br>';
  143.         if ($this->debug==true) echo 'phpself='.$_SERVER['PHP_SELF'].'<br>';
  144.         $this->phpBB['phpbb_url'] = str_replace(array($_SERVER['DOCUMENT_ROOT'],substr($script_filename,0,strpos($script_filename,$_SERVER['PHP_SELF']))),'',$this->phpBB['phpbb_path']);
  145.         $this->phpBB['installed'] = true;
  146.         if ($this->debug==true) echo 'URL='.$this->phpBB['phpbb_url'].'<br>';
  147.         //if neither of the relative paths validate, the function still returns false for 'installed'.
  148.       }
  149.       if ($this->debug==true && $this->phpBB['installed']==false) echo "FAILURE: phpBB NOT activated<br><br>";
  150.      // will use $phpBB->phpBB['installed'] to check for suitability of calling phpBB in the future.
  151.     }
  152.  
  153.  
  154.     function table_exists_zen($table_name) {
  155.       global $db;
  156.     // Check to see if the requested Zen Cart table exists
  157.       $sql = "SHOW TABLES like '".$table_name."'";
  158.       $tables = $db->Execute($sql);
  159. //echo 'tables_found = '. $tables->RecordCount() .'<br>';
  160.       if ($tables->RecordCount() > 0) {
  161.         $found_table = true;
  162.       }
  163.       return $found_table;
  164.     }
  165.     function table_exists_phpbb($table_name) {
  166.     // Check to see if the requested PHPBB table exists, regardless of which database it's set to use
  167.       $sql = "SHOW TABLES like '".$table_name."'";
  168.       $tables = $this->db_phpbb->Execute($sql);
  169.       //echo 'tables_found = '. $tables->RecordCount() .'<br>';
  170.       if ($tables->RecordCount() > 0) {
  171.         $found_table = true;
  172.       }
  173.       return $found_table;
  174.     }
  175.  
  176.     function phpbb_create_account($nick, $password, $email_address) {
  177.       if ($this->phpBB['installed'] != true || !zen_not_null($password) || !zen_not_null($email_address) || !zen_not_null($nick)) return false;
  178.       if (!$this->phpbb_check_for_duplicate_email($email_address) == 'already_exists') {
  179.         $sql = "select max(user_id) as total from " . $this->phpBB['users_table'];
  180.         $phpbb_users = $this->db_phpbb->Execute($sql);
  181.         $user_id = ($phpbb_users->fields['total'] + 1);
  182.         $sql = "insert into " . $this->phpBB['users_table'] . "
  183.                (user_id, group_id, username, username_clean, user_password, user_email, user_email_hash, user_regdate, user_permissions, user_sig, user_occ, user_interests)
  184.                values
  185.                ('" . (int)$user_id . "', " . $this->groupId . ", '" . zen_db_input($nick) . "', '" . zen_db_input(strtolower($nick)) . "', '" . md5($password) . "', '" . zen_db_input($email_address) . "', '" . zen_db_input(crc32(strtolower($email_address))) . strlen($email_address) . "', '" . time() ."', '', '', '', '')";
  186.         $this->db_phpbb->Execute($sql);
  187.         $sql = " update " . $this->phpBB['config_table'] . " SET config_value = '{$user_id}' WHERE config_name = 'newest_user_id'";
  188.         $this->db_phpbb->Execute($sql);
  189.         $sql = " update " . $this->phpBB['config_table'] . " SET config_value = '" . zen_db_input($nick) . "' WHERE config_name = 'newest_username'";
  190.         $this->db_phpbb->Execute($sql);
  191.         $sql = " update " . $this->phpBB['config_table'] . " SET config_value = config_value + 1 WHERE config_name = 'num_users'";
  192.         $this->db_phpbb->Execute($sql);
  193.         $sql = "INSERT INTO " . $this->phpBB['user_group_table'] . " (user_id, group_id, user_pending)
  194.                VALUES ($user_id, $this->groupId, 0)";
  195.         $this->db_phpbb->Execute($sql);
  196.       }
  197.     }
  198.     function v2phpbb_create_account($nick, $password, $email_address) {
  199.       if ($this->phpBB['installed'] != true || !zen_not_null($password) || !zen_not_null($email_address) || !zen_not_null($nick)) return false;
  200.       if ($this->phpbb_check_for_duplicate_email($email_address) == 'already_exists') {
  201. //        $this->phpbb_change_email($old_email, $email_address);
  202.       } else {
  203.         $sql = "select max(user_id) as total from " . $this->phpBB['users_table'];
  204.         $phpbb_users = $this->db_phpbb->Execute($sql);
  205.         $user_id = ($phpbb_users->fields['total'] + 1);
  206.         $sql = "insert into " . $this->phpBB['users_table'] . "
  207.                (user_id, username, user_password, user_email, user_regdate)
  208.                values
  209.                ('" . (int)$user_id . "', '" . zen_db_input($nick) . "', '" . md5($password) . "', '" . zen_db_input($email_address) . "', '" . time() ."')";
  210.         $this->db_phpbb->Execute($sql);
  211.  
  212.         $sql = "INSERT INTO " . $this->phpBB['groups_table'] . " (group_name, group_description, group_single_user, group_moderator)
  213.                VALUES (0, 'Personal User', 1, 0)";
  214.         $this->db_phpbb->Execute($sql);
  215.         $group_id = $this->db_phpbb->Insert_ID();
  216.         $sql = "INSERT INTO " . $this->phpBB['user_group_table'] . " (user_id, group_id, user_pending)
  217.                VALUES ($user_id, $group_id, 0)";
  218.         $this->db_phpbb->Execute($sql);
  219.         //might optionally send an extra email welcoming them to the phpBB forum, reminding them of their nickname?
  220.       }
  221.     }
  222.  
  223.     function phpbb_check_for_duplicate_nick($nick='') {
  224.       if ($this->phpBB['installed'] != true || empty($nick)) return false;
  225.       $status='';
  226.       $sql = "select * from " . $this->phpBB['users_table'] . " where username = '" . zen_db_input($nick) . "'";
  227.       //echo $sql;
  228.       $phpbb_users = $this->db_phpbb->Execute($sql);
  229.       //echo "count=".$phpbb_users->RecordCount();
  230.       if ($phpbb_users->RecordCount() > 0 ) {
  231.         $status='already_exists';
  232.       }
  233.       return $status;
  234.     }
  235.  
  236.     function phpbb_check_for_duplicate_email($email_address) {
  237.       if ($this->phpBB['installed'] != true) return false;
  238.       $status='';
  239.       $sql = "select * from " . $this->phpBB['users_table'] . " where user_email = '" . zen_db_input($email_address) . "'";
  240.       $phpbb_users = $this->db_phpbb->Execute($sql);
  241.       if ($phpbb_users->RecordCount() > 0 ) {
  242.         $status='already_exists';
  243.       }
  244.       return $status;
  245.     }
  246.  
  247.     function phpbb_change_password($nick, $newpassword) {
  248.       if ($this->phpBB['installed'] != true || !zen_not_null($nick) || $nick == '') return false;
  249.         $sql = "update " . $this->phpBB['users_table'] . " set user_password='" . MD5($newpassword) . "'
  250.                where username = '" . zen_db_input($nick) . "'";
  251.         $phpbb_users = $this->db_phpbb->Execute($sql);
  252.     }
  253.  
  254.     function phpbb_change_email($old_email, $email_address) {
  255.     // before utilizing this function, we should do an MD5 password validation first
  256.       if ($this->phpBB['installed'] != true || !zen_not_null($email_address) || $email_address == '') return false;
  257.         $sql = "update " . $this->phpBB['users_table'] . " set user_email='" . zen_db_input($email_address) . "', user_email_hash = '" . crc32(strtolower($email_address)) . strlen($email_address) . "'
  258.                where user_email = '" . zen_db_input($old_email) . "'";
  259.         $phpbb_users = $this->db_phpbb->Execute($sql);
  260.     }
  261.  
  262.     function phpbb_change_nick($old_nick, $new_nick) {
  263.     // before utilizing this function, we should do an MD5 password validation first
  264.       if ($this->phpBB['installed'] != true || !zen_not_null($nick) || $nick == '') return false;
  265.         $sql = "update " . $this->phpBB['users_table'] . " set username='" . zen_db_input($new_nick) . "', username_clean = '" . zen_db_input($new_nick) . "'
  266.                where username = '" . zen_db_input($old_nick) . "'";
  267.         $phpbb_users = $this->db_phpbb->Execute($sql);
  268.     }
  269.  
  270.   }
  271.