By Kyttias
Hello! I have been doing some playing with the 1.3.6 script and I was struggling to get these working with it, but after some messing about I got it lol. So here is how I did it, in case anyone wants to use them.
Also I’m not the best so if anyone way more knowledgeable than me wants to tell me I’ve done it wrong or a better/easier way of doing it totally go for it :ROFLMAO::ROFLMAO:
The assignTemplateVars() has been moved from where it was before now that 1.3.6 has gotten rid of the class_ files. It is now in resource/core/template.php. So find and open that.
To get the values working I had to add at the top:
PHP:
use Resource\Model\DomainModel;
I put it at the bottom of the other ‘use Resource’ lines.
Now scroll down until you find assignTemplateVars() and under the last line put this (make sure it’s before the curly bracket):
PHP:
$mysidia = Registry::get("mysidia");
$this->assign("logged_in",$mysidia->user->isLoggedIn());
$this->assign("username",$mysidia->user->getUsername());
$this->assign("cash",$mysidia->user->getMoney());
$this->assign("currency",$mysidia->settings->cost);
$this->assign("message_num", $mysidia->user->countMessages());
$online = $mysidia->db->select("online", array(), "username != 'Guest'")->rowCount();
$this->assign("online","{$online}");
$guests = $mysidia->db->select("online", array(), "username = 'Guest'")->rowCount();
$this->assign("guests","{$guests}");
Now open model/domainmodel/visitor.php. We need to add getMoney and countMessages into it or the site gives an error.
Put this somewhere, I put it underneath the isLoggedIn part:
PHP:
public function getMoney(){
return FALSE;
}
public function countMessages(){
return FALSE;
}
Now we can open our themes template.tpl and put this somewhere:
HTML:
<!-- If the user is logged in... -->
{if $logged_in}
Hi, <a href="{$home}profile/view/{$username}">{$username}</a><br><br> <!-- Show username -->
You have {$cash} {$currency}<br><br> <!-- Display amount of money and currency name -->
<!-- Display amount of messages you have IF you have any, if you don't just display a link to messages-->
<a href="{$home}messages">Messages {if {$message_num} >= 1}({$message_num}){/if}</a>
<br><br>
<a href="{$home}login/logout">Log Out</a>
{else}
<!-- If the user is logged out... -->
Please <a href="{$home}login">Log In</a> or <a href="{$home}register">Sign Up</a>!
{/if}
<br><br>
<!-- Display online users and guests, is there is only 1 user online display 'User'. If there are 0
or more than 1 online display 'Users'. If there are 0 guests, don't display the guest text,
if there is 1, display 'Guest', if 2 or more display 'Guests'. -->
<a href="{$home}online">{$online} {if {$online == 1}}User{else}Users{/if} Online {if {$guests} >= 1}+ {$guests} Guest{if {$guests} >= 2}s{/if}!{/if}</a>
Adding on to my stuff above, the messages part will count how many messages a user has, but NOT if they’re unread. So it will print a number even if they have read them. So if you want to display a count of unread messages…
Put this in template.php:
PHP:
$messages = $mysidia->db->select("messages", [], "touser = '{$mysidia->user->getID()}' and status='unread'")->rowCount();
$this->assign("messages",$messages);
And then use {$messages} to display unread messages.
You can use this with the {$messages_num} from before if you’d like to display total messages as well as unread ones…