aboutsummaryrefslogtreecommitdiffstats
path: root/mod/chat.php
blob: 42a7808d981c54a6bb494f17ab07f3872e5f69aa (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
<?php /** @file */

require_once('include/chat.php');

function chat_init(&$a) {

	$which = null;
	if(argc() > 1)
		$which = argv(1);
	if(! $which) {
		if(local_user()) {
			$channel = $a->get_channel();
			if($channel && $channel['channel_address'])
			$which = $channel['channel_address'];
		}
	}
	if(! $which) {
		notice( t('You must be logged in to see this page.') . EOL );
		return;
	}

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

	if((local_user()) && (argc() > 2) && (argv(2) === 'view')) {
		$which = $channel['channel_address'];
		$profile = argv(1);		
	}

	$a->page['htmlhead'] .= '<link rel="alternate" type="application/atom+xml" href="' . $a->get_baseurl() . '/feed/' . $which .'" />' . "\r\n" ;

	// Run profile_load() here to make sure the theme is set before
	// we start loading content

	profile_load($a,$which,$profile);

}


function chat_content(&$a) {

	$observer = get_observer_hash();
	if(! $observer) {
		notice( t('Permission denied.') . EOL);
		return;
	}

	if(! perm_is_allowed($a->profile['profile_uid'],$observer,'chat')) {
		notice( t('Permission denied.') . EOL);
		return;
	}
	
	if((argc() > 3) && intval(argv(2)) && (argv(3) === 'leave')) {
		chatroom_leave($observer,$room_id,$_SERVER['REMOTE_ADDR']);
		goaway(z_root() . '/channel/' . argv(1));
	}


	if(argc() > 2 && intval(argv(2))) {
		$room_id = intval(argv(2));
		$x = chatroom_enter($observer,$room_id,'online',$_SERVER['REMOTE_ADDR']);
		if(! $x)
			return;
		$o = replace_macros(get_markup_template('chat.tpl'),array());
		return $o;
	}

}