diff --git a/libs/timeline.css b/libs/timeline.css index eb9ce3f..99afc17 100644 --- a/libs/timeline.css +++ b/libs/timeline.css @@ -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; diff --git a/partials/webmentions_send.php b/partials/webmentions_send.php new file mode 100644 index 0000000..e09588f --- /dev/null +++ b/partials/webmentions_send.php @@ -0,0 +1,33 @@ +"; + + // 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 "
No endpoint found in: ".$mention["url"]."
"; + + } 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 "A webmention was send to: ".$targets_webmention_endpoint." (Status: $status)
"; + } +} \ No newline at end of file diff --git a/views/new_twt.php b/views/new_twt.php index 36dce65..a9562d2 100644 --- a/views/new_twt.php +++ b/views/new_twt.php @@ -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"]."No endpoint found in: ".$mention["url"]."
"; - - } 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 "A webmention was send to: ".$targets_webmention_endpoint." (Status: $status)
"; - } - } + // 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 diff --git a/views/webmention_endpoint.php b/views/webmention_endpoint.php index bf8dfce..b92ed1e 100644 --- a/views/webmention_endpoint.php +++ b/views/webmention_endpoint.php @@ -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: '.$_POST['source'].'' // "%0A" means new line .'You were mentioned in: '.$_POST['source'].'' // "%0A" means new line ." " // add a line break before blockquote ."> " . $twt[1]