Consider our site domain: abcdefghijklmn.com
We have a shorter domain at our disposal: abc.com (both examples are made up names)

We'd like for shurly to spew out the short url for abc.com/short instead of the long domain name. I tried to hack this via it's .module by replacing the calls to GLOBAL['base_url'] but the part that comes to the copy box is still displaying the long site name.

Any help how to acheive this greatly appreciated :)

Comments

klezmer41’s picture

This one took me a while to figure out. In shurly.module on line 380, $final_url is the variable that the form is using, which relies on _surl() which simply relies on Drupal's url().

<?php
// original
$final_url = $form_state['storage']['shurly']['final_url'] = rawurldecode(_surl($short_url, array('absolute' => TRUE)));

// modified example
$final_url = $form_state['storage']['shurly']['final_url'] = rawurldecode(_surl($short_url, array('absolute' => TRUE, 'base_url' => 'http://abc.com')));
?>

More info here: http://api.drupal.org/api/drupal/includes%21common.inc/function/url/7

This would be nice as a configuration option.

jbm333’s picture

Along this same vein, I had to apply this modification to the returned URL on line 559 to get the API to work with a custom base_url.

<?php
// original
return array(
    'success' => $success,
    'error' => $error,
    'longUrl' => $long_url,
    'shortUrl' => isset($short) ? _surl($short, array('absolute' => TRUE)) : '',
  );

// modified
return array(
    'success' => $success,
    'error' => $error,
    'longUrl' => $long_url,
    'shortUrl' => isset($short) ? _surl($short, array('absolute' => TRUE, 'base_url' => 'http://yourshorturl.com')) : '',
  );
?>
dddave’s picture

That would be a killer feature. *dream*

nestor.mata’s picture

Status: Active » Needs review
Issue tags: +#drupalcr
StatusFileSize
new4.25 KB

Hi,

Here is a patch for the solution you proposed, but using a Drupal variable (which by default is the base URL of the site) and added a field to change this base URL for a shorter domain.
Also, the patch is applied in the way the view uses it, so the views also use the configured base URL.
Please test and confirm.

I think this solves the problem for those (like me) that has 2 domains, one shorter to be able to use short URL's.

~Nestor

tregismoreira’s picture

#4 works perfectly for me. Thanks ;)

jibus’s picture

Issue summary: View changes

I am not sure about this.

It seems to me very specific. If you have two domains, why not setup two Drupal instances and use the API provided by the module to generate short url ?

jibus’s picture

StatusFileSize
new4.55 KB

After some though, it can be useful for sharing content from a website.

Patch updated, a new variable has been created, we need to remove it if we uninstall the module.

Leeteq’s picture

Is this ready enough to be committed to the -dev branch?

jibus’s picture

There is one case where the shortner can be broken.

We need to make the field mandatory, and pre-populate by the base url.

jibus’s picture

StatusFileSize
new4.01 KB

Updated patch :
Field is now mandatory and is prepopulate by the current url of the drupal installation

jibus’s picture

StatusFileSize
new4.01 KB

Previous patch is corrupted

jibus’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev

Commited against 7.x-1.x

Lets bring this functionnality to D6 version

jibus’s picture

Status: Needs review » Closed (fixed)
StatusFileSize
new3.91 KB

Committed against 6.x-1.x

Thanks !

diegoj86’s picture

Hey, I've just uninstalled the 7.x-1.1 release and installed the dev version. I can see the configuration for the short URL under /admin/config/system/shurly but when I click Save it says "The configuration options have been saved." and the URL gets back to the original (the short URL is actually not saved). It still displays the long URL under /shurly.
Any help appreciated. Thanks.

jibus’s picture

Confirmed, a new issue has been created.

https://drupal.org/node/2284343