Users can now have custom css if you use this with another module

atuyo60 - January 17, 2008 - 17:23
Project:Blog Theme
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

You have a great module here but combined with another great module by Davy Van Den Bremt, the User Profile Theme module at http://drupal.org/project/user_profile_theme it would be a match made in heaven (at least I hope it works fine, I have not tested this extensively)

First, edit the current release (5.x-1.x-dev as of writing) to resolve the bug http://drupal.org/node/211212 and you can optionally remove the part where the css file is added on view at around line 155, I say optional because it doesn't seem to add a duplicate css file even with the next few changes.

Now in that part of the file (line 155 of the user profile theme module) you copy this:

// We add the CSS file to the header.
if(user_access('view theme') && user_access('have theme', $user)) {
drupal_add_css(_user_profile_theme_get_filename($user->uid), 'module', 'screen');
}

Add just before the break in case comment, case node and case shoutbook of the function blog_theme_menu() in the Blog Theme module:

if (module_exists('user_profile_theme')) {
// We add the CSS file to the header.
if(user_access('view theme') && user_access('have theme', $user)) {
drupal_add_css(_user_profile_theme_get_filename($user->uid), 'module', 'screen');
}
  }

***** I do not know case image is for which display so I did not add it in, anyone can enlighten me on this as I can't seem to find the page which uses that case *****

Next, remember to add

if (module_exists('user_profile_theme')) {
  global $user;
  }
just below the global $custom_theme; line in the same function and you should be all set for users to input their own css.

Set the appropriate permissions for both modules and you should see a css option in the user account edit page.

#1

atuyo60 - January 17, 2008 - 17:53

mm.. sorry, I think some other part needs to be changed, doesn't quite work as expected yet...

Change

if(user_access('view theme') && user_access('have theme', $user)) {
drupal_add_css(_user_profile_theme_get_filename($user->uid), 'module', 'screen');
}
to
if(user_access('view theme')) {
drupal_add_css(_user_profile_theme_get_filename($uid), 'module', 'screen');
}

But to prevent it showing when user does not have theme, I am unsure how user_access('have theme', $user) can be done if we only have the uid of the account to check, as in $user should be replaced by what value?

In the meantime, I have used this:

if(file_exists(_user_profile_theme_get_filename($uid))){
drupal_add_css(_user_profile_theme_get_filename($uid), 'module', 'screen');
}
instead

#2

beginner - April 10, 2008 - 05:12
Category:task» feature request

#3

atuyo60 - August 5, 2008 - 14:24

so which situation does case 'image' actually apply?

#4

beginner - August 6, 2008 - 04:26
Version:5.x-1.2» 6.x-1.x-dev

I am not sure about the case image myself. I think it handles a special path implemented by another module. It was already there when I took over the module.

Can you create a patch following the guidelines here?
http://drupal.org/patch/create

Anyway, I would not implement this feature for D5. New features will go to the head / D6 version of the module. However, the other module does not seem to be actively maintained. There is no commit after the initial commit. There's no official D6 release (see #287361: Port to D6 )

 
 

Drupal is a registered trademark of Dries Buytaert.