OSDN Git Service

static_url better
[pybbs/pybbs.git] / index.py
index 30593b8..2643b83 100755 (executable)
--- a/index.py
+++ b/index.py
@@ -1,6 +1,6 @@
 
 import os.path
-import shutil
+import shutil,re
 import tornado.escape
 import tornado.web
 import tornado.httpserver
@@ -131,17 +131,31 @@ class RegistHandler(tornado.web.RequestHandler):
         com = self.get_argument('comment')
         text = ''
         i = 0
+        url = []
         error = ''
         for word in out:
             if word in com:
                 error = error + u'禁止ワード.'
                 break
         for line in com.splitlines(True):
+            if error != '':
+                break
             for word in words:
                 if word in line.lower():
                     error = error + u'タグ違反.('+word+')'       
-            i += len(line)
+            i += len(line)   
+            obj = re.finditer('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', line)
+            for x in obj:
+                if x.group() not in url:
+                    url.append(x.group())
+            if re.match(' ',line):
+                line = line.replace(' ',' ',1)
             text = text+'<p>'+self.link(line)+'<br></p>'
+        s = ''
+        for x in url:
+            s = s+'<tr><td><a class=livepreview target=_blank href={0}>{0}</a></td></tr>'.format(x)
+        if s:
+            text = text+'<table><tr><td>検出URL:</td></tr>'+s+'</table>'
         pw = self.get_argument('password')
         if i == 0:
             error = error + u'本文がありません.'
@@ -324,7 +338,7 @@ class Application(tornado.web.Application):
                         'ui_modules':{'Footer':FooterModule},
                         'cookie_secret':'bZJc2sWbQLKos6GkHn/VB9oXwQt8SOROkRvJ5/xJ89E=',
                         'xsrf_cookies':True,
-                        #'debug':True,
+                        'debug':True,
                         'login_url':'/login'
                         }
         tornado.web.Application.__init__(self,handlers,**settings)