Package omeroweb :: Package webadmin :: Package templatetags :: Module wikitags
[hide private]
[frames] | no frames]

Source Code for Module omeroweb.webadmin.templatetags.wikitags

  1  #!/usr/bin/env python 
  2  #  
  3  #  
  4  #  
  5  # Copyright (c) 2008 University of Dundee.  
  6  #  
  7  # This program is free software: you can redistribute it and/or modify 
  8  # it under the terms of the GNU Affero General Public License as 
  9  # published by the Free Software Foundation, either version 3 of the 
 10  # License, or (at your option) any later version. 
 11  #  
 12  # This program is distributed in the hope that it will be useful, 
 13  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 15  # GNU Affero General Public License for more details. 
 16  #  
 17  # You should have received a copy of the GNU Affero General Public License 
 18  # along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 19  #  
 20  # Author: Aleksandra Tarkowska <A(dot)Tarkowska(at)dundee(dot)ac(dot)uk>, 2008. 
 21  #  
 22  # Version: 1.0 
 23  # 
 24   
 25  import re 
 26   
 27  from django.template import Library 
 28  from django.conf import settings 
 29  from django.core.urlresolvers import reverse 
 30   
 31  register = Library() 
32 33 @register.filter 34 -def wikify(value):
35 if value is not None: 36 37 urlier = r'(http[s]?://|localhost|ftp://|ftps://)(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\)\|,]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' 38 wikifier = re.compile(r'\b(%s)\b' % urlier, re.IGNORECASE) 39 value = wikifier.sub(r'<a href="\1" target="_blank">\1</a>', value) 40 41 return value 42 43 return value
44
45 # happy :) :-) 46 # wink ;) ;-) 47 # big smile :-D :D 48 # tongue sticking out :-P :P :-p :p 49 # surprised / o, no :-o :O 50 # sad :( :-( 51 # very sad :-(( :(( 52 # embarrassed :"> 53 # wearing sunglasses B-) 54 # kiss =* :-* :* 55 # confused :-/ :-\ 56 # angry X-( x-( X( x( 57 58 59 @register.filter 60 -def sharewikify(value):
61 if value is not None: 62 63 WIKI_WORD = r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\)\|,]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' 64 wikifier = re.compile(r'\b(%s)\b' % WIKI_WORD) 65 value = wikifier.sub(r'<a href="\1" target="_blank">\1</a>', value) 66 67 # happy :) :-) 68 emot1 = re.compile(r'\:[\-]?\)', re.VERBOSE) 69 value = emot1.sub(r'<img src="%s" />' % (reverse(viewname="webstatic", args=["images/emots/tinymce_smiley-smile18.gif"])), value) 70 71 # wink ;) ;-) 72 emot11 = re.compile(r'\;[\-]?\)', re.VERBOSE) 73 value = emot11.sub(r'<img src="%s" />' % (reverse(viewname="webstatic", args=["images/emots/tinymce_smiley-wink18.gif"])), value) 74 75 # very sad :-(( :(( 76 emot22 = re.compile(r'\:[\-]?\(\(', re.VERBOSE) 77 value = emot22.sub(r'<img src="%s" />' % (reverse(viewname="webstatic", args=["images/emots/tinymce_smiley-cry18.gif"])), value) 78 79 # sad :( :-( 80 emot2 = re.compile(r'\:[\-]?\(', re.VERBOSE) 81 value = emot2.sub(r'<img src="%s" />' % (reverse(viewname="webstatic", args=["images/emots/tinymce_smiley-frown18.gif"])), value) 82 83 # kiss =* :-* :* 84 emot3 = re.compile(r'[=\:][\-]?\*', re.VERBOSE) 85 value = emot3.sub(r'<img src="%s" />' % (reverse(viewname="webstatic", args=["images/emots/tinymce_smiley-kiss18.gif"])), value) 86 87 # big smile :-D :D 88 emot4 = re.compile(r'\:[\-]?[dD]', re.VERBOSE) 89 value = emot4.sub(r'<img src="%s" />' % (reverse(viewname="webstatic", args=["images/emots/tinymce_smiley-laughing18.gif"])), value) 90 91 # tongue sticking out :-P :P :-p :p 92 emot5 = re.compile(r'\:[\-]?[pP]', re.VERBOSE) 93 value = emot5.sub(r'<img src="%s" />' % (reverse(viewname="webstatic", args=["images/emots/tinymce_smiley-tongue-out18.gif"])), value) 94 95 # surprised / o, no :-o :O 96 emot6 = re.compile(r'\:[\-]?[oO]', re.VERBOSE) 97 value = emot6.sub(r'<img src="%s" />' % (reverse(viewname="webstatic", args=["images/emots/tinymce_smiley-surprised18.gif"])), value) 98 99 # embarrassed :"> 100 emot7 = re.compile(r'\:\"\>', re.VERBOSE) 101 value = emot7.sub(r'<img src="%s" />' % (reverse(viewname="webstatic", args=["images/emots/tinymce_smiley-embarassed18.gif"])), value) 102 103 # wearing sunglasses B-) 104 emot8 = re.compile(r'B\-\)', re.VERBOSE) 105 value = emot8.sub(r'<img src="%s" />' % (reverse(viewname="webstatic", args=["images/emots/tinymce_smiley-cool18.gif"])), value) 106 107 # confused :-/ :-\ 108 emot9 = re.compile(r'\:\-[\\/]', re.VERBOSE) 109 value = emot9.sub(r'<img src="%s" />' % (reverse(viewname="webstatic", args=["images/emots/tinymce_smiley-undecided18.gif"])), value) 110 111 # angry X-( x-( X( x( 112 emot9 = re.compile(r'[xX][\-]?\(', re.VERBOSE) 113 value = emot9.sub(r'<img src="%s" />' % (reverse(viewname="webstatic", args=["images/emots/tinymce_smiley-yell18.gif"])), value) 114 115 # TODO: Beta 4.1 116 #quote = re.compile(r'\[quote\](.*)\[/quote\]', re.DOTALL) 117 #value = quote.sub(r'<p class="quote">\1</p>', value) 118 119 return value
120 121 # happy :) :-) 122 # wink ;) ;-) 123 # big smile :-D :D 124 # tongue sticking out :-P :P :-p :p 125 # surprised / o, no :-o :O 126 # sad :( :-( 127 # very sad :-(( :(( 128 # embarrassed :"> 129 # wearing sunglasses B-) 130 # kiss =* :-* :* 131 # confused :-/ :-\ 132 # angry X-( x-( X( x( 133