1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
function maintenance_init(){ |
4
|
|
|
|
5
|
|
|
global $CONFIG; |
6
|
|
|
|
7
|
|
|
// check if new walled garden setting is activated. If it is then our view core/account/login_walled_garden.php |
8
|
|
|
// will take care of displaying our maintenance screen (see view default/core/account/login_walled_garden.php) |
9
|
|
|
|
10
|
|
|
if ( !$CONFIG->walled_garden ) { |
11
|
|
|
|
12
|
|
|
// walled garden is not active - so we check our setting and if we're in maintenance mode |
13
|
|
|
// we register a plugin hook for the index page. Notice we set its priority to 200 to get us |
14
|
|
|
// hooked before the custom index plugin. Otherwise we'd have to be installed and configured |
15
|
|
|
// above the custom index plugin - which is a pain. |
16
|
|
|
|
17
|
|
|
if(get_plugin_setting("maintenance_active","maintenance")=="yes" && !isadminloggedin()){ |
18
|
|
|
|
19
|
|
|
elgg_register_plugin_hook_handler('index','system','maintenance_index',200); |
20
|
|
|
|
21
|
|
|
global $CONFIG; |
22
|
|
|
// these are the lines that changed to make the plugin compatible with elgg installed in a sub |
23
|
|
|
// directory. Author unknown. |
24
|
|
|
|
25
|
|
|
$base_uri = parse_url($CONFIG->wwwroot, PHP_URL_PATH); |
26
|
|
|
if($_SERVER["REQUEST_URI"] != $base_uri && $_SERVER["REQUEST_URI"] != "${base_uri}action/login"){ |
27
|
|
|
|
28
|
|
|
admin_gatekeeper(); |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function maintenance_index() { |
35
|
|
|
|
36
|
|
|
// notice that this plugin does not check the return value sent in with the hook. If another plugin already hook system index |
37
|
|
|
// then we just doubled up and hooked it too. This causes both pages to be displayed. |
38
|
|
|
|
39
|
|
|
// the custom index plugin checks the value and returns if the page is already hooked. |
40
|
|
|
// the code is: |
41
|
|
|
|
42
|
|
|
// function custom_index($hook, $type, $return, $params) { |
43
|
|
|
// if ($return == true) { |
44
|
|
|
// another hook has already replaced the front page |
45
|
|
|
// return $return; |
46
|
|
|
// } |
47
|
|
|
// ... |
48
|
|
|
// } |
49
|
|
|
|
50
|
|
|
if (!include_once(dirname(__FILE__) . "/index.php")) { |
51
|
|
|
return false; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// return true to signify that we have handled the front page |
55
|
|
|
return true; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// Initialise plugin |
59
|
|
|
elgg_register_event_handler('init','system','maintenance_init'); |
60
|
|
|
?> |
|
|
|
|
61
|
|
|
|
Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.
A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.