Attachment 'SkypeLink-1.0.py'

Download

   1 # -*- coding: iso-8859-1 -*-
   2 """
   3     MoinMoin - Skype macro Version 1.0, 9.08.2013
   4     
   5     Syntax:
   6        <<SkypeLink>>; <<SkypeLink()>>
   7        <<SkypeLink(username)>>
   8        <<SkypeLink(icon:username)>>
   9        <<SkypeLink(user:username)>>
  10        <<SkypeLink(both:username)>>
  11        
  12     @copyright: 2012-2013 Ian Riley <ian.riley@internode.on.net>
  13     license: GNU GPL, see COPYING for details.
  14 
  15 """
  16 
  17 from MoinMoin import wikiutil
  18 from MoinMoin.config import url_prefix_static
  19   
  20 icon = u'<img src="%s/common/Skypeicon_16px.png" alt="Skype" style="vertical-align: middle;">&nbsp' % url_prefix_static
  21 link = u'<span style="vertical-align: middle;"><a href="skype:%s">%s</a></span>'
  22 opts = ['', 'icon:', 'user:', 'both:']
  23 
  24 def execute(macro, args):
  25     text = wikiutil.escape(args) # make sure nothing harmful
  26     option = 0
  27     result = ''
  28     if text in opts: #no username, so just give Skype the focus
  29         option = 0
  30         result = u'<a href="skype:">%s</a>' % icon
  31     else:
  32         option = 3 #if no suffix, default to both
  33         for i, v in enumerate(opts[1:]):
  34             if text.startswith(v):
  35                 option = i + 1
  36                 text = text.split(':', 1)[1]
  37                 break
  38         if option in [1, 3]:      
  39             result = link % (text, icon)
  40         if option in [2, 3]:
  41             result += link % (text, text)    
  42     return result

You are not allowed to attach a file to this page.