Install | API Key | Issues | ToDo
If you use WordPress, you may have heard of a useful plugin called WordPress Widgets. It allows you to easily manage your sidebar, and there are many widgets for it in existence to help you customize your blog.
Based on the del.icio.us widget that came with the plugin, I have created a similar “recent bookmarks” widget for ma.gnolia.
Installation as a Widget
- Download the Widget!
- Unzip the widget. You should have a file and a folder with two more files in it.
- Upload everything to your wp-content/plugins/widgets folder.
- Log in to your admin panel.
- Go to “Plugins” and activate the widget.
- Go to “Presentation”–>”Sidebar Widgets” to set up your widget!
API KEY
You will need to enter your Ma.gnolia Username and API key to use this widget.
To activate your API Key:
- Log in to Ma.gnolia.
- Click on “Profile” to edit it.
- Click on “Advanced”.
- Create your key, and copy/paste it into your sidebar widget!
Issues
Right now, this script is set to use the URL you have told WordPress that your blog is at in your General Options.
If your server allows you to hit your blog no matter how it is entered in the url (as in, domain.com or www.domain.com) this script might not work. You will have to either change your .htaccess file to redirect URL variations to one URL, or tell me how I can get around this.
If you are allowed to edit your .htaccess file, you can add in the following lines to force your site to have a www in front of the url. You’ll need to make sure you don’t put the code inside the WordPress comments in the file or else WordPress will overwite it for some reason.
RewriteCond %{HTTP_HOST} !^www.yoursite.com$ [NC]
RewriteRule ^(.*)$ http://www.yoursite/$1 [R,L]
ToDo
- Set descriptions as title tags.





I’ve just installed and activated this widget on Wordpress. I’ve added my username, api key etc. however all I’m seeing in the sidebar is the title but none of the links. What could I be doing wrong? thanks.
Hi Vicky,
There’s still a bug in this where it has to match the URL exactly – if you look at my own installation, if you go to animejb.net instead of http://www.animejb.net it does the same thing. I have no idea how to fix it at the moment.
Hey I found a couple of issues with your script. The file that grabs the data from the ma.gnolia server (magUrl.php) makes a couple of assumptions about the environment that might not be true.
1. It assumes that “register globals” is turned on by accessing the GET variables directly. PHP no longer ships with register globals turned on by default, and it may even be removed in the next version of PHP. You can pretty much assume that anyone on a shared host will not have access to these variables. Better to define these variables explicity before using them:
$url = $_GET[url];
$api_key = $_GET[api_key];
$person = $_GET[person];
$limit = $_GET[limit];
$tags = $_GET[tags];
2. It also assumes that fopen URL access is enabled. Many hosts such as dreamhost have disabled this feature for security reasons. Trying to access a remote file using get_file_contents will fail in this case. Luckily, most hosts that do this will compile PHP with cURL support. Here is an alternative to get_file contents using curl:
$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $mag_url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
// display file
echo $file_contents;
Of course many homebrew versions of PHP don’t bother to include curl support, so maybe you want to include a check in your script that will try curl, and then fallback on get_file_contents if that fails?
Anyway, once I added these changes, the script worked fine (before, the XHR request failed, and no links were returned).
Something else I just noticed was that anyone who uses your plugin has their API key passed in plain text to and from the web browser. Correct me if I’m wrong, but wouldn’t this allow a malicious person to grab your API key to add/delete links to your ma.nolia bookmarks? Perhaps you should consider keeping the API key server side instead of passing it to the browser.
[...] thank you to House of AnimeJB for the Ma.gnolia widget for Wordpress. You’ve made my decision between the two services just [...]