This repository has been archived by the owner on Nov 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.php
167 lines (143 loc) · 4.59 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<?php
/**
*
* @author Diego Andrés Ramírez Aragón <[email protected]>
* @copyright Corporación Somos más - 2008
*/
function role_init(){
register_plugin_hook('display', 'view', 'role_profile_links_overwrite_hook');
register_page_handler('roles','role_page_handler');
}
function role_pagesetup(){
if (get_context() == 'admin' && isadminloggedin()) {
global $CONFIG;
add_submenu_item(elgg_echo('role:admin'), $CONFIG->wwwroot . 'pg/roles/admin',"r");
}
}
function role_page_handler($page){
if(isset($page[0])){
if($page[0]=="admin"){
@include (dirname(__FILE__)."/roleadmin.php");
exit;
}
}
}
function role_add_role($name,$contexts = array()){
$role_count = get_entities_from_metadata('name',$name,'object','role',0,1,0,'',0,true);
if($role_count==0){
$role = new ElggObject();
$role->type='role';
$role->name=$name;
return $role->save();
//@todo Add contexts config when it is provided
}
return false;
}
function role_add_role_context($role_id,$context){
//@todo Implement this
}
function role_assign_role($user_id, $role_id){
$user = get_entity($user_id);
$role = get_entity($role_id);
if($user instanceof ElggUser){
$roles = $user->role;
if(!is_array($roles)){
$roles = array($roles);
}
if(!in_array($role->name,$roles)){
create_metadata($user->guid,'role',$role->name,'text',$user->guid,ACCESS_PRIVATE,true);
return true;
}
}
return false;
}
function remove_role($user_id,$role_id){
$user = get_entity($user_id);
$role = get_entity($role_id);
if($user instanceof ElggUser){
$roles = $user->role;
$roles = array_diff($roles,array($role->name));
$user->role=$roles;
return true;
}
return false;
}
function role_has_role($roles,$user=null){
if(empty($user)){
$user = get_loggedin_user();
}
if(!is_array($roles)){
$roles = array($roles);
}
$user_roles = $user->role;
if(!is_array($user_roles)){
$user_roles = array($user_roles);
}
foreach($roles as $role){
return (in_array($role,$user_roles));
}
return false;
}
//@todo Get JS profile/menu/links and profile/menu/links
//@todo make the function that extrats the profile/menu/ and menu info
function role_profile_links_overwrite_hook($hook, $entity_type, $returnvalue, $params){
global $CONFIG;
$rules_js = array(
"profile/menu/actions",
"profile/menu/links",
"messages/menu",
"blog/menu",
"service/menu",
"project/menu",
"offer/menu",
"file/menu",
"tidypics/menu",
);
$rules_profile = array(
"profile/menu/actions",
"profile/menu/links",
"messages/menu",
"reportedcontent/user_report",
"profile/menu/adminwrapper"
);
$view = $params["view"];
$vars = $params["vars"];
if($view =="profile/menu/links"){
$viewtype = elgg_get_viewtype();
if (isset($CONFIG->views->extensions[$view])) {
$viewlist = $CONFIG->views->extensions[$view];
} else {
$viewlist = array(500 => $view);
}
if(!empty($vars["profile_page"])){
$viewlist = $rules_profile;
}
else{
$other = array_diff($viewlist,$rules_js);
$viewlist = array_merge($rules_js, $other);
}
ob_start();
foreach($viewlist as $priority => $view_file) {
$view_location = elgg_get_view_location($view_file);
if (file_exists($view_location . "{$viewtype}/{$view_file}.php") && !@include($view_location . "{$viewtype}/{$view_file}.php")) {
$success = false;
if ($viewtype != "default") {
if (@include($view_location . "default/{$view_file}.php")) {
$success = true;
}
}
if (!$success && isset($CONFIG->debug) && $CONFIG->debug == true) {
error_log(" [This view ({$view_file}) does not exist] ");
}
} else if (isset($CONFIG->debug) && $CONFIG->debug == true && !file_exists($view_location . "{$viewtype}/{$view_file}.php")) {
error_log($view_location . "{$viewtype}/{$view_file}.php");
error_log(" [This view ({$view_file}) does not exist] ");
}
}
$content = ob_get_clean();
return $content;
}
}
register_elgg_event_handler('init','system','role_init');
register_elgg_event_handler('pagesetup','system','role_pagesetup');
?>