Webmention endpoint and mention.txt feed added

This commit is contained in:
sørenpeter 2023-11-27 08:24:41 +01:00
parent 1759dc7336
commit 6c69dd89af
7 changed files with 48 additions and 4 deletions

View file

@ -34,9 +34,11 @@ $routes = [
'/login' => 'login.php',
'/logout' => 'logout.php',
'/profile' => 'profile.php',
'/profile' => 'profile.php',
//'/profile/([a-zA-Z0-9_-]+)' => 'profile.php',
'/conv/([a-zA-Z0-9]{7})' => 'conv.php', // matches only twtHash of exactly 7 alphanumeric characters
'/post/([a-zA-Z0-9]{7})' => 'post.php', // matches only twtHash of exactly 7 alphanumeric characters
'/webmention' => 'webmention_endpoint.php',
];
// Loop through the defined routes and try to match the request URI
@ -64,4 +66,4 @@ echo "<h1>Oops! Page not found.</h1>";
/* Credit:
- PHP FOR BEGINNERS #4 - Create a dynamic Router: https://www.youtube.com/watch?v=eaHBK2XJ5Io
- https://chat.openai.com/c/3082a22a-d70e-4740-891c-9872f5da2180
*/
*/

View file

@ -253,6 +253,7 @@ function replaceMentionsFromTwt(string $twtString): string {
//$replacement = '<a href="/?url=$2">@$1</a>';
$replacement = '<a href="'.str_replace("/index.php", "", $_SERVER["SCRIPT_NAME"]).'/?profile=$2">@$1</a>';
$replacement .= '<a href="$2" class="webmention"></a>'; // Adds a hidden link direcly to the twtxt.txt of the mentioned target
#$twtString = '@<nick https://eapl.mx/twtxt.txt>';

View file

@ -8,6 +8,7 @@ $profile = getTwtsFromTwtxtString($config['public_txt_url']);
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="webmention" href="<?= $baseURL ?>/webmention" />
<link rel="stylesheet" href="<?= $baseURL ?>/libs/simple.css">
<link rel="stylesheet" type="text/css" href="<?= $baseURL ?>/style.css">
<title><?= $title ?></title>
@ -19,7 +20,6 @@ $profile = getTwtsFromTwtxtString($config['public_txt_url']);
<a href="<?= $baseURL ?>">
<img class="avatar" src="<?= $profile->avatar ?>" alt="" loading="lazy">
<!-- Timeline for --><?= $profile->nick ?></a>@<?= parse_url($profile->mainURL, PHP_URL_HOST); ?>
</p>
<nav>

View file

@ -19,11 +19,11 @@
<div class="twt-msg">
<?= $twt->content ?>
<!-- Not sure what this does...
<!-- Not sure what this does...
<?php foreach ($twt->mentions as $mention) { ?>
<br><?= $mention['nick'] ?>(<?= $mention['url'] ?>)
<?php } ?>
-->
-->
</div>
<small>

1
private/.htaccess Normal file
View file

@ -0,0 +1 @@
deny from all

View file

@ -0,0 +1,40 @@
<?php
# Source: https://gist.github.com/adactio/6484118
# Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
# http://creativecommons.org/publicdomain/zero/1.0/
if (!isset($_POST['source']) || !isset($_POST['target'])) {
print('Please send a propper webmention to this endpoint');
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
exit;
}
ob_start();
$ch = curl_init($_POST['source']);
curl_setopt($ch,CURLOPT_USERAGENT,'Timeline Twtxt Web-client (webmention.org)');
curl_setopt($ch,CURLOPT_HEADER,0);
$ok = curl_exec($ch);
curl_close($ch);
$source = ob_get_contents();
ob_end_clean();
if (stristr($source, $_POST['target'])) {
header($_SERVER['SERVER_PROTOCOL'] . ' 202 Accepted');
# Now do something with $source e.g. parse it for h-entry and h-card and store what you find.
$logfile = './mentions.txt'; /* Make sure file is writeable */
$log = date("Y-m-d\TH:i:s\Z") . "\t"
."Recived webmention from ".$_POST['source']
." mentioning ".$_POST['target']
." (IP: ".$_SERVER['REMOTE_ADDR'].")".PHP_EOL;
file_put_contents($logfile, $log, FILE_APPEND);
}
else {
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
exit;
}
?>

BIN
webmention.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB