The Joomla! Forum ™



Forum rules


Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.



Post new topic Reply to topic  [ 18 posts ] 
Author Message
PostPosted: Fri Jul 03, 2009 7:38 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Jul 03, 2009 7:30 pm
Posts: 2
I've managed to create two separate style sheets, one called "narrow.css" and the other aptly called "wide.css".

My question is, what logic string does Joomla use to check for authenticated user-login. I'd like to be able to apply a separate style sheet in the event a user is logged in vs. logged out.

Removed link, for privacy concerns with launching a large-scale website.

Thanks,
Brian Royer
Webmaster / Artist


Top
 Profile  
 
PostPosted: Fri Jul 03, 2009 8:11 pm 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Thu Jul 24, 2008 12:48 pm
Posts: 2678
Location: Austin, TX
You can use the guest property of the JUser class:
http://api.joomla.org/Joomla-Framework/User/JUser.html#$guest

You can see how it's being used in the login module:
.../modules/mod_login/helper.php
Code:
function getType()
{
   $user = & JFactory::getUser();
   return (!$user->get('guest')) ? 'logout' : 'login';
}

_________________
Will Mavis - Joomla Developer
http://www.covertapps.com/jam <<< Joomla! on your Android, iPhone, iPad, and iPod Touch
If you think I can help you, PM me a link to your post and I will respond. Please don't hijack another user's thread.


Top
 Profile  
 
PostPosted: Fri Jul 03, 2009 9:33 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Fri Jul 03, 2009 7:30 pm
Posts: 2
:pop

You are my hero!
Works perfect.

Code:
   <?php if ($user->get('guest')) : ?>
      <script type="text/javascript">
         styleswitch('set', 'narrow');
      </script>
   <?php else : ?>
      <script type="text/javascript">
         styleswitch('set', 'wide');
      </script>
   <?php endif; ?>


^^ Above code posted for future searchers!

Here is the javascript to switch styles, all props are given in the source.

Code:
/* This styleswitcher code is taken in its entirety  from:
http://www.mensching.info/program/mootools-styleswitcher-en.html - the website of Achim Mensching */
function styleswitch(mode, setstyle){
   var stylepath = 'templates/!!TEMPLATENAMEHERE!!/css/';
    // setting the path to the CSS directory
   
/* --------------------- No Need to change anything below this line -------------------------------------------*/
    var i, a;
    var cookstyle = Cookie.get('Stylesheet');
    // getting current cookie value for the stylesheet
    if (cookstyle == false ) {
                              for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
                              if(a.getAttribute("rel").indexOf('style') != -1
                              && a.getAttribute("media").indexOf('screen') != -1
                              && a.getAttribute("title")
                              // find default stylesheet, which is defined in the head section of the document
                              ) {
                                cookstyle = a.getAttribute("title");
                                Cookie.set('Stylesheet', cookstyle, {duration:365, path:'/'});
                                //set the default stylesheet as a cookie value
                                }
                               }
                             }
                             
    switch (mode) {
                  case 'set':
                    new Asset.css(stylepath + setstyle +'.css', {id: setstyle});
                    // loads the new stylesheet
                    Cookie.set('Stylesheet', setstyle, {duration:365, path:'/'});
                    // sets the active stylesheet into a cookie value
                  break;
                case 'noset':
                    new Asset.css(stylepath + setstyle +'.css', {id: setstyle});
                    // only apply the new stylesheet, without saving it in a cookie value
                    break;
                default:
                    setstyle = cookstyle
                    new Asset.css(stylepath + cookstyle +'.css', {id: cookstyle});
                    // sets the current cookie value as active stylesheet
                   break;
               }
  return null;
  }

  window.addEvent('domready', styleswitch);


Top
 Profile  
 
PostPosted: Mon Aug 16, 2010 3:50 am 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon May 11, 2009 5:45 pm
Posts: 5
Can someone explain where to place the above code?

THANK YOU


Top
 Profile  
 
PostPosted: Mon Aug 16, 2010 1:29 pm 
Joomla! Explorer
Joomla! Explorer

Joined: Fri May 21, 2010 11:43 am
Posts: 426
Location: Aachen, Germany
I'd suggest to switch the Stylesheet without using JavaScript. This way people who have disabled Javascript still have a chance, and your sites performance will also improve.


Top
 Profile  
 
PostPosted: Mon Aug 16, 2010 5:54 pm 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Thu Jul 24, 2008 12:48 pm
Posts: 2678
Location: Austin, TX
I assume shyce placed the code in their .../templates/YOURTEMPLATE/index.php file.

I agree with realityking. If you are just trying to have a different background for logged in and logged out users, it's better to do it with php code.

Let me know what you are trying to do and I will try to help give you code that will do it.

_________________
Will Mavis - Joomla Developer
http://www.covertapps.com/jam <<< Joomla! on your Android, iPhone, iPad, and iPod Touch
If you think I can help you, PM me a link to your post and I will respond. Please don't hijack another user's thread.


Top
 Profile  
 
PostPosted: Mon Aug 16, 2010 7:22 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon May 11, 2009 5:45 pm
Posts: 5
Thank you both so much for the speedy response.

I would just like the background image of the template to change when a user (any user) logs in. (Then changes back once they log out of course...)

Any tips would be greatly appreciated. :)


Top
 Profile  
 
PostPosted: Mon Aug 16, 2010 8:21 pm 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Thu Jul 24, 2008 12:48 pm
Posts: 2678
Location: Austin, TX
I would change your .../templates/YOURTEMPLATE/index.php file to have something similar to this:
Code:
<?php
   $user = & JFactory::getUser();
   if($user->get('guest')) {
      $bodyClass = "bd_guest";
   } else {
      $bodyClass = "bd_user";
   }
