aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Widget/Conversations.php
blob: fa59ce20cc6be89b3fe1ce584c326335b69d5a8b (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
72
73
74
<?php

namespace Zotlabs\Widget;

class Conversations {

	function widget($arr) {

		if (! local_channel())
			return;

		if(argc() > 1) {

			switch(argv(1)) {
				case 'combined':
					$mailbox = 'combined';
					$header = t('Conversations');
					break;
				case 'inbox':
					$mailbox = 'inbox';
					$header = t('Received Messages');
					break;
				case 'outbox':
					$mailbox = 'outbox';
					$header = t('Sent Messages');
					break;
				default:
					$mailbox = 'combined';
					$header = t('Conversations');
					break;
			}

			require_once('include/message.php');

			// private_messages_list() can do other more complicated stuff, for now keep it simple
			$r = private_messages_list(local_channel(), $mailbox, App::$pager['start'], App::$pager['itemspage']);

			if(! $r) {
				info( t('No messages.') . EOL);
				return $o;
			}

			$messages = array();

			foreach($r as $rr) {

				$messages[] = array(
					'mailbox'      => $mailbox,
					'id'           => $rr['id'],
					'from_name'    => $rr['from']['xchan_name'],
					'from_url'     => chanlink_hash($rr['from_xchan']),
					'from_photo'   => $rr['from']['xchan_photo_s'],
					'to_name'      => $rr['to']['xchan_name'],
					'to_url'       => chanlink_hash($rr['to_xchan']),
					'to_photo'     => $rr['to']['xchan_photo_s'],
					'subject'      => (($rr['seen']) ? $rr['title'] : '<strong>' . $rr['title'] . '</strong>'),
					'delete'       => t('Delete conversation'),
					'body'         => $rr['body'],
					'date'         => datetime_convert('UTC',date_default_timezone_get(),$rr['created'], 'c'),
					'seen'         => $rr['seen'],
					'selected'     => ((argv(2)) ? (argv(2) == $rr['id']) : ($r[0]['id'] == $rr['id']))
				);
			}

			$tpl = get_markup_template('mail_head.tpl');
			$o .= replace_macros($tpl, array(
				'$header' => $header,
				'$messages' => $messages
			));

		}
		return $o;
	}
}