diff options
author | JoshyPHP <s9e.dev@gmail.com> | 2015-05-02 01:08:32 +0200 |
---|---|---|
committer | JoshyPHP <s9e.dev@gmail.com> | 2015-05-30 17:26:00 +0200 |
commit | ea445ffa4776b7ce0b1d13485f113c7e1ec28af0 (patch) | |
tree | 625afbb7e59242706e96b4d4e0b7659a0b1fd8c6 /phpBB/phpbb/textreparser/base.php | |
parent | 459f1d4c1f26658c70d29ac7c4e3f3389a973a59 (diff) | |
download | forums-ea445ffa4776b7ce0b1d13485f113c7e1ec28af0.tar forums-ea445ffa4776b7ce0b1d13485f113c7e1ec28af0.tar.gz forums-ea445ffa4776b7ce0b1d13485f113c7e1ec28af0.tar.bz2 forums-ea445ffa4776b7ce0b1d13485f113c7e1ec28af0.tar.xz forums-ea445ffa4776b7ce0b1d13485f113c7e1ec28af0.zip |
[ticket/13803] Added methods to detect whether a given feature is in use
They test whether a given BBCode was enabled and has been used in a text,
or smilies, or magic URLs.
PHPBB3-13803
Diffstat (limited to 'phpBB/phpbb/textreparser/base.php')
-rw-r--r-- | phpBB/phpbb/textreparser/base.php | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/phpBB/phpbb/textreparser/base.php b/phpBB/phpbb/textreparser/base.php index f65745f6ab..f3f31ca320 100644 --- a/phpBB/phpbb/textreparser/base.php +++ b/phpBB/phpbb/textreparser/base.php @@ -30,6 +30,62 @@ abstract class base implements reparser_interface abstract protected function get_records($min_id, $max_id); /** + * Guess whether given BBCode is in use in given record + * + * @param array $record + * @param string $bbcode + * @return bool + */ + protected function guess_bbcode(array $record, $bbcode) + { + if (!empty($record['bbcode_uid'])) + { + // Look for the closing tag, e.g. [/url] + $match = '[/' . $bbcode . ':' . $record['bbcode_uid']; + if (stripos($record['text'], $match) !== false) + { + return true; + } + } + + if (substr($record['text'], 0, 2) == '<r') + { + // Look for the closing tag inside of a e element, in an element of the same name, e.g. + // <e>[/url]</e></URL> + $match = '<e>[/' . $bbcode . ']</e></' . $bbcode . '>'; + if (stripos($record['text'], $match) !== false) + { + return true; + } + } + + return false; + } + + /** + * Guess whether magic URLs are in use in given record + * + * @param array $record + * @return bool + */ + protected function guess_magic_url(array $record) + { + // Look for <!-- m --> or for a URL tag that's not immediately followed by <s> + return (strpos($record['text'], '<!-- m -->') !== false || preg_match('(<URL [^>]++>(?!<s>))', strpos($row['text']))); + } + + /** + * Guess whether smilies are in use in given record + * + * @param array $record + * @return bool + */ + protected function guess_smilies(array $record) + { + return (strpos($row['text'], '<!-- s') !== false || strpos($row['text'], '<E>') !== false); + } + + /** * {@inheritdoc} */ public function reparse_range($min_id, $max_id) |