aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Module/Pin.php
blob: 65bb61a7610b067cb486bf5a91e7a1b9de3ab308 (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
<?php
namespace Zotlabs\Module;

/*
 * Pinned post processing
 */

use App;

class Pin extends \Zotlabs\Web\Controller {


	function init() {

		if(argc() !== 1)
			http_status_exit(400, 'Bad request');

		if(! local_channel())
			http_status_exit(403, 'Forbidden');
	}


	function post() {

		$item_id = intval($_POST['id']);

		if ($item_id <= 0)
			http_status_exit(404, 'Not found');

		$channel = \App::get_channel();

		$r = q("SELECT * FROM item WHERE id = %d AND id = parent AND uid = %d AND owner_xchan = '%s' AND item_private = 0 LIMIT 1",
			$item_id,
			intval($channel['channel_id']),
			dbesc($channel['xchan_hash'])
		);
		if(!$r) {
			notice(t('Unable to locate original post.'));
			http_status_exit(404, 'Not found');
		}
		else {
			// Currently allow only one pinned item for each type
			$midb64 = 'b64.' . base64url_encode($r[0]['mid']);
			$pinned = (in_array($midb64, get_pconfig($channel['channel_id'], 'pinned', $r[0]['item_type'], [])) ? [] : [ $midb64 ]);
			set_pconfig($channel['channel_id'], 'pinned', $r[0]['item_type'], $pinned);
			
			build_sync_packet($channel['channel_id'], [ 'config' ]);
		}
	}
}