Tapatalk Modification for vB3 - Issue with Avatar Icons

This post will be soon moved to the "Web Application" forum so our Tapatalk developer friends can follow an unresolved issue with regard to how the Tapatalk app fetches can caches avatar icons.

We start this process by creating a hook in the vB 3.8 tapatalk file get_online_users.php

($hook = vBulletinHook::fetch_hook('neo_tapatalk_online_bits')) ? eval($hook) : false;

in the location within the file here:

$from = 'browser';

if(isset($loggedin['useragent']))
      {
            $userAgent = $loggedin['useragent'];
             
             if(strpos($userAgent,'Android') !== false || strpos($userAgent,'iPhone') !== false ||  strpos($userAgent,'BlackBerry') !== false)
             $from = 'mobile';
             if(strpos($userAgent,'Tapatalk') !== false)
                    $from = 'tapatalk';
              if(strpos($userAgent,'BYO') !== false)
                    $from = 'byo';            
      }


$username = mobiquo_encode($loggedin['musername']) ? mobiquo_encode($loggedin['musername']) : mobiquo_encode($loggedin['username']);

($hook = vBulletinHook::fetch_hook('neo_tapatalk_online_bits')) ? eval($hook) : false;

and the hook code simply takes the $from variable and adds a small bit of text to the $display_text that is displayed in the TT "People" page:

 if($from == 'tapatalk') 
       { 
             if(empty($userinfo['avatarurl'])) 
                    $userinfo['avatarurl'] = 'customavatars/avatar46598_1.gif';  // testing this line
                    $display_text = $display_text . mobiquo_encode(' ...  (using Tapatalk)'); 
        } 
else if($vbulletin->userinfo['styleid'] == '137') 
        { 
                  $display_text = $display_text . mobiquo_encode(' ... (using Mobile Skin)'); 
        } 
else if($from == 'mobile') 
        { 
                  $display_text = $display_text . mobiquo_encode(' ... (using Mobile No Skin)'); 
        }

This code works as expected, and in the screen shot above; we can see two online TT users.

(Note: There is also one "special system bot" user we created that is used to display system information to mods, but I will not describe that code in this post; it is discussed in this post).

Because this works so easily, I then decided to add icons for all users who do not have icons already (because they did not upload a custom avatar). We will do this for the. I created many different hooks and experimented in many different places (because there is an issue with the icons, as they are fetched and cached in the TT app)

Currently, I am using the vB 3 file: functions_user.php

and the hook is:

// final case: didn't get an avatar, so use the fake one
if (empty($userinfo['avatarurl']) AND $returnfakeavatar)  // we never use this fake one, only the hook code below
     {
                $userinfo['avatarurl'] = $stylevar['imgdir_misc'] . '/unknown.gif';
      }

($hook = vBulletinHook::fetch_hook('neo_vbulletin_fetch_avatar_from_userinfo')) ? eval($hook) : false;

and the hook code we are testing is quite simple:

if($userinfo['avatarurl'] == '') 
{ 
$agent = $location;   // for testing purposes
   
if($userinfo['usergroupid'] == '10')   
     $userinfo['avatarurl'] = 'customavatars/avatar302016126_2.gif';   
else if($userinfo['usergroupid'] == '5')   
     $userinfo['avatarurl'] =  'customavatars/avatar302016126_2.gif';   
else if($userinfo['usergroupid'] == '13')   
    $userinfo['avatarurl'] = 'customavatars/avatar34166_2.gif';   
else if($userinfo['usergroupid'] == '11')   
    $userinfo['avatarurl'] = 'customavatars/avatar44786_2.gif';   
else if($userinfo['usergroupid'] == '3')   
    $userinfo['avatarurl'] = 'customavatars/avatar302052812_2.gif'; 
else   
   {   
     if($agent == 'tapatalk')   
        {   
         $userinfo['avatarurl'] = 'customavatars/avatar46598_1.gif';   
        }   
     else if($agent == 'browser')   
        {   
         $userinfo['avatarurl'] = 'customavatars/avatar302087525_1.gif';   
        }   
       else if($agent == 'mobile')   
        {   
         $userinfo['avatarurl'] = 'customavatars/avatar302051592_2.gif';   
        }   
       else  
        {   
         $userinfo['avatarurl'] = 'customavatars/avatar302087525_1.gif';   
        }   

    }   

// our simple logging code for debugging
if(1)  
{  
     $log = '/var/log/apache2/neo_fetch_avatar_from_userinfo';  
     //$stuff = print_r($userinfo,TRUE);  
     error_log(date(DATE_RFC822).' '.$userinfo['usergroupid'].'  '. $_SERVER['REMOTE_ADDR']. 
'  '. $userinfo['username'] .' URL  '.$userinfo['avatarurl'] .' From: '.$agent."\n", 3, $log);
}   

OBTW, I also modify the function (used above) to send it the required $location parameter:

function fetch_avatar_from_userinfo(&$userinfo, $thumb = false, $returnfakeavatar = true,$location= '')

This code basically says, fetch the avatar from the userinfo with an addition location parameter, and if there is no user avatar, replace with our custom avatar, one for various user groups, and if the user is not a member of any of those groups, show a default "UX" avatar, but if their location is "Using Tapatalk" then show a different TT icon.

Unfortunately, this does not work. You can see in the image above, two users are online via TT and the status message is correct, but the icon is not correct. We see the default "UX" icon and not the "TT" icon.

Also, FYI:

fetch_avatar_from_userinfo()

is called from the TT include file common.php

which is located in our modified function (with our optional agent param):

function mobiquo_get_user_icon($userid,$agent = '')

which contains this code:

    
$icon_url = "";
if($vbulletin->options['avatarenabled']){
     fetch_avatar_from_userinfo($userinfo,true,false,$agent);

     if($userinfo[avatarurl]){
            $icon_url = get_icon_real_url($userinfo['avatarurl']);
     } else {
           $icon_url = '';   // this should never happen because we add default icons in the  fetch_avatar_from_userinfo() function
     }
}

I have tried placing the hooks in various locations, clearing the cache, restarting the app on the mobile phone, even restarting the phone. The logging info always shows that the icons are set correct by the code; but they do not display correctly.

So, I have concluded this is a pre-fetching or caching bug in the TT app that causes the avatar icons not to display properly. In this same screenshot, the icons are wrong for the two logged in TT users:

Example debug logging output:

You can see that for two TT users, the correct TT default avatar is set, but it does not show correctly in the app. Clearing the cache, restarting the app and/or the phone does not fix the issue.

Update: This is very strange.

Without any notice TT upgraded their app to remove the user avatar from the "People" pages. Why they would do this, without coordinating with forum owners and admins, is beyond me to understand.

I guess that when TT has a bug in something and they cannot fix it, they just "remove it" without discussing it with forum admins?

Update: I worked many hours to debug this issue and then TT just deleted the feature from the app. It's a bit frustrating.. needless to say.