Skip to content

Instantly share code, notes, and snippets.

@hackervera
Last active November 22, 2016 10:20
Show Gist options
  • Save hackervera/41a76f9843fe46426e9ef44944511873 to your computer and use it in GitHub Desktop.
Save hackervera/41a76f9843fe46426e9ef44944511873 to your computer and use it in GitHub Desktop.
<?php
if ($_POST['content']){
$content = $_POST['content'];
$reply = $_POST['in-reply-to'];
$summary = implode(' ', array_slice(explode(' ', $content), 0, 10));
$alphanum = preg_replace("/[^A-Za-z0-9 ]/", '', $summary);
$words = split(" ", $alphanum);
$filename = join("-", $words);
$date = subStr(date("c"), 0, 19)."Z";
$title = $summary;
$bin = $reply ? "reply" : "post";
$response = $reply ? "<div>In response to <a class='u-in-reply-to' rel='in-reply-to' href='$reply'>" . $reply . "</a></div>" : "";
$body = <<<META
+++
date = "$date"
title = "$title"
+++
<div class='e-content'>$content</div>
$response
META;
$file = "/home/ubuntu/Dropbox/hugo/content/$bin/$filename.md";
file_put_contents($file, $body);
}
$post_url = "http://tyler.cat/$bin/$filename";
if ($reply) {
$curl = <<<CURL
curl $reply|grep rel=\"webmention\"|sed -re 's/.*href="(.*?)".*/\\1/'
CURL;
error_log($curl);
$webmention = trim(shell_exec($curl));
error_log(print_r($webmention, true));
//error_log($webmention);
$curl = <<<CURL
curl $webmention -dtarget="$reply" -dsource="$post_url"
CURL;
error_log($curl);
$post = shell_exec($curl);
error_log(print_r($post, true));
}
header("Location: $post_url");
http_response_code(201);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment