3 namespace Friendica\Model;
5 use Friendica\BaseModel;
6 use Friendica\Content\Text\BBCode;
7 use Friendica\Database\Database;
8 use Friendica\Network\HTTPException\InternalServerErrorException;
9 use Psr\Log\LoggerInterface;
12 * Model for an entry in the notify table
14 * @property string hash
15 * @property integer type
16 * @property string name Full name of the contact subject
17 * @property string url Profile page URL of the contact subject
18 * @property string photo Profile photo URL of the contact subject
19 * @property string date YYYY-MM-DD hh:mm:ss local server time
20 * @property string msg
21 * @property integer uid Owner User Id
22 * @property string link Notification URL
23 * @property integer iid Item Id
24 * @property integer parent Parent Item Id
25 * @property boolean seen Whether the notification was read or not.
26 * @property string verb Verb URL (@see http://activitystrea.ms)
27 * @property string otype Subject type (`item`, `intro` or `mail`)
29 * @property-read string name_cache Full name of the contact subject
30 * @property-read string msg_cache Plaintext version of the notification text with a placeholder (`{0}`) for the subject contact's name.
32 class Notify extends BaseModel
35 /** @var \Friendica\Repository\Notify */
38 public function __construct(Database $dba, LoggerInterface $logger, \Friendica\Repository\Notify $repo, array $data = [])
40 parent::__construct($dba, $logger, $data);
44 $this->setNameCache();
49 * Sets the pre-formatted name (caching)
51 private function setNameCache()
54 $this->name_cache = strip_tags(BBCode::convert($this->source_name ?? ''));
55 } catch (InternalServerErrorException $e) {
60 * Sets the pre-formatted msg (caching)
62 private function setMsgCache()
65 $this->msg_cache = self::formatMessage($this->name_cache, strip_tags(BBCode::convert($this->msg)));
66 } catch (InternalServerErrorException $e) {
70 public function __set($name, $value)
72 parent::__set($name, $value);
78 if ($name == 'source_name') {
79 $this->setNameCache();
84 * Formats a notification message with the notification author
86 * Replace the name with {0} but ensure to make that only once. The {0} is used
87 * later and prints the name in bold.
90 * @param string $message
92 * @return string Formatted message
94 public static function formatMessage($name, $message)
97 $pos = strpos($message, $name);
102 if ($pos !== false) {
103 $message = substr_replace($message, '{0}', $pos, strlen($name));