UserInfoFromIP.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * This file is part of the ForkBB <https://github.com/forkbb>.
  4. *
  5. * @copyright (c) Visman <mio.visman@yandex.ru, https://github.com/MioVisman>
  6. * @license The MIT License (MIT)
  7. */
  8. declare(strict_types=1);
  9. namespace ForkBB\Models\Post;
  10. use ForkBB\Models\Action;
  11. use ForkBB\Models\Post\Post;
  12. class UserInfoFromIP extends Action
  13. {
  14. /**
  15. * Возвращает массив данных с id пользователей (именами гостей)
  16. */
  17. public function userInfoFromIP(string $ip): array
  18. {
  19. $vars = [
  20. ':ip' => $ip,
  21. ];
  22. $query = 'SELECT p.poster_id, p.poster
  23. FROM ::posts AS p
  24. WHERE p.poster_ip=?s:ip
  25. GROUP BY p.poster_id, p.poster
  26. ORDER BY p.poster';
  27. $stmt = $this->c->DB->query($query, $vars);
  28. $result = [];
  29. $ids = [];
  30. while ($row = $stmt->fetch()) {
  31. if ($row['poster_id'] < 1) {
  32. $result[] = $row['poster'];
  33. } elseif (empty($ids[$row['poster_id']])) {
  34. $result[] = $row['poster_id'];
  35. $ids[$row['poster_id']] = true;
  36. }
  37. }
  38. return $result;
  39. }
  40. }