]> git.mxchange.org Git - friendica.git/blob - mod/notifications.php
added posts to network section of the notifications page
[friendica.git] / mod / notifications.php
1 <?php
2
3 function notifications_post(&$a) {
4
5         if(! local_user()) {
6                 goaway(z_root());
7         }
8         
9         $request_id = (($a->argc > 1) ? $a->argv[1] : 0);
10         
11         if($request_id === "all")
12                 return;
13
14         if($request_id) {
15
16                 $r = q("SELECT * FROM `intro` WHERE `id` = %d  AND `uid` = %d LIMIT 1",
17                         intval($request_id),
18                         intval(local_user())
19                 );
20         
21                 if(count($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
30                 // If it is a friend suggestion, the contact is not a new friend but an existing friend
31                 // that should not be deleted.
32
33                 $fid = $r[0]['fid'];
34
35                 if($_POST['submit'] == t('Discard')) {
36                         $r = q("DELETE FROM `intro` WHERE `id` = %d LIMIT 1", 
37                                 intval($intro_id)
38                         );      
39                         if(! $fid) {
40                                 $r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 LIMIT 1", 
41                                         intval($contact_id),
42                                         intval(local_user())
43                                 );
44                         }
45                         return;
46                 }
47                 if($_POST['submit'] == t('Ignore')) {
48                         $r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d LIMIT 1",
49                                 intval($intro_id));
50                         return;
51                 }
52         }
53 }
54
55
56
57
58
59 function notifications_content(&$a) {
60
61         if(! local_user()) {
62                 notice( t('Permission denied.') . EOL);
63                 return;
64         }
65
66         $o = '';
67         
68         if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) {
69                 
70                 if(($a->argc > 2) && ($a->argv[2] == 'all'))
71                         $sql_extra = '';
72                 else
73                         $sql_extra = " AND `ignore` = 0 ";
74                 
75                 $notif_tpl = get_markup_template('notifications.tpl');
76                 
77                 $notif_content .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
78                         . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n";
79
80                 $r = q("SELECT COUNT(*) AS `total` FROM `intro` 
81                         WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
82                                 intval($_SESSION['uid'])
83                 );
84                 if($r && count($r)) {
85                         $a->set_pager_total($r[0]['total']);
86                         $a->set_pager_itemspage(20);
87                 }
88
89                 $r = q("SELECT `intro`.`id` AS `intro_id`, `intro`.*, `contact`.*, `fcontact`.`name` AS `fname`,`fcontact`.`url` AS `furl`,`fcontact`.`photo` AS `fphoto`,`fcontact`.`request` AS `frequest`
90                         FROM `intro` LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id`
91                         WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
92                                 intval($_SESSION['uid']));
93
94                 if(($r !== false) && (count($r))) {
95
96                         $sugg = get_markup_template('suggestions.tpl');
97                         $tpl = get_markup_template("intros.tpl");
98
99                         foreach($r as $rr) {
100                                 if($rr['fid']) {
101
102                                         $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : ''));
103                                         $notif_content .= replace_macros($sugg,array(
104                                                 '$str_notifytype' => t('Notification type: '),
105                                                 '$notify_type' => t('Friend Suggestion'),
106                                                 '$intro_id' => $rr['intro_id'],
107                                                 '$madeby' => sprintf( t('suggested by %s'),$rr['name']),
108                                                 '$contact_id' => $rr['contact-id'],
109                                                 '$photo' => ((x($rr,'fphoto')) ? $rr['fphoto'] : "images/default-profile.jpg"),
110                                                 '$fullname' => $rr['fname'],
111                                                 '$url' => $rr['furl'],
112                                                 '$knowyou' => $knowyou,
113                                                 '$approve' => t('Approve'),
114                                                 '$note' => $rr['note'],
115                                                 '$request' => $rr['frequest'] . '?addr=' . $return_addr,
116                                                 '$ignore' => t('Ignore'),
117                                                 '$discard' => t('Discard')
118
119                                         ));
120
121                                         continue;
122
123                                 }
124                                 $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled ');
125                                 $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : '');
126                                 $dfrn_tpl = get_markup_template('netfriend.tpl');
127
128                                 $knowyou   = '';
129                                 $dfrn_text = '';
130
131                                 if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) {
132                                         if($rr['network'] === NETWORK_DFRN)
133                                                 $knowyou = t('Claims to be known to you: ') . (($rr['knowyou']) ? t('yes') : t('no'));
134                                         else
135                                                 $knowyou = '';
136                                         $dfrn_text = replace_macros($dfrn_tpl,array(
137                                                 '$intro_id' => $rr['intro_id'],
138                                                 '$friend_selected' => $friend_selected,
139                                                 '$fan_selected' => $fan_selected,
140                                                 '$approve_as' => t('Approve as: '),
141                                                 '$as_friend' => t('Friend'),
142                                                 '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer'))
143                                         ));
144                                 }                       
145
146                                 $notif_content .= replace_macros($tpl,array(
147                                         '$str_notifytype' => t('Notification type: '),
148                                         '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')),
149                                         '$dfrn_text' => $dfrn_text,     
150                                         '$dfrn_id' => $rr['issued-id'],
151                                         '$uid' => $_SESSION['uid'],
152                                         '$intro_id' => $rr['intro_id'],
153                                         '$contact_id' => $rr['contact-id'],
154                                         '$photo' => ((x($rr,'photo')) ? $rr['photo'] : "images/default-profile.jpg"),
155                                         '$fullname' => $rr['name'],
156                                         '$url' => $rr['url'],
157                                         '$knowyou' => $knowyou,
158                                         '$approve' => t('Approve'),
159                                         '$note' => $rr['note'],
160                                         '$ignore' => t('Ignore'),
161                                         '$discard' => t('Discard')
162
163                                 ));
164                         }
165                 }
166                 else
167                         info( t('No notifications.') . EOL);
168                 
169                 $o .= replace_macros($notif_tpl,array(
170                         '$notif_content' => $notif_content,
171                         '$activetab' => 'intros'
172                 ));
173                 
174                 $o .= paginate($a);
175                 return $o;
176                                 
177         } else if (($a->argc > 1) && ($a->argv[1] == 'network')) {
178                 
179                 $notif_tpl = get_markup_template('notifications.tpl');
180                 
181                 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, 
182                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`, 
183                                 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` 
184                                 FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
185                                 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
186                                  `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" ,
187                         intval(local_user())
188                 );
189                 
190                 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
191                 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
192                 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
193                 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
194                 $tpl_item_posts = get_markup_template('notifications_posts_item.tpl');
195                 
196                 $notif_content = '';
197                 
198                 if (count($r) > 0) {
199                         
200                         foreach ($r as $it) {
201                                 switch($it['verb']){
202                                         case ACTIVITY_LIKE:
203                                                 $notif_content .= replace_macros($tpl_item_likes,array(
204                                                         '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
205                                                         '$item_image' => $it['author-avatar'],
206                                                         '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
207                                                         '$item_when' => relative_date($it['created'])
208                                                 ));
209                                                 break;
210                                                 
211                                         case ACTIVITY_DISLIKE:
212                                                 $notif_content .= replace_macros($tpl_item_dislikes,array(
213                                                         '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
214                                                         '$item_image' => $it['author-avatar'],
215                                                         '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
216                                                         '$item_when' => relative_date($it['created'])
217                                                 ));
218                                                 break;
219                                                 
220                                         case ACTIVITY_FRIEND:
221                                         
222                                                 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
223                                                 $obj = parse_xml_string($xmlhead.$it['object']);
224                                                 $it['fname'] = $obj->title;
225                                                 
226                                                 $notif_content .= replace_macros($tpl_item_friends,array(
227                                                         '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
228                                                         '$item_image' => $it['author-avatar'],
229                                                         '$item_text' => sprintf( t("%s is now friend with %s"), $it['author-name'], $it['fname']),
230                                                         '$item_when' => relative_date($it['created'])
231                                                 ));
232                                                 break;
233                                                 
234                                         case ACTIVITY_POST;$notif_content .= replace_macros($tpl_item_posts,array(
235                                                         '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
236                                                         '$item_image' => $it['author-avatar'],
237                                                         '$item_text' => sprintf( t("%s posted"), $it['author-name']),
238                                                         '$item_when' => relative_date($it['created'])
239                                                 ));
240                                                 break;
241                                                 
242                                         default:
243                                                 $notif_content .= replace_macros($tpl_item_comments,array(
244                                                         '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
245                                                         '$item_image' => $it['author-avatar'],
246                                                         '$item_text' => sprintf( t("%s commented %s's post"), $it['author-name'], $it['pname']),
247                                                         '$item_when' => relative_date($it['created'])
248                                                 ));
249                                 }
250                         }
251                         
252                 } else {
253                         
254                         $notif_content = 'Nothing new!';
255                 }
256                 
257                 $o .= replace_macros($notif_tpl,array(
258                         '$notif_content' => $notif_content,
259                         '$activetab' => 'network'
260                 ));
261                 
262         } else if (($a->argc > 1) && ($a->argv[1] == 'home')) {
263                 
264                 $notif_tpl = get_markup_template('notifications.tpl');
265                 
266                 $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, 
267                                 `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`, 
268                                 `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink` 
269                                 FROM `item` INNER JOIN `item` as `pitem` ON  `pitem`.`id`=`item`.`parent`
270                                 WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND
271                                  `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
272                         intval(local_user())
273                 );
274                 
275                 $tpl_item_likes = get_markup_template('notifications_likes_item.tpl');
276                 $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl');
277                 $tpl_item_friends = get_markup_template('notifications_friends_item.tpl');
278                 $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
279                 
280                 $notif_content = '';
281                 
282                 if (count($r) > 0) {
283                         
284                         foreach ($r as $it) {
285                                 switch($it['verb']){
286                                         case ACTIVITY_LIKE:
287                                                 $notif_content .= replace_macros($tpl_item_likes,array(
288                                                         '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
289                                                         '$item_image' => $it['author-avatar'],
290                                                         '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
291                                                         '$item_when' => relative_date($it['created'])
292                                                 ));
293
294                                                 break;
295                                         case ACTIVITY_DISLIKE:
296                                                 $notif_content .= replace_macros($tpl_item_dislikes,array(
297                                                         '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
298                                                         '$item_image' => $it['author-avatar'],
299                                                         '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
300                                                         '$item_when' => relative_date($it['created'])
301                                                 ));
302
303                                                 break;
304                                         case ACTIVITY_FRIEND:
305                                         
306                                                 $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">";
307                                                 $obj = parse_xml_string($xmlhead.$it['object']);
308                                                 $it['fname'] = $obj->title;
309                                                 
310                                                 $notif_content .= replace_macros($tpl_item_friends,array(
311                                                         '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
312                                                         '$item_image' => $it['author-avatar'],
313                                                         '$item_text' => sprintf( t("%s is now friend with %s"), $it['author-name'], $it['fname']),
314                                                         '$item_when' => relative_date($it['created'])
315                                                 ));
316
317                                                 break;
318                                         default:
319                                                 $notif_content .= replace_macros($tpl_item_comments,array(
320                                                         '$item_link' => $a->get_baseurl().'/display/'.$a->user['nickname']."/".$it['parent'],
321                                                         '$item_image' => $it['author-avatar'],
322                                                         '$item_text' => sprintf( t("%s commented %s's post"), $it['author-name'], $it['pname']),
323                                                         '$item_when' => relative_date($it['created'])
324                                                 ));
325                                 }
326                         }
327                                 
328                 } else {
329                         $notif_content = 'Nothing new!';
330                 }
331                 
332                 $o .= replace_macros($notif_tpl,array(
333                         '$notif_content' => $notif_content,
334                         '$activetab' => 'home'
335                 ));
336         }
337
338         $o .= paginate($a);
339         return $o;
340 }