Path / Clean URLs not showing up - anonymous users don't get a path

sodani - October 3, 2006 - 13:13
Project:Path
Component:Miscellaneous
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

I have a teaser type, and all the other variables are working for anonymous users, but not the $path. I've been able to get around it by using $nid in this case, but has anyone else seen this?

#1

colm_iqc - October 9, 2006 - 13:24

Fix for this would be really appreciated.

#2

colm_iqc - October 9, 2006 - 13:57
Priority:normal» critical

It seems to be something to do with the administrating the urls:

Turning on the following option for all users makes it work.
path module - administer url aliases

#3

markhope - October 9, 2006 - 18:14

Yes a fix for this would be extremely welcome. Allowing anonymous users to administer paths does fix it - but I'm not mad enough to apply that on a live site!

I hadn't noticed this problem as I'm nearly always logged in. damn.

#4

jeffabailey - October 15, 2006 - 09:07

I have the same problem, a fix would definitely be appreciated.

#5

visualnotion - October 24, 2006 - 00:20

Yes, a fix would be great. Does anyone know if you can get around this by using CCK template files and bypassing Content Template?

#6

czheng - October 31, 2006 - 17:09

ditto above. would love to see a fix for this.

#7

ncameron - December 8, 2006 - 01:27

Hey there,

This is not a fix but a nifty work around until it can be patched up. Slip this snippet of code at the top of your .tpl.php file and if the $path variable is unset then it will replace it look up the url alias and set $path as that.

<?php //If $path is empty (for anon) it replaces it with the correct path from the below function
if (empty($path)){
   
$nodeIDpath= 'node/'.$node->nid;
   
$path = drupal_get_path_alias($nodeIDpath);
    }
?>

Hope this helps. Any thoughts, feedback appreciated.

Thanks,

Neil

-----------------
Connecting Language Learners
www.huitalk.com

#8

technivant - December 8, 2006 - 02:34

Thanks! It dind't work for me in my .tpl.php so I stuck this in my content type template (a la contemplate) and changed $node->nid to $nid and it works perfectly.

#9

jaysmall - January 21, 2007 - 16:23

I couldn't get either of the two snippet methods suggested above (e.g., in template file or Contemplate custom teasers) to work in my teaser blocks in a 5.0 installation. But the following, in my Contemplate custom teasers, does work. Does anyone see a problem with this implementation?

<a href="<?php print drupal_get_path_alias('node/'.$node->nid); ?>">...</a>

Thanks.

#10

maastrix - February 28, 2007 - 23:06

I had the same problem. Put your line of code in my node-type.tpl.php and now it works like a charm. Thanks.. Seems okay.

#11

Brian Harris - March 13, 2007 - 23:50

Also if you use pathauto you can use

<a href="<?php print url("node/$nid");?>">my link</a>

#12

ludek.safar - March 22, 2007 - 10:30

Yep, tried with success, problem seems fixed. Thanks a lot!

#13

marcoBauli - April 3, 2007 - 14:49

tip at #7 above works great in views templates generated by Views Theme Wizard :) Thanks!

#14

wilco - April 22, 2007 - 17:41
Title:print path in teaser for anonymous users doesn't work» Path / Clean URLs not showing up - anonymous users don't get a path
Project:Content Templates (Contemplate)» Path
Version:HEAD» <none>

I came across this issue recently when playing with Clean URLs and URL Aliasing with Views in Drupal 5.1. An anonymous user browsing the site would get all explicit URL Aliases but all the paths created dynamically from the View Module were not showing up.

I did some snooping around and found a solution suggesting modifying the node.tpl.php to add a few lines of code. In doing some thinking I came up with a solution that worked more thoroughly. I found, as in my case, having to modify and keep updated a large set of node.tpl files to cumbersome. Here is my template.php solution:

// This code snippet works well with Drupal 5.x
function _phptemplate_variables($hook, $vars = array()) {
  switch ($hook) {
  case 'node':
$node = $vars['node'];
if (empty($node->path)){
$nodeIDpath= 'node/'.$node->nid;
$node->path = drupal_get_path_alias($nodeIDpath);
$vars['node'] = $node;
}
break;
}
return $vars;
}

#15

sgriffin - April 26, 2007 - 17:35

Awesome thread, just got bit by this with cck to sum up.
use url("node/$nid") not $node->path

Not sure even why $node->path is listed.

#16

Tom-182 - May 28, 2007 - 04:52

I've tried the solution on #14, adding the codes to template.php didn't work on my Drupal 5.1 site.

#17

Tom-182 - May 28, 2007 - 05:00

I finally use the solution in http://drupal.org/node/146477 and it works like a charm.
Just use

<?php
print drupal_get_path_alias("node/$node->nid");
?>
to load the path in Contemplate.

#18

bcswebstudio - June 4, 2007 - 22:28

url("node/$nid"), drupal_get_path_alias('node/'.$node->nid) and other derivatives suggested herein work well, but not with the Contact Module (and I expect some other modules..?) On my contact pages path-aliased like "meetings/contact", "banquets/contact", the suggested workarounds return node/. Node types, however, work like a charm.

I think the fix should be to simply append path to $node regardless of whether a user has path admin privs or not. A bigger fix might be to rely not on Path module's modification of $node but something lower level and hanging off $variables, to be used independently of Path.

#19

ceejayoz - June 26, 2007 - 14:39

I'm baffled that this is apparently a long-standing issue. Having the site be entirely unusable by anonymous users would seem to be a fairly significant problem...

I just commented out the check in path_nodeapi() for user permissions (first line of the function) - it's a better option than enabling anonymous users to administer paths, unless I'm missing something major.

#20

nosro - October 30, 2007 - 22:02

Agreed with #18 - I ran into this problem when using the Services module, and I can't use the suggested workarounds to get the path to be included in my service. My only options seem to be to modify the Services or Path modules.

#21

Summit - January 9, 2008 - 09:02

Hi,
Subscribing. Anonymous users should not be handled differently regarding clean-url's in my perspective.
greetings,
Martijn

#22

rudeboyal - January 10, 2008 - 16:36

OK... after having looked through this whole issue... I found that the problem actually lay within the path.module file of the path module. I have version 5.5 of drupal and the problems were the same for me. No need for these contemplate workarounds or .tpl.php
fixes.... edit the path.module file found in drupal's "../module/path" folder like so:

goto line 214 or do a search for " ('administer url aliases') " in your text editor.

you should come upon this...

function path_nodeapi(&$node, $op, $arg) {
  if (user_access('create url aliases') || user_access('administer url aliases')) {
    switch ($op) {

CHANGE IT TO THIS:

function path_nodeapi(&$node, $op, $arg) {
  if (user_access('create url aliases') || user_access('administer url aliases') || $op) {
    switch ($op) {

Works in both IE and Firefox... hope this is the real fix!

HAPPY NEW YEAR

#23

rudeboyal - January 10, 2008 - 16:43

PS... if you happen to see <b> || $op </b> this is because the server has not yet refreshed its cache.
normally it should just say ...aliases') || $op) {

#24

Summit - January 10, 2008 - 20:12

Hi,

I think this should be put in a patch so with an update the changes are not gone, right?

greetings,
Martijn

#25

tj2653 - January 12, 2008 - 01:50

I just stumbled across this issue when I realized two of my links with $node->path wasn't working for anon/regular users. The patch in #22 seems to fix it for me. Thanks rudeboyal!

#26

Rob Loach - February 22, 2008 - 00:18
Status:active» fixed

http://drupal.org/node/216404

#27

Anonymous (not verified) - March 7, 2008 - 00:21
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.