Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How to Show Online Members to Public

I Want to Show Registered Online Members Widget To Non Registered Members In Forum

Tagged:

Comments

  • jackmaessenjackmaessen ✭✭✭
    edited October 2015

    so actually you want to show the online members to everybody whether they are logged in or not and even for non registered users?
    In that case, go to file class.onlinenowmodule.php in Plugins->OnlineNow and disable the check for login session
    You can find the 2 sessions here: (line 7 and 15 below)

    public function GetData($Invisible = FALSE) {
            $SQL = Gdn::SQL();
            // $this->_OnlineUsers = $SQL
            // insert or update entry into table
            $Session = Gdn::Session();
            //check for valid session
            //if (!($Session->IsValid())) return; // disable this line
            $Photo = $Session->User->Photo;
            $Invisible = ($Invisible ? 1 : 0);
                    .....
    
    public function ToString() {
                $String = '';
                $Session = Gdn::Session();
                //if (!($Session->IsValid())) return; // disable this line
    
                ob_start();
                ?>
                    <div id="OnlineNow" class="Box">
                        <h4><?php echo T("Online Now"); ?> (<?php echo $this->_OnlineUsers->NumRows(); ?>)</h4>
                        <ul class="PanelInfo">
                          .....
    
  • Thanks.. Its Working

  • kopnakopna Coimbra Portugal ☯

    Does not work:
    Changed class.onlinenowmodule.php
    [spoiler]<?php if (!defined('APPLICATION')) exit(); /** * Renders a list of users who are taking part in a particular discussion. */ class OnlineNowModule extends Gdn_Module { protected $_OnlineUsers; public function __construct($Sender = '') { parent::__construct($Sender); } public function SetOnlineUsers($OnlineUsers) { $this->_OnlineUsers = $OnlineUsers; } public function GetData($Invisible = FALSE) { $SQL = Gdn::SQL(); // $this->_OnlineUsers = $SQL // insert or update entry into table $Session = Gdn::Session(); //check for valid session if (!($Session->IsValid())) return; // disable this line $Photo = $Session->User->Photo; $Invisible = ($Invisible ? 1 : 0); if ($Session->UserID) $SQL->Replace('OnlineNow', array( 'UserID' => $Session->UserID, 'Timestamp' => Gdn_Format::ToDateTime(), 'Photo'=> $Session->User->Photo, 'Invisible' => $Invisible), array('UserID' => $Session->UserID) ); $Frequency = C('Plugins.OnlineNow.Frequency', 60); $History = time() - $Frequency; $SQL ->Select('u.UserID, u.Name, u.Photo, u.Email, w.Timestamp, w.Invisible') ->From('OnlineNow w') ->Join('User u', 'w.UserID = u.UserID') ->Where('w.Timestamp >=', date('Y-m-d H:i:s', $History)) ->OrderBy('u.Name'); if (!$Session->CheckPermission('Plugins.OnlineNow.ViewHidden')) $SQL->Where('w.Invisible', 0); $this->_OnlineUsers = $SQL->Get(); } function GetPhoto($User, $Options = array()) { $Session = Gdn::Session(); if (!($Session->IsValid())) return; $Photo = $Session->User->Photo; if (!$Photo && function_exists('UserPhotoDefaultUrl')) $Photo = UserPhotoDefaultUrl($User); if ($Photo) { if (!preg_match('`^https?://`i', $Photo)) { $PhotoUrl = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s')); } else { $PhotoUrl = $Photo; } $Href = Url(UserUrl($User)); return 'Name).'" href="'.$Href.'"'.$LinkClass.'>' .Img($Session->User->PhotoUrl, array('alt' => htmlspecialchars($User->Name),'class' => 'ProfilePhotoSmall','title' => htmlspecialchars($User->Name))).''; } else { return ''; } } */ public function AssetTarget() { //return 'Foot'; return 'Panel'; } public function ToString() { $String = ''; $Session = Gdn::Session(); if (!($Session->IsValid())) return; // disable this line ob_start(); ?>


    <?php echo T("Online Now"); ?> (<?php echo $this->_OnlineUsers->NumRows(); ?>)


      <?php if ($this->_OnlineUsers->NumRows() > 0) { foreach($this->_OnlineUsers->Result() as $User) { if (($Session->CheckPermission('Plugins.OnlineNow.ViewHidden')) || ($User->Invisible < 1)) { echo "<li>"; // echo UserPhoto($User, array('ImageClass' => 'onimage')); $UserPhoto = UserPhoto($User, array('ImageClass' => 'onimage')); $UserPhoto = preg_replace('/(<[^>]+) title=".*?"/i', '$1', $UserPhoto); $PM = Url('/messages/add/'); echo $UserPhoto; $Href = Url(UserUrl($User)); echo '<div class="Time">'.'<a class="'.'Popup Name'.'" title="'.'" href="'.$Href.'"'.'>'.htmlspecialchars($User->Name).'</a>'.'<a class="'.'Popup Time'.'" title="'.'"'.'>'.Gdn_Format::Date($User->Timestamp).'</a>'.'</div>'; echo "</li>"; } } } echo "</ul>"; echo "</div>"; $String = ob_get_contents(); @ob_end_clean(); return $String; } }[/spoiler] Not Changed class.onlinenowmodule.php [spoiler]<?php if (!defined('APPLICATION')) exit(); /** * Renders a list of users who are taking part in a particular discussion. */ class OnlineNowModule extends Gdn_Module { protected $_OnlineUsers; public function __construct($Sender = '') { parent::__construct($Sender); } public function SetOnlineUsers($OnlineUsers) { $this->_OnlineUsers = $OnlineUsers; } /* public function GetData($Invisible = FALSE) { $SQL = Gdn::SQL(); // $this->_OnlineUsers = $SQL // insert or update entry into table $Session = Gdn::Session(); //check for valid session if (!($Session->IsValid())) return; $Photo = $Session->User->Photo; $Invisible = ($Invisible ? 1 : 0); if ($Session->UserID) $SQL->Replace('OnlineNow', array( 'UserID' => $Session->UserID, 'Timestamp' => Gdn_Format::ToDateTime(), 'Photo'=> $Session->User->Photo, 'Invisible' => $Invisible), array('UserID' => $Session->UserID) ); $Frequency = C('Plugins.OnlineNow.Frequency', 60); $History = time() - $Frequency; $SQL ->Select('u.UserID, u.Name, u.Photo, u.Email, w.Timestamp, w.Invisible') ->From('OnlineNow w') ->Join('User u', 'w.UserID = u.UserID') ->Where('w.Timestamp >=', date('Y-m-d H:i:s', $History)) ->OrderBy('u.Name'); if (!$Session->CheckPermission('Plugins.OnlineNow.ViewHidden')) $SQL->Where('w.Invisible', 0); $this->_OnlineUsers = $SQL->Get(); } */ /*function GetPhoto($User, $Options = array()) { $Session = Gdn::Session(); if (!($Session->IsValid())) return; $Photo = $Session->User->Photo; if (!$Photo && function_exists('UserPhotoDefaultUrl')) $Photo = UserPhotoDefaultUrl($User); if ($Photo) { if (!preg_match('`^https?://`i', $Photo)) { $PhotoUrl = Gdn_Upload::Url(ChangeBasename($Photo, 'n%s')); } else { $PhotoUrl = $Photo; } $Href = Url(UserUrl($User)); return 'Name).'" href="'.$Href.'"'.$LinkClass.'>' .Img($Session->User->PhotoUrl, array('alt' => htmlspecialchars($User->Name),'class' => 'ProfilePhotoSmall','title' => htmlspecialchars($User->Name))).''; } else { return ''; } } */ public function AssetTarget() { //return 'Foot'; return 'Panel'; } public function ToString() { $String = ''; $Session = Gdn::Session(); if (!($Session->IsValid())) return; ob_start(); ?> <?php echo T("Online Now"); ?> (<?php echo $this->_OnlineUsers->NumRows(); ?>)
        <?php if ($this->_OnlineUsers->NumRows() > 0) { foreach($this->_OnlineUsers->Result() as $User) { if (($Session->CheckPermission('Plugins.OnlineNow.ViewHidden')) || ($User->Invisible < 1)) { echo "<li>"; // echo UserPhoto($User, array('ImageClass' => 'onimage')); $UserPhoto = UserPhoto($User, array('ImageClass' => 'onimage')); $UserPhoto = preg_replace('/(<[^>]+) title=".*?"/i', '$1', $UserPhoto); $PM = Url('/messages/add/'); echo $UserPhoto; $Href = Url(UserUrl($User)); echo '<div class="Time">'.'<a class="'.'Popup Name'.'" title="'.'" href="'.$Href.'"'.'>'.htmlspecialchars($User->Name).'</a>'.'<a class="'.'Popup Time'.'" title="'.'"'.'>'.Gdn_Format::Date($User->Timestamp).'</a>'.'</div>'; echo "</li>"; } } } echo "</ul>"; echo "</div>"; $String = ob_get_contents(); @ob_end_clean(); return $String; } }[/spoiler] :(
Sign In or Register to comment.