Tips and Tricks HQ Support Portal › Forums › WP eStore Forum › Link Shortener Feature Request
Tagged: google link shortener, URL Shortener
- This topic has 24 replies, 9 voices, and was last updated 9 years, 11 months ago by wzp.
-
AuthorPosts
-
February 27, 2011 at 6:29 pm #2827rnagarajanMember
Many of my customers seem to have trouble with the long links that are generated via eStore for secure downloads. I think some of them have trouble copying the links to their browser and many people have been trained to never click on a link in an email to avoid scams. So often I get a request for new links. All I end up doing is shortening the original links using bit.ly or some other shortening service. I think it would be a good feature to auto shorten links, either by default or as an administrator option. This could save quite a bit of time and headaches for site administrators.
Thanks.
March 3, 2011 at 3:42 pm #29621rnagarajanMemberJust FYI, Subsequent to releasing a new product I have had at least a half dozen customers over the past few days report being unable to use the long links. When I provided bit.ly shortened links, they had no issues. I think this feature could probably eliminate much back-and-forth with customers and administrative time for users of the plug in.
March 3, 2011 at 4:00 pm #29622mikemorrisonMemberAgreed!
March 3, 2011 at 5:40 pm #29623splucknettMemberI have posted the code from a working sample that will return a shortened url — or the original url if there was any problems.
Maybe this can help to speed up the introduction of this feature
I am new to php. (I’ve done perl, java, c++ but not much php)
So, I can’t speak for how industrial strong this code might be.
Hope it helps,
Claude Needham
<?php
function gooshrinkit($url, $key="") {
// if curl lib not around just return the url as is
if(!function_exists('curl_init')) {
return $url;
}
$apiurl = 'https://www.googleapis.com/urlshortener/v1/url';
if (!empty($key)) {
$apiurl .= '?key=' . $key;
}
$curl = curl_init();
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, $apiurl);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$longURLData = array('longUrl' => $url);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($longURLData));
$jsonResult = curl_exec($curl);
curl_close($curl);
$resultArray = json_decode($jsonResult, true);
/* if successful response looks like this
{
"kind": "urlshortener#url",
"id": "http://goo.gl/fbsS",
"longUrl": "http://www.google.com/"
}
*/
if (!isset($resultArray['id']) || empty($resultArray['id'])) {
return $url;
} else {
return $resultArray['id'];
}
} // end gooshrinkit
$longURL = 'http://galaxywebsitedesign.com/';
$shorturl = gooshrinkit($longURL);
echo $shorturl . "<br>";
$longURL = 'http://www.yoyodyneindustries.com/';
echo $shorturl . "<br>";
?>March 3, 2011 at 6:49 pm #29624wzpModeratorCaveat: When using an external shorting service, you run the very slight risk of having the shortened link harvested by others and used before the intended customer. This may result in customer complaints about expired links.
March 3, 2011 at 8:24 pm #29625rnagarajanMemberThanks. How would we use this shortener with the eStore? The eStore dynamically generates the secured links that expire in a certain number of hours (I’ve set my store to 48). What I’d like to do is have the email notification to my customers send the shortened link rather than the long link generated by eStore. Is there a way to automate that process easily? Perhaps a setting option to shorten links would be the best approach, assuming that the administrator is aware of the slight risk of URL harvesting that you mention.
Ravi
March 3, 2011 at 10:10 pm #29626wzpModerator********** DANGER WILL ROBINSON — RUNNING WITH SCISSORS AHEAD **********
********** DANGER WILL ROBINSON — RUNNING WITH SCISSORS AHEAD **********
********** DANGER WILL ROBINSON — RUNNING WITH SCISSORS AHEAD **********
I am only going to give just enough information, so that only the knowledgeable and brave will attempt this at home…
In the file eStore_post_payment_processing_helper.php look for the function definition of generate_download_link(), being careful not to confuse it with generate_download_link_for_product().
Within generate_download_link() look for all calls to eStore_register_link_in_db(), there are two of them.
About 2 lines above, there is a line that assigns a value to $download_item.
Above that assignment, you want to inset something like…
$long_url_link=$script_location.’download.php?file=’.$download_key;
$short_url_link=fts_shorturl($long_url_link, $service);
Where $long_url_link and $service are the parameters to fts_shorturl(), as described in the documentation at: http://wiki.fusedthought.com/docs/url-shortener-wordpress-plugin/v3#TOC-On-demand-shortening-of-URL
Remember to replace “$service” with the hard coded value of the shortening service desired.
You then want to edit the assignment for $download_item, so that $script_location.’download.php?file=’.$download_key is replaced with $short_url_link.
No promises about native eStore hooks to this particular shortening plugin, but it may be possible to include generic hooks into a later version of eStore.
March 3, 2011 at 11:17 pm #29627rnagarajanMemberThanks wzp. I haven’t written any code in several years and this isn’t for the feint of heart. I think I’ll wait on you guys to incorporate this at some future point if you think it has generic value to other customers.
Thanks.
Ravi
May 8, 2011 at 3:06 am #29628amin007ParticipantAdded the option to automatically shorten the encrypted download links in WP eStore. To enable this otpion simply open “eStore_advanced_configs.php” file and search for this line of code:
define('WP_ESTORE_AUTO_SHORTEN_DOWNLOAD_LINKS', false);
Once you find it, change it the following and it will enable this option:
define('WP_ESTORE_AUTO_SHORTEN_DOWNLOAD_LINKS', true);
If everything goes good then I will add this in the eStore’s settings option as a checkbox.
May 13, 2012 at 5:30 pm #29629peeldMemberThis was a year ago – going to be brave and take the plunge to edit this, shouldn’t be hard, but is there a checkbox option coming? My guess is I’ll forget this hack when I update the plugin again
thanks
May 14, 2012 at 2:20 am #29630adminKeymasterYes, this will be coming in the settings as a checkbox. Google’s URL shortener feature was in beta for a long time. It recently went out of beta so I want to give a bit more time to stabilize before adding it in the settings.
April 12, 2013 at 2:13 pm #29631oneskymusicParticipanthello,
i am following the thread how to shorten the download link URLs of my products.
the thread is about a year old.
has there been any updating in eStore that allows an easy way to do this now without using an external plug-in?
April 12, 2013 at 2:25 pm #29632wzpModeratorIf you follow the instructions from @Admin007, near the bottom of page 1 of this thread; the feature will automatically be enabled.
April 12, 2013 at 2:46 pm #29633oneskymusicParticipantok, thanks.
i will try this and let you know.
meanwhile, this is how an eStore generated link looks for my products:
it is an mp3, one of ten tracks of a music cd.
when my customers buy the whole cd, it is a LOT to navigate visually,
plus it can be a little intimidating to the average person, AND the long URLs look messy when there are many of them.
i would suggest because this seems to be an issue other eStore users, to fix it in eStore as a permanent feature or at least have it as a check-box “shorten URLs” in the settings.
what do you think?
regards, oneskymusic
April 12, 2013 at 3:02 pm #29634oneskymusicParticipantWZP,
the fix you suggested from @Admin007 (following thread, near bottom of page 1) — works. thanks!
again, i would suggest making it a more permanent part of the eStore functionality.
regards, oneskymusic
-
AuthorPosts
- You must be logged in to reply to this topic.