This forum is for module development and code related questions, not general module support. For general support, use the Post installation forum.

Dynamically assign non-persistent roles?

Hello,

I am currently working on a module for Drupal 4.5.x in which I would like to dynamically assign non-persistent roles to externally authenticated users. The way that I set out to do this was by catching the load operation in my module's hook_load function and then set or unset elements of $user->roles as required.

Unfortunately, this does not seem to work the way that I had expected it. I am able to manipulate the user object the way I want, and by tracing my way through the user.module code, I found that at the end of user_login() the user object still has the correct roles. This is on line 795 of user.module of version 4.5.2.

Note that to prevent the roles that I set from being overwritten, I moved user_module_invoke('load', $array, $user) in user_load. The last part of that function now looks like:

  if (db_num_rows($result)) {
    $user = db_fetch_object($result);
    $user = drupal_unpack($user);

    $user->roles = array();
    $result = db_query('SELECT r.rid, r.name FROM {role} r INNER JOIN {users_roles} ur ON ur.rid = r.rid WHERE ur.uid = %d', $user->uid);
    while ($role = db_fetch_object($result)) {
      $user->roles[$role->rid] = $role->name;
    }
  }
  else {
    $user = new StdClass();
  }
  user_module_invoke('load', $array, $user);

  return $user;

I also need to point out that my users are authenticated against an external source, which makes things a little more complicated.

My feeling is that the user object gets reset/reloaded somewhere between completing the login sequence and presenting the first page.

For reference, the code that adjusts the user's roles (which I think is correct) is now

    if ($op == 'load') {
        // only address hyperborea users
        if (!ereg('^(.*)@hyperborea.net$', $user->name, $match)) return;

        $hyperuser = _get_hyper_user($match[1]);
        if (sizeof($hyperuser) == 0) return;

        if ($hyperuser['wizlevel'] > 0) {
            $user->roles[WIZARD_ROLEID] = WIZARD_ROLELABEL;
        } else {
            if (array_key_exists(WIZARD_ROLEID, $user->roles)) {
                unset($user->roles[WIZARD_ROLEID]);
            }
        }

        if ($hyperuser['level'] > 0) {
            $user->roles[PLAYER_ROLEID] = PLAYER_ROLELABEL;
        } else {
            if (array_key_exists(PLAYER_ROLEID, $user->roles)) {
                unset($user->roles[PLAYER_ROLEID]);
            }
        }

    }

If anyone could point me into the right direction; either by referring me to docs, code examples, or by helping me debug, I would greatly appreciate any help. I have a tendency of hanging out on #drupal (irc.freenode.net) as pa5kl.

pathauto, adding new placeholders for pattern?

I love the pathauto module but for my purposes I would like to implement two more placeholders:

[node]
The [node] placeholder should write out the current node type, hence "blog" or "book".
[user]
the [user] placeholder should write out the current user name.

This would allow me to create automated path aliasing where users blog submissions receive the following syntax:

[blog]/[user]/[title]

Is there a simple way of implenting this?

Thanx a million.

HTMLtidy brokes rss feeds

Hello! Please help me!
I installed htmltidy, and the RSS feeds syndicated from my site get broken. They can still be readed from RSS Readers, but I have other Drupal site, that aggregates content from the first. Now when I try to aggregate content I see error message "Failed to parse RSS feed : junk after document element at line"...
I need htmltidy, and I can't remove it, becouse it fix my theme Pushbutton. This theme get's broken when user make formating of his text and all text style gets broken.
sorry for english:)

NiceLinks module activation makes my site crash - how to recover / complete installation?

Please help

I've just tried to install the nicelinks module recommended at the Glossary module documentation.
My site is now crashed. On each pageload, I get the following error:
Fatal error: Call to undefined function: drupal_get_path() in .../nicelinks.module on line 18

My first questions: Which mysql table stores drupal module list? And how to disable the module so that my site would load?

More Information:
The nicelinks module was installed just after the nice Glossary module installation, in my new Drupal 4.5.1.
The Glossary module documentation (http://drupal.org/project/glossary) says:
"This module also works with nicelinks.module, which will give you pretty hover-over glossary term descriptions on reasonably modern browsers (while degrading properly on older ones)."

So I've tryied to locate the nicelinks module - it's not mentioned on the modules list.
I've searched Google and found a reference to the source code at
http://cvs.drupal.org/viewcvs/drupal/contributions/modules/nicelinks/

I've installed it, and tried to activate it, but got the following error:
Fatal error: Call to undefined function: drupal_get_path() in .../nicelinks.module on line 18
And all of my site is disabled. I get this error everywhere in the site.

More questions:

1. How to make drupal_get_path work? Should I simply copy the definition at
http://drupaldocs.org/api/head/function/drupal_get_path (( function drupal_get_path($type, $name) { return dirname(drupal_get_filename($type, $name)); } )) or is there anything else needed?

PHP Input Filter

Hi guys,

I have looked at Drupal and played around setting it up, but still consider myself a newbie to it...

I've spent the last 2 weeks working on a PHP class that can process input coming from the user from lets say $_POST or $_GET.. and filter it according to the developer's wishes.

Http://cyberai.com/inputfilter/
http://cyberai.users.phpclasses.org/browse/package/2189.html

How would I go about writing a module for enabling this in Drupal ?

How to add comments to "printer friendly" template?

For a couple of projects, I would like to be able to have the comments included in the printer-friendly page. The readme says:

TO DO
- Add ability to optionally attach comments to nodes for printing
  by calling comment_render().

I'm not adept enough at Drupal code to understand exactly what this means. Has anyone implemented this? (CVS does not have it.) Any suggestions or code snippets (!) would be much appreciated!

Thanks!

-media girl

Pages

Subscribe with RSS Subscribe to RSS - Module development and code questions