Get a user row from our users cache
public get_user ( integer $user_id, boolean $query = false ) : array | boolean | ||
$user_id | integer | User ID of the user you want to retreive |
$query | boolean | Should we query the database if this user has not yet been loaded? Typically this should be left as false and you should make sure you load users ahead of time with load_users() |
Результат | array | boolean | Row from the database of the user or Anonymous if the user wasn't loaded/does not exist or bool False if the anonymous user was not loaded |
/** * Notify using phpBB messenger * * @param int $notify_method Notify method for messenger (e.g. NOTIFY_IM) * @param string $template_dir_prefix Base directory to prepend to the email template name * * @return null */ protected function notify_using_messenger($notify_method, $template_dir_prefix = '') { if (empty($this->queue)) { return; } // Load all users we want to notify (we need their email address) $user_ids = $users = array(); foreach ($this->queue as $notification) { $user_ids[] = $notification->user_id; } // We do not send emails to banned users if (!function_exists('phpbb_get_banned_user_ids')) { include $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext; } $banned_users = phpbb_get_banned_user_ids($user_ids); // Load all the users we need $this->user_loader->load_users($user_ids); // Load the messenger if (!class_exists('messenger')) { include $this->phpbb_root_path . 'includes/functions_messenger.' . $this->php_ext; } $messenger = new \messenger(); // Time to go through the queue and send emails /** @var \phpbb\notification\type\type_interface $notification */ foreach ($this->queue as $notification) { if ($notification->get_email_template() === false) { continue; } $user = $this->user_loader->get_user($notification->user_id); if ($user['user_type'] == USER_IGNORE || $user['user_type'] == USER_INACTIVE && $user['user_inactive_reason'] == INACTIVE_MANUAL || in_array($notification->user_id, $banned_users)) { continue; } $messenger->template($notification->get_email_template(), $user['user_lang'], '', $template_dir_prefix); $messenger->set_addresses($user); $messenger->assign_vars(array_merge(array('USERNAME' => $user['username'], 'U_NOTIFICATION_SETTINGS' => generate_board_url() . '/ucp.' . $this->php_ext . '?i=ucp_notifications&mode=notification_options'), $notification->get_email_template_variables())); $messenger->send($notify_method); } // Save the queue in the messenger class (has to be called or these emails could be lost?) $messenger->save_queue(); // We're done, empty the queue $this->empty_queue(); }
/** * Executes the command user:delete * * Deletes a user from the database. An option to delete the user's posts * is available, by default posts will be retained. * * @param InputInterface $input The input stream used to get the options * @param OutputInterface $output The output stream, used to print messages * * @return int 0 if all is well, 1 if any errors occurred */ protected function execute(InputInterface $input, OutputInterface $output) { $name = $input->getArgument('username'); $mode = $input->getOption('delete-posts') ? 'remove' : 'retain'; if ($name) { $io = new SymfonyStyle($input, $output); $user_id = $this->user_loader->load_user_by_username($name); $user_row = $this->user_loader->get_user($user_id); if ($user_row['user_id'] == ANONYMOUS) { $io->error($this->language->lang('NO_USER')); return 1; } if (!function_exists('user_delete')) { require $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext; } user_delete($mode, $user_row['user_id'], $user_row['username']); $this->log->add('admin', ANONYMOUS, '', 'LOG_USER_DELETED', false, array($user_row['username'])); $io->success($this->language->lang('USER_DELETED')); } return 0; }
/** * Executes the command user:activate * * Activate (or deactivate) a user account * * @param InputInterface $input The input stream used to get the options * @param OutputInterface $output The output stream, used to print messages * * @return int 0 if all is well, 1 if any errors occurred */ protected function execute(InputInterface $input, OutputInterface $output) { $io = new SymfonyStyle($input, $output); $name = $input->getArgument('username'); $mode = $input->getOption('deactivate') ? 'deactivate' : 'activate'; $user_id = $this->user_loader->load_user_by_username($name); $user_row = $this->user_loader->get_user($user_id); if ($user_row['user_id'] == ANONYMOUS) { $io->error($this->language->lang('NO_USER')); return 1; } // Check if the user is already active (or inactive) if ($mode == 'activate' && $user_row['user_type'] != USER_INACTIVE) { $io->error($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_ACTIVE')); return 1; } else { if ($mode == 'deactivate' && $user_row['user_type'] == USER_INACTIVE) { $io->error($this->language->lang('CLI_DESCRIPTION_USER_ACTIVATE_INACTIVE')); return 1; } } // Activate the user account if (!function_exists('user_active_flip')) { require $this->phpbb_root_path . 'includes/functions_user.' . $this->php_ext; } user_active_flip($mode, $user_row['user_id']); // Notify the user upon activation if ($mode == 'activate' && $this->config['require_activation'] == USER_ACTIVATION_ADMIN) { $this->send_notification($user_row, $input); } // Log and display the result $msg = $mode == 'activate' ? 'USER_ADMIN_ACTIVATED' : 'USER_ADMIN_DEACTIVED'; $log = $mode == 'activate' ? 'LOG_USER_ACTIVE' : 'LOG_USER_INACTIVE'; $this->log->add('admin', ANONYMOUS, '', $log, false, array($user_row['username'])); $this->log->add('user', ANONYMOUS, '', $log . '_USER', false, array('reportee_id' => $user_row['user_id'])); $io->success($this->language->lang($msg)); return 0; }
/** * Get email template variables * * @return array */ public function get_email_template_variables() { $user_data = $this->user_loader->get_user($this->get_data('from_user_id')); return array('AUTHOR_NAME' => htmlspecialchars_decode($user_data['username']), 'SUBJECT' => htmlspecialchars_decode(censor_text($this->get_data('message_subject'))), 'U_VIEW_MESSAGE' => generate_board_url() . '/ucp.' . $this->php_ext . "?i=pm&mode=view&p={$this->item_id}"); }
/** * {@inheritdoc} */ public function get_email_template_variables() { $user_data = $this->user_loader->get_user($this->item_id); return array('GROUP_NAME' => htmlspecialchars_decode($this->get_data('group_name')), 'REQUEST_USERNAME' => htmlspecialchars_decode($user_data['username']), 'U_PENDING' => generate_board_url() . "/ucp.{$this->php_ext}?i=groups&mode=manage&action=list&g={$this->item_parent_id}", 'U_GROUP' => generate_board_url() . "/memberlist.{$this->php_ext}?mode=group&g={$this->item_parent_id}"); }