A plugin that converts links to skydrive documents into direct download links. Simple to use, unobtrusive, adds convenience for users.
|Author:||Dino Chiesa (profile at wordpress.org)|
|WordPress version required:||3.2|
|WordPress version tested:||3.9.36|
|Added to WordPress repository:||06-06-2012|
Warning! This plugin has not been updated in over 2 years. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.
|Total downloads:||2 376|
Click to start download
skydrv-hotlink is a WordPress Plugin.
Onedrive is a cloud-based storage service offered by Microsoft, accessible at http://onedrive.com . It’s free. It works nicely and integrates well with Microsoft Office and Windows. Previously it was known as Skydrive.
One problem is that Onedrive does not easily provide direct-download links for the files located on onedrive. Suppose you would like to share a document that exists on your Skydrive. You click the “share” button, and Skydrive gives you a link which you can then embed into any web page.
But, that link is not a direct-download link for the file you intend to share. The actual download link will be embedded within that page. Clicking the “share” link provided by onedrive takes the user to onedrive, where they need to click another link to download the document.
This is fine, but perhaps not as convenient as it could be for users, in some cases.
This plugin allows a wordpress blog to eliminate that extra hop.
It automatically convert links to Onedrive documents into direct-download links.
The way it works:
You login to Onedrive.
Select the file you would like to share.
Click the “share” button. (see screenshot #1)
Copy (ctrl-C) the link for that particular file. Don’t use the URL shortener. The link should look something like this:
or like this:
- Insert an anchor tag into one of your wordpress posts or one of your
wordpress pages; specify that value as the href. It should look like
< a src=’https://onedrive.live.com/?id=842434EBE9688900!1123&cid=842434ebe9688900#’
class=’skydrv-hotlink’>Download the file</ a >
The markup is regular HTML markup, but the anchor must be decorated with the special class ‘skydrv-hotlink’. (see screenshot #2)
- When the actual page or post is rendered, the plugin will transform the href into a direct-download link. The transformed href will look something like this:
When the user clicks that link, it will download the file directly.
Note: The direct-download link has a limited lifetime, so you should not retain it indefinitely. In fact that is the entire reason this plugin exists. Set the cache period for the plugin to set the lifetime of any link. Generally, I’ve found that links are good for at least an hour.
- This plugin relies on jQuery.
- The publisher of the target document must have a Onedrive account.
- The wordpress host must allow outgoing http connections. (true in most cases)
- WordPress must be configured to enable curl. (true in most cases)
- PHP should have mcrypt enabled. If not, operation of the plugin is less secure.
Thanks for your interest!
You can make a donation at http://dinochiesa.github.io/Skydrv-hotlink-Donate.html
Check out all my plugins:
This shows Windows Onedrive; right-click to select the share option for a document.
This shows how to specify anchor tags in wordpress pages.
The Settings menu in the wordpress admin backend. The menu item for skydrv-hotlink is showed here at the bottom of the list. Click it to set the cache lifetime value.
Why would anyone use this plugin?
Onedrive is a nice service that allows people to host files “in the cloud”. It’s also possible to share some of those files with others. But Skydrive doesn’t provide an easy way to get a direct-download link for a file that you want to share.
This plugin lets you do that. It lets you embed a link to a file hosted on skydrive, into any wordpress page or post. Then viewers will be able to download that file without first connecting directly to the skydrive site.
How does this plugin really work?
Warning: geek-speak ahead.
The skydrv-hotlink plugin registers with wordpress to receive the
requests from the client-side logic. Upon receiving such a request,
Wordpress routes the incoming request to the plugin. The plugin checks
the cache for the requested link. If it is not available in cache, the
plugin retrieves the full download page from Onedrive, scrapes the
resulting HTML page, and extracts the hidden direct-download link. The
running in the browser, as a json blob.
What happens if, for whatever reason, the plugin fails?
The plugin is designed so that if the lookup of the direct-download link fails, the original anchor (A tag) continues to work with its original href. In the case of failure, when the user clicks the A link, instead of getting a direct-download, he will visit the usual Onedrive download page.
Do I need to define a css class called ‘skydrv-hotlink’?
No. It’s used as a marker for the plugin. You need not attach any css
styling to that class name. You can do so if you like.
What if I want to style my anchor tags with a different class?
You can specify multiple classes on html tags. The syntax is like this:
Can viewers of the site detect that the plugin is in use?
Why doesn’t this plugin use a shortcode?
It’s just a design choice.
The approach used by this plugin results in faster page loads. The
replacement of regular share links with direct download links can
require a call out to Microsoft Onedrive, which can take several
seconds. Doing this on the server-side with a shortcode would simply
add those several seconds to the page render time that the user sees.
But this plugin perfoms the replacement of the href on the
after the page has been loaded and rendered. Only the href changes,
and that happens with no discernable UI update. The result is a faster
page load time.
Also, the approach used by this plugin is also more reliable than a
short code. Here’s why: if for any reason the connection to onedrive
fails, the anchor link will remain unchanged, pointing to the regular
share page on onedrive.
Does the plugin perform caching?
Yes. On the server side, the plugin caches links and re-uses them. You can specify the lifetime of the cache in the admin back-end. Caching allows the pages to render more quickly. It will also reduce the number of outbound http connections initiated by your wordpress site, which is a good thing in general.
Where is the cache stored?
The direct links are cached in files in a subdirectory of the wp-content directory.
The subdirectory is named skydrv-hotlink-cache . The cache files are very small, around 128 bytes each. There will be at most one cache file per hotlinked file.
Will I be charged a fee by Onedrive if I use this plugin?
No. As far as I know, Onedrive is free.
Will I be charged a fee by my hoster if I use this plugin?
I don’t know. The plugin makes outbound http connections. Most hosters allow this, and don’t charge a fee for data transmission. If you’re not sure, check with your hoster.
Do I need to do anything special on Onedrive to make this work?
You need to set permissions on the file to be downloaded, to make it publicly accessible. Consult the help for Onedrive to understand how to do this.
How is the AJAX stuff implemented?
The plugin uses the recommended wordpress practice of registering an
action word with admin-ajax.php.
Can any user access the AJAX request that provides direct download links?
No. This plugin verifies that the request for download links comes from one of the posts or pages of your blog. It uses WordPress API check_ajax_referer() to do so.
- tested on wordpress version 3.9.1
- Readme updated to use the term “Onedrive” instead of “Skydrive”
- replace space with + in the base64-encoded token before
decoding. Without this fix, sometimes the validation of ajax
requests would deliver false negatives.
- generalize the regex to accept more onedrive links.
- fix admin form to display properly when mcrypt does not exist.
- relaxed the hard dependency on mcrypt().
- fixed the external admin form so that it displays properly.
- include error_log() statements to aid in diagnosis in case of problems.
- include code to prevent direct access, correctly.
- fixed a bug in the generation of random strings.
- un-broke activation.
- delegated admin form rendering to an external php file
- slightly tweaked readme.
- first tagged release
- refactored and improved AJAX token validation
- initial checkin to SVN
- slight refactoring of php code
- added verifier token to prevent replays
- initial release