aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Widget/Activity_filter.php
blob: daaf5fb67932b16ca5001c6f83122ac5dfd8c5f3 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php

/**
 *   * Name: Activity filters
 *   * Description: Filters for the network stream
 *   * Requires: network
 */


namespace Zotlabs\Widget;

use App;
use Zotlabs\Lib\Apps;

class Activity_filter {

	function widget($arr) {

		if(! local_channel())
			return '';

		$filter_active  = '';
		$dm_active      = '';
		$events_active  = '';
		$polls_active   = '';
		$starred_active = '';
		$conv_active    = '';
		$tabs           = [];
		$cmd            = \App::$cmd;

		if(x($_GET,'dm')) {
			$dm_active = (($_GET['dm'] == 1) ? 'active' : '');
			$filter_active = 'dm';
		}

		if(x($_GET,'verb')) {
			$events_active = (($_GET['verb'] == '.Event') ? 'active' : '');
			$polls_active = (($_GET['verb'] == '.Question') ? 'active' : '');
			$filter_active = (($events_active) ? 'events' : 'polls');
		}


		$tabs[] = [
			'label' => t('Direct Messages'),
			'icon' => 'envelope-o',
			'url' => z_root() . '/' . $cmd . '/?f=&dm=1',
			'sel' => $dm_active,
			'title' => t('Show direct (private) messages')
		];

		if(feature_enabled(local_channel(),'events_tab')) {
			$tabs[] = [
				'label' => t('Events'),
				'icon' => 'calendar',
				'url' => z_root() . '/' . $cmd . '/?verb=%2EEvent',
				'sel' => $events_active,
				'title' => t('Show posts that include events')
			];
		}

		if(feature_enabled(local_channel(),'polls_tab')) {
			$tabs[] = [
				'label' => t('Polls'),
				'icon' => 'bar-chart',
				'url' => z_root() . '/' . $cmd . '/?verb=%2EQuestion',
				'sel' => $polls_active,
				'title' => t('Show posts that include polls')
			];
		}


		if(Apps::system_app_installed(local_channel(), 'Privacy Groups')) {
			$groups = q("SELECT * FROM pgrp WHERE deleted = 0 AND uid = %d ORDER BY gname ASC",
				intval(local_channel())
			);

			if($groups) {
				$group_active = '';

				foreach($groups as $g) {
					if(x($_GET,'gid')) {
						$group_active = (($_GET['gid'] == $g['id']) ? 'active' : '');
						$filter_active = 'group';
					}
					$gsub[] = [
						'label' => $g['gname'],
						'icon' => '',
						'url' => z_root() . '/' . $cmd . '/?f=&gid=' . $g['id'],
						'sel' => $group_active,
						'title' => sprintf(t('Show posts related to the %s privacy group'), $g['gname'])
					];
				}
				$tabs[] = [
					'id' => 'privacy_groups',
					'label' => t('Privacy Groups'),
					'icon' => 'users',
					'url' => '#',
					'sel' => (($filter_active == 'group') ? true : false),
					'title' => t('Show my privacy groups'),
					'sub' => $gsub

				];
			}
		}

		if(feature_enabled(local_channel(),'forums_tab')) {
			$forums = get_forum_channels(local_channel());
			$channel = App::get_channel();

			if($forums) {
				$forum_active = '';

				foreach($forums as $f) {
					if(x($_GET,'pf') && x($_GET,'cid')) {
						$forum_active = ((x($_GET,'pf') && $_GET['cid'] == $f['abook_id']) ? 'active' : '');
						$filter_active = 'forums';
					}
					$fsub[] = [
						'label' => $f['xchan_name'],
						'img' => $f['xchan_photo_s'],
						'url' => ((isset($f['private_forum'])) ? $f['xchan_url'] . '/?f=&zid=' . $channel['xchan_addr'] : z_root() . '/' . $cmd . '/?f=&pf=1&cid=' . $f['abook_id']),
						'sel' => $forum_active,
						'title' => t('Show posts to this forum'),
						'lock' => ((isset($f['private_forum'])) ? 'lock' : '')
					];
				}

				$tabs[] = [
					'id' => 'forums',
					'label' => t('Forums'),
					'icon' => 'comments-o',
					'url' => '#',
					'sel' => (($filter_active == 'forums') ? true : false),
					'title' => t('Show forums'),
					'sub' => $fsub

				];
			}
		}

		if(feature_enabled(local_channel(),'star_posts')) {
			if(x($_GET,'star')) {
				$starred_active = (($_GET['star'] == 1) ? 'active' : '');
				$filter_active = 'star';
			}

			$tabs[] = [
				'label' => t('Starred Posts'),
				'icon' => 'star',
				'url'=>z_root() . '/' . $cmd . '/?f=&star=1',
				'sel'=>$starred_active,
				'title' => t('Show posts that I have starred')
			];
		}

		if(feature_enabled(local_channel(),'personal_tab')) {
			if(x($_GET,'conv')) {
				$conv_active = (($_GET['conv'] == 1) ? 'active' : '');
				$filter_active = 'personal';
			}

			$tabs[] = [
				'label' => t('Personal Posts'),
				'icon' => 'user-circle',
				'url' => z_root() . '/' . $cmd . '/?f=&conv=1',
				'sel' => $conv_active,
				'title' => t('Show posts that mention or involve me')
			];
		}

		if(feature_enabled(local_channel(),'filing')) {
			$terms = q("select distinct term from term where uid = %d and ttype = %d order by term asc",
				intval(local_channel()),
				intval(TERM_FILE)
			);

			if($terms) {
				$file_active = '';

				foreach($terms as $t) {
					if(x($_GET,'file')) {
						$file_active = (($_GET['file'] == $t['term']) ? 'active' : '');
						$filter_active = 'file';
					}
					$tsub[] = [
						'label' => $t['term'],
						'icon' => '',
						'url' => z_root() . '/' . $cmd . '/?f=&file=' . $t['term'],
						'sel' => $file_active,
						'title' => sprintf(t('Show posts that I have filed to %s'), $t['term']),
					];
				}

				$tabs[] = [
					'id' => 'saved_folders',
					'label' => t('Saved Folders'),
					'icon' => 'folder',
					'url' => '#',
					'sel' => (($filter_active == 'file') ? true : false),
					'title' => t('Show filed post categories'),
					'sub' => $tsub

				];
			}
		}

		if(x($_GET,'search')) {
			$filter_active = 'search';
			$tabs[] = [
				'label' => t('Search'),
				'icon' => 'search',
				'url' => z_root() . '/' . $cmd . '/?f=&search=' . $_GET['search'],
				'sel' => 'active disabled',
				'title' => t('Panel search')
			];
		}

		$name = [];
		if(feature_enabled(local_channel(),'name_tab')) {
			if(x($_GET,'cid') && ! x($_GET,'pf')) {
				$filter_active = 'name';
			}
			$name = [
				'label' => x($_GET,'name') ? $_GET['name'] : t('Filter by name'),
				'icon' => 'filter',
				'url'=> z_root() . '/' . $cmd . '/',
				'sel'=> $filter_active == 'name' ? 'is-valid' : '',
				'title' => ''
			];
		}

		$reset = [];
		if($filter_active) {
			$reset = [
				'label' => '',
				'icon' => 'remove',
				'url'=> z_root() . '/' . $cmd,
				'sel'=> '',
				'title' => t('Remove active filter')
			];
		}

		$arr = ['tabs' => $tabs];

		call_hooks('activity_filter', $arr);

		$o = '';

		if($arr['tabs']) {
			$content =  replace_macros(get_markup_template('common_pills.tpl'), [
				'$pills' => $arr['tabs']
			]);

			$o .= replace_macros(get_markup_template('activity_filter_widget.tpl'), [
				'$title' => t('Stream Filters'),
				'$reset' => $reset,
				'$content' => $content,
				'$name' => $name
			]);
		}

		return $o;

	}

}