Just a quick one; first of all as a sign of life, I know I’ve been quiet of late, and second of all, to put out something that might be of use (albeit to a niche audience).

DOIs, or Digital Object Identifiers, are persistent identifiers for digital object for all sorts of things on the internet. Typically these are published documents, but they may also be things like datasets, workflows, images, etc.

I deal with these a fair amount at The Day Job, and often need to resolve these strings into something that returns metadata (title, author etc). Nice to be able to do this over an API.

Datacite, Crossref etc, who deal in DOIs, do provide their own resolution APIs, but only for items minted in their own namespaces, not the canonical set. DOI.org do provide a proxy, in order to resolve a doi to a location, but no obvious way of extracting metadata.

As it happens, there is a way of getting this data, with a little bit of Accept header witchcraft.

Anyway, to make it easier for you (and me), I wrote a library. Enjoy!

» Visit the project on Github...

So, another in a series of posts where I package up some code I often use into a reusable library, let me introduce a simple PHP library for creating virtual pages.

Virtual pages are pages on a website that are generated in code, and are sent to the client’s browser, but don’t correspond directly to a physical file. This process requires mod_rewrite on Apache, but similar functionality exists in other web servers.

Defining your endpoint

You must specify your endpoint, and then a handling function. This function can be anything callable; functions, methods or an enclosure.

\simple_page_handler\Page::create('my/page/', function($page, array $subpages) {
        // Your page handling code
});

Writing your endpoint handler

You then trigger the handled pages by writing a page handler, and then directing Apache to redirect unhandled requests to this endpoint.

Example endpoint:

try {
        if (!\simple_page_handler\Page::call(\simple_page_handler\Input::get('page'))) {
            \simple_page_handler\Page::set503();
            echo "Something went wrong.";
        }
} catch (Exception $e) {
    echo $e->getMessage();
}

And your redirect code:

# Redirect anything that isn't a real file to our example page handler
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)$ example_page_handler.php?page=$1 [QSA]

Hopefully this’ll be useful to someone!

» Visit the project on Github...

opengraphlogo So, I needed a simple open graph library for a project. There are other libraries, but I just needed something simple and quick, so I bashed this library together.

The library contains a class with a single static function, you pass it some page contents, and it’ll spit back a key => value array containing any open graph entries in the page.

This was handy for me, it might be for you 🙂

» Visit the project on Github…