Link Trimmer / short urls

Creating and modifying plugins.
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Link Trimmer / short urls

Post by danst0 »

Hi,

I am experiencing issues with the link trimmer plugin.
1) I can create shorturls from the admin interface frontpage, but when using the urls I get: "The requested URL /s/2 was not found on this server." as error message
Do I have to change something in the .htaccess?

2) In article edit mode I have two more problems: I edit text, then click linktrimmer: a) the title of the window is PLUGIN_EVENT_AMAZONCHOOSER_MEDIA_BUTTON, b) when I enter a url to shorten and hit go I am instantly redirected to my homepage (/), no short url is created (when I create a new short url on the frontpage the index is unchanged).

Any hints?

Daniel
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Link Trimmer / short urls

Post by garvinhicking »

Hi!

mod_rewrite needs to be enabled for the trimmer to work, or at least Apache ErrorHandling. Do you have URL Rewriting enabled in your blog? And what's your configuration of the linktrimmer plugin?

Maybe 2) is also caused by this...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Re: Link Trimmer / short urls

Post by danst0 »

Hi,

mod_rewrite should be available (http://wiki.hetzner.de/index.php/Konsol ... w_umleiten).
I put the "RewriteEngine On" into my .htaccess manually, but it still does not work.

The configuration is really standard.
Daniel
Attachments
Link trimmer Config
Link trimmer Config
Screen shot 2011-04-25 at 18.16.33.png (33.62 KiB) Viewed 11465 times
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Link Trimmer / short urls

Post by garvinhicking »

Hi!

Check your s9y configuration for "URL Rewriting". Putting "RewriteEngine On" into .htacess manually doesn't effect anything. :-)

"test.scrmblog.com" is your blog where the plugin actually runs on, right?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Re: Link Trimmer / short urls

Post by danst0 »

test.scrmblog.com is my s9y test installation.
Your hint worked. Url rewriting was set to "no"...

Thanks,

Daniel
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Re: Link Trimmer / short urls

Post by danst0 »

I would like to integrate the link trimmer more into the blog, and start with adjusting the twitter url shortener. Is it somehow possible to trim an url internally using the functions provided by the plugin?

As far as I understand the documentation there is no web api way of doing this?
So that leaves the question: Can I access the function of one plugin (create function from the link trimmer) in another plugin (twitter plugin)?

Daniel
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Link Trimmer / short urls

Post by garvinhicking »

Hi!

Short answer: No

Long answer: The plugin can of course be patched for this, by creating a REST-like interface that shortens links outside of the s9y backend area. But that was not the initial scope of the plugin...

I'd be happy to help in this, and would love to see it implemented, but I cannot dedicate time to coding that myself currently.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Re: Link Trimmer / short urls

Post by danst0 »

Would there be any plugin with such an interface, where I could get some inspiration?
I am not capable of doing it from scratch.

Daniel
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Link Trimmer / short urls

Post by garvinhicking »

Hi!

The "serendipity_event_communityrating" is an example plugin that makes use of offering a "Web-API"...

HTH
,mGarvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Re: Link Trimmer / short urls

Post by danst0 »

How about these approach?

Code: Select all

$ diff serendipity_event_linktrimmer.php ~/Desktop/serendipity_event_linktrimmer.php 
133c133,135
<             $hash = $this->create($url, $custom_hash);
---
>             $hash = serendipity_event_linktrimmer::create($url, $custom_hash);
> 
153c155,157
<             $hash = $this->base62($id);
---
>             $hash = serendipity_event_linktrimmer::base62($id);
And:

Code: Select all

$ diff serendipity_event_twitter.php ~/Desktop/serendipity_event_twitter.php 
39a40
>             'linktrimmer'     => "linktrimmer plugin",
Most importantly:

Code: Select all

$ diff classes/UrlShortener.php ~/Desktop/UrlShortener.php 
9a10,18
> $linktrimmer_plugin = dirname(__FILE__) . '/../../serendipity_event_linktrimmer/serendipity_event_linktrimmer.php';
> $linktrimmer_found = true;
> if(file_exists($linktrimmer_plugin)) {
>     require_once $linktrimmer_plugin;
> } else {
>     $linktrimmer_found = false;
> }
> //echo $linktrimmer_plugin;
> //echo $linktrimmer_found;
50a60,66
>             case 'linktrimmer':
>                 //echo "Linktrimmer";
>                 if (linktrimmer_found) {
>                     //echo "OK";
>                     UrlShortener::shorten_via_linktrimmer( $url, $shorturls );
>                 }
>                 break;

78a97,102
>     
>     function shorten_via_linktrimmer( $url, &$shorturls ) {
>         $shorturl = trim(serendipity_event_linktrimmer::create($url));
>         $shorturls['linktrimmer'] = "http://test.scrmblog.com/s/" . $shorturl;
>     }
Two necessary improvements would be to replace the fixed reference to the domain (last part) and the plugin directory (first part).

Daniel
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Link Trimmer / short urls

Post by garvinhicking »

Hi!

Great, that's a good starting point. I committed it a bit similarly, and placed a "TODO" so that we need to get the proper /s/ URL in there somehow...

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Re: Link Trimmer / short urls

Post by danst0 »

Here are some additional enhancements (I finally got my own short url!).

$diff old/serendipity_event_linktrimmer/lang_en.inc.php new/serendipity_event_linktrimmer/lang_en.inc.php

Code: Select all

9c9
< define('PLUGIN_LINKTRIMMER_LINKPREFIX_DESC', 'Enter a unique URL portion that will be used on your domain to identify the base of the linktrimmer. If you enter "l" for example, your URLs will look like http://yourblog/l/feda [with URL-Rewriting enabled] or http://yourblog/index.php?/l/feda [without URL-Rewriting]');
---
> define('PLUGIN_LINKTRIMMER_LINKPREFIX_DESC', 'Enter a unique URL portion that will be used on your domain to identify the base of the linktrimmer. If you enter "l" for example, your URLs will look like http://yourblog/l/feda [with URL-Rewriting enabled] or http://yourblog/index.php?/l/feda [without URL-Rewriting]. Never leave  empty, even if you have a separate domain for your short url.');
11c11
< define('PLUGIN_LINKTRIMMER_DOMAIN_DESC', 'The link that is used for the output. You could use .htaccess redirection of any other domain you own and enter that here. If you have Serendipity on http://mylongdomain.com/serendipity/ but also own http://short.com/ you could enter http://short.com/ here, and inside the .htaccess of short.com redirect everything to your longdomain: RewriteRule ^(.*)$ http://longdomain.com/serendipity/$1.');
---
> define('PLUGIN_LINKTRIMMER_DOMAIN_DESC', 'The link that is used for the output. You could use .htaccess redirection of any other domain you own and enter that here. If you have Serendipity on http://mylongdomain.com/serendipity/ but also own http://short.com/ you could enter http://short.com/ here, and inside the .htaccess of short.com redirect everything to your longdomain: RewriteRule ^(.*)$ http://longdomain.com/serendipity/yourprefix/$1 (alternativly: redirectMatch 301 ^(.*)$ http://longdomain.com/serendipity/yourprefix/$1). URLs are then redirected twice: from your short.com to mylongdomain.com to the original URL.');
$diff old/serendipity_event_linktrimmer/serendipity_event_linktrimmer.php new/serendipity_event_linktrimmer/serendipity_event_linktrimmer.php

Code: Select all

114,115c114,118
< 
<         $pref = $this->get_config('domain') . $this->get_config('prefix') . '/';
---
>         if ($this->get_config('domain') == $serendipity['baseURL'])  {
>             $pref = $this->get_config('domain') . $this->get_config('prefix') . '/';
>         } else {
>             $pref = $this->get_config('domain');
>         }
This change is important since with my own short url I do not want to have the prefix... since the url is only for, well, redirection.

$diff old/serendipity_plugin_twitter/classes/UrlShortener.php new/serendipity_plugin_twitter/classes/UrlShortener.php

Code: Select all

22,24c22,34
<                     // TODO: Instead of hardcoding '/s/' here, we need to instanciate serendipity_event_linktrimmer and get the proper config variable
<                     // (or issue a SQL statement on serendipity_config directly)
<                     $shorturls['linktrimmer'] = $serendipity['baseURL'] . '/s/' . trim(serendipity_event_linktrimmer::create($url));
---
>                     $res = serendipity_db_query("SELECT value FROM `serendipity_config` WHERE name LIKE 'serendipity_event_linktrimmer:%/prefix';", true, 'assoc');
>                     if (is_array($res) && !empty($res['value'])) {
>                         $lt_prefix = "/" . trim($res['value']) . "/";
>                     }
>                     $res = serendipity_db_query("SELECT value FROM `serendipity_config` WHERE name LIKE 'serendipity_event_linktrimmer:%/domain';", true, 'assoc');
>                     if (is_array($res) && !empty($res['value'])) {
>                         $lt_domain = trim($res['value']);
>                     }
>                     if ($lt_domain == $serendipity['baseURL'])  {
>                         $shorturls['linktrimmer'] = $lt_domain. $lt_prefix .trim(serendipity_event_linktrimmer::create($url));
>                     } else {
>                         $shorturls['linktrimmer'] = $lt_domain . trim(serendipity_event_linktrimmer::create($url));
>                     }

The coolest thing is that even with my own short url, the twitter search for longurl still finds tweets with my own short url...

Daniel
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Re: Link Trimmer / short urls

Post by danst0 »

Would these changes be ok for inclusion into a new version of the plugins?

Daniel
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Link Trimmer / short urls

Post by garvinhicking »

Hi!

could you maybe create a unified diff for all changes in a single file, and upload it somewhere? Then I can wget it and commit the changes.

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Re: Link Trimmer / short urls

Post by danst0 »

I'm not so familiar with all this patching.
I think this is what you need: http://dl.dropbox.com/u/285107/linktrimmer.patch

Daniel
Post Reply