?>
...
<body class="<?php print $bodyClass; ?>">

The above code will add a different class to the body tag depending on if the user is logged in or not.

Then just set the styles for those in your stylesheet (.../templates/YOURTEMPLATE/css/template.css):
Code:
.bd_guest {
background: white url(/images/bg_guest.gif) no-repeat fixed 0% 0%;
}
.bd_user {
background: white url(h/images/bg_user.gif) no-repeat fixed 0% 0%;
}

Make sure to remove the background style on the body if you already have one.

You could also print the style inline on the body tag if you want or change the id of the body tag.

Hope this helps!
Will

_________________
Will Mavis - Joomla Developer
http://www.covertapps.com/jam <<< Joomla! on your Android, iPhone, iPad, and iPod Touch
If you think I can help you, PM me a link to your post and I will respond. Please don't hijack another user's thread.


Top
 Profile  
 
PostPosted: Mon Aug 16, 2010 10:48 pm 
User avatar
Joomla! Apprentice
Joomla! Apprentice

Joined: Mon May 11, 2009 5:45 pm
Posts: 5
Fantastic! Works like a charm :)

I really appreciate your time. I couldn't find that simple code anywhere, and it seems a lot of people are looking for this.

Thanks a million.


Top
 Profile  
 
PostPosted: Mon Aug 16, 2010 11:00 pm 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Thu Jul 24, 2008 12:48 pm
Posts: 2678
Location: Austin, TX
Glad I could help!

_________________
Will Mavis - Joomla Developer
http://www.covertapps.com/jam <<< Joomla! on your Android, iPhone, iPad, and iPod Touch
If you think I can help you, PM me a link to your post and I will respond. Please don't hijack another user's thread.


Top
 Profile  
 
PostPosted: Wed Nov 03, 2010 11:01 pm 
Joomla! Fledgling
Joomla! Fledgling

Joined: Wed Nov 03, 2010 10:56 pm
Posts: 2
Hi there,

I've got a question.
would this be possible for separate users?

I want my users to use there own uploaded images.
And set them as background.

Is there a code for this to integrate with cbe*?
Like a button below a picture users have uploaded with cbe* gallery

*CBE "Community Builder Advanced"


Top
 Profile  
 
PostPosted: Thu Nov 04, 2010 6:36 am 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Thu Jul 24, 2008 12:48 pm
Posts: 2678
Location: Austin, TX
It could be coded, but I don't know of anything that does that currently.

If you want to code it up, I can help walk you through how I would do it.

_________________
Will Mavis - Joomla Developer
http://www.covertapps.com/jam <<< Joomla! on your Android, iPhone, iPad, and iPod Touch
If you think I can help you, PM me a link to your post and I will respond. Please don't hijack another user's thread.


Top
 Profile  
 
PostPosted: Thu Nov 04, 2010 8:15 am 
Joomla! Fledgling
Joomla! Fledgling

Joined: Wed Nov 03, 2010 10:56 pm
Posts: 2
I would really appreciate it if you can guide me trough the coding. :)
I know something about php but not much.

My idea is that when a user is loged in, the the main background goes transparent and the body puts out an image.

Thanks for your fast reply.


Top
 Profile  
 
PostPosted: Thu Nov 04, 2010 6:02 pm 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Thu Jul 24, 2008 12:48 pm
Posts: 2678
Location: Austin, TX
Do you want to try to piggyback off an existing component or just build it up from scratch?

_________________
Will Mavis - Joomla Developer
http://www.covertapps.com/jam <<< Joomla! on your Android, iPhone, iPad, and iPod Touch
If you think I can help you, PM me a link to your post and I will respond. Please don't hijack another user's thread.


Top
 Profile  
 
PostPosted: Thu Nov 25, 2010 6:26 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Sep 17, 2009 7:57 pm
Posts: 6
Best solution around! Thanks a lot...


Top
 Profile  
 
PostPosted: Thu Jan 05, 2012 8:34 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Apr 23, 2009 3:30 am
Posts: 48
I am using Joomla 1.7, and I want to have a different header image with a different URL when someone is logged in. How can I make that happen? Would I use a code similar to this, or...?


Top
 Profile  
 
PostPosted: Fri Jan 06, 2012 1:19 am 
User avatar
Joomla! Hero
Joomla! Hero

Joined: Thu Jul 24, 2008 12:48 pm
Posts: 2678
Location: Austin, TX
There might be a better way to do this in 1.7 without having to write code. Take a look at this and see what you think:
http://docs.joomla.org/How_do_you_hide_something_from_logged_in_users%3F

_________________
Will Mavis - Joomla Developer
http://www.covertapps.com/jam <<< Joomla! on your Android, iPhone, iPad, and iPod Touch
If you think I can help you, PM me a link to your post and I will respond. Please don't hijack another user's thread.


Top
 Profile  
 
PostPosted: Fri Jan 06, 2012 9:14 pm 
Joomla! Apprentice
Joomla! Apprentice

Joined: Thu Apr 23, 2009 3:30 am
Posts: 48
wlrdq wrote:
There might be a better way to do this in 1.7 without having to write code. Take a look at this and see what you think:
http://docs.joomla.org/How_do_you_hide_something_from_logged_in_users%3F



Very cool. I don't think it would apply in this case, though, since the header image is not content, menu, module, etc.

I did a workaround solution, though... I used "display: none" on the header CSS, then added a two new modules to the topmost div position. One of them contains the image for non-logged in users, and the other has the header image for logged in users. I then set the pages on which I want them displayed and set their access permissions as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ] 



Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group