Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
perf(BBCode): Use mjohnson/decoda to parse and cache BBCode
Browse files Browse the repository at this point in the history
In some case , parse bbcode text in the frontend is not good.
So , Use backend library to parse bbcode text..
  • Loading branch information
Rhilip committed May 30, 2019
1 parent b08c2ed commit fbc98ad
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 513 deletions.
490 changes: 0 additions & 490 deletions apps/public/static/js/bbcodeParser.js

This file was deleted.

16 changes: 0 additions & 16 deletions apps/public/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,6 @@ jQuery(document).ready(function() {
return new $.zui.Messager(text, option).show();
}

// Convert ubbcode blcok text to html
$(".ubbcode-block").html(function (index, oldhtml) {
/*
Because:
1. Cloudflare or other CDN may clean the newline characters like `\n`
2. our backend use nl2br() to Inserts HTML line breaks before all newlines in a string,
It's needed to to remove the exist `\n` (if case 1 not happened), and change the html tag `<br />` to `\n`,
then feed to our XBBCODE converter for safety output.
*/
oldhtml = oldhtml.trim()
.replace(/\n/ig, '')
.replace(/<br ?\/?>/ig, '\n');
return XBBCODE.process({text: oldhtml}).html;
});


// Torrent favour Add/Remove action
$('.torrent-favour').click(function () {
let that = $(this);
Expand Down
1 change: 0 additions & 1 deletion apps/views/layout/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
<script src="/lib/zui/dist/js/zui.min.js"></script>

<!-- Custom Javascript of this template -->
<script src="/static/js/bbcodeParser.js"></script>
<script src="/static/js/main.js?<?= $css_tag ?>"></script>

<!-- Other Page script field -->
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"robthree/twofactorauth": "^1.6",
"swiftmailer/swiftmailer": "^6.1",
"siriusphp/validation": "^2.2",
"phpmailer/phpmailer": "^6.0"
"phpmailer/phpmailer": "^6.0",
"mjohnson/decoda": "^6.12"
},
"autoload": {
"psr-4": {
Expand Down
62 changes: 61 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions framework/Redis/BaseRedisConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,4 +302,12 @@ public function getCalledData()
{
return $this->_calledData;
}

/**
* @return \Redis
*/
public function getRedis(): \Redis
{
return $this->_redis;
}
}
14 changes: 10 additions & 4 deletions framework/View/Conversion.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

namespace Rid\View;

use Decoda\Decoda;
use Decoda\Storage\RedisStorage;
use League\Plates\Engine;
use League\Plates\Extension\ExtensionInterface;

Expand Down Expand Up @@ -39,9 +41,13 @@ public function format_bytes($bytes, $precision = 2)

public function format_ubbcode($string)
{
$string = htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
$string = str_replace(array_keys(self::UBBCODE_MAP), array_values(self::UBBCODE_MAP), $string);
$string = nl2br($string);
return $string;
$code = new Decoda($string,[
'escapeHtml' => true
],'Post_cache:' . md5($string));

$code->defaults();

$code->setStorage(new RedisStorage(app()->redis->getRedis()));
return $code->parse();
}
}

0 comments on commit fbc98ad

Please sign in to comment.