How can I change user profile's URL to site.com/guid

Hello!

My question is - Is it possible to change user profile URL to the view site.com/guid with keeping the field username in its native view? I mean the username will still contain users login - not guid.

Thanks and sorry for my English.

  • of course - this can be done - with the appropriate code.. but why do you want to do this ? the code effort involved seems to outweigh any advantages. you'll need to look at implementing the correct hooks with the "elgg_register_entity_url_handler()" function for the logic required; may & probably will require some level of comfort coding with the std elgg api & related functions..

     

  • That is the task given by my chief.

    I was trying just by adding new function like get_user_by_username() but passing guid instead the username.

    But there is a USERNAME_TO_GUID_MAP_CACHE which is strange because all I could find about it is "Map a username to a cached GUID".

    And when I am trying to run without that cache or something - it gives me mistake "Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 128 bytes) in /var/www/elgg/httpdocs/engine/lib/database.php on line 325 " And when I reload the page it shows a mistake in another file "Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 587 bytes) in /var/www/elgg/httpdocs/engine/lib/cache.php on line 241 " and then in another and so on.

    Is it possible by making not much changes to make it work?

  • do a grep for "Profile URL generator for $user->getUrl()" 
    this will take you to the code you need to change for user profile urls
    ~ once you see the url code there - it should be quite a simple task to patch it to use the guid# for the generated href instead & the related existing "get_user_by_username($username)".. easy!

     

  • I am using $CODE_TO_GUID_MAP_CACHE instead of $USERNAME_TO_GUID_MAP_CACHE in my new function get_user_by_guid($guid). And there is an error occures as I wrote before ""Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 128 bytes) in /var/www/elgg/httpdocs/engine/lib/database.php on line 325". Is this because of these variables?

  • did you do a  " grep for "Profile URL generator for $user->getUrl()" this will take you to the code you need to change for user profile urls " ? -- the code change area involved for the function you are seeking - *not the " Fatal error: Allowed memory size of 67108864 bytes exhauste.." error. that has got not much didley to do with the logic change you want. i've given you some very specific guildelines for the effect you want. try to follow those instructions and.. we can make progress.. instead of fooling around with the 'fatal.. memory" problem - which is something quite very different problem.

  • Thank you - it works now.

  • The mistake was that in the /engine/lib/pageowner.php there was
    if ((!isset($returnval)) && ($username = get_input("username"))) {
            if (substr_count($username,'group:')) {
                preg_match('/group\:([0-9]+)/i',$username,$matches);
                $guid = $matches[1];
                if ($entity = get_entity($guid)) {
                    $returnval = $entity->getGUID();
                }
            }
            if ((!isset($returnval)) && ($user = get_user_by_username($username))) {
                $returnval = $user->getGUID();
            }
        }


        if ((!isset($returnval)) && ($owner = get_input("owner_guid"))) {
            if ($user = get_entity($owner)) {
                $returnval = $user->getGUID();
            }
        }

     

    I have just change "owner_guid" to "username" and it is working now.

  • Looks like this was a core hack, so for future people - this is not recommended.

  • ouch and lawdy !? *is a core hack.. while i was so gently guiding towards a solution with far far less code anyways ? good intentions litter the roadside..