Jump to content


[Tutorial + Hack]Add number of registered members to Online block


  • You cannot reply to this topic
No replies to this topic

#1 visiblesoul

  • Administrators
  • 551 posts
  • Location:Earth
  • Texas

Posted 04 May 2006 - 11:42 AM

First let me tell you how I did this so you can start doing these little hacks for yourself.

1) I knew that the "Site Stats" block displays the number of registered users so instead of trying to figure out how to query the information I first looked in the site_stat.php block...

2) It was obvious where the output was for the registered members line once I looked in the code. Not only was the code below in the correct position for what I observed in the online block output but it even used the words "members" and "u_registered" which looked alot like "users registered".

Quote



{$stat['members']} {$this->lang['u_registered']}

3) Next I noticed that there were 2 variables in the output html. I assumed that the language variable ($this->lang['u_registered']) would display since I took it from another block and language variables from one block usually work in all blocks.

I wasn't so sure about the variable that actually displays the number of users so I just put the code in the online.php block and refreshed my test homepage to see what would happen. The number of users did not display.

So now since the variable uses "$stat" I looked for other instances of "$stat" in the site_stat.php file. Toward the top is the line "$stat = $mklib_board->get_site_stat();" which since it says "get_site_stat" I thought it was a safe assumption that the stats info was called from that line. So I added it to the top of online.php and now the new "Registered Members" line worked.

4) Since the $stat variable was not used anywhere in the default online.php I knew I needed to "unset" the variable since non global variables should be unset in MKPortal blocks. This is just something I learned by hanging around here. It's not something that you could just easily figure out on your own I don't think. But now you know.

So you see that with a little thought and experimentation even those of us who are not very good with php can figure out alot of little hacks. You should start trying little stuff like this yourself.

-=DKC=-

------------------------------------------
FIND in online.php:
	$users= $mklib_board->get_onlineblock();
ADD BELOW:
	$stat = $mklib_board->get_site_stat();
FIND:
			  ";

		unset($lonlinelist);
ADD ABOVE:
				<tr>
				  <td class="tdblock">
				  <span class="mktxtcontr">{$stat['members']}</span> {$this->lang['u_registered']}
				  </td>
				</tr>
FIND:
?>
ADD ABOVE:
	unset($stat);



Please note that I offer free support on this forum in my free time. Depending on how much work I have backlogged it may take me a week or more to answer questions. I am not ignoring you. I answer everyone but please be patient. Thanks.

Disclaimer: All forum posts, including code examples, on this forum are offered for free in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Use code examples at your own risk.

"If at first you don't succeed, keep on suckin' til you do succeed." -Curly Howard





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users