aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Notifications.php
blob: 8ecf5760aa8d97e261b52eec34eaa0b08b4c0696 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
namespace Zotlabs\Module;

require_once('include/bbcode.php');

class Notifications extends \Zotlabs\Web\Controller {

	function get() {

		if(! local_channel()) {
			notice( t('Permission denied.') . EOL);
			return;
		}

		nav_set_selected('Notifications');

		$o = '';
		$notif_content = '';
		$notifications_available = false;

		$r = q("select count(*) as total from notify where uid = %d and seen = 0",
			intval(local_channel())
		);
		if($r && intval($r[0]['total']) > 49) {
			$r = q("select * from notify where uid = %d
				and seen = 0 order by created desc limit 50",
				intval(local_channel())
			);
		}
		else {
			$r1 = q("select * from notify where uid = %d
				and seen = 0 order by created desc limit 50",
				intval(local_channel())
			);
			$r2 = q("select * from notify where uid = %d
				and seen = 1 order by created desc limit %d",
				intval(local_channel()),
				intval(50 - intval($r[0]['total']))
			);
			$r = array_merge($r1,$r2);
		}

		if($r) {
			$notifications_available = true;
			foreach ($r as $rr) {
				$x = strip_tags(bbcode($rr['msg']));
				$notif_content .= replace_macros(get_markup_template('notify.tpl'),array(
					'$item_link' => z_root().'/notify/view/'. $rr['id'],
					'$item_image' => $rr['photo'],
					'$item_text' => $x,
					'$item_when' => relative_date($rr['created']),
					'$item_seen' => (($rr['seen']) ? true : false),
					'$new' => t('New')
				));
			}
		}
		else {
			$notif_content = t('No more system notifications.');
		}

		$o .= replace_macros(get_markup_template('notifications.tpl'),array(
			'$notif_header' => t('System Notifications'),
			'$notif_link_mark_seen' => t('Mark all seen'),
			'$notif_content' => $notif_content,
			'$notifications_available' => $notifications_available,
		));

		return $o;
	}

}