diff --git a/README.md b/README.md index b23b2a4..7fd5f1f 100644 --- a/README.md +++ b/README.md @@ -3,4 +3,30 @@ 1. Download the [latest release](https://github.com/s9e/phpbb-ext-zeta-bbcodes/releases/latest). 2. Unpack the archive on your computer. 3. Upload the `s9e` directory to the `ext` directory of your phpBB instllation. -4. Go to your forum's admin panel and enable the extension. \ No newline at end of file +4. Go to your forum's admin panel and enable the extension. + +## Supported BBCodes + + - bgcolor: `[bgcolor=red]` + - big, small + - border: + - `[border=red]` + - `[border=red,1]` + - `[border=red,1,solid]` + - center + - font: `[font=Arial]` + - hr + - html + - me + - member + - nocode + - right + - s, sub, sup + - spoiler + - staff + - table: + - `[table]` + - `[table=2]` (2 columns) + - `[table=2,Title]` + - `[table=2,Title,1]` + - tr, th, td and c diff --git a/s9e/zetabbcodes/composer.json b/s9e/zetabbcodes/composer.json index 001f218..fd770a8 100644 --- a/s9e/zetabbcodes/composer.json +++ b/s9e/zetabbcodes/composer.json @@ -3,7 +3,7 @@ "type": "phpbb-extension", "description": "Compatibility layer for BBCodes used in posts imported from Zeta Boards.", "homepage": "https://github.com/s9e/phpbb-ext-zeta-bbcodes/", - "version": "0.2.0", + "version": "1.0.0", "keywords": ["phpbb"], "license": "MIT", "require": { diff --git a/s9e/zetabbcodes/config/services.yml b/s9e/zetabbcodes/config/services.yml index 83e2328..c696bf8 100644 --- a/s9e/zetabbcodes/config/services.yml +++ b/s9e/zetabbcodes/config/services.yml @@ -1,5 +1,8 @@ services: s9e.zetabbcodes.listener: class: s9e\zetabbcodes\listener + arguments: + - '@auth' + - '@user' tags: - { name: event.listener } \ No newline at end of file diff --git a/s9e/zetabbcodes/listener.php b/s9e/zetabbcodes/listener.php index 401302c..97810ed 100644 --- a/s9e/zetabbcodes/listener.php +++ b/s9e/zetabbcodes/listener.php @@ -8,39 +8,102 @@ namespace s9e\zetabbcodes; use Symfony\Component\EventDispatcher\EventSubscriberInterface; +use phpbb\auth\auth; +use phpbb\user; +use s9e\TextFormatter\Configurator\Items\Tag as TagConfig; use s9e\TextFormatter\Parser; use s9e\TextFormatter\Parser\Tag; class listener implements EventSubscriberInterface { + protected $auth; protected static $colPos = -1; + protected $user; + + public function __construct(auth $auth, user $user) + { + $this->auth = $auth; + $this->user = $user; + } public static function getSubscribedEvents() { - return ['core.text_formatter_s9e_configure_after' => 'onConfigure']; + return [ + 'core.text_formatter_s9e_configure_after' => 'onConfigure', + 'core.text_formatter_s9e_renderer_setup' => 'onRendererSetup' + ]; } public function onConfigure($event) { $configurator = $event['configurator']; - $configurator->tags['C']->filterChain->add(__CLASS__ . '::processCell') + foreach ($configurator->tags as $tagName => $tag) + { + $methodName = 'onConfigure' . ucfirst(strtolower($tagName)); + if (method_exists($this, $methodName)) + { + $this->$methodName($tag); + } + } + + // Make [html] an alias for [code=html] + if (isset($configurator->tags['CODE'])) + { + $configurator->BBCodes->add('HTML')->tagName = 'CODE'; + } + } + + protected function onConfigureC(TagConfig $tag) + { + $tag->filterChain->append(__CLASS__ . '::processCell') ->resetParameters() ->addParameterByName('tag') ->addParameterByName('parser') ->addParameterByName('openTags'); - $configurator->tags['TR']->filterChain->add(__CLASS__ . '::processRow') + } + + protected function onConfigureCode(TagConfig $tag) + { + $tag->filterChain->prepend(__CLASS__ . '::processCode') ->resetParameters() ->addParameterByName('tag') - ->addParameterByName('parser') - ->addParameterByName('openTags'); + ->addParameterByName('text'); + } + + protected function onConfigureImg(TagConfig $tag) + { + // Add support for [img=width,height] + $tag->attributePreprocessors->add('img', '/^(?\\d+),(?\\d+)$/'); + $this->addImgDimension($tag, 'height'); + $this->addImgDimension($tag, 'width'); + } + protected function onConfigureQuote(TagConfig $tag) + { // Interpret [quote=foo,(time=123)] as [quote author=foo time=123] - $configurator->tags['quote']->attributePreprocessors->add( + $tag->attributePreprocessors->add( 'author', '/^(?.+),\\(time=(?