The Known framework has the ability to execute commands from the console, which is kind of cool and enables, among other things, stuff like these console development tools.

You can see what commands are currently available by going to the console, navigate to your Known directory, and execute ./known.php.

The commands available can be added to in two ways…

Create a pure console plugin

If you look in ConsolePlugins you’ll see a plugin called Example, which probably tells you all you need to know.. but in summary:

  • Create a subdirectory for your plugin in ConsolePlugins (or at least copy/symlink it there later)
  • Create a Main.php file, containing a class called Main which extends the class \Idno\Common\ConsolePlugin
  • Implement the abstract methods:
    • getCommand() the command name you are providing
    • getDescription() the description of the command
    • getParameters() a method returning an array of the command’s parameters
    • execute() your actual code

And you’re done!

Add a console plugin to a regular Known plugin

If you’re using the most recent build of Known from github, you can also add a console command to an existing traditional Known plugin (i.e. those sitting in IdnoPlugins/*). To do this, create a class called ConsoleMain that extends \Idno\Common\ConsolePlugin and save it in a file called ConsoleMain.php sitting along side your regular Main.php.

Known comes bundled with a Firefox plugin that, using Mozilla’s Social API, allows you to add a Known share/reply button to your browser.

This is pretty cool, but sadly only works for Firefox.

While other browsers, including Chrome, can use the bookmarklet to access the same functionality, this is rather clunky – for one thing, Chrome’s bookmark bar is hidden by default, for another Chrome has an extensive API and it’d be a shame not to use it!

A Chrome plugin for your site

So, I had a go at putting together a Chrome plugin… partly to scratch this itch, but also to learn how to write Chrome extensions (which turns out to be fabulously easy).

Install and activate the plugin, then go to your settings page to download a chrome extension which has been customised to your site.

Go to your Settings -> Extensions page, and then drag the archive into the list; all being well, you’ll have a new icon next to your address bar!

» Visit the project on Github...

There are now many plugins for Known, a lot of them I’ve written, are available on Github.

Many people, myself included, like to install these plugins via a git submodule checkout – this simplifies deployment and makes updating installed plugins easier, however it can be problematic.

The problem is that either the repository contains the actual plugin in a subdirectory (e.g. my Github plugin is in the repo ‘KnownGithub‘, and the plugin is in a subdirectory ‘Github’), or if they don’t, the actual clone of the repository will default to an incompatible name (e.g. Known’s Facebook plugin is in a repo ‘facebook’, but the code wants it in a directory ‘Facebook’).

Both have their own issues, but both mean you can’t directly use them in a submodule git checkout (unless you use my symlink trick). It would be nice if you could use these repos directly, so I put together a patch (which has been accepted) that allows you to build your plugin repos in such a way that they can be used directly from a git clone.

Introducing the autoloader

The patch I submitted introduces the ability to provide a loader for your plugin in the root directory of your plugin repository. So, if your plugin is Foo in a directory inside your repository KnownFoo, you could create a special autoloader.php file in the root that will allow Known to load your plugin in the normal way, direct from a git clone into your IdnoPlugins directory.

To do this, create a file autoloader.php with the following code:

This code will automatically load your plugin classes from its “real name” subdirectory, and make it available to your plugin loader.

Have a look at my Github plugin for an example, have fun!