aboutsummaryrefslogtreecommitdiff
path: root/mod/developers/start.php
blob: 23b82d9db52dc7175fc29a82fb8641edc274e39a (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
91
<?php
/**
 * Elgg developer tools
 */

// we want to run this as soon as possible - other plugins should not need to do this
developers_process_settings();

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

function developers_init() {
	elgg_register_event_handler('pagesetup', 'system', 'developers_setup_menu');

	elgg_extend_view('css/admin', 'developers/css');
	elgg_extend_view('css/elgg', 'developers/css');

	elgg_register_page_handler('theme_preview', 'developers_theme_preview_controller');

	$action_base = elgg_get_plugins_path() . 'developers/actions/developers';
	elgg_register_action('developers/settings', "$action_base/settings.php", 'admin');
	elgg_register_action('developers/inspect', "$action_base/inspect.php", 'admin');

	elgg_register_js('jquery.jstree', 'mod/developers/vendors/jsTree/jquery.jstree.js', 'footer');
	elgg_register_css('jquery.jstree', 'mod/developers/vendors/jsTree/themes/default/style.css');

	elgg_register_js('elgg.dev', 'js/developers/developers.js', 'footer');
	elgg_load_js('elgg.dev');
}

function developers_process_settings() {
	if (elgg_get_plugin_setting('display_errors', 'developers') == 1) {
		ini_set('display_errors', 1);
	} else {
		ini_set('display_errors', 0);
	}

	if (elgg_get_plugin_setting('screen_log', 'developers') == 1) {
		$cache = new ElggLogCache();
		elgg_set_config('log_cache', $cache);
		elgg_register_plugin_hook_handler('debug', 'log', array($cache, 'insertDump'));
		elgg_extend_view('page/elements/foot', 'developers/log');
	}
}

function developers_setup_menu() {
	if (elgg_in_context('admin')) {
		elgg_register_admin_menu_item('develop', 'settings', 'developers');
		elgg_register_admin_menu_item('develop', 'inspect', 'developers');
		elgg_register_admin_menu_item('develop', 'preview', 'developers');
	}
}

/**
 * Serve the theme preview pages
 *
 * @param array $page
 */
function developers_theme_preview_controller($page) {
	if (!isset($page[0])) {
		forward('theme_preview/general');
	}

	$pages = array(
		'buttons',
		'components', 
		'forms', 
		'grid', 
		'icons',
		'modules', 
		'navigation', 
		'typography', 
	);
	
	foreach ($pages as $page_name) {
		elgg_register_menu_item('page', array(
			'name' => $page_name,
			'text' => elgg_echo("theme_preview:$page_name"),
			'href' => "theme_preview/$page_name",
		));
	}

	$title = elgg_echo("theme_preview:{$page[0]}");
	$body =  elgg_view("theme_preview/{$page[0]}");

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