Bookcafe

Monday, August 17, 2009

Custom "Who's Online," "Most Users Online" and "IP of Guest" blocks

This is a customization of the "Who's Online" block (it should help you to change whatever else you would like to change as well). This one just adds the total number of registered users in addition to telling who is online.


Drupal 4.7

$number = db_result(db_query('SELECT COUNT(uid) AS number FROM {users} WHERE status=1'));
if (user_access('access content')) {
// Count users with activity in the past defined period.
$time_period = variable_get('user_block_seconds_online', 900);

// Perform database queries to gather online user lists.
$guests = db_fetch_object(db_query('SELECT COUNT(sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0', time() - $time_period));
$users = db_query('SELECT uid, name, access FROM {users} WHERE access >= %d AND uid != 0 ORDER BY access DESC', time() - $time_period);
$total_users = db_num_rows($users);

// Format the output with proper grammar.
echo "Out of $number registered users ";
if ($total_users == 1 && $guests->count == 1) {
$output = t('%members and %visitors online.', array('%members' => format_plural($total_users, 'there is currently 1 user', 'there are currently %count users'), '%visitors' => format_plural($guests->count, '1 guest', '%count guests')));
}
else {
$output = t('there are currently %members and %visitors online.', array('%members' => format_plural($total_users, '1 user', '%count users'), '%visitors' => format_plural($guests->count, '1 guest', '%count guests')));
}

// Display a list of currently online users.
$max_users = variable_get('user_block_max_list_count', 10);
if ($total_users && $max_users) {
$items = array();

while ($max_users-- && $account = db_fetch_object($users)) {
$items[] = $account;
}

$output .= theme('user_list', $items, t('Online users'));
}
}
return $output;
?>

>Variation: Most Users Ever Online
Right before


}
return $output;
?>

add:

$total_users_online = $total_users + $guests->count;
if (variable_get('most_users_online_ever', '') < $total_users_online) {
variable_set('most_users_online_ever', $total_users_online);
variable_set('most_users_online_ever_time', time());
}
$output .= "Most users ever online was " . variable_get('most_users_online_ever', '');
$output .= " on " . format_date(variable_get('most_users_online_ever_time', ''), 'medium', '');
?>

It will print something like:

Most users ever online was 66 on 01/24/2008 - 02:00

Tested in Drupal 5.6.

You can change "<" to "<=" if you'd like to show the most recent date.

Variation - showing IP and domain of guest
This doesn't call on the theming functions, so it includes some html formatting that might need to be change.


$number = db_result(db_query('SELECT COUNT(uid) AS number FROM {users} WHERE status=1'));
if (user_access('access content')) {
// Count users with activity in the past defined period.
$time_period = variable_get('user_block_seconds_online', 900);

// Perform database queries to gather online user lists.
$guests = db_fetch_object(db_query('SELECT COUNT(sid) AS count FROM {sessions} WHERE timestamp >= %d AND uid = 0', time() - $time_period));
$guests_hostname = db_query('SELECT hostname FROM {sessions} WHERE timestamp >= %d AND uid = 0', time() - $time_period);
$total_guests = db_num_rows($guests_hostname);

$users = db_query('SELECT uid, name, access FROM {users} WHERE access >= %d AND uid != 0 ORDER BY access DESC', time() - $time_period);
$total_users = db_num_rows($users);

// Display a list of currently online users.
$max_users = variable_get('user_block_max_list_count', 10);
if ($total_users && $max_users) {
$items = array();
while ($max_users-- && $account = db_fetch_object($users)) {
$items[] = $account;
}
$output.="Users";
$output .= theme('user_list', $items, NULL);
}

// Display a list of currently online guests.
if ($total_guests) {
$output.="
Guests
";
}
}
return $output;
?>

which gives as result:

Who is online
Users
* administrator
Guests
* 192.168.0.50 Saturnus

of course the 192.. Ip will change to any guests IP looking at your site.

Tuesday, June 9, 2009

Calls to Mysql

These are the number of calls for the Mysql from the Wikka Wikki files:

install.php 99 calls
wikka.class.php 26 calls
wikka.php 1 call

So far, install.php is having the greater number of calls to the PHP/Mysql. The smaller number of calls to the database is the most recommended in developing an Mysql based application as stated at http://www.webmasterworld.com/forum88/5922.htm
However, the install.php execution takes only once at the beginning of the installation of Wikka Wikki, so I think it will not takes too much computer processor and memory resources.

Sunday, May 31, 2009

LampWin Contest-End Of Chapter

Finally, the contest is over. Time given is not suffient for me to do all the conversion from mysql to mssql. Furthermore, the database was down about 2 times and costing me a lot of time. The admin of this hosting did not respond as quick as I expected. The usage of Plesk was not a good choice in this competition. Almost all the time it having problem with mssql. Maybe the orgeniser was not well prepared for this competition. I was assigned Wakka Wikki and I have tried my best to do the job. These are the chances that I have made to make the Wakka Wiki running on mssql backend. You can visit my application at this link: http://azmipelah.dev.lamp2win.com/wikka/wikka.php?wakka=HomePage

The process is not completed yet. I managed to make creation of tables in Mssql and make the default page loading. Some other functions are not fully working yet. The only thing you can do is to post a comment in the frontpage.

The files that are involved in the process are:

install.php (Setup directory)
wikka.class.php (Libs)
All files in Actions Directory
All files in Handlers Directory

Some other mysql functions that are not supported n mssql need to be changed. The functions are:

md5
mysql_real_escape_string is replaced by str_replace (Refer http://osdir.com/ml/php.tcphp/2005-06/msg00056.html)
Now() is replaced by getdate()

Friday, May 15, 2009

LAMP2WIN PHP Programming Contest

I just enrolled in the competition. I hope I can apply my knowledge of 7 years of PHP programming. There are about 20 applications and I need to choose one application to be converted to MsSql Enabled Application. I need some sort of driver or converter that can convert the Mysql Database into Mssql. I am positively thinking that this is the the key factor to succeed in the competition.

Saturday, April 18, 2009

Welcome to My Blog

Well finally, I have my own blog site. After considering the idea, my decision is coming to an end. I need a blog site. My objectives of joining this blog are to record my findings or study on Open Source Applications or any other computer technology related especially to PHP(recursive acronym for PHP: Hypertext Preprocessor).