<?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; } }
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); /* */ }
Source: https://habr.com/ru/post/253773/
All Articles