aboutsummaryrefslogtreecommitdiff
path: root/mod/externalpages/start.php
blob: ce911bf107003b2f8a1e751000ec53a47ec8f6d4 (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
90
<?php
/**
 * Plugin for creating web pages for your site
 */

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

function expages_init() {

	// Register a page handler, so we can have nice URLs
	elgg_register_page_handler('about', 'expages_page_handler');
	elgg_register_page_handler('terms', 'expages_page_handler');
	elgg_register_page_handler('privacy', 'expages_page_handler');
	elgg_register_page_handler('expages', 'expages_page_handler');
	
	// Register public external pages
	elgg_register_plugin_hook_handler('public_pages', 'walled_garden', 'expages_public');

	// add a menu item for the admin edit page
	elgg_register_admin_menu_item('configure', 'expages', 'appearance');

	// add footer links
	expages_setup_footer_menu();

	// register action
	$actions_base = elgg_get_plugins_path() . 'externalpages/actions';
	elgg_register_action("expages/edit", "$actions_base/edit.php", 'admin');
}

/**
 * Extend the public pages range
 *
 */
function expages_public($hook, $handler, $return, $params){
	$pages = array('about', 'terms', 'privacy');
	return array_merge($pages, $return);
}

/**
 * Setup the links to site pages
 */
function expages_setup_footer_menu() {
	$pages = array('about', 'terms', 'privacy');
	foreach ($pages as $page) {
		$url = "$page";
		$item = new ElggMenuItem($page, elgg_echo("expages:$page"), $url);
		elgg_register_menu_item('footer', $item);
	}
}

/**
 * External pages page handler
 *
 * @param array  $page    URL segements
 * @param string $handler Handler identifier
 */
function expages_page_handler($page, $handler) {
	if ($handler == 'expages') {
		expages_url_forwarder($page[1]);
	}
	$type = strtolower($handler);

	$title = elgg_echo("expages:$type");
	$content = elgg_view_title($title);

	$object = elgg_get_entities(array(
		'type' => 'object',
		'subtype' => $type,
		'limit' => 1,
	));
	if ($object) {
		$content .= elgg_view('output/longtext', array('value' => $object[0]->description));
	} else {
		$content .= elgg_echo("expages:notset");
	}

	$body = elgg_view_layout("one_sidebar", array('content' => $content));
	echo elgg_view_page($title, $body);
}

/**
 * Forward to the new style of URLs
 *
 * @param string $page
 */
function expages_url_forwarder($page) {
	global $CONFIG;
	$url = "{$CONFIG->wwwroot}{$page}";
	forward($url);
}