diff --git a/acp/main_module.php b/acp/main_module.php index 0f73500..a37df3c 100644 --- a/acp/main_module.php +++ b/acp/main_module.php @@ -10,12 +10,6 @@ namespace flerex\linkedaccounts\acp; -// Required by EPV -if (!defined('IN_PHPBB')) -{ - exit; -} - class main_module { @@ -63,18 +57,18 @@ public function main($id, $mode) switch($mode) { case 'overview': + default: $this->tpl_name = 'acp_overview'; $this->page_title = $this->user->lang('ADM_LINKED_ACCOUNTS_OVERVIEW'); + $this->mode_overview(); break; case 'management': $this->tpl_name = 'acp_management'; $this->page_title = $this->user->lang('ADM_LINKED_ACCOUNTS_MANAGEMENT'); + $this->mode_management(); break; - } - - $this->{'mode_' . $mode}(); - + } } @@ -85,24 +79,8 @@ private function mode_overview() { add_form_key('flerex_linkedaccounts_ucp_management'); - // if ($this->request->is_set_post('unlink')) - // { - // if (!check_form_key('flerex_linkedaccounts_ucp_management')) - // { - // trigger_error('FORM_INVALID'); - // } - - // $keys = $this->request->variable('keys', array('')); - - // if(!empty($keys)) - // { - // $this->utils->remove_links($keys); - // } - - // } - - $start = (int) $this->request->variable('start', 0); - $limit = (int) $this->request->variable('limit', main_module::ACCOUNTS_PER_PAGE); + $start = $this->request->variable('start', 0); + $limit = $this->request->variable('limit', main_module::ACCOUNTS_PER_PAGE); $accounts = $this->utils->get_accounts($start, $limit); foreach($accounts as $account) @@ -141,7 +119,7 @@ private function mode_management() } $username = utf8_clean_string($this->request->variable('account', '', true)); - $user_id = (int) $this->request->variable('accountID', 0, true); + $user_id = $this->request->variable('accountID', 0); if($user_id || $username) { @@ -187,7 +165,7 @@ private function mode_management() } $keys = $this->request->variable('keys', array('')); - $current_account = (int) $this->request->variable('currentaccount', ''); + $current_account = $this->request->variable('currentaccount', 0); if(!empty($keys)) { diff --git a/composer.json b/composer.json index a40431a..76bbba1 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,8 @@ "type": "phpbb-extension", "description": "A phpBB 3.2 extension that allows users to switch between their accounts with ease.", "homepage": "https://github.com/flerex/linkedaccounts", - "version": "1.0.1", - "time": "2018-3-01", + "version": "1.0.2", + "time": "2018-03-01", "keywords": ["flerex", "topic", "participants", "list"], "license": "GPL-2.0", "authors": [ diff --git a/config/services.yml b/config/services.yml index 84a1c87..41612ed 100644 --- a/config/services.yml +++ b/config/services.yml @@ -4,7 +4,6 @@ services: flerex.linkedaccounts.listener: class: flerex\linkedaccounts\event\main_listener arguments: - - '@user' - '@auth' - '@template' - '@controller.helper' diff --git a/controller/switcher.php b/controller/switcher.php index 7fe94eb..8d1bc0c 100644 --- a/controller/switcher.php +++ b/controller/switcher.php @@ -20,8 +20,8 @@ class switcher /** @var \phpbb\auth\auth $auth, */ protected $auth; - /** @var \phpbb\controller\helper */ - protected $helper; + /** @var \flerex\linkedaccounts\service\utils $utils */ + protected $utils; /** * Constructor @@ -38,9 +38,8 @@ public function __construct(\phpbb\user $user, \phpbb\auth\auth $auth, \flerex\l /** * Demo controller for route /demo/{name} * - * @param string $name + * @param int $account_id * @throws \phpbb\exception\http_exception - * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object */ public function handle($account_id) { diff --git a/event/main_listener.php b/event/main_listener.php index 273b6be..74b46eb 100644 --- a/event/main_listener.php +++ b/event/main_listener.php @@ -15,9 +15,6 @@ class main_listener implements EventSubscriberInterface { - /** @var \phpbb\user */ - protected $user; - /** @var \phpbb\auth\auth */ protected $auth; @@ -53,9 +50,8 @@ static public function getSubscribedEvents() * @param \phpbb\controller\helper $helper * @param \flerex\linkedaccounts\service\utils $utils */ - public function __construct(\phpbb\user $user, \phpbb\auth\auth $auth, \phpbb\template\template $template, \phpbb\controller\helper $helper, \flerex\linkedaccounts\service\utils $utils) + public function __construct(\phpbb\auth\auth $auth, \phpbb\template\template $template, \phpbb\controller\helper $helper, \flerex\linkedaccounts\service\utils $utils) { - $this->user = $user; $this->auth = $auth; $this->template = $template; $this->helper = $helper; diff --git a/language/en/common.php b/language/en/common.php index f08a080..9edfb2b 100644 --- a/language/en/common.php +++ b/language/en/common.php @@ -41,7 +41,7 @@ 'FIND_ACCOUNT' => 'Find account', 'CURRENT_PASSWORD_EXPLAIN_LINKACCOUNTS' => 'You must enter your current password if you wish to create a link to the previous account.', 'EMPTY_FIELDS' => 'Username and password cannot be empty.', - 'INCORRECT_LINKED_ACCOUNT_CREDENTIALS' => 'The provided credentials don\'t match any account.', + 'INCORRECT_LINKED_ACCOUNT_CREDENTIALS' => 'The provided credentials don’t match any account.', 'SAME_ACCOUNT' => 'You cannot link this account to itself!', 'INACTIVE_ACCOUNT' => 'The account you are trying to link to appears to be inactive.', 'BANNED_ACCOUNT' => 'The account you are trying to link to appears to be banned.', @@ -53,7 +53,7 @@ // ACP Overview Module 'ADM_LINKED_ACCOUNTS_OVERVIEW' => 'Overview', - 'ADM_LINKED_ACCOUNTS_OVERVIEW_EXPLAIN' => 'In this section you\'ll find some usage statistics along with a list with the users that have links to other accounts.', + 'ADM_LINKED_ACCOUNTS_OVERVIEW_EXPLAIN' => 'In this section you’ll find some usage statistics along with a list with the users that have links to other accounts.', 'LINKED_ACCOUNTS_COUNT' => 'Users with links', 'LINKED_ACCOUNTS_COUNT_EXPLAIN' => 'Amount of accounts that have at least one link.', 'LINK_COUNT' => 'Links', diff --git a/service/utils.php b/service/utils.php index 12effa2..b5b170b 100644 --- a/service/utils.php +++ b/service/utils.php @@ -49,11 +49,11 @@ public function get_user($key) if(is_numeric($key)) { - $sql .= 'WHERE user_id = ' . (int) $key . ';'; + $sql .= 'WHERE user_id = ' . (int) $key; } else { - $sql .= 'WHERE username_clean = \'' . $this->db->sql_escape(utf8_clean_string($key)) . '\';'; + $sql .= 'WHERE username_clean = ' . $this->db->sql_escape(utf8_clean_string($key)); } $result = $this->db->sql_query($sql); @@ -120,7 +120,7 @@ public function remove_links($links, $account = null) $len = count($links); foreach($links as $key => $account) { - $sql_where .= '(user_id = ' . (int) $this->db->sql_escape($account) . ' OR linked_user_id = ' . (int) $this->db->sql_escape($account) . ')'; + $sql_where .= '(user_id = ' . (int) $account . ' OR linked_user_id = ' . (int) $account . ')'; if($key != $len - 1) { @@ -148,8 +148,8 @@ public function already_linked($linked_id) { $sql = 'SELECT COUNT(user_id) AS already_linked FROM ' . $this->linkedacconts_table . ' - WHERE (user_id = ' . (int) $this->user->data['user_id'] . ' AND linked_user_id = ' . (int) $this->db->sql_escape($linked_id) . ') - OR (user_id = ' . (int) $this->db->sql_escape($linked_id) . ' AND linked_user_id = ' . (int) $this->user->data['user_id'] . ')'; + WHERE (user_id = ' . (int) $this->user->data['user_id'] . ' AND linked_user_id = ' . (int) $linked_id . ') + OR (user_id = ' . (int) $linked_id . ' AND linked_user_id = ' . (int) $this->user->data['user_id'] . ')'; $result = $this->db->sql_query($sql); $found_something = $this->db->sql_fetchfield('already_linked') != 0; @@ -169,8 +169,6 @@ public function already_linked($linked_id) */ public function can_switch_to($account_id) { - - $is_linked = false; $saved_account = null; foreach($this->get_linked_accounts() as $account) { @@ -181,13 +179,12 @@ public function can_switch_to($account_id) } } - if(!$saved_account || ($saved_account['user_type'] == 1 || $this->user->check_ban($account_id, false, $saved_account['user_email'], true) !== false)) + if(!$saved_account || ($saved_account['user_type'] == USER_INACTIVE || $this->user->check_ban($account_id, false, $saved_account['user_email'], true) !== false)) { return false; } return true; - } /** @@ -291,7 +288,7 @@ public function get_user_auth_info($username) $sql = 'SELECT user_id, user_password, user_email, user_type FROM ' . USERS_TABLE . ' - WHERE username_clean = \'' . $this->db->sql_escape(utf8_clean_string($username)) . '\''; + WHERE username_clean = ' . $this->db->sql_escape(utf8_clean_string($username)); $result = $this->db->sql_query($sql); $output = $this->db->sql_fetchrow($result); diff --git a/ucp/main_module.php b/ucp/main_module.php index 422845e..eb915b0 100644 --- a/ucp/main_module.php +++ b/ucp/main_module.php @@ -19,8 +19,6 @@ class main_module { - const MODULE_BASENAME = '-flerex-linkedaccounts-ucp-main_module'; - public $u_action; public $tpl_name; public $page_title; @@ -41,6 +39,8 @@ class main_module protected $utils; + protected $module_basename; + public function main($id, $mode) { global $config, $request, $template, $user, $db, $phpbb_container; @@ -58,6 +58,7 @@ public function main($id, $mode) $this->linkedacconts_table = $this->table_prefix . 'flerex_linkedaccounts'; $this->utils = $this->phpbb_container->get('flerex.linkedaccounts.utils'); + $this->module_basename = str_replace('\\', '-', $id); switch($mode) { @@ -152,7 +153,7 @@ private function mode_link() else { $this->utils->create_link($this->user->data['user_id'], $user['user_id']); - redirect(append_sid($this->phpbb_root_path . 'ucp.' . $this->phpEx, 'i=' . main_module::MODULE_BASENAME . '&mode=management')); + redirect(append_sid($this->phpbb_root_path . 'ucp.' . $this->phpEx, 'i=' . $this->module_basename . '&mode=management')); } } @@ -199,7 +200,7 @@ private function mode_management() $this->template->assign_vars(array( 'U_ACTION' => $this->u_action, - 'U_LINK_ACCOUNT' => append_sid($this->phpbb_root_path . 'ucp.' . $this->phpEx, 'i=' . main_module::MODULE_BASENAME . '&mode=link'), + 'U_LINK_ACCOUNT' => append_sid($this->phpbb_root_path . 'ucp.' . $this->phpEx, 'i=' . $this->module_basename . '&mode=link'), )); }