rewrite urls so they append token - HEAD

moshe weitzman - June 19, 2007 - 03:00
Project:Token authentication
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

the patch just landed in HEAD so that we can rewrite all urls ithat run through URL. we do so by defining custom_url_rewrite_outbound() and we should be adding a querystring as necessary. this should be done with performance in mind, since this function will be called very very frequently.

#1

grendzy - July 26, 2008 - 00:53

It looks to me like custom_url_rewrite_outbound() is only in Drupal 6. Anyway, here is a solution that worked for me on D5 (add this to tokenauth.module). It won't universally hit all paths you might like, but it will add the token to the feed links in forums.

<?php
/**
* Format the forum body.
*
* A bit of an ugly hack - this is pasted in from forum.module.
* The it's identical to the forum code, except that the call to drupal_add_feed
* has been altered to include the token
*/
function phptemplate_forum_display($forums, $topics, $parents, $tid, $sortby, $forum_per_page) {
  global
$user;
 
// forum list, topics list, topic browser and 'add new topic' link

 
$vocabulary = taxonomy_get_vocabulary(variable_get('forum_nav_vocabulary', ''));
 
$title = $vocabulary->name;

 
// Breadcrumb navigation:
 
$breadcrumb = array();
  if (
$tid) {
   
$breadcrumb[] = array('path' => 'forum', 'title' => $title);
  }

  if (
$parents) {
   
$parents = array_reverse($parents);
    foreach (
$parents as $p) {
      if (
$p->tid == $tid) {
       
$title = $p->name;
      }
      else {
       
$breadcrumb[] = array('path' => 'forum/'. $p->tid, 'title' => $p->name);
      }
    }
  }

 
drupal_set_title(check_plain($title));

 
$breadcrumb[] = array('path' => $_GET['q']);
 
menu_set_location($breadcrumb);

  if (
count($forums) || count($parents)) {
   
$output  = '<div id="forum">';
   
$output .= '<ul>';

    if (
user_access('create forum topics')) {
     
$output .= '<li>'. l(t('Post new forum topic.'), "node/add/forum/$tid") .'</li>';
    }
    else if (
$user->uid) {
     
$output .= '<li>'. t('You are not allowed to post a new forum topic.') .'</li>';
    }
    else {
     
$output .= '<li>'. t('<a href="@login">Login</a> to post a new forum topic.', array('@login' => url('user/login', drupal_get_destination()))) .'</li>';
    }
   
$output .= '</ul>';

   
$output .= theme('forum_list', $forums, $parents, $tid);

    if (
$tid && !in_array($tid, variable_get('forum_containers', array()))) {
     
$output .= theme('forum_topic_list', $tid, $topics, $sortby, $forum_per_page);
     
$token = NULL;
      if (
$user->uid != 0) {
       
$token = tokenauth_get_token($user->uid); // tokenauth module
     
}
     
drupal_add_feed(url('taxonomy/term/'. $tid .'/0/feed', $token), 'RSS - '. $title);
    }
   
$output .= '</div>';
  }
  else {
   
drupal_set_title(t('No forums defined'));
   
$output = '';
  }

  return
$output;
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.