<?php

include __DIR__ . '/../../src/autoloader.php';
$configurator = new s9e\TextFormatter\Configurator();
$configurator->tags->add('A', ['attributes' => ['href' => ['filterChain' => ['#url'], 'required' => true]], 'template' => '<a href="{@href}"><xsl:apply-templates/></a>']);
$configurator->BBCodes->add('A', ['contentAttributes' => ['href'], 'defaultAttribute' => 'href']);
//==============================================================================
extract($configurator->finalize());
$text = "[a]http://example.org[/a]\n" . "[a=http://example.org]site[/a]";
$xml = $parser->parse($text);
$html = $renderer->render($xml);
echo $html, "\n";
// Outputs:
//
// <a href="http://example.org">http://example.org</a>
// <a href="http://example.org">site</a>
#!/usr/bin/php
<?php 
include __DIR__ . '/../src/autoloader.php';
$configurator = new s9e\TextFormatter\Configurator();
$configurator->plugins->load('MediaEmbed', ['captureURLs' => false]);
$configurator->registeredVars['cacheDir'] = __DIR__ . '/../tests/.cache';
$siteId = $_SERVER['argv'][1];
$configurator->MediaEmbed->add($siteId);
$dirpath = realpath(__DIR__ . '/../src/Plugins/MediaEmbed/Configurator/sites');
$siteFile = $dirpath . '/' . $siteId . '.xml';
$parser = $configurator->getParser();
$renderer = $configurator->getRenderer();
$html = '';
$site = simplexml_load_file($siteFile);
foreach ($site->example as $example) {
    $text = '[media=' . $siteId . ']' . $example . '[/media]';
    $xml = $parser->parse($text);
    $html .= $renderer->render($xml) . "\n";
}
$out = '<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>MediaEmbed test page</title>
	<base href="http://localhost"/>
</head>
<body>' . $html . '</body></html>';
file_put_contents('/tmp/MediaEmbed.html', $out);
die("Done.\n");
#!/usr/bin/php
<?php 
include __DIR__ . '/../src/autoloader.php';
$configurator = new s9e\TextFormatter\Configurator();
$configurator->enableJavaScript();
$configurator->rootRules->enableAutoLineBreaks();
$configurator->BBCodes->addFromRepository('*');
$configurator->BBCodes->addFromRepository('B');
$configurator->BBCodes->addFromRepository('C');
$configurator->BBCodes->addFromRepository('CODE');
$configurator->BBCodes->addFromRepository('COLOR');
$configurator->BBCodes->addFromRepository('FLOAT');
$configurator->BBCodes->addFromRepository('HR');
$configurator->BBCodes->addFromRepository('I');
$configurator->BBCodes->addFromRepository('LIST');
$configurator->BBCodes->addFromRepository('QUOTE');
$configurator->BBCodes->addFromRepository('S');
$configurator->BBCodes->addFromRepository('U');
$configurator->BBCodes->addFromRepository('URL');
$configurator->Censor->add('apple', 'banana');
$configurator->Emoticons->add(':)', '<img src="s.png" alt=":)"/>');
$configurator->Preg->replace('/#(?<tag>[a-z0-9]+)/i', '<a href="https://twitter.com/#!/search/%23{@tag}"><xsl:apply-templates/></a>');
$configurator->HTMLElements->allowElement('a');
$configurator->HTMLElements->allowElement('b');
$configurator->HTMLElements->allowAttribute('a', 'href');
$configurator->HTMLElements->allowAttribute('a', 'title');
$configurator->Autolink;
$configurator->HTMLEntities;
$configurator->FancyPants;
$configurator->MediaEmbed->createIndividualBBCodes = true;
$configurator->MediaEmbed->add('youtube');
    $addonTitle = 's9e Media Pack';
    $addonUrl = 'https://xenforo.com/community/resources/s9e-media-bbcodes-pack.2476/';
    $linkText = 'Media embeds by s9e';
    $tagsDescUrl = 'http://s9e.github.io/XenForoMediaBBCodes/tags.html';
    $githubUrl = 'https://github.com/s9e/XenForoMediaBBCodes/blob/master/docs/';
}
// The version is simply the current UTC day, optionally followed by the first argument given to
// this script
$version = gmdate('Ymd');
$versionId = $version * 10;
if (isset($_SERVER['argv'][1])) {
    $version .= $_SERVER['argv'][1];
    $versionId += $_SERVER['argv'][1] === '-dev' ? -1 : ord($_SERVER['argv'][1]) - 97;
}
// Set up the MediaEmbed plugin
$configurator = new s9e\TextFormatter\Configurator();
$configurator->rendering->engine = 'PHP';
$configurator->rendering->engine->forceEmptyElements = false;
$configurator->rendering->engine->useEmptyElements = false;
$configurator->rendering->engine->serializer->branchTableThreshold = PHP_INT_MAX;
$configurator->MediaEmbed->sitesDir = $sitesDir;
// Load the PHP file and remove the renderers
$php = file_get_contents($classFile);
$php = preg_replace('((.*?)(?:\\s*public static function render.*)?\\}$)s', '$1', $php);
// Redefine the constants here
preg_match_all('(^\\s*const\\s+.*)m', $php, $m);
eval(implode('', $m[0]));
function setAttributes(DOMElement $element, array $attributes)
{
    foreach ($attributes as $attrName => $attrValue) {
        $element->setAttribute($attrName, $attrValue);
#!/usr/bin/php
<?php 
include __DIR__ . '/../../src/autoloader.php';
$configurator = new s9e\TextFormatter\Configurator();
$tag = $configurator->tags->add('X');
$tag->attributes->add('x')->filterChain->append('#url');
$tag->template = '<a href="{@url}"><xsl:apply-templates/></a>';
$configurator->rendering->engine = 'PHP';
$configurator->finalize();
$scores = $relations = array();
foreach (get_declared_classes() as $className) {
    if (strpos($className, 's9e\\TextFormatter\\Configurator\\') !== 0) {
        continue;
    }
    $scores[$className] = 0;
    $relations[$className] = array();
    $class = new ReflectionClass($className);
    foreach ($class->getInterfaceNames() as $interfaceName) {
        if (strpos($interfaceName, 's9e\\TextFormatter\\Configurator\\') !== 0) {
            continue;
        }
        $scores[$interfaceName] = 0;
        $relations[$className][] = $interfaceName;
    }
    if (method_exists($class, 'getTraitNames')) {
        foreach ($class->getTraitNames() as $traitName) {
            if (strpos($traitName, 's9e\\TextFormatter\\Configurator\\') !== 0) {
                continue;
            }
            $scores[$traitName] = 0;
            $relations[$className][] = $traitName;