Avatars

By Kyttias

Managed to get avatars working with the help of Nemesis on the Discord (thank you!)

In template.php put this:

PHP:

$profile = $mysidia->db->select("users_profile", array("uid", "avatar"), "uid = '{$mysidia->user->getID()}'")->fetchObject();

if ($profile == NULL) $img = "";


else $img = "<img src='../../".$profile->avatar."' class='avatar'>";

$this->assign->("avatar",$img);

That assigns the avatar image if the user has a profile and if they don’t (ie are a visitor) it assigns nothing.

To use it use {$avatar}.

Got a few more smarty things for 1.3.6!

First of all showing your favourite pet. Now this is probably a really long-winded way of doing this, would NOT be surprised if there is a better way, but hey… it works… It’s been tested with logged out users, as well as logged in users that both have a favpet assigned as well as don’t have one assigned.

PHP:

/* Get a user’s favourite pet */

        $favpetID = $mysidia->db->select(“users_profile”, array(“uid”, “favpet”), “uid = ‘{$mysidia->user->getID()}'”)->fetchObject();

        if ($favpetID == NULL) $favpetInfo = “”;

        else $favpetInfo = $mysidia->db->select(“owned_adoptables”, array(“aid”, “adopt”, “name”, “currentlevel”), “aid = ‘{$favpetID->favpet}'”)->fetchObject();

        if ($favpetInfo == NULL) $favpetImg = “”;

        elseif ($favpetInfo != ‘0’) $favpetImg = $mysidia->db->select(“levels”, array(“lvid”, “adopt”, “level”, “primaryimage”), “adopt = ‘{$favpetInfo->adopt}’ and level = ‘{$favpetInfo->currentlevel}'”)->fetchObject();

        if ($favpetID == NULL || $favpetInfo == ‘0’) $petImg = “”;

        elseif ($favpetInfo != NULL || $favpetInfo != ‘0’) $petImg = “<a href=’../../myadopts/manage/”.$favpetID->favpet.”‘><img src='”.$favpetImg->primaryimage.”‘ title=’Your favourite pet’></a>”;

        else $petImg = “Something has gone wrong with this data… please contact a site admin for assistance.

                        <br><br>Please include information such as what you were doing when you saw this message, as

                        well as screenshots, if possible!”;

        $this->assign(“favpet”,$petImg);

Use {$favpet} to call it.

  Spoiler: Optional alternative if you have Bootstrap 5 installed 

  Spoiler: Optional if you have Kyttias’ tooltips installed (from shop mod, inventory mod, etc) 

Random Greetings

Next this is just a little fun thing that you can add if you want to make a random greeting for your users. It uses greetings in a random array and displays them!

PHP:

/* Greetings array to display different greetings randomly */

        $sentences = array('Hello,', 'Hi,', 'Welcome,', 'Greetings,', 'Howdy,', 'Good day,', 'Hey,');

        shuffle($sentences);

        $this->assign('sentence', $sentences[0]);

Then use {$sentence} to display the greeting! They include commas so make sure to add the username using {$username} in your template.tpl if you have assigned that one.

It should display something like this:

2022-01-04 07_22_17-Bean Pets and 14 more pages – Personal – Microsoft​ Edge.png

2022-01-04 07_22_27-Bean Pets and 14 more pages – Personal – Microsoft​ Edge.png

They randomise on refresh!

This is the code that displays it like mine:

HTML:

<em>{$sentence} <a href='{$home}profile/view/{$username}'>{$username}</a></em>

Their username links to their profile. 😀

Leave a Reply

Your email address will not be published. Required fields are marked *