Last active
August 29, 2015 14:25
-
-
Save JoshyPHP/918d393796f7f66cc10f to your computer and use it in GitHub Desktop.
Flarum mentions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include '/s9e/TextFormatter/src/autoloader.php'; | |
$configurator = new s9e\TextFormatter\Configurator; | |
$tagName = 'MENTION'; | |
$tag = $configurator->tags->add($tagName); | |
$tag->attributes->add('username'); | |
$tag->attributes->add('id')->filterChain->append('#uint'); | |
$tag->filterChain->prepend('mentionator::addId')->addParameterByName('mentionator'); | |
$tag->template = '<a href="{$PROFILE_URL}{@id}"><xsl:value-of select="@username"/></a>'; | |
$configurator->Preg->match('/@(?<username>\\w+)/', $tagName); | |
class mentionator | |
{ | |
protected $cache = ['Bob' => 123]; | |
public static function addId($tag, self $mentionator) | |
{ | |
$tag->setAttribute('id', $mentionator->getId($tag->getAttribute('username'))); | |
return true; | |
} | |
protected function getId($username) | |
{ | |
return (isset($this->cache[$username])) ? $this->cache[$username] : false; | |
} | |
} | |
extract($configurator->finalize()); | |
$mentionator = new mentionator; | |
$parser->registeredVars['mentionator'] = $mentionator; | |
$renderer->setParameter('PROFILE_URL', 'http://example.org/profile/'); | |
$text = '@Bob @NotBob'; | |
$xml = $parser->parse($text); | |
$html = $renderer->render($xml); | |
echo $xml, "\n", $html, "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="http://example.org/profile/123">Bob</a> @NotBob |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<r><MENTION id="123" username="Bob">@Bob</MENTION> @NotBob</r> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment