Skip to content

Commit

Permalink
Refactor absolute href.
Browse files Browse the repository at this point in the history
  • Loading branch information
thijstriemstra committed Sep 20, 2010
1 parent 6b1abed commit 063786a
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions FacebookPlugins.py
Expand Up @@ -2,9 +2,10 @@
# See LICENSE.txt for details.

"""
Collection of Trac wiki macro's for Facebook's plugins.
Collection of Trac wiki macro's for U{Facebook<http://facebook.com>}'s plugins.
@see: http://developers.facebook.com/plugins
@see: http://developers.facebook.com/docs/guides/web#plugins
@note: Also support XFBML?
"""

Expand All @@ -25,8 +26,21 @@ class FacebookPlugins(Component):
Support for Facebook plugins in Trac.
"""


class FBWikiMacro(object):

fb_url = 'http://www.facebook.com/plugins'

class LikeButton(WikiMacroBase):
def _abs_href(self, formatter):
"""
Get absolute href for trac resource.
@param formatter
"""
return self.env.abs_href.base + get_resource_url(self.env, formatter.resource, formatter.href)


class LikeButton(WikiMacroBase, FBWikiMacro):
"""
The [http://developers.facebook.com/docs/reference/plugins/like Like button] lets
users share pages from your site back to their [http://facebook.com Facebook]
Expand All @@ -41,13 +55,15 @@ class LikeButton(WikiMacroBase):
}}}
"""

plugin_name = 'like'

def expand_macro(self, formatter, name, args):
"""
@param name: the actual name of the macro
@param args: text enclosed in parenthesis at the call of the macro
"""
options = unicode(args).split(",")
href = self.env.project_url + get_resource_url(self.env, formatter.resource, formatter.href)
href = self._abs_href(formatter)
layout = 'standard' # options: 'button_count', 'box_count'
show_faces = 'true'
width = '450'
Expand All @@ -61,13 +77,13 @@ def expand_macro(self, formatter, name, args):
if len(options) > 1:
layout = options[1] + "_count"

iframe_code = '<iframe src="http://www.facebook.com/plugins/like.php?href=%s&layout=%s&show_faces=%s&width=%s&action=%s&colorscheme=%s&height=%s" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:%spx; height:%spx;" allowTransparency="true"></iframe>' % (
href, layout, show_faces, width, action, colorscheme, height, width, height)
iframe_code = '<iframe src="%s/%s.php?href=%s&layout=%s&show_faces=%s&width=%s&action=%s&colorscheme=%s&height=%s" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:%spx; height:%spx;" allowTransparency="true"></iframe>' % (
self.fb_url, self.plugin_name, href, layout, show_faces, width, action, colorscheme, height, width, height)

return iframe_code


class ActivityFeed(WikiMacroBase):
class ActivityFeed(WikiMacroBase, FBWikiMacro):
"""
The [http://developers.facebook.com/docs/reference/plugins/activity Activity Feed]
plugins displays the most interesting recent [http://facebook.com Facebook] activity
Expand All @@ -81,13 +97,15 @@ class ActivityFeed(WikiMacroBase):
}}}
"""

plugin_name = 'activity'

def expand_macro(self, formatter, name, args):
"""
@param name: the actual name of the macro
@param args: text enclosed in parenthesis at the call of the macro
"""
options = unicode(args).split(",")
href = self.env.project_url + get_resource_url(self.env, formatter.resource, formatter.href)
href = self._abs_href(formatter)
width = '300'
height = '300'
header = 'true'
Expand All @@ -100,7 +118,7 @@ def expand_macro(self, formatter, name, args):
if len(options) > 1:
recommendations = 'false'

iframe_code = '<iframe src="http://www.facebook.com/plugins/activity.php?site=%s&width=%s&height=%s&header=%s&colorscheme=%s&recommendations=%s" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:%spx; height:%spx;" allowTransparency="true"></iframe>' % (
href, width, height, header, colorscheme, recommendations, width, height)
iframe_code = '<iframe src="%s/%s.php?site=%s&width=%s&height=%s&header=%s&colorscheme=%s&recommendations=%s" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:%spx; height:%spx;" allowTransparency="true"></iframe>' % (
self.fb_url, self.plugin_name, href, width, height, header, colorscheme, recommendations, width, height)

return iframe_code

0 comments on commit 063786a

Please sign in to comment.