aboutsummaryrefslogtreecommitdiff
path: root/mod/graphstats/start.php
blob: cf5f2b4f53be09ae281dc870ee09e1cb19a874b9 (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
<?php
/**
 * Elgg graph stats.
 *
 * @package ElggGraphStats
 */

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

function graphstats_init() {
	
	$timestats_path = elgg_get_plugins_path() . 'graphstats/lib/timestats.php';
	elgg_register_library('elgg:graphs:timestats', $timestats_path);
	
	elgg_register_page_handler('graphs', 'graphstats_pagehandler');
	
	// register the timeline's JavaScript
	$timeline_js = elgg_get_simplecache_url('js', 'timeline');
	elgg_register_js('simile.timeline', $timeline_js);
	
	// register the raphael's Javascript
	$raphael_js = elgg_get_simplecache_url('js', 'raphael/raphael');
	elgg_register_js('raphael', $raphael_js, 'head');
	
	// register the raphael analytics's Javascript
	$analytics_js = elgg_get_simplecache_url('js', 'raphael/analytics');
	elgg_register_js('raphael.analytics', $analytics_js, 'head');
	
	// Modifying group activity pagehander
	elgg_register_plugin_hook_handler('route','groups', 'graphstats_setup_title_button');
}

/**
 * Dispatches graphs pages.
 * URLs take the form of
 *  Time stats:      graphs/timestats/[?type=<type>&subtype=<subtype>][&relative=true]
 *  Group network:   graphs/groupnetwork/
 *  Implication:     graphs/implication/
 *  Group timeline:  graphs/group/<guid>/
 * 
 * @param array $page
 * @return NULL
 */
function graphstats_pagehandler($page){
	$graphstats_dir = elgg_get_plugins_path() . 'graphstats/pages/graphstats';
	
	$page_type = $page[0];
	switch ($page_type) {
		case 'timestats':
			include "$graphstats_dir/timestats.php";
			break;
		case 'groupnetwork':
			break;
		case 'implication':
			break;
		case 'group':
			set_input('group_guid', $page[1]);
			include "$graphstats_dir/group.php";
			break;
	}
}

function graphstats_setup_title_button($hook, $type, $params, $return){
	$page_type = $params['segments'][0];
	$group_guid = $params['segments'][1];
	
	if($page_type == 'activity'){
		add_translation(get_current_language(), array('graphs:group' => elgg_echo('timeline')));
		elgg_set_page_owner_guid((int) $group_guid);
		elgg_register_title_button('graphs', 'group');
	}
}