Dreamstime

Saturday, 21 September 2013

Zoundry Raven: Inserting Amazon Affiliate "iframe" Ads

With This Modification, There Should Be A New Version For Zoundry Raven

The offline blog editor Zoundry Raven converts my Amazon Affiliate "<iframe><iframe/>" tags to "<iframe/>" upon publishing my blog posts. As a consequence, my Amazon Affiliate "iframe" ads do not get displayed correctly when viewed from the Opera desktop and Opera Mini web browsers, and perhaps on other web browsers too. What puzzles me though is that Raven displays these ads correctly while editing - albeit the ad must be inserted at the end of a blog post and no editing is allowed in the "Design" tab after these ads have been inserted. I wonder why?

The Problem

After having successfully installed the development environment, I went about searching and digging into Raven's source code and I managed to narrow down the problem to the 4Suite XML processing library that Raven uses.

For any XML tags containing empty element (elements are the text between the opening and closing tags), the tag will be represented as a single tag ended with a slash in 4Suite. Amazon Affiliate "iframe" ads have empty elements and hence, self-terminating "iframe" tags upon publishing.

My Work-around

To enable me to insert these "iframe" ads, what I did is to filter my blog post through uTidyLib just before publishing so that any invalid HTML tags generated by 4Suite will be corrected by uTidyLib (uTidyLib is just a wrapper for TidyLib, and TidyLib is just a library version of Dave Raggett's HTML Tidy, a program that fixes invalid HTML markups). To achieve this, I added 3 extra lines of code (enclosed between "# ---- START ----" and "# ---- END -----" in the code below) to the function _transformContentForPublishing in the file "zoundry\blogapp\services\pubsystems\blog\blogpublisher.py".



def _transformContentForPublishing(self, zblog, zxhtmlDocument): #@UnusedVariable
u"""_transformContentForPublishing(ZBlog, ZXhtmlDocument) -> string representation of content.
Subclasses can override to convert the xhtml document to a string prior to publishing.
""" #$NON-NLS-1$
# simply serialize the body content (but not including the body element).
content = extractBody(zxhtmlDocument.getBody().serialize())

# ---- START ----
#
# To avoid getting self-terminating "iframe" tags, we filter the 'body' content through "tidyutil.py".
# ChuahTC Date: 2013-Sept-3
#
tidyOptions = dict(output_xml=1, show_body_only=1, quiet=1, char_encoding="utf8", \
output_error=0, show_warnings=0, quote_nbsp=0, raw=1)
content = tidyutil.tidyHtml(content, tidyOptions)
# ---- END -----



removeNewLines = zblog.getPreferences().getUserPreferenceBool(IZBlogAppUserPrefsKeys.SP_REMOVE_NEWLINES, False)
if removeNewLines:
transformer = ZXhtmlRemoveNewLinesTransformer()
content = transformer.transform(content)

return content
# end _transformContentForPublishing()


I will also need to add this line to the list of imports in this file in order to make calls to the uTidyLib functions:

from zoundry.base.zdom import tidyutil

A picture of the above mention code below if you find the above a bit hard to read because of word-wrap (Sorry):


Note:

  • I tried a quick and dirty fix by inserting one or more characters between the tags "<iframe>" and "</iframe>" so that their elements are non empty, but I noticed that the characters got displayed (and seemed out of placed) in Opera Mini when I viewed my blog homepage http://chuahtc.blogspot.com. Inserting an empty space to make the element non empty would be ideal but it got striped out by Raven and consequently, making my "iframe" tags self-terminating.
  • The Editor in Raven is built using the library wxWidgets - ( Update 2nd June 2014: It is a Microsoft COM based object that is borrowed from MS Internet Explorer actually, and not wxWidgets ). I believe wxWidgets, is aware that "iframe" tags should not be the self-terminating; which, to me, explains why the Amazon "iframe" ads got displayed correctly while editing.
  • Amazon "iframe" ads can only be inserted at the end of a blog post, and no editing is allowed in the "Design" tab after these ads have been inserted - editing is still allowed in the "XHTML" tab though.( Update 4th October 2014: Stumble across this by accident (actually wasted my time tracing through the Python code trying to find the cause of this problem) - editing is allowed in the "Design" tab when there is a valid connection to the Internet on the computer. I usually compose my blog offline - that's the cause of my problem previously. Also, the reason why the "iframe" ads can only be inserted at the end is because of self-terminating "iframe" tag that is being used in the "Design" tab. The blog post should be filtered through uTidyLib first to solve this problem ).


I am posting this blog from Zoundry Raven. You should see some Amazon Affiliate "iframe" ads below.




0 comments:

Post a Comment