# HG changeset patch
# User Dan
# Date 1184216641 14400
# Node ID a8a21e1c7afa71495f9c202365a4568b92794b65
# Parent 8f6143115bf5110aa4b2a1898be3453e0732cfd3
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.
diff -r 8f6143115bf5 -r a8a21e1c7afa plugins/PunBB.php
--- a/plugins/PunBB.php Wed Jul 11 21:28:39 2007 -0400
+++ b/plugins/PunBB.php Thu Jul 12 01:04:01 2007 -0400
@@ -30,9 +30,23 @@
\'namespace\'=>\'Special\',
\'special\'=>0,\'visible\'=>1,\'comments_on\'=>0,\'protected\'=>1,\'delvotes\'=>0,\'delvote_ips\'=>\'\',
));
+
');
+$plugins->attachHook('session_started', '
+ $pid = RenderMan::strToPageId($paths->get_pageid_from_url());
+
+ if ( getConfig("punbb_installed") == "yes" && getConfig("punbb_version") == PUNANO_VERSION && $pid[0] == "Forum" && $pid[1] == "Special" )
+ {
+ require( "punbb/include/common.php" );
+ }
+ ');
+
define('PUNANO_VERSION', '0.1.12.15');
+define('PUNBB_VERSION', '1.2.15');
+define('PUN_ROOT', ENANO_ROOT . '/punbb/');
+define('PUN', '');
+define('PUN_DISABLE_BUFFERING', '');
function page_Special_Forum()
{
@@ -63,7 +77,123 @@
$url = makeUrlNS('Special', 'Login/' . $paths->page, 'level=' . USER_LEVEL_ADMIN, true);
redirect($url, 'Permission denied', 'You need to have an active high-privilege session to set up Punano.', 4);
}
+
+ $template->header();
+
// Permissions are good
+ if ( isset($_POST['do_install']) )
+ {
+ $result = _punano_perform_install();
+ if ( $result )
+ {
+ echo '
';
+ }
+ }
+
+ foreach ( $schema as $query )
+ {
+ if ( !$db->sql_query($query) )
+ {
+ echo $db->get_error();
+ return false;
+ }
+ }
+
+ // Insert users
+ $q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users WHERE user_id > 1;');
+ if ( !$q )
+ {
+ echo $db->get_error();
+ return false;
+ }
+ $uid_list = array();
+ while ( $row = $db->fetchrow_num() )
+ {
+ $uid_list[] = $row[0];
+ }
+ $query = 'INSERT INTO '.table_prefix.'pun_users(id) VALUES(' . implode('),(', $uid_list) . ');';
+
+ if ( !$db->sql_query($query) )
+ {
+ echo $db->get_error();
+ return false;
+ }
+
+ setConfig('punbb_installed', 'yes');
+ setConfig('punbb_version', PUNANO_VERSION);
+
+ return true;
+
}
function punano_upgrade()
@@ -76,6 +206,24 @@
{
global $db, $session, $paths, $template, $plugins; // Common objects
+ // At this point, the PunBB API is already loaded
+ // So we'll include one of the Pun frontend files
+
+ $valid = array('delete', 'edit', 'extern', 'help', 'index', 'misc', 'moderate', 'post', 'profile', 'search', 'userlist', 'viewforum', 'viewtopic');
+
+ $file = 'index';
+ if ( $x = $paths->getParam(0) )
+ {
+ $x = preg_replace('/\.php$/', '', $x);
+ if ( in_array(strtolower($x), $valid) )
+ {
+ $file = strtolower($x);
+ }
+ }
+
+ // Don't worry. This is sanitized.
+ require PUN_ROOT . $file . '.php';
+
}
?>
diff -r 8f6143115bf5 -r a8a21e1c7afa punbb/admin_bans.php
--- a/punbb/admin_bans.php Wed Jul 11 21:28:39 2007 -0400
+++ b/punbb/admin_bans.php Thu Jul 12 01:04:01 2007 -0400
@@ -26,12 +26,15 @@
// Tell header.php to use the admin template
define('PUN_ADMIN_CONSOLE', 1);
-define('PUN_ROOT', './');
-require PUN_ROOT.'include/common.php';
+//define('PUN_ROOT', './');
+//require PUN_ROOT.'include/common.php';
+
+global $pun_db, $pun_user, $pun_config, $lang_common;
+
require PUN_ROOT.'include/common_admin.php';
-if ($pun_user['g_id'] > PUN_MOD || ($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_ban_users'] == '0'))
+if ($pun_user['g_id'] < PUN_MOD || ($pun_user['g_id'] == PUN_MOD && $pun_config['p_mod_ban_users'] == '0'))
message($lang_common['No permission']);
@@ -49,9 +52,9 @@
$user_id = $add_ban;
- $result = $db->query('SELECT group_id, username, email FROM '.$db->prefix.'users WHERE id='.$user_id) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
- if ($db->num_rows($result))
- list($group_id, $ban_user, $ban_email) = $db->fetch_row($result);
+ $result = $pun_db->query('SELECT group_id, username, email FROM '.$pun_db->prefix.'users WHERE id='.$user_id) or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
+ if ($pun_db->num_rows($result))
+ list($group_id, $ban_user, $ban_email) = $pun_db->fetch_row($result);
else
message('No user by that ID registered.');
}
@@ -61,9 +64,9 @@
if ($ban_user != '')
{
- $result = $db->query('SELECT id, group_id, username, email FROM '.$db->prefix.'users WHERE username=\''.$db->escape($ban_user).'\' AND id>1') or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());
- if ($db->num_rows($result))
- list($user_id, $group_id, $ban_user, $ban_email) = $db->fetch_row($result);
+ $result = $pun_db->query('SELECT id, group_id, username, email FROM '.$pun_db->prefix.'users WHERE username=\''.$pun_db->escape($ban_user).'\' AND id>1') or error('Unable to fetch user info', __FILE__, __LINE__, $pun_db->error());
+ if ($pun_db->num_rows($result))
+ list($user_id, $group_id, $ban_user, $ban_email) = $pun_db->fetch_row($result);
else
message('No user by that username registered. If you want to add a ban not tied to a specific username just leave the username blank.');
}
@@ -76,8 +79,8 @@
// If we have a $user_id, we can try to find the last known IP of that user
if (isset($user_id))
{
- $result = $db->query('SELECT poster_ip FROM '.$db->prefix.'posts WHERE poster_id='.$user_id.' ORDER BY posted DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
- $ban_ip = ($db->num_rows($result)) ? $db->result($result) : '';
+ $result = $pun_db->query('SELECT poster_ip FROM '.$pun_db->prefix.'posts WHERE poster_id='.$user_id.' ORDER BY posted DESC LIMIT 1') or error('Unable to fetch post info', __FILE__, __LINE__, $pun_db->error());
+ $ban_ip = ($pun_db->num_rows($result)) ? $pun_db->result($result) : '';
}
$mode = 'add';
@@ -88,9 +91,9 @@
if ($ban_id < 1)
message($lang_common['Bad request']);
- $result = $db->query('SELECT username, ip, email, message, expire FROM '.$db->prefix.'bans WHERE id='.$ban_id) or error('Unable to fetch ban info', __FILE__, __LINE__, $db->error());
- if ($db->num_rows($result))
- list($ban_user, $ban_ip, $ban_email, $ban_message, $ban_expire) = $db->fetch_row($result);
+ $result = $pun_db->query('SELECT username, ip, email, message, expire FROM '.$pun_db->prefix.'bans WHERE id='.$ban_id) or error('Unable to fetch ban info', __FILE__, __LINE__, $pun_db->error());
+ if ($pun_db->num_rows($result))
+ list($ban_user, $ban_ip, $ban_email, $ban_message, $ban_expire) = $pun_db->fetch_row($result);
else
message($lang_common['Bad request']);
@@ -238,21 +241,21 @@
else
$ban_expire = 'NULL';
- $ban_user = ($ban_user != '') ? '\''.$db->escape($ban_user).'\'' : 'NULL';
- $ban_ip = ($ban_ip != '') ? '\''.$db->escape($ban_ip).'\'' : 'NULL';
- $ban_email = ($ban_email != '') ? '\''.$db->escape($ban_email).'\'' : 'NULL';
- $ban_message = ($ban_message != '') ? '\''.$db->escape($ban_message).'\'' : 'NULL';
+ $ban_user = ($ban_user != '') ? '\''.$pun_db->escape($ban_user).'\'' : 'NULL';
+ $ban_ip = ($ban_ip != '') ? '\''.$pun_db->escape($ban_ip).'\'' : 'NULL';
+ $ban_email = ($ban_email != '') ? '\''.$pun_db->escape($ban_email).'\'' : 'NULL';
+ $ban_message = ($ban_message != '') ? '\''.$pun_db->escape($ban_message).'\'' : 'NULL';
if ($_POST['mode'] == 'add')
- $db->query('INSERT INTO '.$db->prefix.'bans (username, ip, email, message, expire) VALUES('.$ban_user.', '.$ban_ip.', '.$ban_email.', '.$ban_message.', '.$ban_expire.')') or error('Unable to add ban', __FILE__, __LINE__, $db->error());
+ $pun_db->query('INSERT INTO '.$pun_db->prefix.'bans (username, ip, email, message, expire) VALUES('.$ban_user.', '.$ban_ip.', '.$ban_email.', '.$ban_message.', '.$ban_expire.')') or error('Unable to add ban', __FILE__, __LINE__, $pun_db->error());
else
- $db->query('UPDATE '.$db->prefix.'bans SET username='.$ban_user.', ip='.$ban_ip.', email='.$ban_email.', message='.$ban_message.', expire='.$ban_expire.' WHERE id='.intval($_POST['ban_id'])) or error('Unable to update ban', __FILE__, __LINE__, $db->error());
+ $pun_db->query('UPDATE '.$pun_db->prefix.'bans SET username='.$ban_user.', ip='.$ban_ip.', email='.$ban_email.', message='.$ban_message.', expire='.$ban_expire.' WHERE id='.intval($_POST['ban_id'])) or error('Unable to update ban', __FILE__, __LINE__, $pun_db->error());
// Regenerate the bans cache
require_once PUN_ROOT.'include/cache.php';
generate_bans_cache();
- redirect('admin_bans.php', 'Ban '.(($_POST['mode'] == 'edit') ? 'edited' : 'added').'. Redirecting …');
+ pun_redirect('admin_bans.php', 'Ban '.(($_POST['mode'] == 'edit') ? 'edited' : 'added').'. Redirecting …');
}
@@ -265,13 +268,13 @@
if ($ban_id < 1)
message($lang_common['Bad request']);
- $db->query('DELETE FROM '.$db->prefix.'bans WHERE id='.$ban_id) or error('Unable to delete ban', __FILE__, __LINE__, $db->error());
+ $pun_db->query('DELETE FROM '.$pun_db->prefix.'bans WHERE id='.$ban_id) or error('Unable to delete ban', __FILE__, __LINE__, $pun_db->error());
// Regenerate the bans cache
require_once PUN_ROOT.'include/cache.php';
generate_bans_cache();
- redirect('admin_bans.php', 'Ban removed. Redirecting …');
+ pun_redirect('admin_bans.php', 'Ban removed. Redirecting …');
}
@@ -310,10 +313,10 @@
query('SELECT id, username, ip, email, message, expire FROM '.$db->prefix.'bans ORDER BY id') or error('Unable to fetch ban list', __FILE__, __LINE__, $db->error());
-if ($db->num_rows($result))
+$result = $pun_db->query('SELECT id, username, ip, email, message, expire FROM '.$pun_db->prefix.'bans ORDER BY id') or error('Unable to fetch ban list', __FILE__, __LINE__, $pun_db->error());
+if ($pun_db->num_rows($result))
{
- while ($cur_ban = $db->fetch_assoc($result))
+ while ($cur_ban = $pun_db->fetch_assoc($result))
{
$expire = format_time($cur_ban['expire'], true);
diff -r 8f6143115bf5 -r a8a21e1c7afa punbb/admin_categories.php
--- a/punbb/admin_categories.php Wed Jul 11 21:28:39 2007 -0400
+++ b/punbb/admin_categories.php Thu Jul 12 01:04:01 2007 -0400
@@ -26,12 +26,15 @@
// Tell header.php to use the admin template
define('PUN_ADMIN_CONSOLE', 1);
-define('PUN_ROOT', './');
-require PUN_ROOT.'include/common.php';
+//define('PUN_ROOT', './');
+//require PUN_ROOT.'include/common.php';
+
+global $pun_db, $pun_user, $pun_config, $lang_common;
+
require PUN_ROOT.'include/common_admin.php';
-if ($pun_user['g_id'] > PUN_ADMIN)
+if ($pun_user['g_id'] < PUN_ADMIN)
message($lang_common['No permission']);
@@ -44,9 +47,9 @@
if ($new_cat_name == '')
message('You must enter a name for the category.');
- $db->query('INSERT INTO '.$db->prefix.'categories (cat_name) VALUES(\''.$db->escape($new_cat_name).'\')') or error('Unable to create category', __FILE__, __LINE__, $db->error());
+ $pun_db->query('INSERT INTO '.$pun_db->prefix.'categories (cat_name) VALUES(\''.$pun_db->escape($new_cat_name).'\')') or error('Unable to create category', __FILE__, __LINE__, $pun_db->error());
- redirect('admin_categories.php', 'Category added. Redirecting …');
+ pun_redirect('admin_categories.php', 'Category added. Redirecting …');
}
@@ -63,45 +66,45 @@
{
@set_time_limit(0);
- $result = $db->query('SELECT id FROM '.$db->prefix.'forums WHERE cat_id='.$cat_to_delete) or error('Unable to fetch forum list', __FILE__, __LINE__, $db->error());
- $num_forums = $db->num_rows($result);
+ $result = $pun_db->query('SELECT id FROM '.$pun_db->prefix.'forums WHERE cat_id='.$cat_to_delete) or error('Unable to fetch forum list', __FILE__, __LINE__, $pun_db->error());
+ $num_forums = $pun_db->num_rows($result);
for ($i = 0; $i < $num_forums; ++$i)
{
- $cur_forum = $db->result($result, $i);
+ $cur_forum = $pun_db->result($result, $i);
// Prune all posts and topics
prune($cur_forum, 1, -1);
// Delete the forum
- $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$cur_forum) or error('Unable to delete forum', __FILE__, __LINE__, $db->error());
+ $pun_db->query('DELETE FROM '.$pun_db->prefix.'forums WHERE id='.$cur_forum) or error('Unable to delete forum', __FILE__, __LINE__, $pun_db->error());
}
// Locate any "orphaned redirect topics" and delete them
- $result = $db->query('SELECT t1.id FROM '.$db->prefix.'topics AS t1 LEFT JOIN '.$db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error());
- $num_orphans = $db->num_rows($result);
+ $result = $pun_db->query('SELECT t1.id FROM '.$pun_db->prefix.'topics AS t1 LEFT JOIN '.$pun_db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $pun_db->error());
+ $num_orphans = $pun_db->num_rows($result);
if ($num_orphans)
{
for ($i = 0; $i < $num_orphans; ++$i)
- $orphans[] = $db->result($result, $i);
+ $orphans[] = $pun_db->result($result, $i);
- $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
+ $pun_db->query('DELETE FROM '.$pun_db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $pun_db->error());
}
// Delete the category
- $db->query('DELETE FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to delete category', __FILE__, __LINE__, $db->error());
+ $pun_db->query('DELETE FROM '.$pun_db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to delete category', __FILE__, __LINE__, $pun_db->error());
// Regenerate the quickjump cache
require_once PUN_ROOT.'include/cache.php';
generate_quickjump_cache();
- redirect('admin_categories.php', 'Category deleted. Redirecting …');
+ pun_redirect('admin_categories.php', 'Category deleted. Redirecting …');
}
else // If the user hasn't comfirmed the delete
{
- $result = $db->query('SELECT cat_name FROM '.$db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to fetch category info', __FILE__, __LINE__, $db->error());
- $cat_name = $db->result($result);
+ $result = $pun_db->query('SELECT cat_name FROM '.$pun_db->prefix.'categories WHERE id='.$cat_to_delete) or error('Unable to fetch category info', __FILE__, __LINE__, $pun_db->error());
+ $cat_name = $pun_db->result($result);
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Categories';
require PUN_ROOT.'header.php';
@@ -143,8 +146,8 @@
$cat_order = $_POST['cat_order'];
$cat_name = $_POST['cat_name'];
- $result = $db->query('SELECT id, disp_position FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
- $num_cats = $db->num_rows($result);
+ $result = $pun_db->query('SELECT id, disp_position FROM '.$pun_db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $pun_db->error());
+ $num_cats = $pun_db->num_rows($result);
for ($i = 0; $i < $num_cats; ++$i)
{
@@ -154,25 +157,25 @@
if (!@preg_match('#^\d+$#', $cat_order[$i]))
message('Position must be an integer value.');
- list($cat_id, $position) = $db->fetch_row($result);
+ list($cat_id, $position) = $pun_db->fetch_row($result);
- $db->query('UPDATE '.$db->prefix.'categories SET cat_name=\''.$db->escape($cat_name[$i]).'\', disp_position='.$cat_order[$i].' WHERE id='.$cat_id) or error('Unable to update category', __FILE__, __LINE__, $db->error());
+ $pun_db->query('UPDATE '.$pun_db->prefix.'categories SET cat_name=\''.$pun_db->escape($cat_name[$i]).'\', disp_position='.$cat_order[$i].' WHERE id='.$cat_id) or error('Unable to update category', __FILE__, __LINE__, $pun_db->error());
}
// Regenerate the quickjump cache
require_once PUN_ROOT.'include/cache.php';
generate_quickjump_cache();
- redirect('admin_categories.php', 'Categories updated. Redirecting …');
+ pun_redirect('admin_categories.php', 'Categories updated. Redirecting …');
}
// Generate an array with all categories
-$result = $db->query('SELECT id, cat_name, disp_position FROM '.$db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $db->error());
-$num_cats = $db->num_rows($result);
+$result = $pun_db->query('SELECT id, cat_name, disp_position FROM '.$pun_db->prefix.'categories ORDER BY disp_position') or error('Unable to fetch category list', __FILE__, __LINE__, $pun_db->error());
+$num_cats = $pun_db->num_rows($result);
for ($i = 0; $i < $num_cats; ++$i)
- $cat_list[] = $db->fetch_row($result);
+ $cat_list[] = $pun_db->fetch_row($result);
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Categories';
diff -r 8f6143115bf5 -r a8a21e1c7afa punbb/admin_censoring.php
--- a/punbb/admin_censoring.php Wed Jul 11 21:28:39 2007 -0400
+++ b/punbb/admin_censoring.php Thu Jul 12 01:04:01 2007 -0400
@@ -26,12 +26,15 @@
// Tell header.php to use the admin template
define('PUN_ADMIN_CONSOLE', 1);
-define('PUN_ROOT', './');
-require PUN_ROOT.'include/common.php';
+//define('PUN_ROOT', './');
+//require PUN_ROOT.'include/common.php';
+
+global $pun_db, $pun_user, $pun_config, $lang_common;
+
require PUN_ROOT.'include/common_admin.php';
-if ($pun_user['g_id'] > PUN_MOD)
+if ($pun_user['g_id'] < PUN_MOD)
message($lang_common['No permission']);
@@ -46,9 +49,9 @@
if ($search_for == '' || $replace_with == '')
message('You must enter both a word to censor and text to replace it with.');
- $db->query('INSERT INTO '.$db->prefix.'censoring (search_for, replace_with) VALUES (\''.$db->escape($search_for).'\', \''.$db->escape($replace_with).'\')') or error('Unable to add censor word', __FILE__, __LINE__, $db->error());
+ $pun_db->query('INSERT INTO '.$pun_db->prefix.'censoring (search_for, replace_with) VALUES (\''.$pun_db->escape($search_for).'\', \''.$pun_db->escape($replace_with).'\')') or error('Unable to add censor word', __FILE__, __LINE__, $pun_db->error());
- redirect('admin_censoring.php', 'Censor word added. Redirecting …');
+ pun_redirect('admin_censoring.php', 'Censor word added. Redirecting …');
}
@@ -65,9 +68,9 @@
if ($search_for == '' || $replace_with == '')
message('You must enter both text to search for and text to replace with.');
- $db->query('UPDATE '.$db->prefix.'censoring SET search_for=\''.$db->escape($search_for).'\', replace_with=\''.$db->escape($replace_with).'\' WHERE id='.$id) or error('Unable to update censor word', __FILE__, __LINE__, $db->error());
+ $pun_db->query('UPDATE '.$pun_db->prefix.'censoring SET search_for=\''.$pun_db->escape($search_for).'\', replace_with=\''.$pun_db->escape($replace_with).'\' WHERE id='.$id) or error('Unable to update censor word', __FILE__, __LINE__, $pun_db->error());
- redirect('admin_censoring.php', 'Censor word updated. Redirecting …');
+ pun_redirect('admin_censoring.php', 'Censor word updated. Redirecting …');
}
@@ -78,9 +81,9 @@
$id = intval(key($_POST['remove']));
- $db->query('DELETE FROM '.$db->prefix.'censoring WHERE id='.$id) or error('Unable to delete censor word', __FILE__, __LINE__, $db->error());
+ $pun_db->query('DELETE FROM '.$pun_db->prefix.'censoring WHERE id='.$id) or error('Unable to delete censor word', __FILE__, __LINE__, $pun_db->error());
- redirect('admin_censoring.php', 'Censor word removed. Redirecting …');
+ pun_redirect('admin_censoring.php', 'Censor word removed. Redirecting …');
}
@@ -125,8 +128,8 @@
query('SELECT id, search_for, replace_with FROM '.$db->prefix.'censoring ORDER BY id') or error('Unable to fetch censor word list', __FILE__, __LINE__, $db->error());
-if ($db->num_rows($result))
+$result = $pun_db->query('SELECT id, search_for, replace_with FROM '.$pun_db->prefix.'censoring ORDER BY id') or error('Unable to fetch censor word list', __FILE__, __LINE__, $pun_db->error());
+if ($pun_db->num_rows($result))
{
?>
@@ -141,7 +144,7 @@
fetch_assoc($result))
+ while ($cur_word = $pun_db->fetch_assoc($result))
echo "\t\t\t\t\t\t\t\t".'
'."\n";
?>
diff -r 8f6143115bf5 -r a8a21e1c7afa punbb/admin_forums.php
--- a/punbb/admin_forums.php Wed Jul 11 21:28:39 2007 -0400
+++ b/punbb/admin_forums.php Thu Jul 12 01:04:01 2007 -0400
@@ -26,12 +26,15 @@
// Tell header.php to use the admin template
define('PUN_ADMIN_CONSOLE', 1);
-define('PUN_ROOT', './');
-require PUN_ROOT.'include/common.php';
+//define('PUN_ROOT', './');
+//require PUN_ROOT.'include/common.php';
+
+global $pun_db, $pun_user, $pun_config, $lang_common;
+
require PUN_ROOT.'include/common_admin.php';
-if ($pun_user['g_id'] > PUN_ADMIN)
+if ($pun_user['g_id'] < PUN_ADMIN)
message($lang_common['No permission']);
@@ -44,13 +47,13 @@
if ($add_to_cat < 1)
message($lang_common['Bad request']);
- $db->query('INSERT INTO '.$db->prefix.'forums (cat_id) VALUES('.$add_to_cat.')') or error('Unable to create forum', __FILE__, __LINE__, $db->error());
+ $pun_db->query('INSERT INTO '.$pun_db->prefix.'forums (cat_id) VALUES('.$add_to_cat.')') or error('Unable to create forum', __FILE__, __LINE__, $pun_db->error());
// Regenerate the quickjump cache
require_once PUN_ROOT.'include/cache.php';
generate_quickjump_cache();
- redirect('admin_forums.php', 'Forum added. Redirecting …');
+ pun_redirect('admin_forums.php', 'Forum added. Redirecting …');
}
@@ -71,31 +74,31 @@
prune($forum_id, 1, -1);
// Locate any "orphaned redirect topics" and delete them
- $result = $db->query('SELECT t1.id FROM '.$db->prefix.'topics AS t1 LEFT JOIN '.$db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $db->error());
- $num_orphans = $db->num_rows($result);
+ $result = $pun_db->query('SELECT t1.id FROM '.$pun_db->prefix.'topics AS t1 LEFT JOIN '.$pun_db->prefix.'topics AS t2 ON t1.moved_to=t2.id WHERE t2.id IS NULL AND t1.moved_to IS NOT NULL') or error('Unable to fetch redirect topics', __FILE__, __LINE__, $pun_db->error());
+ $num_orphans = $pun_db->num_rows($result);
if ($num_orphans)
{
for ($i = 0; $i < $num_orphans; ++$i)
- $orphans[] = $db->result($result, $i);
+ $orphans[] = $pun_db->result($result, $i);
- $db->query('DELETE FROM '.$db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $db->error());
+ $pun_db->query('DELETE FROM '.$pun_db->prefix.'topics WHERE id IN('.implode(',', $orphans).')') or error('Unable to delete redirect topics', __FILE__, __LINE__, $pun_db->error());
}
// Delete the forum and any forum specific group permissions
- $db->query('DELETE FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to delete forum', __FILE__, __LINE__, $db->error());
- $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
+ $pun_db->query('DELETE FROM '.$pun_db->prefix.'forums WHERE id='.$forum_id) or error('Unable to delete forum', __FILE__, __LINE__, $pun_db->error());
+ $pun_db->query('DELETE FROM '.$pun_db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $pun_db->error());
// Regenerate the quickjump cache
require_once PUN_ROOT.'include/cache.php';
generate_quickjump_cache();
- redirect('admin_forums.php', 'Forum deleted. Redirecting …');
+ pun_redirect('admin_forums.php', 'Forum deleted. Redirecting …');
}
else // If the user hasn't confirmed the delete
{
- $result = $db->query('SELECT forum_name FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
- $forum_name = pun_htmlspecialchars($db->result($result));
+ $result = $pun_db->query('SELECT forum_name FROM '.$pun_db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $pun_db->error());
+ $forum_name = pun_htmlspecialchars($pun_db->result($result));
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Forums';
@@ -140,14 +143,14 @@
if (!@preg_match('#^\d+$#', $disp_position))
message('Position must be a positive integer value.');
- $db->query('UPDATE '.$db->prefix.'forums SET disp_position='.$disp_position.' WHERE id='.intval($forum_id)) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
+ $pun_db->query('UPDATE '.$pun_db->prefix.'forums SET disp_position='.$disp_position.' WHERE id='.intval($forum_id)) or error('Unable to update forum', __FILE__, __LINE__, $pun_db->error());
}
// Regenerate the quickjump cache
require_once PUN_ROOT.'include/cache.php';
generate_quickjump_cache();
- redirect('admin_forums.php', 'Forums updated. Redirecting …');
+ pun_redirect('admin_forums.php', 'Forums updated. Redirecting …');
}
@@ -175,16 +178,16 @@
if ($cat_id < 1)
message($lang_common['Bad request']);
- $forum_desc = ($forum_desc != '') ? '\''.$db->escape($forum_desc).'\'' : 'NULL';
- $redirect_url = ($redirect_url != '') ? '\''.$db->escape($redirect_url).'\'' : 'NULL';
+ $forum_desc = ($forum_desc != '') ? '\''.$pun_db->escape($forum_desc).'\'' : 'NULL';
+ $redirect_url = ($redirect_url != '') ? '\''.$pun_db->escape($redirect_url).'\'' : 'NULL';
- $db->query('UPDATE '.$db->prefix.'forums SET forum_name=\''.$db->escape($forum_name).'\', forum_desc='.$forum_desc.', redirect_url='.$redirect_url.', sort_by='.$sort_by.', cat_id='.$cat_id.' WHERE id='.$forum_id) or error('Unable to update forum', __FILE__, __LINE__, $db->error());
+ $pun_db->query('UPDATE '.$pun_db->prefix.'forums SET forum_name=\''.$pun_db->escape($forum_name).'\', forum_desc='.$forum_desc.', redirect_url='.$redirect_url.', sort_by='.$sort_by.', cat_id='.$cat_id.' WHERE id='.$forum_id) or error('Unable to update forum', __FILE__, __LINE__, $pun_db->error());
// Now let's deal with the permissions
if (isset($_POST['read_forum_old']))
{
- $result = $db->query('SELECT g_id, g_read_board, g_post_replies, g_post_topics FROM '.$db->prefix.'groups WHERE g_id!='.PUN_ADMIN) or error('Unable to fetch user group list', __FILE__, __LINE__, $db->error());
- while ($cur_group = $db->fetch_assoc($result))
+ $result = $pun_db->query('SELECT g_id, g_read_board, g_post_replies, g_post_topics FROM '.$pun_db->prefix.'groups WHERE g_id!='.PUN_ADMIN) or error('Unable to fetch user group list', __FILE__, __LINE__, $pun_db->error());
+ while ($cur_group = $pun_db->fetch_assoc($result))
{
$read_forum_new = ($cur_group['g_read_board'] == '1') ? isset($_POST['read_forum_new'][$cur_group['g_id']]) ? '1' : '0' : intval($_POST['read_forum_old'][$cur_group['g_id']]);
$post_replies_new = isset($_POST['post_replies_new'][$cur_group['g_id']]) ? '1' : '0';
@@ -195,13 +198,13 @@
{
// If the new settings are identical to the default settings for this group, delete it's row in forum_perms
if ($read_forum_new == '1' && $post_replies_new == $cur_group['g_post_replies'] && $post_topics_new == $cur_group['g_post_topics'])
- $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
+ $pun_db->query('DELETE FROM '.$pun_db->prefix.'forum_perms WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $pun_db->error());
else
{
// Run an UPDATE and see if it affected a row, if not, INSERT
- $db->query('UPDATE '.$db->prefix.'forum_perms SET read_forum='.$read_forum_new.', post_replies='.$post_replies_new.', post_topics='.$post_topics_new.' WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id) or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error());
- if (!$db->affected_rows())
- $db->query('INSERT INTO '.$db->prefix.'forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) VALUES('.$cur_group['g_id'].', '.$forum_id.', '.$read_forum_new.', '.$post_replies_new.', '.$post_topics_new.')') or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error());
+ $pun_db->query('UPDATE '.$pun_db->prefix.'forum_perms SET read_forum='.$read_forum_new.', post_replies='.$post_replies_new.', post_topics='.$post_topics_new.' WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id) or error('Unable to insert group forum permissions', __FILE__, __LINE__, $pun_db->error());
+ if (!$pun_db->affected_rows())
+ $pun_db->query('INSERT INTO '.$pun_db->prefix.'forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) VALUES('.$cur_group['g_id'].', '.$forum_id.', '.$read_forum_new.', '.$post_replies_new.', '.$post_topics_new.')') or error('Unable to insert group forum permissions', __FILE__, __LINE__, $pun_db->error());
}
}
}
@@ -211,28 +214,28 @@
require_once PUN_ROOT.'include/cache.php';
generate_quickjump_cache();
- redirect('admin_forums.php', 'Forum updated. Redirecting …');
+ pun_redirect('admin_forums.php', 'Forum updated. Redirecting …');
}
else if (isset($_POST['revert_perms']))
{
confirm_referrer('admin_forums.php');
- $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error());
+ $pun_db->query('DELETE FROM '.$pun_db->prefix.'forum_perms WHERE forum_id='.$forum_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $pun_db->error());
// Regenerate the quickjump cache
require_once PUN_ROOT.'include/cache.php';
generate_quickjump_cache();
- redirect('admin_forums.php?edit_forum='.$forum_id, 'Permissions reverted to defaults. Redirecting …');
+ pun_redirect('admin_forums.php?edit_forum='.$forum_id, 'Permissions reverted to defaults. Redirecting …');
}
// Fetch forum info
- $result = $db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id FROM '.$db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $db->error());
- if (!$db->num_rows($result))
+ $result = $pun_db->query('SELECT id, forum_name, forum_desc, redirect_url, num_topics, sort_by, cat_id FROM '.$pun_db->prefix.'forums WHERE id='.$forum_id) or error('Unable to fetch forum info', __FILE__, __LINE__, $pun_db->error());
+ if (!$pun_db->num_rows($result))
message($lang_common['Bad request']);
- $cur_forum = $db->fetch_assoc($result);
+ $cur_forum = $pun_db->fetch_assoc($result);
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / Admin / Forums';
@@ -265,8 +268,8 @@