notifications.php: move more code to NotificationsManager

This commit is contained in:
rabuzarus 2016-08-01 18:18:11 +02:00
parent 52f641904b
commit 7a4be1cead
11 changed files with 330 additions and 332 deletions

View file

@ -5,6 +5,7 @@
require_once('include/html2plain.php'); require_once('include/html2plain.php');
require_once("include/datetime.php"); require_once("include/datetime.php");
require_once("include/bbcode.php"); require_once("include/bbcode.php");
require_once("include/dbm.php");
/** /**
* @brief Read and write notifications from/to database * @brief Read and write notifications from/to database
@ -146,87 +147,56 @@ class NotificationsManager {
'label' => t('System'), 'label' => t('System'),
'url'=>'notifications/system', 'url'=>'notifications/system',
'sel'=> (($this->a->argv[1] == 'system') ? 'active' : ''), 'sel'=> (($this->a->argv[1] == 'system') ? 'active' : ''),
'id' => 'system-tab',
'accesskey' => 'y', 'accesskey' => 'y',
), ),
array( array(
'label' => t('Network'), 'label' => t('Network'),
'url'=>'notifications/network', 'url'=>'notifications/network',
'sel'=> (($this->a->argv[1] == 'network') ? 'active' : ''), 'sel'=> (($this->a->argv[1] == 'network') ? 'active' : ''),
'id' => 'network-tab',
'accesskey' => 'w', 'accesskey' => 'w',
), ),
array( array(
'label' => t('Personal'), 'label' => t('Personal'),
'url'=>'notifications/personal', 'url'=>'notifications/personal',
'sel'=> (($this->a->argv[1] == 'personal') ? 'active' : ''), 'sel'=> (($this->a->argv[1] == 'personal') ? 'active' : ''),
'id' => 'personal-tab',
'accesskey' => 'r', 'accesskey' => 'r',
), ),
array( array(
'label' => t('Home'), 'label' => t('Home'),
'url' => 'notifications/home', 'url' => 'notifications/home',
'sel'=> (($this->a->argv[1] == 'home') ? 'active' : ''), 'sel'=> (($this->a->argv[1] == 'home') ? 'active' : ''),
'id' => 'home-tab',
'accesskey' => 'h', 'accesskey' => 'h',
), ),
array( array(
'label' => t('Introductions'), 'label' => t('Introductions'),
'url' => 'notifications/intros', 'url' => 'notifications/intros',
'sel'=> (($this->a->argv[1] == 'intros') ? 'active' : ''), 'sel'=> (($this->a->argv[1] == 'intros') ? 'active' : ''),
'id' => 'intro-tab',
'accesskey' => 'i', '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; 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 if (dbm::is_result($notifs)) {
$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) { foreach ($notifs as $it) {
// switch ($notifs['ident']) { if($it['unseen'])
// case 'system': $it['seen'] = ($it['unseen'] > 0 ? false : true);
// $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 ($ident) {
switch ($notifs['ident']) {
case 'system': case 'system':
$default_item_label = 'notify';
$default_item_link = app::get_baseurl(true).'/notify/view/'. $it['id']; $default_item_link = app::get_baseurl(true).'/notify/view/'. $it['id'];
$default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO); $default_item_image = proxy_url($it['photo'], false, PROXY_SIZE_MICRO);
$default_item_text = strip_tags(bbcode($it['msg'])); $default_item_text = strip_tags(bbcode($it['msg']));
@ -235,6 +205,7 @@ class NotificationsManager {
break; break;
case 'home': case 'home':
$default_item_label = 'comment';
$default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid'];
$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); $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_text = sprintf( t("%s commented on %s's post"), $it['author-name'], $it['pname']);
@ -243,6 +214,7 @@ class NotificationsManager {
break; break;
default: default:
$default_item_label = (($it['id'] == $it['parent']) ? 'post' : 'comment');
$default_item_link = app::get_baseurl(true).'/display/'.$it['pguid']; $default_item_link = app::get_baseurl(true).'/display/'.$it['pguid'];
$default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO); $default_item_image = proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO);
$default_item_text = (($it['id'] == $it['parent']) $default_item_text = (($it['id'] == $it['parent'])
@ -255,23 +227,27 @@ class NotificationsManager {
switch($it['verb']){ switch($it['verb']){
case ACTIVITY_LIKE: 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' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
'$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], 'label' => 'like',
'$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), 'link' => app::get_baseurl(true).'/display/'.$it['pguid'],
'$item_text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']), '$image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
'$item_when' => relative_date($it['created']) 'text' => sprintf( t("%s liked %s's post"), $it['author-name'], $it['pname']),
)); 'when' => relative_date($it['created']),
'seen' => $it['seen']
);
break; break;
case ACTIVITY_DISLIKE: 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' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
'$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], 'label' => 'dislike',
'$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), 'link' => app::get_baseurl(true).'/display/'.$it['pguid'],
'$item_text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']), 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
'$item_when' => relative_date($it['created']) 'text' => sprintf( t("%s disliked %s's post"), $it['author-name'], $it['pname']),
)); 'when' => relative_date($it['created']),
'seen' => $it['seen']
);
break; break;
case ACTIVITY_FRIEND: case ACTIVITY_FRIEND:
@ -279,28 +255,235 @@ class NotificationsManager {
$obj = parse_xml_string($xmlhead.$it['object']); $obj = parse_xml_string($xmlhead.$it['object']);
$it['fname'] = $obj->title; $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' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
'$item_link' => app::get_baseurl(true).'/display/'.$it['pguid'], 'label' => 'friend',
'$item_image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO), 'link' => app::get_baseurl(true).'/display/'.$it['pguid'],
'$item_text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']), 'image' => proxy_url($it['author-avatar'], false, PROXY_SIZE_MICRO),
'$item_when' => relative_date($it['created']) 'text' => sprintf( t("%s is now friends with %s"), $it['author-name'], $it['fname']),
)); 'when' => relative_date($it['created']),
'seen' => $it['seen']
);
break; break;
default: default:
$notif_content[] = replace_macros($default_tpl,array( $notif = array(
//'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'], //'$item_link' => $a->get_baseurl(true).'/display/'.$a->user['nickname']."/".$it['parent'],
'$item_link' => $default_item_link, 'label' => $default_item_label,
'$item_image' => $default_item_image, 'link' => $default_item_link,
'$item_text' => $default_item_text, 'image' => $default_item_image,
'$item_when' => $default_item_when '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;
}
}
} }

View file

@ -67,6 +67,7 @@ function notifications_content(&$a) {
return; return;
} }
$show = (x($_REQUEST,'show') ? $_REQUEST['show'] : 0);
nav_set_selected('notifications'); nav_set_selected('notifications');
$json = (($a->argc > 1 && $a->argv[$a->argc - 1] === 'json') ? true : false); $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_header = t('Notifications');
$notif_tpl = get_markup_template('notifications.tpl'); $notif_tpl = get_markup_template('notifications.tpl');
$notif_ignored_lnk .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >' // $notif_show_lnk .= '<a href="' . ((strlen($sql_extra)) ? 'notifications/intros/all' : 'notifications/intros' ) . '" id="notifications-show-hide-link" >'
. ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\r\n"; // . ((strlen($sql_extra)) ? t('Show Ignored Requests') : t('Hide Ignored Requests')) . '</a></div>' . "\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 ", WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
intval($_SESSION['uid']) intval($_SESSION['uid'])
); );
if($r && count($r)) { if(dbm::is_result($r)) {
$a->set_pager_total($r[0]['total']); $a->set_pager_total($r[0]['total']);
$a->set_pager_itemspage(20); $a->set_pager_itemspage(20);
} }
@ -114,7 +121,7 @@ function notifications_content(&$a) {
WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ", WHERE `intro`.`uid` = %d $sql_extra AND `intro`.`blocked` = 0 ",
intval($_SESSION['uid'])); intval($_SESSION['uid']));
if(($r !== false) && (count($r))) { if(dbm::is_result($r)) {
$sugg = get_markup_template('suggestions.tpl'); $sugg = get_markup_template('suggestions.tpl');
$tpl = get_markup_template("intros.tpl"); $tpl = get_markup_template("intros.tpl");
@ -240,82 +247,16 @@ function notifications_content(&$a) {
$notif_header = t('Network Notifications'); $notif_header = t('Network Notifications');
$notif_tpl = get_markup_template('notifications.tpl'); $notif_tpl = get_markup_template('notifications.tpl');
$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, $notifs = $nm->networkNotifs($show);
`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` $notif_show_lnk = array(
FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent` 'href' => ($show ? 'notifications/network' : 'notifications/network?show=all' ),
WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND `pitem`.`parent` != 0 AND 'text' => ($show ? t('Show unread') : t('Show all')),
`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'); if(!dbm::is_result($notifs)) {
// $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); if($show)
// $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); $notif_show_lnk = array();
// $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 {
$notif_nocontent = t('No more network notifications.'); $notif_nocontent = t('No more network notifications.');
} }
@ -325,28 +266,17 @@ function notifications_content(&$a) {
$notif_header = t('System Notifications'); $notif_header = t('System Notifications');
$notif_tpl = get_markup_template('notifications.tpl'); $notif_tpl = get_markup_template('notifications.tpl');
$not_tpl = get_markup_template('notify.tpl'); $notifs = $nm->systemNotifs($show);
require_once('include/bbcode.php');
$r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc", $notif_show_lnk = array(
intval(local_user()) 'href' => ($show ? 'notifications/system' : 'notifications/system?show=all' ),
'text' => ($show ? t('Show unread') : t('Show all')),
); );
if (count($r) > 0) { if(!dbm::is_result($notifs)) {
// foreach ($r as $it) { if($show)
// $notif_content[] = replace_macros($not_tpl,array( $notif_show_lnk = 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.'); $notif_nocontent = t('No more system notifications.');
} }
@ -355,94 +285,16 @@ function notifications_content(&$a) {
$notif_header = t('Personal Notifications'); $notif_header = t('Personal Notifications');
$notif_tpl = get_markup_template('notifications.tpl'); $notif_tpl = get_markup_template('notifications.tpl');
$myurl = $a->get_baseurl(true) . '/profile/'. $a->user['nickname']; $notifs = $nm->personalNotifs($show);
$myurl = substr($myurl,strpos($myurl,'://')+3);
$myurl = str_replace(array('www.','.'),array('','\\.'),$myurl); $notif_show_lnk = array(
$diasp_url = str_replace('/profile/','/u/',$myurl); 'href' => ($show ? 'notifications/personal' : 'notifications/personal?show=all' ),
$sql_extra .= sprintf(" AND ( `item`.`author-link` regexp '%s' or `item`.`tag` regexp '%s' or `item`.`tag` regexp '%s' ) ", 'text' => ($show ? t('Show unread') : t('Show all')),
dbesc($myurl . '$'),
dbesc($myurl . '\\]'),
dbesc($diasp_url . '\\]')
); );
if(!dbm::is_result($notifs)) {
$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, if($show)
`item`.`author-link`, `item`.`author-avatar`, `item`.`created`, `item`.`object` as `object`, $notif_show_lnk = array();
`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 {
$notif_nocontent = t('No more personal notifications.'); $notif_nocontent = t('No more personal notifications.');
} }
@ -452,90 +304,53 @@ function notifications_content(&$a) {
$notif_header = t('Home Notifications'); $notif_header = t('Home Notifications');
$notif_tpl = get_markup_template('notifications.tpl'); $notif_tpl = get_markup_template('notifications.tpl');
$r = q("SELECT `item`.`id`,`item`.`parent`, `item`.`verb`, `item`.`author-name`, $notifs = $nm->homeNotifs($show);
`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` $notif_show_lnk = array(
FROM `item` INNER JOIN `item` as `pitem` ON `pitem`.`id`=`item`.`parent` 'href' => ($show ? 'notifications/home' : 'notifications/home?show=all' ),
WHERE `item`.`unseen` = 1 AND `item`.`visible` = 1 AND 'text' => ($show ? t('Show unread') : t('Show all')),
`item`.`deleted` = 0 AND `item`.`uid` = %d AND `item`.`wall` = 1 ORDER BY `item`.`created` DESC",
intval(local_user())
); );
// $tpl_item_likes = get_markup_template('notifications_likes_item.tpl'); if(!dbm::is_result($notifs)) {
// $tpl_item_dislikes = get_markup_template('notifications_dislikes_item.tpl'); if($show)
// $tpl_item_friends = get_markup_template('notifications_friends_item.tpl'); $notif_show_lnk = array();
// $tpl_item_comments = get_markup_template('notifications_comments_item.tpl');
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.'); $notif_nocontent = t('No more home notifications.');
} }
} }
if(count($notifs['notifications']) > 0 ) if(count($notifs['notifications']) > 0 ) {
$notif_content =$nm->format ($notifs); // 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( $o .= replace_macros($notif_tpl, array(
'$notif_header' => $notif_header, '$notif_header' => $notif_header,
'$tabs' => $tabs, '$tabs' => $tabs,
'$notif_content' => $notif_content, '$notif_content' => $notif_content,
'$notif_nocontent' => $notif_nocontent, '$notif_nocontent' => $notif_nocontent,
'$notif_ignored_lnk' => $notif_ignored_lnk, '$notif_show_lnk' => $notif_show_lnk,
)); ));
$o .= paginate($a); $o .= paginate($a);

View file

@ -6,7 +6,7 @@
<div class="notif-network-wrapper"> <div class="notif-network-wrapper">
{{* The "show ignored" link *}} {{* The "show ignored" link *}}
{{if $notif_ignored_lnk}}{{$notif_ignored_lnk}}{{/if}} {{if $notif_show_lnk}}<a href="{{$notif_show_lnk.href}}" id="notifications-show-hide-link">{{$notif_show_lnk.text}}</a>{{/if}}
{{* The notifications *}} {{* The notifications *}}
{{if $notif_content}} {{if $notif_content}}

View file

@ -1,4 +1,4 @@
<div class="notif-item"> <div class="notif-item {{if !$item_seen}}unseen{{/if}}">
<a href="{{$item_link}}" target="friendica-notifications"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a> <a href="{{$item_link}}" target="friendica-notifications"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a>
</div> </div>

View file

@ -1,4 +1,4 @@
<div class="notif-item"> <div class="notif-item {{if !$item_seen}}unseen{{/if}}">
<a href="{{$item_link}}" target="friendica-notifications"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a> <a href="{{$item_link}}" target="friendica-notifications"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a>
</div> </div>

View file

@ -1,4 +1,4 @@
<div class="notif-item"> <div class="notif-item {{if !$item_seen}}unseen{{/if}}">
<a href="{{$item_link}}" target="friendica-notifications"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a> <a href="{{$item_link}}" target="friendica-notifications"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a>
</div> </div>

View file

@ -1,4 +1,4 @@
<div class="notif-item"> <div class="notif-item {{if !$item_seen}}unseen{{/if}}">
<a href="{{$item_link}}" target="friendica-notification"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a> <a href="{{$item_link}}" target="friendica-notification"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a>
</div> </div>

View file

@ -1,4 +1,4 @@
<div class="notif-item"> <div class="notif-item {{if !$item_seen}}unseen{{/if}}">
<a href="{{$item_link}}" target="friendica-notifications"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a> <a href="{{$item_link}}" target="friendica-notifications"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a>
</div> </div>

View file

@ -1,4 +1,4 @@
<div class="notif-item"> <div class="notif-item {{if !$item_seen}}unseen{{/if}}">
<a href="{{$item_link}}" target="friendica-notifications"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a> <a href="{{$item_link}}" target="friendica-notifications"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a>
</div> </div>

View file

@ -1,4 +1,4 @@
<div class="notif-item"> <div class="notif-item {{if !$item_seen}}unseen{{/if}}">
<a href="{{$item_link}}" target="friendica-notifications"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a> <a href="{{$item_link}}" target="friendica-notifications"><img src="{{$item_image}}" class="notif-image">{{$item_text}} <span class="notif-when">{{$item_when}}</span></a>
</div> </div>

View file

@ -6,7 +6,7 @@
<div class="notif-network-wrapper"> <div class="notif-network-wrapper">
{{* The "show ignored" link *}} {{* The "show ignored" link *}}
{{if $notif_ignored_lnk}}{{$notif_ignored_lnk}}{{/if}} {{if $notif_show_lnk}}<a href="{{$notif_show_lnk.href}}" id="notifications-show-hide-link">{{$notif_show_lnk.text}}</a>{{/if}}
{{* The notifications *}} {{* The notifications *}}
{{if $notif_content}} {{if $notif_content}}