Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

77 lines
1.8 KiB

  1. <?php
  2. require_once('include/NotificationsManager.php');
  3. function notify_init(App &$a) {
  4. if (! local_user()) {
  5. return;
  6. }
  7. $nm = new NotificationsManager();
  8. if ($a->argc > 2 && $a->argv[1] === 'view' && intval($a->argv[2])) {
  9. $note = $nm->getByID($a->argv[2]);
  10. if ($note) {
  11. $nm->setSeen($note);
  12. // The friendica client has problems with the GUID. this is some workaround
  13. if ($a->is_friendica_app()) {
  14. require_once("include/items.php");
  15. $urldata = parse_url($note['link']);
  16. $guid = basename($urldata["path"]);
  17. $itemdata = get_item_id($guid, local_user());
  18. if ($itemdata["id"] != 0) {
  19. $note['link'] = App::get_baseurl().'/display/'.$itemdata["nick"].'/'.$itemdata["id"];
  20. }
  21. }
  22. goaway($note['link']);
  23. }
  24. goaway(App::get_baseurl(true));
  25. }
  26. if ($a->argc > 2 && $a->argv[1] === 'mark' && $a->argv[2] === 'all' ) {
  27. $r = $nm->setAllSeen();
  28. $j = json_encode(array('result' => ($r) ? 'success' : 'fail'));
  29. echo $j;
  30. killme();
  31. }
  32. }
  33. function notify_content(App &$a) {
  34. if (! local_user()) {
  35. return login();
  36. }
  37. $nm = new NotificationsManager();
  38. $notif_tpl = get_markup_template('notifications.tpl');
  39. $not_tpl = get_markup_template('notify.tpl');
  40. require_once('include/bbcode.php');
  41. $r = $nm->getAll(array('seen'=>0));
  42. if (dbm::is_result($r) > 0) {
  43. foreach ($r as $it) {
  44. $notif_content .= replace_macros($not_tpl,array(
  45. '$item_link' => App::get_baseurl(true).'/notify/view/'. $it['id'],
  46. '$item_image' => $it['photo'],
  47. '$item_text' => strip_tags(bbcode($it['msg'])),
  48. '$item_when' => relative_date($it['date'])
  49. ));
  50. }
  51. } else {
  52. $notif_content .= t('No more system notifications.');
  53. }
  54. $o .= replace_macros($notif_tpl, array(
  55. '$notif_header' => t('System Notifications'),
  56. '$tabs' => false, // $tabs,
  57. '$notif_content' => $notif_content,
  58. ));
  59. return $o;
  60. }