aboutsummaryrefslogtreecommitdiff
path: root/start.php
blob: e044cc9b5fee04241cf03e0317662e0f28482389 (plain)
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
<?php
/**
 * Elgg friend request plugin.
 *
 * @package ElggFriendRequest
 */

elgg_register_event_handler('init', 'system', 'friendrequest_init');

function friendrequest_init() {
	
	//This will let users view their friend requests
	elgg_register_page_handler('friendrequests', 'friendrequest_page_handler');
	
	if (elgg_is_logged_in()) {
		$params = array(
				'name' => 'friendrequests',
				'text' => elgg_echo('friendrequest'),
				'href' => "friendrequests",
				'contexts' => array('friends'),
		);
		elgg_register_menu_item('page', $params);
	}
	
	//We need to override the friend remove action to remove the relationship we created
	$actions_dir = elgg_get_plugins_path().'friendrequest/actions/friends';
	elgg_register_action('friends/add', "$actions_dir/add.php");
	elgg_register_action('friends/remove', "$actions_dir/remove.php");
   	
   	$actions_dir = elgg_get_plugins_path().'friendrequest/actions/friendrequest';
	elgg_register_action('friendrequest/decline', "$actions_dir/decline.php");
   	
   	//Regular Elgg engine sends out an email via an event. The 400 priority will let us run first.
	//Then we return false to stop the event chain. The normal event handler will never get to run.
	//elgg_register_event_handler('create', 'friend', 'friendrequest_event_create_friend', 400);
	
	//Handle our add action event:
	//elgg_register_event_handler('create', 'friendrequest', 'friendrequest_event_create_friendrequest');
	
}

function friendrequest_page_handler($page){
	
	//Keep the URLs uniform:
	if (isset($page[0])) {
		forward("friendrequests");
	}
	
	elgg_push_context('friends');
	
	$params = array(
		'title' => elgg_echo('friendrequest'),
		'filter' => '',
	);
	
	$body = elgg_view_layout('content', $params);

	echo elgg_view_page($params['title'], $body);
	return true;
}

function friendrequest_event_create_friend($event, $object_type, $object){
	if (($object instanceof ElggRelationship) && ($event == 'create') && ($object_type == 'friend')) {
		//We don't want anything happening here... (no email/etc)
		
		//Returning false will interrupt the rest of the chain.
		//The normal handler for the create friend event has a priority of 500 so it will never be called.	
		return false;
	}
	return true; //Shouldn't get here...
}

function friendrequest_event_create_friendrequest($event, $object_type, $object){
	
}