Auto Redirect
covenantd - May 30, 2006 - 20:50
| Project: | Janode |
| Version: | HEAD |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | AjK |
| Status: | closed |
Description
It would be really nice to have an option so that the title of the node (maybe only when displaying a teaser) redirects directly to the external link - yet still records the view for mods like statistics etc. So basically, if the option is set and the viewing user is an anonymous user or non-editor, when they click on the title it takes them to the node, but then redirects immediately. Maybe using something like:
<?php
header('Location: '.$node->http_link);
?>
#1
I'm not sure that making the node title do a redirect is a good idea as that would deviate the users "usual experience" of what titles in Drupal do (and I'm one for keeping UIs consistent across applications).
However, it may be an idea to make the link itself "redirect inward" and then back out again so that the "click" can be recorded by the watchdog. That's a possibility.
Thoughts please!
regards
--AjK
#2
That is a good point about having a consistent UI - scratch the title idea. I really like your inward redirection of the link idea. That would be nice! Is this very hard to do?
~Joshua
#3
Patch attached to do what you want. Note the new option in the settings area "inward" redirect. I think this prob needs better explaination as to what it actually does.
If this works for you I will commit it and update the README.txt instructions.
Look forward to feedback
best regards
--AjK
#4
Okay, it kind of works but doesn't totally for what I was originally hoping.
Nice redirection - very quick and smooth. The redirect page is logged in the statistics so we can see how many times the redirection was done. However, it is not logged as a read for the page. So down below where it says "x reads", unless the person goes to the actual node it doesn't update. This I think is called the post access counter in the access control area for statistics. I think this is because we are redirecting custom url you used, but not to the actual node. Would it even be possible to do it in the actual node? If not it isn't the end of the world, but I really want my clients to see the number of clicks on each link, not just views of the node - and I don't think they would be tech-saavy enough to use the statistics module :)
#5
Hi,
Ok, the attached patch "bumps" the page counter. Note, it *always* bumps on redirect. So, if you follow the link via a redirect from a teaser the page counter is +1. However, if you go to the node and the follow the link via a redirect the page counter is +2 as you get a node page read +1 and then a redirect +1.
I'm kind of thinking that I should really mod the db schema to add a "click_thru_count" to the janode table rather than bump the page counter but that's more work as it involves a db mod.
Let me know how you get on and further thoughts.
Btw, the patch updates the CVS version and not any previously patched version (ie the patch above) so you'll need to get a fresh copy of janode.module and patch that)
regards
--AjK
#6
Sweet! That was just what I needed...thanks so much AjK!
It would be nice to have the click_thru_count in the db, but I wouldn't rush it. Right now I hacked mine up a bit so that when users aren't logged in the titles take them directly to the external link (thru the redirect of course), but when they are authenticated they go to the actual node. I also did a custom query on the homepage so that the janode's there go straight to the redirect.
Once I go live (sometime next week hopefully) I'll send you the link so you can see it in action if you want.
BTW, do you know of any easy ways to patch with some GUI in Windows? I'm too lazy to install a Unix shell and though my install of Netbeans did it the first time, after that it said there "Were no differences" so I just did the two patches by hand. I haven't been able to find any, but just thought I'd ask in case :)
Thanks again!
#7
http://drupal.org/cvs?commit=33328
#8
This can be accomplished via templating.
node-janode.tpl.php
<div class="node<?php print ($sticky) ? " sticky" : ""; ?>"><?php if ($page == 0): ?>
<h2><a href="<?php print $node->http_link ?>" title="<?php print $title ?>"><?php print $title ?></a></h2>
<?php else: ?>
<?php print $picture ?>
<em class="info"><?php print $submitted ?></em>
<?php endif; ?>
<div class="content">
<?php print $content ?>
</div>
<?php if ($links && !$is_front): ?>
<em class="clear links"><?php print $links ?></em>
<?php endif; ?>
<?php if (($page == 1) && !$is_front): ?>
<em class="clear terms"><?php print $terms ?></em>
<?php endif; ?>
</div>
#9