-
Notifications
You must be signed in to change notification settings - Fork 2
/
start.php
executable file
·122 lines (99 loc) · 3.94 KB
/
start.php
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* Content debugger plugin
*
* @package content_debugger
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
* @author Andras Szepeshazi
* @copyright Andras Szepeshazi
* @link http://wamped.org
*/
// Global variable to hold profiling info while rendering views
$content_debugger_timestamps = new stdClass();
/**
* Content debugger initialization
*/
function content_debugger_init() {
if (elgg_is_admin_logged_in()) {
elgg_register_page_handler('content_debugger', 'content_debugger_page_handler');
$base_name = basename(dirname(__FILE__));
$path = elgg_get_plugins_path() . $base_name;
elgg_register_library('content_debugger', $path.'/lib/content_debugger/content_debugger.php');
elgg_load_library('content_debugger');
elgg_extend_view('css/elgg', 'content_debugger/css');
elgg_extend_view('css/admin', 'content_debugger/css');
elgg_register_js('poshytips', "mod/$base_name/vendors/poshytip-1.0/src/jquery.poshytip.js");
$magicmarker_path = elgg_get_simplecache_url('js', 'content_debugger/magicmarker');
elgg_register_simplecache_view('js/content_debugger/magicmarker');
elgg_register_js('content_debugger.magicmarker', $magicmarker_path);
$content_debugger_path = elgg_get_simplecache_url('js', 'content_debugger/content_debugger');
elgg_register_simplecache_view('js/content_debugger/content_debugger');
elgg_register_js('content_debugger.content_debugger', $content_debugger_path);
$ui = content_debugger_get_ui_type();
if ($_SESSION['content_debugger'][$ui] === 'enabled') {
elgg_load_js('poshytips');
elgg_load_js('content_debugger.magicmarker');
elgg_load_js('content_debugger.content_debugger');
elgg_register_event_handler('pagesetup', 'system', 'content_debugger_profiler_start');
elgg_register_plugin_hook_handler('view', 'all', 'content_debugger_view_hook', 1000);
}
elgg_register_event_handler('pagesetup', 'system', 'content_debugger_setup_menu');
}
}
function content_debugger_setup_menu() {
if (elgg_in_context('admin')) {
// Register content debugger toggle menu item in developer section for backend
$admin_status = 'enabled';
if (!isset($_SESSION['content_debugger']['admin']) || $_SESSION['content_debugger']['admin'] == 'disabled') {
$admin_status = 'disabled';
}
if (!elgg_is_menu_item_registered('page', 'develop_tools')) {
elgg_register_admin_menu_item('develop', 'develop_tools');
}
elgg_register_menu_item('page', array(
'name' => 'content_debugger',
'href' => 'content_debugger/toggle?context=admin',
'text' => elgg_echo("content_debugger:toggle:$admin_status"),
'section' => 'develop',
'parent_name' => 'develop_tools'
));
} else {
// Register content debugger toggle menu item in topbar menu for frontend
$menu_icon_class = "elgg-icon elgg-icon-info";
if (isset($_SESSION['content_debugger']['frontend']) && $_SESSION['content_debugger']['frontend'] === 'enabled') {
$menu_icon_class .= '-active';
}
elgg_register_menu_item('topbar', array(
'name' => 'content_debugger',
'href' => 'content_debugger/toggle',
'text' => "<span class='$menu_icon_class'></span>",
'priority' => 90,
'title' => elgg_echo('content_debugger:toggle'),
'section' => 'alt'
));
}
}
/**
* Content debugger page handler
*
* @param array $page Array of page elements, forwarded by the page handling mechanism
*/
function content_debugger_page_handler($page) {
if (isset($page[0]) && !empty($page[0])) {
switch ($page[0]) {
case 'toggle':
if (get_input('context', null) === 'admin') {
elgg_set_context('admin');
}
$ui = content_debugger_get_ui_type();
if (!isset($_SESSION['content_debugger'][$ui]) || $_SESSION['content_debugger'][$ui] == 'disabled') {
$_SESSION['content_debugger'][$ui] = 'enabled';
} else {
$_SESSION['content_debugger'][$ui] = 'disabled';
}
forward($_SERVER['HTTP_REFERER']);
break;
}
}
}
elgg_register_event_handler('init', 'system', 'content_debugger_init');