From 2180bca050064b1a33dd0a138dd9b69c71f84247 Mon Sep 17 00:00:00 2001 From: themohooks <81331307+themohooks@users.noreply.github.com> Date: Thu, 3 Oct 2024 20:35:13 +0300 Subject: [PATCH] users show from transphoto --- app/Controllers/Api/Images/LoadRecent.php | 4 +- app/Controllers/Api/Users/LoadUser.php | 111 ++++++++++++++++++++++ app/Controllers/ApiController.php | 4 + app/Core/Routes.php | 2 +- 4 files changed, 118 insertions(+), 3 deletions(-) create mode 100644 app/Controllers/Api/Users/LoadUser.php diff --git a/app/Controllers/Api/Images/LoadRecent.php b/app/Controllers/Api/Images/LoadRecent.php index 4173a5a..3a55032 100644 --- a/app/Controllers/Api/Images/LoadRecent.php +++ b/app/Controllers/Api/Images/LoadRecent.php @@ -12,7 +12,7 @@ class LoadRecent { $response = []; - if ($_POST['serverhost'] === 'transphoto.org') { + if ($_POST['serverhost'] != 'transphoto.org') { $photos = DB::query('SELECT * FROM photos WHERE moderated=1 ORDER BY id DESC LIMIT 30'); @@ -45,7 +45,7 @@ class LoadRecent if (curl_errno($ch)) { $response = [ 'error' => 1, - 'errorcode' => 'СТТС не отвечает. Попробуйте позже' + 'errorcode' => 'СТТС не отвечает. Попробуйте позже', ]; } else { $data = json_decode($responsed, true); diff --git a/app/Controllers/Api/Users/LoadUser.php b/app/Controllers/Api/Users/LoadUser.php new file mode 100644 index 0000000..b04d8e6 --- /dev/null +++ b/app/Controllers/Api/Users/LoadUser.php @@ -0,0 +1,111 @@ +i('id') != null) { + $response[] = [ + 'id' => $user->i('id'), + 'username' => $user->i('username'), + 'regdate' => $user->content('regdate'), + 'online' => $user->i('online'), + 'photourl' => $user->i('photourl'), + ]; + } else { + $response = [ + 'error' => 1, + 'errorcode' => 'Пользователь не найден' + ]; + } + + } else { + $url = "https://transphoto.org/author/".$id; + + // Инициализируем cURL + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HTTPHEADER, array( + 'Cookie: '.NGALLERY['transphoto']['cookie'] + )); + + + $html = curl_exec($ch); + curl_close($ch); + + $dom = new DOMDocument(); + libxml_use_internal_errors(true); + $dom->loadHTML($html); + libxml_clear_errors(); + + $xpath = new DOMXPath($dom); + $mainNode = $xpath->query('//td[@class="main"]')->item(0); + + if ($mainNode) { + + + $titleNode = $xpath->query('.//h1', $mainNode)->item(0); + $title = $titleNode ? $titleNode->textContent : 'Не найдено'; + + $realNameNode = $xpath->query('.//tr[td[contains(text(),"Реальное имя:")]]/td[2]/b', $mainNode)->item(0); + $realName = $realNameNode ? $realNameNode->textContent : 'Не найдено'; + + // Откуда + $city = $xpath->query('.//tr[td[contains(text(),"Откуда:")]]/td[2]', $mainNode)->item(0)->textContent; + + // Дата рождения + $birthDate = $xpath->query('.//tr[td[contains(text(),"Дата рождения:")]]/td[2]', $mainNode)->item(0)->textContent; + + // Дата регистрации + $regDate = $xpath->query('.//tr[td[contains(text(),"Дата регистрации:")]]/td[2]/span', $mainNode)->item(0)->textContent; + + // Рейтинг + $rating = $xpath->query('.//tr[td[contains(text(),"Рейтинг:")]]/td[2]/span', $mainNode)->item(0)->textContent; + + // Пол + $gender = $xpath->query('.//tr[td[contains(text(),"Пол:")]]/td[2]/span', $mainNode)->item(0)->textContent; + + // Владение языками + $languages = $xpath->query('.//tr[td[contains(text(),"Владение языками:")]]/td[2]/span', $mainNode)->item(0)->textContent; + + + + + + + + $response[] = [ + 'id' => $id, + 'username' => $title, + 'online' => 0, + 'photourl' => 'https://transphoto.org/_update_temp/userphotos/'.$id.'.jpg' + ]; + + } else { + echo "Блок не найден."; + } + + + + + + + } + + + header('Content-Type: application/json'); + echo json_encode($response); + } +} diff --git a/app/Controllers/ApiController.php b/app/Controllers/ApiController.php index d4f903a..0fb491b 100644 --- a/app/Controllers/ApiController.php +++ b/app/Controllers/ApiController.php @@ -16,6 +16,7 @@ use \App\Controllers\Api\Images\Comments\Create as PhotoComment; use \App\Controllers\Api\Images\Comments\Load as PhotoCommentLoad; use \App\Controllers\Api\Images\Comments\Rate as PhotoCommentVote; use \App\Controllers\Api\Profile\Update as ProfileUpdate; +use \App\Controllers\Api\Users\LoadUser as UserLoad; use \App\Controllers\Api\Admin\Images\SetVisibility as AdminPhotoSetVisibility; use \App\Controllers\Api\Admin\CreateNews as AdminCreateNews; use \App\Controllers\Api\Admin\LoadNews as AdminLoadNews; @@ -62,6 +63,9 @@ class ApiController public static function recentphotos() { return new PhotoLoadRecent(); } + public static function loaduser() { + return new UserLoad(); + } public static function photostats() { return new PhotoStats(); } diff --git a/app/Core/Routes.php b/app/Core/Routes.php index eab679e..de702d0 100644 --- a/app/Core/Routes.php +++ b/app/Core/Routes.php @@ -31,7 +31,7 @@ class Routes Router::get('/photoext', 'PhotoController@photoext'); Router::get('/api/photo/compress', 'ApiController@photocompress'); Router::get('/api/photo/loadrecent', 'ApiController@recentphotos'); - + Router::get('/api/users/load/$id', 'ApiController@loaduser'); if (Auth::userid() > 0) {