PDA

View Full Version : Bookmarklet 0.2



Nick
11-30-2009, 03:13 PM
Bookmarklet
Version: 0.2
Author: Nick Ramsay
Created: 2009/11/29
Last Updated: 2010/06/03
Tested on: Hotaru 1.0.5 ~ 1.3.0
Plugins Required: Submit
Plug & Play: No. One template edit required.
Supported: Yes

Description
A simple plugin that displays a bookmarklet link for users to drag to their toolbar or add to their favorites. They can click that link when browsing other webpages to open a new window at step 2 of the post submission process. In other words, a bookmarklet is a tool for making it easier to use your site.

Instructions
1. Upload the "bookmarklet" folder to your plugins folder. Install it from Plugin Management in Admin.
2. Add the following plugin hook in a template, wherever you want to display the link:


<?php $h->pluginHook('hotaru_bookmarklet'); ?>By default, the language used for the link is "Submit to YOUR SITE". You can change that in the language file.

It's advisable to add instructions around the bookmarklet link in the /templates/bookmarklet.php file so your users can understand how to use it. E.g.


You can easily submit articles to SITE NAME with the link below. Just bookmark it in your browser and click it whenever you are reading something you want to share!
Firefox: Drag the link to your Bookmarks Toolbar
Opera: Right click the link, and choose "Bookmark Link"
Internet Explorer: Right click the link, and choose "Add to favorites"

Revision History
v.0.2 2009/12/28 - Nick - Updated for compatibility with Hotaru 1.0
v.0.1 2009/11/28 - Nick - Released first version

Please click "Rate Thread" and give this plugin a rating. Thank you.

VAHID
12-01-2009, 01:40 PM
Its important plugin.
Just i want to say THANKS

Nick
02-21-2010, 09:43 AM
The bookmarklet plugin is very, very basic. All it does is display a link wherever you put the "hotaru_bookmarklet" plugin hook.

With that in mind, I made a bookmarklet page which does not use the plugin.

First, here's what it looks like on my site:

560

Here's how to make it:

1. Create a new .php file in your theme folder and name it bookmarklet.php
2. Paste this into it:


<h2><?php echo SITE_NAME; ?> Bookmarklet</h2>

Submit stories on the fly by adding the <?php echo SITE_NAME; ?> bookmarklet to your browser.<br /><br />
Whenever you find an interesting article that you'd like to share, simply click the bookmarklet in your toolbar or Favorites menu and the <?php echo SITE_NAME; ?> submit form will open with the page's url and title already filled in.
<br /><br />

<p style="text-align: center;">
<img src="<?php echo BASEURL; ?>content/themes/<?php echo THEME; ?>images/EXAMPLE_IMAGE.png" />
</p>
<br /><br />

<?php if ($h->currentUser->loggedIn) { ?>

<h2>Instructions</h2>
<ul>
<li><b>Internet Explorer:</b> Right click "Submit it!" and choose "Add to favorites"</li>
<li><b>Firefox:</b> Drag "Submit it!" to your Bookmarks Toolbar</li>
<li><b>Opera:</b> Right click "Submit it!" and choose "Bookmark Link"</li>
</il>

<p style="font-size: 20pt; font-weight: bold; text-align: center;">
<a class="bookmarklet" href="javascript:q=(document.location.href);void(open('<?php echo BASEURL; ?>index.php?page=submit&url='+escape(q),'','resizable,location,scrollbars, menubar,toolbar,status'));">Submit it!</a>
</p>

<?php } else {?>
You'll need to <a href="<?php echo $h->url(array('page'=>'login')); ?>">log in</a> to get the bookmarklet.
<?php } ?>3. Link to that page in one of your other templates using this:


<a href="<?php echo $h->url(array('page'=>'bookmarklet')); ?>">Get our bookmarklet!</a>

baadier
04-22-2010, 01:19 AM
Is there any way to attach an image to the bookmarklet on the toolbar?

