tangled
alpha
login
or
join now
benharri.org
/
atblog
2
fork
atom
tiny whitewind client
2
fork
atom
overview
issues
pulls
pipelines
save resolved identity stuff to session
benharri.org
6 months ago
8aadda68
b1fc07b6
+18
-16
1 changed file
expand all
collapse all
unified
split
index.php
+18
-16
index.php
···
17
17
$environment->addExtension(new AutolinkExtension());
18
18
$converter = new MarkdownConverter($environment);
19
19
20
20
+
function getSlingshot(string $user): mixed
21
21
+
{
22
22
+
return $_SESSION["slingshot"][$user] ??=
23
23
+
json_decode(file_get_contents("https://slingshot.microcosm.blue/xrpc/com.bad-example.identity.resolveMiniDoc?identifier=$user"));
24
24
+
}
25
25
+
26
26
+
session_start();
27
27
+
20
28
// short circuit if no other user is specified
21
29
$user = $_GET["user"] ?? "benharri.org";
22
30
$format = $_GET["format"] ?? "html";
23
31
24
24
-
$slingshot = json_decode(file_get_contents("https://slingshot.microcosm.blue/xrpc/com.bad-example.identity.resolveMiniDoc?identifier=$user"));
25
25
-
$pds = $slingshot->pds;
26
26
-
$did = $slingshot->did;
27
27
-
$handle = $slingshot->handle;
28
28
-
29
29
-
$user_url = "?user=$handle";
30
30
-
$at_uri = "at://$handle/com.whtwnd.blog.entry";
31
31
-
$at_permauri = "at://$did/com.whtwnd.blog.entry";
32
32
+
$id = getSlingshot($user);
33
33
+
$user_url = "?user=$id->handle";
34
34
+
$at_uri = "at://$id->handle/com.whtwnd.blog.entry";
35
35
+
$at_permauri = "at://$id->did/com.whtwnd.blog.entry";
32
36
33
37
if (isset($_GET["p"])) {
34
38
// get single post record
35
39
$query = http_build_query([
36
36
-
"repo" => $did,
40
40
+
"repo" => $id->did,
37
41
"collection" => "com.whtwnd.blog.entry",
38
42
"rkey" => $_GET["p"]
39
43
]);
40
40
-
$url = $pds . "/xrpc/com.atproto.repo.getRecord?" . $query;
41
41
-
$post = json_decode(file_get_contents($url), true);
44
44
+
$post = json_decode(file_get_contents("$id->pds/xrpc/com.atproto.repo.getRecord?$query"), true);
42
45
43
46
if ($format === "markdown") {
44
47
// print raw markdown and we're done
45
48
header("Content-Type: text/markdown; variant=GFM");
46
46
-
echo '# ' . $post["value"]["title"] . PHP_EOL . PHP_EOL;
47
47
-
echo $post["value"]["content"];
49
49
+
echo '# ' . $post["value"]["title"] . PHP_EOL . PHP_EOL . $post["value"]["content"];
48
50
die();
49
51
}
50
52
···
55
57
// get all posts
56
58
// TODO: pagination
57
59
$q = http_build_query([
58
58
-
"repo" => $did,
60
60
+
"repo" => $id->did,
59
61
"collection" => "com.whtwnd.blog.entry",
60
62
"limit" => 100
61
63
]);
62
62
-
$posts = json_decode(file_get_contents($pds . "/xrpc/com.atproto.repo.listRecords?" . $q), true)["records"];
64
64
+
$posts = json_decode(file_get_contents("$id->pds/xrpc/com.atproto.repo.listRecords?$q"), true)["records"];
63
65
}
64
66
65
67
?>
···
75
77
<link rel="alternate" type="text/markdown; variant=GFM" href="https://bhh.sh/pub/atblog/<?=$post_url?>&format=markdown">
76
78
<?php } ?>
77
79
<link rel="alternate" href="<?=$at_permauri?>">
78
78
-
<title>atblog: <?=$post["value"]["title"] ?? $handle?></title>
80
80
+
<title>atblog: <?=$post["value"]["title"] ?? $id->handle ?></title>
79
81
</head>
80
82
81
83
<body>