Exemplo n.º 1
0
 public static function run()
 {
     $manager = new ShortcodeManager();
     foreach (Plugins::get() as $plugin) {
         if ($plugin['isActive']) {
             if (file_exists($path = MODULES_PATH . trim($plugin['folder']) . '/Libraries')) {
                 if ($handle = opendir($path)) {
                     /* This is the correct way to loop over the directory. */
                     while (false !== ($entry = readdir($handle))) {
                         if (substr($entry, -13) == 'Shortcode.php') {
                             include $path . '/' . $entry;
                             $className = 'Modules\\' . trim($plugin['folder']) . '\\Libraries\\' . substr($entry, 0, -4);
                             $manager->register(new $className());
                         }
                     }
                     closedir($handle);
                 }
             }
         }
     }
     return $manager;
 }
Exemplo n.º 2
0
<?php

require '../bootstrap/autoload.php';
use Maiorano\Shortcodes\Manager\ShortcodeManager;
use Maiorano\Shortcodes\Library\SimpleShortcode;
/*
 * Managers may be instantiated with an array of Shortcodes pre-registered into its library
 */
$manager = new ShortcodeManager(['date' => new SimpleShortcode('date', null, function () {
    return date('l \\t\\h\\e jS \\o\\f F, Y');
})]);
/*
 * You can chain alias/register/deregister methods
 * This aliases the above [date] tag with [d]
 */
echo $manager->alias('date', 'd')->doShortcode('Today is [d]') . '<br><br>';
/*
 * You may choose which shortcodes you would like to render
 * */
echo $manager->doShortcode('Today is [date], not "[d]"', 'date') . '<br><br>';
/*
 * Shortcodes and their aliases can be registered at any time
 * */
echo $manager->register(new SimpleShortcode('mail', ['address' => ''], function ($content, $atts) {
    return sprintf('<a href="%s">%1$s</a>%s', $atts['address'] ? 'mailto:' . $atts['address'] : '#', $content);
}))->alias('mail', 'm')->doShortcode('[m address=test@test.com]Test[/m]') . '<br><br>';
/*
 * Nested shortcode can be processed by the Manager
 * You can also decide which tags are available for rendering
 * */
echo $manager->register(new SimpleShortcode('nest', null, function ($content) {
Exemplo n.º 3
0
 /**
  * @expectedException \Maiorano\Shortcodes\Exceptions\DeregisterException
  * @expectedExceptionMessage The shortcode 'test' does not exist in the current library
  */
 public function testDeregisterError()
 {
     $manager = new ShortcodeManager();
     $manager->deregister('test');
 }
Exemplo n.º 4
0
 public function testShorthand()
 {
     $manager = new ShortcodeManager();
     $test = new Library\SimpleShortcode('test', null, function () {
         return 'test';
     });
     $test->alias('t');
     $manager[] = $test;
     $this->assertEquals($test->doShortcode('[test/][t/]'), 'testtest');
     $this->assertEquals($manager->doShortcode('[test/][t/]'), 'testtest');
 }