Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 06-17-2014, 02:47 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,983
Kyttias is on a distinguished road
Default Smarty and Conditional Templating~?

So I've been reading through Smarty documentation, since Mysidia is built using that templating system.

The documentation suggests we can do things such as the following in our template (.tpl) files:

PHP Code:
{if $logged_in}
Welcome, {$username}!
{else}
Please log in or sign up~
{/if} 
That's pretty neat, and conditional templating sounds fun, considering there are large portions of my menu I'd rather not display to users not signed in. Currently a $logged_in variable by that name does not exist, so only the else statement will ever appear, and I was hoping {$mysidia->user->isloggedin} and {$mysidia->user->username} would work but those are not accessible outside their scope, and, honestly, why isn't Registry::get("mysidia"); on a global scope? They're accessible in the sidebar.

My complaint with the sidebar usage is that... well... I want more freedom than that? I want to place it in anywhere in my template (.tpl) and not have to mess with deep Mysidia files every time I want to place my user's name or currency amount. If I want to display any variable on this site, I want to make full use of the Smarty templating. I think some considerations for the next version of Mysidia should be made in regards to variables accessible to us from any page, any where, any time.

In short -
Where can I/should I/do I position Registry::get("mysidia"); to make its usage global?
How do I go about shortening {$mysidia->user->username} to {$username}, {$mysidia->user->isloggedin} to {$logged_in}, and {$mysidia->user->money} {$mysidia->settings->cost} to {$currency}?

~ <3

Last edited by Kyttias; 06-17-2014 at 03:26 PM.
Reply With Quote
  #2  
Old 06-17-2014, 04:10 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,353
IntoRain is on a distinguished road
Default

I'm currently enjoying the joys of Smarty, after having to use it for a class this semester. I will see if I can explain this well! :D

Basically Smarty is a way to code a template without putting PHP and HTML together. You basically need to assign a PHP variable into a Smarty variable, to be able to use it in a .tpl

I usually set my variables in class_template.php's assignTemplateVars() function with

PHP Code:
$this->assign("nameToUseInTemplate",$nameOfVariable); 
and in class_frame.php with

PHP Code:
$mysidia->template->assign("temp",$var); 
So, in those files, as long as you have this:

PHP Code:
$mysidia Registry::get("mysidia"); 
You can use anything from mysidia.

--------------

To assign the loggedin variable to a Smarty variable called logged_in in class_template.php:

PHP Code:
$mysidia Registry::get("mysidia");
$this->assign("logged_in",$mysidia->user->isloggedin); 
You can now use {$logged_in} in your template.tpl file.

More examples (in class_template.php):

PHP Code:
$mysidia Registry::get("mysidia");
$this->assign("logged_in",$mysidia->user->isloggedin);

//get user's cash
$this->assign("user_cash",$mysidia->user->getcash());

//get user's username
$this->assign("username",$mysidia->user->username);

//get user's group
$this->assign("group",$mysidia->user->getusergroup());

//get user's new unread messages (3 max)
$messages $mysidia->db->select("messages", array(), "touser='{$mysidia->user->username}' and status='unread' ORDER BY id DESC LIMIT 3")->fetchAll();
$this->assign("messages",$messages);

//using messages in template.tpl (example):
{foreach from=$messages item=message}
<
a href="/messages/read/{$message.id}">
      
From:{$message.fromuser}
      
Title:{$message.messagetitle}
      
Date:{$message.datesent}
</
a>
{/foreach} 
__________________


asp.net stole my soul.
Reply With Quote
  #3  
Old 06-17-2014, 04:54 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,983
Kyttias is on a distinguished road
Default

I've still yet to get it to work completely.

Let's start with what I've successfully done -
In class_template.php's assignTemplateVars() function I've added:
Code:
$mysidia = Registry::get("mysidia");
$this->assign("logged_in",$mysidia->user->isloggedin);
$this->assign("username",$mysidia->user->username);
$this->assign("cash",$mysidia->user->getcash());
$this->assign("currency",$mysidia->settings->cost);
And in template.tpl:
Code:
{if $logged_in}
Welcome, <a href="{$home}profile/view/{$username}"><b>{$username}</b></a>! 
<br/>
You have {$cash} <b>{$currency}</b>. 
{else}
Please sign up or log in~! 
{/if}
And this displays the correct outcome! Yay!

However, using -
Code:
$this->assign("group",$mysidia->user->getusergroup());
Results in a blank white page.

I'm as of yet unsure how or if the messages work, but I'd like it to just display a number of unread messages a user has, and possibly 0 if there is none? I have no messages, so nothing appears. It looked like it would display more than just a number, but information about the messages. I don't think I need that, but a number next to an envelope icon is floating in my head as a pleasant sight.

Also, thank you very much!

Last edited by Kyttias; 11-05-2014 at 02:11 PM.
Reply With Quote
  #4  
Old 06-17-2014, 05:21 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,353
IntoRain is on a distinguished road
Default

Sorry! It's $mysidia->user->getgroup()! Which will return one of the groups available in your database (rootadmins, admins,registered,artists,banned,visitors).

Messages is an array containing multiple message objects, that's why I use foreach there, it goes through every "item" in the messages variable. Each Message contains a title, content, date, etc... To get just the number of new messages:

$messages = $mysidia->db->select("messages", array(), "touser='{$mysidia->user->username}' and status='unread'")->rowCount();
$this->assign("messages",$messages);
__________________


