15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
# This is an IVLE application.
23
# A SMF forum application for IVLE.
18
# Author: David Coles, Will Grant
30
from ivle import interpret
34
Handler for the Forum application.
36
This application implements a general purpose PHP CGI loader
41
forum_base = "php/phpBB3"
43
# Set request attributes
45
req.styles = ["media/forum/forum.css"]
47
# Process URL for special directives
48
url = urlparse.urlparse(req.path)
49
hierarchical_part = url[2]
51
forum_page = "" # use the default forum page
54
board = re.match('board/(.*?)(/|$)',hierarchical_part)
56
framequery += 'f=' + board.group(1) + "&"
57
forum_page = "viewforum.php"
59
topic = re.search('topic/(.*?)(/|$)',hierarchical_part)
61
framequery += 't=' + topic.group(1)
62
forum_page = "viewtopic.php"
64
# If the tail of the forum url is empty or a known special request
65
# then wrap the page in the headers and footer and load the default or
66
# special page in the ivlebody frame
69
location = forum_page + framequery
71
frameurl = util.make_path(os.path.join(forum_base,location))
72
req.content_type = "text/html"
73
req.write_html_head_foot = True
74
req.write('<object class="fullscreen" type="text/html" data="%s">'%
75
(frameurl + framequery))
25
from urllib import quote
27
from ivle.webapp.base.xhtml import XHTMLView
28
from ivle.webapp.base.plugins import ViewPlugin, CookiePlugin, MediaPlugin
32
class ForumView(XHTMLView):
35
def __init__(self, req, path):
38
def authorize(self, req):
39
return req.user is not None
41
def populate(self, req, ctx):
42
self.plugin_styles[Plugin] = ['forum.css']
43
forum_base = req.config.plugin_configs[Plugin]['base']
45
ctx['url'] = ivle.util.make_path(os.path.join(forum_base, self.path))
47
class ForumBoardView(ForumView):
48
def __init__(self, req, board):
49
self.path = 'viewforum.php?f=' + board
51
class ForumTopicView(ForumView):
52
def __init__(self, req, topic):
53
self.path = 'viewtopic.php?t=' + topic
55
def make_forum_cookie(user):
56
secret = ivle.config.Config().plugin_configs[Plugin]['secret']
58
login = quote(user.login)
59
nick = quote(user.nick)
61
if user.email != None:
62
email = quote(user.email)
64
role = quote(str(user.role))
66
hashtext = login + nick + email + role + secret
67
hash = hashlib.md5(hashtext).hexdigest()
68
data = quote(login + ':' + nick + ':' + email + ':' + role + ':' + hash)
72
class Plugin(ViewPlugin, CookiePlugin, MediaPlugin):
74
('forum', ForumView, {'path': ''}),
75
('forum/+board/:board', ForumBoardView),
76
('forum/+topic/:topic', ForumTopicView),
77
('forum/*path', ForumView),
81
('forum', 'Forum', 'Discussion boards for material relating to '
82
'Informatics, IVLE and Python.', 'forum.png', 'forum', 4)
85
cookies = {'ivleforumcookie': make_forum_cookie}