mirror of
https://github.com/sorenpeter/timeline.git
synced 2025-12-15 10:57:01 +00:00
distinguish Webmentions from twtxt and brid.gy plus better CSS
This commit is contained in:
parent
566d24017d
commit
9edae5a91e
4 changed files with 68 additions and 41 deletions
|
|
@ -6,7 +6,7 @@
|
|||
"Nimbus Sans L", Roboto, "Noto Sans", "Segoe UI", Arial, Helvetica,
|
||||
"Helvetica Neue", sans-serif;
|
||||
--mono-font: Consolas, Menlo, Monaco, "Andale Mono", "Ubuntu Mono", monospace;
|
||||
--standard-border-radius: 5px;
|
||||
--standard-border-radius: 0.25rem;
|
||||
|
||||
/* Default (light) theme */
|
||||
--bg: #fff;
|
||||
|
|
@ -66,6 +66,11 @@ header > nav select {
|
|||
header > nav a span { display: none; }
|
||||
}
|
||||
|
||||
.notice {
|
||||
border-radius: 0.25rem;
|
||||
margin: 2rem 0.5rem;
|
||||
}
|
||||
|
||||
/* === Timeline Style === */
|
||||
|
||||
.right {
|
||||
|
|
@ -184,7 +189,6 @@ a.author {
|
|||
color: var(--accent);
|
||||
}
|
||||
|
||||
|
||||
.profile-nav {
|
||||
margin-top: 1rem;
|
||||
font-size: smaller;
|
||||
|
|
|
|||
33
partials/webmentions_send.php
Normal file
33
partials/webmentions_send.php
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
// Send webmentions (TODO: move to it own file?)
|
||||
$new_mentions = getMentionsFromTwt($twt);
|
||||
|
||||
foreach ($new_mentions as $mention) {
|
||||
//print_r(getMentionsFromTwt($twt));
|
||||
//echo $mention["nick"] . " from " . $mention["url"]."<br>";
|
||||
|
||||
// Detect webmention endpoint define in twtxt.txt as `# webmention = URL`
|
||||
$targets_webmention_endpoint = getSingleParameter("webmention", file_get_contents($mention["url"]));
|
||||
|
||||
if (!isset($targets_webmention_endpoint)) {
|
||||
echo "<p class='notice'>No endpoint found in: ".$mention["url"]."</p>";
|
||||
|
||||
} else {
|
||||
|
||||
$new_twt_url = $public_txt_url."#:~:text=".$datetime;
|
||||
//$target_url = $mention["url"];
|
||||
$payload = "source=".$new_twt_url."&target=".$mention["url"];
|
||||
//echo $payload;
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $targets_webmention_endpoint);
|
||||
curl_setopt($curl, CURLOPT_POST, TRUE);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
|
||||
$data = curl_exec($curl);
|
||||
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
|
||||
curl_close($curl);
|
||||
|
||||
echo "<p class='notice'>A webmention was send to: ".$targets_webmention_endpoint." (Status: $status)</p>";
|
||||
}
|
||||
}
|
||||
|
|
@ -83,37 +83,8 @@ if (isset($_POST['submit'])) {
|
|||
$file_write_result = file_put_contents($txt_file_path, $contents);
|
||||
// TODO: replace with file_put_contents($logfile, $log, FILE_APPEND) -- https://www.w3schools.com/php/func_filesystem_file_put_contents.asp
|
||||
|
||||
// Send webmentions (TODO: move to it own file?)
|
||||
$new_mentions = getMentionsFromTwt($twt);
|
||||
|
||||
foreach ($new_mentions as $mention) {
|
||||
//print_r(getMentionsFromTwt($twt));
|
||||
//echo $mention["nick"] . " from " . $mention["url"]."<br>";
|
||||
|
||||
// Detect webmention endpoint define in twtxt.txt as `# webmention = URL`
|
||||
$targets_webmention_endpoint = getSingleParameter("webmention", file_get_contents($mention["url"]));
|
||||
|
||||
if (!isset($targets_webmention_endpoint)) {
|
||||
echo "<p>No endpoint found in: ".$mention["url"]."</p>";
|
||||
|
||||
} else {
|
||||
|
||||
$new_twt_url = $public_txt_url."#:~:text=".$datetime;
|
||||
//$target_url = $mention["url"];
|
||||
$payload = "source=".$new_twt_url."&target=".$mention["url"];
|
||||
//echo $payload;
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_URL, $targets_webmention_endpoint);
|
||||
curl_setopt($curl, CURLOPT_POST, TRUE);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, $payload);
|
||||
$data = curl_exec($curl);
|
||||
$status = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
|
||||
curl_close($curl);
|
||||
|
||||
echo "<p>A webmention was send to: ".$targets_webmention_endpoint." (Status: $status)</p>";
|
||||
}
|
||||
}
|
||||
// Send webmentions
|
||||
include_once 'partials/webmentions_send.php';
|
||||
|
||||
//header('Refresh:0; url=.');
|
||||
//header("Location: refresh?url=".$public_txt_url); // Trying to fix issue with douple posting
|
||||
|
|
|
|||
|
|
@ -3,6 +3,11 @@
|
|||
# Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
# http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
// Set path to your mentions twtxt file:
|
||||
$logfile = './mentions.txt'; /* Make sure file is writeable */
|
||||
|
||||
|
||||
|
||||
if (!isset($_POST['source']) || !isset($_POST['target'])) {
|
||||
print('Please send a propper webmention to this endpoint');
|
||||
header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad Request');
|
||||
|
|
@ -15,26 +20,40 @@ 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();
|
||||
$sourceFile = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
if (stristr($source, $_POST['target'])) {
|
||||
|
||||
// Log if Webmention is not a twtxt-formated by chekcing for text fragment:
|
||||
if(!stristr($_POST['source'], ":~:text=")) {
|
||||
|
||||
$log = date("Y-m-d\TH:i:s\Z") . "\t"
|
||||
."Recived a non-twtxt webmention from ".$_POST['source']."
"
|
||||
." mentioning ".$_POST['target']."
"
|
||||
." (IP: ".$_SERVER['REMOTE_ADDR'].")"."
"
|
||||
.PHP_EOL;
|
||||
|
||||
file_put_contents($logfile, $log, FILE_APPEND);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
if (stristr($sourceFile, $_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.
|
||||
# Now do something with $sourceFile e.g. parse it for h-entry and h-card and store what you find.
|
||||
|
||||
// TODO: test if $datetime is to be found in $source
|
||||
// TODO: test if $datetime is to be found in $sourceFile
|
||||
// and then write the $twt to the $log
|
||||
|
||||
$datetime = explode( ":~:text=", $_POST['source'] );
|
||||
$pattern = '/^'.$datetime[1].'\t(.*?)$/m';
|
||||
preg_match($pattern, $source, $twt); // $twt[1] contains your line.
|
||||
preg_match($pattern, $sourceFile, $twt); // $twt[1] contains your line.
|
||||
|
||||
//preg_match('/^'.$datetime[1].'\t(.*?)$/m', $source, $twt);
|
||||
|
||||
$logfile = './mentions.txt'; /* Make sure file is writeable */
|
||||
//preg_match('/^'.$datetime[1].'\t(.*?)$/m', $sourceFile, $twt);
|
||||
|
||||
$log = date("Y-m-d\TH:i:s\Z") . "\t"
|
||||
//.'You were mentioned in: <a href="'.$_POST['source'].',%0A" rel=noopener>'.$_POST['source'].'</a>' // "%0A" means new line
|
||||
.'You were mentioned in: <a href="'.$_POST['source'].',%0A" rel=noopener>'.$_POST['source'].'</a>' // "%0A" means new line
|
||||
."
" // add a line break before blockquote
|
||||
."> " . $twt[1]
|
||||
|
|
|
|||
Loading…
Reference in a new issue