Logged in elements

Mark

Administrator
Staff member
everything is possible ;) you can make a simple plugin to do this

PHP:
  if (isset($_COOKIE['atsphp_sid_user_cp'])) {
$TMPL['user_logged_in_hide'] = ' style="disply: none";'
}
then in your template you can add {$user_logged_in_hide} to the element you want to hide.

for example: <div class="something" {$user_logged_in_hide}>Some text</div>

You can also use the welcome_not_logged_in.html and welcome_logged_in.html templates to show login form or login links etc.

there are several other ways you can handle this, its up to you and your needs
 

proxydesign

Visiolist-Fan
Okey, thank you Mark.
I think it is difficult to make a plugin, I don't know which filename it should be (index.php), (details.php). If you have time, can you help me further?

Thank you in advance.
 

proxydesign

Visiolist-Fan
Thank you, I did follow the tutorial and is a step longer, but I can't get it to work.

I have uploaded my plugin as it is, and maybe you can check it for errors - or maybe the PHP-code isn't working at all.

My HTML in wrapper.html is like this:
HTML:
<div id="rightnav">
          <a href="#" class="classname" {$user_logged_in_hide}>Logg inn</a>
          <a href="#" class="classname" {$user_logged_in_hide}>Registrer</a>
 
        </div>
Thank you for helping.
 

Attachments

Basti

Administrator
Staff member
2 issues i see here

1) if you run on visiolist 0.9 the filename is wrong. stats_compile_stats hook dont exist anymore
- in case you want it only be hidden from stats ( details in 0.9 ) the filename has to be details_compile_details.php since it run from sources/details.php and the hook within there is called details_compile_details
Now it would be only hidden from stats pages. But i suppose you want it hidden globally
In that case you have an option for several hooks you could use. The most suitable would be
--> global_start.php which is run from the index.php file
--> or skin_global.php which is run from sources/misc/skin.php

Which one you take doesnt really matter and might be a personal preference. But use either of them

2) now open the file, your current code is
Code:
if (isset($_COOKIE['atsphp_sid_user_cp'])) {
$TMPL['user_logged_in_hide'] = ' style="disply: none";'
}
There are 3 issues in there ( thanks to marks fast typing :p )
The semicoln is wrong, the css stuff has a typing mistake, and the template tag is not initialized, which cause a php error notice in php > 5.3

Use this
Code:
$TMPL['user_logged_in_hide'] = '';  // This initialize a php variable if its a string
if (isset($_COOKIE['atsphp_sid_user_cp'])) {
    $TMPL['user_logged_in_hide'] = ' style="display: none;"';
}
 

proxydesign

Visiolist-Fan
Thank you so much!!!

That did work perfectly, thank you again! :D

Btw, may I ask how I can do this with {$user_logged_in} (only be seen when a user is logged in).
 

Basti

Administrator
Staff member
It goes the same way, you have your code
$TMPL['user_logged_in_hide'] = ''; // This initialize a php variable if its a string
if (isset($_COOKIE['atsphp_sid_user_cp'])) {
$TMPL['user_logged_in_hide'] = ' style="display: none;"';
}
Now initialize your new tag like above
and then the new tag goes exactly where the other one is. Everything in between the "if" is only seen when user is logged in. If he isnt, the template tag is a blank variable ( the initialized tag )
 

proxydesign

Visiolist-Fan
Well, yeah.
I get it to be seen when a user logs in, but it is also possible to see the box when a user isn't logged in.

My code is like this now:
PHP:
$TMPL['user_logged_in'] = '';  // This initialize a php variable if its a string
if (isset($_COOKIE['atsphp_sid_user_cp'])) {
    $TMPL['user_logged_in'] = ' style=""';
}
Thank you.

EDIT: I did also try this:
PHP:
$TMPL['user_logged_in'] = '';  // This initialize a php variable if its a string
if (isset($_COOKIE['atsphp_sid_user_cp'])) {
    $TMPL['user_not_logged_in'] = ' style="display: none;"';
}
with the HTML:
HTML:
 <a href="#" class="button"{$user_not_logged_in} {$user_logged_in}><span style="color: #fff;">Log out</span></a>
but didnt work that either. :/
 

Basti

Administrator
Staff member
Uhm in that case i suggest you something entirely different
Code:
 // This time no intialize is needed, because we use an if, else
 
// If user is logged in 
if (isset($_COOKIE['atsphp_sid_user_cp'])) {
    // Logout button 
    $TMPL['top_buttons'] =  '<a href="#" class="button"><span style="color: #fff;">Log out</span></a>';
}
// Else user not is not logged in ( cookie dont exist )
else {
    // Login, register button 
    $TMPL['top_buttons']  =  '<a href="#" class="button"><span style="color: #fff;">Login</span></a>';
    $TMPL['top_buttons'] .=  '<a href="#" class="button"><span style="color: #fff;">Register</span></a>';  
}
Now place {$top_buttons} into wrapper where you want the buttons to appear
This way you also dont have to much hidden content

Or another way, without using a plugin, like Mark mentioned before is to use your welcome_not_logged_in.html and welcome_logged_in.html files of your skin.
You could replace the content in these files simply with your buttons and place {$wrapper_welcome} where the buttons shall appear
The "magic" with this is practically the same as with the plugin, just that its a core feature
 
Top