From 85b324b00f63a2a92b67e536e656703a29663461 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?s=C3=B8renpeter?= Date: Tue, 12 Dec 2023 16:41:13 +0100 Subject: [PATCH] twtmention experiments --- index.php | 1 + views/twtmention_endpoint.php | 67 +++++++++++++++++++++++++++++++++++ views/webmention_endpoint.php | 22 ++++++------ 3 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 views/twtmention_endpoint.php diff --git a/index.php b/index.php index bddbf4d..5b6d865 100644 --- a/index.php +++ b/index.php @@ -38,6 +38,7 @@ $routes = [ //'/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 + '/twtmention' => 'twtmention_endpoint.php', '/webmention' => 'webmention_endpoint.php', ]; diff --git a/views/twtmention_endpoint.php b/views/twtmention_endpoint.php new file mode 100644 index 0000000..5a6925b --- /dev/null +++ b/views/twtmention_endpoint.php @@ -0,0 +1,67 @@ +]+)\s([^>]+)>/'; // Matches "@" + // Match only mention of specific URL from TARGET + return preg_match($pattern, $twt); +} + +if (stristr($_POST['source'], ".txt#")) { + header($_SERVER['SERVER_PROTOCOL'] . ' 202 Accepted'); + + // Split URL into fragment and file path, and retrurns twt maching date + $datetime = "/".parse_url($_POST['source'], PHP_URL_FRAGMENT)."/"; + //$twtfile = strtok($_POST['source'], "#"); + $txt = explode(PHP_EOL, $source); + $twt = preg_grep($datetime, $txt); + + + /* + if (twtMentionInSource($twt) { + $twtMention = "YES!"; + } + */ + + $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'] + ." -- ".$twt.$datetime + //." (IP: ".$_SERVER['REMOTE_ADDR'].")" + .PHP_EOL; + file_put_contents($logfile, $log, FILE_APPEND); + +} +else { + header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request'); + exit; +} + +?> diff --git a/views/webmention_endpoint.php b/views/webmention_endpoint.php index 82dcea6..1b82549 100644 --- a/views/webmention_endpoint.php +++ b/views/webmention_endpoint.php @@ -40,23 +40,23 @@ if (str_contains($url, ".txt#")) { if (stristr($source, $_POST['target'])) { -header($_SERVER['SERVER_PROTOCOL'] . ' 202 Accepted'); + 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. + # 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 */ + $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); + $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; + header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request'); + exit; } ?>