mirror of
https://github.com/claradex/nativegallery.git
synced 2024-12-22 08:30:56 +03:00
совместимость с api transphoto.org
This commit is contained in:
parent
2a8ca039fc
commit
4f542c99cf
5 changed files with 121 additions and 2 deletions
72
app/Controllers/Api/Images/LoadRecent.php
Normal file
72
app/Controllers/Api/Images/LoadRecent.php
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
namespace App\Controllers\Api\Images;
|
||||
|
||||
use \App\Services\{Auth, DB, Date, HTMLParser};
|
||||
use DOMDocument, DOMXPath;
|
||||
|
||||
class LoadRecent
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$response = [];
|
||||
|
||||
if ($_POST['serverhost'] === 'transphoto.org') {
|
||||
$photos = DB::query('SELECT * FROM photos WHERE moderated=1 ORDER BY id DESC LIMIT 30');
|
||||
|
||||
|
||||
foreach ($photos as $p) {
|
||||
if ($p['posted_at'] === 943909200 || Date::zmdate($p['posted_at']) === '30 ноября 1999 в 00:00') {
|
||||
$date = 'дата не указана';
|
||||
} else {
|
||||
$date = Date::zmdate($p['posted_at']);
|
||||
}
|
||||
$user = DB::query('SELECT * FROM users WHERE id=:id', array(':id' => $p['user_id']))[0];
|
||||
|
||||
$response[] = [
|
||||
'id' => $p['id'],
|
||||
'place' => htmlspecialchars($p['place']),
|
||||
'date' => $date,
|
||||
'user_name' => $user['username'],
|
||||
'user_id' => $p['user_id'],
|
||||
'photourl' => $p['photourl'],
|
||||
'photourl_small' => 'https://' . $_SERVER['SERVER_NAME'] . '/api/photo/compress?url=' . $p['photourl']
|
||||
];
|
||||
}
|
||||
} else {
|
||||
$url = 'https://transphoto.org/api.php?action=get-recent-photos&width=802&lastpid=0&hidden=0';
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$responsed = curl_exec($ch);
|
||||
if (curl_errno($ch)) {
|
||||
$response = [
|
||||
'error' => 1,
|
||||
'errorcode' => 'СТТС не отвечает. Попробуйте позже'
|
||||
];
|
||||
} else {
|
||||
$data = json_decode($responsed, true);
|
||||
foreach ($data as $d) {
|
||||
$response[] = [
|
||||
'id' => $d['pid'],
|
||||
'place' => strip_tags($d['links']),
|
||||
'date' => $d['pdate'],
|
||||
'photourl_small' => 'https://transphoto.org'.$d['prw'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($response);
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ use \App\Controllers\Api\Images\{Upload};
|
|||
use \App\Controllers\Api\Images\Rate as PhotoVote;
|
||||
use \App\Controllers\Api\Images\Compress as PhotoCompress;
|
||||
use \App\Controllers\Api\Images\CheckAll as PhotoCheckAll;
|
||||
use \App\Controllers\Api\Images\LoadRecent as PhotoLoadRecent;
|
||||
use \App\Controllers\Api\Images\Stats as PhotoStats;
|
||||
use \App\Controllers\Api\Images\Comments\Create as PhotoComment;
|
||||
use \App\Controllers\Api\Images\Comments\Load as PhotoCommentLoad;
|
||||
|
@ -58,6 +59,9 @@ class ApiController
|
|||
public static function checkallphotos() {
|
||||
return new PhotoCheckAll();
|
||||
}
|
||||
public static function recentphotos() {
|
||||
return new PhotoLoadRecent();
|
||||
}
|
||||
public static function photostats() {
|
||||
return new PhotoStats();
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ class Routes
|
|||
Router::get('/top30', 'MainController@top30');
|
||||
Router::get('/photoext', 'PhotoController@photoext');
|
||||
Router::get('/api/photo/compress', 'ApiController@photocompress');
|
||||
|
||||
Router::get('/api/photo/loadrecent', 'ApiController@recentphotos');
|
||||
|
||||
|
||||
|
||||
|
|
43
app/Services/HTMLParser.php
Normal file
43
app/Services/HTMLParser.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
use DOMDocument, DOMXPath;
|
||||
|
||||
class HTMLParser
|
||||
{
|
||||
|
||||
|
||||
public static function parse($url, $mask)
|
||||
{
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
$response = curl_exec($ch);
|
||||
|
||||
if (curl_errno($ch)) {
|
||||
echo 'Ошибка cURL: ' . curl_error($ch);
|
||||
return;
|
||||
}
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
$dom = new DOMDocument;
|
||||
|
||||
@$dom->loadHTML($response);
|
||||
|
||||
$xpath = new DOMXPath($dom);
|
||||
|
||||
$nodes = $xpath->query($mask);
|
||||
|
||||
if ($nodes->length > 0) {
|
||||
$firstNode = $nodes->item(0)->textContent;
|
||||
$cleanedContent = ltrim($firstNode);
|
||||
return $cleanedContent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@ use App\Models\{User, Vote, Comment};
|
|||
$id = explode('/', $_SERVER['REQUEST_URI'])[2];
|
||||
$photo = new \App\Models\Photo($id);
|
||||
if ($photo->i('id') !== null) {
|
||||
if ($photo->content('video') != 'null') {
|
||||
if ($photo->content('video') != null) {
|
||||
$extname = 'видео';
|
||||
$extnamef = 'видеоролик';
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue