PHP session_start docs: "..will magically contain the session data."
Seems legit.
PHP session_start docs: "..will magically contain the session data."
Seems legit.
+ https://gist.github.com/aaronpk/40d6bb333447ff4265a4
Amy added https://gist.github.com/aaronpk/40d6bb333447ff4265a4 to https://rhiaro.co.uk/bookmarks/
PHP
Aaaaas usual it's my code, not someone else's, that is causing my problems. Hashtag interop.
Finally you can get my blog post content in a number of different formats. You'll notice alternative URLs (noted currently as 'Permalink') in the metadata section of a normal view of a post. Hit this up with no Accept header, and you'll get neat markdown (which is what I authored it in; the 'source', as it were).
Browsers automatically send Accept: text/html, in which case they are redirected to the rendered HTML version of the post you're probably reading now. But here are some alternatives you can try:
curl https://rhiaro.co.uk/llog/micropub-test
-> plain markdown.
curl -H "Accept: application/json" https://rhiaro.co.uk/llog/micropub-test
because there's obviously not enough JSON in the world. Note this isn't correct JSON-LD yet. I'll sort that out another time.
curl -H "Accept: text/turtle" https://rhiaro.co.uk/llog/micropub-test
Ohemgee! RDF! It's what you've all been waiting for, I know.
For those of you who like angular brackets, you could try:
curl -H "Accept: rdf/xml" https://rhiaro.co.uk/llog/micropub-test
Briefly discussed with Tantek, Aaron and Bret at IWC Cambridge and on IRC about how a micropub client could fetch post content for editing. Many people aren't editing raw HTML as it's presented on the page, but maybe markdown or some other syntax, so a client needs to be able to discover this (the 'source') to present it to be edited. Now if someone makes their client check a post for a rel="source" or shoots off a request with Accept: text/plain (less likely, since static sites can't do conneg) then they'll get my markdown directly (uh, when I actually put rel="source" in my HTML, which I haven't yet).
As a related aside, I also return source="markdown" if a micropub client asks my endpoint q=source.
"Micropub is an open API standard that is used to create posts on one's own domain using third-party clients. Web apps and native apps (e.g. iPhone, Android) can use Micropub to post short notes, photos, events or other posts to your own site, similar to a Twitter client posting to Twitter.com." (Micropub on Indiewebcamp)
This means I can now publish blog posts to my site using other peoples' posting clients, of which there are several. Previously, I was ftping markdown files to my server, then running a slightly unreliable PHP script to process the queue based on when the files were last updated. Which mostly worked, but when it didn't it was a pain to untangle.
I wasn't expecting to have a micropub endpoint any time soon because it needs you to be able to sign into your site with IndieAuth. Fortunately, thanks to amazing work of aaronpk and others, most of the legwork has been done here, and you can delegate your IndieAuth; in your site <head>:
<link rel="authorization_endpoint" href="https://indieauth.com/auth" />
<link rel="token_endpoint" href="https://tokens.indieauth.com/token" />
Then create a micropub script (eg. micropub.php) and make it discoverable in the same way:
<link rel="micropub" href="https://rhiaro.co.uk/micropub.php" />
Initially I wanted my endpoint at https://rhiaro.co.uk/micropub and set an .htaccess rule to redirect to the PHP script. This doesn't work; POST requests can't follow redirects.
Next, here's a bare minimum PHP script to store things posted to your site with a micropub client. This just dumps the POST request to a text file, which is where I started to see if it would work. What I actually do now is turn posts and metadata into triples and insert them into my triplestore, but you probably don't want to hear about that :)
<?
// Tell client where I can syndicate to
if(isset($_GET['q']) && $_GET['q'] == "syndicate-to"){
header('Content-type: application/x-www-form-urlencoded');
echo "syndicate-to[]=twitter.com%2Frhiaro";
exit;
}
// Check for post
if(!empty($_POST)){
$headers = apache_request_headers();
// Check token is valid
$token = $headers['Authorization'];
$ch = curl_init("https://tokens.indieauth.com/token");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array(
"Content-Type: application/x-www-form-urlencoded"
,"Authorization: $token"
));
$response = Array();
parse_str(curl_exec($ch), $response);
curl_close($ch);
// Check for scope=post
// Check for me=https://rhiaro.co.uk
$me = $response['me'];
$iss = $response['issued_by'];
$client = $response['client_id'];
$scope = $response['scope'];
if(empty($response)){
header("HTTP/1.1 401 Unauthorized");
exit;
}elseif($me != "https://rhiaro.co.uk" || $scope != "post"){
header("HTTP/1.1 403 Forbidden");
exit;
// Check that something was posted
}elseif(empty($_POST['content']){
header("HTTP/1.1 400 Bad Request");
echo "Missing content";
}else{
// DO YOUR THING HERE
// ie. insert post content and metadata into your store, write it to a file, whatever you do to add it to your site.
// For demonstration purposes, let's dump the POST request into a file and return the URL of the file.
$fn = "posts/".time().".txt";
$h = fopen($fn, 'w');
foreach($_POST as $k => $v){
$data .= "[$k] => $v<br/>";
}
fwrite($h, $data);
fclose($h);
// Set headers, return location
header("HTTP/1.1 201 Created");
header("Location: ".$fn);
}
}
?>
I got this far by working through the instructions as part of setting up Quill, so that's a good place to start!
I think I'll use Chris Gutteridge's Graphite layer on top of ARC2. I've been putting off thinking about yet more libraries, but I think I'll end up implementing bits of Graphite in an effort to make ARC2 more friendly anyway, and I'm sure he's done a better job than I ever could.
Taught basic web design and development, including responsive design and progressive enhancement, to students from a variety of (mostly non-technical) backgrounds. Marked coursework.
Last modified:
Created a location-constrained community noticeboard as part of a hyperlocal digital newspaper (via a Wordpress plugin). The cool part is, you read and write to the noticeboard through scanning a QR code that's on a giant wooden totem pole in the middle of a field. I can't take responsibility for the totem pole.
Taught basic web design and development, including responsive design and progressive enhancement, to students from a variety of (mostly non-technical) backgrounds. Marked coursework.
I started on a 0 hour contract to deliver posters around campus. Then they found out I could use PhotoShop, so I started making posters too. Then they found out I could make websites, so I did that for minimum wage on a 0 hour contract for a couple of years, too. Mostly one-off sites for events and projects, sometimes in collaboration with other organisations. I also managed and over-engineered some Access databases, tried to make the best of what we had with an off-the-shelf CRM/CMS for the main SU website, and trained non-technical staff to use various administration systems.
Here, I learned to love flexible working hours and hate office politics, but never actually take advantage of either.
Learnt how to learn, graduated with a 1st, plus an Award for Outstanding Contribution to the School of Computer Science (I did waaaay too much extra-curricular activity).