public function testAllowBadwords() { $usertext = new CM_Usertext_Usertext(new CM_Frontend_Render()); $usertext->setMode('escape', null, null, null, true); $badwordList = new CM_Paging_ContentList_Badwords(); $badWord = 'testBad'; $badwordList->add($badWord); $sentString = 'Hello i am ' . $badWord . ' !'; $this->assertSame($sentString, $usertext->transform($sentString)); }
public function testAddFilterAfterNoFilterFound() { $usertext = new CM_Usertext_Usertext(); $exception = $this->catchException(function () use($usertext) { $usertext->addFilterAfter('Filter Not Set', new CM_Usertext_Filter_Emoticon()); }); $this->assertInstanceOf('CM_Exception_Invalid', $exception); /** @var CM_Exception_Invalid $exception */ $this->assertSame('Filter not found', $exception->getMessage()); $this->assertSame(['filter' => 'Filter Not Set'], $exception->getMetaInfo()); }
/** * Supported modes: * ===================================================== * escape = escape, remove badwords * oneline = escape, remove badwords, add emoticons * simple = escape, remove badwords, nl2br, add emoticons * markdown = escape, remove badwords, create html markdown, add emoticons * markdownPlain = escape, remove badwords, create html markdown, strip all tags, add emoticons */ function smarty_function_usertext($params, Smarty_Internal_Template $template) { /** @var CM_Frontend_Render $render */ $render = $template->smarty->getTemplateVars('render'); $options = $params; $text = (string) $params['text']; unset($options['text']); $mode = (string) $params['mode']; unset($options['mode']); if (isset($params['isMail'])) { if ($params['isMail']) { $options['emoticonFixedHeight'] = 16; } unset($options['isMail']); } $usertext = CM_Usertext_Usertext::factory(); $usertext->setMode($mode, $options); $text = $usertext->transform($text, $render); switch ($mode) { case 'escape': return $text; break; case 'markdown': return '<div class="usertext ' . $mode . '">' . $text . '</div>'; break; default: return '<span class="usertext ' . $mode . '">' . $text . '</span>'; } }
/** * Supported modes: * ===================================================== * escape = escape, remove badwords * oneline = escape, remove badwords, add emoticons * simple = escape, remove badwords, nl2br, add emoticons * markdown = escape, remove badwords, create html markdown, add emoticons * markdownPlain = escape, remove badwords, create html markdown, strip all tags, add emoticons */ function smarty_function_usertext($params, Smarty_Internal_Template $template) { /** @var CM_Frontend_Render $render */ $render = $template->smarty->getTemplateVars('render'); $text = (string) $params['text']; $mode = (string) $params['mode']; $maxLength = isset($params['maxLength']) ? (int) $params['maxLength'] : null; $isMail = isset($params['isMail']) ? (bool) $params['isMail'] : null; $skipAnchors = isset($params['skipAnchors']) ? (bool) $params['skipAnchors'] : null; $allowBadwords = isset($params['allowBadwords']) ? (bool) $params['allowBadwords'] : null; $usertext = CM_Usertext_Usertext::factory($render); $usertext->setMode($mode, $maxLength, $isMail, $skipAnchors, $allowBadwords); $text = $usertext->transform($text); switch ($mode) { case 'escape': return $text; break; case 'markdown': return '<div class="usertext ' . $mode . '">' . $text . '</div>'; break; default: return '<span class="usertext ' . $mode . '">' . $text . '</span>'; } }