| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
function community_pagesetup() { |
|---|
| 23 |
|
|---|
| 24 |
global $profile_id; |
|---|
| 25 |
global $PAGE; |
|---|
| 26 |
global $CFG; |
|---|
| 27 |
global $USER; |
|---|
| 28 |
|
|---|
| 29 |
require_once (dirname(__FILE__)."/default_template.php"); |
|---|
| 30 |
require_once (dirname(__FILE__)."/lib/communities_config.php"); |
|---|
| 31 |
|
|---|
| 32 |
$page_owner = $profile_id; |
|---|
| 33 |
|
|---|
| 34 |
$usertype = user_type($page_owner); |
|---|
| 35 |
|
|---|
| 36 |
$username= user_info('username', $page_owner); |
|---|
| 37 |
|
|---|
| 38 |
if (isloggedin()) { |
|---|
| 39 |
if(COMMUNITY_CONTEXT!="network"){ |
|---|
| 40 |
if (defined("context") && context == COMMUNITY_CONTEXT ) { |
|---|
| 41 |
$PAGE->menu[] = array( 'name' => 'community', |
|---|
| 42 |
'html' => "<li><a href=\"{$CFG->wwwroot}{$_SESSION['username']}/communities\" class=\"selected\" >" .__gettext("Your Communities").'</a></li>'); |
|---|
| 43 |
} else{ |
|---|
| 44 |
$PAGE->menu[] = array( 'name' => 'community', |
|---|
| 45 |
'html' => "<li><a href=\"{$CFG->wwwroot}{$_SESSION['username']}/communities\" >" .__gettext("Your Communities").'</a></li>'); |
|---|
| 46 |
} |
|---|
| 47 |
} |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
if ($usertype == "community") { |
|---|
| 51 |
|
|---|
| 52 |
if (defined("context") && context == "profile") { |
|---|
| 53 |
|
|---|
| 54 |
if (run("permissions:check", "profile")) { |
|---|
| 55 |
|
|---|
| 56 |
|
|---|
| 57 |
$PAGE->menu_sub[] = array( 'name' => 'profile:edit', |
|---|
| 58 |
'html' => '<a href="'.$CFG->wwwroot.'profile/edit.php?profile_id='.$page_owner.'">' |
|---|
| 59 |
. __gettext("Edit community profile") . '</a>'); |
|---|
| 60 |
|
|---|
| 61 |
$PAGE->menu_sub[] = array( 'name' => 'community:pic', |
|---|
| 62 |
'html' => a_href("{$CFG->wwwroot}_icons/?context=profile&profile_id=$page_owner" , |
|---|
| 63 |
__gettext("Community site picture"))); |
|---|
| 64 |
|
|---|
| 65 |
$PAGE->menu_sub[] = array( 'name' => 'community:edit', |
|---|
| 66 |
'html' => a_href("{$CFG->wwwroot}_userdetails/?context=profile&profile_id=$page_owner" , |
|---|
| 67 |
__gettext("Edit community details"))); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
} |
|---|
| 71 |
|
|---|
| 72 |
if (defined("context") && (context == "profile" || context == COMMUNITY_CONTEXT)) { |
|---|
| 73 |
if (run("permissions:check", "profile")) { |
|---|
| 74 |
if(context == COMMUNITY_CONTEXT){ |
|---|
| 75 |
$PAGE->menu_sub[] = array( 'name' => 'profile:view', |
|---|
| 76 |
'html' => a_href("{$CFG->wwwroot}{$username}/profile", |
|---|
| 77 |
__gettext("Return to community profile"))); |
|---|
| 78 |
} |
|---|
| 79 |
|
|---|
| 80 |
$PAGE->menu_sub[] = array( 'name' => 'community:adminmembers', |
|---|
| 81 |
'html' => a_href("{$CFG->wwwroot}{$username}/community/members", |
|---|
| 82 |
__gettext("Edit members"))); |
|---|
| 83 |
|
|---|
| 84 |
$PAGE->menu_sub[] = array( 'name' => 'community:requests', |
|---|
| 85 |
'html' => a_href("{$CFG->wwwroot}{$username}/community/requests", |
|---|
| 86 |
__gettext("View membership requests"))); |
|---|
| 87 |
|
|---|
| 88 |
$PAGE->menu_sub[] = array( 'name' => 'community:invite', |
|---|
| 89 |
'html' => a_href("{$CFG->wwwroot}{$username}/community/invite", |
|---|
| 90 |
__gettext("Invite people"))); |
|---|
| 91 |
} |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
if (defined("context") && context == "profile") { |
|---|
| 95 |
|
|---|
| 96 |
if (run("permissions:check", "profile")) { |
|---|
| 97 |
|
|---|
| 98 |
if (!empty($CFG->uses_YUI)) { |
|---|
| 99 |
$PAGE->menu_sub[] = array( 'name' => 'profile:widget:manage', |
|---|
| 100 |
'html' => '<a href="'.$CFG->wwwroot.'mod/widget/manage_widgets.php?owner='.$page_owner.'">' |
|---|
| 101 |
. __gettext("Manage widgets") . '</a>'); |
|---|
| 102 |
} else { |
|---|
| 103 |
$PAGE->menu_sub[] = array( 'name' => 'profile:widget:add', |
|---|
| 104 |
'html' => '<a href="'.$CFG->wwwroot.'mod/profile/add.php?owner='.$page_owner.'">' |
|---|
| 105 |
. __gettext("Add widget") . '</a>'); |
|---|
| 106 |
|
|---|
| 107 |
} |
|---|
| 108 |
|
|---|
| 109 |
} |
|---|
| 110 |
} |
|---|
| 111 |
} else if ($usertype == "person") { |
|---|
| 112 |
|
|---|
| 113 |
if (defined("context") && context == COMMUNITY_CONTEXT) { |
|---|
| 114 |
if(COMMUNITY_COMPACT_VIEW){ |
|---|
| 115 |
$PAGE->menu_sub[] = array( 'name' => 'community', |
|---|
| 116 |
'html' => a_href("{$CFG->wwwroot}{$username}/communities" , |
|---|
| 117 |
__gettext("Communities"))); |
|---|
| 118 |
|
|---|
| 119 |
if (logged_on && $page_owner == $_SESSION['userid'] && |
|---|
| 120 |
($CFG->community_create_flag == "" || user_flag_get($CFG->community_create_flag, $USER->ident))) { |
|---|
| 121 |
$PAGE->menu_sub[] = array( 'name' => 'community:owned', |
|---|
| 122 |
'html' => a_href("{$CFG->wwwroot}{$username}/communities/new" , |
|---|
| 123 |
__gettext("New Community"))); |
|---|
| 124 |
} |
|---|
| 125 |
} |
|---|
| 126 |
else{ |
|---|
| 127 |
$PAGE->menu_sub[] = array( 'name' => 'community', |
|---|
| 128 |
'html' => a_href("{$CFG->wwwroot}{$username}/communities" , |
|---|
| 129 |
__gettext("Communities"))); |
|---|
| 130 |
|
|---|
| 131 |
if ($CFG->community_create_flag == "" || user_flag_get($CFG->community_create_flag, $USER->ident)) { |
|---|
| 132 |
$PAGE->menu_sub[] = array( 'name' => 'community:owned', |
|---|
| 133 |
'html' => a_href("{$CFG->wwwroot}{$username}/communities/owned" , |
|---|
| 134 |
__gettext("Owned Communities"))); |
|---|
| 135 |
} |
|---|
| 136 |
} |
|---|
| 137 |
} |
|---|
| 138 |
} |
|---|
| 139 |
|
|---|
| 140 |
$PAGE->search_menu[] = array( 'name' => __gettext("Communities"), |
|---|
| 141 |
'user_type' => 'community'); |
|---|
| 142 |
|
|---|
| 143 |
|
|---|
| 144 |
if (defined("context") && context == "network" && isloggedin() && $page_owner == $_SESSION['userid']) { |
|---|
| 145 |
$PAGE->menu_sub[] = array( 'name' => 'membership:invites', |
|---|
| 146 |
'html' => a_href( "{$CFG->wwwroot}{$username}/communities/invitations", |
|---|
| 147 |
__gettext("Community invitations"))); |
|---|
| 148 |
} |
|---|
| 149 |
} |
|---|
| 150 |
|
|---|
| 151 |
function community_init() { |
|---|
| 152 |
global $CFG,$function; |
|---|
| 153 |
|
|---|
| 154 |
|
|---|
| 155 |
$function['init'][] = $CFG->dirroot . "mod/community/lib/communities_access_levels.php"; |
|---|
| 156 |
$function['userdetails:init'][] = $CFG->dirroot . "mod/community/lib/userdetails_actions.php"; |
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 |
$function['communities:init'][] = $CFG->dirroot . "mod/community/lib/communities_config.php"; |
|---|
| 160 |
$function['communities:init'][] = $CFG->dirroot . "mod/community/lib/communities_actions.php"; |
|---|
| 161 |
|
|---|
| 162 |
|
|---|
| 163 |
$function['display:sidebar'][] = $CFG->dirroot . "mod/community/lib/communities_owned.php"; |
|---|
| 164 |
$function['display:sidebar'][] = $CFG->dirroot . "mod/community/lib/community_memberships.php"; |
|---|
| 165 |
|
|---|
| 166 |
|
|---|
| 167 |
$function['community:infobox:menu'][] = $CFG->dirroot . "mod/community/lib/user_info_menu.php"; |
|---|
| 168 |
$function['users:infobox:menu:text'][] = $CFG->dirroot . "mod/community/lib/user_info_menu_text.php"; |
|---|
| 169 |
|
|---|
| 170 |
|
|---|
| 171 |
$function['permissions:check'][] = $CFG->dirroot . "mod/community/lib/permissions_check.php"; |
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 |
$function['communities:editpage'][] = $CFG->dirroot . "mod/community/lib/communities_edit_wrapper.php"; |
|---|
| 175 |
$function['communities:edit'][] = $CFG->dirroot . "mod/community/lib/communities_edit.php"; |
|---|
| 176 |
$function['communities:members'][] = $CFG->dirroot . "mod/community/lib/communities_members.php"; |
|---|
| 177 |
$function['communities:owned'][] = $CFG->dirroot . "mod/community/lib/communities_moderator_of.php"; |
|---|
| 178 |
$function['communities:owned'][] = $CFG->dirroot . "mod/community/lib/communities_create.php"; |
|---|
| 179 |
$function['communities:create'][] = $CFG->dirroot . "mod/community/lib/communities_create.php"; |
|---|
| 180 |
|
|---|
| 181 |
|
|---|
| 182 |
$function['communities:requests:view'][] = $CFG->dirroot . "mod/community/lib/communities_membership_requests.php"; |
|---|
| 183 |
|
|---|
| 184 |
|
|---|
| 185 |
$function['users:access_level_check'][] = $CFG->dirroot . "mod/community/lib/communities_access_level_check.php"; |
|---|
| 186 |
|
|---|
| 187 |
|
|---|
| 188 |
$function['users:access_level_sql_where'][] = $CFG->dirroot . "mod/community/lib/communities_access_level_sql_check.php"; |
|---|
| 189 |
|
|---|
| 190 |
|
|---|
| 191 |
$function['profile:edit:link'][] = $CFG->dirroot . "mod/community/lib/profile_edit_link.php"; |
|---|
| 192 |
|
|---|
| 193 |
|
|---|
| 194 |
$function['userdetails:edit'][] = $CFG->dirroot . "mod/community/lib/userdetails_edit.php"; |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
$function['community:members:data'][] = $CFG->dirroot ."mod/community/lib/community_members_data.php"; |
|---|
| 198 |
$function['community:members:count'][] = $CFG->dirroot ."mod/community/lib/community_members_count.php"; |
|---|
| 199 |
$function['community:membership'][] = $CFG->dirroot ."mod/community/lib/community_membership.php"; |
|---|
| 200 |
$function['community:membership:check'][] = $CFG->dirroot ."mod/community/lib/community_membership_check.php"; |
|---|
| 201 |
$function['community:membership:data'][] = $CFG->dirroot ."mod/community/lib/community_membership_data.php"; |
|---|
| 202 |
|
|---|
| 203 |
|
|---|
| 204 |
$function['community:member:add'][] = $CFG->dirroot ."mod/community/lib/community_member_add.php"; |
|---|
| 205 |
$function['community:member:remove'][] = $CFG->dirroot ."mod/community/lib/community_member_remove.php"; |
|---|
| 206 |
|
|---|
| 207 |
|
|---|
| 208 |
listen_for_event("community","publish","community_owner_as_member"); |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
listen_for_event("user","delete","community_user_delete"); |
|---|
| 212 |
|
|---|
| 213 |
register_user_type('community'); |
|---|
| 214 |
} |
|---|
| 215 |
|
|---|
| 216 |
function community_owner_as_member($object_type,$event,$object){ |
|---|
| 217 |
global $messages; |
|---|
| 218 |
if($object_type=="community" && $event=="publish" && !empty($object->ident)){ |
|---|
| 219 |
$_messages = run('community:member:add',array($object->ident)); |
|---|
| 220 |
$messages = array_merge($messages,$_messages); |
|---|
| 221 |
|
|---|
| 222 |
} |
|---|
| 223 |
return $object; |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
function community_user_delete($object_type, $event, $object) { |
|---|
| 227 |
global $CFG, $data, $messages; |
|---|
| 228 |
if (!empty($object->ident) && $object_type == "user" && $event == "delete") { |
|---|
| 229 |
if ($newsuser = user_info_username("info","news")) { |
|---|
| 230 |
} else { |
|---|
| 231 |
$newsuser = -1; |
|---|
| 232 |
} |
|---|
| 233 |
|
|---|
| 234 |
if ($communities = get_records_sql("select * from {$CFG->prefix}users where owner = {$object->ident}")) { |
|---|
| 235 |
foreach($communities as $community) { |
|---|
| 236 |
$community->owner = $newsuser; |
|---|
| 237 |
update_record('users',$community); |
|---|
| 238 |
if ($newsuser != -1) { |
|---|
| 239 |
$messages[] = sprintf(__gettext("Community %s was returned to the news user."),$community->username); |
|---|
| 240 |
} else { |
|---|
| 241 |
$messages[] = sprintf(__gettext("Community %s is now owned by -1 (nobody)."),$community->username); |
|---|
| 242 |
} |
|---|
| 243 |
} |
|---|
| 244 |
} |
|---|
| 245 |
} |
|---|
| 246 |
|
|---|
| 247 |
|
|---|
| 248 |
return $object; |
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 |
community_permissions_check($object_type, $object_owner) { |
|---|
| 252 |
$result = null; |
|---|
| 253 |
|
|---|
| 254 |
$object_type) { |
|---|
| 255 |
'files': |
|---|
| 256 |
|
|---|
| 257 |
if (run('community:membership:check', array($_SESSION['userid'], $object_owner))) { |
|---|
| 258 |
$result = true; |
|---|
| 259 |
|
|---|
| 260 |
|
|---|
| 261 |
'files:edit': |
|---|
| 262 |
|
|---|
| 263 |
if (record_exists('users', 'ident', $object_owner, 'owner', $_SESSION['userid'])) { |
|---|
| 264 |
$result = true; |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
'profile': |
|---|
| 268 |
|
|---|
| 269 |
if (record_exists('users', 'ident', $object_owner, 'owner', $_SESSION['userid'])) { |
|---|
| 270 |
$result = true; |
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
$result; |
|---|
| 276 |
|
|---|
| 277 |
|
|---|
| 278 |
|
|---|
| 279 |
?> |
|---|
| 280 |
|
|---|