streams/mod/notifications.php

106 lines
2.5 KiB
PHP
Raw Normal View History

2010-07-01 23:48:07 +00:00
<?php
function notifications_post(&$a) {
2010-08-16 04:49:29 +00:00
if(! local_user()) {
goaway(z_root());
2010-07-01 23:48:07 +00:00
}
2010-08-16 04:49:29 +00:00
$request_id = (($a->argc > 1) ? $a->argv[1] : 0);
2010-07-01 23:48:07 +00:00
if($request_id === "all")
2010-07-01 23:48:07 +00:00
return;
if($request_id) {
2011-06-27 04:55:24 +00:00
$r = q("SELECT * FROM `intro` WHERE `id` = %d AND `uid` = %d LIMIT 1",
intval($request_id),
intval(local_user())
2010-07-01 23:48:07 +00:00
);
if(count($r)) {
$intro_id = $r[0]['id'];
2010-11-07 00:01:57 +00:00
$contact_id = $r[0]['contact-id'];
2010-07-01 23:48:07 +00:00
}
else {
2010-08-16 04:49:29 +00:00
notice( t('Invalid request identifier.') . EOL);
2010-07-01 23:48:07 +00:00
return;
}
2011-06-27 04:55:24 +00:00
// If it is a friend suggestion, the contact is not a new friend but an existing friend
// that should not be deleted.
$fid = $r[0]['fid'];
2010-08-16 05:43:42 +00:00
if($_POST['submit'] == t('Discard')) {
2010-09-09 03:14:17 +00:00
$r = q("DELETE FROM `intro` WHERE `id` = %d LIMIT 1",
intval($intro_id)
);
2011-06-27 04:55:24 +00:00
if(! $fid) {
// The check for blocked and pending is in case the friendship was already approved
// and we just want to get rid of the now pointless notification
$r = q("DELETE FROM `contact` WHERE `id` = %d AND `uid` = %d AND `self` = 0 AND `blocked` = 1 AND `pending` = 1 LIMIT 1",
2011-06-27 04:55:24 +00:00
intval($contact_id),
intval(local_user())
);
}
2012-03-15 04:20:20 +00:00
goaway($a->get_baseurl(true) . '/notifications/intros');
2010-07-01 23:48:07 +00:00
}
2010-08-16 04:49:29 +00:00
if($_POST['submit'] == t('Ignore')) {
2010-07-01 23:48:07 +00:00
$r = q("UPDATE `intro` SET `ignore` = 1 WHERE `id` = %d LIMIT 1",
intval($intro_id));
2012-03-15 04:20:20 +00:00
goaway($a->get_baseurl(true) . '/notifications/intros');
2010-07-01 23:48:07 +00:00
}
}
}
function notifications_content(&$a) {
2010-08-16 04:49:29 +00:00
if(! local_user()) {
notice( t('Permission denied.') . EOL);
return;
2010-07-01 23:48:07 +00:00
}
2011-10-12 04:30:23 +00:00
nav_set_selected('notifications');
2010-08-16 04:49:29 +00:00
$o = '';
2013-07-22 00:45:36 +00:00
$notif_tpl = get_markup_template('notifications.tpl');
$not_tpl = get_markup_template('notify.tpl');
require_once('include/bbcode.php');
$r = q("SELECT * from notify where uid = %d and seen = 0 order by date desc",
intval(local_user())
);
if (count($r) > 0) {
$notifications_available =1;
foreach ($r as $it) {
$notif_content .= replace_macros($not_tpl,array(
2012-03-15 04:20:20 +00:00
'$item_link' => $a->get_baseurl(true).'/notify/view/'. $it['id'],
'$item_image' => $it['photo'],
'$item_text' => strip_tags(bbcode($it['msg'])),
'$item_when' => relative_date($it['date'])
));
}
} else {
$notif_content .= t('No more system notifications.');
}
$o .= replace_macros($notif_tpl,array(
'$notif_header' => t('System Notifications'),
2014-05-04 15:28:43 +00:00
'$notif_link_mark_seen' => t('Mark all system notifications seen'),
'$notif_content' => $notif_content,
'$notifications_available' => $notifications_available,
));
2010-07-01 23:48:07 +00:00
return $o;
}