punbb/include/functions.php
author Dan
Sun, 02 Sep 2007 11:00:57 -0400
changeset 5 e3d7322305bf
parent 4 eb9ed4c366d0
permissions -rw-r--r--
Merging Scribus and Nighthawk branches
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(
3
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
    44
      'SELECT eu.*, u.*, eu.real_name AS realname, g.*, eu.user_level AS g_id, o.logged, o.idle
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
    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;
3
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   241
  global $db, $session, $paths, $template, $plugins; // Common objects
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   242
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   243
	// Index and Userlist should always be displayed
5
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   244
	$links[] = '<li id="navindex"><a href="index.php">'.$lang_common['Index'].'</a>';
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   245
	$links[] = '<li id="navuserlist"><a href="userlist.php">'.$lang_common['User list'].'</a>';
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   246
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   247
	if ($pun_config['o_rules'] == '1')
5
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   248
		$links[] = '<li id="navrules"><a href="misc.php?action=rules">'.$lang_common['Rules'].'</a>';
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   249
3
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   250
	if ( !$session->user_logged_in )
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   251
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   252
		if ($pun_user['g_search'] == '1')
5
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   253
			$links[] = '<li id="navsearch"><a href="search.php">'.$lang_common['Search'].'</a>';
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   254
5
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   255
		$links[] = '<li id="navregister"><a href="register.php">'.$lang_common['Register'].'</a>';
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   256
		// $links[] = '<li id="navlogin"><a href="login.php">'.$lang_common['Login'].'</a>';
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   257
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   258
		$info = $lang_common['Not logged in'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   259
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   260
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   261
	{
3
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   262
		if ($pun_user['g_id'] < USER_LEVEL_ADMIN)
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   263
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   264
			if ($pun_user['g_search'] == '1')
5
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   265
				$links[] = '<li id="navsearch"><a href="search.php">'.$lang_common['Search'].'</a>';
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   266
5
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   267
			$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
   268
			// $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
   269
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   270
		else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   271
		{
5
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   272
			$links[] = '<li id="navsearch"><a href="search.php">'.$lang_common['Search'].'</a>';
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   273
			$links[] = '<li id="navprofile"><a href="profile.php?id='.$pun_user['id'].'">'.$lang_common['Profile'].'</a>';
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   274
			$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
   275
			// $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
   276
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   277
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   278
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   279
	// Are there any additional navlinks we should insert into the array before imploding it?
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   280
	if ($pun_config['o_additional_navlinks'] != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   281
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   282
		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
   283
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   284
			// Insert any additional links into the $links array (at the correct index)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   285
			for ($i = 0; $i < count($extra_links[1]); ++$i)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   286
				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
   287
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   288
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   289
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   290
	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
   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
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   295
// Display the profile navigation menu
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   296
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   297
function generate_profile_menu($page = '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   298
{
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
   299
	global $lang_profile, $pun_config, $pun_user, $id, $lang_common;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   300
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   301
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   302
<div id="profile" class="block2col">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   303
	<div class="blockmenu">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   304
		<h2><span><?php echo $lang_profile['Profile menu'] ?></span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   305
		<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   306
			<div class="inbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   307
				<ul>
5
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   308
					<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>
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   309
					<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>
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   310
					<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>
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   311
					<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>
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   312
					<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>
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   313
					<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>
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   314
<?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>
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   315
<?php endif; ?>				</ul>
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
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   319
<?php
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
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   325
// 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
   326
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   327
function update_forum($forum_id)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   328
{
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
   329
	global $pun_db;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   330
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
   331
	$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
   332
	list($num_topics, $num_posts) = $pun_db->fetch_row($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   333
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   334
	$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
   335
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
   336
	$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
   337
	if ($pun_db->num_rows($result))		// There are topics in the forum
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   338
	{
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
   339
		list($last_post, $last_post_id, $last_poster) = $pun_db->fetch_row($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   340
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
   341
		$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
   342
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   343
	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
   344
		$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
   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
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   349
// Delete a topic and all of it's posts
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   350
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   351
function delete_topic($topic_id)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   352
{
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
   353
	global $pun_db;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   354
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   355
	// 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
   356
	$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
   357
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   358
	// Create a list of the post ID's in this topic
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   359
	$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
   360
	$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
   361
	while ($row = $pun_db->fetch_row($result))
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   362
		$post_ids .= ($post_ids != '') ? ','.$row[0] : $row[0];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   363
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   364
	// Make sure we have a list of post ID's
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   365
	if ($post_ids != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   366
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   367
		strip_search_index($post_ids);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   368
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   369
		// 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
   370
		$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
   371
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   372
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   373
	// 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
   374
	$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
   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
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   379
// Delete a single post
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   380
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   381
function delete_post($post_id, $topic_id)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   382
{
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
   383
	global $pun_db;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   384
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
   385
	$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
   386
	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
   387
	list($second_last_id, $second_poster, $second_posted) = $pun_db->fetch_row($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   388
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   389
	// 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
   390
	$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
   391
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   392
	strip_search_index($post_id);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   393
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   394
	// 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
   395
	$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
   396
	$num_replies = $pun_db->result($result, 0) - 1;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   397
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   398
	// 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
   399
	if ($last_id == $post_id)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   400
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   401
		// If there is a $second_last_id there is more than 1 reply to the topic
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   402
		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
   403
			$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
   404
		else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   405
			// 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
   406
			$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
   407
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   408
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   409
		// 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
   410
		$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
   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
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   415
// Replace censored words in $text
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   416
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   417
function censor_words($text)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   418
{
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
   419
	global $pun_db;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   420
	static $search_for, $replace_with;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   421
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   422
	// 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
   423
	if (!isset($search_for))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   424
	{
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
   425
		$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
   426
		$num_words = $pun_db->num_rows($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   427
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   428
		$search_for = array();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   429
		for ($i = 0; $i < $num_words; ++$i)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   430
		{
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
   431
			list($search_for[$i], $replace_with[$i]) = $pun_db->fetch_row($result);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   432
			$search_for[$i] = '/\b('.str_replace('\*', '\w*?', preg_quote($search_for[$i], '/')).')\b/i';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   433
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   434
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   435
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   436
	if (!empty($search_for))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   437
		$text = substr(preg_replace($search_for, $replace_with, ' '.$text.' '), 1, -1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   438
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   439
	return $text;
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
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   444
// Determines the correct title for $user
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   445
// $user must contain the elements 'username', 'title', 'posts', 'g_id' and 'g_user_title'
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   446
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   447
function get_title($user)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   448
{
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
   449
	global $pun_db, $pun_config, $pun_bans, $lang_common;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   450
	static $ban_list, $pun_ranks;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   451
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   452
	// If not already built in a previous call, build an array of lowercase banned usernames
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   453
	if (empty($ban_list))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   454
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   455
		$ban_list = array();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   456
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   457
		foreach ($pun_bans as $cur_ban)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   458
			$ban_list[] = strtolower($cur_ban['username']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   459
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   460
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   461
	// If not already loaded in a previous call, load the cached ranks
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   462
	if ($pun_config['o_ranks'] == '1' && empty($pun_ranks))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   463
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   464
		@include PUN_ROOT.'cache/cache_ranks.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   465
		if (!defined('PUN_RANKS_LOADED'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   466
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   467
			require_once PUN_ROOT.'include/cache.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   468
			generate_ranks_cache();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   469
			require PUN_ROOT.'cache/cache_ranks.php';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   470
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   471
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   472
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   473
	// If the user has a custom title
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   474
	if ($user['title'] != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   475
		$user_title = pun_htmlspecialchars($user['title']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   476
	// If the user is banned
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   477
	else if (in_array(strtolower($user['username']), $ban_list))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   478
		$user_title = $lang_common['Banned'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   479
	// If the user group has a default user title
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   480
	else if ($user['g_user_title'] != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   481
		$user_title = pun_htmlspecialchars($user['g_user_title']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   482
	// If the user is a guest
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   483
	else if ($user['g_id'] == PUN_GUEST)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   484
		$user_title = $lang_common['Guest'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   485
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   486
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   487
		// Are there any ranks?
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   488
		if ($pun_config['o_ranks'] == '1' && !empty($pun_ranks))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   489
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   490
			@reset($pun_ranks);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   491
			while (list(, $cur_rank) = @each($pun_ranks))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   492
			{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   493
				if (intval($user['num_posts']) >= $cur_rank['min_posts'])
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   494
					$user_title = pun_htmlspecialchars($cur_rank['rank']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   495
			}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   496
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   497
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   498
		// If the user didn't "reach" any rank (or if ranks are disabled), we assign the default
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   499
		if (!isset($user_title))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   500
			$user_title = $lang_common['Member'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   501
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   502
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   503
	return $user_title;
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
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   508
// Generate a string with numbered links (for multipage scripts)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   509
//
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
   510
function pun_paginate($num_pages, $cur_page, $link_to)
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   511
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   512
	$pages = array();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   513
	$link_to_all = false;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   514
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   515
	// If $cur_page == -1, we link to all pages (used in viewforum.php)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   516
	if ($cur_page == -1)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   517
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   518
		$cur_page = 1;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   519
		$link_to_all = true;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   520
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   521
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   522
	if ($num_pages <= 1)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   523
		$pages = array('<strong>1</strong>');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   524
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   525
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   526
		if ($cur_page > 3)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   527
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   528
			$pages[] = '<a href="'.$link_to.'&amp;p=1">1</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   529
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   530
			if ($cur_page != 4)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   531
				$pages[] = '&hellip;';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   532
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   533
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   534
		// Don't ask me how the following works. It just does, OK? :-)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   535
		for ($current = $cur_page - 2, $stop = $cur_page + 3; $current < $stop; ++$current)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   536
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   537
			if ($current < 1 || $current > $num_pages)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   538
				continue;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   539
			else if ($current != $cur_page || $link_to_all)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   540
				$pages[] = '<a href="'.$link_to.'&amp;p='.$current.'">'.$current.'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   541
			else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   542
				$pages[] = '<strong>'.$current.'</strong>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   543
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   544
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   545
		if ($cur_page <= ($num_pages-3))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   546
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   547
			if ($cur_page != ($num_pages-3))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   548
				$pages[] = '&hellip;';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   549
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   550
			$pages[] = '<a href="'.$link_to.'&amp;p='.$num_pages.'">'.$num_pages.'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   551
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   552
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   553
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   554
	return implode('&nbsp;', $pages);
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
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   559
// Display a message
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   560
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   561
function message($message, $no_back_link = false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   562
{
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
   563
	global $pun_db, $lang_common, $pun_config, $pun_start, $tpl_main;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   564
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   565
	if (!defined('PUN_HEADER'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   566
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   567
		global $pun_user;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   568
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   569
		$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Info'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   570
		require PUN_ROOT.'header.php';
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
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   575
<div id="msg" class="block">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   576
	<h2><span><?php echo $lang_common['Info'] ?></span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   577
	<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   578
		<div class="inbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   579
		<p><?php echo $message ?></p>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   580
<?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
   581
<?php endif; ?>		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   582
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   583
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   584
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   585
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   586
	require PUN_ROOT.'footer.php';
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
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   591
// Format a time string according to $time_format and timezones
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   592
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   593
function format_time($timestamp, $date_only = false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   594
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   595
	global $pun_config, $lang_common, $pun_user;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   596
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   597
	if ($timestamp == '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   598
		return $lang_common['Never'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   599
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   600
	$diff = ($pun_user['timezone'] - $pun_config['o_server_timezone']) * 3600;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   601
	$timestamp += $diff;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   602
	$now = time();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   603
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   604
	$date = date($pun_config['o_date_format'], $timestamp);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   605
	$today = date($pun_config['o_date_format'], $now+$diff);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   606
	$yesterday = date($pun_config['o_date_format'], $now+$diff-86400);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   607
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   608
	if ($date == $today)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   609
		$date = $lang_common['Today'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   610
	else if ($date == $yesterday)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   611
		$date = $lang_common['Yesterday'];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   612
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   613
	if (!$date_only)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   614
		return $date.' '.date($pun_config['o_time_format'], $timestamp);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   615
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   616
		return $date;
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
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   621
// 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
   622
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   623
if (!function_exists('file_get_contents'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   624
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   625
	function file_get_contents($filename, $use_include_path = 0)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   626
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   627
		$data = '';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   628
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   629
		if ($fh = fopen($filename, 'rb', $use_include_path))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   630
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   631
			$data = fread($fh, filesize($filename));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   632
			fclose($fh);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   633
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   634
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   635
		return $data;
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
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   641
// Make sure that HTTP_REFERER matches $pun_config['o_base_url']/$script
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   642
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   643
function confirm_referrer($script)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   644
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   645
	global $pun_config, $lang_common;
3
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   646
  
5
e3d7322305bf Merging Scribus and Nighthawk branches
Dan
parents: 4
diff changeset
   647
  // Not gonna worry about this for Enano, because Enano handles Pun's security
4
eb9ed4c366d0 Various bugfixes, mostly with URL generation (maintenance commit, may not be in a working state)
Dan
parents: 3
diff changeset
   648
  return true;
eb9ed4c366d0 Various bugfixes, mostly with URL generation (maintenance commit, may not be in a working state)
Dan
parents: 3
diff changeset
   649
  
3
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   650
  $script = preg_replace('/\.php$/i', '', $script);
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   651
  
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   652
  if ( isset($_SERVER['HTTP_REFERER']) )
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   653
    $referrer = strtolower($_SERVER['HTTP_REFERER']);
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   654
3
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   655
  $regex = '#^' . preg_quote(strtolower(str_replace('www.', '', $pun_config['o_base_url'])).'/'.$script, '#') . '#i';
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   656
  $ref_check = str_replace('www.', '', (isset($referrer) ? $referrer : ''));
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   657
  
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   658
	if ( !preg_match($regex, $ref_check) )
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   659
		message($lang_common['Bad referrer']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   660
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   661
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   662
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   663
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   664
// Generate a random password of length $len
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   665
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   666
function random_pass($len)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   667
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   668
	$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   669
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   670
	$password = '';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   671
	for ($i = 0; $i < $len; ++$i)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   672
		$password .= substr($chars, (mt_rand() % strlen($chars)), 1);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   673
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   674
	return $password;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   675
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   676
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   677
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   678
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   679
// Compute a hash of $str
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   680
// Uses sha1() if available. If not, SHA1 through mhash() if available. If not, fall back on md5().
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   681
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   682
function pun_hash($str)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   683
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   684
	if (function_exists('sha1'))	// Only in PHP 4.3.0+
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   685
		return sha1($str);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   686
	else if (function_exists('mhash'))	// Only if Mhash library is loaded
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   687
		return bin2hex(mhash(MHASH_SHA1, $str));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   688
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   689
		return md5($str);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   690
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   691
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   692
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   693
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   694
// Try to determine the correct remote IP-address
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   695
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   696
function get_remote_address()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   697
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   698
	return $_SERVER['REMOTE_ADDR'];
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 htmlspecialchars(), but allows &#[0-9]+ (for unicode)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   704
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   705
function pun_htmlspecialchars($str)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   706
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   707
	$str = preg_replace('/&(?!#[0-9]+;)/s', '&amp;', $str);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   708
	$str = str_replace(array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $str);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   709
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   710
	return $str;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   711
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   712
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   713
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   714
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   715
// Equivalent to strlen(), but counts &#[0-9]+ as one character (for unicode)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   716
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   717
function pun_strlen($str)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   718
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   719
	return strlen(preg_replace('/&#([0-9]+);/', '!', $str));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   720
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   721
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   722
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   723
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   724
// Convert \r\n and \r to \n
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   725
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   726
function pun_linebreaks($str)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   727
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   728
	return str_replace("\r", "\n", str_replace("\r\n", "\n", $str));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   729
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   730
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   731
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   732
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   733
// A more aggressive version of trim()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   734
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   735
function pun_trim($str)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   736
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   737
	global $lang_common;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   738
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   739
	if (strpos($lang_common['lang_encoding'], '8859') !== false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   740
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   741
		$fishy_chars = array(chr(0x81), chr(0x8D), chr(0x8F), chr(0x90), chr(0x9D), chr(0xA0));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   742
		return trim(str_replace($fishy_chars, ' ', $str));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   743
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   744
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   745
		return trim($str);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   746
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   747
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   748
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   749
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   750
// Display a message when board is in maintenance mode
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   751
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   752
function maintenance_message()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   753
{
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
   754
	global $pun_db, $pun_config, $lang_common, $pun_user;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   755
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   756
	// Deal with newlines, tabs and multiple spaces
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   757
	$pattern = array("\t", '  ', '  ');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   758
	$replace = array('&nbsp; &nbsp; ', '&nbsp; ', ' &nbsp;');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   759
	$message = str_replace($pattern, $replace, $pun_config['o_maintenance_message']);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   760
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   761
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   762
	// Load the maintenance template
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   763
	$tpl_maint = trim(file_get_contents(PUN_ROOT.'include/template/maintenance.tpl'));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   764
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   765
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   766
	// START SUBST - <pun_include "*">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   767
	while (preg_match('#<pun_include "([^/\\\\]*?)\.(php[45]?|inc|html?|txt)">#', $tpl_maint, $cur_include))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   768
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   769
		if (!file_exists(PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2]))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   770
			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
   771
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   772
		ob_start();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   773
		include PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   774
		$tpl_temp = ob_get_contents();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   775
		$tpl_maint = str_replace($cur_include[0], $tpl_temp, $tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   776
	    ob_end_clean();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   777
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   778
	// END SUBST - <pun_include "*">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   779
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   780
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   781
	// START SUBST - <pun_content_direction>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   782
	$tpl_maint = str_replace('<pun_content_direction>', $lang_common['lang_direction'], $tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   783
	// END SUBST - <pun_content_direction>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   784
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   785
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   786
	// START SUBST - <pun_char_encoding>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   787
	$tpl_maint = str_replace('<pun_char_encoding>', $lang_common['lang_encoding'], $tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   788
	// END SUBST - <pun_char_encoding>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   789
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   790
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   791
	// START SUBST - <pun_head>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   792
	ob_start();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   793
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   794
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   795
<title><?php echo pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Maintenance'] ?></title>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   796
<link rel="stylesheet" type="text/css" href="style/<?php echo $pun_user['style'].'.css' ?>" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   797
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   798
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   799
	$tpl_temp = trim(ob_get_contents());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   800
	$tpl_maint = str_replace('<pun_head>', $tpl_temp, $tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   801
	ob_end_clean();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   802
	// END SUBST - <pun_head>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   803
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   804
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   805
	// START SUBST - <pun_maint_heading>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   806
	$tpl_maint = str_replace('<pun_maint_heading>', $lang_common['Maintenance'], $tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   807
	// END SUBST - <pun_maint_heading>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   808
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   809
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   810
	// START SUBST - <pun_maint_message>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   811
	$tpl_maint = str_replace('<pun_maint_message>', $message, $tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   812
	// END SUBST - <pun_maint_message>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   813
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   814
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   815
	// 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
   816
	$pun_db->end_transaction();
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   817
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   818
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   819
	// 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
   820
	$pun_db->close();
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   821
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   822
	exit($tpl_maint);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   823
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   824
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   825
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   826
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   827
// Display $message and redirect user to $destination_url
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   828
//
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
   829
function pun_redirect($destination_url, $message)
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   830
{
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
   831
	global $pun_db, $pun_config, $lang_common, $pun_user;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   832
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   833
	if ($destination_url == '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   834
		$destination_url = 'index.php';
3
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   835
  
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   836
  if ( preg_match('/^admin_([a-z0-9_]+?)\.php$/i', $destination_url, $match) )
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   837
  {
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   838
    $module = capitalize_first_letter($match[1]);
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   839
    $destination_url = makeUrlNS('Special', 'Forum/Admin_' . $module);
c0c445d4a13e Got some basic security in there, admin panel works now, and most admin panel forms work (used regex mass search + replace)
Dan
parents: 2
diff changeset
   840
  }
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   841
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   842
	// If the delay is 0 seconds, we might as well skip the redirect all together
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   843
	if ($pun_config['o_redirect_delay'] == '0')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   844
		header('Location: '.str_replace('&amp;', '&', $destination_url));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   845
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   846
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   847
	// Load the redirect template
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   848
	$tpl_redir = trim(file_get_contents(PUN_ROOT.'include/template/redirect.tpl'));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   849
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   850
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   851
	// START SUBST - <pun_include "*">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   852
	while (preg_match('#<pun_include "([^/\\\\]*?)\.(php[45]?|inc|html?|txt)">#', $tpl_redir, $cur_include))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   853
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   854
		if (!file_exists(PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2]))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   855
			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
   856
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   857
		ob_start();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   858
		include PUN_ROOT.'include/user/'.$cur_include[1].'.'.$cur_include[2];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   859
		$tpl_temp = ob_get_contents();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   860
		$tpl_redir = str_replace($cur_include[0], $tpl_temp, $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   861
	    ob_end_clean();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   862
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   863
	// END SUBST - <pun_include "*">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   864
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   865
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   866
	// START SUBST - <pun_content_direction>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   867
	$tpl_redir = str_replace('<pun_content_direction>', $lang_common['lang_direction'], $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   868
	// END SUBST - <pun_content_direction>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   869
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   870
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   871
	// START SUBST - <pun_char_encoding>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   872
	$tpl_redir = str_replace('<pun_char_encoding>', $lang_common['lang_encoding'], $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   873
	// END SUBST - <pun_char_encoding>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   874
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   875
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   876
	// START SUBST - <pun_head>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   877
	ob_start();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   878
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   879
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   880
<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
   881
<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
   882
<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
   883
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   884
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   885
	$tpl_temp = trim(ob_get_contents());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   886
	$tpl_redir = str_replace('<pun_head>', $tpl_temp, $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   887
	ob_end_clean();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   888
	// END SUBST - <pun_head>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   889
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   890
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   891
	// START SUBST - <pun_redir_heading>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   892
	$tpl_redir = str_replace('<pun_redir_heading>', $lang_common['Redirecting'], $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   893
	// END SUBST - <pun_redir_heading>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   894
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   895
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   896
	// START SUBST - <pun_redir_text>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   897
	$tpl_temp = $message.'<br /><br />'.'<a href="'.$destination_url.'">'.$lang_common['Click redirect'].'</a>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   898
	$tpl_redir = str_replace('<pun_redir_text>', $tpl_temp, $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   899
	// END SUBST - <pun_redir_text>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   900
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   901
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   902
	// START SUBST - <pun_footer>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   903
	ob_start();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   904
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   905
	// 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
   906
	$pun_db->end_transaction();
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   907
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   908
	// Display executed queries (if enabled)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   909
	if (defined('PUN_SHOW_QUERIES'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   910
		display_saved_queries();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   911
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   912
	$tpl_temp = trim(ob_get_contents());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   913
	$tpl_redir = str_replace('<pun_footer>', $tpl_temp, $tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   914
	ob_end_clean();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   915
	// END SUBST - <pun_footer>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   916
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   917
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   918
	// 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
   919
	$pun_db->close();
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   920
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   921
	exit($tpl_redir);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   922
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   923
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   924
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   925
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   926
// Display a simple error message
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   927
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   928
function error($message, $file, $line, $db_error = false)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   929
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   930
	global $pun_config;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   931
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   932
	// Set a default title if the script failed before $pun_config could be populated
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   933
	if (empty($pun_config))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   934
		$pun_config['o_board_title'] = 'PunBB';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   935
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   936
	// Empty output buffer and stop buffering
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   937
	@ob_end_clean();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   938
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   939
	// "Restart" output buffering if we are using ob_gzhandler (since the gzip header is already sent)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   940
	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
   941
		ob_start('ob_gzhandler');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   942
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   943
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   944
<!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
   945
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   946
<head>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   947
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   948
<title><?php echo pun_htmlspecialchars($pun_config['o_board_title']) ?> / Error</title>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   949
<style type="text/css">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   950
<!--
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   951
BODY {MARGIN: 10% 20% auto 20%; font: 10px Verdana, Arial, Helvetica, sans-serif}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   952
#errorbox {BORDER: 1px solid #B84623}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   953
H2 {MARGIN: 0; COLOR: #FFFFFF; BACKGROUND-COLOR: #B84623; FONT-SIZE: 1.1em; PADDING: 5px 4px}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   954
#errorbox DIV {PADDING: 6px 5px; BACKGROUND-COLOR: #F1F1F1}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   955
-->
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   956
</style>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   957
</head>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   958
<body>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   959
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   960
<div id="errorbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   961
	<h2>An error was encountered</h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   962
	<div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   963
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   964
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   965
	if (defined('PUN_DEBUG'))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   966
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   967
		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
   968
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   969
		if ($db_error)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   970
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   971
			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
   972
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   973
			if ($db_error['error_sql'] != '')
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   974
				echo "\t\t".'<br /><br /><strong>Failed query:</strong> '.pun_htmlspecialchars($db_error['error_sql'])."\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   975
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   976
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   977
	else
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   978
		echo "\t\t".'Error: <strong>'.$message.'.</strong>'."\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   979
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   980
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   981
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   982
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   983
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   984
</body>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   985
</html>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   986
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   987
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   988
	// If a database connection was established (before this error) we close it
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   989
	if ($db_error)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   990
		$GLOBALS['db']->close();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   991
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   992
	exit;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   993
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   994
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   995
// DEBUG FUNCTIONS BELOW
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   996
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   997
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   998
// Display executed queries (if enabled)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
   999
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1000
function display_saved_queries()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1001
{
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
  1002
	global $pun_db, $lang_common;
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1003
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1004
	// 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
  1005
	$saved_queries = $pun_db->get_saved_queries();
0
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1006
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1007
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1008
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1009
<div id="debug" class="blocktable">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1010
	<h2><span><?php echo $lang_common['Debug table'] ?></span></h2>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1011
	<div class="box">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1012
		<div class="inbox">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1013
			<table cellspacing="0">
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1014
			<thead>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1015
				<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1016
					<th class="tcl" scope="col">Time (s)</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1017
					<th class="tcr" scope="col">Query</th>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1018
				</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1019
			</thead>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1020
			<tbody>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1021
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1022
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1023
	$query_time_total = 0.0;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1024
	while (list(, $cur_query) = @each($saved_queries))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1025
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1026
		$query_time_total += $cur_query[1];
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1027
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1028
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1029
				<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1030
					<td class="tcl"><?php echo ($cur_query[1] != 0) ? $cur_query[1] : '&nbsp;' ?></td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1031
					<td class="tcr"><?php echo pun_htmlspecialchars($cur_query[0]) ?></td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1032
				</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1033
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1034
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1035
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1036
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1037
?>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1038
				<tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1039
					<td class="tcl" colspan="2">Total query time: <?php echo $query_time_total ?> s</td>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1040
				</tr>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1041
			</tbody>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1042
			</table>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1043
		</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1044
	</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1045
</div>
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1046
<?php
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1047
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1048
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1049
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1050
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1051
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1052
// Unset any variables instantiated as a result of register_globals being enabled
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1053
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1054
function unregister_globals()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1055
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1056
	$register_globals = @ini_get('register_globals');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1057
	if ($register_globals === "" || $register_globals === "0" || strtolower($register_globals === "off"))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1058
		return;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1059
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1060
	// Prevent script.php?GLOBALS[foo]=bar
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1061
	if (isset($_REQUEST['GLOBALS']) || isset($_FILES['GLOBALS']))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1062
		exit('I\'ll have a steak sandwich and... a steak sandwich.');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1063
	
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1064
	// Variables that shouldn't be unset
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1065
	$no_unset = array('GLOBALS', '_GET', '_POST', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1066
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1067
	// Remove elements in $GLOBALS that are present in any of the superglobals
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1068
	$input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_ENV, $_FILES, isset($_SESSION) && is_array($_SESSION) ? $_SESSION : array());
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1069
	foreach ($input as $k => $v)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1070
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1071
		if (!in_array($k, $no_unset) && isset($GLOBALS[$k]))
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1072
		{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1073
			unset($GLOBALS[$k]);
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1074
			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
  1075
		}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1076
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1077
}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1078
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1079
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1080
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1081
// Dump contents of variable(s)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1082
//
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1083
function dump()
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1084
{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1085
	echo '<pre>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1086
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1087
	$num_args = func_num_args();
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1088
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1089
	for ($i = 0; $i < $num_args; ++$i)
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1090
	{
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1091
		print_r(func_get_arg($i));
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1092
		echo "\n\n";
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1093
	}
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1094
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1095
	echo '</pre>';
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1096
	exit;
f9ffdbd96607 Initial population
Dan
parents:
diff changeset
  1097
}