Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2016-07-18 08:38:33

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 191
Website

kuo_user_last_action: record username, timestamp and partial URL...

There’s another topic where people are talking about collecting date and time when user logs in. ;-) This plugin doesn’t actually save timestamp when user logs in, or when user logs out, but after logging in it saves the last action user made + timestamp when user did it. Please open the screenshot for more info.

Offline

#2 2016-07-18 15:59:57

mrdale
Moderator
From: Walla Walla
Registered: 2004-11-19
Posts: 2,202
Website

Re: kuo_user_last_action: record username, timestamp and partial URL...

kuopassa wrote #300316:

There’s another topic where people are talking about collecting date and time when user logs in. ;-) This plugin doesn’t actually save timestamp when user logs in, or when user logs out, but after logging in it saves the last action user made + timestamp when user did it. Please open the screenshot for more info.

Perfect! much more useful than the stock user tracking capability.

Offline

#3 2016-07-18 16:23:54

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,400

Re: kuo_user_last_action: record username, timestamp and partial URL...

I tried it on a Textpattern 4.5.7 installation and it gives me an error:

Parse error: syntax error, unexpected ‘[’ in /home/www/web222/html/domain/textpattern/lib/txplib_misc.php(812) : eval()’d code on line 37

Los errores anteriores los ha causado el plugin:kuo_user_last_action

Offline

#4 2016-07-18 21:53:33

mrdale
Moderator
From: Walla Walla
Registered: 2004-11-19
Posts: 2,202
Website

Re: kuo_user_last_action: record username, timestamp and partial URL...

Yeah. I had the same issues. Think this one needs more work

Offline

#5 2016-07-18 21:53:51

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 272
Website

Re: kuo_user_last_action: record username, timestamp and partial URL...

I’m seeing the same error as GugUser. Is this plugin 4.6 only?

Excellent idea though.

Offline

#6 2016-07-19 11:04:09

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 8,631
Website

Re: kuo_user_last_action: record username, timestamp and partial URL...

towndock wrote #300324:

I’m seeing the same error as GugUser.

It’s probably a PHP version thing. kuopassa is accessing an array index directly off the back of a function call, which wasn’t introduced until PHP 5.4 or 5.5 or something.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#7 2016-07-19 14:19:57

towndock
Member
From: Oriental, NC USA
Registered: 2007-04-06
Posts: 272
Website

Re: kuo_user_last_action: record username, timestamp and partial URL...

Bloke wrote #300333:

It’s probably a PHP version thing. kuopassa is accessing an array index directly off the back of a function call, which wasn’t introduced until PHP 5.4 or 5.5 or something.

Damn, Bloke. You’re always right. Yup – the install I tried it on had PHP 5.3. I just tried it on a TXP install on a different server (PHP 5.5) – no errors. Thank you.

Question for kuopassa – is there anywhere this plugin displays the information? Or does it just write to the database – and we need to code to display that info?

Offline

#8 2016-07-21 13:54:12

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,400

Re: kuo_user_last_action: record username, timestamp and partial URL...

Yes, it was a PHP version related issue. Now, that it works (PHP 5.6.19), where can I see the details?

Offline

#9 2016-07-22 13:49:34

kuopassa
Plugin Author
From: Porvoo, Finland
Registered: 2008-12-03
Posts: 191
Website

Re: kuo_user_last_action: record username, timestamp and partial URL...

This plugin simply logs the data, but here are some code examples:

List users who haven’t had any activity in recent months according to kuo_user_last_action

By modifying this code below you could for example send mail() to those users who haven’t been around, or you could delete those accounts, or change their privileges.

<txp:php>
$passive_users = safe_rows("username","kuo_user_last_action","`username` != '' AND `username` IS NOT NULL AND `timestamp` < ('".date('Y-m-d H:i:s')."' - INTERVAL 6 MONTH)",0);
if ($passive_users) {
    foreach ($passive_users as $passive_user) {
        echo $passive_user['username'].'<br />';
    }
}
</txp:php>

Get current user’s information from txp_users if that user is logged in

<txp:php>
if (is_logged_in()) {
    $current_user_information = safe_query("SELECT
    ".safe_pfx('txp_users').".user_id AS `user_id`,
    ".safe_pfx('txp_users').".RealName AS `realname`,
    ".safe_pfx('txp_users').".email AS `email`,
    ".safe_pfx('txp_users').".privs AS `privs`
    FROM ".safe_pfx('txp_users')."
    LEFT JOIN `".safe_pfx('kuo_user_last_action')."` ON '".safe_pfx('kuo_user_last_action').".username' = '".safe_pfx('txp_users').".name'
    WHERE `name` = '".is_logged_in()['name']."'",0);
    if ($current_user_information) {
        $current_user_information = nextRow($current_user_information);
        echo '<ul>
            <li>ID: '.$current_user_information['user_id'].'</li>
            <li>Name: '.$current_user_information['realname'].'</li>
            <li>Email: '.$current_user_information['email'].'</li>
            <li>Privileges: '.$current_user_information['privs'].'</li>
        </ul>';
    }
}
</txp:php>

Show in HTML table all users activity according to this plugin

This lists username, date and time of last activity, as well as the partial URL of what action that user made.

<txp:php>
$all_users_last_activity = safe_rows("username, timestamp, action","kuo_user_last_action","`username` != '' AND `username` IS NOT NULL",0);
if ($all_users_last_activity) {
    $last_activity_table = NULL;
    foreach ($all_users_last_activity as $user_last_activity) {
        $last_activity_table .= '<tr>
            <td>'.$user_last_activity['username'].'</td>
            <td>'.$user_last_activity['timestamp'].'</td>
            <td>'.$user_last_activity['action'].'</td>
        </tr>';
    }
    echo '<table>
        <thead>
            <tr>
                <th>User</th>
                <th>Date and time</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            '.$last_activity_table.'
        </tbody>
    </table>';
}
</txp:php>

Offline

Board footer

Powered by FluxBB