stripslashes($_POST["title"]),
"url" => $url,
"image" => stripslashes($_POST["IMG"]),
"audio" => stripslashes($_POST["AUD"]),
"video" => stripslashes($_POST["VID"]),
"comment" => stripslashes($_POST["comment"]),
"poster" => $poster
);//XXX Note here that if editing, it changes poster to whoever last edited the post
if(empty($fh)) {//If none was passed in, we need to make one
$tdtime = new DateTime(null, new DateTimeZone($timezone));
$today = $tdtime->format('m.d.y');
$now = $tdtime->format('H:i:s');
$newsdir = $_SERVER["DOCUMENT_ROOT"].'/'.$basedir.$microblogdir;
@mkdir($newsdir.$today);
$fh = fopen($newsdir.$today."/".$now, 'w');
if (!$fh) die("ERROR: couldn't write $newsdir$today/$now to $newsdir$today, check permissions");
}
fwrite($fh,json_encode($postBody));
fclose($fh);
} else {//Print errors at the top, since we didn't have what we needed from POST
$message = 'Could not post due to errors:
';
foreach ($errors as $err) {$message .= "- $err
";}
$message .= '
POST Variable Dump below:
'.print_r($_POST, true).'';
echo $message;
}
}
//Microblog Posting engine - also used to display a form for submitting stories
if($_SERVER['REQUEST_METHOD'] == 'POST') {//Don't do anything unless we are POSTing
if(empty($_POST["id"])) {//See if we need to post something new
write_post();
} else {//OK, so we've established that the post has an ID. Let's see if we're editing/deleting a post.
if (!empty($_POST["action"]) && $_POST["action"] == 'Delete') {//BLANKING IN PROGRESS
$res = unlink($_POST["id"]);
if (!$res) {
header("HTTP/1.1 500 Internal Server Error");
die("ERROR: couldn't delete ".$_POST['id'].", check permissions");
}
echo "Deleted ".$_POST["id"]."
";
} else {//Attempt editing, first detecting whether content is json
$fh = fopen($_POST["id"], 'w');
if (!$fh) {
header("HTTP/1.1 500 Internal Server Error");
die("ERROR (500): couldn't open ".$_POST['id'].", check permissions");
}
if(empty($_POST["type"]) && !empty($_POST["content"])) {//Do some munging if it's just raw text
$content = stripslashes($_POST["content"]);
} else {//Process the JSON Post, write to file
write_post($fh);
}
fwrite($fh,$content);//Just write the blob ,TODO validation
fclose($fh);
echo "Edited ".$_POST["id"]."
";
}
}
}
//DOM below
?>