7 use Friendica\Content\Text\BBCode;
8 use Friendica\Core\L10n;
9 use Friendica\Core\NotificationsManager;
10 use Friendica\Core\System;
11 use Friendica\Database\DBM;
12 use Friendica\Model\Item;
13 use Friendica\Module\Login;
14 use Friendica\Util\Temporal;
16 function notify_init(App $a)
22 $nm = new NotificationsManager();
24 if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
25 $note = $nm->getByID($a->argv[2]);
29 // The friendica client has problems with the GUID. this is some workaround
30 if ($a->is_friendica_app()) {
31 require_once("include/items.php");
32 $urldata = parse_url($note['link']);
33 $guid = basename($urldata["path"]);
34 $itemdata = Item::getIdAndNickByGuid($guid, local_user());
35 if ($itemdata["id"] != 0) {
36 $note['link'] = System::baseUrl().'/display/'.$itemdata["nick"].'/'.$itemdata["id"];
40 goaway($note['link']);
43 goaway(System::baseUrl(true));
46 if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all') {
47 $r = $nm->setAllSeen();
48 $j = json_encode(['result' => ($r) ? 'success' : 'fail']);
54 function notify_content(App $a)
60 $nm = new NotificationsManager();
62 $notif_tpl = get_markup_template('notifications.tpl');
64 $not_tpl = get_markup_template('notify.tpl');
66 $r = $nm->getAll(['seen'=>0]);
67 if (DBM::is_result($r) > 0) {
69 $notif_content .= replace_macros($not_tpl, [
70 '$item_link' => System::baseUrl(true).'/notify/view/'. $it['id'],
71 '$item_image' => $it['photo'],
72 '$item_text' => strip_tags(BBCode::convert($it['msg'])),
73 '$item_when' => Temporal::getRelativeDate($it['date'])
77 $notif_content .= L10n::t('No more system notifications.');
80 $o = replace_macros($notif_tpl, [
81 '$notif_header' => L10n::t('System Notifications'),
82 '$tabs' => false, // $tabs,
83 '$notif_content' => $notif_content,