punbb/include/functions.php
author Dan
Thu, 12 Jul 2007 01:04:01 -0400
changeset 2 a8a21e1c7afa
parent 0 f9ffdbd96607
child 3 c0c445d4a13e
permissions -rw-r--r--
Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     1
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     2
/***********************************************************************
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     3
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     4
  Copyright (C) 2002-2005  Rickard Andersson (rickard@punbb.org)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     5
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     6
  This file is part of PunBB.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     7
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     8
  PunBB is free software; you can redistribute it and/or modify it
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
     9
  under the terms of the GNU General Public License as published
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    10
  by the Free Software Foundation; either version 2 of the License,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    11
  or (at your option) any later version.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    12
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    13
  PunBB is distributed in the hope that it will be useful, but
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    14
  WITHOUT ANY WARRANTY; without even the implied warranty of
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    15
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    16
  GNU General Public License for more details.
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    17
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    18
  You should have received a copy of the GNU General Public License
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    19
  along with this program; if not, write to the Free Software
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    20
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    21
  MA  02111-1307  USA
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    22
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    23
************************************************************************/
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    24
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    25
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    26
// Cookie stuff!
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    27
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    28
function check_cookie(&$pun_user)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    29
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    30
  // Import Enano
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    31
  global $db, $session, $paths, $template, $plugins; // Common objects
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    32
  
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    33
  // Import PunBB
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    34
	global $pun_db, $db_type, $pun_config, $cookie_name, $cookie_seed;
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    35
  
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    36
  $now = time();
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    37
  
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    38
  if(!$session->started)
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    39
    $session->start();
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    40
  
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    41
  if($session->user_logged_in)
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    42
  {
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    43
    $result = $pun_db->query(
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    44
      'SELECT eu.*, u.*, eu.real_name AS realname, eu.user_level AS g_id, g.*, o.logged, o.idle
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    45
        FROM '.$pun_db->prefix.'users AS u
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    46
        LEFT JOIN '.table_prefix.'users AS eu
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    47
          ON eu.user_id=u.id
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    48
        INNER JOIN '.$pun_db->prefix.'groups AS g
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    49
          ON u.group_id=g.g_id 
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    50
        LEFT JOIN '.$pun_db->prefix.'online AS o
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    51
          ON o.user_id=u.id
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    52
        WHERE u.id='.intval($session->user_id))
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    53
      or error('Unable to fetch user information', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    54
		$pun_user = $pun_db->fetch_assoc($result);
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    55
    // Set a default language if the user selected language no longer exists
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    56
		if (!@file_exists(PUN_ROOT.'lang/'.$pun_user['language']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    57
			$pun_user['language'] = $pun_config['o_default_lang'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    58
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    59
		// Set a default style if the user selected style no longer exists
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    60
		// if (!@file_exists(PUN_ROOT.'style/'.$pun_user['style'].'.css'))
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    61
		// 	$pun_user['style'] = $pun_config['o_default_style'];
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    62
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    63
		if (!$pun_user['disp_topics'])
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    64
			$pun_user['disp_topics'] = $pun_config['o_disp_topics_default'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    65
		if (!$pun_user['disp_posts'])
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    66
			$pun_user['disp_posts'] = $pun_config['o_disp_posts_default'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    67
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    68
		if ($pun_user['save_pass'] == '0')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    69
			$expire = 0;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    70
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    71
		// Define this if you want this visit to affect the online list and the users last visit data
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    72
		if (!defined('PUN_QUIET_VISIT'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    73
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    74
			// Update the online list
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    75
			if (!$pun_user['logged'])
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    76
				$pun_db->query('INSERT INTO '.$pun_db->prefix.'online (user_id, ident, logged) VALUES('.$pun_user['id'].', \''.$pun_db->escape($pun_user['username']).'\', '.$now.')') or error('Unable to insert into online list', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    77
			else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    78
			{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    79
				// Special case: We've timed out, but no other user has browsed the forums since we timed out
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    80
				if ($pun_user['logged'] < ($now-$pun_config['o_timeout_visit']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    81
				{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    82
					$pun_db->query('UPDATE '.$pun_db->prefix.'users SET last_visit='.$pun_user['logged'].' WHERE id='.$pun_user['id']) or error('Unable to update user visit data', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    83
					$pun_user['last_visit'] = $pun_user['logged'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    84
				}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    85
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    86
				$idle_sql = ($pun_user['idle'] == '1') ? ', idle=0' : '';
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    87
				$pun_db->query('UPDATE '.$pun_db->prefix.'online SET logged='.$now.$idle_sql.' WHERE user_id='.$pun_user['id']) or error('Unable to update online list', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    88
			}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    89
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    90
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    91
		$pun_user['is_guest'] = false;
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    92
  }
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    93
  else
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    94
  {
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    95
    set_default_user();
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
    96
  }
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    97
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    98
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
    99
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   100
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   101
// Fill $pun_user with default values (for guests)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   102
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   103
function set_default_user()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   104
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   105
	global $pun_db, $pun_user, $pun_config;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   106
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   107
	$remote_addr = get_remote_address();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   108
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   109
	// Fetch guest user
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   110
	$result = $pun_db->query('SELECT u.*, g.*, o.logged FROM '.$pun_db->prefix.'users AS u INNER JOIN '.$pun_db->prefix.'groups AS g ON u.group_id=g.g_id LEFT JOIN '.$pun_db->prefix.'online AS o ON o.ident=\''.$remote_addr.'\' WHERE u.id=1') or error('Unable to fetch guest information', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   111
	if (!$pun_db->num_rows($result))
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   112
		exit('Unable to fetch guest information. The table \''.$pun_db->prefix.'users\' must contain an entry with id = 1 that represents anonymous users.');
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   113
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   114
	$pun_user = $pun_db->fetch_assoc($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   115
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   116
	// Update online list
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   117
	if (!$pun_user['logged'])
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   118
		$pun_db->query('INSERT INTO '.$pun_db->prefix.'online (user_id, ident, logged) VALUES(1, \''.$pun_db->escape($remote_addr).'\', '.time().')') or error('Unable to insert into online list', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   119
	else
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   120
		$pun_db->query('UPDATE '.$pun_db->prefix.'online SET logged='.time().' WHERE ident=\''.$pun_db->escape($remote_addr).'\'') or error('Unable to update online list', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   121
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   122
	$pun_user['disp_topics'] = $pun_config['o_disp_topics_default'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   123
	$pun_user['disp_posts'] = $pun_config['o_disp_posts_default'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   124
	$pun_user['timezone'] = $pun_config['o_server_timezone'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   125
	$pun_user['language'] = $pun_config['o_default_lang'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   126
	$pun_user['style'] = $pun_config['o_default_style'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   127
	$pun_user['is_guest'] = true;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   128
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   129
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   130
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   131
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   132
// Set a cookie, PunBB style!
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   133
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   134
function pun_setcookie($user_id, $password_hash, $expire)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   135
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   136
	global $cookie_name, $cookie_path, $cookie_domain, $cookie_secure, $cookie_seed;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   137
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   138
	// Enable sending of a P3P header by removing // from the following line (try this if login is failing in IE6)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   139
//	@header('P3P: CP="CUR ADM"');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   140
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   141
	if (version_compare(PHP_VERSION, '5.2.0', '>='))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   142
		setcookie($cookie_name, serialize(array($user_id, md5($cookie_seed.$password_hash))), $expire, $cookie_path, $cookie_domain, $cookie_secure, true);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   143
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   144
		setcookie($cookie_name, serialize(array($user_id, md5($cookie_seed.$password_hash))), $expire, $cookie_path.'; HttpOnly', $cookie_domain, $cookie_secure);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   145
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   146
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   147
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   148
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   149
// Check whether the connecting user is banned (and delete any expired bans while we're at it)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   150
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   151
function check_bans()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   152
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   153
	global $pun_db, $pun_config, $lang_common, $pun_user, $pun_bans;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   154
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   155
	// Admins aren't affected
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   156
	if ($pun_user['g_id'] == PUN_ADMIN || !$pun_bans)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   157
		return;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   158
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   159
	// Add a dot at the end of the IP address to prevent banned address 192.168.0.5 from matching e.g. 192.168.0.50
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   160
	$user_ip = get_remote_address().'.';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   161
	$bans_altered = false;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   162
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   163
	foreach ($pun_bans as $cur_ban)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   164
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   165
		// Has this ban expired?
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   166
		if ($cur_ban['expire'] != '' && $cur_ban['expire'] <= time())
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   167
		{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   168
			$pun_db->query('DELETE FROM '.$pun_db->prefix.'bans WHERE id='.$cur_ban['id']) or error('Unable to delete expired ban', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   169
			$bans_altered = true;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   170
			continue;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   171
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   172
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   173
		if ($cur_ban['username'] != '' && !strcasecmp($pun_user['username'], $cur_ban['username']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   174
		{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   175
			$pun_db->query('DELETE FROM '.$pun_db->prefix.'online WHERE ident=\''.$pun_db->escape($pun_user['username']).'\'') or error('Unable to delete from online list', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   176
			message($lang_common['Ban message'].' '.(($cur_ban['expire'] != '') ? $lang_common['Ban message 2'].' '.strtolower(format_time($cur_ban['expire'], true)).'. ' : '').(($cur_ban['message'] != '') ? $lang_common['Ban message 3'].'<br /><br /><strong>'.pun_htmlspecialchars($cur_ban['message']).'</strong><br /><br />' : '<br /><br />').$lang_common['Ban message 4'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.', true);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   177
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   178
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   179
		if ($cur_ban['ip'] != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   180
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   181
			$cur_ban_ips = explode(' ', $cur_ban['ip']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   182
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   183
			for ($i = 0; $i < count($cur_ban_ips); ++$i)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   184
			{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   185
				$cur_ban_ips[$i] = $cur_ban_ips[$i].'.';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   186
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   187
				if (substr($user_ip, 0, strlen($cur_ban_ips[$i])) == $cur_ban_ips[$i])
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   188
				{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   189
					$pun_db->query('DELETE FROM '.$pun_db->prefix.'online WHERE ident=\''.$pun_db->escape($pun_user['username']).'\'') or error('Unable to delete from online list', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   190
					message($lang_common['Ban message'].' '.(($cur_ban['expire'] != '') ? $lang_common['Ban message 2'].' '.strtolower(format_time($cur_ban['expire'], true)).'. ' : '').(($cur_ban['message'] != '') ? $lang_common['Ban message 3'].'<br /><br /><strong>'.pun_htmlspecialchars($cur_ban['message']).'</strong><br /><br />' : '<br /><br />').$lang_common['Ban message 4'].' <a href="mailto:'.$pun_config['o_admin_email'].'">'.$pun_config['o_admin_email'].'</a>.', true);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   191
				}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   192
			}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   193
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   194
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   195
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   196
	// If we removed any expired bans during our run-through, we need to regenerate the bans cache
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   197
	if ($bans_altered)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   198
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   199
		require_once PUN_ROOT.'include/cache.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   200
		generate_bans_cache();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   201
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   202
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   203
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   204
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   205
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   206
// Update "Users online"
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   207
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   208
function update_users_online()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   209
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   210
	global $pun_db, $pun_config, $pun_user;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   211
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   212
	$now = time();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   213
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   214
	// Fetch all online list entries that are older than "o_timeout_online"
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   215
	$result = $pun_db->query('SELECT * FROM '.$pun_db->prefix.'online WHERE logged<'.($now-$pun_config['o_timeout_online'])) or error('Unable to fetch old entries from online list', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   216
	while ($cur_user = $pun_db->fetch_assoc($result))
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   217
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   218
		// If the entry is a guest, delete it
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   219
		if ($cur_user['user_id'] == '1')
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   220
			$pun_db->query('DELETE FROM '.$pun_db->prefix.'online WHERE ident=\''.$pun_db->escape($cur_user['ident']).'\'') or error('Unable to delete from online list', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   221
		else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   222
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   223
			// If the entry is older than "o_timeout_visit", update last_visit for the user in question, then delete him/her from the online list
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   224
			if ($cur_user['logged'] < ($now-$pun_config['o_timeout_visit']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   225
			{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   226
				$pun_db->query('UPDATE '.$pun_db->prefix.'users SET last_visit='.$cur_user['logged'].' WHERE id='.$cur_user['user_id']) or error('Unable to update user visit data', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   227
				$pun_db->query('DELETE FROM '.$pun_db->prefix.'online WHERE user_id='.$cur_user['user_id']) or error('Unable to delete from online list', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   228
			}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   229
			else if ($cur_user['idle'] == '0')
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   230
				$pun_db->query('UPDATE '.$pun_db->prefix.'online SET idle=1 WHERE user_id='.$cur_user['user_id']) or error('Unable to insert into online list', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   231
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   232
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   233
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   234
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   235
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   236
// Generate the "navigator" that appears at the top of every page
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   237
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   238
function generate_navlinks()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   239
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   240
	global $pun_config, $lang_common, $pun_user;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   241
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   242
	// Index and Userlist should always be displayed
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   243
	$links[] = '<li id="navindex"><a href="index.php">'.$lang_common['Index'].'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   244
	$links[] = '<li id="navuserlist"><a href="userlist.php">'.$lang_common['User list'].'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   245
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   246
	if ($pun_config['o_rules'] == '1')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   247
		$links[] = '<li id="navrules"><a href="misc.php?action=rules">'.$lang_common['Rules'].'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   248
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   249
	if ($pun_user['is_guest'])
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   250
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   251
		if ($pun_user['g_search'] == '1')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   252
			$links[] = '<li id="navsearch"><a href="search.php">'.$lang_common['Search'].'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   253
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   254
		$links[] = '<li id="navregister"><a href="register.php">'.$lang_common['Register'].'</a>';
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   255
		// $links[] = '<li id="navlogin"><a href="login.php">'.$lang_common['Login'].'</a>';
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   256
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   257
		$info = $lang_common['Not logged in'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   258
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   259
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   260
	{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   261
		if ($pun_user['g_id'] < PUN_MOD)
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   262
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   263
			if ($pun_user['g_search'] == '1')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   264
				$links[] = '<li id="navsearch"><a href="search.php">'.$lang_common['Search'].'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   265
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   266
			$links[] = '<li id="navprofile"><a href="profile.php?id='.$pun_user['id'].'">'.$lang_common['Profile'].'</a>';
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   267
			// $links[] = '<li id="navlogout"><a href="login.php?action=out&amp;id='.$pun_user['id'].'">'.$lang_common['Logout'].'</a>';
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   268
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   269
		else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   270
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   271
			$links[] = '<li id="navsearch"><a href="search.php">'.$lang_common['Search'].'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   272
			$links[] = '<li id="navprofile"><a href="profile.php?id='.$pun_user['id'].'">'.$lang_common['Profile'].'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   273
			$links[] = '<li id="navadmin"><a href="admin_index.php">'.$lang_common['Admin'].'</a>';
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   274
			// $links[] = '<li id="navlogout"><a href="login.php?action=out&amp;id='.$pun_user['id'].'">'.$lang_common['Logout'].'</a>';
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   275
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   276
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   277
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   278
	// Are there any additional navlinks we should insert into the array before imploding it?
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   279
	if ($pun_config['o_additional_navlinks'] != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   280
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   281
		if (preg_match_all('#([0-9]+)\s*=\s*(.*?)\n#s', $pun_config['o_additional_navlinks']."\n", $extra_links))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   282
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   283
			// Insert any additional links into the $links array (at the correct index)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   284
			for ($i = 0; $i < count($extra_links[1]); ++$i)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   285
				array_splice($links, $extra_links[1][$i], 0, array('<li id="navextra'.($i + 1).'">'.$extra_links[2][$i]));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   286
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   287
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   288
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   289
	return '<ul>'."\n\t\t\t\t".implode($lang_common['Link separator'].'</li>'."\n\t\t\t\t", $links).'</li>'."\n\t\t\t".'</ul>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   290
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   291
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   292
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   293
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   294
// Display the profile navigation menu
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   295
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   296
function generate_profile_menu($page = '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   297
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   298
	global $lang_profile, $pun_config, $pun_user, $id, $lang_common;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   299
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   300
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   301
<div id="profile" class="block2col">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   302
	<div class="blockmenu">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   303
		<h2><span><?php echo $lang_profile['Profile menu'] ?></span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   304
		<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   305
			<div class="inbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   306
				<ul>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   307
					<li<?php if ($page == 'essentials') echo ' class="isactive"'; ?>><a href="profile.php?section=essentials&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section essentials'] ?></a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   308
					<li<?php if ($page == 'personal') echo ' class="isactive"'; ?>><a href="profile.php?section=personal&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section personal'] ?></a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   309
					<li<?php if ($page == 'messaging') echo ' class="isactive"'; ?>><a href="profile.php?section=messaging&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section messaging'] ?></a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   310
					<li<?php if ($page == 'personality') echo ' class="isactive"'; ?>><a href="profile.php?section=personality&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section personality'] ?></a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   311
					<li<?php if ($page == 'display') echo ' class="isactive"'; ?>><a href="profile.php?section=display&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section display'] ?></a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   312
					<li<?php if ($page == 'privacy') echo ' class="isactive"'; ?>><a href="profile.php?section=privacy&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section privacy'] ?></a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   313
<?php if ($pun_user['g_id'] == PUN_ADMIN || ($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_ban_users'] == '1')): ?>					<li<?php if ($page == 'admin') echo ' class="isactive"'; ?>><a href="profile.php?section=admin&amp;id=<?php echo $id ?>"><?php echo $lang_profile['Section admin'] ?></a></li>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   314
<?php endif; ?>				</ul>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   315
			</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   316
		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   317
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   318
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   319
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   320
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   321
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   322
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   323
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   324
// Update posts, topics, last_post, last_post_id and last_poster for a forum (redirect topics are not included)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   325
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   326
function update_forum($forum_id)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   327
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   328
	global $pun_db;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   329
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   330
	$result = $pun_db->query('SELECT COUNT(id), SUM(num_replies) FROM '.$pun_db->prefix.'topics WHERE moved_to IS NULL AND forum_id='.$forum_id) or error('Unable to fetch forum topic count', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   331
	list($num_topics, $num_posts) = $pun_db->fetch_row($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   332
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   333
	$num_posts = $num_posts + $num_topics;		// $num_posts is only the sum of all replies (we have to add the topic posts)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   334
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   335
	$result = $pun_db->query('SELECT last_post, last_post_id, last_poster FROM '.$pun_db->prefix.'topics WHERE forum_id='.$forum_id.' AND moved_to IS NULL ORDER BY last_post DESC LIMIT 1') or error('Unable to fetch last_post/last_post_id/last_poster', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   336
	if ($pun_db->num_rows($result))		// There are topics in the forum
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   337
	{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   338
		list($last_post, $last_post_id, $last_poster) = $pun_db->fetch_row($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   339
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   340
		$pun_db->query('UPDATE '.$pun_db->prefix.'forums SET num_topics='.$num_topics.', num_posts='.$num_posts.', last_post='.$last_post.', last_post_id='.$last_post_id.', last_poster=\''.$pun_db->escape($last_poster).'\' WHERE id='.$forum_id) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   341
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   342
	else	// There are no topics
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   343
		$pun_db->query('UPDATE '.$pun_db->prefix.'forums SET num_topics=0, num_posts=0, last_post=NULL, last_post_id=NULL, last_poster=NULL WHERE id='.$forum_id) or error('Unable to update last_post/last_post_id/last_poster', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   344
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   345
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   346
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   347
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   348
// Delete a topic and all of it's posts
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   349
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   350
function delete_topic($topic_id)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   351
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   352
	global $pun_db;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   353
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   354
	// Delete the topic and any redirect topics
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   355
	$pun_db->query('DELETE FROM '.$pun_db->prefix.'topics WHERE id='.$topic_id.' OR moved_to='.$topic_id) or error('Unable to delete topic', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   356
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   357
	// Create a list of the post ID's in this topic
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   358
	$post_ids = '';
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   359
	$result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'posts WHERE topic_id='.$topic_id) or error('Unable to fetch posts', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   360
	while ($row = $pun_db->fetch_row($result))
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   361
		$post_ids .= ($post_ids != '') ? ','.$row[0] : $row[0];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   362
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   363
	// Make sure we have a list of post ID's
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   364
	if ($post_ids != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   365
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   366
		strip_search_index($post_ids);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   367
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   368
		// Delete posts in topic
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   369
		$pun_db->query('DELETE FROM '.$pun_db->prefix.'posts WHERE topic_id='.$topic_id) or error('Unable to delete posts', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   370
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   371
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   372
	// Delete any subscriptions for this topic
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   373
	$pun_db->query('DELETE FROM '.$pun_db->prefix.'subscriptions WHERE topic_id='.$topic_id) or error('Unable to delete subscriptions', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   374
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   375
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   376
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   377
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   378
// Delete a single post
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   379
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   380
function delete_post($post_id, $topic_id)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   381
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   382
	global $pun_db;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   383
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   384
	$result = $pun_db->query('SELECT id, poster, posted FROM '.$pun_db->prefix.'posts WHERE topic_id='.$topic_id.' ORDER BY id DESC LIMIT 2') or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   385
	list($last_id, ,) = $pun_db->fetch_row($result);
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   386
	list($second_last_id, $second_poster, $second_posted) = $pun_db->fetch_row($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   387
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   388
	// Delete the post
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   389
	$pun_db->query('DELETE FROM '.$pun_db->prefix.'posts WHERE id='.$post_id) or error('Unable to delete post', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   390
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   391
	strip_search_index($post_id);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   392
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   393
	// Count number of replies in the topic
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   394
	$result = $pun_db->query('SELECT COUNT(id) FROM '.$pun_db->prefix.'posts WHERE topic_id='.$topic_id) or error('Unable to fetch post count for topic', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   395
	$num_replies = $pun_db->result($result, 0) - 1;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   396
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   397
	// If the message we deleted is the most recent in the topic (at the end of the topic)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   398
	if ($last_id == $post_id)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   399
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   400
		// If there is a $second_last_id there is more than 1 reply to the topic
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   401
		if (!empty($second_last_id))
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   402
			$pun_db->query('UPDATE '.$pun_db->prefix.'topics SET last_post='.$second_posted.', last_post_id='.$second_last_id.', last_poster=\''.$pun_db->escape($second_poster).'\', num_replies='.$num_replies.' WHERE id='.$topic_id) or error('Unable to update topic', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   403
		else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   404
			// We deleted the only reply, so now last_post/last_post_id/last_poster is posted/id/poster from the topic itself
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   405
			$pun_db->query('UPDATE '.$pun_db->prefix.'topics SET last_post=posted, last_post_id=id, last_poster=poster, num_replies='.$num_replies.' WHERE id='.$topic_id) or error('Unable to update topic', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   406
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   407
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   408
		// Otherwise we just decrement the reply counter
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   409
		$pun_db->query('UPDATE '.$pun_db->prefix.'topics SET num_replies='.$num_replies.' WHERE id='.$topic_id) or error('Unable to update topic', __FILE__, __LINE__, $pun_db->error());
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   410
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   411
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   412
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   413
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   414
// Replace censored words in $text
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   415
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   416
function censor_words($text)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   417
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   418
	global $pun_db;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   419
	static $search_for, $replace_with;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   420
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   421
	// If not already built in a previous call, build an array of censor words and their replacement text
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   422
	if (!isset($search_for))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   423
	{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   424
		$result = $pun_db->query('SELECT search_for, replace_with FROM '.$pun_db->prefix.'censoring') or error('Unable to fetch censor word list', __FILE__, __LINE__, $pun_db->error());
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   425
		$num_words = $pun_db->num_rows($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   426
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   427
		$search_for = array();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   428
		for ($i = 0; $i < $num_words; ++$i)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   429
		{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   430
			list($search_for[$i], $replace_with[$i]) = $pun_db->fetch_row($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   431
			$search_for[$i] = '/\b('.str_replace('\*', '\w*?', preg_quote($search_for[$i], '/')).')\b/i';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   432
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   433
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   434
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   435
	if (!empty($search_for))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   436
		$text = substr(preg_replace($search_for, $replace_with, ' '.$text.' '), 1, -1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   437
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   438
	return $text;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   439
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   440
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   441
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   442
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   443
// Determines the correct title for $user
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   444
// $user must contain the elements 'username', 'title', 'posts', 'g_id' and 'g_user_title'
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   445
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   446
function get_title($user)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   447
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   448
	global $pun_db, $pun_config, $pun_bans, $lang_common;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   449
	static $ban_list, $pun_ranks;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   450
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   451
	// If not already built in a previous call, build an array of lowercase banned usernames
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   452
	if (empty($ban_list))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   453
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   454
		$ban_list = array();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   455
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   456
		foreach ($pun_bans as $cur_ban)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   457
			$ban_list[] = strtolower($cur_ban['username']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   458
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   459
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   460
	// If not already loaded in a previous call, load the cached ranks
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   461
	if ($pun_config['o_ranks'] == '1' && empty($pun_ranks))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   462
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   463
		@include PUN_ROOT.'cache/cache_ranks.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   464
		if (!defined('PUN_RANKS_LOADED'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   465
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   466
			require_once PUN_ROOT.'include/cache.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   467
			generate_ranks_cache();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   468
			require PUN_ROOT.'cache/cache_ranks.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   469
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   470
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   471
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   472
	// If the user has a custom title
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   473
	if ($user['title'] != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   474
		$user_title = pun_htmlspecialchars($user['title']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   475
	// If the user is banned
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   476
	else if (in_array(strtolower($user['username']), $ban_list))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   477
		$user_title = $lang_common['Banned'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   478
	// If the user group has a default user title
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   479
	else if ($user['g_user_title'] != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   480
		$user_title = pun_htmlspecialchars($user['g_user_title']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   481
	// If the user is a guest
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   482
	else if ($user['g_id'] == PUN_GUEST)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   483
		$user_title = $lang_common['Guest'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   484
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   485
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   486
		// Are there any ranks?
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   487
		if ($pun_config['o_ranks'] == '1' && !empty($pun_ranks))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   488
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   489
			@reset($pun_ranks);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   490
			while (list(, $cur_rank) = @each($pun_ranks))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   491
			{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   492
				if (intval($user['num_posts']) >= $cur_rank['min_posts'])
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   493
					$user_title = pun_htmlspecialchars($cur_rank['rank']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   494
			}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   495
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   496
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   497
		// If the user didn't "reach" any rank (or if ranks are disabled), we assign the default
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   498
		if (!isset($user_title))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   499
			$user_title = $lang_common['Member'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   500
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   501
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   502
	return $user_title;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   503
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   504
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   505
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   506
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   507
// Generate a string with numbered links (for multipage scripts)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   508
//
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   509
function pun_paginate($num_pages, $cur_page, $link_to)
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   510
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   511
	$pages = array();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   512
	$link_to_all = false;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   513
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   514
	// If $cur_page == -1, we link to all pages (used in viewforum.php)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   515
	if ($cur_page == -1)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   516
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   517
		$cur_page = 1;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   518
		$link_to_all = true;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   519
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   520
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   521
	if ($num_pages <= 1)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   522
		$pages = array('<strong>1</strong>');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   523
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   524
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   525
		if ($cur_page > 3)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   526
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   527
			$pages[] = '<a href="'.$link_to.'&amp;p=1">1</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   528
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   529
			if ($cur_page != 4)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   530
				$pages[] = '&hellip;';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   531
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   532
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   533
		// Don't ask me how the following works. It just does, OK? :-)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   534
		for ($current = $cur_page - 2, $stop = $cur_page + 3; $current < $stop; ++$current)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   535
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   536
			if ($current < 1 || $current > $num_pages)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   537
				continue;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   538
			else if ($current != $cur_page || $link_to_all)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   539
				$pages[] = '<a href="'.$link_to.'&amp;p='.$current.'">'.$current.'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   540
			else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   541
				$pages[] = '<strong>'.$current.'</strong>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   542
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   543
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   544
		if ($cur_page <= ($num_pages-3))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   545
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   546
			if ($cur_page != ($num_pages-3))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   547
				$pages[] = '&hellip;';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   548
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   549
			$pages[] = '<a href="'.$link_to.'&amp;p='.$num_pages.'">'.$num_pages.'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   550
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   551
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   552
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   553
	return implode('&nbsp;', $pages);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   554
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   555
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   556
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   557
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   558
// Display a message
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   559
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   560
function message($message, $no_back_link = false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   561
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   562
	global $pun_db, $lang_common, $pun_config, $pun_start, $tpl_main;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   563
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   564
	if (!defined('PUN_HEADER'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   565
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   566
		global $pun_user;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   567
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   568
		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Info'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   569
		require PUN_ROOT.'header.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   570
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   571
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   572
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   573
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   574
<div id="msg" class="block">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   575
	<h2><span><?php echo $lang_common['Info'] ?></span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   576
	<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   577
		<div class="inbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   578
		<p><?php echo $message ?></p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   579
<?php if (!$no_back_link): ?>		<p><a href="javascript: history.go(-1)"><?php echo $lang_common['Go back'] ?></a></p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   580
<?php endif; ?>		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   581
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   582
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   583
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   584
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   585
	require PUN_ROOT.'footer.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   586
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   587
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   588
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   589
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   590
// Format a time string according to $time_format and timezones
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   591
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   592
function format_time($timestamp, $date_only = false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   593
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   594
	global $pun_config, $lang_common, $pun_user;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   595
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   596
	if ($timestamp == '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   597
		return $lang_common['Never'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   598
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   599
	$diff = ($pun_user['timezone'] - $pun_config['o_server_timezone']) * 3600;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   600
	$timestamp += $diff;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   601
	$now = time();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   602
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   603
	$date = date($pun_config['o_date_format'], $timestamp);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   604
	$today = date($pun_config['o_date_format'], $now+$diff);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   605
	$yesterday = date($pun_config['o_date_format'], $now+$diff-86400);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   606
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   607
	if ($date == $today)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   608
		$date = $lang_common['Today'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   609
	else if ($date == $yesterday)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   610
		$date = $lang_common['Yesterday'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   611
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   612
	if (!$date_only)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   613
		return $date.' '.date($pun_config['o_time_format'], $timestamp);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   614
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   615
		return $date;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   616
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   617
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   618
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   619
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   620
// If we are running pre PHP 4.3.0, we add our own implementation of file_get_contents
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   621
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   622
if (!function_exists('file_get_contents'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   623
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   624
	function file_get_contents($filename, $use_include_path = 0)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   625
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   626
		$data = '';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   627
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   628
		if ($fh = fopen($filename, 'rb', $use_include_path))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   629
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   630
			$data = fread($fh, filesize($filename));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   631
			fclose($fh);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   632
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   633
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   634
		return $data;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   635
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   636
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   637
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   638
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   639
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   640
// Make sure that HTTP_REFERER matches $pun_config['o_base_url']/$script
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   641
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   642
function confirm_referrer($script)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   643
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   644
	global $pun_config, $lang_common;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   645
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   646
	if (!preg_match('#^'.preg_quote(str_replace('www.', '', $pun_config['o_base_url']).'/'.$script, '#').'#i', str_replace('www.', '', (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''))))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   647
		message($lang_common['Bad referrer']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   648
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   649
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   650
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   651
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   652
// Generate a random password of length $len
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   653
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   654
function random_pass($len)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   655
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   656
	$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   657
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   658
	$password = '';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   659
	for ($i = 0; $i < $len; ++$i)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   660
		$password .= substr($chars, (mt_rand() % strlen($chars)), 1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   661
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   662
	return $password;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   663
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   664
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   665
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   666
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   667
// Compute a hash of $str
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   668
// Uses sha1() if available. If not, SHA1 through mhash() if available. If not, fall back on md5().
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   669
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   670
function pun_hash($str)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   671
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   672
	if (function_exists('sha1'))	// Only in PHP 4.3.0+
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   673
		return sha1($str);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   674
	else if (function_exists('mhash'))	// Only if Mhash library is loaded
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   675
		return bin2hex(mhash(MHASH_SHA1, $str));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   676
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   677
		return md5($str);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   678
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   679
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   680
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   681
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   682
// Try to determine the correct remote IP-address
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   683
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   684
function get_remote_address()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   685
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   686
	return $_SERVER['REMOTE_ADDR'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   687
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   688
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   689
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   690
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   691
// Equivalent to htmlspecialchars(), but allows &#[0-9]+ (for unicode)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   692
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   693
function pun_htmlspecialchars($str)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   694
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   695
	$str = preg_replace('/&(?!#[0-9]+;)/s', '&amp;', $str);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   696
	$str = str_replace(array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $str);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   697
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   698
	return $str;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   699
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   700
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   701
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   702
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   703
// Equivalent to strlen(), but counts &#[0-9]+ as one character (for unicode)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   704
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   705
function pun_strlen($str)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   706
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   707
	return strlen(preg_replace('/&#([0-9]+);/', '!', $str));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   708
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   709
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   710
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   711
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   712
// Convert \r\n and \r to \n
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   713
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   714
function pun_linebreaks($str)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   715
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   716
	return str_replace("\r", "\n", str_replace("\r\n", "\n", $str));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   717
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   718
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   719
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   720
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   721
// A more aggressive version of trim()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   722
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   723
function pun_trim($str)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   724
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   725
	global $lang_common;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   726
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   727
	if (strpos($lang_common['lang_encoding'], '8859') !== false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   728
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   729
		$fishy_chars = array(chr(0x81), chr(0x8D), chr(0x8F), chr(0x90), chr(0x9D), chr(0xA0));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   730
		return trim(str_replace($fishy_chars, ' ', $str));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   731
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   732
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   733
		return trim($str);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   734
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   735
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   736
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   737
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   738
// Display a message when board is in maintenance mode
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   739
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   740
function maintenance_message()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   741
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   742
	global $pun_db, $pun_config, $lang_common, $pun_user;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   743
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   744
	// Deal with newlines, tabs and multiple spaces
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   745
	$pattern = array("\t", '  ', '  ');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   746
	$replace = array('&nbsp; &nbsp; ', '&nbsp; ', ' &nbsp;');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   747
	$message = str_replace($pattern, $replace, $pun_config['o_maintenance_message']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   748
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   749
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   750
	// Load the maintenance template
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   751
	$tpl_maint = trim(file_get_contents(PUN_ROOT.'include/template/maintenance.tpl'));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   752
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   753
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   754
	// START SUBST - <pun_include "*">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   755
	while (preg_match('#<pun_include "([^/\\\\]*?)\.(php[45]?|inc|html?|txt)">#', $tpl_maint, $cur_include))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   756
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   757
		if (!file_exists(PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2]))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   758
			error('Unable to process user include '.htmlspecialchars($cur_include[0]).' from template maintenance.tpl. There is no such file in folder /include/user/');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   759
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   760
		ob_start();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   761
		include PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   762
		$tpl_temp = ob_get_contents();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   763
		$tpl_maint = str_replace($cur_include[0], $tpl_temp, $tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   764
	    ob_end_clean();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   765
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   766
	// END SUBST - <pun_include "*">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   767
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   768
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   769
	// START SUBST - <pun_content_direction>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   770
	$tpl_maint = str_replace('<pun_content_direction>', $lang_common['lang_direction'], $tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   771
	// END SUBST - <pun_content_direction>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   772
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   773
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   774
	// START SUBST - <pun_char_encoding>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   775
	$tpl_maint = str_replace('<pun_char_encoding>', $lang_common['lang_encoding'], $tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   776
	// END SUBST - <pun_char_encoding>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   777
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   778
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   779
	// START SUBST - <pun_head>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   780
	ob_start();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   781
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   782
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   783
<title><?php echo pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Maintenance'] ?></title>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   784
<link rel="stylesheet" type="text/css" href="style/<?php echo $pun_user['style'].'.css' ?>" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   785
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   786
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   787
	$tpl_temp = trim(ob_get_contents());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   788
	$tpl_maint = str_replace('<pun_head>', $tpl_temp, $tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   789
	ob_end_clean();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   790
	// END SUBST - <pun_head>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   791
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   792
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   793
	// START SUBST - <pun_maint_heading>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   794
	$tpl_maint = str_replace('<pun_maint_heading>', $lang_common['Maintenance'], $tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   795
	// END SUBST - <pun_maint_heading>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   796
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   797
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   798
	// START SUBST - <pun_maint_message>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   799
	$tpl_maint = str_replace('<pun_maint_message>', $message, $tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   800
	// END SUBST - <pun_maint_message>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   801
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   802
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   803
	// End the transaction
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   804
	$pun_db->end_transaction();
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   805
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   806
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   807
	// Close the db connection (and free up any result data)
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   808
	$pun_db->close();
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   809
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   810
	exit($tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   811
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   812
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   813
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   814
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   815
// Display $message and redirect user to $destination_url
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   816
//
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   817
function pun_redirect($destination_url, $message)
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   818
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   819
	global $pun_db, $pun_config, $lang_common, $pun_user;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   820
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   821
	if ($destination_url == '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   822
		$destination_url = 'index.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   823
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   824
	// If the delay is 0 seconds, we might as well skip the redirect all together
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   825
	if ($pun_config['o_redirect_delay'] == '0')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   826
		header('Location: '.str_replace('&amp;', '&', $destination_url));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   827
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   828
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   829
	// Load the redirect template
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   830
	$tpl_redir = trim(file_get_contents(PUN_ROOT.'include/template/redirect.tpl'));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   831
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   832
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   833
	// START SUBST - <pun_include "*">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   834
	while (preg_match('#<pun_include "([^/\\\\]*?)\.(php[45]?|inc|html?|txt)">#', $tpl_redir, $cur_include))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   835
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   836
		if (!file_exists(PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2]))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   837
			error('Unable to process user include '.htmlspecialchars($cur_include[0]).' from template redirect.tpl. There is no such file in folder /include/user/');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   838
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   839
		ob_start();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   840
		include PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   841
		$tpl_temp = ob_get_contents();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   842
		$tpl_redir = str_replace($cur_include[0], $tpl_temp, $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   843
	    ob_end_clean();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   844
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   845
	// END SUBST - <pun_include "*">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   846
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   847
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   848
	// START SUBST - <pun_content_direction>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   849
	$tpl_redir = str_replace('<pun_content_direction>', $lang_common['lang_direction'], $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   850
	// END SUBST - <pun_content_direction>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   851
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   852
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   853
	// START SUBST - <pun_char_encoding>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   854
	$tpl_redir = str_replace('<pun_char_encoding>', $lang_common['lang_encoding'], $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   855
	// END SUBST - <pun_char_encoding>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   856
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   857
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   858
	// START SUBST - <pun_head>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   859
	ob_start();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   860
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   861
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   862
<meta http-equiv="refresh" content="<?php echo $pun_config['o_redirect_delay'] ?>;URL=<?php echo str_replace(array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $destination_url) ?>" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   863
<title><?php echo pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Redirecting'] ?></title>
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   864
<link rel="stylesheet" type="text/css" href="<?php echo scriptPath; ?>/punbb/style/<?php echo $pun_user['style'].'.css' ?>" />
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   865
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   866
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   867
	$tpl_temp = trim(ob_get_contents());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   868
	$tpl_redir = str_replace('<pun_head>', $tpl_temp, $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   869
	ob_end_clean();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   870
	// END SUBST - <pun_head>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   871
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   872
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   873
	// START SUBST - <pun_redir_heading>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   874
	$tpl_redir = str_replace('<pun_redir_heading>', $lang_common['Redirecting'], $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   875
	// END SUBST - <pun_redir_heading>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   876
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   877
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   878
	// START SUBST - <pun_redir_text>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   879
	$tpl_temp = $message.'<br /><br />'.'<a href="'.$destination_url.'">'.$lang_common['Click redirect'].'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   880
	$tpl_redir = str_replace('<pun_redir_text>', $tpl_temp, $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   881
	// END SUBST - <pun_redir_text>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   882
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   883
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   884
	// START SUBST - <pun_footer>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   885
	ob_start();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   886
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   887
	// End the transaction
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   888
	$pun_db->end_transaction();
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   889
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   890
	// Display executed queries (if enabled)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   891
	if (defined('PUN_SHOW_QUERIES'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   892
		display_saved_queries();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   893
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   894
	$tpl_temp = trim(ob_get_contents());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   895
	$tpl_redir = str_replace('<pun_footer>', $tpl_temp, $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   896
	ob_end_clean();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   897
	// END SUBST - <pun_footer>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   898
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   899
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   900
	// Close the db connection (and free up any result data)
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   901
	$pun_db->close();
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   902
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   903
	exit($tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   904
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   905
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   906
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   907
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   908
// Display a simple error message
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   909
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   910
function error($message, $file, $line, $db_error = false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   911
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   912
	global $pun_config;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   913
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   914
	// Set a default title if the script failed before $pun_config could be populated
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   915
	if (empty($pun_config))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   916
		$pun_config['o_board_title'] = 'PunBB';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   917
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   918
	// Empty output buffer and stop buffering
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   919
	@ob_end_clean();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   920
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   921
	// "Restart" output buffering if we are using ob_gzhandler (since the gzip header is already sent)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   922
	if (!empty($pun_config['o_gzip']) && extension_loaded('zlib') && (strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false || strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'deflate') !== false))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   923
		ob_start('ob_gzhandler');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   924
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   925
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   926
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   927
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   928
<head>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   929
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   930
<title><?php echo pun_htmlspecialchars($pun_config['o_board_title']) ?> / Error</title>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   931
<style type="text/css">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   932
<!--
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   933
BODY {MARGIN: 10% 20% auto 20%; font: 10px Verdana, Arial, Helvetica, sans-serif}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   934
#errorbox {BORDER: 1px solid #B84623}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   935
H2 {MARGIN: 0; COLOR: #FFFFFF; BACKGROUND-COLOR: #B84623; FONT-SIZE: 1.1em; PADDING: 5px 4px}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   936
#errorbox DIV {PADDING: 6px 5px; BACKGROUND-COLOR: #F1F1F1}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   937
-->
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   938
</style>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   939
</head>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   940
<body>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   941
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   942
<div id="errorbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   943
	<h2>An error was encountered</h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   944
	<div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   945
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   946
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   947
	if (defined('PUN_DEBUG'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   948
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   949
		echo "\t\t".'<strong>File:</strong> '.$file.'<br />'."\n\t\t".'<strong>Line:</strong> '.$line.'<br /><br />'."\n\t\t".'<strong>PunBB reported</strong>: '.$message."\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   950
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   951
		if ($db_error)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   952
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   953
			echo "\t\t".'<br /><br /><strong>Database reported:</strong> '.pun_htmlspecialchars($db_error['error_msg']).(($db_error['error_no']) ? ' (Errno: '.$db_error['error_no'].')' : '')."\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   954
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   955
			if ($db_error['error_sql'] != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   956
				echo "\t\t".'<br /><br /><strong>Failed query:</strong> '.pun_htmlspecialchars($db_error['error_sql'])."\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   957
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   958
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   959
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   960
		echo "\t\t".'Error: <strong>'.$message.'.</strong>'."\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   961
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   962
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   963
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   964
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   965
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   966
</body>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   967
</html>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   968
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   969
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   970
	// If a database connection was established (before this error) we close it
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   971
	if ($db_error)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   972
		$GLOBALS['db']->close();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   973
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   974
	exit;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   975
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   976
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   977
// DEBUG FUNCTIONS BELOW
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   978
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   979
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   980
// Display executed queries (if enabled)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   981
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   982
function display_saved_queries()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   983
{
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   984
	global $pun_db, $lang_common;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   985
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   986
	// Get the queries so that we can print them out
2
a8a21e1c7afa Let's just say that the API loads. While a decent part of PunBB works, we've still got a LONG way to go, mainly with form validation and security. At this point, Punano is NOT secure as far as privileges and user levels go.
Dan
parents: 0
diff changeset
   987
	$saved_queries = $pun_db->get_saved_queries();
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   988
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   989
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   990
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   991
<div id="debug" class="blocktable">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   992
	<h2><span><?php echo $lang_common['Debug table'] ?></span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   993
	<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   994
		<div class="inbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   995
			<table cellspacing="0">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   996
			<thead>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   997
				<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   998
					<th class="tcl" scope="col">Time (s)</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   999
					<th class="tcr" scope="col">Query</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1000
				</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1001
			</thead>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1002
			<tbody>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1003
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1004
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1005
	$query_time_total = 0.0;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1006
	while (list(, $cur_query) = @each($saved_queries))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1007
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1008
		$query_time_total += $cur_query[1];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1009
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1010
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1011
				<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1012
					<td class="tcl"><?php echo ($cur_query[1] != 0) ? $cur_query[1] : '&nbsp;' ?></td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1013
					<td class="tcr"><?php echo pun_htmlspecialchars($cur_query[0]) ?></td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1014
				</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1015
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1016
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1017
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1018
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1019
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1020
				<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1021
					<td class="tcl" colspan="2">Total query time: <?php echo $query_time_total ?> s</td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1022
				</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1023
			</tbody>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1024
			</table>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1025
		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1026
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1027
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1028
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1029
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1030
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1031
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1032
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1033
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1034
// Unset any variables instantiated as a result of register_globals being enabled
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1035
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1036
function unregister_globals()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1037
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1038
	$register_globals = @ini_get('register_globals');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1039
	if ($register_globals === "" || $register_globals === "0" || strtolower($register_globals === "off"))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1040
		return;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1041
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1042
	// Prevent script.php?GLOBALS[foo]=bar
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1043
	if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1044
		exit('I\'ll have a steak sandwich and... a steak sandwich.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1045
	
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1046
	// Variables that shouldn't be unset
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1047
	$no_unset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1048
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1049
	// Remove elements in $GLOBALS that are present in any of the superglobals
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1050
	$input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1051
	foreach ($input as $k => $v)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1052
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1053
		if (!in_array($k, $no_unset) && isset($GLOBALS[$k]))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1054
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1055
			unset($GLOBALS[$k]);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1056
			unset($GLOBALS[$k]);	// Double unset to circumvent the zend_hash_del_key_or_index hole in PHP <4.4.3 and <5.1.4
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1057
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1058
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1059
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1060
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1061
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1062
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1063
// Dump contents of variable(s)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1064
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1065
function dump()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1066
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1067
	echo '<pre>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1068
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1069
	$num_args = func_num_args();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1070
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1071
	for ($i = 0; $i < $num_args; ++$i)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1072
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1073
		print_r(func_get_arg($i));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1074
		echo "\n\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1075
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1076
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1077
	echo '</pre>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1078
	exit;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1079
}