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

Commit

Permalink
Revert "Revert "Make CM_Usertext_Usertext extensible regarding custom…
Browse files Browse the repository at this point in the history
… filters in..."
  • Loading branch information
alexispeter committed Mar 19, 2015
1 parent 23f2cdc commit 440417e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 129 deletions.
31 changes: 0 additions & 31 deletions library/CM/Usertext/Filter/Markdown/UserContent.php

This file was deleted.

81 changes: 45 additions & 36 deletions library/CM/Usertext/Usertext.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,51 @@ public function setMode($mode, $maxLength = null, $isMail = null, $skipAnchors =
if ($isMail) {
$emoticonFixedHeight = 16;
}
$this->_setMode($mode, $maxLength, $skipAnchors, $emoticonFixedHeight);
}

/**
* @param string $text
* @return string
*/
public function transform($text) {
$cacheKey = $this->_getCacheKey($text);
$cache = CM_Cache_Local::getInstance();
if (($result = $cache->get($cacheKey)) === false) {
$result = $text;
foreach ($this->_getFilters() as $filter) {
$result = $filter->transform($result, $this->_render);
}
$cache->set($cacheKey, $result);
}
return $result;
}

/**
* @param string $text
* @return string
*/
protected function _getCacheKey($text) {
$cacheKey = CM_CacheConst::Usertext . '_text:' . md5($text);
$filterList = $this->_getFilters();
if (0 !== count($filterList)) {
$cacheKeyListFilter = array_map(function (CM_Usertext_Filter_Interface $filter) {
return $filter->getCacheKey();
}, $filterList);
$cache = CM_Cache_Local::getInstance();
$cacheKey .= '_filter:' . $cache->key($cacheKeyListFilter);
}
return $cacheKey;
}

/**
* @param string $mode
* @param int|null $maxLength
* @param boolean|null $skipAnchors
* @param int|null $emoticonFixedHeight
* @throws CM_Exception_Invalid
*/
protected function _setMode($mode, $maxLength = null, $skipAnchors = null, $emoticonFixedHeight = null) {
$this->addFilter(new CM_Usertext_Filter_Badwords());
if ('escape' != $mode) {
$this->addFilter(new CM_Usertext_Filter_Emoticon_ReplaceAdditional());
Expand All @@ -61,15 +106,13 @@ public function setMode($mode, $maxLength = null, $isMail = null, $skipAnchors =
if (null !== $maxLength) {
throw new CM_Exception_Invalid('MaxLength is not allowed in mode markdown.');
}
$this->addFilter(new CM_Usertext_Filter_Markdown_UserContent());
$this->addFilter(new CM_Usertext_Filter_Emoticon_EscapeMarkdown());
$this->addFilter(new CM_Usertext_Filter_Markdown_UnescapeBlockquote());
$this->addFilter(new CM_Usertext_Filter_Markdown($skipAnchors));
$this->addFilter(new CM_Usertext_Filter_Emoticon_UnescapeMarkdown());
$this->addFilter(new CM_Usertext_Filter_Emoticon($emoticonFixedHeight));
break;
case 'markdownPlain':
$this->addFilter(new CM_Usertext_Filter_Markdown_UserContent());
$this->addFilter(new CM_Usertext_Filter_Emoticon_EscapeMarkdown());
$this->addFilter(new CM_Usertext_Filter_Markdown($skipAnchors));
$this->addFilter(new CM_Usertext_Filter_Emoticon_UnescapeMarkdown());
Expand All @@ -84,40 +127,6 @@ public function setMode($mode, $maxLength = null, $isMail = null, $skipAnchors =
}
}

/**
* @param string $text
* @return string
*/
public function transform($text) {
$cacheKey = $this->_getCacheKey($text);
$cache = CM_Cache_Local::getInstance();
if (($result = $cache->get($cacheKey)) === false) {
$result = $text;
foreach ($this->_getFilters() as $filter) {
$result = $filter->transform($result, $this->_render);
}
$cache->set($cacheKey, $result);
}
return $result;
}

/**
* @param string $text
* @return string
*/
protected function _getCacheKey($text) {
$cacheKey = CM_CacheConst::Usertext . '_text:' . md5($text);
$filterList = $this->_getFilters();
if (0 !== count($filterList)) {
$cacheKeyListFilter = array_map(function (CM_Usertext_Filter_Interface $filter) {
return $filter->getCacheKey();
}, $filterList);
$cache = CM_Cache_Local::getInstance();
$cacheKey .= '_filter:' . $cache->key($cacheKeyListFilter);
}
return $cacheKey;
}

private function _clearFilters() {
$this->_filterList = array();
}
Expand Down
62 changes: 0 additions & 62 deletions tests/library/CM/Usertext/Filter/Markdown/UserContentTest.php

This file was deleted.

0 comments on commit 440417e

Please sign in to comment.