diff --git a/app/controllers/course/forum/index.php b/app/controllers/course/forum/index.php index f62a6c15cefcf0578cf0afb2ea383cc01717f4cf..02e2e9a233d474d4412c0fdbab4d4605e529de5c 100644 --- a/app/controllers/course/forum/index.php +++ b/app/controllers/course/forum/index.php @@ -341,14 +341,9 @@ class Course_Forum_IndexController extends ForumController */ function preview_action() { if (Request::isXhr()) { - $this->set_content_type('text/html; charset=UTF-8'); - $this->render_text(formatReady(transformBeforeSave(Request::get('posting')))); + $this->render_text(formatReady(Request::get('posting'))); } else { - $this->render_text( - ForumEntry::getContentAsHtml( - transformBeforeSave(Request::get('posting')) - ) - ); + $this->render_text(ForumEntry::getContentAsHtml(Request::get('posting'))); } } diff --git a/lib/classes/ForumEntry.php b/lib/classes/ForumEntry.php index f18fbb2141c42b0e19528d928ec6fe2e54d5061d..ec1185f748a1f1b1dbbd72b270e4e7aa4f7a4391 100644 --- a/lib/classes/ForumEntry.php +++ b/lib/classes/ForumEntry.php @@ -948,7 +948,7 @@ class ForumEntry implements PrivacyObject chdate, author, author_host, lft, rgt, depth, anonymous) VALUES (? ,?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), UNIX_TIMESTAMP(), ?, ?, ?, ?, ?, ?)"); $stmt->execute([$data['topic_id'], $data['seminar_id'], $data['user_id'], - $data['name'], transformBeforeSave($data['content']), $data['author'], $data['author_host'], + $data['name'], $data['content'], $data['author'], $data['author_host'], $constraint['rgt'], $constraint['rgt'] + 1, $constraint['depth'] + 1, $data['anonymous'] ?? 0]); // update "latest_chdate" for easier sorting of actual threads @@ -979,7 +979,7 @@ class ForumEntry implements PrivacyObject $stmt = DBManager::get()->prepare("UPDATE forum_entries SET name = ?, content = ?, chdate = UNIX_TIMESTAMP(), latest_chdate = UNIX_TIMESTAMP() WHERE topic_id = ?"); - $stmt->execute([$name, transformBeforeSave($content), $topic_id]); + $stmt->execute([$name, $content, $topic_id]); // update "latest_chdate" for easier sorting of actual threads $parent_id = ForumEntry::getParentTopicId($topic_id); diff --git a/lib/classes/JsonApi/Routes/Forum/AbstractEntriesCreate.php b/lib/classes/JsonApi/Routes/Forum/AbstractEntriesCreate.php index a4905b632a6e10380545ea305f7fe3fdb13371d6..204414b711e463d8e1dd79d590bcc72a8918b966 100644 --- a/lib/classes/JsonApi/Routes/Forum/AbstractEntriesCreate.php +++ b/lib/classes/JsonApi/Routes/Forum/AbstractEntriesCreate.php @@ -24,9 +24,7 @@ abstract class AbstractEntriesCreate extends JsonApiController //Check whether the parent is category or entry of first or seccond depth $title = self::arrayGet($json, 'data.attributes.title'); $content = self::arrayGet($json, 'data.attributes.content'); - if (method_exists(\Studip\Markup::class, 'purifyHtml')) { - $content = transformBeforeSave(\Studip\Markup::purifyHtml($content)); - } + $content = \Studip\Markup::purifyHtml($content); $parent = $this->getParentObject($parentId); return $this->createEntry($title, $content, $parent, $user); diff --git a/lib/classes/JsonApi/Routes/Forum/ForumEntriesUpdate.php b/lib/classes/JsonApi/Routes/Forum/ForumEntriesUpdate.php index 4ef1ee10d2a2769d27c35841439807dd4a1153a0..1165ff2d84636b1557d68550267e86d15e5f99f1 100644 --- a/lib/classes/JsonApi/Routes/Forum/ForumEntriesUpdate.php +++ b/lib/classes/JsonApi/Routes/Forum/ForumEntriesUpdate.php @@ -50,9 +50,7 @@ class ForumEntriesUpdate extends JsonApiController $entry->name = $title; } if (!empty($content)) { - if (method_exists(\Studip\Markup::class, 'purifyHtml')) { - $content = transformBeforeSave(\Studip\Markup::purifyHtml($content)); - } + $content = \Studip\Markup::purifyHtml($content); $entry->content = $content; } if ($entry->isDirty()) { diff --git a/lib/classes/JsonApi/Routes/Wiki/WikiCreate.php b/lib/classes/JsonApi/Routes/Wiki/WikiCreate.php index 79a8a558fd096e6102372a3dc0ef11d9702b6e53..ffd4efcefac445e40a01f9e75b9d79824ea5cfb2 100644 --- a/lib/classes/JsonApi/Routes/Wiki/WikiCreate.php +++ b/lib/classes/JsonApi/Routes/Wiki/WikiCreate.php @@ -54,10 +54,7 @@ class WikiCreate extends JsonApiController { $keyword = self::arrayGet($json, 'data.attributes.keyword'); $content = self::arrayGet($json, 'data.attributes.content'); - - if (method_exists(\Studip\Markup::class, 'purifyHtml')) { - $content = transformBeforeSave(\Studip\Markup::purifyHtml($content)); - } + $content = \Studip\Markup::purifyHtml($content); $wiki = new \WikiPage(); $wiki->keyword = $keyword; diff --git a/lib/classes/JsonApi/Routes/Wiki/WikiUpdate.php b/lib/classes/JsonApi/Routes/Wiki/WikiUpdate.php index 7fc7088d8a51bf1595ca96067655c31c04d2f95d..15acd600cadc768f44bea9322b30dae005547205 100644 --- a/lib/classes/JsonApi/Routes/Wiki/WikiUpdate.php +++ b/lib/classes/JsonApi/Routes/Wiki/WikiUpdate.php @@ -40,10 +40,7 @@ class WikiUpdate extends JsonApiController protected function updateWikiFromJSON(\User $user, \WikiPage $wikiPage, $json) { $content = self::arrayGet($json, 'data.attributes.content'); - - if (method_exists(\Studip\Markup::class, 'purifyHtml')) { - $content = transformBeforeSave(\Studip\Markup::purifyHtml($content)); - } + $content = \Studip\Markup::purifyHtml($content); if ($wikiPage->body === $content) { return $wikiPage; diff --git a/lib/classes/StudipTransformFormat.php b/lib/classes/StudipTransformFormat.php index 9b56d1af4ab1386ccab79778d8a5764d394810e6..04cf7a3c5e2d2c6a754d1aca09f600e6039e987d 100644 --- a/lib/classes/StudipTransformFormat.php +++ b/lib/classes/StudipTransformFormat.php @@ -12,6 +12,7 @@ /** * Format class to transform text before it is saved into the database. + * @deprecated since Stud.IP 5.3 */ class StudipTransformFormat extends TextFormat { diff --git a/lib/models/BlubberComment.php b/lib/models/BlubberComment.php index 1da67436224a9505ad2b8f622d7d5acec19d800c..3e076af093a3366aaab9c6df672df9aae0539e98 100644 --- a/lib/models/BlubberComment.php +++ b/lib/models/BlubberComment.php @@ -117,21 +117,8 @@ class BlubberComment extends SimpleORMap implements PrivacyObject public function transformMentions() { - BlubberThread::$mention_thread_id = $this->thread_id; - StudipTransformFormat::addStudipMarkup( - 'mention1', - '(?:^|\W)(@\"[^\n\"]*\")', - '', - 'BlubberThread::mention' - ); - StudipTransformFormat::addStudipMarkup( - 'mention2', - '(?:^|\W)(@[^\s]*[\d\w_]+)', - '', - 'BlubberThread::mention' - ); - $this['content'] = \Studip\Markup::purifyHtml($this['content']); - $this['content'] = transformBeforeSave($this['content']); + $callback = [$this->thread, 'mention']; + $this['content'] = preg_replace_callback('/\B@("[^\n"]+"|\S+)/', $callback, $this['content']); } /** diff --git a/lib/models/BlubberThread.php b/lib/models/BlubberThread.php index 70d99e25fab9aa6067fb55a32e1a03ce427cef42..0048c219c6858b189b7323c73676e3f708648018 100644 --- a/lib/models/BlubberThread.php +++ b/lib/models/BlubberThread.php @@ -47,22 +47,18 @@ class BlubberThread extends SimpleORMap implements PrivacyObject parent::configure($config); } - public static $mention_thread_id = null; protected $last_visit = null; /** - * Pre-Markup rule. Recognizes mentions in blubber as @username or @"Firstname lastname" + * Recognizes mentions in blubber as @username or @"Firstname lastname" * and turns them into usual studip-links. The mentioned person is notified by * sending a message to him/her as a side-effect. - * @param StudipTransformFormat $markup * @param array $matches * @return string */ - public static function mention($markup, $matches) + public function mention($matches) { - $mention = $matches[1]; - $thread = self::find(self::$mention_thread_id); - $username = stripslashes(mb_substr($mention, 1)); + $username = stripslashes(mb_substr($matches[0], 1)); if ($username[0] !== '"') { $user = User::findByUsername($username); } else { @@ -70,21 +66,21 @@ class BlubberThread extends SimpleORMap implements PrivacyObject $user = User::findOneBySQL("CONCAT(Vorname, ' ', Nachname) = ?", [$name]); } if ($user - && !$thread->isNew() + && !$this->isNew() && $user->getId() && $user->getId() !== $GLOBALS['user']->id ) { - if ($thread['context_type'] === 'private') { + if ($this['context_type'] === 'private') { $mention = new BlubberMention(); - $mention['thread_id'] = $thread->getId(); + $mention['thread_id'] = $this->getId(); $mention['user_id'] = $user->getId(); $mention->store(); - } elseif ($thread['context_type'] === 'public') { + } elseif ($this['context_type'] === 'public') { PersonalNotifications::add( $user->getId(), - $thread->getURL(), + $this->getURL(), sprintf(_('%s hat Sie in einem Blubber erwähnt.'), get_fullname()), - 'blubberthread_' . $thread->getId(), + 'blubberthread_' . $this->getId(), Icon::create('blubber'), true ); @@ -93,14 +89,10 @@ class BlubberThread extends SimpleORMap implements PrivacyObject $url = URLHelper::getLink('dispatch.php/profile', ['username' => $user->username]); URLHelper::setBaseURL($oldbase); - return str_replace( - $matches[1], - '[' . $user->getFullName() . ']' . $url . ' ', - $matches[0] - ); + return '[' . $user->getFullName() . ']' . $url . ' '; } - return $markup->quote($matches[0]); + return $matches[0]; } public static function findBySQL($sql, $params = []) diff --git a/lib/visual.inc.php b/lib/visual.inc.php index 1c3cd9e16d5c55e87542f83029f0d602d7b33a53..a4bb96eb070ba0cc41172ae4d01873d097853839 100644 --- a/lib/visual.inc.php +++ b/lib/visual.inc.php @@ -173,14 +173,14 @@ function blubberReady($text, $trim=TRUE) { } /** - * Apply StudipTransformFormat rules to marked-up text. + * Obsolete function for compatibility, returns text unchanged. * * @param string $text Marked-up text. - * @return string HTML code computed by applying markup-rules. + * @return string Marked-up text. + * @deprecated since Stud.IP 5.3 */ function transformBeforeSave($text){ - $markup = new StudipTransformFormat(); - return $markup->format($text); + return $text; } //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/wiki.inc.php b/lib/wiki.inc.php index e5a0ff4d3a2781c8fce02d35620b15a1a3aff0b4..0b6be7b54ff707c2300ff902baf7bea476a66d06 100644 --- a/lib/wiki.inc.php +++ b/lib/wiki.inc.php @@ -69,8 +69,7 @@ function submitWikiPage($keyword, $version, $body, $user_id, $range_id, $ancesto $wp = WikiPage::find([$range_id, $keyword, $version]); if ($wp) { if ($wp->isEditableBy($GLOBALS['user'])) { - // apply replace-before-save transformations - $wp->body = transformBeforeSave($body); + $wp->body = $body; if ($wp->isValidAncestor($ancestor)) { $wp->setAncestorForAllVersions($ancestor); } else { @@ -88,8 +87,6 @@ function submitWikiPage($keyword, $version, $body, $user_id, $range_id, $ancesto $version = $latestVersion['version'] + 1; } - // apply replace-before-save transformations - $body = transformBeforeSave($body); WikiPage::create(compact('range_id', 'user_id', 'keyword', 'body', 'ancestor', 'version')); } StudipTransformFormat::removeStudipMarkup('wiki-comments');