mirror of
https://github.com/sorenpeter/timeline.git
synced 2025-12-16 11:27:01 +00:00
Webmention endpoint and mention.txt feed added
This commit is contained in:
parent
1759dc7336
commit
6c69dd89af
7 changed files with 48 additions and 4 deletions
|
|
@ -34,9 +34,11 @@ $routes = [
|
||||||
'/login' => 'login.php',
|
'/login' => 'login.php',
|
||||||
'/logout' => 'logout.php',
|
'/logout' => 'logout.php',
|
||||||
'/profile' => 'profile.php',
|
'/profile' => 'profile.php',
|
||||||
|
'/profile' => 'profile.php',
|
||||||
//'/profile/([a-zA-Z0-9_-]+)' => '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
|
'/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
|
'/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
|
// Loop through the defined routes and try to match the request URI
|
||||||
|
|
|
||||||
|
|
@ -253,6 +253,7 @@ function replaceMentionsFromTwt(string $twtString): string {
|
||||||
//$replacement = '<a href="/?url=$2">@$1</a>';
|
//$replacement = '<a href="/?url=$2">@$1</a>';
|
||||||
|
|
||||||
$replacement = '<a href="'.str_replace("/index.php", "", $_SERVER["SCRIPT_NAME"]).'/?profile=$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>';
|
#$twtString = '@<nick https://eapl.mx/twtxt.txt>';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ $profile = getTwtsFromTwtxtString($config['public_txt_url']);
|
||||||
<head>
|
<head>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<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" href="<?= $baseURL ?>/libs/simple.css">
|
||||||
<link rel="stylesheet" type="text/css" href="<?= $baseURL ?>/style.css">
|
<link rel="stylesheet" type="text/css" href="<?= $baseURL ?>/style.css">
|
||||||
<title><?= $title ?></title>
|
<title><?= $title ?></title>
|
||||||
|
|
@ -19,7 +20,6 @@ $profile = getTwtsFromTwtxtString($config['public_txt_url']);
|
||||||
<a href="<?= $baseURL ?>">
|
<a href="<?= $baseURL ?>">
|
||||||
<img class="avatar" src="<?= $profile->avatar ?>" alt="" loading="lazy">
|
<img class="avatar" src="<?= $profile->avatar ?>" alt="" loading="lazy">
|
||||||
<!-- Timeline for --><?= $profile->nick ?></a>@<?= parse_url($profile->mainURL, PHP_URL_HOST); ?>
|
<!-- Timeline for --><?= $profile->nick ?></a>@<?= parse_url($profile->mainURL, PHP_URL_HOST); ?>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
<nav>
|
<nav>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
<?php foreach ($twt->mentions as $mention) { ?>
|
<?php foreach ($twt->mentions as $mention) { ?>
|
||||||
<br><?= $mention['nick'] ?>(<?= $mention['url'] ?>)
|
<br><?= $mention['nick'] ?>(<?= $mention['url'] ?>)
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
-->
|
-->
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<small>
|
<small>
|
||||||
|
|
|
||||||
1
private/.htaccess
Normal file
1
private/.htaccess
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
deny from all
|
||||||
40
views/webmention_endpoint.php
Normal file
40
views/webmention_endpoint.php
Normal 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
BIN
webmention.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 8.5 KiB |
Loading…
Reference in a new issue