<?php
require_once dirname(__FILE__) . '/../config.inc.php';
$db = \Typecho\Db::get();
try {
    $query = $db->select('title', 'url', 'logo')
                ->from('table.friends')
                ->where('status = ?', 1);
    $rows = $db->fetchAll($query);
    $friends = [];
    foreach ($rows as $row) {
        $friends[] = [
            $row['title'],
            $row['url'],
            $row['logo'] ?? ''
        ];
    }
    $output = [
        'friends' => $friends
    ];
    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);
}