Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 958 lines (822 sloc) 36.869 kb
4775e82 # more line-ending properties
ts77 authored
1 <?php
2
3 ////////////////////////////////////////////////////////////////////////////////
4 // //
0ceef25 # Updated copyright notices to 2006
mmakaay authored
5 // Copyright (C) 2006 Phorum Development Team //
4775e82 # more line-ending properties
ts77 authored
6 // http://www.phorum.org //
7 // //
8 // This program is free software. You can redistribute it and/or modify //
9 // it under the terms of either the current Phorum License (viewable at //
10 // phorum.org) or the Phorum License that was distributed with this file //
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. //
15 // //
16 // You should have received a copy of the Phorum License //
17 // along with this program. //
18 ////////////////////////////////////////////////////////////////////////////////
19
20 // Check that this file is not loaded directly.
21 if ( basename( __FILE__ ) == basename( $_SERVER["PHP_SELF"] ) ) exit();
22
23 // all other constants in ./include/constants.php
a2b66d1 # bumping dev version on trunk
brian authored
24 define( "PHORUM", "5.2-dev" );
4775e82 # more line-ending properties
ts77 authored
25
26 // our internal version in format of year-month-day-serial
0c4d577 MFB: added index for user_id, rarely used, i.e. for user-deletion (thx t...
ts77 authored
27 define( "PHORUMINTERNAL", "2006032300" );
4775e82 # more line-ending properties
ts77 authored
28
29 define( "DEBUG", 0 );
30
31 include_once( "./include/constants.php" );
32
33 // setup the PHORUM var
34 $PHORUM = array();
35
36 // temp member to hold arrays and such in templates
37 $PHORUM["TMP"] = array();
38
39 // The data member is the data the templates can access
40 $PHORUM["DATA"] = array();
41 $PHORUM["DATA"]["GET_VARS"] = array();
42 $PHORUM["DATA"]["POST_VARS"] = "";
43
44 // get the forum id if set with a post
45 if ( isset( $_REQUEST["forum_id"] ) && is_numeric( $_REQUEST["forum_id"] ) ) {
46 $PHORUM["forum_id"] = $_REQUEST["forum_id"];
47 }
48
49 // strip the slashes off of POST data if magic_quotes is on
50 if ( get_magic_quotes_gpc() && count( $_REQUEST ) ) {
51 foreach( $_POST as $key => $value ) {
52 if ( !is_array( $value ) )
53 $_POST[$key] = stripslashes( $value );
54 else
55 $_POST[$key] = phorum_recursive_stripslashes( $value );
56 }
57 foreach( $_GET as $key => $value ) {
58 if ( !is_array( $value ) )
59 $_GET[$key] = stripslashes( $value );
60 else
61 $_GET[$key] = phorum_recursive_stripslashes( $value );
62 }
63 }
64
65 // look for and parse the QUERY_STRING
66 // this only applies to urls that we create.
67 // scrips using urls from forms (search) should use $_GET or $_POST
68 if ( !defined( "PHORUM_ADMIN" ) ) {
69 if ( isset( $_SERVER["QUERY_STRING"] ) || isset( $PHORUM["CUSTOM_QUERY_STRING"] ) ) {
70 $Q_STR = empty( $GLOBALS["PHORUM_CUSTOM_QUERY_STRING"] ) ? $_SERVER["QUERY_STRING"]: $GLOBALS["PHORUM_CUSTOM_QUERY_STRING"];
71
72 // ignore stuff past a #
73 if ( strstr( $Q_STR, "#" ) ) list( $Q_STR, $other ) = explode( "#", $Q_STR );
74
75 // explode it on comma
76 $PHORUM["args"] = explode( ",", $Q_STR );
77
78 // check for any assigned values
79 if ( strstr( $Q_STR, "=" ) ) {
80 foreach( $PHORUM["args"] as $key => $arg ) {
81
82 // if an arg has an = create an element in args
83 // with left part as key and right part as value
84 if ( strstr( $arg, "=" ) ) {
85 list( $var, $value ) = explode( "=", $arg );
86 $PHORUM["args"][$var] = urldecode( $value );
87 // get rid of the numbered arg, it is useless.
88 unset( $PHORUM["args"][$key] );
89 }
90 }
91 }
92
93 // set forum_id if not set already by
94 if ( empty( $PHORUM["forum_id"] ) && isset( $PHORUM["args"][0] ) ) {
95 $PHORUM["forum_id"] = ( int )$PHORUM["args"][0];
96 }
97 }
98 }
99
100 // set the forum_id to 0 if not set by now.
101 if ( empty( $PHORUM["forum_id"] ) ) $PHORUM["forum_id"] = 0;
102
115e527 # Give Phorum owners a bit more guidance when db/config.php cannot be re...
mmakaay authored
103 // Get the database settings.
4775e82 # more line-ending properties
ts77 authored
104 if ( empty( $GLOBALS["PHORUM_ALT_DBCONFIG"] ) || $GLOBALS["PHORUM_ALT_DBCONFIG"]==$_REQUEST["PHORUM_ALT_DBCONFIG"] || !defined("PHORUM_WRAPPER") ) {
115e527 # Give Phorum owners a bit more guidance when db/config.php cannot be re...
mmakaay authored
105 // Backup display_errors setting.
106 $orig = ini_get("display_errors");
72edf94 MFB: # Suppress error output in case ini_set is disabled for PHP
mmakaay authored
107 @ini_set("display_errors", 0);
115e527 # Give Phorum owners a bit more guidance when db/config.php cannot be re...
mmakaay authored
108
109 // Load configuration.
81b7c74 # upgrade scripts for fixes to #156
ts77 authored
110 if (! include_once( "./include/db/config.php" )) {
115e527 # Give Phorum owners a bit more guidance when db/config.php cannot be re...
mmakaay authored
111 print '<html><head><title>Phorum error</title></head><body>';
112 print '<h2>Phorum database configuration error</h2>';
113
114 // No database configuration found.
115 if (!file_exists("./include/db/config.php")) { ?>
116 Phorum has been installed on this server, but the configuration<br/>
117 for the database connection has not yet been made. Please read<br/>
118 <a href="docs/install.txt">docs/install.txt</a> for installation instructions. <?php
81b7c74 # upgrade scripts for fixes to #156
ts77 authored
119 } else {
115e527 # Give Phorum owners a bit more guidance when db/config.php cannot be re...
mmakaay authored
120 $fp = fopen("./include/db/config.php", "r");
121 // Unable to read the configuration file.
122 if (!$fp) { ?>
123 A database configuration file was found in ./include/db/config.php,<br/>
124 but Phorum was unable to read it. Please check the file permissions<br/>
125 for this file. <?php
126 // Unknown error.
81b7c74 # upgrade scripts for fixes to #156
ts77 authored
127 } else {
115e527 # Give Phorum owners a bit more guidance when db/config.php cannot be re...
mmakaay authored
128 fclose($fp); ?>
129 A database configuration file was found in ./include/dbconfig.php,<br/>
130 but it could not be loaded. It possibly contains one or more errors.<br/>
131 Please check your configuration file. <?php
132 }
81b7c74 # upgrade scripts for fixes to #156
ts77 authored
133 }
115e527 # Give Phorum owners a bit more guidance when db/config.php cannot be re...
mmakaay authored
134
135 print '</body></html>';
136 exit(1);
137 }
138
139 // Restore original display_errors setting.
72edf94 MFB: # Suppress error output in case ini_set is disabled for PHP
mmakaay authored
140 @ini_set("display_errors", $orig);
4775e82 # more line-ending properties
ts77 authored
141 } else {
142 $PHORUM["DBCONFIG"] = $GLOBALS["PHORUM_ALT_DBCONFIG"];
143 }
144
115e527 # Give Phorum owners a bit more guidance when db/config.php cannot be re...
mmakaay authored
145 // Load the database layer.
4775e82 # more line-ending properties
ts77 authored
146 include_once( "./include/db/{$PHORUM['DBCONFIG']['type']}.php" );
147
148 if(!phorum_db_check_connection()){
149 if(isset($PHORUM["DBCONFIG"]["down_page"])){
150 header("Location: ".$PHORUM["DBCONFIG"]["down_page"]);
151 exit();
152 } else {
37c8617 # Message in case of a database failure wasn't good
mmakaay authored
153 echo "The database connection failed. Please check your database configuration in include/db/config.php. If the configuration is okay, check if the database server is running.";
4775e82 # more line-ending properties
ts77 authored
154 exit();
155 }
156 }
157
158 // get the Phorum settings
159 phorum_db_load_settings();
160
febd033 # Some fixes for the recent feed and caching changes.
mmakaay authored
161 // Defaults for missing settings (these can be needed after upgrading, in
162 // case the admin did not yet save a newly added Phorum setting).
163 if (! isset($PHORUM["default_feed"])) $PHORUM["default_feed"] = "rss";
164
352c4b3 MFB: Added a simple general purpose private key based signature system
mmakaay authored
165 // If we have no private key for signing data, generate one now.
166 if (! isset($PHORUM["private_key"]) || empty($PHORUM["private_key"])) {
167 $chars = "0123456789!@#$%&abcdefghijklmnopqr".
168 "stuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
169 $private_key = "";
170 for ($i = 0; $i<40; $i++) {
171 $private_key .= substr($chars, rand(0, strlen($chars)-1), 1);
172 }
173 $PHORUM["private_key"] = $private_key;
174 phorum_db_update_settings(array("private_key" => $PHORUM["private_key"]));
175 }
176
4775e82 # more line-ending properties
ts77 authored
177 // a hook for rewriting vars at the beginning of common.php,
178 //right after loading the settings from the database
179 phorum_hook( "common_pre", "" );
180
febd033 # Some fixes for the recent feed and caching changes.
mmakaay authored
181 //include_once( "./include/cache.php" );
4908808 # more template changes. added feed.php script.
brian authored
182 include_once( "./include/cache_memcached.php" );
4775e82 # more line-ending properties
ts77 authored
183
184 // stick some stuff from the settings into the DATA member
185 $PHORUM["DATA"]["TITLE"] = ( isset( $PHORUM["title"] ) ) ? $PHORUM["title"] : "";
1620d74 # beginning of template rewrite. Includes changes to core
brian authored
186 $PHORUM["DATA"]["DESCRIPTION"] = ( isset( $PHORUM["description"] ) ) ? $PHORUM["description"] : "";
4775e82 # more line-ending properties
ts77 authored
187 $PHORUM["DATA"]["HTML_TITLE"] = ( !empty( $PHORUM["html_title"] ) ) ? $PHORUM["html_title"] : $PHORUM["DATA"]["TITLE"];
188 $PHORUM["DATA"]["HEAD_TAGS"] = ( isset( $PHORUM["head_tags"] ) ) ? $PHORUM["head_tags"] : "";
1620d74 # beginning of template rewrite. Includes changes to core
brian authored
189 $PHORUM["DATA"]["LOCALE"] = ( isset( $PHORUM["locale"] ) ) ? $PHORUM["locale"] : "";
3302bcb Private Messages are now separate from the Control Center.
brian authored
190 $PHORUM["DATA"]["FORUM_ID"] = $PHORUM["forum_id"];
4775e82 # more line-ending properties
ts77 authored
191
192 ////////////////////////////////////////////////////////////
193 // only do this stuff if we are not in the admin
194
195 if ( !defined( "PHORUM_ADMIN" ) ) {
196
197 // if the Phorum is disabled, display a message.
198 if(isset($PHORUM["status"]) && $PHORUM["status"]=="disabled"){
199 if(!empty($PHORUM["disabled_url"])){
200 header("Location: ".$PHORUM["disabled_url"]);
201 exit();
202 } else {
567d095 # Prevent permission conflicts on compiled settings.tpl for external scr...
mmakaay authored
203 echo "This Phorum is currently disabled. Please contact the web site owner at ".$PHORUM['system_email_from_address']." for more information.\n";
4775e82 # more line-ending properties
ts77 authored
204 exit();
205 }
206 }
207
208 // checking for upgrade or new install
209 if ( !isset( $PHORUM['internal_version'] ) ) {
115e527 # Give Phorum owners a bit more guidance when db/config.php cannot be re...
mmakaay authored
210 echo "<html><head><title>Phorum error</title></head><body>No Phorum settings were found. Either this is a brand new installation of Phorum or there is an error with your database server. If this is a new install, please <a href=\"admin.php\">go to the admin page</a> to complete the installation. If not, check your database server.</body></html>";
4775e82 # more line-ending properties
ts77 authored
211 exit();
212 } elseif ( $PHORUM['internal_version'] < PHORUMINTERNAL ) {
213 echo "<html><head><title>Error</title></head><body>Looks like you have installed a new version. Go to the admin to complete the upgrade!</body></html>";
214 exit();
215 }
216
217 // load the forum's settings
218 if ( !empty( $PHORUM["forum_id"] ) ) {
219 $forum_settings = phorum_db_get_forums( $PHORUM["forum_id"] );
220 if ( empty( $forum_settings[$PHORUM["forum_id"]] ) ) {
08b2f83 # added another hook common_no_forum
ts77 authored
221 phorum_hook( "common_no_forum", "" );
4775e82 # more line-ending properties
ts77 authored
222 phorum_redirect_by_url( phorum_get_url( PHORUM_INDEX_URL ) );
223 exit();
224 }
225 $PHORUM = array_merge( $PHORUM, $forum_settings[$PHORUM["forum_id"]] );
226 } else {
227 // some defaults we might need if no forum is set (i.e. on the index-page)
228 $PHORUM['vroot']=0;
229 $PHORUM['parent_id']=0;
230 $PHORUM['active']=1;
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
231 $PHORUM['folder_flag']=1;
0a6aa47 MFB: sanitizing rss-url
ts77 authored
232 $PHORUM["template"] = $PHORUM["default_template"];
4775e82 # more line-ending properties
ts77 authored
233 }
234
235 // stick some stuff from the settings into the DATA member
236 $PHORUM["DATA"]["NAME"] = ( isset( $PHORUM["name"] ) ) ? $PHORUM["name"] : "";
28f3067 # more template related changes for 5.2
brian authored
237 $PHORUM["DATA"]["DESCRIPTION"] = ( isset( $PHORUM["description"] ) ) ? strip_tags( preg_replace("!\s+!", " ", $PHORUM["description"]) ) : "";
4775e82 # more line-ending properties
ts77 authored
238 $PHORUM["DATA"]["ENABLE_PM"] = ( isset( $PHORUM["enable_pm"] ) ) ? $PHORUM["enable_pm"] : "";
239 if ( !empty( $PHORUM["DATA"]["HTML_TITLE"] ) && !empty( $PHORUM["DATA"]["NAME"] ) ) {
240 $PHORUM["DATA"]["HTML_TITLE"] .= PHORUM_SEPARATOR;
241 }
242 $PHORUM["DATA"]["HTML_TITLE"] .= $PHORUM["DATA"]["NAME"];
243
244 // check the user session
245 include_once( "./include/users.php" );
246 if ( phorum_user_check_session() ) {
247 $PHORUM["DATA"]["LOGGEDIN"] = true;
ba5300d New security feature! Users must confirm their login before posting or ...
brian authored
248
b1d9b7c # new session code to hopefully solve problems in tickets #134 and #135
brian authored
249 if(!$PHORUM["tight_security"] || phorum_user_check_session( PHORUM_SESSION_SHORT_TERM )){
ba5300d New security feature! Users must confirm their login before posting or ...
brian authored
250 $PHORUM["DATA"]["FULLY_LOGGEDIN"] = true;
251 } else {
252 $PHORUM["DATA"]["FULLY_LOGGEDIN"] = false;
253 }
254
4775e82 # more line-ending properties
ts77 authored
255 // if the user has overridden thread settings, change it here.
256 if ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) {
257 if ( $PHORUM["user"]["threaded_list"] == PHORUM_THREADED_ON ) {
258 $PHORUM["threaded_list"] = true;
259 } elseif ( $PHORUM["user"]["threaded_list"] == PHORUM_THREADED_OFF ) {
260 $PHORUM["threaded_list"] = false;
261 }
262 if ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_ON ) {
263 $PHORUM["threaded_read"] = true;
264 } elseif ( $PHORUM["user"]["threaded_read"] == PHORUM_THREADED_OFF ) {
265 $PHORUM["threaded_read"] = false;
266 }
267 }
268 }
269
270 // set up the blank user if not logged in
271 if ( empty( $PHORUM["user"] ) ) {
272 $PHORUM["user"] = array( "user_id" => 0, "username" => "", "admin" => false, "newinfo" => array() );
273 $PHORUM["DATA"]["LOGGEDIN"] = false;
274 }
275
276
277 // a hook for rewriting vars in common.php after loading the user
278 phorum_hook( "common_post_user", "" );
279
280
281 // set up the template
282
283 // check for a template being passed on the url
5c87d60 # Prevent the use of illegal template paths from the URL.
mmakaay authored
284 // only use valid template names
4775e82 # more line-ending properties
ts77 authored
285 if ( !empty( $PHORUM["args"]["template"] ) ) {
5c87d60 # Prevent the use of illegal template paths from the URL.
mmakaay authored
286 $template = basename( $PHORUM["args"]["template"] );
43c4da7 # Fallback to default template if user_template does not exist (anymore)
mmakaay authored
287 if ($template != '..') {
5c87d60 # Prevent the use of illegal template paths from the URL.
mmakaay authored
288 $PHORUM["template"] = $template;
289 }
4775e82 # more line-ending properties
ts77 authored
290 }
291
292 // user output buffering so we don't get header errors
567d095 # Prevent permission conflicts on compiled settings.tpl for external scr...
mmakaay authored
293 // not loaded if we are running an external or scheduled script
294 if (! defined('PHORUM_SCRIPT')) {
295 ob_start();
296 include_once( phorum_get_template( "settings" ) );
1620d74 # beginning of template rewrite. Includes changes to core
brian authored
297 $PHORUM["DATA"]["TEMPLATE"] = $PHORUM['template'];
567d095 # Prevent permission conflicts on compiled settings.tpl for external scr...
mmakaay authored
298 ob_end_clean();
299 }
4775e82 # more line-ending properties
ts77 authored
300
301 // get the language file
302 if ( ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) && isset( $PHORUM['user']['user_language'] ) && !empty($PHORUM['user']['user_language']) )
303 $PHORUM['language'] = $PHORUM['user']['user_language'];
304
305 if ( !isset( $PHORUM["language"] ) || empty( $PHORUM["language"] ) || !file_exists( "./include/lang/$PHORUM[language].php" ) )
306 $PHORUM["language"] = $PHORUM["default_language"];
307
308 if ( file_exists( "./include/lang/$PHORUM[language].php" ) ) {
309 include_once( "./include/lang/$PHORUM[language].php" );
310 }
311 // load languages for localized modules
b6560f6 "# fixing some php5-related errors"
ts77 authored
312 if ( isset( $PHORUM["hooks"]["lang"] ) && is_array($PHORUM["hooks"]["lang"]) ) {
4775e82 # more line-ending properties
ts77 authored
313 foreach( $PHORUM["hooks"]["lang"]["mods"] as $mod ) {
314 // load mods for this hook
315 if ( file_exists( "./mods/$mod/lang/$PHORUM[language].php" ) ) {
316 include_once "./mods/$mod/lang/$PHORUM[language].php";
317 }
318 elseif ( file_exists( "./mods/$mod/lang/english.php" ) ) {
319 include_once "./mods/$mod/lang/english.php";
320 }
321 }
322 }
323
b080ff0 added newflag caching
ts77 authored
324
325 // just setting this up for upgraded installs where this might not be set up
326 if(!isset($PHORUM['cache_newflags'])) {
327 $PHORUM['cache_newflags'] = 0;
328 }
329
330 if(!isset($PHORUM['cache_messages'])) {
331 $PHORUM['cache_messages'] = 0;
332 }
333
cc1e271 # Fixed escaping problems for HTML_TITLE and NAME members in $PHORUM["DA...
mmakaay authored
334 // HTML titles can't contain HTML code, so we strip HTML tags
335 // and HTML escape the title.
1620d74 # beginning of template rewrite. Includes changes to core
brian authored
336 $PHORUM["DATA"]["HTML_TITLE"] = htmlentities(strip_tags($PHORUM["DATA"]["HTML_TITLE"]), ENT_COMPAT, $PHORUM["DATA"]["CHARSET"]);
cc1e271 # Fixed escaping problems for HTML_TITLE and NAME members in $PHORUM["DA...
mmakaay authored
337
4775e82 # more line-ending properties
ts77 authored
338 // if the Phorum is disabled, display a message.
339 if(isset($PHORUM["status"]) && $PHORUM["status"]=="admin-only" && !$PHORUM["user"]["admin"]){
340 // set all our URL's
341 phorum_build_common_urls();
342
343 $PHORUM["DATA"]["MESSAGE"]=$PHORUM["DATA"]["LANG"]["AdminOnlyMessage"];
344 include phorum_get_template("header");
345 phorum_hook("after_header");
346 include phorum_get_template("message");
347 phorum_hook("before_footer");
348 include phorum_get_template("footer");
349 exit();
350
351 }
352
f2735f3 # Added new template settings.tpl define 'show_notify_for_pages'.
mmakaay authored
353 // If moderator notifications are on and the person is a mod,
354 // lets find out if anything is new.
355
356 $PHORUM["user"]["NOTICE"]["MESSAGES"] = false;
357 $PHORUM["user"]["NOTICE"]["USERS"] = false;
358 $PHORUM["user"]["NOTICE"]["GROUPS"] = false;
359
360 if ( $PHORUM["DATA"]["LOGGEDIN"] ) {
361
362 // By default, only bug the user on the list, index and cc pages.
363 // The template can override this behaviour by setting a comma
364 // separated list of phorum_page names in a template define statement
365 // like this: {DEFINE show_notify_for_pages "page 1,page 2,..,page n"}
366 if (isset($PHORUM["TMP"]["show_notify_for_pages"])) {
367 $show_notify_for_pages = explode(",", $PHORUM["TMP"]["show_notify_for_pages"]);
368 } else {
369 $show_notify_for_pages = array('index','list','cc');
370 }
371
372 if ( in_array(phorum_page, $show_notify_for_pages) ) {
373
374 if ( $PHORUM["enable_moderator_notifications"] ) {
375 $forummodlist = phorum_user_access_list( PHORUM_USER_ALLOW_MODERATE_MESSAGES );
376 if ( count( $forummodlist ) > 0 ) {
377 $PHORUM["user"]["NOTICE"]["MESSAGES"] = ( count( phorum_db_get_unapproved_list( $forummodlist, true ) ) > 0 );
378 $PHORUM["DATA"]["URL"]["NOTICE"]["MESSAGES"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_UNAPPROVED );
379 }
380 if ( phorum_user_access_allowed( PHORUM_USER_ALLOW_MODERATE_USERS ) ) {
381 $PHORUM["user"]["NOTICE"]["USERS"] = ( count( phorum_db_user_get_unapproved() ) > 0 );
382 $PHORUM["DATA"]["URL"]["NOTICE"]["USERS"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_USERS );
383 }
384 if ( phorum_user_allow_moderate_group() ) {
385 $groups = phorum_user_get_moderator_groups();
386 if ( count( $groups ) > 0 ) {
387 $PHORUM["user"]["NOTICE"]["GROUPS"] = count( phorum_db_get_group_members( array_keys( $groups ), PHORUM_USER_GROUP_UNAPPROVED ) );
388 $PHORUM["DATA"]["URL"]["NOTICE"]["GROUPS"] = phorum_get_url( PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_GROUP_MODERATION );
389 }
390 }
391 }
0a6aa47 MFB: sanitizing rss-url
ts77 authored
392
f2735f3 # Added new template settings.tpl define 'show_notify_for_pages'.
mmakaay authored
393 $PHORUM["user"]["NOTICE"]["SHOW"] = $PHORUM["user"]["NOTICE"]["MESSAGES"] || $PHORUM["user"]["NOTICE"]["USERS"] || $PHORUM["user"]["NOTICE"]["GROUPS"];
394 }
0a6aa47 MFB: sanitizing rss-url
ts77 authored
395 }
4775e82 # more line-ending properties
ts77 authored
396
397 // a hook for rewriting vars at the end of common.php
398 phorum_hook( "common", "" );
399
1620d74 # beginning of template rewrite. Includes changes to core
brian authored
400 $PHORUM['DATA']['USER'] = $PHORUM['user'];
84abc50 # Added some useful variables to the template data
mmakaay authored
401 $PHORUM['DATA']['PHORUM_PAGE'] = phorum_page;
402 $PHORUM['DATA']['USERTRACK'] = $PHORUM['track_user_activity'];
4775e82 # more line-ending properties
ts77 authored
403 }
404
405
406 //////////////////////////////////////////////////////////
407 // functions
408
409 /**
410 * A common function to check that a user is logged in
411 */
412 function phorum_require_login()
413 {
414 $PHORUM = $GLOBALS['PHORUM'];
415 if ( !$PHORUM["user"]["user_id"] ) {
416 $url = phorum_get_url( PHORUM_LOGIN_URL, "redir=" . urlencode( $PHORUM["http_path"] . "/" . basename( $_SERVER["PHP_SELF"] ) . "?" . $_SERVER["QUERY_STRING"] ) );
417 phorum_redirect_by_url( $url );
418 exit();
419 }
420 }
421
422 /**
423 * A common function for checking the read-permissions for a forum-page
424 * returns false if access is not allowed and an error page-was output
425 */
426 function phorum_check_read_common()
427 {
428 $PHORUM = $GLOBALS['PHORUM'];
429
430 $retval = true;
431
432 if ( $PHORUM["forum_id"] > 0 && !$PHORUM["folder_flag"] && !phorum_user_access_allowed( PHORUM_USER_ALLOW_READ ) ) {
433 if ( $PHORUM["DATA"]["LOGGEDIN"] ) {
434 // if they are logged in and not allowed, they don't have rights
1b2e550 # change MESSAGE to OKMSG where it had not already been done
brian authored
435 $PHORUM["DATA"]["OKMSG"] = $PHORUM["DATA"]["LANG"]["NoRead"];
4775e82 # more line-ending properties
ts77 authored
436 } else {
437 // check if they could read if logged in.
438 // if so, let them know to log in.
439 if ( ( empty( $PHORUM["DATA"]["POST"]["parentid"] ) && $PHORUM["reg_perms"] &PHORUM_USER_ALLOW_READ ) ) {
1b2e550 # change MESSAGE to OKMSG where it had not already been done
brian authored
440 $PHORUM["DATA"]["OKMSG"] = $PHORUM["DATA"]["LANG"]["PleaseLoginRead"];
4775e82 # more line-ending properties
ts77 authored
441 } else {
1b2e550 # change MESSAGE to OKMSG where it had not already been done
brian authored
442 $PHORUM["DATA"]["OKMSG"] = $PHORUM["DATA"]["LANG"]["NoRead"];
4775e82 # more line-ending properties
ts77 authored
443 }
444 }
445
446 phorum_build_common_urls();
447
448 include phorum_get_template( "header" );
449 phorum_hook( "after_header" );
450 include phorum_get_template( "message" );
451 phorum_hook( "before_footer" );
452 include phorum_get_template( "footer" );
453
454 $retval = false;
455 }
456
457 return $retval;
458 }
459
460 // used for all url creation.
461 function phorum_get_url()
462 {
463 $PHORUM = $GLOBALS["PHORUM"];
464
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
465 $argv_array = func_get_args();
466 if (is_array($argv_array[0])) {
467 $return_array = true;
468 } else {
469 $return_array = false;
470 $argv_array = array($argv_array);
471 }
472
473 $url_array = array();
474
475 foreach ($argv_array as $argv)
476 {
477 $args = "";
478 $url = "";
479 $suffix = "";
480 $add_forum_id = false;
481 $add_get_vars = true;
482
483 $type = array_shift( $argv );
484
485 switch ( $type ) {
486 case PHORUM_LIST_URL:
487 $page = "list";
488 if ( empty( $argv ) ) $add_forum_id = true;
489 break;
490 case PHORUM_READ_URL:
4775e82 # more line-ending properties
ts77 authored
491 $page = "read";
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
492 $add_forum_id = true;
493 if ( !empty( $argv[1] ) && is_numeric( $argv[1] ) ) $suffix = "#msg-$argv[1]";
494 break;
495 case PHORUM_FOREIGN_READ_URL:
496 $page = "read";
497 if ( !empty( $argv[2] ) && is_numeric( $argv[2] ) ) $suffix = "#msg-$argv[2]";
498 break;
499 case PHORUM_REPLY_URL:
500 if(isset($PHORUM["reply_on_read_page"]) && $PHORUM["reply_on_read_page"]){
501 $page = "read";
502 $suffix = "#REPLY";
503 } else {
504 $page = "posting";
505 // For reply on a separate page, we call posting.php on its own.
506 // In that case argv[0] is the editor mode we want to use
507 // (reply in this case). Currently, the thread id is in argv[0],
508 // but we don't need that one for posting.php. So we simply
509 // replace argv[0] with the correct argument.
510 $argv[0] = "reply";
511 }
512 $add_forum_id = true;
513 break;
514 case PHORUM_POSTING_URL:
59aaefd # Reply on separate page used the old reply.php script, instead of posti...
mmakaay authored
515 $page = "posting";
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
516 $add_forum_id = true;
517 break;
518 case PHORUM_REDIRECT_URL:
519 $page = "redirect";
520 $add_forum_id = false;
521 break;
522 case PHORUM_SEARCH_URL:
523 $page = "search";
524 $add_forum_id = true;
525 break;
526 case PHORUM_SEARCH_ACTION_URL:
527 $page = "search";
528 $add_get_vars = true;
529 break;
530 case PHORUM_DOWN_URL:
531 $page = "down";
532 $add_forum_id = true;
533 break;
534 case PHORUM_VIOLATION_URL:
535 $page = "violation";
536 $add_forum_id = true;
537 break;
538 case PHORUM_INDEX_URL:
539 $page = "index";
540 break;
541 case PHORUM_LOGIN_URL:
542 $page = "login";
543 $add_forum_id = true;
544 break;
545 case PHORUM_LOGIN_ACTION_URL:
546 $page = "login";
547 break;
548 case PHORUM_REGISTER_URL:
549 $page = "register";
550 $add_forum_id = true;
551 break;
552 case PHORUM_REGISTER_ACTION_URL:
553 $page = "register";
554 break;
555 case PHORUM_PROFILE_URL:
556 $page = "profile";
557 $add_forum_id = true;
558 break;
559 case PHORUM_SUBSCRIBE_URL:
560 $page = "subscribe";
561 $add_forum_id = true;
562 break;
563 case PHORUM_MODERATION_URL:
564 $page = "moderation";
565 $add_forum_id = true;
566 break;
567 case PHORUM_MODERATION_ACTION_URL:
568 $page = "moderation";
569 $add_get_vars = false;
570 break;
571 case PHORUM_PREPOST_URL:
572 $page = "control";
573 $argv[] = "panel=messages";
574 $add_forum_id = true;
575 break;
576 case PHORUM_CONTROLCENTER_URL:
577 $page = "control";
578 $add_forum_id = true;
579 break;
580 case PHORUM_CONTROLCENTER_ACTION_URL:
581 $page = "control";
582 break;
583 case PHORUM_PM_URL:
584 $page = "pm";
585 $add_forum_id = true;
586 break;
587 case PHORUM_PM_ACTION_URL:
588 $page = "pm";
589 break;
590 case PHORUM_FILE_URL:
591 $page = "file";
592 $add_forum_id = true;
593 break;
594 case PHORUM_FOLLOW_URL:
595 $page = "follow";
596 $add_forum_id = true;
597 break;
598 case PHORUM_FOLLOW_ACTION_URL:
599 $page = "follow";
600 $add_forum_id = false;
601 break;
602 case PHORUM_REPORT_URL:
603 $page = "report";
604 $add_forum_id = true;
605 break;
4908808 # more template changes. added feed.php script.
brian authored
606 case PHORUM_FEED_URL:
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
607 switch(phorum_page){
608 case "list":
609 $add_forum_id = true;
610 break;
611 case "read":
612 $add_forum_id = true;
613 $thread_id = (int)$PHORUM["args"][1];
614 array_push($argv, $thread_id);
615 break;
616 }
4908808 # more template changes. added feed.php script.
brian authored
617 $page = "feed";
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
618 break;
619 // this is for adding own generic urls
620 case PHORUM_CUSTOM_URL:
621 $page = array_shift($argv); // first arg is our page
622 $add_forum_id_tmp=array_shift($argv); // second determining if we should add the forum_id
623 $add_forum_id = $add_forum_id_tmp?true:false;
624 break;
625
626 case PHORUM_BASE_URL:
627 // only to flag phorum_custom_get_url() that base url is requested
628 $page = '';
629 break;
630
631 default:
632 trigger_error( "Unhandled page type.", E_USER_WARNING );
633 break;
634 }
4775e82 # more line-ending properties
ts77 authored
635
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
636 // build the query string
637 $query_items = array();
4775e82 # more line-ending properties
ts77 authored
638
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
639 if ( $add_forum_id ) {
640 $query_items[] = ( int )$PHORUM["forum_id"];
641 }
4775e82 # more line-ending properties
ts77 authored
642
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
643 if ( count( $argv ) > 0 ) {
644 $query_items = array_merge( $query_items, $argv );
645 }
4775e82 # more line-ending properties
ts77 authored
646
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
647 if ( !empty( $PHORUM["DATA"]["GET_VARS"] ) && $add_get_vars ) {
648 $query_items = array_merge( $query_items, $PHORUM["DATA"]["GET_VARS"] );
649 }
650 // build the url
651 if ( !function_exists( "phorum_custom_get_url" ) ) {
652 if ($type == PHORUM_BASE_URL) return $PHORUM["http_path"] . '/';
d6acb35 # Added PHORUM_BASE_URL as a type for phorum_get_url()
mmakaay authored
653
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
654 $url = "$PHORUM[http_path]/$page." . PHORUM_FILE_EXTENSION;
4775e82 # more line-ending properties
ts77 authored
655
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
656 if ( count( $query_items ) ) $url .= "?" . implode( ",", $query_items );
4775e82 # more line-ending properties
ts77 authored
657
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
658 if ( !empty( $suffix ) ) $url .= $suffix;
659 } else {
660 $url = phorum_custom_get_url( $page, $query_items, $suffix );
661 }
662
663 $url_array[] = $url;
4775e82 # more line-ending properties
ts77 authored
664 }
665
646564a # Change for making batch processing possible in phorum_get_url()
mmakaay authored
666 return $return_array ? $url_array : $url_array[0];
4775e82 # more line-ending properties
ts77 authored
667 }
668
15fe7b7 Added a new function: phorum_get_template_file(), which is used for
mmakaay authored
669 /**
670 * Find out what input and output files to use for a template file.
0a6aa47 MFB: sanitizing rss-url
ts77 authored
671 *
15fe7b7 Added a new function: phorum_get_template_file(), which is used for
mmakaay authored
672 * @param $page - The template base name (e.g. "header", "css", etc.).
673 * @return $phpfile - The PHP file to include for the template base name.
674 * @return $tplfile - The file to use as template input. In case there's no
675 * .tpl file to pre-process, the value will be NULL.
0a6aa47 MFB: sanitizing rss-url
ts77 authored
676 * In that case, the $phpfile return value can be
15fe7b7 Added a new function: phorum_get_template_file(), which is used for
mmakaay authored
677 * included directly.
0a6aa47 MFB: sanitizing rss-url
ts77 authored
678 */
15fe7b7 Added a new function: phorum_get_template_file(), which is used for
mmakaay authored
679 function phorum_get_template_file( $page )
4775e82 # more line-ending properties
ts77 authored
680 {
681 $PHORUM = $GLOBALS["PHORUM"];
682
50279dd MFB: # Defend against relative path and \0 injection for template names.
mmakaay authored
683 $page = basename($page);
684
4775e82 # more line-ending properties
ts77 authored
685 if ( ( !isset( $PHORUM['display_fixed'] ) || !$PHORUM['display_fixed'] ) && isset( $PHORUM['user']['user_template'] ) && !empty($PHORUM['user']['user_template'])) {
686 $PHORUM['template'] = $PHORUM['user']['user_template'];
687 }
688
15fe7b7 Added a new function: phorum_get_template_file(), which is used for
mmakaay authored
689 // If no user template is set or if the template file cannot be found,
43c4da7 # Fallback to default template if user_template does not exist (anymore)
mmakaay authored
690 // fallback to the default template.
691 if (empty($PHORUM["template"]) || !file_exists("./templates/{$PHORUM['template']}")) {
4775e82 # more line-ending properties
ts77 authored
692 $PHORUM["template"] = $PHORUM["default_template"];
693 }
694
15fe7b7 Added a new function: phorum_get_template_file(), which is used for
mmakaay authored
695 $tplbase = "./templates/$PHORUM[template]/$page";
696
4775e82 # more line-ending properties
ts77 authored
697 // check for straight PHP file
15fe7b7 Added a new function: phorum_get_template_file(), which is used for
mmakaay authored
698 if ( file_exists( "$tplbase.php" ) ) {
699 return array("$tplbase.php", NULL);
700 // not there, look for a template
4775e82 # more line-ending properties
ts77 authored
701 } else {
15fe7b7 Added a new function: phorum_get_template_file(), which is used for
mmakaay authored
702 $tplfile = "$tplbase.tpl";
cfc2663 # Minus signs in template directories and files are now allowed
mmakaay authored
703 $safetemplate = str_replace("-", "_", $PHORUM["template"]);
704 $safepage = str_replace("-", "_", $page);
15fe7b7 Added a new function: phorum_get_template_file(), which is used for
mmakaay authored
705 $phpfile = "{$PHORUM["cache"]}/tpl-$safetemplate-$safepage-" .
706 md5(dirname(__FILE__)) . ".php";
4775e82 # more line-ending properties
ts77 authored
707
15fe7b7 Added a new function: phorum_get_template_file(), which is used for
mmakaay authored
708 return array($phpfile, $tplfile);
709 }
710 }
711
712 /**
713 * Returns the PHP file to include for a template file. This function will
714 * automatically compile .tpl files if no compiled template is available.
715 *
716 * @param $page - The template base name (e.g. "header", "css", etc.).
717 * @param $is_include - Whether the template is an include or not (deprecated).
718 * @return $phpfile - The PHP file to include for the template base name.
719 */
720 function phorum_get_template( $page )
721 {
722 list ($phpfile, $tplfile) = phorum_get_template_file($page);
723
724 // No template to pre-process.
725 if ($tplfile == NULL) return $phpfile;
726
727 // Pre-process template if the output file isn't available.
728 if (! file_exists($phpfile)) {
729 include_once "./include/templates.php";
730 phorum_import_template($page, $tplfile, $phpfile);
4775e82 # more line-ending properties
ts77 authored
731 }
732
733 return $phpfile;
734 }
735
736 // creates URLs used on most pages
737 function phorum_build_common_urls()
738 {
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
739 $PHORUM=$GLOBALS['PHORUM'];
740
1620d74 # beginning of template rewrite. Includes changes to core
brian authored
741 $GLOBALS["PHORUM"]["DATA"]["URL"]["BASE_URL"] = phorum_get_url( PHORUM_BASE_URL );
742
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
743 // those links are only needed in forums, not in folders
744 if(isset($PHORUM['folder_flag']) && !$PHORUM['folder_flag']) {
28f3067 # more template related changes for 5.2
brian authored
745 $GLOBALS["PHORUM"]["DATA"]["URL"]["LIST"] = phorum_get_url( PHORUM_LIST_URL );
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
746 $GLOBALS["PHORUM"]["DATA"]["URL"]["MARKREAD"] = phorum_get_url( PHORUM_LIST_URL, "markread=1" );
747 $GLOBALS["PHORUM"]["DATA"]["URL"]["POST"] = phorum_get_url( PHORUM_POSTING_URL );
748 $GLOBALS["PHORUM"]["DATA"]["URL"]["SUBSCRIBE"] = phorum_get_url( PHORUM_SUBSCRIBE_URL );
749 }
750
751 // those are general urls, needed nearly everywhere
4775e82 # more line-ending properties
ts77 authored
752 $GLOBALS["PHORUM"]["DATA"]["URL"]["SEARCH"] = phorum_get_url( PHORUM_SEARCH_URL );
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
753
754 // RSS-Url only makes sense on a couple of pages
b28f8f7 added a switch for using RSS and a link to the header for it
ts77 authored
755 if(isset($PHORUM['use_rss']) && $PHORUM['use_rss']
756 && (phorum_page=="index" || phorum_page=="list" || phorum_page=="read")){
febd033 # Some fixes for the recent feed and caching changes.
mmakaay authored
757 if($PHORUM["default_feed"]=="rss"){
4908808 # more template changes. added feed.php script.
brian authored
758 $GLOBALS["PHORUM"]["DATA"]["URL"]["FEED"] = phorum_get_url( PHORUM_FEED_URL, "type=rss" );
759 $GLOBALS["PHORUM"]["DATA"]["FEED"] = $PHORUM["DATA"]["LANG"]["RSS"];
760 } else {
761 $GLOBALS["PHORUM"]["DATA"]["URL"]["FEED"] = phorum_get_url( PHORUM_FEED_URL, "type=atom" );
762 $GLOBALS["PHORUM"]["DATA"]["FEED"] = $PHORUM["DATA"]["LANG"]["ATOM"];
763 }
4775e82 # more line-ending properties
ts77 authored
764 }
765
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
766 $index_id=-1;
767 // in a folder
4775e82 # more line-ending properties
ts77 authored
768
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
769 if( $PHORUM['folder_flag'] && phorum_page != 'index'
770 && ($PHORUM['forum_id'] == 0 || $PHORUM['vroot'] == $PHORUM['forum_id'])) {
771 // folder where we usually don't show the index-link but on
772 // additional pages like search and login its shown
773 $index_id=$PHORUM['forum_id'];
4775e82 # more line-ending properties
ts77 authored
774
670bc17 "fixing index-links + #220"
ts77 authored
775 } elseif( ( $PHORUM['folder_flag'] &&
776 ($PHORUM['forum_id'] != 0 && $PHORUM['vroot'] != $PHORUM['forum_id'])) ||
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
777 (!$PHORUM['folder_flag'] && $PHORUM['active'])) {
778 // either a folder where the link should be shown (not vroot or root)
779 // or an active forum where the link should be shown
4775e82 # more line-ending properties
ts77 authored
780
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
781 if(isset($PHORUM["use_new_folder_style"]) && $PHORUM["use_new_folder_style"] ) {
782 // go to root or vroot
783 $index_id=$PHORUM["vroot"]; // vroot is either 0 (root) or another id
4775e82 # more line-ending properties
ts77 authored
784
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
785 } else {
786 // go to parent
787 $index_id=$PHORUM["parent_id"]; // parent_id is always set now
4775e82 # more line-ending properties
ts77 authored
788
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
789 }
4775e82 # more line-ending properties
ts77 authored
790
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
791 }
792 if($index_id > -1) {
793 // check if its the full root, avoid adding an id in this case (SE-optimized ;))
794 if (!empty($index_id))
795 $GLOBALS["PHORUM"]["DATA"]["URL"]["INDEX"] = phorum_get_url( PHORUM_INDEX_URL, $index_id );
796 else
797 $GLOBALS["PHORUM"]["DATA"]["URL"]["INDEX"] = phorum_get_url( PHORUM_INDEX_URL );
798 }
4775e82 # more line-ending properties
ts77 authored
799
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
800 // these urls depend on the login-status of a user
4775e82 # more line-ending properties
ts77 authored
801 if ( $GLOBALS["PHORUM"]["DATA"]["LOGGEDIN"] ) {
802 $GLOBALS["PHORUM"]["DATA"]["URL"]["LOGINOUT"] = phorum_get_url( PHORUM_LOGIN_URL, "logout=1" );
803 $GLOBALS["PHORUM"]["DATA"]["URL"]["REGISTERPROFILE"] = phorum_get_url( PHORUM_CONTROLCENTER_URL );
3f75d93 streamlined index/messagelist/post-url creation should fix #199
ts77 authored
804 $GLOBALS["PHORUM"]["DATA"]["URL"]["PM"] = phorum_get_url( PHORUM_PM_URL );
4775e82 # more line-ending properties
ts77 authored
805 } else {
806 $GLOBALS["PHORUM"]["DATA"]["URL"]["LOGINOUT"] = phorum_get_url( PHORUM_LOGIN_URL );
807 $GLOBALS["PHORUM"]["DATA"]["URL"]["REGISTERPROFILE"] = phorum_get_url( PHORUM_REGISTER_URL );
808 }
809 }
810
811 // calls phorum mod functions
812 function phorum_hook( $hook, $arg = "" )
813 {
814 $PHORUM = $GLOBALS["PHORUM"];
815
b6560f6 "# fixing some php5-related errors"
ts77 authored
816 if ( isset( $PHORUM["hooks"][$hook] ) && is_array($PHORUM["hooks"][$hook])) {
817
4775e82 # more line-ending properties
ts77 authored
818 foreach( $PHORUM["hooks"][$hook]["mods"] as $mod ) {
819 // load mods for this hook
820 if ( file_exists( "./mods/$mod/$mod.php" ) ) {
821 include_once "./mods/$mod/$mod.php";
822 } elseif ( file_exists( "./mods/$mod.php" ) ) {
823 include_once "./mods/$mod.php";
824 }
825 }
826
827 foreach( $PHORUM["hooks"][$hook]["funcs"] as $func ) {
828 // call functions for this hook
829 if ( function_exists( $func ) ) {
830 $arg = call_user_func( $func, $arg );
831 }
832 }
833 }
834
835 return $arg;
836 }
837
838 // HTML encodes a string
839 function phorum_html_encode( $string )
840 {
841 $ret_string = "";
842 $len = strlen( $string );
843 for( $x = 0;$x < $len;$x++ ) {
844 $ord = ord( $string[$x] );
845 $ret_string .= "&#$ord;";
846 }
847 return $ret_string;
848 }
849
850 // removes slashes from all array-entries
851 function phorum_recursive_stripslashes( $array )
852 {
853 if ( !is_array( $array ) ) {
854 return $array;
855 } else {
856 foreach( $array as $key => $value ) {
857 if ( !is_array( $value ) )
858 $array[$key] = stripslashes( $value );
859 else
860 $array[$key] = phorum_recursive_stripslashes( $value );
861 }
862 }
863 return $array;
864 }
865
866 // returns the available templates as an array
867 function phorum_get_template_info()
868 {
869 $tpls = array();
870
871 $d = dir( "./templates" );
872 while ( false !== ( $entry = $d->read() ) ) {
cfc2663 # Minus signs in template directories and files are now allowed
mmakaay authored
873 if ( $entry != "." && $entry != ".." && file_exists( "./templates/$entry/info.php" ) ) {
4775e82 # more line-ending properties
ts77 authored
874 include "./templates/$entry/info.php";
875 if ( !isset( $template_hide ) || empty( $template_hide ) || defined( "PHORUM_ADMIN" ) ) {
876 $tpls[$entry] = "$name $version";
877 } else {
878 unset( $template_hide );
879 }
880 }
881 }
882
883 return $tpls;
884 }
885
886 // returns the available languages as an array
887 function phorum_get_language_info()
888 {
889 $langs = array();
890
891 $d = dir( "./include/lang" );
892 while ( false !== ( $entry = $d->read() ) ) {
893 if ( substr( $entry, -4 ) == ".php" && is_file( "./include/lang/$entry" ) ) {
894 @include "./include/lang/$entry";
895 if ( !isset( $language_hide ) || empty( $language_hide ) || defined( "PHORUM_ADMIN" ) ) {
896 $langs[str_replace( ".php", "", $entry )] = $language;
897 } else {
898 unset( $language_hide );
899 }
900 }
901 }
902
903 return $langs;
904 }
905
906 function phorum_redirect_by_url( $redir_url )
907 {
908 if ( stristr( $_SERVER['SERVER_SOFTWARE'], "Microsoft-IIS" ) ) {
909 // the ugly IIS-hack to avoid crashing IIS
910 print "<html><head>\n<title>Redirecting ...</title>\n";
911 print "<meta http-equiv=\"refresh\" content=\"0; URL=$redir_url\">";
912 print "</head>\n";
913 print "<body><a href=\"$redir_url\">Redirecting ...</a></body>\n";
914 print "</html>";
915 } else {
916 // our standard-way
917 header( "Location: $redir_url" );
918 }
b7b2805 # Added exit(0) after the redirect code for phorum_redirect_by_url()
mmakaay authored
919 exit(0);
4775e82 # more line-ending properties
ts77 authored
920 }
921
922 // might remove these, might not. Need it for debugging.
923 function print_var( $var )
924 {
925 echo "<xmp>";
926 print_r( $var );
927 echo "</xmp>";
928 }
929
352c4b3 MFB: Added a simple general purpose private key based signature system
mmakaay authored
930 /**
931 * Generates an MD5 signature for a piece of data using Phorum's secret
932 * private key. This can be used to sign data which travels an unsafe path
933 * (for example data that is sent to a user's browser and then back to
934 * Phorum) and for which tampering should be prevented.
935 *
936 * @param $data The data to sign.
937 * @return $signature The signature for the data.
938 */
939 function phorum_generate_data_signature($data)
940 {
6d1a7bd MFB: # Stupid me, forgot to use global PHORUM var in the signing functio...
mmakaay authored
941 $signature = md5($data . $GLOBALS["PHORUM"]["private_key"]);
352c4b3 MFB: Added a simple general purpose private key based signature system
mmakaay authored
942 return $signature;
943 }
944
945 /**
946 * Checks whether the signature for a piece of data is valid.
947 *
948 * @param $data The signed data.
949 * @param $signature The signature for the data.
950 * @return True in case the signature is okay, false otherwise.
951 */
952 function phorum_check_data_signature($data, $signature)
953 {
6d1a7bd MFB: # Stupid me, forgot to use global PHORUM var in the signing functio...
mmakaay authored
954 return md5($data . $GLOBALS["PHORUM"]["private_key"]) == $signature;
352c4b3 MFB: Added a simple general purpose private key based signature system
mmakaay authored
955 }
956
4775e82 # more line-ending properties
ts77 authored
957 ?>
Something went wrong with that request. Please try again.