From f09cd571655bfd9966dd4529d4fb10256246a81c Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Thu, 28 Jul 2016 11:39:09 +0200 Subject: [PATCH 01/10] notifications.php - move duplicated code in an own function --- mod/notifications.php | 486 +++++++++++++++++++++++++++--------------- 1 file changed, 316 insertions(+), 170 deletions(-) diff --git a/mod/notifications.php b/mod/notifications.php index fa2c78cf67..ae4c97f83a 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -247,66 +247,71 @@ function notifications_content(&$a) { intval(local_user()) ); - $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); - $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); - $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); - $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); - $tpl_item_posts = get_markup_template('notifications_posts_item.tpl'); +// $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); +// $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); +// $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); +// $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); +// $tpl_item_posts = get_markup_template('notifications_posts_item.tpl'); if ($r) { - foreach ($r as $it) { - switch($it['verb']){ - case ACTIVITY_LIKE: - $notif_content[] = replace_macros($tpl_item_likes,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), - '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - break; + $notifs = array( + 'notifications' => $r, + 'ident' => 'network', + ); - case ACTIVITY_DISLIKE: - $notif_content[] = replace_macros($tpl_item_dislikes,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), - '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - break; - - case ACTIVITY_FRIEND: - - $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; - $obj = parse_xml_string($xmlhead.$it['object']); - $it['fname'] = $obj->title; - - $notif_content[] = replace_macros($tpl_item_friends,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), - '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), - '$item_when' => relative_date($it['created']) - )); - break; - - default: - $item_text = (($it['id'] == $it['parent']) - ? sprintf( t("%s created a new post"), $it['author-name']) - : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); - $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); - - $notif_content[] = replace_macros($tpl,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), - '$item_text' => $item_text, - '$item_when' => relative_date($it['created']) - )); - } - } +// foreach ($r as $it) { +// switch($it['verb']){ +// case ACTIVITY_LIKE: +// $notif_content[] = replace_macros($tpl_item_likes,array( +// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], +// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], +// '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), +// '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), +// '$item_when' => relative_date($it['created']) +// )); +// break; +// +// case ACTIVITY_DISLIKE: +// $notif_content[] = replace_macros($tpl_item_dislikes,array( +// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], +// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], +// '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), +// '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), +// '$item_when' => relative_date($it['created']) +// )); +// break; +// +// case ACTIVITY_FRIEND: +// +// $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; +// $obj = parse_xml_string($xmlhead.$it['object']); +// $it['fname'] = $obj->title; +// +// $notif_content[] = replace_macros($tpl_item_friends,array( +// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], +// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], +// '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), +// '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), +// '$item_when' => relative_date($it['created']) +// )); +// break; +// +// default: +// $item_text = (($it['id'] == $it['parent']) +// ? sprintf( t("%s created a new post"), $it['author-name']) +// : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); +// $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); +// +// $notif_content[] = replace_macros($tpl,array( +// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], +// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], +// '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), +// '$item_text' => $item_text, +// '$item_when' => relative_date($it['created']) +// )); +// } +// } } else { @@ -326,14 +331,19 @@ function notifications_content(&$a) { ); if (count($r) > 0) { - foreach ($r as $it) { - $notif_content[] = replace_macros($not_tpl,array( - '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'], - '$item_image' => proxy_url($it['photo'], false, PROXY_SIZE_MICRO), - '$item_text' => strip_tags(bbcode($it['msg'])), - '$item_when' => relative_date($it['date']) - )); - } +// foreach ($r as $it) { +// $notif_content[] = replace_macros($not_tpl,array( +// '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'], +// '$item_image' => proxy_url($it['photo'], false, PROXY_SIZE_MICRO), +// '$item_text' => strip_tags(bbcode($it['msg'])), +// '$item_when' => relative_date($it['date']) +// )); +// } + $notifs = array( + 'notifications' => $r, + 'ident' => 'system', + ); + } else { $notif_nocontent = t('No more system notifications.'); } @@ -364,66 +374,71 @@ function notifications_content(&$a) { intval(local_user()) ); - $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); - $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); - $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); - $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); - $tpl_item_posts = get_markup_template('notifications_posts_item.tpl'); +// $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); +// $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); +// $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); +// $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); +// $tpl_item_posts = get_markup_template('notifications_posts_item.tpl'); if (count($r) > 0) { + $notifs =array( + 'notifications' => $r, + 'ident' => 'personal' + ); - foreach ($r as $it) { - switch($it['verb']){ - case ACTIVITY_LIKE: - $notif_content[] = replace_macros($tpl_item_likes,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - break; - case ACTIVITY_DISLIKE: - $notif_content[] = replace_macros($tpl_item_dislikes,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - break; - - case ACTIVITY_FRIEND: - - $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; - $obj = parse_xml_string($xmlhead.$it['object']); - $it['fname'] = $obj->title; - - $notif_content[] = replace_macros($tpl_item_friends,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), - '$item_when' => relative_date($it['created']) - )); - break; - - default: - $item_text = (($it['id'] == $it['parent']) - ? sprintf( t("%s created a new post"), $it['author-name']) - : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); - $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); - - $notif_content[] = replace_macros($tpl,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => $it['author-avatar'], - '$item_text' => $item_text, - '$item_when' => relative_date($it['created']) - )); - } - } +// foreach ($r as $it) { +// switch($it['verb']){ +// case ACTIVITY_LIKE: +// $notif_content[] = replace_macros($tpl_item_likes,array( +// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], +// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], +// '$item_image' => $it['author-avatar'], +// '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), +// '$item_when' => relative_date($it['created']) +// )); +// break; +// +// case ACTIVITY_DISLIKE: +// $notif_content[] = replace_macros($tpl_item_dislikes,array( +// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], +// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], +// '$item_image' => $it['author-avatar'], +// '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), +// '$item_when' => relative_date($it['created']) +// )); +// break; +// +// case ACTIVITY_FRIEND: +// +// $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; +// $obj = parse_xml_string($xmlhead.$it['object']); +// $it['fname'] = $obj->title; +// +// $notif_content[] = replace_macros($tpl_item_friends,array( +// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], +// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], +// '$item_image' => $it['author-avatar'], +// '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), +// '$item_when' => relative_date($it['created']) +// )); +// break; +// +// default: +// $item_text = (($it['id'] == $it['parent']) +// ? sprintf( t("%s created a new post"), $it['author-name']) +// : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); +// $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); +// +// $notif_content[] = replace_macros($tpl,array( +// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], +// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], +// '$item_image' => $it['author-avatar'], +// '$item_text' => $item_text, +// '$item_when' => relative_date($it['created']) +// )); +// } +// } } else { @@ -444,60 +459,65 @@ function notifications_content(&$a) { intval(local_user()) ); - $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); - $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); - $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); - $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); +// $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); +// $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); +// $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); +// $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); if (count($r) > 0) { - foreach ($r as $it) { - switch($it['verb']){ - case ACTIVITY_LIKE: - $notif_content[] = replace_macros($tpl_item_likes,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); + $notifs = array( + 'notifications' => $r, + 'ident' => 'home', + ); - break; - case ACTIVITY_DISLIKE: - $notif_content[] = replace_macros($tpl_item_dislikes,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - - break; - case ACTIVITY_FRIEND: - - $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; - $obj = parse_xml_string($xmlhead.$it['object']); - $it['fname'] = $obj->title; - - $notif_content[] = replace_macros($tpl_item_friends,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), - '$item_when' => relative_date($it['created']) - )); - - break; - default: - $notif_content[] = replace_macros($tpl_item_comments,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => $it['author-avatar'], - '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - } - } +// foreach ($r as $it) { +// switch($it['verb']){ +// case ACTIVITY_LIKE: +// $notif_content[] = replace_macros($tpl_item_likes,array( +// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], +// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], +// '$item_image' => $it['author-avatar'], +// '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), +// '$item_when' => relative_date($it['created']) +// )); +// +// break; +// case ACTIVITY_DISLIKE: +// $notif_content[] = replace_macros($tpl_item_dislikes,array( +// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], +// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], +// '$item_image' => $it['author-avatar'], +// '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), +// '$item_when' => relative_date($it['created']) +// )); +// +// break; +// case ACTIVITY_FRIEND: +// +// $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; +// $obj = parse_xml_string($xmlhead.$it['object']); +// $it['fname'] = $obj->title; +// +// $notif_content[] = replace_macros($tpl_item_friends,array( +// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], +// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], +// '$item_image' => $it['author-avatar'], +// '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), +// '$item_when' => relative_date($it['created']) +// )); +// +// break; +// default: +// $notif_content[] = replace_macros($tpl_item_comments,array( +// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], +// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], +// '$item_image' => $it['author-avatar'], +// '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']), +// '$item_when' => relative_date($it['created']) +// )); +// } +// } } else { $notif_nocontent = t('No more home notifications.'); @@ -505,6 +525,9 @@ function notifications_content(&$a) { } + if(count($notifs['notifications']) > 0 ) + $notif_content = format_notifiations ($a, $notifs); + $o .= replace_macros($notif_tpl, array( '$notif_header' => $notif_header, '$tabs' => $tabs, @@ -512,6 +535,7 @@ function notifications_content(&$a) { '$notif_nocontent' => $notif_nocontent, '$notif_ignored_lnk' => $notif_ignored_lnk, )); + $o .= paginate($a); return $o; } @@ -561,4 +585,126 @@ function notifications_tabs($a) { ); return $tabs; +} + +function format_notifiations(&$a, $notifs) { + + $notif_content = array(); + + // The template files we need in different cases for formatting the content + $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); + $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); + $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); + $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); + $tpl_item_posts = get_markup_template('notifications_posts_item.tpl'); + $tpl_notify = get_markup_template('notify.tpl'); + + if (count($notifs['notifications']) > 0) { +// switch ($notifs['ident']) { +// case 'system': +// $default_item_link = app::get_baseurl(true).'/notify/view/'. $it['id']; +// $default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO); +// $default_item_text = strip_tags(bbcode($it['msg'])); +// $default_item_when = relative_date($it['date']); +// $default_tpl = $tpl_notify; +// break; +// +// case 'home': +// $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; +// $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); +// $default_item_text = sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']); +// $default_item_when = relative_date($it['created']); +// $default_tpl = $tpl_item_comments; +// break; +// +// default: +// $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; +// $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); +// $default_item_text = (($it['id'] == $it['parent']) +// ? sprintf( t("%s created a new post"), $it['author-name']) +// : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); +// $default_item_when = relative_date($it['created']); +// $default_tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); +// +// } + + foreach ($notifs['notifications'] as $it) { + + switch ($notifs['ident']) { + case 'system': + $default_item_link = app::get_baseurl(true).'notify/view/'. $it['id']; + $default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO); + $default_item_text = strip_tags(bbcode($it['msg'])); + $default_item_when = relative_date($it['date']); + $default_tpl = $tpl_notify; + break; + + case 'home': + $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; + $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); + $default_item_text = sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']); + $default_item_when = relative_date($it['created']); + $default_tpl = $tpl_item_comments; + break; + + default: + $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; + $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); + $default_item_text = (($it['id'] == $it['parent']) + ? sprintf( t("%s created a new post"), $it['author-name']) + : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); + $default_item_when = relative_date($it['created']); + $default_tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); + + } + + switch($it['verb']){ + case ACTIVITY_LIKE: + $notif_content[] = replace_macros($tpl_item_likes,array( + //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], + '$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], + '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), + '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), + '$item_when' => relative_date($it['created']) + )); + break; + + case ACTIVITY_DISLIKE: + $notif_content[] = replace_macros($tpl_item_dislikes,array( + //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], + '$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], + '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), + '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), + '$item_when' => relative_date($it['created']) + )); + break; + + case ACTIVITY_FRIEND: + $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; + $obj = parse_xml_string($xmlhead.$it['object']); + $it['fname'] = $obj->title; + + $notif_content[] = replace_macros($tpl_item_friends,array( + //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], + '$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], + '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), + '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), + '$item_when' => relative_date($it['created']) + )); + break; + + default: + $notif_content[] = replace_macros($default_tpl,array( + //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], + '$item_link' => $default_item_link, + '$item_image' => $default_item_image, + '$item_text' => $default_item_text, + '$item_when' => $default_item_when + )); + } + } + } + + return $notif_content; + } \ No newline at end of file From 52f641904bab4c79c1138e237f3de8eb6864839a Mon Sep 17 00:00:00 2001 From: trebor Date: Sat, 30 Jul 2016 10:51:21 +0200 Subject: [PATCH 02/10] notifications.php: reduce code duplication --- include/NotificationsManager.php | 380 ++++++++++++++++++++++--------- mod/notifications.php | 175 +------------- 2 files changed, 279 insertions(+), 276 deletions(-) diff --git a/include/NotificationsManager.php b/include/NotificationsManager.php index 5f8211eb87..cbf8986d09 100644 --- a/include/NotificationsManager.php +++ b/include/NotificationsManager.php @@ -10,12 +10,12 @@ require_once("include/bbcode.php"); * @brief Read and write notifications from/to database */ class NotificationsManager { - private $a; - - public function __construct() { - $this->a = get_app(); - } - + private $a; + + public function __construct() { + $this->a = get_app(); + } + /** * @brief set some extra note properties * @@ -28,109 +28,279 @@ class NotificationsManager { * - msg_html: message as html string * - msg_plain: message as plain text string */ - private function _set_extra($notes) { - $rets = array(); - foreach($notes as $n) { - $local_time = datetime_convert('UTC',date_default_timezone_get(),$n['date']); - $n['timestamp'] = strtotime($local_time); - $n['date_rel'] = relative_date($n['date']); - $n['msg_html'] = bbcode($n['msg'], false, false, false, false); - $n['msg_plain'] = explode("\n",trim(html2plain($n['msg_html'], 0)))[0]; - - $rets[] = $n; - } - return $rets; - } + private function _set_extra($notes) { + $rets = array(); + foreach($notes as $n) { + $local_time = datetime_convert('UTC',date_default_timezone_get(),$n['date']); + $n['timestamp'] = strtotime($local_time); + $n['date_rel'] = relative_date($n['date']); + $n['msg_html'] = bbcode($n['msg'], false, false, false, false); + $n['msg_plain'] = explode("\n",trim(html2plain($n['msg_html'], 0)))[0]; + + $rets[] = $n; + } + return $rets; + } - /** - * @brief get all notifications for local_user() - * - * @param array $filter optional Array "column name"=>value: filter query by columns values - * @param string $order optional Space separated list of column to sort by. prepend name with "+" to sort ASC, "-" to sort DESC. Default to "-date" - * @param string $limit optional Query limits - * - * @return array of results or false on errors - */ - public function getAll($filter = array(), $order="-date", $limit="") { - $filter_str = array(); - $filter_sql = ""; - foreach($filter as $column => $value) { - $filter_str[] = sprintf("`%s` = '%s'", $column, dbesc($value)); - } - if (count($filter_str)>0) { - $filter_sql = "AND ".implode(" AND ", $filter_str); - } - - $aOrder = explode(" ", $order); - $asOrder = array(); - foreach($aOrder as $o) { - $dir = "asc"; - if ($o[0]==="-") { - $dir = "desc"; - $o = substr($o,1); - } - if ($o[0]==="+") { - $dir = "asc"; - $o = substr($o,1); - } - $asOrder[] = "$o $dir"; - } - $order_sql = implode(", ", $asOrder); - - if ($limit!="") $limit = " LIMIT ".$limit; - - $r = q("SELECT * FROM `notify` WHERE `uid` = %d $filter_sql ORDER BY $order_sql $limit", + /** + * @brief get all notifications for local_user() + * + * @param array $filter optional Array "column name"=>value: filter query by columns values + * @param string $order optional Space separated list of column to sort by. prepend name with "+" to sort ASC, "-" to sort DESC. Default to "-date" + * @param string $limit optional Query limits + * + * @return array of results or false on errors + */ + public function getAll($filter = array(), $order="-date", $limit="") { + $filter_str = array(); + $filter_sql = ""; + foreach($filter as $column => $value) { + $filter_str[] = sprintf("`%s` = '%s'", $column, dbesc($value)); + } + if (count($filter_str)>0) { + $filter_sql = "AND ".implode(" AND ", $filter_str); + } + + $aOrder = explode(" ", $order); + $asOrder = array(); + foreach($aOrder as $o) { + $dir = "asc"; + if ($o[0]==="-") { + $dir = "desc"; + $o = substr($o,1); + } + if ($o[0]==="+") { + $dir = "asc"; + $o = substr($o,1); + } + $asOrder[] = "$o $dir"; + } + $order_sql = implode(", ", $asOrder); + + if ($limit!="") $limit = " LIMIT ".$limit; + + $r = q("SELECT * FROM `notify` WHERE `uid` = %d $filter_sql ORDER BY $order_sql $limit", + intval(local_user()) + ); + if ($r!==false && count($r)>0) return $this->_set_extra($r); + return false; + } + + /** + * @brief get one note for local_user() by $id value + * + * @param int $id + * @return array note values or null if not found + */ + public function getByID($id) { + $r = q("SELECT * FROM `notify` WHERE `id` = %d AND `uid` = %d LIMIT 1", + intval($id), intval(local_user()) ); - if ($r!==false && count($r)>0) return $this->_set_extra($r); - return false; - } - - /** - * @brief get one note for local_user() by $id value - * - * @param int $id - * @return array note values or null if not found - */ - public function getByID($id) { - $r = q("SELECT * FROM `notify` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($id), - intval(local_user()) - ); - if($r!==false && count($r)>0) { - return $this->_set_extra($r)[0]; - } - return null; - } - - /** - * @brief set seen state of $note of local_user() - * - * @param array $note - * @param bool $seen optional true or false, default true - * @return bool true on success, false on errors - */ - public function setSeen($note, $seen = true) { - return q("UPDATE `notify` SET `seen` = %d WHERE ( `link` = '%s' OR ( `parent` != 0 AND `parent` = %d AND `otype` = '%s' )) AND `uid` = %d", - intval($seen), - dbesc($note['link']), - intval($note['parent']), - dbesc($note['otype']), - intval(local_user()) - ); - } - - /** - * @brief set seen state of all notifications of local_user() - * - * @param bool $seen optional true or false. default true - * @return bool true on success, false on error - */ - public function setAllSeen($seen = true) { - return q("UPDATE `notify` SET `seen` = %d WHERE `uid` = %d", - intval($seen), + if($r!==false && count($r)>0) { + return $this->_set_extra($r)[0]; + } + return null; + } + + /** + * @brief set seen state of $note of local_user() + * + * @param array $note + * @param bool $seen optional true or false, default true + * @return bool true on success, false on errors + */ + public function setSeen($note, $seen = true) { + return q("UPDATE `notify` SET `seen` = %d WHERE ( `link` = '%s' OR ( `parent` != 0 AND `parent` = %d AND `otype` = '%s' )) AND `uid` = %d", + intval($seen), + dbesc($note['link']), + intval($note['parent']), + dbesc($note['otype']), intval(local_user()) ); - } + } + + /** + * @brief set seen state of all notifications of local_user() + * + * @param bool $seen optional true or false. default true + * @return bool true on success, false on error + */ + public function setAllSeen($seen = true) { + return q("UPDATE `notify` SET `seen` = %d WHERE `uid` = %d", + intval($seen), + intval(local_user()) + ); + } + + /** + * @brief List of pages for the Notifications TabBar + * + * @param app $a The + * @return array with with notifications TabBar data + */ + public function getTabs() { + $tabs = array( + array( + 'label' => t('System'), + 'url'=>'notifications/system', + 'sel'=> (($this->a->argv[1] == 'system') ? 'active' : ''), + 'accesskey' => 'y', + ), + array( + 'label' => t('Network'), + 'url'=>'notifications/network', + 'sel'=> (($this->a->argv[1] == 'network') ? 'active' : ''), + 'accesskey' => 'w', + ), + array( + 'label' => t('Personal'), + 'url'=>'notifications/personal', + 'sel'=> (($this->a->argv[1] == 'personal') ? 'active' : ''), + 'accesskey' => 'r', + ), + array( + 'label' => t('Home'), + 'url' => 'notifications/home', + 'sel'=> (($this->a->argv[1] == 'home') ? 'active' : ''), + 'accesskey' => 'h', + ), + array( + 'label' => t('Introductions'), + 'url' => 'notifications/intros', + 'sel'=> (($this->a->argv[1] == 'intros') ? 'active' : ''), + 'accesskey' => 'i', + ), + /*array( + 'label' => t('Messages'), + 'url' => 'message', + 'sel'=> '', + ),*/ /*while I can have notifications for messages, this tablist is not place for message page link */ + ); + + return $tabs; + } + + public function format($notifs) { + + $notif_content = array(); + + // The template files we need in different cases for formatting the content + $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); + $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); + $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); + $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); + $tpl_item_posts = get_markup_template('notifications_posts_item.tpl'); + $tpl_notify = get_markup_template('notify.tpl'); + + if (count($notifs['notifications']) > 0) { + // switch ($notifs['ident']) { + // case 'system': + // $default_item_link = app::get_baseurl(true).'/notify/view/'. $it['id']; + // $default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO); + // $default_item_text = strip_tags(bbcode($it['msg'])); + // $default_item_when = relative_date($it['date']); + // $default_tpl = $tpl_notify; + // break; + // + // case 'home': + // $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; + // $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); + // $default_item_text = sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']); + // $default_item_when = relative_date($it['created']); + // $default_tpl = $tpl_item_comments; + // break; + // + // default: + // $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; + // $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); + // $default_item_text = (($it['id'] == $it['parent']) + // ? sprintf( t("%s created a new post"), $it['author-name']) + // : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); + // $default_item_when = relative_date($it['created']); + // $default_tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); + // + // } + + foreach ($notifs['notifications'] as $it) { + + switch ($notifs['ident']) { + case 'system': + $default_item_link = app::get_baseurl(true).'/notify/view/'. $it['id']; + $default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO); + $default_item_text = strip_tags(bbcode($it['msg'])); + $default_item_when = relative_date($it['date']); + $default_tpl = $tpl_notify; + break; + + case 'home': + $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; + $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); + $default_item_text = sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']); + $default_item_when = relative_date($it['created']); + $default_tpl = $tpl_item_comments; + break; + + default: + $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; + $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); + $default_item_text = (($it['id'] == $it['parent']) + ? sprintf( t("%s created a new post"), $it['author-name']) + : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); + $default_item_when = relative_date($it['created']); + $default_tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); + + } + + switch($it['verb']){ + case ACTIVITY_LIKE: + $notif_content[] = replace_macros($tpl_item_likes,array( + //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], + '$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], + '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), + '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), + '$item_when' => relative_date($it['created']) + )); + break; + + case ACTIVITY_DISLIKE: + $notif_content[] = replace_macros($tpl_item_dislikes,array( + //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], + '$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], + '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), + '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), + '$item_when' => relative_date($it['created']) + )); + break; + + case ACTIVITY_FRIEND: + $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; + $obj = parse_xml_string($xmlhead.$it['object']); + $it['fname'] = $obj->title; + + $notif_content[] = replace_macros($tpl_item_friends,array( + //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], + '$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], + '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), + '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), + '$item_when' => relative_date($it['created']) + )); + break; + + default: + $notif_content[] = replace_macros($default_tpl,array( + //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], + '$item_link' => $default_item_link, + '$item_image' => $default_item_image, + '$item_text' => $default_item_text, + '$item_when' => $default_item_when + )); + } + } + } + + return $notif_content; + + } } diff --git a/mod/notifications.php b/mod/notifications.php index ae4c97f83a..5a1ef51ca7 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -1,4 +1,5 @@ argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false); + $nm = new NotificationsManager(); $o = ''; // get the nav tabs for the notification pages - $tabs = notifications_tabs($a); + $tabs = $nm->getTabs(); $notif_content = array(); if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) { @@ -526,7 +528,7 @@ function notifications_content(&$a) { } if(count($notifs['notifications']) > 0 ) - $notif_content = format_notifiations ($a, $notifs); + $notif_content =$nm->format ($notifs); $o .= replace_macros($notif_tpl, array( '$notif_header' => $notif_header, @@ -539,172 +541,3 @@ function notifications_content(&$a) { $o .= paginate($a); return $o; } -/** - * @brief List of pages for the Notifications TabBar - * - * @param app $a The - * @return array with with notifications TabBar data - */ -function notifications_tabs($a) { - $tabs = array( - array( - 'label' => t('System'), - 'url'=>'notifications/system', - 'sel'=> (($a->argv[1] == 'system') ? 'active' : ''), - 'accesskey' => 'y', - ), - array( - 'label' => t('Network'), - 'url'=>'notifications/network', - 'sel'=> (($a->argv[1] == 'network') ? 'active' : ''), - 'accesskey' => 'w', - ), - array( - 'label' => t('Personal'), - 'url'=>'notifications/personal', - 'sel'=> (($a->argv[1] == 'personal') ? 'active' : ''), - 'accesskey' => 'r', - ), - array( - 'label' => t('Home'), - 'url' => 'notifications/home', - 'sel'=> (($a->argv[1] == 'home') ? 'active' : ''), - 'accesskey' => 'h', - ), - array( - 'label' => t('Introductions'), - 'url' => 'notifications/intros', - 'sel'=> (($a->argv[1] == 'intros') ? 'active' : ''), - 'accesskey' => 'i', - ), - /*array( - 'label' => t('Messages'), - 'url' => 'message', - 'sel'=> '', - ),*/ /*while I can have notifications for messages, this tablist is not place for message page link */ - ); - - return $tabs; -} - -function format_notifiations(&$a, $notifs) { - - $notif_content = array(); - - // The template files we need in different cases for formatting the content - $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); - $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); - $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); - $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); - $tpl_item_posts = get_markup_template('notifications_posts_item.tpl'); - $tpl_notify = get_markup_template('notify.tpl'); - - if (count($notifs['notifications']) > 0) { -// switch ($notifs['ident']) { -// case 'system': -// $default_item_link = app::get_baseurl(true).'/notify/view/'. $it['id']; -// $default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO); -// $default_item_text = strip_tags(bbcode($it['msg'])); -// $default_item_when = relative_date($it['date']); -// $default_tpl = $tpl_notify; -// break; -// -// case 'home': -// $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; -// $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); -// $default_item_text = sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']); -// $default_item_when = relative_date($it['created']); -// $default_tpl = $tpl_item_comments; -// break; -// -// default: -// $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; -// $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); -// $default_item_text = (($it['id'] == $it['parent']) -// ? sprintf( t("%s created a new post"), $it['author-name']) -// : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); -// $default_item_when = relative_date($it['created']); -// $default_tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); -// -// } - - foreach ($notifs['notifications'] as $it) { - - switch ($notifs['ident']) { - case 'system': - $default_item_link = app::get_baseurl(true).'notify/view/'. $it['id']; - $default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO); - $default_item_text = strip_tags(bbcode($it['msg'])); - $default_item_when = relative_date($it['date']); - $default_tpl = $tpl_notify; - break; - - case 'home': - $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; - $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); - $default_item_text = sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']); - $default_item_when = relative_date($it['created']); - $default_tpl = $tpl_item_comments; - break; - - default: - $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; - $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); - $default_item_text = (($it['id'] == $it['parent']) - ? sprintf( t("%s created a new post"), $it['author-name']) - : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); - $default_item_when = relative_date($it['created']); - $default_tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); - - } - - switch($it['verb']){ - case ACTIVITY_LIKE: - $notif_content[] = replace_macros($tpl_item_likes,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), - '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - break; - - case ACTIVITY_DISLIKE: - $notif_content[] = replace_macros($tpl_item_dislikes,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), - '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); - break; - - case ACTIVITY_FRIEND: - $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; - $obj = parse_xml_string($xmlhead.$it['object']); - $it['fname'] = $obj->title; - - $notif_content[] = replace_macros($tpl_item_friends,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), - '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), - '$item_when' => relative_date($it['created']) - )); - break; - - default: - $notif_content[] = replace_macros($default_tpl,array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $default_item_link, - '$item_image' => $default_item_image, - '$item_text' => $default_item_text, - '$item_when' => $default_item_when - )); - } - } - } - - return $notif_content; - -} \ No newline at end of file From 7a4be1cead9c388c7529118cc943eb661b0960bc Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Mon, 1 Aug 2016 18:18:11 +0200 Subject: [PATCH 03/10] notifications.php: move more code to NotificationsManager --- include/NotificationsManager.php | 323 ++++++++++++++---- mod/notifications.php | 321 ++++------------- view/templates/notifications.tpl | 2 +- .../templates/notifications_comments_item.tpl | 2 +- .../templates/notifications_dislikes_item.tpl | 2 +- view/templates/notifications_friends_item.tpl | 2 +- view/templates/notifications_likes_item.tpl | 2 +- view/templates/notifications_network_item.tpl | 2 +- view/templates/notifications_posts_item.tpl | 2 +- view/templates/notify.tpl | 2 +- view/theme/frio/templates/notifications.tpl | 2 +- 11 files changed, 330 insertions(+), 332 deletions(-) diff --git a/include/NotificationsManager.php b/include/NotificationsManager.php index cbf8986d09..09e9c1494e 100644 --- a/include/NotificationsManager.php +++ b/include/NotificationsManager.php @@ -5,6 +5,7 @@ require_once('include/html2plain.php'); require_once("include/datetime.php"); require_once("include/bbcode.php"); +require_once("include/dbm.php"); /** * @brief Read and write notifications from/to database @@ -146,87 +147,56 @@ class NotificationsManager { 'label' => t('System'), 'url'=>'notifications/system', 'sel'=> (($this->a->argv[1] == 'system') ? 'active' : ''), + 'id' => 'system-tab', 'accesskey' => 'y', ), array( 'label' => t('Network'), 'url'=>'notifications/network', 'sel'=> (($this->a->argv[1] == 'network') ? 'active' : ''), + 'id' => 'network-tab', 'accesskey' => 'w', ), array( 'label' => t('Personal'), 'url'=>'notifications/personal', 'sel'=> (($this->a->argv[1] == 'personal') ? 'active' : ''), + 'id' => 'personal-tab', 'accesskey' => 'r', ), array( 'label' => t('Home'), 'url' => 'notifications/home', 'sel'=> (($this->a->argv[1] == 'home') ? 'active' : ''), + 'id' => 'home-tab', 'accesskey' => 'h', ), array( 'label' => t('Introductions'), 'url' => 'notifications/intros', 'sel'=> (($this->a->argv[1] == 'intros') ? 'active' : ''), + 'id' => 'intro-tab', 'accesskey' => 'i', ), - /*array( - 'label' => t('Messages'), - 'url' => 'message', - 'sel'=> '', - ),*/ /*while I can have notifications for messages, this tablist is not place for message page link */ ); return $tabs; } - public function format($notifs) { + public function format($notifs, $ident = "") { - $notif_content = array(); + $notif = array(); + $arr = array(); - // The template files we need in different cases for formatting the content - $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); - $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); - $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); - $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); - $tpl_item_posts = get_markup_template('notifications_posts_item.tpl'); - $tpl_notify = get_markup_template('notify.tpl'); + if (dbm::is_result($notifs)) { - if (count($notifs['notifications']) > 0) { - // switch ($notifs['ident']) { - // case 'system': - // $default_item_link = app::get_baseurl(true).'/notify/view/'. $it['id']; - // $default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO); - // $default_item_text = strip_tags(bbcode($it['msg'])); - // $default_item_when = relative_date($it['date']); - // $default_tpl = $tpl_notify; - // break; - // - // case 'home': - // $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; - // $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); - // $default_item_text = sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']); - // $default_item_when = relative_date($it['created']); - // $default_tpl = $tpl_item_comments; - // break; - // - // default: - // $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; - // $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); - // $default_item_text = (($it['id'] == $it['parent']) - // ? sprintf( t("%s created a new post"), $it['author-name']) - // : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); - // $default_item_when = relative_date($it['created']); - // $default_tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); - // - // } + foreach ($notifs as $it) { + if($it['unseen']) + $it['seen'] = ($it['unseen'] > 0 ? false : true); - foreach ($notifs['notifications'] as $it) { - - switch ($notifs['ident']) { + switch ($ident) { case 'system': + $default_item_label = 'notify'; $default_item_link = app::get_baseurl(true).'/notify/view/'. $it['id']; $default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO); $default_item_text = strip_tags(bbcode($it['msg'])); @@ -235,6 +205,7 @@ class NotificationsManager { break; case 'home': + $default_item_label = 'comment'; $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); $default_item_text = sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']); @@ -243,6 +214,7 @@ class NotificationsManager { break; default: + $default_item_label = (($it['id'] == $it['parent']) ? 'post' : 'comment'); $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); $default_item_text = (($it['id'] == $it['parent']) @@ -255,23 +227,27 @@ class NotificationsManager { switch($it['verb']){ case ACTIVITY_LIKE: - $notif_content[] = replace_macros($tpl_item_likes,array( + $notif = array( //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), - '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); + 'label' => 'like', + 'link' => app::get_baseurl(true).'/display/'.$it['pguid'], + '$image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), + 'text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), + 'when' => relative_date($it['created']), + 'seen' => $it['seen'] + ); break; case ACTIVITY_DISLIKE: - $notif_content[] = replace_macros($tpl_item_dislikes,array( + $notif = array( //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), - '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), - '$item_when' => relative_date($it['created']) - )); + 'label' => 'dislike', + 'link' => app::get_baseurl(true).'/display/'.$it['pguid'], + 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), + 'text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), + 'when' => relative_date($it['created']), + 'seen' => $it['seen'] + ); break; case ACTIVITY_FRIEND: @@ -279,28 +255,235 @@ class NotificationsManager { $obj = parse_xml_string($xmlhead.$it['object']); $it['fname'] = $obj->title; - $notif_content[] = replace_macros($tpl_item_friends,array( + $notif = array( //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], - '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), - '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), - '$item_when' => relative_date($it['created']) - )); + 'label' => 'friend', + 'link' => app::get_baseurl(true).'/display/'.$it['pguid'], + 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), + 'text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), + 'when' => relative_date($it['created']), + 'seen' => $it['seen'] + ); break; default: - $notif_content[] = replace_macros($default_tpl,array( + $notif = array( //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], - '$item_link' => $default_item_link, - '$item_image' => $default_item_image, - '$item_text' => $default_item_text, - '$item_when' => $default_item_when - )); + 'label' => $default_item_label, + 'link' => $default_item_link, + 'image' => $default_item_image, + 'text' => $default_item_text, + 'when' => $default_item_when, + 'seen' => $it['seen'] + ); } + + $arr[] = $notif; } } - return $notif_content; + return $arr; } + + private function networkTotal($seen = 0) { + if($seen === 0) + $sql_seen = " AND `item`.`unseen` = 1 "; + + $r = q("SELECT COUNT(*) AS `total` + FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent` + WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND + `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 + $sql_seen", + intval(local_user()) + ); + + if(dbm::is_result($r)) + return $r[0]['total']; + + return 0; + } + + public function networkNotifs($seen = 0) { + $ident = 'network'; + $total = $this->networkTotal($seen); + + if($seen === 0) + $sql_seen = " AND `item`.`unseen` = 1 "; + + + $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`, + `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`, + `pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid` + FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent` + WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND + `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 + $sql_seen + ORDER BY `item`.`created` DESC", + intval(local_user()) + ); + + if(dbm::is_result($r)) { + $notifs = $this->format($r, $ident); + $arr = array ( + 'notifications' => $notifs, + 'ident' => $ident, + 'total' => $total, + ); + + return $arr; + } + } + + private function systemTotal($seen = 0) { + if($seen === 0) + $sql_seen = " AND `seen` = 0 "; + + $r = q("SELECT COUNT(*) AS `total` FROM `notify` WHERE `uid` = %d $sql_seen", + intval(local_user()) + ); + + if(dbm::is_result($r)) + return $r[0]['total']; + + return 0; + } + + public function systemNotifs($seen = 0) { + $ident = 'system'; + $total = $this->systemTotal($seen); + + if($seen === 0) + $sql_seen = " AND `seen` = 0 "; + + $r = q("SELECT * FROM `notify` WHERE `uid` = %d $sql_seen ORDER BY `date` DESC", + intval(local_user()) + ); + + if(dbm::is_result($r)) { + $notifs = $this->format($r, $ident); + $arr = array ( + 'notifications' => $notifs, + 'ident' => $ident, + 'total' => $total, + ); + + return $arr; + } + } + + private function _personal_sql_extra() { + $myurl = app::get_baseurl(true) . '/profile/'. $this->a->user['nickname']; + $myurl = substr($myurl,strpos($myurl,'://')+3); + $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl); + $diasp_url = str_replace('/profile/','/u/',$myurl); + $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ", + dbesc($myurl . '$'), + dbesc($myurl . '\\]'), + dbesc($diasp_url . '\\]') + ); + + return $sql_extra; + } + + private function personalTotal($seen = 0) { + $sql_extra .= $this->_personal_sql_extra(); + + if($seen === 0) + $sql_seen = " AND `item`.`unseen` = 1 "; + + $r = q("SELECT COUNT(*) AS `total` + FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent` + WHERE `item`.`visible` = 1 + $sql_extra + $sql_seen + AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 " , + intval(local_user()) + ); + + if(dbm::is_result($r)) + return $r[0]['total']; + + return 0; + } + public function personalNotifs($seen = 0) { + $ident = 'personal'; + $total = 0; + $sql_extra .= $this->_personal_sql_extra(); + + if($seen === 0) + $sql_seen = " AND `item`.`unseen` = 1 "; + + $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`, + `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`, + `pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`, + FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent` + WHERE `item`.`visible` = 1 + $sql_extra + $sql_seen + AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 + ORDER BY `item`.`created` DESC" , + intval(local_user()) + ); + + if(dbm::is_result($r)) { + $notifs = $this->format($r, $ident); + $arr = array ( + 'notifications' => $notifs, + 'ident' => $ident, + 'total' => $total, + ); + + return $arr; + } + } + + private function homeTotal($seen = 0) { + if($seen === 0) + $sql_seen = " AND `item`.`unseen` = 1 "; + + $r = q("SELECT COUNT(*) AS `total` FROM `item` + WHERE ``item`.`visible` = 1 AND + `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 + $sql_seen", + intval(local_user()) + ); + + if(dbm::is_result($r)) + return $r['total']; + + return 0; + } + + public function homeNotifs($seen = 0) { + $ident = 'home'; + $total = $this->homeTotal($seen); + + if($seen === 0) + $sql_seen = " AND `item`.`unseen` = 1 "; + + $total = $this->homeTotal($seen); + + $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`, + `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`, + `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid` + FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent` + WHERE `item`.`visible` = 1 AND + `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 + $sql_seen + ORDER BY `item`.`created` DESC", + intval(local_user()) + ); + + if(dbm::is_result($r)) { + $notifs = $this->format($r, $ident); + $arr = array ( + 'notifications' => $notifs, + 'ident' => $ident, + 'total' => $total, + ); + + return $arr; + } + } } diff --git a/mod/notifications.php b/mod/notifications.php index 5a1ef51ca7..faf7651914 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -67,6 +67,7 @@ function notifications_content(&$a) { return; } + $show = (x($_REQUEST,'show') ? $_REQUEST['show'] : 0); nav_set_selected('notifications'); $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false); @@ -89,14 +90,20 @@ function notifications_content(&$a) { $notif_header = t('Notifications'); $notif_tpl = get_markup_template('notifications.tpl'); - $notif_ignored_lnk .= '' - . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '' . "\r\n"; +// $notif_show_lnk .= '' +// . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '' . "\r\n"; - $r = q("SELECT COUNT(*) AS `total` FROM `intro` + $notif_show_lnk = array( + 'href' => ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ), + 'text' => ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')), + 'id' => "notifications-show-hide-link", + ); + + $r = q("SELECT COUNT(*) AS `total` FROM `intro` WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ", intval($_SESSION['uid']) ); - if($r && count($r)) { + if(dbm::is_result($r)) { $a->set_pager_total($r[0]['total']); $a->set_pager_itemspage(20); } @@ -114,7 +121,7 @@ function notifications_content(&$a) { WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ", intval($_SESSION['uid'])); - if(($r !== false) && (count($r))) { + if(dbm::is_result($r)) { $sugg = get_markup_template('suggestions.tpl'); $tpl = get_markup_template("intros.tpl"); @@ -240,82 +247,16 @@ function notifications_content(&$a) { $notif_header = t('Network Notifications'); $notif_tpl = get_markup_template('notifications.tpl'); - $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, - `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`, - `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid` - FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent` - WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND - `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" , - intval(local_user()) + $notifs = $nm->networkNotifs($show); + + $notif_show_lnk = array( + 'href' => ($show ? 'notifications/network' : 'notifications/network?show=all' ), + 'text' => ($show ? t('Show unread') : t('Show all')), ); -// $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); -// $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); -// $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); -// $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); -// $tpl_item_posts = get_markup_template('notifications_posts_item.tpl'); - - if ($r) { - - $notifs = array( - 'notifications' => $r, - 'ident' => 'network', - ); - -// foreach ($r as $it) { -// switch($it['verb']){ -// case ACTIVITY_LIKE: -// $notif_content[] = replace_macros($tpl_item_likes,array( -// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], -// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], -// '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), -// '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), -// '$item_when' => relative_date($it['created']) -// )); -// break; -// -// case ACTIVITY_DISLIKE: -// $notif_content[] = replace_macros($tpl_item_dislikes,array( -// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], -// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], -// '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), -// '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), -// '$item_when' => relative_date($it['created']) -// )); -// break; -// -// case ACTIVITY_FRIEND: -// -// $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; -// $obj = parse_xml_string($xmlhead.$it['object']); -// $it['fname'] = $obj->title; -// -// $notif_content[] = replace_macros($tpl_item_friends,array( -// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], -// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], -// '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), -// '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), -// '$item_when' => relative_date($it['created']) -// )); -// break; -// -// default: -// $item_text = (($it['id'] == $it['parent']) -// ? sprintf( t("%s created a new post"), $it['author-name']) -// : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); -// $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); -// -// $notif_content[] = replace_macros($tpl,array( -// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], -// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], -// '$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), -// '$item_text' => $item_text, -// '$item_when' => relative_date($it['created']) -// )); -// } -// } - - } else { + if(!dbm::is_result($notifs)) { + if($show) + $notif_show_lnk = array(); $notif_nocontent = t('No more network notifications.'); } @@ -325,28 +266,17 @@ function notifications_content(&$a) { $notif_header = t('System Notifications'); $notif_tpl = get_markup_template('notifications.tpl'); - $not_tpl = get_markup_template('notify.tpl'); - require_once('include/bbcode.php'); + $notifs = $nm->systemNotifs($show); - $r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc", - intval(local_user()) + $notif_show_lnk = array( + 'href' => ($show ? 'notifications/system' : 'notifications/system?show=all' ), + 'text' => ($show ? t('Show unread') : t('Show all')), ); - if (count($r) > 0) { -// foreach ($r as $it) { -// $notif_content[] = replace_macros($not_tpl,array( -// '$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'], -// '$item_image' => proxy_url($it['photo'], false, PROXY_SIZE_MICRO), -// '$item_text' => strip_tags(bbcode($it['msg'])), -// '$item_when' => relative_date($it['date']) -// )); -// } - $notifs = array( - 'notifications' => $r, - 'ident' => 'system', - ); + if(!dbm::is_result($notifs)) { + if($show) + $notif_show_lnk = array(); - } else { $notif_nocontent = t('No more system notifications.'); } @@ -355,94 +285,16 @@ function notifications_content(&$a) { $notif_header = t('Personal Notifications'); $notif_tpl = get_markup_template('notifications.tpl'); - $myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname']; - $myurl = substr($myurl,strpos($myurl,'://')+3); - $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl); - $diasp_url = str_replace('/profile/','/u/',$myurl); - $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ", - dbesc($myurl . '$'), - dbesc($myurl . '\\]'), - dbesc($diasp_url . '\\]') + $notifs = $nm->personalNotifs($show); + + $notif_show_lnk = array( + 'href' => ($show ? 'notifications/personal' : 'notifications/personal?show=all' ), + 'text' => ($show ? t('Show unread') : t('Show all')), ); - - $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, - `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`, - `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid` - FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent` - WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 - $sql_extra - AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 ORDER BY `item`.`created` DESC" , - intval(local_user()) - ); - -// $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); -// $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); -// $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); -// $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); -// $tpl_item_posts = get_markup_template('notifications_posts_item.tpl'); - - if (count($r) > 0) { - $notifs =array( - 'notifications' => $r, - 'ident' => 'personal' - ); - - -// foreach ($r as $it) { -// switch($it['verb']){ -// case ACTIVITY_LIKE: -// $notif_content[] = replace_macros($tpl_item_likes,array( -// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], -// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], -// '$item_image' => $it['author-avatar'], -// '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), -// '$item_when' => relative_date($it['created']) -// )); -// break; -// -// case ACTIVITY_DISLIKE: -// $notif_content[] = replace_macros($tpl_item_dislikes,array( -// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], -// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], -// '$item_image' => $it['author-avatar'], -// '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), -// '$item_when' => relative_date($it['created']) -// )); -// break; -// -// case ACTIVITY_FRIEND: -// -// $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; -// $obj = parse_xml_string($xmlhead.$it['object']); -// $it['fname'] = $obj->title; -// -// $notif_content[] = replace_macros($tpl_item_friends,array( -// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], -// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], -// '$item_image' => $it['author-avatar'], -// '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), -// '$item_when' => relative_date($it['created']) -// )); -// break; -// -// default: -// $item_text = (($it['id'] == $it['parent']) -// ? sprintf( t("%s created a new post"), $it['author-name']) -// : sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname'])); -// $tpl = (($it['id'] == $it['parent']) ? $tpl_item_posts : $tpl_item_comments); -// -// $notif_content[] = replace_macros($tpl,array( -// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], -// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], -// '$item_image' => $it['author-avatar'], -// '$item_text' => $item_text, -// '$item_when' => relative_date($it['created']) -// )); -// } -// } - - } else { + if(!dbm::is_result($notifs)) { + if($show) + $notif_show_lnk = array(); $notif_nocontent = t('No more personal notifications.'); } @@ -452,90 +304,53 @@ function notifications_content(&$a) { $notif_header = t('Home Notifications'); $notif_tpl = get_markup_template('notifications.tpl'); - $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, - `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`, - `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid` - FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent` - WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND - `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC", - intval(local_user()) + $notifs = $nm->homeNotifs($show); + + $notif_show_lnk = array( + 'href' => ($show ? 'notifications/home' : 'notifications/home?show=all' ), + 'text' => ($show ? t('Show unread') : t('Show all')), ); -// $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); -// $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); -// $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); -// $tpl_item_comments = get_markup_template('notifications_comments_item.tpl'); + if(!dbm::is_result($notifs)) { + if($show) + $notif_show_lnk = array(); - if (count($r) > 0) { - - $notifs = array( - 'notifications' => $r, - 'ident' => 'home', - ); - -// foreach ($r as $it) { -// switch($it['verb']){ -// case ACTIVITY_LIKE: -// $notif_content[] = replace_macros($tpl_item_likes,array( -// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], -// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], -// '$item_image' => $it['author-avatar'], -// '$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), -// '$item_when' => relative_date($it['created']) -// )); -// -// break; -// case ACTIVITY_DISLIKE: -// $notif_content[] = replace_macros($tpl_item_dislikes,array( -// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], -// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], -// '$item_image' => $it['author-avatar'], -// '$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), -// '$item_when' => relative_date($it['created']) -// )); -// -// break; -// case ACTIVITY_FRIEND: -// -// $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; -// $obj = parse_xml_string($xmlhead.$it['object']); -// $it['fname'] = $obj->title; -// -// $notif_content[] = replace_macros($tpl_item_friends,array( -// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], -// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], -// '$item_image' => $it['author-avatar'], -// '$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), -// '$item_when' => relative_date($it['created']) -// )); -// -// break; -// default: -// $notif_content[] = replace_macros($tpl_item_comments,array( -// //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], -// '$item_link' => $a->get_baseurl(true).'/display/'.$it['pguid'], -// '$item_image' => $it['author-avatar'], -// '$item_text' => sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']), -// '$item_when' => relative_date($it['created']) -// )); -// } -// } - - } else { $notif_nocontent = t('No more home notifications.'); } } - if(count($notifs['notifications']) > 0 ) - $notif_content =$nm->format ($notifs); + if(count($notifs['notifications']) > 0 ) { + // The template files we need in different cases for formatting the content + $tpl_item_like = 'notifications_likes_item.tpl'; + $tpl_item_dislike = 'notifications_dislikes_item.tpl'; + $tpl_item_friend = 'notifications_friends_item.tpl'; + $tpl_item_comment = 'notifications_comments_item.tpl'; + $tpl_item_post = 'notifications_posts_item.tpl'; + $tpl_item_notify = 'notify.tpl'; + + foreach ($notifs['notifications'] as $it) { + $tplname = 'tpl_item_'.$it['label']; + $templ = get_markup_template($$tplname); + + $notif_content[] = replace_macros($templ,array( + '$item_label' => $it['label'], + '$item_link' => $it['link'], + '$item_image' => $it['image'], + '$item_text' => $it['text'], + '$item_when' => $it['when'], + '$item_seen' => $it['seen'], + )); + } + + } $o .= replace_macros($notif_tpl, array( '$notif_header' => $notif_header, '$tabs' => $tabs, '$notif_content' => $notif_content, '$notif_nocontent' => $notif_nocontent, - '$notif_ignored_lnk' => $notif_ignored_lnk, + '$notif_show_lnk' => $notif_show_lnk, )); $o .= paginate($a); diff --git a/view/templates/notifications.tpl b/view/templates/notifications.tpl index 9c671c2a5b..4048cfa46b 100644 --- a/view/templates/notifications.tpl +++ b/view/templates/notifications.tpl @@ -6,7 +6,7 @@
{{* The "show ignored" link *}} - {{if $notif_ignored_lnk}}{{$notif_ignored_lnk}}{{/if}} + {{if $notif_show_lnk}}{{$notif_show_lnk.text}}{{/if}} {{* The notifications *}} {{if $notif_content}} diff --git a/view/templates/notifications_comments_item.tpl b/view/templates/notifications_comments_item.tpl index a578941706..dfa15df280 100644 --- a/view/templates/notifications_comments_item.tpl +++ b/view/templates/notifications_comments_item.tpl @@ -1,4 +1,4 @@ -
+ \ No newline at end of file diff --git a/view/templates/notifications_dislikes_item.tpl b/view/templates/notifications_dislikes_item.tpl index a578941706..dfa15df280 100644 --- a/view/templates/notifications_dislikes_item.tpl +++ b/view/templates/notifications_dislikes_item.tpl @@ -1,4 +1,4 @@ -
+ \ No newline at end of file diff --git a/view/templates/notifications_friends_item.tpl b/view/templates/notifications_friends_item.tpl index a578941706..dfa15df280 100644 --- a/view/templates/notifications_friends_item.tpl +++ b/view/templates/notifications_friends_item.tpl @@ -1,4 +1,4 @@ -
+ \ No newline at end of file diff --git a/view/templates/notifications_likes_item.tpl b/view/templates/notifications_likes_item.tpl index c2ebbd39e3..6add369cb4 100644 --- a/view/templates/notifications_likes_item.tpl +++ b/view/templates/notifications_likes_item.tpl @@ -1,4 +1,4 @@ -
+ \ No newline at end of file diff --git a/view/templates/notifications_network_item.tpl b/view/templates/notifications_network_item.tpl index bef25326ec..64395a83d0 100644 --- a/view/templates/notifications_network_item.tpl +++ b/view/templates/notifications_network_item.tpl @@ -1,4 +1,4 @@ -
+ diff --git a/view/templates/notifications_posts_item.tpl b/view/templates/notifications_posts_item.tpl index a578941706..dfa15df280 100644 --- a/view/templates/notifications_posts_item.tpl +++ b/view/templates/notifications_posts_item.tpl @@ -1,4 +1,4 @@ -
+ \ No newline at end of file diff --git a/view/templates/notify.tpl b/view/templates/notify.tpl index a578941706..dfa15df280 100644 --- a/view/templates/notify.tpl +++ b/view/templates/notify.tpl @@ -1,4 +1,4 @@ -
+ \ No newline at end of file diff --git a/view/theme/frio/templates/notifications.tpl b/view/theme/frio/templates/notifications.tpl index 3729e6f8c2..5f131bd7ed 100644 --- a/view/theme/frio/templates/notifications.tpl +++ b/view/theme/frio/templates/notifications.tpl @@ -6,7 +6,7 @@
{{* The "show ignored" link *}} - {{if $notif_ignored_lnk}}{{$notif_ignored_lnk}}{{/if}} + {{if $notif_show_lnk}}{{$notif_show_lnk.text}}{{/if}} {{* The notifications *}} {{if $notif_content}} From bcee356f661c02dc6f4d92bd223d293638d30475 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Mon, 1 Aug 2016 23:04:41 +0200 Subject: [PATCH 04/10] notifications - add docu & pagination --- include/NotificationsManager.php | 149 +++++++++++++++++--- mod/notifications.php | 26 ++-- view/templates/notifications.tpl | 3 + view/theme/frio/templates/notifications.tpl | 3 + 4 files changed, 151 insertions(+), 30 deletions(-) diff --git a/include/NotificationsManager.php b/include/NotificationsManager.php index 09e9c1494e..b14e76740b 100644 --- a/include/NotificationsManager.php +++ b/include/NotificationsManager.php @@ -183,7 +183,20 @@ class NotificationsManager { return $tabs; } - public function format($notifs, $ident = "") { + /** + * @brief Format the notification query in an usable array + * + * @param array $notifs The array from the db query + * @param string $ident The notifications identifier (e.g. network) + * @return array + * string 'label' => The type of the notification + * string 'link' => URL to the source + * string 'image' => The avatar image + * string 'text' => The notification text + * string 'when' => Relative date of the notification + * bool 'seen' => Is the notification marked as "seen" + */ + private function format($notifs, $ident = "") { $notif = array(); $arr = array(); @@ -191,13 +204,17 @@ class NotificationsManager { if (dbm::is_result($notifs)) { foreach ($notifs as $it) { + // Because we use different db tables for the notification query + // we have sometimes $it['unseen'] and sometimes $it['seen]. + // So we will have to transform $it['unseen'] if($it['unseen']) $it['seen'] = ($it['unseen'] > 0 ? false : true); + // Depending on the identifier of the notification we need to use different defaults switch ($ident) { case 'system': $default_item_label = 'notify'; - $default_item_link = app::get_baseurl(true).'/notify/view/'. $it['id']; + $default_item_link = $this->a->get_baseurl(true).'/notify/view/'. $it['id']; $default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO); $default_item_text = strip_tags(bbcode($it['msg'])); $default_item_when = relative_date($it['date']); @@ -206,7 +223,7 @@ class NotificationsManager { case 'home': $default_item_label = 'comment'; - $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; + $default_item_link = $this->a->get_baseurl(true).'/display/'.$it['pguid']; $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); $default_item_text = sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']); $default_item_when = relative_date($it['created']); @@ -215,7 +232,7 @@ class NotificationsManager { default: $default_item_label = (($it['id'] == $it['parent']) ? 'post' : 'comment'); - $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; + $default_item_link = $this->a->get_baseurl(true).'/display/'.$it['pguid']; $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); $default_item_text = (($it['id'] == $it['parent']) ? sprintf( t("%s created a new post"), $it['author-name']) @@ -225,12 +242,13 @@ class NotificationsManager { } + // Transform the different types of notification in an usable array switch($it['verb']){ case ACTIVITY_LIKE: $notif = array( //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], 'label' => 'like', - 'link' => app::get_baseurl(true).'/display/'.$it['pguid'], + 'link' => $this->a->get_baseurl(true).'/display/'.$it['pguid'], '$image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), 'text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), 'when' => relative_date($it['created']), @@ -242,7 +260,7 @@ class NotificationsManager { $notif = array( //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], 'label' => 'dislike', - 'link' => app::get_baseurl(true).'/display/'.$it['pguid'], + 'link' => $this->a->get_baseurl(true).'/display/'.$it['pguid'], 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), 'text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), 'when' => relative_date($it['created']), @@ -258,7 +276,7 @@ class NotificationsManager { $notif = array( //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], 'label' => 'friend', - 'link' => app::get_baseurl(true).'/display/'.$it['pguid'], + 'link' => $this->a->get_baseurl(true).'/display/'.$it['pguid'], 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), 'text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), 'when' => relative_date($it['created']), @@ -286,6 +304,13 @@ class NotificationsManager { } + /** + * @brief Total number of network notifications + * @param int $seen + * If 0 only include notifications into the query + * which arn't marked as "seen" into + * @return int Number of network notifications + */ private function networkTotal($seen = 0) { if($seen === 0) $sql_seen = " AND `item`.`unseen` = 1 "; @@ -304,7 +329,18 @@ class NotificationsManager { return 0; } - public function networkNotifs($seen = 0) { + /** + * @brief Get network notifications + * + * @param type $seen + * If 0 only include notifications into the query + * which arn't marked as "seen" into + * @param int $start Start the query at this point + * @param int $limit Maximum number of query results + * + * @return array Query output + */ + public function networkNotifs($seen = 0, $start = 0, $limit = 20) { $ident = 'network'; $total = $this->networkTotal($seen); @@ -319,8 +355,10 @@ class NotificationsManager { WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 $sql_seen - ORDER BY `item`.`created` DESC", - intval(local_user()) + ORDER BY `item`.`created` DESC LIMIT %d, %d ", + intval(local_user()), + intval($start), + intval($limit) ); if(dbm::is_result($r)) { @@ -335,6 +373,13 @@ class NotificationsManager { } } + /** + * @brief Total number of system notifications + * @param int $seen + * If 0 only include notifications into the query + * which arn't marked as "seen" into + * @return int Number of system notifications + */ private function systemTotal($seen = 0) { if($seen === 0) $sql_seen = " AND `seen` = 0 "; @@ -349,15 +394,29 @@ class NotificationsManager { return 0; } - public function systemNotifs($seen = 0) { + /** + * @brief Get system notifications + * + * @param type $seen + * If 0 only include notifications into the query + * which arn't marked as "seen" into + * @param int $start Start the query at this point + * @param int $limit Maximum number of query results + * + * @return array Query output + */ + public function systemNotifs($seen = 0, $start = 0, $limit = 20) { $ident = 'system'; $total = $this->systemTotal($seen); if($seen === 0) $sql_seen = " AND `seen` = 0 "; - $r = q("SELECT * FROM `notify` WHERE `uid` = %d $sql_seen ORDER BY `date` DESC", - intval(local_user()) + $r = q("SELECT `id`, `photo`, `msg`, `date`, `seen` FROM `notify` + WHERE `uid` = %d $sql_seen ORDER BY `date` DESC LIMIT %d, %d ", + intval(local_user()), + intval($start), + intval($limit) ); if(dbm::is_result($r)) { @@ -372,8 +431,13 @@ class NotificationsManager { } } + /** + * @brief Addional SQL query string for the personal notifications + * + * @return string The additional sql query + */ private function _personal_sql_extra() { - $myurl = app::get_baseurl(true) . '/profile/'. $this->a->user['nickname']; + $myurl = $this->a->get_baseurl(true) . '/profile/'. $this->a->user['nickname']; $myurl = substr($myurl,strpos($myurl,'://')+3); $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl); $diasp_url = str_replace('/profile/','/u/',$myurl); @@ -386,6 +450,13 @@ class NotificationsManager { return $sql_extra; } + /** + * @brief Total number of personal notifications + * @param int $seen + * If 0 only include notifications into the query + * which arn't marked as "seen" into + * @return int Number of personal notifications + */ private function personalTotal($seen = 0) { $sql_extra .= $this->_personal_sql_extra(); @@ -406,7 +477,19 @@ class NotificationsManager { return 0; } - public function personalNotifs($seen = 0) { + + /** + * @brief Get personal notifications + * + * @param type $seen + * If 0 only include notifications into the query + * which arn't marked as "seen" into + * @param int $start Start the query at this point + * @param int $limit Maximum number of query results + * + * @return array Query output + */ + public function personalNotifs($seen = 0, $start = 0, $limit = 20) { $ident = 'personal'; $total = 0; $sql_extra .= $this->_personal_sql_extra(); @@ -422,8 +505,10 @@ class NotificationsManager { $sql_extra $sql_seen AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 - ORDER BY `item`.`created` DESC" , - intval(local_user()) + ORDER BY `item`.`created` DESC LIMIT %d, %d " , + intval(local_user()), + intval($start), + intval($limit) ); if(dbm::is_result($r)) { @@ -438,24 +523,42 @@ class NotificationsManager { } } + /** + * @brief Total number of home notifications + * @param int $seen + * If 0 only include notifications into the query + * which arn't marked as "seen" into + * @return int Number of home notifications + */ private function homeTotal($seen = 0) { if($seen === 0) $sql_seen = " AND `item`.`unseen` = 1 "; $r = q("SELECT COUNT(*) AS `total` FROM `item` - WHERE ``item`.`visible` = 1 AND + WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 $sql_seen", intval(local_user()) ); if(dbm::is_result($r)) - return $r['total']; + return $r[0]['total']; return 0; } - public function homeNotifs($seen = 0) { + /** + * @brief Get home notifications + * + * @param type $seen + * If 0 only include notifications into the query + * which arn't marked as "seen" into + * @param int $start Start the query at this point + * @param int $limit Maximum number of query results + * + * @return array Query output + */ + public function homeNotifs($seen = 0, $start = 0, $limit = 20) { $ident = 'home'; $total = $this->homeTotal($seen); @@ -471,8 +574,10 @@ class NotificationsManager { WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 $sql_seen - ORDER BY `item`.`created` DESC", - intval(local_user()) + ORDER BY `item`.`created` DESC LIMIT %d, %d ", + intval(local_user()), + intval($start), + intval($limit) ); if(dbm::is_result($r)) { diff --git a/mod/notifications.php b/mod/notifications.php index faf7651914..cdafe07ee9 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -67,7 +67,9 @@ function notifications_content(&$a) { return; } + $page = (x($_REQUEST,'page') ? $_REQUEST['page'] : 1); $show = (x($_REQUEST,'show') ? $_REQUEST['show'] : 0); + nav_set_selected('notifications'); $json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false); @@ -78,6 +80,8 @@ function notifications_content(&$a) { // get the nav tabs for the notification pages $tabs = $nm->getTabs(); $notif_content = array(); + $perpage = 20; + $startrec = ($page * $perpage) - $perpage; if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) { nav_set_selected('introductions'); @@ -90,8 +94,6 @@ function notifications_content(&$a) { $notif_header = t('Notifications'); $notif_tpl = get_markup_template('notifications.tpl'); -// $notif_show_lnk .= '' -// . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '
' . "\r\n"; $notif_show_lnk = array( 'href' => ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ), @@ -105,7 +107,7 @@ function notifications_content(&$a) { ); if(dbm::is_result($r)) { $a->set_pager_total($r[0]['total']); - $a->set_pager_itemspage(20); + $a->set_pager_itemspage($perpage); } /// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact @@ -247,7 +249,7 @@ function notifications_content(&$a) { $notif_header = t('Network Notifications'); $notif_tpl = get_markup_template('notifications.tpl'); - $notifs = $nm->networkNotifs($show); + $notifs = $nm->networkNotifs($show, $startrec, $perpage); $notif_show_lnk = array( 'href' => ($show ? 'notifications/network' : 'notifications/network?show=all' ), @@ -266,7 +268,7 @@ function notifications_content(&$a) { $notif_header = t('System Notifications'); $notif_tpl = get_markup_template('notifications.tpl'); - $notifs = $nm->systemNotifs($show); + $notifs = $nm->systemNotifs($show, $startrec, $perpage); $notif_show_lnk = array( 'href' => ($show ? 'notifications/system' : 'notifications/system?show=all' ), @@ -285,7 +287,7 @@ function notifications_content(&$a) { $notif_header = t('Personal Notifications'); $notif_tpl = get_markup_template('notifications.tpl'); - $notifs = $nm->personalNotifs($show); + $notifs = $nm->personalNotifs($show, $startrec, $perpage); $notif_show_lnk = array( 'href' => ($show ? 'notifications/personal' : 'notifications/personal?show=all' ), @@ -304,7 +306,7 @@ function notifications_content(&$a) { $notif_header = t('Home Notifications'); $notif_tpl = get_markup_template('notifications.tpl'); - $notifs = $nm->homeNotifs($show); + $notifs = $nm->homeNotifs($show, $startrec, $perpage); $notif_show_lnk = array( 'href' => ($show ? 'notifications/home' : 'notifications/home?show=all' ), @@ -321,6 +323,14 @@ function notifications_content(&$a) { } if(count($notifs['notifications']) > 0 ) { + // set the pager + $a->set_pager_total($notifs['total']); + $a->set_pager_itemspage($perpage); + + // add additional informations (needed for json output) + $notifs['items_page'] = $a->pager['itemspage']; + $notifs['page'] = $a->pager['page']; + // The template files we need in different cases for formatting the content $tpl_item_like = 'notifications_likes_item.tpl'; $tpl_item_dislike = 'notifications_dislikes_item.tpl'; @@ -351,8 +361,8 @@ function notifications_content(&$a) { '$notif_content' => $notif_content, '$notif_nocontent' => $notif_nocontent, '$notif_show_lnk' => $notif_show_lnk, + '$notif_paginate' => paginate($a) )); - $o .= paginate($a); return $o; } diff --git a/view/templates/notifications.tpl b/view/templates/notifications.tpl index 4048cfa46b..f3068226c4 100644 --- a/view/templates/notifications.tpl +++ b/view/templates/notifications.tpl @@ -19,4 +19,7 @@ {{if $notif_nocontent}}
{{$notif_nocontent}}
{{/if}} + + {{* The pager *}} + {{$notif_paginate}}
diff --git a/view/theme/frio/templates/notifications.tpl b/view/theme/frio/templates/notifications.tpl index 5f131bd7ed..82f11c8be4 100644 --- a/view/theme/frio/templates/notifications.tpl +++ b/view/theme/frio/templates/notifications.tpl @@ -22,4 +22,7 @@
{{$notif_nocontent}}
{{/if}}
+ + {{* The pager *}} + {{$notif_paginate}}
From 6d3c15fe9100de9d773ddb28784574d046fbe8ea Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Tue, 2 Aug 2016 00:01:43 +0200 Subject: [PATCH 05/10] notifications - add attendance notifications --- include/NotificationsManager.php | 37 +++++++++++++++++--- mod/notifications.php | 3 ++ view/templates/notifications_attend_item.tpl | 4 +++ 3 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 view/templates/notifications_attend_item.tpl diff --git a/include/NotificationsManager.php b/include/NotificationsManager.php index b14e76740b..362e3f5326 100644 --- a/include/NotificationsManager.php +++ b/include/NotificationsManager.php @@ -246,7 +246,6 @@ class NotificationsManager { switch($it['verb']){ case ACTIVITY_LIKE: $notif = array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], 'label' => 'like', 'link' => $this->a->get_baseurl(true).'/display/'.$it['pguid'], '$image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), @@ -258,7 +257,6 @@ class NotificationsManager { case ACTIVITY_DISLIKE: $notif = array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], 'label' => 'dislike', 'link' => $this->a->get_baseurl(true).'/display/'.$it['pguid'], 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), @@ -268,13 +266,45 @@ class NotificationsManager { ); break; + case ACTIVITY_ATTEND: + $notif = array( + 'label' => 'attend', + 'link' => $this->a->get_baseurl(true).'/display/'.$it['pguid'], + 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), + 'text' => sprintf( t("%s is attending %s's event"), $it['author-name'], $it['pname']), + 'when' => relative_date($it['created']), + 'seen' => $it['seen'] + ); + break; + + case ACTIVITY_ATTENDNO: + $notif = array( + 'label' => 'attendno', + 'link' => $this->a->get_baseurl(true).'/display/'.$it['pguid'], + 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), + 'text' => sprintf( t("%s is not attending %s's event"), $it['author-name'], $it['pname']), + 'when' => relative_date($it['created']), + 'seen' => $it['seen'] + ); + break; + + case ACTIVITY_ATTENDMAYBE: + $notif = array( + 'label' => 'attendmaybe', + 'link' => $this->a->get_baseurl(true).'/display/'.$it['pguid'], + 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), + 'text' => sprintf( t("%s may attend %s's event"), $it['author-name'], $it['pname']), + 'when' => relative_date($it['created']), + 'seen' => $it['seen'] + ); + break; + case ACTIVITY_FRIEND: $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; $obj = parse_xml_string($xmlhead.$it['object']); $it['fname'] = $obj->title; $notif = array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], 'label' => 'friend', 'link' => $this->a->get_baseurl(true).'/display/'.$it['pguid'], 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), @@ -286,7 +316,6 @@ class NotificationsManager { default: $notif = array( - //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], 'label' => $default_item_label, 'link' => $default_item_link, 'image' => $default_item_image, diff --git a/mod/notifications.php b/mod/notifications.php index cdafe07ee9..a22703ba95 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -334,6 +334,9 @@ function notifications_content(&$a) { // The template files we need in different cases for formatting the content $tpl_item_like = 'notifications_likes_item.tpl'; $tpl_item_dislike = 'notifications_dislikes_item.tpl'; + $tpl_item_attend = 'notifications_attend_item.tpl'; + $tpl_item_attendno = 'notifications_attend_item.tpl'; + $tpl_item_attendmaybe = 'notifications_attend_item.tpl'; $tpl_item_friend = 'notifications_friends_item.tpl'; $tpl_item_comment = 'notifications_comments_item.tpl'; $tpl_item_post = 'notifications_posts_item.tpl'; diff --git a/view/templates/notifications_attend_item.tpl b/view/templates/notifications_attend_item.tpl new file mode 100644 index 0000000000..6add369cb4 --- /dev/null +++ b/view/templates/notifications_attend_item.tpl @@ -0,0 +1,4 @@ + + \ No newline at end of file From ce3188d5c6a8dc2e4ebf188faef235a1b3b5c5b1 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Wed, 3 Aug 2016 12:44:04 +0200 Subject: [PATCH 06/10] notifications - move intros to NotificationsManager & make json output work --- include/NotificationsManager.php | 338 ++++++++++++++++++++------- mod/notifications.php | 383 ++++++++++++++----------------- 2 files changed, 421 insertions(+), 300 deletions(-) diff --git a/include/NotificationsManager.php b/include/NotificationsManager.php index 362e3f5326..fef48d5d43 100644 --- a/include/NotificationsManager.php +++ b/include/NotificationsManager.php @@ -1,6 +1,8 @@ value: filter query by columns values * @param string $order optional Space separated list of column to sort by. prepend name with "+" to sort ASC, "-" to sort DESC. Default to "-date" @@ -89,7 +92,7 @@ class NotificationsManager { } /** - * @brief get one note for local_user() by $id value + * @brief Get one note for local_user() by $id value * * @param int $id * @return array note values or null if not found @@ -196,7 +199,7 @@ class NotificationsManager { * string 'when' => Relative date of the notification * bool 'seen' => Is the notification marked as "seen" */ - private function format($notifs, $ident = "") { + private function formatNotifs($notifs, $ident = "") { $notif = array(); $arr = array(); @@ -335,9 +338,9 @@ class NotificationsManager { /** * @brief Total number of network notifications - * @param int $seen + * @param int|string $seen * If 0 only include notifications into the query - * which arn't marked as "seen" into + * which aren't marked as "seen" * @return int Number of network notifications */ private function networkTotal($seen = 0) { @@ -361,17 +364,21 @@ class NotificationsManager { /** * @brief Get network notifications * - * @param type $seen + * @param int|string $seen * If 0 only include notifications into the query - * which arn't marked as "seen" into + * which aren't marked as "seen" * @param int $start Start the query at this point * @param int $limit Maximum number of query results * - * @return array Query output + * @return array with + * string 'ident' => Notification identifier + * int 'total' => Total number of available network notifications + * array 'notifications' => Network notifications */ - public function networkNotifs($seen = 0, $start = 0, $limit = 20) { + public function networkNotifs($seen = 0, $start = 0, $limit = 80) { $ident = 'network'; $total = $this->networkTotal($seen); + $notifs = array(); if($seen === 0) $sql_seen = " AND `item`.`unseen` = 1 "; @@ -380,33 +387,33 @@ class NotificationsManager { $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`, `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`, `pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid` - FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent` - WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND + FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent` + WHERE `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 $sql_seen - ORDER BY `item`.`created` DESC LIMIT %d, %d ", - intval(local_user()), - intval($start), - intval($limit) + ORDER BY `item`.`created` DESC LIMIT %d, %d ", + intval(local_user()), + intval($start), + intval($limit) ); - if(dbm::is_result($r)) { - $notifs = $this->format($r, $ident); - $arr = array ( - 'notifications' => $notifs, - 'ident' => $ident, - 'total' => $total, - ); + if(dbm::is_result($r)) + $notifs = $this->formatNotifs($r, $ident); - return $arr; - } + $arr = array ( + 'notifications' => $notifs, + 'ident' => $ident, + 'total' => $total, + ); + + return $arr; } /** * @brief Total number of system notifications - * @param int $seen + * @param int|string $seen * If 0 only include notifications into the query - * which arn't marked as "seen" into + * which aren't marked as "seen" * @return int Number of system notifications */ private function systemTotal($seen = 0) { @@ -426,17 +433,21 @@ class NotificationsManager { /** * @brief Get system notifications * - * @param type $seen + * @param int|string $seen * If 0 only include notifications into the query - * which arn't marked as "seen" into + * which aren't marked as "seen" * @param int $start Start the query at this point * @param int $limit Maximum number of query results * - * @return array Query output + * @return array with + * string 'ident' => Notification identifier + * int 'total' => Total number of available system notifications + * array 'notifications' => System notifications */ - public function systemNotifs($seen = 0, $start = 0, $limit = 20) { + public function systemNotifs($seen = 0, $start = 0, $limit = 80) { $ident = 'system'; $total = $this->systemTotal($seen); + $notifs = array(); if($seen === 0) $sql_seen = " AND `seen` = 0 "; @@ -448,16 +459,16 @@ class NotificationsManager { intval($limit) ); - if(dbm::is_result($r)) { - $notifs = $this->format($r, $ident); - $arr = array ( - 'notifications' => $notifs, - 'ident' => $ident, - 'total' => $total, - ); + if(dbm::is_result($r)) + $notifs = $this->formatNotifs($r, $ident); - return $arr; - } + $arr = array ( + 'notifications' => $notifs, + 'ident' => $ident, + 'total' => $total, + ); + + return $arr; } /** @@ -481,9 +492,9 @@ class NotificationsManager { /** * @brief Total number of personal notifications - * @param int $seen + * @param int|string $seen * If 0 only include notifications into the query - * which arn't marked as "seen" into + * which aren't marked as "seen" * @return int Number of personal notifications */ private function personalTotal($seen = 0) { @@ -510,18 +521,22 @@ class NotificationsManager { /** * @brief Get personal notifications * - * @param type $seen + * @param int|string $seen * If 0 only include notifications into the query - * which arn't marked as "seen" into + * which aren't marked as "seen" * @param int $start Start the query at this point * @param int $limit Maximum number of query results * - * @return array Query output + * @return array with + * string 'ident' => Notification identifier + * int 'total' => Total number of available personal notifications + * array 'notifications' => Personal notifications */ - public function personalNotifs($seen = 0, $start = 0, $limit = 20) { + public function personalNotifs($seen = 0, $start = 0, $limit = 80) { $ident = 'personal'; - $total = 0; + $total = $this->personalTotal($seen); $sql_extra .= $this->_personal_sql_extra(); + $notifs = array(); if($seen === 0) $sql_seen = " AND `item`.`unseen` = 1 "; @@ -529,34 +544,34 @@ class NotificationsManager { $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`, `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` AS `object`, `pitem`.`author-name` AS `pname`, `pitem`.`author-link` AS `plink`, `pitem`.`guid` AS `pguid`, - FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent` - WHERE `item`.`visible` = 1 + FROM `item` INNER JOIN `item` AS `pitem` ON `pitem`.`id`=`item`.`parent` + WHERE `item`.`visible` = 1 $sql_extra $sql_seen AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 0 - ORDER BY `item`.`created` DESC LIMIT %d, %d " , - intval(local_user()), - intval($start), - intval($limit) + ORDER BY `item`.`created` DESC LIMIT %d, %d " , + intval(local_user()), + intval($start), + intval($limit) ); - if(dbm::is_result($r)) { - $notifs = $this->format($r, $ident); - $arr = array ( - 'notifications' => $notifs, - 'ident' => $ident, - 'total' => $total, - ); + if(dbm::is_result($r)) + $notifs = $this->formatNotifs($r, $ident); + + $arr = array ( + 'notifications' => $notifs, + 'ident' => $ident, + 'total' => $total, + ); - return $arr; - } + return $arr; } /** * @brief Total number of home notifications - * @param int $seen + * @param int|string $seen * If 0 only include notifications into the query - * which arn't marked as "seen" into + * which aren't marked as "seen" * @return int Number of home notifications */ private function homeTotal($seen = 0) { @@ -579,45 +594,200 @@ class NotificationsManager { /** * @brief Get home notifications * - * @param type $seen + * @param int|string $seen * If 0 only include notifications into the query - * which arn't marked as "seen" into + * which aren't marked as "seen" * @param int $start Start the query at this point * @param int $limit Maximum number of query results * - * @return array Query output + * @return array with + * string 'ident' => Notification identifier + * int 'total' => Total number of available home notifications + * array 'notifications' => Home notifications */ - public function homeNotifs($seen = 0, $start = 0, $limit = 20) { + public function homeNotifs($seen = 0, $start = 0, $limit = 80) { $ident = 'home'; $total = $this->homeTotal($seen); + $notifs = array(); if($seen === 0) $sql_seen = " AND `item`.`unseen` = 1 "; - $total = $this->homeTotal($seen); - $r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, `item`.`unseen`, `item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`, `pitem`.`author-name` as `pname`, `pitem`.`author-link` as `plink`, `pitem`.`guid` as `pguid` - FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent` - WHERE `item`.`visible` = 1 AND + FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent` + WHERE `item`.`visible` = 1 AND `item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 $sql_seen - ORDER BY `item`.`created` DESC LIMIT %d, %d ", - intval(local_user()), - intval($start), - intval($limit) + ORDER BY `item`.`created` DESC LIMIT %d, %d ", + intval(local_user()), + intval($start), + intval($limit) ); - if(dbm::is_result($r)) { - $notifs = $this->format($r, $ident); - $arr = array ( - 'notifications' => $notifs, - 'ident' => $ident, - 'total' => $total, - ); + if(dbm::is_result($r)) + $notifs = $this->formatNotifs($r, $ident); - return $arr; + $arr = array ( + 'notifications' => $notifs, + 'ident' => $ident, + 'total' => $total, + ); + + return $arr; + } + + /** + * @brief Total number of introductions + * @param int $all + * If 0 only include introductions into the query + * which aren't marked as ignored + * @return int Number of introductions + */ + private function introTotal($all) { + if($all === 0) + $sql_extra = " AND `ignore` = 0 "; + + $r = q("SELECT COUNT(*) AS `total` FROM `intro` + WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ", + intval($_SESSION['uid']) + ); + + if(dbm::is_result($r)) + return $r[0]['total']; + + return 0; + } + + /** + * @brief Get introductions + * + * @param int $all + * If 0 only include introductions into the query + * which aren't marked as ignored + * @param int $start Start the query at this point + * @param int $limit Maximum number of query results + * + * @return array with + * string 'ident' => Notification identifier + * int 'total' => Total number of available introductions + * array 'notifications' => Introductions + */ + public function introNotifs($all = 0, $start = 0, $limit = 80) { + $ident = 'introductions'; + $total = $this->introTotal($seen); + $notifs = array(); + + if($all === 0) + $sql_extra = " AND `ignore` = 0 "; + + /// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact + $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`, + `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`, + `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`, + `gcontact`.`network` AS `gnetwork` + FROM `intro` + LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` + LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl` + LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id` + WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 + LIMIT %d, %d", + intval($_SESSION['uid']), + intval($start), + intval($limit) + ); + + if(dbm::is_result($r)) + $notifs = $this->formatIntros($r); + + $arr = array ( + 'ident' => $ident, + 'total' => $total, + 'notifications' => $notifs, + ); + + return $arr; + } + + /** + * @brief Format the notification query in an usable array + * + * @param array $intros The array from the db query + * @return array with the introductions + */ + private function formatIntros($intros) { + $knowyou = ''; + + foreach($intros as $it) { + // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests. + // We have to distinguish between these two because they use different data. + + // Contact suggestions + if($it['fid']) { + + $return_addr = bin2hex($this->a->user['nickname'] . '@' . $this->a->get_hostname() . (($this->a->path) ? '/' . $this->a->path : '')); + + $intro = array( + 'label' => 'friend_suggestion', + 'notify_type' => t('Friend Suggestion'), + 'intro_id' => $it['intro_id'], + 'madeby' => $it['name'], + 'contact_id' => $it['contact-id'], + 'photo' => ((x($it,'fphoto')) ? proxy_url($it['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"), + 'name' => $it['fname'], + 'url' => zrl($it['furl']), + 'hidden' => $it['hidden'] == 1, + 'post_newfriend' => (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), + + 'knowyou' => $knowyou, + 'note' => $it['note'], + 'request' => $it['frequest'] . '?addr=' . $return_addr, + + ); + + // Normal connection requests + } else { + + // Probe the contact url to get missing data + $ret = probe_url($it["url"]); + + if ($it['gnetwork'] == "") + $it['gnetwork'] = $ret["network"]; + + // Don't show these data until you are connected. Diaspora is doing the same. + if($it['gnetwork'] === NETWORK_DIASPORA) { + $it['glocation'] = ""; + $it['gabout'] = ""; + $it['ggender'] = ""; + } + $intro = array( + 'label' => (($it['network'] !== NETWORK_OSTATUS) ? 'friend_request' : 'follower'), + 'notify_type' => (($it['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')), + 'dfrn_id' => $it['issued-id'], + 'uid' => $_SESSION['uid'], + 'intro_id' => $it['intro_id'], + 'contact_id' => $it['contact-id'], + 'photo' => ((x($it,'photo')) ? proxy_url($it['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"), + 'name' => $it['name'], + 'location' => bbcode($it['glocation'], false, false), + 'about' => bbcode($it['gabout'], false, false), + 'keywords' => $it['gkeywords'], + 'gender' => $it['ggender'], + 'hidden' => $it['hidden'] == 1, + 'post_newfriend' => (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), + 'url' => $it['url'], + 'zrl' => zrl($it['url']), + 'addr' => $ret['addr'], + 'network' => $it['gnetwork'], + 'knowyou' => $it['knowyou'], + 'note' => $it['note'], + ); + } + + $arr[] = $intro; } + + return $arr; } } diff --git a/mod/notifications.php b/mod/notifications.php index a22703ba95..fd7f0c33de 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -1,8 +1,13 @@ getTabs(); $notif_content = array(); + + // Notification results per page $perpage = 20; $startrec = ($page * $perpage) - $perpage; + // Get introductions if( (($a->argc > 1) && ($a->argv[1] == 'intros')) || (($a->argc == 1))) { nav_set_selected('introductions'); + $notif_header = t('Notifications'); if(($a->argc > 2) && ($a->argv[2] == 'all')) - $sql_extra = ''; + $all = 1; else - $sql_extra = " AND `ignore` = 0 "; + $all = 0; - $notif_header = t('Notifications'); - $notif_tpl = get_markup_template('notifications.tpl'); + $notifs = $nm->introNotifs($all, $startrec, $perpage); + + // Get the network notifications + } else if (($a->argc > 1) && ($a->argv[1] == 'network')) { + + $notif_header = t('Network Notifications'); + $notifs = $nm->networkNotifs($show, $startrec, $perpage); + + // Get the system notifications + } else if (($a->argc > 1) && ($a->argv[1] == 'system')) { + + $notif_header = t('System Notifications'); + $notifs = $nm->systemNotifs($show, $startrec, $perpage); + + // Get the personal notifications + } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) { + + $notif_header = t('Personal Notifications'); + $notifs = $nm->personalNotifs($show, $startrec, $perpage); + + // Get the home notifications + } else if (($a->argc > 1) && ($a->argv[1] == 'home')) { + + $notif_header = t('Home Notifications'); + $notifs = $nm->homeNotifs($show, $startrec, $perpage); + + } + // Set the pager + $a->set_pager_total($notifs['total']); + $a->set_pager_itemspage($perpage); + + // Add additional informations (needed for json output) + $notifs['items_page'] = $a->pager['itemspage']; + $notifs['page'] = $a->pager['page']; + + // Json output + if(intval($json) === 1) + json_return_and_die($notifs); + + $notif_tpl = get_markup_template('notifications.tpl'); + + // Process the data for template creation + if($notifs['ident'] === 'introductions') { + + $sugg = get_markup_template('suggestions.tpl'); + $tpl = get_markup_template("intros.tpl"); + + // The link to switch between ignored and normal connection requests $notif_show_lnk = array( - 'href' => ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ), - 'text' => ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')), - 'id' => "notifications-show-hide-link", + 'href' => ($all === 0 ? 'notifications/intros/all' : 'notifications/intros' ), + 'text' => ($all === 0 ? t('Show Ignored Requests') : t('Hide Ignored Requests')) ); - $r = q("SELECT COUNT(*) AS `total` FROM `intro` - WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ", - intval($_SESSION['uid']) - ); - if(dbm::is_result($r)) { - $a->set_pager_total($r[0]['total']); - $a->set_pager_itemspage($perpage); - } - - /// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact - - $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`, - `gcontact`.`location` AS `glocation`, `gcontact`.`about` AS `gabout`, - `gcontact`.`keywords` AS `gkeywords`, `gcontact`.`gender` AS `ggender`, - `gcontact`.`network` AS `gnetwork` - FROM `intro` - LEFT JOIN `contact` ON `contact`.`id` = `intro`.`contact-id` - LEFT JOIN `gcontact` ON `gcontact`.`nurl` = `contact`.`nurl` - LEFT JOIN `fcontact` ON `intro`.`fid` = `fcontact`.`id` - WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ", - intval($_SESSION['uid'])); - - if(dbm::is_result($r)) { - - $sugg = get_markup_template('suggestions.tpl'); - $tpl = get_markup_template("intros.tpl"); - - foreach($r as $rr) { - - if($rr['fid']) { - - $return_addr = bin2hex($a->user['nickname'] . '@' . $a->get_hostname() . (($a->path) ? '/' . $a->path : '')); + // Loop through all introduction notifications.This creates an array with the output html for each + // introduction + foreach ($notifs['notifications'] as $it) { + // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests. + // We have to distinguish between these two because they use different data. + switch ($it['label']) { + case 'friend_suggestion': $notif_content[] = replace_macros($sugg, array( '$str_notifytype' => t('Notification type: '), - '$notify_type' => t('Friend Suggestion'), - '$intro_id' => $rr['intro_id'], - '$madeby' => sprintf( t('suggested by %s'),$rr['name']), - '$contact_id' => $rr['contact-id'], - '$photo' => ((x($rr,'fphoto')) ? proxy_url($rr['fphoto'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"), - '$fullname' => $rr['fname'], - '$url' => zrl($rr['furl']), - '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''), - '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')), + '$notify_type' => $it['notify_type'], + '$intro_id' => $it['intro_id'], + '$madeby' => sprintf( t('suggested by %s'),$it['madeby']), + '$contact_id' => $it['contact-id'], + '$photo' => $it['photo'], + '$fullname' => $it['name'], + '$url' => $it['url'], + '$hidden' => array('hidden', t('Hide this contact from others'), ($it['hidden'] == 1), ''), + '$activity' => array('activity', t('Post a new friend activity'), $it['post_newfriend'], t('if applicable')), - '$knowyou' => $knowyou, + '$knowyou' => $it['knowyou'], '$approve' => t('Approve'), - '$note' => $rr['note'], - '$request' => $rr['frequest'] . '?addr=' . $return_addr, + '$note' => $it['note'], + '$request' => $it['request'], '$ignore' => t('Ignore'), '$discard' => t('Discard'), - )); + break; - continue; + // Normal connection requests + default: + $friend_selected = (($it['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled '); + $fan_selected = (($it['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : ''); + $dfrn_tpl = get_markup_template('netfriend.tpl'); - } - $friend_selected = (($rr['network'] !== NETWORK_OSTATUS) ? ' checked="checked" ' : ' disabled '); - $fan_selected = (($rr['network'] === NETWORK_OSTATUS) ? ' checked="checked" disabled ' : ''); - $dfrn_tpl = get_markup_template('netfriend.tpl'); + $knowyou = ''; + $dfrn_text = ''; - $knowyou = ''; - $dfrn_text = ''; - - if($rr['network'] === NETWORK_DFRN || $rr['network'] === NETWORK_DIASPORA) { - if($rr['network'] === NETWORK_DFRN) { - $lbl_knowyou = t('Claims to be known to you: '); - $knowyou = (($rr['knowyou']) ? t('yes') : t('no')); - $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Fan/Admirer" means that you allow to read but you do not want to read theirs. Approve as: '); - } else { - $knowyou = ''; - $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Sharer" means that you allow to read but you do not want to read theirs. Approve as: '); + if($it['network'] === NETWORK_DFRN || $it['network'] === NETWORK_DIASPORA) { + if($it['network'] === NETWORK_DFRN) { + $lbl_knowyou = t('Claims to be known to you: '); + $knowyou = (($it['knowyou']) ? t('yes') : t('no')); + $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Fan/Admirer" means that you allow to read but you do not want to read theirs. Approve as: '); + } else { + $knowyou = ''; + $helptext = t('Shall your connection be bidirectional or not? "Friend" implies that you allow to read and you subscribe to their posts. "Sharer" means that you allow to read but you do not want to read theirs. Approve as: '); + } } $dfrn_text = replace_macros($dfrn_tpl,array( - '$intro_id' => $rr['intro_id'], + '$intro_id' => $it['intro_id'], '$friend_selected' => $friend_selected, '$fan_selected' => $fan_selected, '$approve_as' => $helptext, '$as_friend' => t('Friend'), - '$as_fan' => (($rr['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer')) + '$as_fan' => (($it['network'] == NETWORK_DIASPORA) ? t('Sharer') : t('Fan/Admirer')) )); - } - $header = $rr["name"]; + $header = $it["name"]; - $ret = probe_url($rr["url"]); + if ($it["addr"] != "") + $header .= " <".$it["addr"].">"; - if ($rr['gnetwork'] == "") - $rr['gnetwork'] = $ret["network"]; + $header .= " (".network_to_name($it['network'], $it['url']).")"; - if ($ret["addr"] != "") - $header .= " <".$ret["addr"].">"; + $notif_content[] = replace_macros($tpl, array( + '$header' => htmlentities($header), + '$str_notifytype' => t('Notification type: '), + '$notify_type' => $it['notify_type'], + '$dfrn_text' => $dfrn_text, + '$dfrn_id' => $it['dfrn_id'], + '$uid' => $it['uid'], + '$intro_id' => $it['intro_id'], + '$contact_id' => $it['contact_id'], + '$photo' => $it['photo'], + '$fullname' => $it['name'], + '$location' => $it['location'], + '$lbl_location' => t('Location:'), + '$about' => $it['about'], + '$lbl_about' => t('About:'), + '$keywords' => $it['keywords'], + '$lbl_keywords' => t('Tags:'), + '$gender' => $it['gender'], + '$lbl_gender' => t('Gender:'), + '$hidden' => array('hidden', t('Hide this contact from others'), ($it['hidden'] == 1), ''), + '$activity' => array('activity', t('Post a new friend activity'), $it['post_newfriend'], t('if applicable')), + '$url' => $it['url'], + '$zrl' => $it['zrl'], + '$lbl_url' => t('Profile URL'), + '$addr' => $it['addr'], + '$lbl_knowyou' => $lbl_knowyou, + '$lbl_network' => t('Network:'), + '$network' => network_to_name($it['network'], $it['url']), + '$knowyou' => $knowyou, + '$approve' => t('Approve'), + '$note' => $it['note'], + '$ignore' => t('Ignore'), + '$discard' => t('Discard'), - $header .= " (".network_to_name($rr['gnetwork'], $rr['url']).")"; - - // Don't show these data until you are connected. Diaspora is doing the same. - if($rr['gnetwork'] === NETWORK_DIASPORA) { - $rr['glocation'] = ""; - $rr['gabout'] = ""; - $rr['ggender'] = ""; - } - - $notif_content[] = replace_macros($tpl, array( - '$header' => htmlentities($header), - '$str_notifytype' => t('Notification type: '), - '$notify_type' => (($rr['network'] !== NETWORK_OSTATUS) ? t('Friend/Connect Request') : t('New Follower')), - '$dfrn_text' => $dfrn_text, - '$dfrn_id' => $rr['issued-id'], - '$uid' => $_SESSION['uid'], - '$intro_id' => $rr['intro_id'], - '$contact_id' => $rr['contact-id'], - '$photo' => ((x($rr,'photo')) ? proxy_url($rr['photo'], false, PROXY_SIZE_SMALL) : "images/person-175.jpg"), - '$fullname' => $rr['name'], - '$location' => bbcode($rr['glocation'], false, false), - '$location_label' => t('Location:'), - '$about' => bbcode($rr['gabout'], false, false), - '$about_label' => t('About:'), - '$keywords' => $rr['gkeywords'], - '$keywords_label' => t('Tags:'), - '$gender' => $rr['ggender'], - '$gender_label' => t('Gender:'), - '$hidden' => array('hidden', t('Hide this contact from others'), ($rr['hidden'] == 1), ''), - '$activity' => array('activity', t('Post a new friend activity'), (intval(get_pconfig(local_user(),'system','post_newfriend')) ? '1' : 0), t('if applicable')), - '$url' => $rr['url'], - '$zrl' => zrl($rr['url']), - '$url_label' => t('Profile URL'), - '$addr' => $rr['addr'], - '$lbl_knowyou' => $lbl_knowyou, - '$lbl_network' => t('Network:'), - '$network' => network_to_name($rr['gnetwork'], $rr['url']), - '$knowyou' => $knowyou, - '$approve' => t('Approve'), - '$note' => $rr['note'], - '$ignore' => t('Ignore'), - '$discard' => t('Discard'), - - )); + )); + break; } } - else + + if($notifs['total'] == 0) info( t('No introductions.') . EOL); - } else if (($a->argc > 1) && ($a->argv[1] == 'network')) { - - $notif_header = t('Network Notifications'); - $notif_tpl = get_markup_template('notifications.tpl'); - - $notifs = $nm->networkNotifs($show, $startrec, $perpage); - - $notif_show_lnk = array( - 'href' => ($show ? 'notifications/network' : 'notifications/network?show=all' ), - 'text' => ($show ? t('Show unread') : t('Show all')), - ); - - if(!dbm::is_result($notifs)) { - if($show) - $notif_show_lnk = array(); - - $notif_nocontent = t('No more network notifications.'); - } - - } else if (($a->argc > 1) && ($a->argv[1] == 'system')) { - - $notif_header = t('System Notifications'); - $notif_tpl = get_markup_template('notifications.tpl'); - - $notifs = $nm->systemNotifs($show, $startrec, $perpage); - - $notif_show_lnk = array( - 'href' => ($show ? 'notifications/system' : 'notifications/system?show=all' ), - 'text' => ($show ? t('Show unread') : t('Show all')), - ); - - if(!dbm::is_result($notifs)) { - if($show) - $notif_show_lnk = array(); - - $notif_nocontent = t('No more system notifications.'); - } - - } else if (($a->argc > 1) && ($a->argv[1] == 'personal')) { - - $notif_header = t('Personal Notifications'); - $notif_tpl = get_markup_template('notifications.tpl'); - - $notifs = $nm->personalNotifs($show, $startrec, $perpage); - - $notif_show_lnk = array( - 'href' => ($show ? 'notifications/personal' : 'notifications/personal?show=all' ), - 'text' => ($show ? t('Show unread') : t('Show all')), - ); - - if(!dbm::is_result($notifs)) { - if($show) - $notif_show_lnk = array(); - - $notif_nocontent = t('No more personal notifications.'); - } - - } else if (($a->argc > 1) && ($a->argv[1] == 'home')) { - - $notif_header = t('Home Notifications'); - $notif_tpl = get_markup_template('notifications.tpl'); - - $notifs = $nm->homeNotifs($show, $startrec, $perpage); - - $notif_show_lnk = array( - 'href' => ($show ? 'notifications/home' : 'notifications/home?show=all' ), - 'text' => ($show ? t('Show unread') : t('Show all')), - ); - - if(!dbm::is_result($notifs)) { - if($show) - $notif_show_lnk = array(); - - $notif_nocontent = t('No more home notifications.'); - } - - } - - if(count($notifs['notifications']) > 0 ) { - // set the pager - $a->set_pager_total($notifs['total']); - $a->set_pager_itemspage($perpage); - - // add additional informations (needed for json output) - $notifs['items_page'] = $a->pager['itemspage']; - $notifs['page'] = $a->pager['page']; + // Normal notifications (no introductions) + } else { // The template files we need in different cases for formatting the content $tpl_item_like = 'notifications_likes_item.tpl'; @@ -342,11 +276,15 @@ function notifications_content(&$a) { $tpl_item_post = 'notifications_posts_item.tpl'; $tpl_item_notify = 'notify.tpl'; + // Loop trough ever notification This creates an array with the output html for each + // notification and apply the correct template according to the notificationtype (label). foreach ($notifs['notifications'] as $it) { - $tplname = 'tpl_item_'.$it['label']; - $templ = get_markup_template($$tplname); - $notif_content[] = replace_macros($templ,array( + // We use the notification label to get the correct template file + $tpl_var_name = 'tpl_item_'.$it['label']; + $tpl_notif = get_markup_template($$tpl_var_name); + + $notif_content[] = replace_macros($tpl_notif,array( '$item_label' => $it['label'], '$item_link' => $it['link'], '$item_image' => $it['image'], @@ -356,8 +294,21 @@ function notifications_content(&$a) { )); } + // It doesn't make sense to show the Show unread / Show all link visible if the user is on the + // "Show all" page and there are no notifications. So we will hide it. + if($show == 0 || intval($show) && $notifs['total'] > 0) { + $notif_show_lnk = array( + 'href' => ($show ? 'notifications/'.$notifs['ident'] : 'notifications/'.$notifs['ident'].'?show=all' ), + 'text' => ($show ? t('Show unread') : t('Show all')), + ); + } + + // Output if there aren't any notifications available + if($notifs['total'] == 0) + $notif_nocontent = sprintf( t('No more %s notifications.'), $notifs['ident']); } + $o .= replace_macros($notif_tpl, array( '$notif_header' => $notif_header, '$tabs' => $tabs, From 178b89711a8c3bad5fe0f88be77137cf417024e1 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Wed, 3 Aug 2016 12:55:37 +0200 Subject: [PATCH 07/10] restore gitignore --- .gitignore | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/.gitignore b/.gitignore index 77151060d2..b300f579e2 100644 --- a/.gitignore +++ b/.gitignore @@ -42,16 +42,3 @@ nbproject #ignore local folder /local/ - -#other stuff -.directory -.gitignore - -/view/theme/Friendiboot -/view/theme/Viereinhalb -/view/theme/blog -/view/theme/boheme -/view/theme/clean -/view/theme/suckerberg - -/addon/frio_hovercard From 8ad345c43431d222a61f4e6217cc7dbbd4fd6bd4 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Thu, 4 Aug 2016 11:46:57 +0200 Subject: [PATCH 08/10] notifications - remove TAB (clean up) --- include/NotificationsManager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/NotificationsManager.php b/include/NotificationsManager.php index fef48d5d43..87c72536c4 100644 --- a/include/NotificationsManager.php +++ b/include/NotificationsManager.php @@ -430,7 +430,7 @@ class NotificationsManager { return 0; } - /** + /** * @brief Get system notifications * * @param int|string $seen From de02154a1b1073890ff304d4dd1cab109e9bd84b Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Sat, 6 Aug 2016 18:59:39 +0200 Subject: [PATCH 09/10] notifications - set default values for some varibles --- include/NotificationsManager.php | 47 ++++++++++++++++++++++---------- mod/notifications.php | 9 ++---- 2 files changed, 35 insertions(+), 21 deletions(-) diff --git a/include/NotificationsManager.php b/include/NotificationsManager.php index 87c72536c4..6962d02cc0 100644 --- a/include/NotificationsManager.php +++ b/include/NotificationsManager.php @@ -7,7 +7,6 @@ require_once('include/html2plain.php'); require_once("include/datetime.php"); require_once("include/bbcode.php"); -require_once("include/dbm.php"); /** * @brief Methods for read and write notifications from/to database @@ -82,12 +81,16 @@ class NotificationsManager { } $order_sql = implode(", ", $asOrder); - if ($limit!="") $limit = " LIMIT ".$limit; + if($limit!="") + $limit = " LIMIT ".$limit; $r = q("SELECT * FROM `notify` WHERE `uid` = %d $filter_sql ORDER BY $order_sql $limit", intval(local_user()) ); - if ($r!==false && count($r)>0) return $this->_set_extra($r); + + if(dbm::is_result($r)) + return $this->_set_extra($r); + return false; } @@ -102,7 +105,7 @@ class NotificationsManager { intval($id), intval(local_user()) ); - if($r!==false && count($r)>0) { + if(dbm::is_result($r)) { return $this->_set_extra($r)[0]; } return null; @@ -344,6 +347,8 @@ class NotificationsManager { * @return int Number of network notifications */ private function networkTotal($seen = 0) { + $sql_seen = ""; + if($seen === 0) $sql_seen = " AND `item`.`unseen` = 1 "; @@ -379,6 +384,7 @@ class NotificationsManager { $ident = 'network'; $total = $this->networkTotal($seen); $notifs = array(); + $sql_seen = ""; if($seen === 0) $sql_seen = " AND `item`.`unseen` = 1 "; @@ -417,6 +423,8 @@ class NotificationsManager { * @return int Number of system notifications */ private function systemTotal($seen = 0) { + $sql_seen = ""; + if($seen === 0) $sql_seen = " AND `seen` = 0 "; @@ -448,6 +456,7 @@ class NotificationsManager { $ident = 'system'; $total = $this->systemTotal($seen); $notifs = array(); + $sql_seen = ""; if($seen === 0) $sql_seen = " AND `seen` = 0 "; @@ -481,7 +490,7 @@ class NotificationsManager { $myurl = substr($myurl,strpos($myurl,'://')+3); $myurl = str_replace(array('www.','.'),array('','\\.'),$myurl); $diasp_url = str_replace('/profile/','/u/',$myurl); - $sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ", + $sql_extra = sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ", dbesc($myurl . '$'), dbesc($myurl . '\\]'), dbesc($diasp_url . '\\]') @@ -498,7 +507,8 @@ class NotificationsManager { * @return int Number of personal notifications */ private function personalTotal($seen = 0) { - $sql_extra .= $this->_personal_sql_extra(); + $sql_seen = ""; + $sql_extra = $this->_personal_sql_extra(); if($seen === 0) $sql_seen = " AND `item`.`unseen` = 1 "; @@ -535,8 +545,9 @@ class NotificationsManager { public function personalNotifs($seen = 0, $start = 0, $limit = 80) { $ident = 'personal'; $total = $this->personalTotal($seen); - $sql_extra .= $this->_personal_sql_extra(); + $sql_extra = $this->_personal_sql_extra(); $notifs = array(); + $sql_seen = ""; if($seen === 0) $sql_seen = " AND `item`.`unseen` = 1 "; @@ -575,6 +586,8 @@ class NotificationsManager { * @return int Number of home notifications */ private function homeTotal($seen = 0) { + $sql_seen = ""; + if($seen === 0) $sql_seen = " AND `item`.`unseen` = 1 "; @@ -609,6 +622,7 @@ class NotificationsManager { $ident = 'home'; $total = $this->homeTotal($seen); $notifs = array(); + $sql_seen = ""; if($seen === 0) $sql_seen = " AND `item`.`unseen` = 1 "; @@ -640,13 +654,15 @@ class NotificationsManager { /** * @brief Total number of introductions - * @param int $all - * If 0 only include introductions into the query + * @param bool $all + * If false only include introductions into the query * which aren't marked as ignored * @return int Number of introductions */ - private function introTotal($all) { - if($all === 0) + private function introTotal($all = false) { + $sql_extra = ""; + + if($all === false) $sql_extra = " AND `ignore` = 0 "; $r = q("SELECT COUNT(*) AS `total` FROM `intro` @@ -663,8 +679,8 @@ class NotificationsManager { /** * @brief Get introductions * - * @param int $all - * If 0 only include introductions into the query + * @param bool $all + * If false only include introductions into the query * which aren't marked as ignored * @param int $start Start the query at this point * @param int $limit Maximum number of query results @@ -674,12 +690,13 @@ class NotificationsManager { * int 'total' => Total number of available introductions * array 'notifications' => Introductions */ - public function introNotifs($all = 0, $start = 0, $limit = 80) { + public function introNotifs($all = false, $start = 0, $limit = 80) { $ident = 'introductions'; $total = $this->introTotal($seen); $notifs = array(); + $sql_extra = ""; - if($all === 0) + if($all === false) $sql_extra = " AND `ignore` = 0 "; /// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact diff --git a/mod/notifications.php b/mod/notifications.php index fd7f0c33de..01dce2f447 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -95,10 +95,7 @@ function notifications_content(&$a) { nav_set_selected('introductions'); $notif_header = t('Notifications'); - if(($a->argc > 2) && ($a->argv[2] == 'all')) - $all = 1; - else - $all = 0; + $all = (($a->argc > 2) && ($a->argv[2] == 'all')); $notifs = $nm->introNotifs($all, $startrec, $perpage); @@ -151,8 +148,8 @@ function notifications_content(&$a) { // The link to switch between ignored and normal connection requests $notif_show_lnk = array( - 'href' => ($all === 0 ? 'notifications/intros/all' : 'notifications/intros' ), - 'text' => ($all === 0 ? t('Show Ignored Requests') : t('Hide Ignored Requests')) + 'href' => ($all === false ? 'notifications/intros/all' : 'notifications/intros' ), + 'text' => ($all === false ? t('Show Ignored Requests') : t('Hide Ignored Requests')) ); // Loop through all introduction notifications.This creates an array with the output html for each From 0532dc6a6103cc694050350c2a7a7f92f354ab46 Mon Sep 17 00:00:00 2001 From: rabuzarus <> Date: Sun, 7 Aug 2016 12:26:49 +0200 Subject: [PATCH 10/10] notifications - correct boolean variable checking --- include/NotificationsManager.php | 4 ++-- mod/notifications.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/NotificationsManager.php b/include/NotificationsManager.php index 6962d02cc0..3b7cbdfc99 100644 --- a/include/NotificationsManager.php +++ b/include/NotificationsManager.php @@ -662,7 +662,7 @@ class NotificationsManager { private function introTotal($all = false) { $sql_extra = ""; - if($all === false) + if(!$all) $sql_extra = " AND `ignore` = 0 "; $r = q("SELECT COUNT(*) AS `total` FROM `intro` @@ -696,7 +696,7 @@ class NotificationsManager { $notifs = array(); $sql_extra = ""; - if($all === false) + if(!$all) $sql_extra = " AND `ignore` = 0 "; /// @todo Fetch contact details by "get_contact_details_by_url" instead of queries to contact, fcontact and gcontact diff --git a/mod/notifications.php b/mod/notifications.php index 01dce2f447..d43e2cc04f 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -148,8 +148,8 @@ function notifications_content(&$a) { // The link to switch between ignored and normal connection requests $notif_show_lnk = array( - 'href' => ($all === false ? 'notifications/intros/all' : 'notifications/intros' ), - 'text' => ($all === false ? t('Show Ignored Requests') : t('Hide Ignored Requests')) + 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros' ), + 'text' => (!$all ? t('Show Ignored Requests') : t('Hide Ignored Requests')) ); // Loop through all introduction notifications.This creates an array with the output html for each