format('U')); //$twt = $datetime . "\t$new_post\n"; //$twt = date('c') . "\t$new_post\n"; $datetime = date('Y-m-d\TH:i:sp'); // abracting to be used for webmentions $twt = "\n" . $datetime . "\t" .$new_post; // NB: only works with PHP 8 // TODO: Delete? /*if (strpos($contents, NEW_TWT_MARKER) !== false) { // Add the previous marker // Take note that doesn't not work if twtxt file has CRLF line ending // (which is wrong anyway) $twt = NEW_TWT_MARKER . $twt; $contents = str_replace(NEW_TWT_MARKER, $twt, $contents); } else { // Fall back if the marker is not found. $contents .= $twt; }*/ // Append twt at the end of file $contents .= $twt; // TODO: Add error handling if write to the file fails // For example due to permissions problems // https://www.w3docs.com/snippets/php/how-can-i-handle-the-warning-of-file-get-contents-function-in-php.html $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"]."
"; // 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)

"; } } //header('Refresh:0; url=.'); //header("Location: refresh?url=".$public_txt_url); // Trying to fix issue with douple posting //exit; } else { require_once("partials/base.php"); $title = "New post - ".$title; include_once 'partials/header.php'; if (!isset($textareaValue)) { $textareaValue = ''; } if (isset($_GET['hash'])) { $hash = $_GET['hash']; $textareaValue = "(#$hash) "; // COPY from conv.php // TODO: make into a partial or global function // Get the hashes (both post and replies) as $hash from the router and return an inverted list $twt_op = array_filter($twts, function($twt) use ($hash) { return $twt->hash === $hash; //|| $twt->replyToHash === $hash; }); //$twts = array_reverse($twts, true); //$textareaValue .= print_r($twts); //$textareaValue .= $twts["nick"]; include_once 'partials/timeline.php'; } ?>