Naposledy aktivní 2 months ago

朋友圈精简版 friend.json 适配

Joe
php Raw
1<?php
2require_once dirname(__FILE__) . '/../config.inc.php';
3$db = \Typecho\Db::get();
4try {
5 $query = $db->select('title', 'url', 'logo')
6 ->from('table.friends')
7 ->where('status = ?', 1);
8 $rows = $db->fetchAll($query);
9 $friends = [];
10 foreach ($rows as $row) {
11 $friends[] = [
12 $row['title'],
13 $row['url'],
14 $row['logo'] ?? ''
15 ];
16 }
17 $output = [
18 'friends' => $friends
19 ];
20 header('Content-Type: application/json; charset=utf-8');
21 echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
22} catch (\Typecho\Db\Exception $e) {
23 header('Content-Type: application/json; charset=utf-8');
24 echo json_encode(['error' => $e->getMessage()], JSON_UNESCAPED_UNICODE);
25}