Ejemplo n.º 1
0
 /**
  * @expectedException \Maiorano\Shortcodes\Exceptions\RegisterException
  * @expectedExceptionMessage The shortcode 'test' has already been registered
  */
 public function testRegisterError()
 {
     $manager = new ShortcodeManager();
     $test = new SimpleShortcode('test');
     $manager['test'] = $test;
     $manager->register($test);
 }
Ejemplo n.º 2
0
 public function testShortcodeAliasDeregister()
 {
     $manager = new ShortcodeManager();
     $test = new Library\SimpleShortcode('test', null, function () {
         return 'test';
     });
     $manager->register($test)->alias('test', 't');
     $manager->deregister('test', false);
     $this->assertTrue(isset($manager['t']));
     $this->assertFalse(isset($manager['test']));
     $this->assertEquals($manager->doShortcode('[t]'), 'test');
     $this->assertEquals($manager->doShortcode('[test]'), '[test]');
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
    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) {
    return $this->manager->doShortcode($content, 'mail');
}))->doShortcode('[nest]My email is [mail address=test@test.com], but "[date]" doesn\'t work[/nest]') . '<br><br>';
/*
 * You may also tell the original calling manager to override permissions
 * A third parameter of 'true' will attempt to use the calling manager's tag declarations
 * */
echo $manager->doShortcode('[nest]My email is [mail address=test@test.com], and the date is [d/][/mail][/nest]', 'nest|d', true) . '<br><br>';
/*
 * Let's get rid of 'm' and use it for something else