BBCodetoHTML Plugin Channel

From AwasuWiki
Revision as of 16:22, 12 March 2007 by DiabloNL (talk | contribs) (Installation)
Jump to: navigation, search

Installation

  • Install Python
  • Create the two files listed below. It is recommended to put them into the `ChannelPlugins` directory under Awasu's installation directory.

BBCodetoHTML.plugin:

[Config]
AuthorName=Bobby van Dam
AuthorEmailAddress=notlisted
PluginNotes=This plug-in strips BB-Code from a RSS feed and tries to replace it so the content is shown in the correct way. Please understand that I'm no coding guru and this plugin was made and tested on one web site for my own use.

' --------------------------------------------------------------------------------

[ChannelParameterDefinition-1]
Name=Feed URL
Type=string
Description=The URL of the feed to be stripped from it's BB-Code.

BBCodetoHTML.py:

#awasuStripBBcode.py -- Channel plug-in to strip BB-Code from a RSS feed and convert it to HTML
#2007 by Bobby van Dam
#Thanks to Allan B. Wilson who's ChannelFeedEncoding script helped me a lot with making this one
#This script works for the website I created it for. I can't guarantee that it will work for you.
#You are free to change it so it will work better for you. Or maybe you will get some ideas from
#this script to make your own. ^_^

import urllib, os, win32api, sys


progpath = os.path.abspath(os.path.dirname(sys.argv[0]))


feedurl = win32api.GetProfileVal("ChannelParameters", "Feed URL", "", os.path.join(progpath,sys.argv[1]))


	

try:
	input = urllib.urlopen(feedurl)
	data = input.read()\
	  .replace("[list]","<ul>").replace("[*]","<li>").replace("[/list]","</ul>")\
	  .replace("[quote]","<blockquote>").replace("[/quote]","</blockquote>")\
	  .replace("[center]","<center>").replace("[/center]","</center>")\
	  .replace("[code]","<code>").replace("[/code]","</code>")\
	  .replace("[i]","<i>").replace("[/i]","</i>")\
	  .replace("[u]","<u>").replace("[/u]","</u>")\
	  .replace("[b]","<b>").replace("[/b]","</b>")\
	  .replace("&<object","<a href='").replace("</object>","'></a>")\
	  .replace("[img]","<br/><br/><img src='").replace("[/img]","'align='center'><br/><br/>")\
	  .replace("<embed","<a href='").replace("</embed>","'></a>")\
	  .replace("]","**").replace("[/url**","</a>")\
	  .replace("[email=","<a href='mailto:").replace("[/email**","</a>")\
	  .replace("**","'>").replace("[url=","<a href='") 
	input.close()
except IOError:
	print >>sys.stderr, "? Could not open URL: %s" % feedurl
	sys.exit(2)


print data

Usage

To use the BBCode plugin, select File -> New channel, then "Generated by a channel plugin", and browse to the BBCodetoHTML.py file. Add the feed URL in the plugin's URL parameter, and you're done.

It will turn this:

Image1.jpg

Into this:

Image2.jpg

Image3.jpg