Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
27 lines (20 sloc) 769 Bytes
<?php
namespace Grav\Plugin\Shortcodes;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
class RandomShortcode extends Shortcode
{
public function init()
{
$this->shortcode->getHandlers()->add('random', function(ShortcodeInterface $sc) {
$content = $sc->getContent();
if ($content) {
$delimeter = $sc->getParameter('delimeter', ',');
$enclosure = $sc->getParameter('enclosure', '"');
$escape = $sc->getParameter('escape', "\\");
$array = str_getcsv($content, $delimeter, $enclosure, $escape);
$content = $array[mt_rand(0, count($array)-1)];
}
return $content;
});
}
}
You can’t perform that action at this time.