* @return string text
*/
public function parseSmilies($text) {
+ $smileyCount = 0;
foreach ($this->smilies as $code => $html) {
- //$text = preg_replace('~(?<!&\w{2}|&\w{3}|&\w{4}|&\w{5}|&\w{6}|&#\d{2}|&#\d{3}|&#\d{4}|&#\d{5})'.preg_quote(StringUtil::encodeHTML($code), '~').'(?![^<]*>)~', $html, $text);
- $text = preg_replace('~(?<=^|\s)'.preg_quote(StringUtil::encodeHTML($code), '~').'(?=$|\s|<br />|<br>)~', $html, $text);
+ $text = preg_replace_callback('~(?<=^|\s)'.preg_quote(StringUtil::encodeHTML($code), '~').'(?=$|\s|<br />|<br>)~', function() use ($code, $html, &$smileyCount) {
+ if ($smileyCount === 50) {
+ return $code;
+ }
+
+ $smileyCount++;
+ return $html;
+ }, $text);
}
return $text;
* @since 3.0
*/
class HtmlInputNodeImg extends AbstractHtmlInputNode {
+ /**
+ * number of found smilies
+ * @var integer
+ */
+ protected $smiliesFound = 0;
+
/**
* @inheritDoc
*/
* @inheritDoc
*/
public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) {
+ $this->smiliesFound = 0;
+
/** @var \DOMElement $element */
foreach ($elements as $element) {
$class = $element->getAttribute('class');
}
}
+ /**
+ * Returns the number of smilies found within the message.
+ *
+ * @return integer
+ */
+ public function getSmileyCount() {
+ return $this->smiliesFound;
+ }
+
/**
* Replaces image element with attachment metacode element.
*
/** @var Smiley $smiley */
$smiley = SmileyCache::getInstance()->getSmileyByCode($code);
- if ($smiley === null) {
+ if ($smiley === null || $this->smiliesFound === 50) {
$element->parentNode->insertBefore($element->ownerDocument->createTextNode($code), $element);
$element->parentNode->removeChild($element);
}
if ($smiley->smileyPath2x) $element->setAttribute('srcset', $smiley->getURL2x() . ' 2x');
else $element->removeAttribute('srcset');
+
+ $this->smiliesFound++;
}
}
}
$this->enforceQuoteDepth(MESSAGE_MAX_QUOTE_DEPTH);
}
- $this->invokeHtmlNode(new HtmlInputNodeImg());
+ $imgNodeHandler = new HtmlInputNodeImg();
+ $this->invokeHtmlNode($imgNodeHandler);
+ $smileyCount = $imgNodeHandler->getSmileyCount();
// dynamic node handlers
$this->invokeNodeHandlers('wcf\system\html\input\node\HtmlInputNode', ['img', 'woltlab-metacode']);
$this->trim();
// detect mentions, urls, emails and smileys
- $textParser = new HtmlInputNodeTextParser($this);
+ $textParser = new HtmlInputNodeTextParser($this, $smileyCount);
$textParser->parse();
// strip invalid class names
*/
protected $nodeStack = [];
+ /**
+ * number of found smilies
+ * @var integer
+ */
+ protected $smileyCount = 0;
+
/**
* list of smilies by smiley code
* @var Smiley[]
* HtmlInputNodeTextParser constructor.
*
* @param HtmlInputNodeProcessor $htmlInputNodeProcessor
+ * @param integer $smileyCount
*/
- public function __construct(HtmlInputNodeProcessor $htmlInputNodeProcessor) {
+ public function __construct(HtmlInputNodeProcessor $htmlInputNodeProcessor, $smileyCount = 0) {
$this->htmlInputNodeProcessor = $htmlInputNodeProcessor;
$this->sourceBBCodes = HtmlBBCodeParser::getInstance()->getSourceBBCodes();
if (MODULE_SMILEY) {
+ $this->smileyCount = $smileyCount;
+
// get smilies
$smilies = SmileyCache::getInstance()->getSmilies();
$categories = SmileyCache::getInstance()->getCategories();
$value = $this->parseEmail($node, $value);
}
- $value = $this->parseSmiley($node, $value);
+ if ($this->smileyCount !== 50) {
+ $value = $this->parseSmiley($node, $value);
+ }
if ($value !== $oldValue) {
$node->textContent = $value;
return preg_replace_callback($smileyPattern, function($matches) use ($text) {
$smileyCode = $matches[0];
+ if ($this->smileyCount === 50) {
+ return $smileyCode;
+ }
+ $this->smileyCount++;
$smiley = $this->smilies[$smileyCode];
$element = $text->ownerDocument->createElement('img');
$element->setAttribute('src', $smiley->getURL());