This repository has been archived by the owner on Jun 2, 2023. It is now read-only.
/
start.php
126 lines (107 loc) · 3.41 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
123
124
125
126
<?php
/**
* General customizations for the Elgg community site
*
*/
elgg_register_event_handler('init', 'system', 'customizations_init');
/**
* Initialize the plugin
*/
function customizations_init() {
elgg_extend_view('css/elgg', 'customizations/css');
if (function_exists("elgg_ws_unexpose_function")) {
elgg_ws_unexpose_function('auth.gettoken');
}
// filter certain items from going to the river
elgg_register_plugin_hook_handler('creating', 'river', 'customizations_filter_river');
elgg_register_event_handler('delete', 'user', 'customizations_purge_messages');
// convert messageboard to private message interface
elgg_register_widget_type('messageboard', elgg_echo("customizations:widget:pm"), elgg_echo("customizations:widget:pm:desc"), array("profile"));
elgg_register_plugin_hook_handler('forward', 'system', 'customizations_pm_forward');
// do not want the pages link in hover menu
elgg_unextend_view('profile/menu/links', 'pages/menu');
// button for flushing apc cache
elgg_register_plugin_hook_handler('register', 'menu:admin_control_panel', 'customizations_control_panel');
// shut googlebot out from search
elgg_register_plugin_hook_handler('route', 'search', 'customizations_stop_googlebot');
$action_path = elgg_get_plugins_path() . "community_customizations/actions";
elgg_register_action('comments/edit', "$action_path/edit_comment.php", 'admin');
elgg_register_action('admin/flush_apc', "$action_path/admin/flush_apc.php", 'admin');
elgg_register_action('comments/disable', "$action_path/comments_disable.php", 'admin');
}
/**
* Forward to referrer if posting a pm from widget
*/
function customizations_pm_forward() {
if (get_input('pm_widget') == true) {
return $_SERVER['HTTP_REFERER'];
}
}
/**
* Delete messages from a user who is being deleted
*
* @param string $event
* @param string $type
* @param ElggUser $user
*/
function customizations_purge_messages($event, $type, $user) {
// make sure we delete them all
$entity_disable_override = access_get_show_hidden_status();
access_show_hidden_entities(true);
$messages = elgg_get_entities_from_metadata(array(
'type' => 'object',
'subtype' => 'messages',
'metadata_name' => 'fromId',
'metadata_value' => $user->getGUID(),
'limit' => 0,
));
if ($messages) {
foreach ($messages as $e) {
$e->delete();
}
}
access_show_hidden_entities($entity_disable_override);
}
/**
* Register a button for flushing apc cache
*
* @param string $hook
* @param string $type
* @param ElggMenuItem[] $menu
* @param array $params
* @return ElggMenuItem[] $menu
*/
function customizations_control_panel($hook, $type, $menu, $params) {
$options = array(
'name' => 'flush_apc',
'text' => elgg_echo('apc:flush'),
'href' => 'action/admin/flush_apc',
'is_action' => true,
'link_class' => 'elgg-button elgg-button-action',
);
$menu[] = ElggMenuItem::factory($options);
return $menu;
}
/**
* Prevent particular items from going to the river
*/
function customizations_filter_river($hook, $type, $item) {
$view = $item['view'];
switch ($view) {
case 'river/relationship/friend/create':
return false;
break;
case 'river/object/bookmarks/create':
return false;
break;
}
}
/**
* Googlebot does not respect robots.txt so we block it
*/
function customizations_stop_googlebot() {
if (stripos($_SERVER['HTTP_USER_AGENT'], 'googlebot') !== false) {
header("HTTP/1.1 403 Forbidden");
exit;
}
}