aboutsummaryrefslogtreecommitdiffstats
path: root/mod/mood.php
blob: 98064beab7d84a9b24c79857531aa175ad33b185 (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
<?php

require_once('include/security.php');
require_once('include/bbcode.php');
require_once('include/items.php');


function mood_init(&$a) {

	if(! local_user())
		return;

	$uid = local_user();
	$verb = notags(trim($_GET['verb']));
	
	if(! $verb) 
		return;

	$verbs = get_mood_verbs();

	if(! in_array($verb,$verbs))
		return;

	$activity = ACTIVITY_MOOD . '#' . urlencode($verb);

	$parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : 0);


	logger('mood: verb ' . $verb, LOGGER_DEBUG);


	if($parent) {
		$r = q("select uri, owner_xchan, private, allow_cid, allow_gid, deny_cid, deny_gid 
			from item where id = %d and parent = %d and uid = %d limit 1",
			intval($parent),
			intval($parent),
			intval($uid)
		);
		if(count($r)) {
			$parent_uri = $r[0]['uri'];
			$private    = $r[0]['private'];
			$allow_cid  = $r[0]['allow_cid'];
			$allow_gid  = $r[0]['allow_gid'];
			$deny_cid   = $r[0]['deny_cid'];
			$deny_gid   = $r[0]['deny_gid'];
		}
	}
	else {

		$private       = 0;
		$channel       = $a->get_channel();

		$allow_cid     =  $channel['channel_allow_cid'];
		$allow_gid     =  $channel['channel_allow_gid'];
		$deny_cid      =  $channel['channel_deny_cid'];
		$deny_gid      =  $channel['channel_deny_gid'];
	}

	$poster = $a->get_observer();

	$uri = item_message_id();

	$action = sprintf( t('%1$s is currently %2$s'), '[url=' . $poster['xchan_url'] . ']' . $poster['xchan_name'] . '[/url]' , $verbs[$verb]); 
	$item_flags = ITEM_WALL|ITEM_ORIGIN|ITEM_UNSEEN;
	if(! $parent_uri)
		$item_flags |= ITEM_THREAD_TOP;


	$arr = array();

	$arr['aid']           = get_account_id();
	$arr['uid']           = $uid;
	$arr['uri']           = $uri;
	$arr['parent_uri']    = (($parent_uri) ? $parent_uri : $uri);
	$arr['item_flags']    = $item_flags;
	$arr['author_xchan']  = $poster['xchan_hash'];
	$arr['owner_xchan']   = (($parent_uri) ? $r[0]['owner_xchan'] : $poster['xchan_hash']);
	$arr['title']         = '';
	$arr['allow_cid']     = $allow_cid;
	$arr['allow_gid']     = $allow_gid;
	$arr['deny_cid']      = $deny_cid;
	$arr['deny_gid']      = $deny_gid;
	$arr['verb']          = $activity;
	$arr['body']          = $action;

	$item_id = item_store($arr);
	if($item_id) {
//		q("UPDATE `item` SET `plink` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1",
//			dbesc($a->get_baseurl() . '/display/' . $poster['nickname'] . '/' . $item_id),
//			intval($uid),
//			intval($item_id)
//		);

		proc_run('php',"include/notifier.php","activity", $item_id);

	}

	call_hooks('post_local_end', $arr);

	if($_SESSION['return_url'])
		goaway(z_root() . '/' . $_SESSION['return_url']);

	return;
}



function mood_content(&$a) {

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

	$parent = ((x($_GET,'parent')) ? intval($_GET['parent']) : '0');



	$verbs = get_mood_verbs();

	$shortlist = array();
	foreach($verbs as $k => $v)
		if($v !== 'NOTRANSLATION')
			$shortlist[] = array($k,$v);


	$tpl = get_markup_template('mood_content.tpl');

	$o = replace_macros($tpl,array(
		'$title' => t('Mood'),
		'$desc' => t('Set your current mood and tell your friends'),
		'$verbs' => $shortlist,
		'$parent' => $parent,
		'$submit' => t('Submit'),
	));

	return $o;

}