root/trunk/redirectors/preview.php

Revision 291, 3.7 kB (checked in by hannes, 3 years ago)

establishing a global warnings array to store and display (choke) warnings

Line 
1 <?php
2
3 /**
4  * Package: Spam Board 5
5  * File: redirectors/preview.php
6  * Description: Preview of a post before saving it to the database
7  *
8  * Copyright (C) 2007, 2009 Hannes Schueller
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU Affero General Public License as
12  * published by the Free Software Foundation, version 3 of the
13  * License.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Affero General Public License for more details.
19  *
20  * You should have received a copy of the GNU Affero General Public License
21  * along with this program (see LICENCE). If not,
22  * see <http://www.gnu.org/licenses/>.
23  **/
24
25 // called independently from index
26 require_once('../includes/config/settings.php');
27
28 // load classes on demand
29 function __autoload($class) {
30     global $SETTINGS;
31     if (is_file($SETTINGS['fspath'] . 'classes/pages/' . $class . '.php')) {
32         require_once($SETTINGS['fspath'] . 'classes/pages/' . $class . '.php');
33     } elseif (is_file($SETTINGS['fspath'] . 'classes/misc/' . $class . '.php')) {
34         require_once($SETTINGS['fspath'] . 'classes/misc/' . $class . '.php');
35     } else { die('Class ' . $class . ' not found.'); }
36 }
37
38 // initialize global warnings array
39 $WARNINGS = Array();
40
41 // import version number
42 require_once($SETTINGS['fspath'] . 'includes/config/version.php');
43 // bots definition
44 require_once($SETTINGS['fspath'] . 'includes/config/bots.php');
45 // formatting object
46 $F = new Format();
47 require($SETTINGS['fspath'] . 'includes/lang/' . $SETTINGS['language'] . '.php');
48 // open database connection
49 $C = new Connection();
50 Member::session();
51 if (isset($_SESSION['lang']) && $_SESSION['lang'] != '') {
52     include($SETTINGS['fspath'] . 'includes/lang/' . $_SESSION['lang'] . '.php');
53 }
54 // translate passed variables to local identifiers
55 require($SETTINGS['fspath'] . 'includes/input.php');
56
57 // page start
58 $_pref = '../';
59 $html = Page::start();
60
61 // check if user has permission; required: read; independent from id
62 if (Member::checkRights('Preview', 'r')) {
63     // permission granted
64     // header
65     $html->body->addChild('h2', $LANG['Preview']);
66     $INPUT['user'] = base64_decode(strtr($INPUT['user'], '-_', '+/'));
67     if (isset($INPUT['user']) && $INPUT['user'] != '') {
68         // manual authentication
69         // get user info
70         $q = $C->prepare('SELECT memberid, membername AS poster FROM sb_members WHERE membername=:user');
71         $q->bindParam(':user', $INPUT['user'], PDO::PARAM_STR);
72         $s = $q->execute();
73         if ($s && $row = $q->fetchObject()) {
74             // valid member
75             $row->postedbymember = $row->memberid;
76         } else {
77             // guest
78             $row->poster = $INPUT['user'];
79             $row->postedbymember = 0;
80         }
81         $q = NULL;
82     } else {
83         // logged in
84         $row = new stdClass();
85         $row->poster = $_SESSION['membername'];
86         $row->postedbymember = 1;
87     }
88     // decode post
89     $row->post = $F->htmlentities(base64_decode(strtr($INPUT['post'], '-_', '+/')), TRUE);
90     $row->postid = 0;
91     // construct and format timestamp
92     $_now = new DateTime('now', new DateTimeZone('UTC'));
93     $row->posttime = $_now->format('Y-m-d H:i:s');
94     // display post as it would look with all the above information
95     $table = new Table();
96     $p = new Post();
97     $p->setPost($row);
98     $p->add($table);
99     $html->body->addElement($table->get());
100     // link to close pop up
101     $div = $html->body->addChild('div');
102     $div->addAttribute('align', 'center');
103     $a = $div->addChild('a', $LANG['Close_Window']);
104     $a->addAttribute('href', 'javascript:self.close()');
105 } else {
106     // permission denied
107     $div = $html->body->addChild('div', $LANG['error_permission_denied']);
108     $div->addAttribute('class', 'message');
109 }
110
111 // page output
112 Page::send($html);
113
114 ?>
Note: See TracBrowser for help on using the browser.