aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/textformatter/s9e/acp_utils.php
diff options
context:
space:
mode:
authorMaat <maat-pub@mageia.biz>2020-05-09 01:15:08 +0200
committerMaat <maat-pub@mageia.biz>2020-05-09 01:15:08 +0200
commit6985226b17e8a0ef0a720bf1d12fe0c216e13dab (patch)
tree116d2565ac02c40abe0548863c6badf8ec3e1d1e /phpBB/phpbb/textformatter/s9e/acp_utils.php
parent8ea437e30605e0f66b5220bf904a61d7c1d11ddd (diff)
parent8d00784dfe2c8bcb10843ff70b4cfa998d703285 (diff)
downloadforums-master.tar
forums-master.tar.gz
forums-master.tar.bz2
forums-master.tar.xz
forums-master.zip
Merge remote-tracking branch 'upstream/prep-release-3.3.0'HEADmaster
Diffstat (limited to 'phpBB/phpbb/textformatter/s9e/acp_utils.php')
-rw-r--r--phpBB/phpbb/textformatter/s9e/acp_utils.php67
1 files changed, 67 insertions, 0 deletions
diff --git a/phpBB/phpbb/textformatter/s9e/acp_utils.php b/phpBB/phpbb/textformatter/s9e/acp_utils.php
new file mode 100644
index 0000000000..c4a668020e
--- /dev/null
+++ b/phpBB/phpbb/textformatter/s9e/acp_utils.php
@@ -0,0 +1,67 @@
+<?php
+/**
+*
+* This file is part of the phpBB Forum Software package.
+*
+* @copyright (c) phpBB Limited <https://www.phpbb.com>
+* @license GNU General Public License, version 2 (GPL-2.0)
+*
+* For full copyright and license information, please see
+* the docs/CREDITS.txt file.
+*
+*/
+
+namespace phpbb\textformatter\s9e;
+
+use phpbb\textformatter\acp_utils_interface;
+use s9e\TextFormatter\Configurator\Exceptions\UnsafeTemplateException;
+
+class acp_utils implements acp_utils_interface
+{
+ /**
+ * @var factory $factory
+ */
+ protected $factory;
+
+ /**
+ * @param factory $factory
+ */
+ public function __construct(factory $factory)
+ {
+ $this->factory = $factory;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function analyse_bbcode(string $definition, string $template): array
+ {
+ $configurator = $this->factory->get_configurator();
+ $return = ['status' => self::BBCODE_STATUS_SAFE];
+
+ // Capture and normalize the BBCode name manually because there's no easy way to retrieve
+ // it in TextFormatter <= 2.x
+ if (preg_match('(\\[([-\\w]++))', $definition, $m))
+ {
+ $return['name'] = strtoupper($m[1]);
+ }
+
+ try
+ {
+ $configurator->BBCodes->addCustom($definition, $template);
+ }
+ catch (UnsafeTemplateException $e)
+ {
+ $return['status'] = self::BBCODE_STATUS_UNSAFE;
+ $return['error_text'] = $e->getMessage();
+ $return['error_html'] = $e->highlightNode('<span class="highlight">');
+ }
+ catch (\Exception $e)
+ {
+ $return['status'] = (preg_match('(xml|xpath|xsl)i', $e->getMessage())) ? self::BBCODE_STATUS_INVALID_TEMPLATE : self::BBCODE_STATUS_INVALID_DEFINITION;
+ $return['error_text'] = $e->getMessage();
+ }
+
+ return $return;
+ }
+}