
まず、自分の時間やクライアントの時間を無駄にしないために、既製のソリューションを探すことにしました。 phpBB3_libraryライブラリへの有効なリンクはもはや見つかりませんでした。WPやその他のエンジンのプラグインは見つかりましたが、自分自身と私の頭脳(サイト)とフォーラムの統合を簡単にしたかったのです。
私は長い間グーグルしなかった、この記事を見つけたので、phpBBのユーザー機能の深さへの潜入が始まりました。
問題の声明
- 簡単に統合できます。 1つの実装クラスが必要です。 フォーラムエンジンに変更はありません。そのため、フォーラムを更新しても何も飛ぶことがありません。
- クラスでのフォーラム機能の最大使用。 自転車に乗りたくありません。
- 既存のフォーラム機能に基づいて、共同登録、パスワード変更、認証、セッションの終了、ユーザーのブロックとブロック解除を実装します。
分析
ドックを読んだ後、ユーザー管理機能が<forum root> /includes/functions_user.phpにあり、承認が<forum root> / phpbb / auth / providerにあることが明らかになりました。 このフォルダーには、いくつかの許可オプションの機能が含まれています。 許可のタイプは、フォーラムの管理パネルの「一般->認証」セクションで設定します。 デフォルト値-Dbを設定します。
原則として、ユーザーデータの更新に加えて、これら2つのファイルに必要な機能を見つけました。 次に、実装に進みます。
初期データ
- codeigniterを使用して実装されたWebサイト。
- PhpBBフォーラム。
- サイトユーザーのテーブル-USERS。
- フォーラムユーザーのテーブルはphpbb_USERSです。
- サイト上のユーザーの登録/承認-Codeigniter Authライブラリーがニーズに変換されました。
解決策
タスクが設定されました。実行する必要があります。
始める前に-いくつかのニュアンス。
- サイトでユーザー登録を無効にする必要があります。 これは管理パネルで行います(一般->ユーザー登録->ユーザー名の変更を許可->いいえ)。 ユーザーはサイトでのみ登録できます。
- ユーザー名の変更は禁止されています(一般->ユーザー登録->アカウントの有効化->無効)。
- フォーラムからの許可を禁止しています。 承認を行い、サイトからのみ終了します。 「額」でした-ファイル<forum root> /ucp.phpで、サイト上の対応するページにリダイレクトしました。 (「case 'login':」、「case 'login_link':」、「case 'logout':」の行を参照してください。リダイレクト「header( 'Location:/ auth / login');」および「header( 'Location: / auth / logout ');”)。
- サイトで(リダイレクト()関数がある場合)、名前の競合を回避するために、たとえば、リダイレクト()関数をciredirect()に置き換えます-phpBBには同じ名前の関数があります。
codeigniterの場合、my_phplib.phpライブラリを作成します(codeigniterのライブラリは、アプリケーション/ライブラリフォルダーにあるプラグインクラスの一種です。他に異常はないため、他のエンジン/フレームワークのユーザーに落胆しないでください)。
したがって、ライブラリの内容は次のとおりです。
ライブラリmy_phplib.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class My_phpbblib { public $phpBB_user; public $phpBB_auth; public $phpBB_db; public $table_prefix; public function __construct(){ // . global $phpbb_root_path, $phpEx, $user, $auth, $cache, $db, $config, $template, $table_prefix, $request, $phpbb_container, $symfony_request, $phpbb_filesystem, $phpbb_log, $phpbb_path_helper, $phpbb_dispatcher; // ... define('IN_PHPBB', TRUE); // . $phpbb_root_path = './forum/'; // . - php $phpEx = substr(strrchr(__FILE__, '.'), 1); // // include($phpbb_root_path . 'common.' . $phpEx); include($phpbb_root_path . 'config.php.' . $phpEx); // include($phpbb_root_path . 'includes/functions_user.' . $phpEx); // ... $request->enable_super_globals(); // $user->session_begin(); $auth->acl($user->data); $this->phpBB_user = $user; $this->phpBB_auth = $auth; $this->phpBB_db = $db; $this->table_prefix = $table_prefix; } // public function registration($data = array()) { // , if(count($data) < 3){ // 3 - , email return false; } $new_phphBB_user = array(); // . if(isset($data['username'])) return false; $new_phphBB_user['username'] = $data['username']; // if(isset($data['user_password'])) return false; $new_phphBB_user['user_password'] = phpbb_hash($data['user_password']); // email if(isset($data['user_email'])) return false; $new_phphBB_user['user_email'] = $data['user_email']; // . // phpBB3 // - 1 - GUESTS - ( ) // - 2 - REGISTERED - // - 3 - REGISTERED_COPPA - COPPA // - 4 - GLOBAL_MODERATORS - - // - 5 - ADMINISTRATORS - // - 6 - BOTS - // - 7 - NEWLY_REGISTERED - . // NEWLY_REGISTERED $new_phphBB_user['group_id'] = isset($data['group_id']) ? $data['group_id'] : 7; // . // 4 // - 0 - // - 1 - . . // - 2 - () // - 3 - // . $new_phphBB_user['user_type'] = isset($data['user_type']) ? $data['user_type'] : 1; // . $phphBB_user_id = user_add($user_row, false); // id phpBB return $phphBB_user_id; } // public function login($data = array()){ $this->phpBB_user->setup('ucp'); // $username = $data['username']; // $password = $data['user_password']; // $autologin = $data['autologin']; // $viewonline = true; // phpBB $result = $this->phpBB_auth->login($username, $password, $autologin, $viewonline); // result // array( // 'status' => status-code(int), // 'error_msg'=> status-message-id(text), // 'user_row'=> user-row(array), // ); // // 1 - // 3 - // 10 - // 11 - // 12 - // 13 - return $result; } // public function logout(){ $this->phpBB_user->session_kill(); $this->phpBB_user->session_begin(); } // public function delete_user($mode = 'remove', $user_name = '') { // $mode = remove/retain - // id, , id - . $sql = 'SELECT user_id, username FROM phpbb_users WHERE username_clean = "'.utf8_clean_string($user_name).'"'; $result = $this->phpBB_db->sql_query($sql); if (!($row = $this->phpBB_db->sql_fetchrow($result))) { $db->sql_freeresult($result); } do { $user_id_ary[] = $row['user_id']; } // . $this->phpBB_db->sql_freeresult($result); if($user_id_ary){ // - return user_delete($mode, $user_id_ary, $retain_username = true); } return false; } // . public function ban_user($user_name = '', $ban_minutes = 432000, $ban_reason = ''){ // - // - (user), (ip), email (email) return user_ban('user', $user_name, $ban_minutes, $ban_len_other = '', $ban_exclude = false, $ban_reason, $ban_give_reason = ''); } // . public function unban_user($user_name = ''){ // - // - (user), (ip), email (email) // id $sql = 'SELECT b.ban_id, u.user_id FROM phpbb_users u, phpbb_banlist b WHERE u.username_clean = "'.utf8_clean_string($user_name).'" AND u.user_id = b.ban_userid'; $result = $this->phpBB_db->sql_query($sql); if (!($row = $this->phpBB_db->sql_fetchrow($result))) { $this->phpBB_db->sql_freeresult($result); } do { $user_ban_id_ary[] = $row['ban_id']; } $this->phpBB_db->sql_freeresult($result); return user_unban('user', $user_ban_id_ary); } // . public function edit_user_pass($user_name ='', $user_pass) { if (empty($user_name) || empty($user_pass)){ return false; } $sql = 'UPDATE ' . $this->table_prefix . 'users SET user_password="' . md5($user_pass) . '" WHERE username_clean = "'.utf8_clean_string($user_name).'"'; $this->phpBB_db->sql_query($sql); return true; } }
codeigniterで使用-デフォルトでは-認可を担当するコントローラーのライブラリを接続します。
my_phplib.phpを使用する
function __construct(){ parent::__construct(); $this->load->library('my_phpbblib'); } // public function login(){ /* */ $data = array(); $data['username'] = $this->input->post('login'); $data['user_password'] = $this->input->post('pass'); $data['autologin'] = $remember; // . $registration_result = $this->my_phpbblib->login($data); /* */ } // public function registration(){ /* */ $user_row['username'] = $user_login; $user_row['user_password'] = phpbb_hash($user_pass); $user_row['user_email'] = $user_email; $user_row['group_id'] = 2; $user_row['user_type'] = 0; // $forum_id = $this->my_phpbblib->registration($user_row); /* */ } // public function logout() { /* */ $this->my_phpbblib->logout($data); /* */ } // . public function delete($id = 0){ /* */ $this->my_phpbblib->delete_user('remove', $user_login); /* */ } // public function change_pass(){ /* */ // $this->my_phpbblib->edit_user_pass($user_login, $user_pass); /* */ } // . public function ban(){ /* */ // . $b = $this->my_phpbblib->ban_user($user_login, 432000, $ban_reason); /* */ } // . public function unban(){ /* */ $ub = $this->my_phpbblib->unban_user($user_login); /* */ }
この方法は、phpBB 3.1.1およびphpBB 3.1.3で実行されました(更新後、介入は不要です)。
ご清聴ありがとうございました。
この記事が誰かを助けてくれたら嬉しいです。