Jump to content

Resent Client Widget using Gravatar


lims

Recommended Posts

example widget

<?php

namespace WHMCS\Module\Widget;
use WHMCS\Carbon;
use WHMCS\Module\AbstractWidget;
use WHMCS\User\Client;

class ClientOnline extends AbstractWidget
{
    protected $title = 'Client Online';
    protected $description = 'Recent online clients.';
    protected $weight = 50;
    protected $cache = true;
    protected $cacheExpiry = 60;
    protected $requiredPermission = 'List Clients';

    public function getData()
    {
        return array(
            'recentActiveClients' => Client::orderBy('lastlogin', 'desc')->limit(25)
                ->get(array('id', 'firstname', 'lastname', 'companyname', 'ip', 'lastlogin'))->toArray(),
        );
    }
    public function generateOutput($data)
    {
        $clientOutput = '';
        foreach ($data['recentActiveClients'] as $client) {
            $clientOutput .= '<div class="client">'
                . '<img src="https://www.gravatar.com/avatar/' . $client['email']['gravatarHash'] . '?s=60&d=mm" width="60" height="60" />'
                . '<div class="name">' . $client['lastlogin']['firstname'] . ' ' . $client['lastlogin']['lastname'] . '</div>'
                . '<div class="note text-muted">'
                . Carbon::createFromFormat('Y-m-d H:i:s', $client['lastvisit'])->diffForHumans() . '</div>'
                . '</div>';
        }
        return <<<EOF
<div class="clients-list">
    {$clientOutput}
</div>
EOF;
    }
}

 

Link to comment
Share on other sites

already fixed with my self using

        return array(
            'client' => Client::orderBy('lastlogin', 'desc')->limit(6)
                ->get(array('email', 'id', 'firstname', 'lastname', 'ip', 'lastlogin'))->toArray(),
        );
$client['email']['gravatarHash']

change to

md5($client['email'])

 

Link to comment
Share on other sites

9 minutes ago, brian! said:

@lims - can you post the entire file, as this doesn't work for me when I test it locally. 

@brian! here this full custom already modified

<?php

namespace WHMCS\Module\Widget;

use WHMCS\Carbon;
use WHMCS\Module\AbstractWidget;
use WHMCS\User\Client;

class ClientOnline extends AbstractWidget
{
    protected $title = 'Client Last Login';
    protected $weight = 80;
    protected $cache = true;
    protected $cacheExpiry = 60;
    protected $requiredPermission = 'List Clients';

    public function getData()
    {
        return array(
            'client' => Client::orderBy('lastlogin', 'desc')->limit(24)
                ->get(array('email', 'id', 'firstname', 'lastname', 'ip', 'lastlogin'))->toArray(),
        );
    }
    public function generateOutput($data)
    {
        $clientOutput = '';
        $clients = array();
        foreach ($data['client'] as $client) {
            $clientOutput .= '<div class="staff">'
                . '<a href="clientssummary.php?userid='.$client['id'].'"><img class="body-avatar" src="https://www.gravatar.com/avatar/'.md5($client['email']).'?s=60&d=mm" width="60" height="60"/></a>'
                . '<div class="name">'.$client['firstname'].' '.$client['lastname'].'</div>'
                . '<small><a href="http://www.geoiptool.com/en/?IP='.$client['ip'].'" target="_blank" class="name" style="color:red">'.$client['ip'].'</a></small>'
                . '<div class="note text-muted">'
                . Carbon::createFromFormat('Y-m-d H:i:s', $client['lastlogin'])->diffForHumans().'</div>'
                . '</div>';
        }
        return <<<EOF
<div class="widget-staff-container clearfix">
    {$clientOutput}
</div>
EOF;
    }
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated