Project:CCK Redirection
Version:6.x-1.2
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:needs work

Issue Summary

Somehow the views module triggers hook_nodeapi(&$node, $op = 'view'...) regardless the way a node is viewed as a list, teaser of full page. This leads to an unwanted redirect to the first redirection found in the list.

This can easily be fixed with the attached patch, where the redirection takes place in hook_menu instead.

function cck_redirection_menu($may_cache) {
  if (!$may_cache && arg(0) == 'node' && is_numeric(arg(1)) && !arg(2)) {
    $node = node_load(arg(1));
    $fields = _cck_redirection_get_redirect_fields($node->type);
    if(!empty($fields)) {
      $field = array_shift($fields);
      $data = $node->$field['field_name'];
      $url = check_plain($data[0]['value']);
      if (!empty($url)) {
        if(user_access('bypass redirection')) {
          drupal_set_message(t('This node is redirected to a !r', array('!r' => l(t('remote source'), $url))));
        } else {
          drupal_goto($url);
        }
      }
    }
  }
}
AttachmentSize
cck_redirection.module.patch17.58 KB

Comments

#1

By the way, the patch includes more lines than just the changed ones. The checkout I patched returned a file with crappy linebreaks. to me.

#2

redirecting in hook_menu sounds like a much safer option.

#3

it would be nice to track down the line that is doing this. i know that token module could do this too.

#4

The patch would not apply for me but simply replacing the entire cck_redirection_nodeapi function with the code provided by fokke fixed the problem. I tried creating a patch but ran into the same problems. Either way, it would be nice if this was finally put in an official release since it is a critical problem with views.

#5

The file seems to be using CRLF instead of LF line endings (yuck). Here's an uploaded one with LF endings (assuming textmate did it's job). It also has a small fix to check the node_load because the node might not exist which will result in an error later in the code if it runs.

AttachmentSize
cck_redirection.module.zip 2.81 KB

#6

Tried using both patches, the main one and the one submitted by jmstacey. The official patch gave me a blank page with errors, the updated patch jmstacey worked at first however was causing errors, I tried doing a delete and reinstall and now I can't get the cck forms to appear at all. They don't turn up on the node I want to edit or post and the options for how the redirect works doesn't turn up in manage fields either. I have tried deleting and reinstalling the module a few times and that doesn't seem to be working at all.

any ideas.

running.

Drupal 6
Ubercart
Views
CCK

#7

Are there any updates to this?

I tested both the patch and jmstacey's and wasn't able to get either working. I'll jump in and look at the code to see if I can get it going but wanted to see if anyone else has gotten this working with views?

#8

Parse error: syntax error, unexpected T_FUNCTION in /etc/drupal/6/sites/all/modules/cck_redirection/cck_redirection.module on line 24

With the official patch I get the above error

With the unofficial patch by jmstacey the field does not appear when you try to edit the node and the options to control the redirect do not appear under manage fields.

any ideas

Just noticed this one, when you created a field for the redirect under the original .module file the field the "Form element to edit the data" box was listed as just text jmstacey patch when you get text field with URI Validation. You also get no redirect options or a field to edit if you create the field

#9

I'm still using this on a production site. Do you by chance happen to be running Drupal 6? This patch is for 5.x.

#10

so does anyone have a fix for drupal 6 before I start trying to do redirects at a server level?

#11

Don't worry, just worked out how to do what I wanted using views and the cck link field which makes this entire module irrelevant.

#12

Version:5.x-1.0» 6.x-1.2
Status:reviewed & tested by the community» needs work

For what it's worth, I'm seeing this same problem in 6.x-1.2.

I'm including the redirect CCK field in the view, but excluding it from display. It's used by a custom handler on one of the other fields in the view. Even thought the format for the redirect field is set to "Show as Plain Text," it's still redirecting when the view is displayed.

I did some debugging and found that it is calling theme_cck_redirection_formatter_plain(). This function calls _cck_redirection_redirect(). THAT function looks to $widget['redirect_type'] to decide how to handle the redirect. I think this value should be set to CCK_REDIRECTION_NONE when it's being formatted as plain text, so that it it doesn't execute one of the _cck_redirection_{method} functions.

On my site, I removed the call to _cck_redirection_redirect() from theme_cck_redirection_formatter_link() and theme_cck_redirection_formatter_plain(). It seems like neither of these theme functions needed to be calling _cck_redirection_redirect(), and they still return the correct value. The patch for this is attached.

AttachmentSize
192897-12.patch 809 bytes

#13

Assigned to:fokke» Anonymous

#14

BrockBoland's patch in #12 doesn't apply for me with 6.x-1.2.

Making the same changes in code does fix the issue.

However, does this patch break the desired behavior when Redirection type is set to delay instead of divert? In the delay case, we might want to show the link as a URL or plain text, but still redirect after a delay.

I think the previous strategy of using hook_menu instead of hook_nodeapi might be a better one...

Thanks for your work on this!