View Single Post
  #60  
Old 07-10-2004, 12:04 PM
buro9 buro9 is offline
 
Join Date: Feb 2002
Location: London, UK
Posts: 585
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I hope no-one minds, but I wanted to highlight another way of doing this which requires less processing (fractionally) and is a little more elegant.

I should note that I'm not using avatars in the memberlist, so this isn't for that. But this does the showthread and private messaging ones

In includes/functions_bigthree.php there is already a function that finds out someones online status.

Within that file find:
PHP Code:
  if ($setstatusimage)
  {
    eval(
'$user[\'onlinestatus\'] = "' fetch_template('postbit_onlinestatus') . '";');
  } 
BEFORE that, put:
PHP Code:
  // HACK : START : STATUS ACCESS
  
switch ($onlinestatus) {
    case 
0:
      
$user['IsOnline'] = false;
      break;
    case 
1:
      
$user['IsOnline'] = true;
      break;
    case 
2:
      
$user['IsOnline'] = true;
      break;
    default:
      
$user['IsOnline'] = false;
      break;
  }
  
// HACK : END : STATUS ACCESS 
Now the $user object has an additional property in its array:

$user['IsOnline'] indicates that the user is online or not... or rather, should appear online to the current user... it takes into account invisibility and permissions, as the code above this already does all of this.

So we have less processing as none of this needs to be run:
Code:
  //avatar opacity grog6 - vbulletindev.net
    $datecut = TIMENOW - $vboptions['cookietimeout'];
     if (!ereg("MSIE", $_SERVER["HTTP_USER_AGENT"]))
       $style_avatar="style=\"-moz-opacity:0.3\"";
      else $style_avatar= "style=\"filter:alpha(opacity=30)\"";
  if ($post['lastactivity'] > $datecut AND $post['lastvisit'] != $post['lastactivity'])
     if (($permissions['genericpermissions'] & CANSEEHIDDEN) OR $post['userid'] == $bbuserinfo['userid'])
    {
      // user is online and invisible BUT bbuser can see them
                 if (!ereg("MSIE", $_SERVER["HTTP_USER_AGENT"]))
                        $style_avatar="style=\"-moz-opacity:1.0\"";
                       else $style_avatar= "style=\"filter:alpha(opacity=100)\"";
    }
          else
    {
           // user is online and visible
                       if (!ereg("MSIE", $_SERVER["HTTP_USER_AGENT"]))
                        $style_avatar="style=\"-moz-opacity:1.0\"";
                       else $style_avatar= "style=\"filter:alpha(opacity=100)\"";
And it's more elegant as it's a simple switch that uses all of vBulletins own logic, when their logic evolves, the switch will remain the same

Now, all we have to do is find the avatar line in the postbit template and add a conditional to it:
Code:
          <if condition="$post[IsOnline] == true">
					  &nbsp;<br /><a href="member.php?$session[sessionurl]u=$post[userid]"><img src="$avatarurl" alt="<phrase 1="$post[username]">$vbphrase[xs_avatar]</phrase>" border="0" /></a>
          <else />
					  &nbsp;<br /><a href="member.php?$session[sessionurl]u=$post[userid]"><img src="$avatarurl" alt="<phrase 1="$post[username]">$vbphrase[xs_avatar]</phrase>" border="0" style="filter:alpha(opacity=30);-moz-opacity:0.3;opacity: 0.3;" /></a>
          </if>
Notice that if it's online, it doesn't even have the style added... which is a good thing as why apply opacity when it's not required?

Secondly I apply both the IE and Mozilla and Opera opacity switches at the same time. Yes, I said Opera... Opera is currently using the CSS3 recommendation of 'opacity'... which is the best thing to do as that is also what Mozilla will be using in the future.

Styles set like this are ignored if not applicable... so it breaks nothing.

Anyhow... more elegant because of the simplicity of the code modification and the fact that we keep all of the presentation logic in templates rather than in code.

It shouldn't be hard for those who want to use this for the memberlist or memberprofile to add a call to the fetch_online_status() function in functions_bigthree.php and to add a conditional to their template.

But yeah... a different way of doing the same thing. Better? Hard to say... but I think a little more elegant.

Cheers

David K
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01219 seconds
  • Memory Usage 1,803KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code
  • (2)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete