~azzar1/unity/add-show-desktop-key

443 by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0
1
# IVLE
2
# Copyright (C) 2007-2008 The University of Melbourne
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18
# App: Forum
19
# Author: David Coles
20
# Date: 12/02/2008
21
22
# This is an IVLE application.
23
# A SMF forum application for IVLE.
24
25
from common import util
26
from common import interpret
27
from os import path
28
import os
29
import urlparse
30
import re
31
32
def handle(req):
33
    """
34
    Handler for the Forum application.
35
    
36
    This application implements a general purpose PHP CGI loader
37
    """
38
    
39
    # Settings
493 by dcoles
session.php: More interfaceing between IVLE and phpBB. Adds groups, emails and
40
443 by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0
41
    forum_base = "php/phpBB3"
493 by dcoles
session.php: More interfaceing between IVLE and phpBB. Adds groups, emails and
42
    #forum_base = "/phpBB3"
443 by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0
43
44
    # Set request attributes
45
46
    # These files don't really exist - just a test of our linking
47
    # capabilities
48
    #req.styles = ["media/dummy/dummy.css"]
49
    #req.scripts = ["media/dummy/dummy.js", "media/dummy/hello.js"]
50
    
51
    # Process URL for special directives
52
    url = urlparse.urlparse(req.path)
53
    hierarchical_part = url[2]
54
55
    forum_page = "" # use the default forum page
56
    framequery = "?"
57
58
    board = re.match('board/(.*?)(/|$)',hierarchical_part)
59
    if board:
60
        framequery += 'f=' + board.group(1) + "&"
61
        forum_page = "viewforum.php"
62
63
    topic = re.search('topic/(.*?)(/|$)',hierarchical_part)
64
    if topic:
65
        framequery += 't=' + topic.group(1)
66
        forum_page = "viewtopic.php"
67
68
    
69
    #req.write(framequery + '\n')
70
71
    # If the tail of the forum url is empty or a known special request
72
    # then wrap the page in the headers and footer and load the default or
73
    # special page in the ivlebody frame
74
    location = req.path
75
    if board or topic:
76
        location = forum_page + framequery
77
    
78
    frameurl = util.make_path(path.join(forum_base,location))
79
    req.content_type = "text/html"
80
    req.write_html_head_foot = True
81
    req.write('<object' +
524 by dcoles
forum: Changed setup to just copy the phpBB directory (probbaly can be made
82
              ' id="forumwindow"' +
83
              ' style="top:0;width:100%;height:100%;position:absolute"' +
443 by dcoles
Added Forum application along with unmodifed version of phpBB3 "Olympus" 3.0.0
84
              ' type="text/html"' +
85
              ' data="' + frameurl + framequery + '"' +
86
              '/>\n'
87
    )
88
    # Otherwise serve the page without the wrapper
89
    #else:
90
    #    req.write(req.path)
91
    #    req.throw_error(req.HTTP_BAD_REQUEST)
92
93
94
95
        # Let the Server determine the MIME type
96
    #    req.content_type = ""
97
98
        # Don't write header or footer - we can't tell if it's HTML or 
99
        # something else like an image
100
    #    req.write_html_head_foot = False
101
102
        # Do some basic dispatch, if it ends in .php interpret with php-cgi
103
    #    if re.search('\.php$',hierarchical_part,re.IGNORECASE):
104
    #        interpret.execute_cgi(
105
    #            ['/usr/bin/php5-cgi'],
106
    #            forum_base,
107
    #            req
108
    #        )
109
        # Otherwise just ship the file directly
110
    #    else:
111
            #req.content_type = "application/x-httpd-php"
112
    #        file_path = os.path.join(forum_base, req.path)
113
    #        if os.access(file_path,os.R_OK):
114
    #            req.sendfile(path.join(forum_base, req.path))
115
            # If we can't read the file, throw HTTP Error
116
    #        else:
117
    #            req.throw_error(req.HTTP_BAD_REQUEST)
118