]> git.mxchange.org Git - friendica.git/blob - src/Navigation/Notifications/Entity/Notify.php
Replace Javascript notification string formatting with Smarty templates
[friendica.git] / src / Navigation / Notifications / Entity / Notify.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Navigation\Notifications\Entity;
23
24 use DateTime;
25 use Friendica\BaseEntity;
26 use Friendica\Content\Text\BBCode;
27 use Friendica\Core\Renderer;
28 use Psr\Http\Message\UriInterface;
29
30 /**
31  * @property-read $type
32  * @property-read $name
33  * @property-read $url
34  * @property-read $photo
35  * @property-read $date
36  * @property-read $msg
37  * @property-read $uid
38  * @property-read $link
39  * @property-read $itemId
40  * @property-read $parent
41  * @property-read $seen
42  * @property-read $verb
43  * @property-read $otype
44  * @property-read $name_cache
45  * @property-read $msg_cache
46  * @property-read $uriId
47  * @property-read $parentUriId
48  * @property-read $id
49  *
50  * @deprecated since 2022.05 Use \Friendica\Navigation\Notifications\Entity\Notification instead
51  */
52 class Notify extends BaseEntity
53 {
54         /** @var int */
55         protected $type;
56         /** @var string */
57         protected $name;
58         /** @var UriInterface */
59         protected $url;
60         /** @var UriInterface */
61         protected $photo;
62         /** @var DateTime */
63         protected $date;
64         /** @var string */
65         protected $msg;
66         /** @var int */
67         protected $uid;
68         /** @var UriInterface */
69         protected $link;
70         /** @var int */
71         protected $itemId;
72         /** @var int */
73         protected $parent;
74         /** @var bool */
75         protected $seen;
76         /** @var string */
77         protected $verb;
78         /** @var string */
79         protected $otype;
80         /** @var string */
81         protected $name_cache;
82         /** @var string */
83         protected $msg_cache;
84         /** @var int|null */
85         protected $uriId;
86         /** @var int|null */
87         protected $parentUriId;
88         /** @var int */
89         protected $id;
90
91         public function __construct(int $type, string $name, UriInterface $url, UriInterface $photo, DateTime $date, int $uid, UriInterface $link, bool $seen, string $verb, string $otype, string $name_cache, string $msg = null, string $msg_cache = null, int $itemId = null, int $uriId = null, int $parent = null, ?int $parentUriId = null, ?int $id = null)
92         {
93                 $this->type        = $type;
94                 $this->name        = $name;
95                 $this->url         = $url;
96                 $this->photo       = $photo;
97                 $this->date        = $date;
98                 $this->msg         = $msg;
99                 $this->uid         = $uid;
100                 $this->link        = $link;
101                 $this->itemId      = $itemId;
102                 $this->parent      = $parent;
103                 $this->seen        = $seen;
104                 $this->verb        = $verb;
105                 $this->otype       = $otype;
106                 $this->name_cache  = $name_cache;
107                 $this->msg_cache   = $msg_cache;
108                 $this->uriId       = $uriId;
109                 $this->parentUriId = $parentUriId;
110                 $this->id          = $id;
111         }
112
113         public function setSeen()
114         {
115                 $this->seen = true;
116         }
117
118         public function updateMsgFromPreamble($epreamble)
119         {
120                 $this->msg       = Renderer::replaceMacros($epreamble, ['$itemlink' => $this->link->__toString()]);
121                 $this->msg_cache = self::formatMessage($this->name_cache, strip_tags(BBCode::convert($this->msg)));
122         }
123
124         /**
125          * Formats a notification message with the notification author
126          *
127          * Replace the name with {0} but ensure to make that only once. The {0} is used
128          * later and prints the name in bold.
129          *
130          * @param string $name
131          * @param string $message
132          *
133          * @return string Formatted message
134          */
135         public static function formatMessage(string $name, string $message): string
136         {
137                 return str_replace('{0}', '<span class="contactname">' . strip_tags(BBCode::convert($name)) . '</span>', $message);
138         }
139 }