php
· 1.2 KiB · PHP
Surowy
<?php
require_once dirname(__FILE__) . '/../config.inc.php';
$db = \Typecho\Db::get();
try {
$query = $db->select('title', 'url', 'logo', 'description')
->from('table.friends')
->where('status = ?', 1);
$rows = $db->fetchAll($query);
$link_list = [];
foreach ($rows as $row) {
$name = $row['title'];
$link = $row['url'];
$avatar = $row['logo'] ?? '';
$descr = $row['description'];
$siteshot = "https://v2.xxapi.cn/api/screenshot?url=" . urlencode($link) . "&return=302";
$link_list[] = [
"name" => $name,
"link" => $link,
"avatar" => $avatar,
"descr" => $descr,
"siteshot" => $siteshot
];
}
$length = count($link_list);
$output = [
"link_list" => $link_list,
"length" => $length
];
header('Content-Type: application/json; charset=utf-8');
echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
} catch (\Typecho\Db\Exception $e) {
header('Content-Type: application/json; charset=utf-8');
echo json_encode(['error' => $e->getMessage()], JSON_UNESCAPED_UNICODE);
}
| 1 | <?php |
| 2 | require_once dirname(__FILE__) . '/../config.inc.php'; |
| 3 | $db = \Typecho\Db::get(); |
| 4 | try { |
| 5 | $query = $db->select('title', 'url', 'logo', 'description') |
| 6 | ->from('table.friends') |
| 7 | ->where('status = ?', 1); |
| 8 | $rows = $db->fetchAll($query); |
| 9 | $link_list = []; |
| 10 | foreach ($rows as $row) { |
| 11 | $name = $row['title']; |
| 12 | $link = $row['url']; |
| 13 | $avatar = $row['logo'] ?? ''; |
| 14 | $descr = $row['description']; |
| 15 | $siteshot = "https://v2.xxapi.cn/api/screenshot?url=" . urlencode($link) . "&return=302"; |
| 16 | |
| 17 | $link_list[] = [ |
| 18 | "name" => $name, |
| 19 | "link" => $link, |
| 20 | "avatar" => $avatar, |
| 21 | "descr" => $descr, |
| 22 | "siteshot" => $siteshot |
| 23 | ]; |
| 24 | } |
| 25 | $length = count($link_list); |
| 26 | $output = [ |
| 27 | "link_list" => $link_list, |
| 28 | "length" => $length |
| 29 | ]; |
| 30 | header('Content-Type: application/json; charset=utf-8'); |
| 31 | echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); |
| 32 | } catch (\Typecho\Db\Exception $e) { |
| 33 | header('Content-Type: application/json; charset=utf-8'); |
| 34 | echo json_encode(['error' => $e->getMessage()], JSON_UNESCAPED_UNICODE); |
| 35 | } |