00001 <?php
00018 function elgg_get_page_owner_guid($guid = 0) {
00019 static $page_owner_guid;
00020
00021 if ($guid) {
00022 $page_owner_guid = $guid;
00023 }
00024
00025 if (isset($page_owner_guid)) {
00026 return $page_owner_guid;
00027 }
00028
00029
00030 $guid = elgg_trigger_plugin_hook('page_owner', 'system', NULL, 0);
00031
00032 if ($guid) {
00033 $page_owner_guid = $guid;
00034 }
00035
00036 return $guid;
00037 }
00038
00048 function elgg_get_page_owner_entity() {
00049 $guid = elgg_get_page_owner_guid();
00050 if ($guid > 0) {
00051 $ia = elgg_set_ignore_access(true);
00052 $owner = get_entity($guid);
00053 elgg_set_ignore_access($ia);
00054
00055 return $owner;
00056 }
00057
00058 return false;
00059 }
00060
00068 function elgg_set_page_owner_guid($guid) {
00069 elgg_get_page_owner_guid($guid);
00070 }
00071
00097 function default_page_owner_handler($hook, $entity_type, $returnvalue, $params) {
00098
00099 if ($returnvalue) {
00100 return $returnvalue;
00101 }
00102
00103 $ia = elgg_set_ignore_access(true);
00104
00105 $username = get_input("username");
00106 if ($username) {
00107
00108 if (substr_count($username, 'group:')) {
00109 preg_match('/group\:([0-9]+)/i', $username, $matches);
00110 $guid = $matches[1];
00111 if ($entity = get_entity($guid)) {
00112 elgg_set_ignore_access($ia);
00113 return $entity->getGUID();
00114 }
00115 }
00116
00117 if ($user = get_user_by_username($username)) {
00118 elgg_set_ignore_access($ia);
00119 return $user->getGUID();
00120 }
00121 }
00122
00123 $owner = get_input("owner_guid");
00124 if ($owner) {
00125 if ($user = get_entity($owner)) {
00126 elgg_set_ignore_access($ia);
00127 return $user->getGUID();
00128 }
00129 }
00130
00131
00132 $uri = current_page_url();
00133 $path = str_replace(elgg_get_site_url(), '', $uri);
00134 $path = trim($path, "/");
00135 if (strpos($path, "?")) {
00136 $path = substr($path, 0, strpos($path, "?"));
00137 }
00138
00139
00140 if (get_input('page', FALSE)) {
00141 $segments = explode('/', $path);
00142 if (isset($segments[1]) && isset($segments[2])) {
00143 switch ($segments[1]) {
00144 case 'owner':
00145 case 'friends':
00146 $user = get_user_by_username($segments[2]);
00147 if ($user) {
00148 elgg_set_ignore_access($ia);
00149 return $user->getGUID();
00150 }
00151 break;
00152 case 'view':
00153 case 'edit':
00154 $entity = get_entity($segments[2]);
00155 if ($entity) {
00156 elgg_set_ignore_access($ia);
00157 return $entity->getContainerGUID();
00158 }
00159 break;
00160 case 'add':
00161 case 'group':
00162 $entity = get_entity($segments[2]);
00163 if ($entity) {
00164 elgg_set_ignore_access($ia);
00165 return $entity->getGUID();
00166 }
00167 break;
00168 }
00169 }
00170 }
00171
00172 elgg_set_ignore_access($ia);
00173 }
00174
00198 function elgg_set_context($context) {
00199 global $CONFIG;
00200
00201 $context = trim($context);
00202
00203 if (empty($context)) {
00204 return false;
00205 }
00206
00207 $context = strtolower($context);
00208
00209 array_pop($CONFIG->context);
00210 array_push($CONFIG->context, $context);
00211
00212 return true;
00213 }
00214
00223 function elgg_get_context() {
00224 global $CONFIG;
00225
00226 if (!$CONFIG->context) {
00227 return null;
00228 }
00229
00230 return $CONFIG->context[count($CONFIG->context) - 1];
00231 }
00232
00240 function elgg_push_context($context) {
00241 global $CONFIG;
00242
00243 array_push($CONFIG->context, $context);
00244 }
00245
00252 function elgg_pop_context() {
00253 global $CONFIG;
00254
00255 return array_pop($CONFIG->context);
00256 }
00257
00270 function elgg_in_context($context) {
00271 global $CONFIG;
00272
00273 return in_array($context, $CONFIG->context);
00274 }
00275
00284 function page_owner_boot() {
00285
00286 elgg_register_plugin_hook_handler('page_owner', 'system', 'default_page_owner_handler');
00287
00288
00289
00290
00291 $handler = get_input('handler', FALSE);
00292 if ($handler) {
00293 elgg_set_context($handler);
00294 }
00295 }
00296
00297 elgg_register_event_handler('boot', 'system', 'page_owner_boot');