repo = $repo; $this->setNameCache(); $this->setMsgCache(); } /** * Sets the pre-formatted name (caching) */ private function setNameCache() { try { $this->name_cache = strip_tags(BBCode::convert($this->source_name ?? '')); } catch (InternalServerErrorException $e) { } } /** * Sets the pre-formatted msg (caching) */ private function setMsgCache() { try { $this->msg_cache = self::formatMessage($this->name_cache, strip_tags(BBCode::convert($this->msg))); } catch (InternalServerErrorException $e) { } } public function __set($name, $value) { parent::__set($name, $value); if ($name == 'msg') { $this->setMsgCache(); } if ($name == 'source_name') { $this->setNameCache(); } } /** * Formats a notification message with the notification author * * Replace the name with {0} but ensure to make that only once. The {0} is used * later and prints the name in bold. * * @param string $name * @param string $message * * @return string Formatted message */ public static function formatMessage($name, $message) { if ($name != '') { $pos = strpos($message, $name); } else { $pos = false; } if ($pos !== false) { $message = substr_replace($message, '{0}', $pos, strlen($name)); } return $message; } }