aboutsummaryrefslogtreecommitdiff
path: root/mod/event_connect/start.php
blob: 46062a957437acb94d1af0be4d3c2db4dc646c60 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
 * Event Connector
 *
 * @package ElggEventConnector
 */

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

function event_connector_init() {
	
	elgg_register_library('vendors:icalcreator', elgg_get_plugins_path() . 'event_connector/vendors/iCalcreator.class.php');
	
	// Register a page handler, so we can have nice URLs
	elgg_register_page_handler('event_connector', 'event_connector_page_handler');
	
	elgg_register_event_handler('pagesetup', 'system', 'event_connector_pagesetup');

	// Register actions
	elgg_register_action("event_connector/import", elgg_get_plugins_path() . "event_connector/actions/event_connector/import.php");

}

/**
 * Dispatcher for ical.
 * URLs take the form of
 *  Import events:    event_connector/import/<guid>
 * 
 * @param array $page
 * @return bool
 */
function event_connector_page_handler($page) {
	if (!isset($page[0])) {
		$page[0] = 'import';
	}

	elgg_push_breadcrumb(elgg_echo('event_calendar:show_events_title'), 'event_calendar/list');

	$base_dir = elgg_get_plugins_path() . 'event_connector/pages/event_connector';

	$page_type = $page[0];
	switch ($page_type) {
		case 'import':
			set_input('guid', $page[1]);
			include "$base_dir/import.php";
			break;
		default:
			return false;
	}
	return true;
}

function event_connector_pagesetup() {
	$event_id = get_input('event_id', 0);
	$filter = get_input('filter', 'all');
	$original_start_date = get_input('start_date',0);
	$mode = trim(get_input('mode',''));
	$group_guid = (int) get_input('group_guid',0);
	$offset = (int) get_input('offset',0);
	$region = get_input('region',0);
	$param = "filter={$filter}";
	if($original_start_date)
		$param .= "&start_date={$original_start_date}";
	if($mode != '')
		$param .= "&mode={$mode}";
	if($group_guid)
		$param .= "&group_guid={$group_guid}";
	if($offset)
		$param .= "&offset={$offset}";
	if($region)
		$param .= "&region={$region}";
	if (elgg_get_context() == 'event_calendar' && !(strpos($_SERVER['REQUEST_URI'], '/manage_event')) && !(strpos($_SERVER['REQUEST_URI'], '/delete_confirm')) && !(strpos($_SERVER['REQUEST_URI'], '/event_connector'))) {
		if($event_id ) {
			add_submenu_item(elgg_echo('event_connector:menu:one'), elgg_get_site_url() . "mod/event_connector/export_event.php?event_id={$event_id}");
		}
		else {
			add_submenu_item(elgg_echo('event_connector:menu:all'), elgg_get_site_url() . "mod/event_connector/export_events.php?{$param}");
		}
		elgg_register_title_button('event_connector', 'import');
	} else if(elgg_get_context() == 'groups' && strpos($_SERVER['REQUEST_URI'], 'event_calendar/') && !(strpos($_SERVER['REQUEST_URI'], '/manage_event')) && !(strpos($_SERVER['REQUEST_URI'], '/delete_confirm')) && !(strpos($_SERVER['REQUEST_URI'], '/event_connector'))) {
		if($event_id) {
			add_submenu_item(elgg_echo('event_connector:menu:title'), elgg_get_site_url() . "mod/event_connector/export_event.php?event_id={$event_id}");
		}
		else {
			add_submenu_item(elgg_echo('event_connector:menu:title'), elgg_get_site_url() . "mod/event_connector/export_events.php?{$param}");
		}
		elgg_register_title_button('event_connector', 'import');
	}
}