boogdesign posts

Longer posts on standards based web design, portable web development and Linux, intermingled with some stuff on my other nerd interests.

Rob Crowther, London, UK based Blogger, Web Developer, Web Designer and System Administrator - read my Curriculum Vitae

Buy my book!

Book CoverHello! HTML5 and CSS3 available now

Buy my other book!

Book CoverEarly access to HTML5 in Action available now
« Standards.Next HTML5 :: Things I did last year (part two) »

Fun with b2evolution plugins

24/06/09

11:18:32 pm Permalink Fun with b2evolution plugins

Categories: Web Develop, Blogging and Internet Culture

As I've mentioned in my recent posts, this blog hasn't received a lot of love in the last two years or so. I'm slowly getting back on track but, following my upgrade to b2evo 2.x in February, I've been missing some of the features I used to have.

About two and half years ago I implemented social network sharing buttons on my skin. I didn't have the time to figure out how to make them work in my 2.x skin, but today I discovered BAE Social Bookmarks. The developer's website is sadly defunct but the plugin has been made available by someone who'd downloaded it before the site disappeared. I had a bit of trouble figuring out how it worked but I eventually worked it out from the code. Basically you insert a template for the link and insert $permanent_url$ and $title$ in an appropriate place:

<a href="http://del.icio.us/post" onclick="window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+encodeURIComponent('$permanent_url$')+'&title='+encodeURIComponent('$title$'),'delicious', 'toolbar=no,width=700,height=400'); return false;" title="del.icio.us"><img src="/images/delicious.gif" border="0" height="16" width="16"></a>

<script type="text/javascript">document.write('  <a href="http://reddit.com/submit?url='+encodeURIComponent('$permanent_url$')+'&title='+encodeURIComponent('$title$')+'" target="blank" title="Reddit"><img src="/images/reddit.png" width="16" height="16" border="0" /></a>');</script>

After this success I turned my attention to my technorati tags. There are a couple of different versions of this, Technorati Plugin and Rich Tags Plugin, though I couldn't find a download for the former and the latter seemed to be for 1.9 and earlier versions. Also the 0.3 version Rich Tags plugin was missing the 'Technorati' button on the edit post screen which the 0.2 version had. Looking at the code, the AdminDisplayEditorButton function was still defined in /inc/plugins/_plugin.class.php so it seemed like all I had to do was simply copy that bit across:

function AdminDisplayEditorButton( & $params )
	{
		?><script language="JavaScript" type="text/javascript">
function WriteTag(){
		document.getElementById('itemform_post_content').value += "<!--tags MyTag My+Tag -->";
}
</script><input type="button" id="b2eRchTgs_button" value="Rich Tags" onclick="WriteTag()" /><?php
		return true;
	}

Tried it, and it worked &amp;#58;&amp;#41;

Intoxicated by this early success I decided to see what else I could do, so I read the documentation and also had another look at the BAE Social Bookmarks plugin. I thought it would be good to have options other than technorati for tagging - I use delicious a lot and there are some other good candidates. First thing I wanted was some configuration options, looking at the BAE code this didn't seem too difficult, but I didn't need a textarea like it uses and the one thing that did seem hard to find was documentation. The source code again comes to the rescue, there is some quite extensive documentation starting from line 361 in /inc/plugins/_plugin.class.php, so I figured out I wanted a checkbox which takes a value of 0 or 1:

   function GetDefaultSettings( & $params )
    {
      $r = array(
         'technorati_tags' => array(
               'label' => 'Enable Technorati Tags',
               'type' => 'checkbox',
               'defaultvalue' => 1,
                'note' => 'Inserts links to technorati tag pages, you should also add a CSS rule for either .tags (generic) or technorati_tags (specific)',
                ),
          'delicious_tags' => array(
               'label' => 'Enable Delicious Tags',
               'type' => 'checkbox',
               'defaultvalue' => 0,
                'note' => 'Inserts links to delicious tag pages, you should also add a CSS rule for either .tags (generic) or delicious_tags (specific)',
                ),
        );
      return $r;
    }

Easy enough, I also copied this function from the BAE plugin, because I assume it's just a bit of boilerplate:

    function PluginSettingsUpdateAction()
    {
      global $DB;
      $DB->query('DELETE FROM T_items__prerendering WHERE 1');
      $this->msg( sprintf( T_('Removed %d cached entries.'), $DB->rows_affected ), 'success' );
    }

Finally I modified the RenderItemAsHtml method to detect the settings and render the appropriate tags (nothing fancy here):

    if ($this->Settings->get( 'technorati_tags' ) == 1) {
            $AddedAtLeastOneTag |= $this->addTags( $content, $Matches[ 1 ], '<div class="tags technorati_tags"><strong>Technorati tags for this post :</strong> ', '</div>', 'http://technorati.com/tag/', ' rel="tag"' );
    }

    if ($this->Settings->get( 'delicious_tags' ) == 1) {
            $AddedAtLeastOneTag |= $this->addTags( $content, $Matches[ 1 ], '<div class="tags delicious_tags"><strong>Delicious tags for this post :</strong> ', '</div>', 'http://delicious.com/tag/', ' rel="tag"' );
    }

It all seems to work, so I added flickr and twitter just for the heck of it and then some extra CSS rules for my template to make them look distinctive. Download Rich Tags Plugin v0.4.


Tweet this!
PermalinkPermalink

Comments:

Comment from: Walter Cruz [Visitor] · http://b2evolution.waltercruz.com
25/06/09 @ 04:03
Great to see!
Comment from: Lee Turner [Visitor] · http://leeturner.org
25/06/09 @ 09:45
Good work, and thanks for making it available to everyone.
Comment from: Xiao Hou [Visitor] · http://www.associated-conferences.com
06/01/10 @ 16:04
i have had such a nightmare with b2evo plugins.. this is a great help! thankyou
Comment from: Evden Eve Nakliyat [Visitor] · http://www.evdenevenakliyatl.com
08/01/10 @ 11:05
Hi .. thanks for making it available to everyone.. boogdesign.com = NUMBER ONE ;)