Last active
November 22, 2016 10:20
-
-
Save hackervera/41a76f9843fe46426e9ef44944511873 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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