asp.net stole my soul.
Reply With Quote
  #5  
Old 06-17-2014, 05:29 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,983
Kyttias is on a distinguished road
Default

Awesome! Very soon I'll have replaced the entire sidebar. Added this, too:
Code:
$online = $mysidia->db->select("online", array(), "username != 'Visitor'")->rowCount();
$offline = $mysidia->db->select("online", array(), "username = 'Visitor'")->rowCount();
$this->assign("population","{$online} Users Online, {$offline} Guests");
I've always wanted this in the footer, now I finally can.
Code:
<a href="{$home}/online">{$population}</a>
And as a follow up to something we had done in another thread, and in case anyone is paying attention to this one, this will allow one to display the current server time with {$time} and it will show up as, for example, 07:37 PM:
Code:
$now = new DateTime();		
$display = $now->format('h:i A');		
$this->assign("time",$display);

Also~!!

I almost forgot Mysidia had a friend's list system. The 'send friend request' button is currently on the last tab of the profile... I'll be moving that to the front where it's easier to find. However, Is there a table in the database that may be able to help me make a notification system for unaccepted/new friend requests? And I seem to be overlooking where I can link users to a list of their own friends, other than their profile...

Last edited by Kyttias; 06-17-2014 at 06:37 PM.
Reply With Quote
  #6  
Old 06-17-2014, 06:55 PM
IntoRain's Avatar
IntoRain IntoRain is offline
Moderator
 
Join Date: Jul 2013
Location: Portugal
Posts: 461
Gender: Female
Credits: 19,353
IntoRain is on a distinguished road
Default

Hehe it's good you are getting used to it ^^ The table friend_requests might help, status = pending means unaccepted.

The table users keeps a list of friends as a string (each friend separated by a comma). The way profile does it is to create a Friendlist object (class_friendlist), with the user object. The Friendlist object then creates an array of integers (the friends IDs) by dividing the entire string (explode(",",string)). I'd look into class_userprofile.php (getfriends() function) and class_friendlist.php depending on what you want to do. mysidia->user->getfriends() seems to return the full string with friends as well, if you want to use Explode() on it yourself. After Explode() you get an array with all the ids, you can then create a Member object using those ids.
__________________


asp.net stole my soul.
Reply With Quote
  #7  
Old 06-17-2014, 08:30 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,983
Kyttias is on a distinguished road
Default

Ah, what if I just wanted the number of pending friend requests, but not a list of names? Is that simpler? (Is exploding supposed to sound dangerous, because it does.) I'll take a closer look in a few minutes, but I really can't thank you enough for all this help. ovo~

I could probably make a tooltip with a fun combination of Smarty conditionals and Javascript, that if the 'pending requests' are 'greater than 0', hovering over the notification would pull down a notification with, if I knew how to get this information, the pending friend(s) names and links to confirm or deny them without the need to travel to a new page. But that sounds more ambitious than I want to trouble myself with for tonight.

On a similar vein, if the messages in the inbox were 'greater than zero', to hover over the number and show some basic information, like the message titles (wherein clicking a specific title would take you to that specific message as well) and the senders, of about the first three messages, sort of like you had originally given.

I'll probably accumulate the things I've learned here into a nice convenient post for others eventually. My intention is, of course, to give people a way to easily install something like this, to go under a header image of their choosing:

Last edited by Kyttias; 06-17-2014 at 08:39 PM.
Reply With Quote
  #8  
Old 06-17-2014, 09:04 PM
Kesstryl's Avatar
Kesstryl Kesstryl is offline
Member
 
Join Date: Feb 2012
Posts: 125
Gender: Female
Credits: 17,267
Kesstryl is on a distinguished road
Default

You wouldn't mind making a mod for this and putting it in the mod section, would you please? I like your changes and I'd love to have something similar for my site. I don't want to copy you, but something simple like showing how much cash you have on each page, unread messages, etc, those are must haves.
Reply With Quote
  #9  
Old 06-17-2014, 09:11 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,983
Kyttias is on a distinguished road
Default

Quote:
Originally Posted by Kesstryl View Post
You wouldn't mind making a mod for this and putting it in the mod section, would you please? I like your changes and I'd love to have something similar for my site. I don't want to copy you, but something simple like showing how much cash you have on each page, unread messages, etc, those are must haves.
^^ I think I will, given enough time. For now, you're more than welcome to reference any information here! It's relatively straight forward, luckily. I think I also might release a theme around it (one that expands on Bootstrap). Thus far. . .

Last edited by Kyttias; 06-18-2014 at 02:16 AM.
Reply With Quote
  #10  
Old 06-18-2014, 04:33 AM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 331,531
Hall of Famer is on a distinguished road
Default

It should be very easy to make a friend request notification system. The mechanism can be very similar to new PM notification, my suggestion is to look at how PM notification is generated and make something similar to this. In fact, this feature is planned for Mys v1.4.0.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Smarty Tips: Things you can do with Templates Kyttias Tutorials and Tips 5 04-03-2015 10:53 AM
Assigning array to smarty variables IntoRain Questions and Supports 3 06-03-2014 02:06 PM
Smarty errors and WAMPP Kesstryl Questions and Supports 15 01-29-2014 09:07 PM
Problem: smarty class 1.3.4 draugluin Questions and Supports 8 11-15-2013 02:29 AM


All times are GMT -5. The time now is 11:09 AM.

Currently Active Users: 612 (0 members and 612 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636