Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshyPHP committed Sep 18, 2018
1 parent 144933f commit 33d9371
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 11 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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
2 changes: 1 addition & 1 deletion s9e/zetabbcodes/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
3 changes: 3 additions & 0 deletions s9e/zetabbcodes/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
services:
s9e.zetabbcodes.listener:
class: s9e\zetabbcodes\listener
arguments:
- '@auth'
- '@user'
tags:
- { name: event.listener }
104 changes: 98 additions & 6 deletions s9e/zetabbcodes/listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '/^(?<width>\\d+),(?<height>\\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',
'/^(?<author>.+),\\(time=(?<time>\\d+)\\)$/'
);
}

protected function onConfigureTr(TagConfig $tag)
{
$tag->filterChain->append(__CLASS__ . '::processRow')
->resetParameters()
->addParameterByName('tag')
->addParameterByName('parser')
->addParameterByName('openTags');
}

public function onRendererSetup($event)
{
$event['renderer']->get_renderer()->setParameters([
'USERNAME' => $this->user->data['username'],
'S_IS_STAFF' => $this->auth->acl_gets('a_', 'm_')
]);
}

public static function processCell(Tag $tag, Parser $parser, array $openTags)
{
$i = count($openTags);
Expand Down Expand Up @@ -98,6 +161,16 @@ public static function processCell(Tag $tag, Parser $parser, array $openTags)
return false;
}

public static function processCode(Tag $tag, $text)
{
if (strtolower(substr($text, $tag->getPos(), $tag->getLen())) === '[html]')
{
$tag->setAttribute('lang', 'html');
}

return true;
}

public static function processRow(Tag $tag, Parser $parser, array $openTags)
{
self::$colPos = -1;
Expand All @@ -117,4 +190,23 @@ public static function processRow(Tag $tag, Parser $parser, array $openTags)

return true;
}

protected function addImgDimension(TagConfig $img, $attrName)
{
$attribute = $img->attributes->add($attrName);
$attribute->filterChain->append('#uint');
$attribute->required = false;
if (strpos($img->template, '<xsl:copy-of select="@' . $attrName . '"/>') !== false)
{
return;
}

$dom = $img->template->asDOM();
foreach ($dom->getElementsByTagName('img') as $node)
{
$node->appendChild($dom->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:copy-of'))
->setAttribute('select', '@' . $attrName);
}
$dom->saveChanges();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
namespace s9e\zetabbcodes\migrations;

class v000200 extends \phpbb\db\migration\migration
class bbcodes extends \phpbb\db\migration\migration
{
protected $bbcodes = [
[
Expand Down Expand Up @@ -73,8 +73,23 @@ class v000200 extends \phpbb\db\migration\migration
'<span style="background-color:{COLOR}">{TEXT}</span>'
],
[
'[border={COLOR},{UINT},{ALNUM} color={COLOR} width={UINT} style={ALNUM}]{TEXT}[/border]',
'<span style="border:{@style} {@width}px {@color}">{TEXT}</span>'
'[me]',
'<xsl:value-of select="$USERNAME"/>'
],
[
'[member]{TEXT}[/member]',
'<xsl:choose>
<xsl:when test="$S_USER_LOGGED_IN">{TEXT}</xsl:if>
<xsl:otherwise>[Hidden Content: Login/Register to View]</xsl:otherwise>
</xsl:choose>'
],
[
'[staff]{TEXT}[/staff]',
'<xsl:if test="$S_IS_STAFF">{TEXT}</xsl:if>'
],
[
'[border={PARSE=/^(?<color>#?\\w+)(?:,(?<width>\\d+)(?:,(?<style>\\w+))?)?/} color={COLOR} width={UINT;defaultValue=1} style={IDENTIFIER;defaultValue=solid}]{TEXT}[/border]',
'<span style="border:{@width}px {@style} {@color}">{TEXT}</span>'
],
[
'[center]{TEXT}[/center]',
Expand Down

0 comments on commit 33d9371

Please sign in to comment.