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.

332 lines
11 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
9 years ago
9 years ago
11 years ago
11 years ago
11 years ago
  1. <?php
  2. /**
  3. * @file mod/notifications.php
  4. * @brief The notifications module
  5. */
  6. require_once("include/NotificationsManager.php");
  7. require_once("include/contact_selectors.php");
  8. require_once("include/network.php");
  9. function notifications_post(App $a) {
  10. if (! local_user()) {
  11. goaway(z_root());
  12. }
  13. $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
  14. if($request_id === "all")
  15. return;
  16. if($request_id) {
  17. $r = q("SELECT * FROM `intro` WHERE `id` = %d AND `uid` = %d LIMIT 1",
  18. intval($request_id),
  19. intval(local_user())
  20. );
  21. if (dbm::is_result($r)) {
  22. $intro_id = $r[0]['id'];
  23. $contact_id = $r[0]['contact-id'];
  24. }
  25. else {
  26. notice( t('Invalid request identifier.') . EOL);
  27. return;
  28. }
  29. // If it is a friend suggestion, the contact is not a new friend but an existing friend
  30. // that should not be deleted.
  31. $fid = $r[0]['fid'];
  32. if($_POST['submit'] == t('Discard')) {
  33. $r = q("DELETE FROM `intro` WHERE `id` = %d",
  34. intval($intro_id)
  35. );
  36. if(! $fid) {
  37. // The check for blocked and pending is in case the friendship was already approved
  38. // and we just want to get rid of the now pointless notification
  39. $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 AND `blocked` = 1 AND `pending` = 1",
  40. intval($contact_id),
  41. intval(local_user())
  42. );
  43. }
  44. goaway('notifications/intros');
  45. }
  46. if($_POST['submit'] == t('Ignore')) {
  47. $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d",
  48. intval($intro_id));
  49. goaway('notifications/intros');
  50. }
  51. }
  52. }
  53. function notifications_content(App $a) {
  54. if (! local_user()) {
  55. notice( t('Permission denied.') . EOL);
  56. return;
  57. }
  58. $page = (x($_REQUEST,'page') ? $_REQUEST['page'] : 1);
  59. $show = (x($_REQUEST,'show') ? $_REQUEST['show'] : 0);
  60. nav_set_selected('notifications');
  61. $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false);
  62. $nm = new NotificationsManager();
  63. $o = '';
  64. // Get the nav tabs for the notification pages
  65. $tabs = $nm->getTabs();
  66. $notif_content = array();
  67. // Notification results per page
  68. $perpage = 20;
  69. $startrec = ($page * $perpage) - $perpage;
  70. // Get introductions
  71. if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
  72. nav_set_selected('introductions');
  73. $notif_header = t('Notifications');
  74. $all = (($a->argc > 2) && ($a->argv[2] == 'all'));
  75. $notifs = $nm->introNotifs($all, $startrec, $perpage);
  76. // Get the network notifications
  77. } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
  78. $notif_header = t('Network Notifications');
  79. $notifs = $nm->networkNotifs($show, $startrec, $perpage);
  80. // Get the system notifications
  81. } else if (($a->argc > 1) && ($a->argv[1] == 'system')) {
  82. $notif_header = t('System Notifications');
  83. $notifs = $nm->systemNotifs($show, $startrec, $perpage);
  84. // Get the personal notifications
  85. } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) {
  86. $notif_header = t('Personal Notifications');
  87. $notifs = $nm->personalNotifs($show, $startrec, $perpage);
  88. // Get the home notifications
  89. } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
  90. $notif_header = t('Home Notifications');
  91. $notifs = $nm->homeNotifs($show, $startrec, $perpage);
  92. }
  93. // Set the pager
  94. $a->set_pager_total($notifs['total']);
  95. $a->set_pager_itemspage($perpage);
  96. // Add additional informations (needed for json output)
  97. $notifs['items_page'] = $a->pager['itemspage'];
  98. $notifs['page'] = $a->pager['page'];
  99. // Json output
  100. if(intval($json) === 1)
  101. json_return_and_die($notifs);
  102. $notif_tpl = get_markup_template('notifications.tpl');
  103. // Process the data for template creation
  104. if($notifs['ident'] === 'introductions') {
  105. $sugg = get_markup_template('suggestions.tpl');
  106. $tpl = get_markup_template("intros.tpl");
  107. // The link to switch between ignored and normal connection requests
  108. $notif_show_lnk = array(
  109. 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros' ),
  110. 'text' => (!$all ? t('Show Ignored Requests') : t('Hide Ignored Requests'))
  111. );
  112. // Loop through all introduction notifications.This creates an array with the output html for each
  113. // introduction
  114. foreach ($notifs['notifications'] as $it) {
  115. // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests.
  116. // We have to distinguish between these two because they use different data.
  117. switch ($it['label']) {
  118. case 'friend_suggestion':
  119. $notif_content[] = replace_macros($sugg, array(
  120. '$str_notifytype' => t('Notification type: '),
  121. '$notify_type' => $it['notify_type'],
  122. '$intro_id' => $it['intro_id'],
  123. '$madeby' => sprintf( t('suggested by %s'),$it['madeby']),
  124. '$contact_id' => $it['contact-id'],
  125. '$photo' => $it['photo'],
  126. '$fullname' => $it['name'],
  127. '$url' => $it['url'],
  128. '$hidden' => array('hidden', t('Hide this contact from others'), ($it['hidden'] == 1), ''),
  129. '$activity' => array('activity', t('Post a new friend activity'), $it['post_newfriend'], t('if applicable')),
  130. '$knowyou' => $it['knowyou'],
  131. '$approve' => t('Approve'),
  132. '$note' => $it['note'],
  133. '$request' => $it['request'],
  134. '$ignore' => t('Ignore'),
  135. '$discard' => t('Discard'),
  136. ));
  137. break;
  138. // Normal connection requests
  139. default:
  140. $friend_selected = (($it['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
  141. $fan_selected = (($it['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
  142. $dfrn_tpl = get_markup_template('netfriend.tpl');
  143. $knowyou = '';
  144. $dfrn_text = '';
  145. if($it['network'] === NETWORK_DFRN || $it['network'] === NETWORK_DIASPORA) {
  146. if($it['network'] === NETWORK_DFRN) {
  147. $lbl_knowyou = t('Claims to be known to you: ');
  148. $knowyou = (($it['knowyou']) ? t('yes') : t('no'));
  149. $helptext = t('Shall your connection be bidirectional or not?');
  150. $helptext2 = sprintf(t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.'), $it['name'], $it['name']);
  151. $helptext3 = sprintf(t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.'), $it['name']);
  152. } else {
  153. $knowyou = '';
  154. $helptext = t('Shall your connection be bidirectional or not?');
  155. $helptext2 = sprintf(t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.'), $it['name'], $it['name']);
  156. $helptext3 = sprintf(t('Accepting %s as a sharer allows them to subscribe to your posts, but you will not receive updates from them in your news feed.'), $it['name']);
  157. }
  158. }
  159. $dfrn_text = replace_macros($dfrn_tpl,array(
  160. '$intro_id' => $it['intro_id'],
  161. '$friend_selected' => $friend_selected,
  162. '$fan_selected' => $fan_selected,
  163. '$approve_as1' => $helptext,
  164. '$approve_as2' => $helptext2,
  165. '$approve_as3' => $helptext3,
  166. '$as_friend' => t('Friend'),
  167. '$as_fan' => (($it['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Subscriber'))
  168. ));
  169. $header = $it["name"];
  170. if ($it["addr"] != "")
  171. $header .= " <".$it["addr"].">";
  172. $header .= " (".network_to_name($it['network'], $it['url']).")";
  173. if ($it['network'] != NETWORK_DIASPORA) {
  174. $discard = t('Discard');
  175. } else {
  176. $discard = '';
  177. }
  178. $notif_content[] = replace_macros($tpl, array(
  179. '$header' => htmlentities($header),
  180. '$str_notifytype' => t('Notification type: '),
  181. '$notify_type' => $it['notify_type'],
  182. '$dfrn_text' => $dfrn_text,
  183. '$dfrn_id' => $it['dfrn_id'],
  184. '$uid' => $it['uid'],
  185. '$intro_id' => $it['intro_id'],
  186. '$contact_id' => $it['contact_id'],
  187. '$photo' => $it['photo'],
  188. '$fullname' => $it['name'],
  189. '$location' => $it['location'],
  190. '$lbl_location' => t('Location:'),
  191. '$about' => $it['about'],
  192. '$lbl_about' => t('About:'),
  193. '$keywords' => $it['keywords'],
  194. '$lbl_keywords' => t('Tags:'),
  195. '$gender' => $it['gender'],
  196. '$lbl_gender' => t('Gender:'),
  197. '$hidden' => array('hidden', t('Hide this contact from others'), ($it['hidden'] == 1), ''),
  198. '$activity' => array('activity', t('Post a new friend activity'), $it['post_newfriend'], t('if applicable')),
  199. '$url' => $it['url'],
  200. '$zrl' => $it['zrl'],
  201. '$lbl_url' => t('Profile URL'),
  202. '$addr' => $it['addr'],
  203. '$lbl_knowyou' => $lbl_knowyou,
  204. '$lbl_network' => t('Network:'),
  205. '$network' => network_to_name($it['network'], $it['url']),
  206. '$knowyou' => $knowyou,
  207. '$approve' => t('Approve'),
  208. '$note' => $it['note'],
  209. '$ignore' => t('Ignore'),
  210. '$discard' => $discard,
  211. ));
  212. break;
  213. }
  214. }
  215. if($notifs['total'] == 0)
  216. info( t('No introductions.') . EOL);
  217. // Normal notifications (no introductions)
  218. } else {
  219. // The template files we need in different cases for formatting the content
  220. $tpl_item_like = 'notifications_likes_item.tpl';
  221. $tpl_item_dislike = 'notifications_dislikes_item.tpl';
  222. $tpl_item_attend = 'notifications_attend_item.tpl';
  223. $tpl_item_attendno = 'notifications_attend_item.tpl';
  224. $tpl_item_attendmaybe = 'notifications_attend_item.tpl';
  225. $tpl_item_friend = 'notifications_friends_item.tpl';
  226. $tpl_item_comment = 'notifications_comments_item.tpl';
  227. $tpl_item_post = 'notifications_posts_item.tpl';
  228. $tpl_item_notify = 'notify.tpl';
  229. // Loop trough ever notification This creates an array with the output html for each
  230. // notification and apply the correct template according to the notificationtype (label).
  231. foreach ($notifs['notifications'] as $it) {
  232. // We use the notification label to get the correct template file
  233. $tpl_var_name = 'tpl_item_'.$it['label'];
  234. $tpl_notif = get_markup_template($$tpl_var_name);
  235. $notif_content[] = replace_macros($tpl_notif,array(
  236. '$item_label' => $it['label'],
  237. '$item_link' => $it['link'],
  238. '$item_image' => $it['image'],
  239. '$item_url' => $it['url'],
  240. '$item_text' => $it['text'],
  241. '$item_when' => $it['when'],
  242. '$item_ago' => $it['ago'],
  243. '$item_seen' => $it['seen'],
  244. ));
  245. }
  246. // It doesn't make sense to show the Show unread / Show all link visible if the user is on the
  247. // "Show all" page and there are no notifications. So we will hide it.
  248. if($show == 0 || intval($show) && $notifs['total'] > 0) {
  249. $notif_show_lnk = array(
  250. 'href' => ($show ? 'notifications/'.$notifs['ident'] : 'notifications/'.$notifs['ident'].'?show=all' ),
  251. 'text' => ($show ? t('Show unread') : t('Show all')),
  252. );
  253. }
  254. // Output if there aren't any notifications available
  255. if($notifs['total'] == 0)
  256. $notif_nocontent = sprintf( t('No more %s notifications.'), $notifs['ident']);
  257. }
  258. $o .= replace_macros($notif_tpl, array(
  259. '$notif_header' => $notif_header,
  260. '$tabs' => $tabs,
  261. '$notif_content' => $notif_content,
  262. '$notif_nocontent' => $notif_nocontent,
  263. '$notif_show_lnk' => $notif_show_lnk,
  264. '$notif_paginate' => paginate($a)
  265. ));
  266. return $o;
  267. }