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
34 const OTYPE_ITEM = 'item';
35 const OTYPE_INTRO = 'intro';
36 const OTYPE_MAIL = 'mail';
37 const OTYPE_PERSON = 'person';
39 /** @var \Friendica\Repository\Notify */
42 public function __construct(Database $dba, LoggerInterface $logger, \Friendica\Repository\Notify $repo, array $data = [])
44 parent::__construct($dba, $logger, $data);
48 $this->setNameCache();
53 * Sets the pre-formatted name (caching)
55 private function setNameCache()
58 $this->name_cache = strip_tags(BBCode::convert($this->source_name ?? ''));
59 } catch (InternalServerErrorException $e) {
64 * Sets the pre-formatted msg (caching)
66 private function setMsgCache()
69 $this->msg_cache = self::formatMessage($this->name_cache, strip_tags(BBCode::convert($this->msg)));
70 } catch (InternalServerErrorException $e) {
74 public function __set($name, $value)
76 parent::__set($name, $value);
82 if ($name == 'source_name') {
83 $this->setNameCache();
88 * Formats a notification message with the notification author
90 * Replace the name with {0} but ensure to make that only once. The {0} is used
91 * later and prints the name in bold.
94 * @param string $message
96 * @return string Formatted message
98 public static function formatMessage($name, $message)
101 $pos = strpos($message, $name);
106 if ($pos !== false) {
107 $message = substr_replace($message, '{0}', $pos, strlen($name));