I'm on the newest Elgg (v. 2.3.6). I installed the Profile URL plugin (https://elgg.org/plugins/1091233) to shorten URLs from mysite/profile/user to mysite/user. I think there was some change introduced post-v.1.9 that is causing the at symbol '@' to get appended to the URL so that mysite/user becomes mysite/@user.
I can't figure out where this insertion is coming from. I have 5 or 6 users, none of which have @ in their username.
Strangely, the first two users were added before I first enabled the plugin and they do not have '@', but every subsequent user gets '@' added on. When I deactivate the plugin the URLs work again (so mysite/@user becomes mysite/profile/user).
The insertion is causing 404 errors because site links are pointing to the URLs with the @ symbol. The actual, working profile pages themselves do not have @ in the URL.
Any suggestions would be welcome. The raw PHP handling the URL shortening is below:
---
<?php
namespace ProfileURL;
const PLUGIN_ID = 'profile_url';
elgg_register_event_handler('init', 'system', __NAMESPACE__ . '\\init');
function init() {
elgg_register_plugin_hook_handler('forward', '404', __NAMESPACE__ . '\\forward_hook', 0);
elgg_register_plugin_hook_handler('registeruser:validate:username', 'all', __NAMESPACE__ . '\\check_username');
elgg_register_plugin_hook_handler('entity:url', 'user', __NAMESPACE__ . '\\member_url');
}
function forward_hook($hook, $type, $return, $params) {
$base_path = parse_url(elgg_get_site_url(), PHP_URL_PATH);
$current_path = parse_url($params['current_url'], PHP_URL_PATH);
$current_path = ($base_path == '/') ? substr($current_path, 1) : str_replace($base_path, '', $current_path);
$parts = explode('/', $current_path);
if (count($parts) == 1 && $user = get_user_by_username(str_replace('-', '.', $parts[0]))) {
elgg_set_context('profile');
$result = elgg_trigger_plugin_hook('route', 'profile', null, array(
'identifier' => 'profile',
'handler' => 'profile',
'segments' => array($user->username)
));
if ($result === false) {
// it's been handled
exit;
}
// yes private API but there's nothing we can do about it
$handlers = _elgg_services()->router->getPageHandlers();
if (is_callable($handlers['profile'])) {
$result = call_user_func($handlers['profile'], array($user->username), 'profile');
if ($result) {
exit;
}
}
}
return $return;
}
function member_url($h, $t, $r, $p) {
return elgg_get_site_url() . str_replace('.', '-', $p['entity']->username);
}
function check_username($h, $t, $r, $p) {
// yes private API but there's nothing we can do about it
$handlers = _elgg_services()->router->getPageHandlers();
return !in_array($p['username'], array_keys($handlers));
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Gdray@Gdray
Gdray - 0 likes
You must log in to post replies.Found the issue! Apparently hypeSEO was causing a conflict. Deactivating that plugin resolved the problem.