Plugins
While the core of Kirby should stay as clean and simple as possible there's a lot of room for plugins. I will release some of which I've already built within the next weeks. Please feel free to build your own and add them on Github
Remote
Remote is the a Plugin, which makes it easy to handle remote get and post requests.
<?php
require_once('kirby.php');
require_once('plugins/remote.php');
$data = remote::get('http://api.twitter.com/1/statuses/show/bastianallgeier.json', 'json');
a::show($data);
?>
This is all you've got to do to get the latest Tweets from the Twitter API, for example. Remote can automatically parse the response (here it will parse the json) and return a nice and pretty PHP array. There's a lot more remote can do for you, so stay tuned for more docs or dive into the code.
Template
This is probably the tiniest template engine ever. It is very easy to use and yet powerfull enough for bigger projects.
<?php
require_once('kirby.php');
require_once('plugins/template.php');
// fill the template
tpl::set('title', 'Some random Site title');
tpl::set('body', 'Great site, bla, bla, bla');
// load the default template
tpl::load('blog');
?>
Just add a template folder to the same directory where your kirby core file stays and add your template files there. All template files are normal php files:
<!-- this is your templates/blog.php template file -->
<html>
<head>
<title><?php echo $title ?></title>
</head>
<body>
<?php echo $body ?>
</body>
</html>
You can even use tpl::load() inside template files to add common code snippets:
<!-- this is your templates/blog.php template file -->
<html>
<head>
<title><?php echo $title ?></title>
</head>
<body>
<?php echo tpl::load('menu') ?>
<?php echo $body ?>
</body>
</html>
Timer
Include the timer to do some raw benchmarking of your code.
<?php
require_once('kirby.php');
require_once('plugins/timer.php');
// some code
echo timer::get();
// sample output: 0.123412
// start a new timer
timer::set('another_timer');
// some more code
echo timer::get('another_timer');
// sample output : 1.21231
?>
You can start as many timers as you like and get them back later. A global timer is started when you include the plugin, which will be returned when you don't specify a key i.e: echo timer::get();
Upload
Handling file uploads is always a pain in the ass. This plugin tries to make it as joyful as possible. All you need to do is to set the name of the file field and the destination, where the file should be stored.
<?php
require_once('kirby.php');
require_once('plugins/upload.php');
if(get('submit')) {
upload::file('file-upload', 'files/upload.jpg');
}
?>
<form action="" enctype="multipart/form-data" method="post">
<input type="file" name="file-upload" />
<input type="submit" name="submit" />
</form>
There are a lot of ways to customize the upload. Please stay tuned for the documentation.
Pager
The pager plugin helps to page through a larger number of entries. Just enter the number of entries, the current page and the limit of entries, which will be shown and all the calculation is done for you. Additionally the pager sanitizes user input, so if you enter a invalid page number the nearest possible page will be returned instead.
<?php
require_once('kirby.php');
require_once('plugins/pager.php');
$entries = 100;
$page = 2;
$limit = 20;
pager::set($entries, $page, $limit);
echo pager::get();
// output: 2
echo pager::next();
// output: 3
echo pager::previous();
// output: 1
echo pager::last();
// output: 5
echo pager::first();
// output: 1
echo pager::db();
// output: 20 (returns a valid page number for SQL queries)
?>
Crypt
Arno has built a great crypt plugin, which helps to encode and decode strings. This requires mcrypt.
<?php
require_once('kirby.php');
require_once('plugins/crypt.php');
$key = '12345';
$secret_text = 'supersecretpassword';
$encrypted_text = crypt::encode($secret_text, $key);
// later
echo crypt::decode($encrypted_text, $key);
// output: 'supersecretpassword'
?>