Download & Extend

Short URLs and Pathauto modules

Project:Short URL
Version:6.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active

Issue Summary

Shorten module provides [url] - token for the shortened URL for the nodes. When [url] token is used as pattern alias then it produces paths like:

http://mysite.com/wwwmysitecomlqy

instead of
http://mysite.com/lqy

Shouldn't this module provide to pathauto a token which contains only shoretened part of url without adding site's url?

Comments

#1

Title:Shorten URLs and Pathauto modules» Short URLs and Pathauto modules
Project:Shorten URLs» Short URL
Version:6.x-1.x-dev» 6.x-1.x-dev

Shorten URLs gets shortened URLs from dozens of services. It can only provide a full URL as a token. The Short URL module, however, is the one that actually processes short URLs for your site specifically, so it is the one that would be providing such tokens.

#2

Thank you, IceCreamYou, for clarifying that to me and transferring the issue to the right place.

Dear maintainers of Short URL, can you change the module so it provides right token to pathauto module, please.

#3

Category:bug report» feature request

I believe this is feature request rather than a bug.

#4

Dear Irakli,

I thought it is a bug for Shorten module when I noticed paths like: http://mysite.com/wwwmysitecomlqy and the issue had been transferred here as such. However, for Short URL module it, of course, should be feature request. And I hope it can be realized, because some people might really want to use Short URL's possibilities with pathauto, and with current state it doesn't make much sense to repeat website's address in shortened part of path.

#5

Honestly it probably doesn't make any sense to use a Short URL token with Pathauto. What Pathauto does is create aliases to URLs, but Short URL already does that, so you'd basically just be creating two identical aliases for the same URL. A token would be useful in other places though.

#6

I agree.

#7

I would like visitors of my site access nodes on and see address like http://mysite.com/lqy only. I don't have to use use pathauto if I can make short ruls seen by default instead of paths like node/[nid]. How can i do that without pathauto?

#8

if i understand you dont want visitors to go to node/node_id url right? then check globalredirect and use it with pathauto
it will redirect node/node_id to whatever you set the url alias with pathauto

#9

ddorian,

the problem is that pathauto has only one token for shortened url - [url], and when one uses it she gets: http://mysite.com/wwwmysitecomlq instead of http://mysite.com/lq
there should be some way to pass shortened part, in this case 'lg' to pathauto as url alias.

#10

IceCreamYou, I completely agree with what you wrote above:

What Pathauto does is create aliases to URLs, but Short URL already does that, so you'd basically just be creating two identical aliases for the same URL.

I really do not want to create double aliases for the same URL.

Can you consult how can I make my Drupal installation use aliases for noded created by Short URL as clean urls, please? I would like the visitors of my site see short urls in their browsers address lines, not 'node/[nid]' or pathauto generated aliases. Could I explain myself?

#11

Well I don't think Short URL actually uses the {url_alias} table, so to the best of my knowledge it won't work with Global Redirect. Pathauto would be one way around that; I don't know of any other way that does not involve writing code. It's not particularly complex code though -- maybe even something that could go into ShortURL itself.

But it's irakli's module, not mine, so maybe he knows something I don't.

#12

Interesting point.

Right now, ShortURL creates redirects (!) not aliases. Redirect is always HTTP 301 and its purpose is _not_ to be canonical path for a resource.

That said, I guess shortURL keys CAN be used for aliases as well. Not sure what the use-case is, but definitely a possibility. Either way exposing key as a token and making it available for pathauto is an interesting thought that I would like to look into when I get a chance. It needs some thinking though, because a key can not be both a redirect and a token participating into a path-auto as a token. The two are not compatible. I am also not sure, right now, if it makes sense to be a token (part of the alias) or has to be alias per se.

Thank you

#13

Use case is that it becomes possible for Drupal sites generate nodes with twitpic style addresses like, for example: http://twitpic.com/1zntfn

[ulr] token provided now for pathauto is really not very much useable, but if that token contained only shortened part of url without site address would be excellent.

#14

Got it.

I think I may have an idea bout how this might be implemented... More about it later.

Thanks

#15

Thanks for positive reply. So will this request be implemented as a token for pathauto or it can be done without it?

#16

I added the following lines to the module, which create a new token for pathauto. I am not sure if it is done the right way, but it serves the need of my sites for now. Thanks!

/**
* Implementation of hook_token_list().
*/
function shorturl_token_list($type = 'all') {
      $tokens['shorturl'] = array(
      'short' => t('The shortened URL token.'),
    );
    return $tokens;
  }
 
/**
* Implementation of hook_token_values().
*/
   
function shorturl_token_values($type, $data = NULL, $options = array()) {
    $data = (object) $data;
    return array(
      'short' => _shorturl_get_token(shorten_url(url('node/'. $data->nid, array('absolute' => TRUE, 'alias' => variable_get('shorten_use_alias',
1)))) ),
     
    );
}              
     

#17

Unfortunately, the above code is inconsistent with the ShortURL generated for Shorten. I tried also:

function shorturl_token_values($type, $data = NULL, $options = array()) {
  if ($type == 'node' && variable_get('shorten_generate_token', 1)) {
    //Casting $data to an object may not be necessary.
    $data = (object) $data;
    return array(
      'short' => _shorturl_get_token(url('node/'. $data->nid, array('absolute' => TRUE, 'alias' => variable_get('shorten_use_alias', 1)))),
    );
  }  
}

Again with no success to produce the same Short URL with pathauto, which used by Shorten module. And they have to be the same.

#18

Even if you were able to get a token working -- and the correct code to get the short URL token, by the way, is shorturl_shorten(url('node/'. $data->nid, array('absolute' => TRUE, 'alias' => variable_get('shorten_use_alias', 1)))) -- I think ShortURL would redirect it. Users wouldn't see the short URL in the URL bar.

#19

You are right. The best way in my situation would go using [nid] in pathauto, but [nid] gives only numbers and I would like to combinate numbers with letters. Probably there is need for another module, which would provide short url token for pathauto without redirecting.

#20

Another option would be like p/[short]. It would add 2 characters to your URL but you would still be able to use the token without redirection. Or you could exclude the "p" character from ShortURL tokens and just use p[short].

#21

The above code with your correction:

<?php
function shorturl_token_list($type = 'all') {
     
$tokens['shorturl'] = array(
     
'short' => t('The shortened URL token.'),
    );
    return
$tokens;
  }
 
function
shorturl_token_values($type, $data = NULL, $options = array()) {
   
$data = (object) $data;
    return array(
     
'short' => shorturl_shorten(url('node/'. $data->nid, array('absolute' => TRUE, 'alias' => variable_get('shorten_use_alias', 1)))),
     
    );
}  
?>

works just fine without any additional letters. But the problem is it gives different url than Shorturl provides for other modules like Shorten. Of course it does, because, as I understood, it takes URL from the address bar and generates Short URL, so what I want just is not achievable.

#22

Oh. Well you could look it up. The ShortURL tokens have to be stored somewhere in the database.

Anyway, not my area. Irakli would know more.

#23

subscribe

#24

Would be nice if only actual clean address of the node (like node/[nid]) and not any of its aliases would be shortened.

#25

Hi,
Would love to have this on D7. Any progress in this field please?
greetings, Martijn

nobody click here