ties
04-22-2010, 11:01 AM
no.............
Edit: srry for the short answer i needed to go, euhm it cant be done because normal bookmarks use the favicon (icon) of the page they are pointing to, bookmarklets dont point a website, hell they dont even use the http uri scheme (http://en.wikipedia.org/wiki/URI_scheme), they use the javascript uri scheme (javascript:) to run one (possibly really long) line of code
this is generated by the plugin

javascript:q=(document.location.href);void(open('<?php echo BASEURL; ?>index.php?page=submit&url='+escape(q),'','resizable,location,scrollbars, menubar,toolbar,status'));

So the image cant be fetched from the uri

angolanmade
05-07-2010, 02:54 AM
The selected text feature caught my attention, this would be a welcome addition to this plugin.

http://friendfeed.com/share/bookmarklet

anika039
07-22-2010, 11:10 AM
When I click in the bookmarklet in my browser it bookmarks only the link and the heading but no description. is there any way to take the description from the link?

Nick
07-22-2010, 11:56 AM
Not with the current plugins. If you enjoy programming, you could extend the Submit plugin to fetch descriptions from the meta description tags.

mystermarque
10-25-2010, 07:23 PM
With both the bookmarklet plugin, as well as the page method, users get an error message if they click the bookmarklet when not logged in.

I've managed to get the submit page to redirect to the login page if a user isn't logged in (as it should) - including the referring url to send them back to the submit page by making the following modification:

Replace the following in Submit.php (in the submit plugin folder)


// check user has permission to post. Exit if not.
$h->vars['posting_denied'] = false;
if ($h->currentUser->getPermission('can_submit') == 'no') {
// No permission to submit
$h->messages[$h->lang['submit_no_post_permission']] = "red";
$h->vars['posting_denied'] = true;
$h->vars['can_edit'] = false;
$h->vars['post_deleted'] = false;
return false;
}

With the following:


// check user has permission to post. Exit if not.
$h->vars['posting_denied'] = false;
if ($h->currentUser->getPermission('can_submit') == 'no' && $h->currentUser->loggedIn) {
// No permission to submit
$h->messages[$h->lang['submit_no_post_permission']] = "red";
$h->vars['posting_denied'] = true;
$h->vars['can_edit'] = false;
$h->vars['post_deleted'] = false;
return false;
}


Don't know if this is the most elegant solution, but it works. Hope it helps anyone wrestling with the problem and brings the issue to the attention of anyone who hasn't tried the bookmarklet when logged out. Cheers, Mark.

mystermarque
10-27-2010, 06:25 PM
@anika039

I also need the link's description - as well as the keywords - and I just worked out how to do it.

Copy submit2.php (in the submit plugin folder) to your theme folder and paste the following at the top (below the license):


<?php
$tags = get_meta_tags($h->vars['submit_orig_url']);
$h->vars['submit_content'] = $tags['description'];
$h->vars['submit_tags'] = $tags['keywords'];
?>

Note: You can remove the keywords line if you don't need them - but if you use the code as is, you might want to increase the plugin's tag character limit setting in admin to 1000 rather than 100. Otherwise you'll likely get a "too many tags" error message upon submission.

svalluripalli
02-22-2011, 06:23 PM
First of all thank you for the great plugins. Me being a newbie to both PHP as well as Hotaru having little hard time[thanks to excellent doc]. I have not been successful in adding the bookmarklet. One thing which i am still unable to understand to how does the code add a bookmarklet to the browser? Where should i be adding the code: <a href="<?php echo $h->url(array('page'=>'bookmarklet')); ?>">Get our bookmarklet!</a>?

frytec
03-07-2012, 07:06 PM
The bookmarklet plugin is very, very basic. All it does is display a link wherever you put the "hotaru_bookmarklet" plugin hook.

With that in mind, I made a bookmarklet page which does not use the plugin.

First, here's what it looks like on my site:

560

Here's how to make it:

1. Create a new .php file in your theme folder and name it bookmarklet.php
2. Paste this into it:


<h2><?php echo SITE_NAME; ?> Bookmarklet</h2>

Submit stories on the fly by adding the <?php echo SITE_NAME; ?> bookmarklet to your browser.<br /><br />
Whenever you find an interesting article that you'd like to share, simply click the bookmarklet in your toolbar or Favorites menu and the <?php echo SITE_NAME; ?> submit form will open with the page's url and title already filled in.
<br /><br />

<p style="text-align: center;">
<img src="<?php echo BASEURL; ?>content/themes/<?php echo THEME; ?>images/EXAMPLE_IMAGE.png" />
</p>
<br /><br />

<?php if ($h->currentUser->loggedIn) { ?>

<h2>Instructions</h2>
<ul>
<li><b>Internet Explorer:</b> Right click "Submit it!" and choose "Add to favorites"</li>
<li><b>Firefox:</b> Drag "Submit it!" to your Bookmarks Toolbar</li>
<li><b>Opera:</b> Right click "Submit it!" and choose "Bookmark Link"</li>
</il>

<p style="font-size: 20pt; font-weight: bold; text-align: center;">
<a class="bookmarklet" href="javascript:q=(document.location.href);void(open('<?php echo BASEURL; ?>index.php?page=submit&url='+escape(q),'','resizable,location,scrollbars, menubar,toolbar,status'));">Submit it!</a>
</p>

<?php } else {?>
You'll need to <a href="<?php echo $h->url(array('page'=>'login')); ?>">log in</a> to get the bookmarklet.
<?php } ?>3. Link to that page in one of your other templates using this:


<a href="<?php echo $h->url(array('page'=>'bookmarklet')); ?>">Get our bookmarklet!</a>




is there a way to hide the javascript code of the bookmarklet?

i dont want my users see the script code when passing mouse over the "Submit it!" anchor.

atddoug
03-20-2012, 11:06 PM
Is there a way to include my 16x16 share icon with the link dragged to the Firefox Bookmarks toolbar?

I tried inserting the image tag with the absolute path like so but the image is left behind:


<a class="bookmarklet" href="javascript:q=(document.location.href);void(open('<?php echo BASEURL; ?>index.php?page=submit&url='+escape(q),'','resizable,location,scrollbars, menubar,toolbar,status'));"><img src="http://allthingsdemocrat.com/pages/images/ATD-button-16x16rounded.jpg" alt="Submit to ATD"><?php echo $h->lang['bookmarklet_submit']; ?></a>

frytec
03-20-2012, 11:52 PM
atdoug, you can do it with some complex tricks.. using html img tags will not work at all..

i was trying to figure out how to put an icon in bookmarklet some days ago and just gave up. Its too complex and not compatible with all browsers.

If you wanna try, look http://stackoverflow.com/questions/521040/how-to-have-favicon-icon-set-when-bookmarklet-dragged-to-toolbar and http://wiki.whatwg.org/wiki/Link_Icons

atddoug
03-21-2012, 12:03 AM
This may be old news but using the bookmarklet in IE 8, it treats the new window as a pop-up that I need to temporarily allow. Then it completes the script and the page works correctly, but generates this error:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; BRI/1; BRI/2)
Timestamp: Tue, 20 Mar 2012 23:51:13 UTC


Message: 'document.getElementById(...)' is null or not an object
Line: 262
Char: 2
Code: 0
URI: http://rsnews.allthingsdemocrat.com/cache/css_js_cache/hotaru_js_1332284408.js

atddoug
03-21-2012, 12:08 AM
frytec,

Thanks for the info.

Funny - one respondent in that page link says it can't be done, but I have several bookmarklets in my bookmark toolbar that include an icon (Including Hotaru's firefly). So obviously there's a way to do it that we're not aware of at the moment. But if I find out I'll share ...

atddoug
03-21-2012, 12:13 AM
fyi:

I added these additional instructions for my users to bookmark in Chrome:


Chrome: Drag the link to the Bookmarks Toolbar, which creates a globe icon. Right-click on the globe, select Edit from the menu, then change the Name to "Submit to YOUR HOTARU SITE"