Personalize all pages

letharion - April 14, 2009 - 19:33

Hey people :)

I have a Registered user. (R), with user-ID: X, and a anonymous visitor (V)

I have 2 questions.
1) What I'd like to do is to give (V) the adress /home/X.
When (V) comes to /home/X, the regular /home is displayed, but a block on the left side also uses the X to pull some profile information from (R).
Also, when the "Contact" menu choice is clicked, (V) isn't transported to /contact, but /user/X/contact.

2) As an anonymous user, I don't have access /user/X/contact. I want that, but can't see such an option under permissions. (Or it's there and I'm blind ;) )

Any and all help would be greatly appreciated :)
Thanks, Claes

I've checked the contact

thijsvdanker - April 14, 2009 - 20:41

I've checked the contact module, and it doesn't use the permissions functionality at this moment.
It checks:
1) Has the user (id X) activated the contact option for his account?
2) is the user (v) logged in (in your case this is no)

The function that is called also requires the $user object (currently logged in user).

There seems to be a long discussion on getting this into drupal 5, 6 and now 7, with some patches here and there that might help you:
http://drupal.org/node/58224

Good luck!

Quite a discussion that's

letharion - April 15, 2009 - 06:25

Quite a discussion that's been going on :)

Thanks thijsvdanker, I'm gonna see what I can do about it.
Will work my way down and hope to find 6.x patches.

Incase I have problems with patching, is the forums here still the place to be asking questions about it?

Any comments on my first question still highly welcome :)

I found patches that should

letharion - April 16, 2009 - 20:22

I found patches that should apply to drupal 6.x, so hopefully I'll get it working. Might post back here if I have questions on the patching. (Might warrant it's own thread)

Meanwhile I bump this in hope that someone can point me in a direction that helps me to work on my first question :)

views arguments

thijsvdanker - April 17, 2009 - 07:19

I didn't get the first question up till now (I think :))
part I of you question can be solved with the views module.
If you make a 'user-type' view, and use arguments (User: UID), than that block will use X to get the information of R in that block.

The contact link thing depends on how you build that menu I guess.
You could have a look at the arg() function (http://api.drupal.org/api/function/arg) on how to get part of the path.

Good luck!

Major progress :)

letharion - April 20, 2009 - 13:50

Great :) I've almost got it.
If I create a user view, like you suggested, it works as intended during the preview.
However, I don't know how to actually "use" it, by putting it on the site.

And if I create a block instead, then it naturally shows up in the blocks list as I want, but then
the argument appears to be ignored for some reason, and it's always set to 1.

On a side-note, views appear to be majorly powerful. Neat

way to go!

thijsvdanker - April 20, 2009 - 17:31

In your arguments setting, you can provide an argument if none is given.

Action to take if argument is not present: --> Provide default argument
Default argument type: --> PHP Code
The code could be something like:

if (arg(0) == 'home' && is_numeric(arg(1)){
return arg(1);
}

this should return the second argument in the url to the views argument. (home is arg(0)).
hope this helps!

The question: "I don't

letharion - April 20, 2009 - 20:33

The question: "I don't understand how to pass the argument outside of the sandbox."

Alot of background:
Ok lets see if we can figure out what I don't understand :P

I create a new "user" view.
I pick "block", and then I "add display".
I add one argument. "User: UID"
I add one field. "User: Name".

Now if I look at the preview, all usernames are listed.
Set "items to display" to 1
Now if I look at the preview, only "Anonymous" shows up. So far so good.
I try to enter a UID of a user, and I the corresponding username. \o/

Since I don't want the Anonymous user to show up, I edit the argument UID's setting to "Hide view/404".

Everything works as expected. No argument returns "No query was run". Correct user ids still work well.

I save my view. I add it to the left side, and "All" pages. Nothing shows up. Ok, hardly surprising I guess, since I haven't provided an argument. I go back, update the view to list "All values" when without argument, and the view shows up with the Anonymous username.

So my view "works", but I don't understand how to pass the argument outside of the sandbox.
site.com/1 and site.com/home/1 both give me a 404.

Edit below:
I tried /node/1, as that is the "real" path to "Home".
If I now add /1, it appears to be an argument, because I now longer get a 404.
However, the view still doesn't seem to pick it up.
I tried this php code:
if (arg(0) == 'node' && arg(1) == '1' && is_numeric(arg(2)){
return arg(2);
}
And figured maybe it could be a correct adaptation of yours. No luck. "Anonymous" is still there, so no argument.

almost there

thijsvdanker - April 20, 2009 - 22:46

you don't have to limit your view I think, as one user id will only return one user.

if (arg(0) == 'node' && arg(1) == '1' && is_numeric(arg(2)){
return arg(2);
}

looks pretty good, except that there's a ) missing after arg(2) in the if statement. (I missed it in my previous example as well :))

so should be something like

if (arg(0) == 'node' && arg(1) == '1' && is_numeric(arg(2))){
return arg(2);
}

you could go for

if (arg(0) == 'node' && arg(1) == '1' && is_numeric(arg(2))){
return arg(2);
} else if (arg(0) == 'home' && is_numeric(arg(1))){
  return arg(1);
}

that would allow both site.com/home/1 and site.com/node/1/1 to work.

Let me know if it works!

great!

letharion - April 22, 2009 - 18:13

So it was that easy :D
/node/1/1 now works perfectly :)
However, /home/1 does not, that's still a 404. I assume it has something to do with it not being a "real" path.

You were also right about not needing to limit to 1. During the preview, the view showed up that many times, that's why I choose 1. But in real usage, it only showed 1.
Might as well have it at one anyone, can't harm.

real path

thijsvdanker - April 23, 2009 - 05:59

Great :)

Are you using the "path" module to actually set the path of the particular node to "home"?
(if not, have a look at pathauto as well!)

Umm...

letharion - April 23, 2009 - 06:58

Well, I don't know, is there some other way I could have done it? Since /home by itself does work I mean.

I have included the core module path, and I've set node/1's "URL path settings" to "home"
Path-auto looks like a great idea, and I might use it later for another site. This one won't have many nodes at all, so I won't bother.

discussions

thijsvdanker - April 23, 2009 - 07:56

There seems to be something with aliases and arguments.

Maybe this discussion could help you in some way (http://drupalsn.com/learn-drupal/drupal-questions/question-2650).
Another option I can think of is creating a view that displays that node (node/1) and give the page-display for that view the path 'home'.
Views do like arguments, aliases don't.

This is as far as my current knowledge on aliases and arguments go, but if I wake up tonight with some brilliant solution I'll post back ;)

It's not very important :)

letharion - May 14, 2009 - 19:46

I'm really grateful for all your help. :D

Maybe I'll get back to this later, but for now it can say node instead of home.

 
 

Drupal is a registered trademark of Dries Buytaert.