# HG changeset patch # User Dan # Date 1213508551 14400 # Node ID a932ce8c4827d5bec13b2ad33efc5b298c93e617 # Parent 8baccbad4a5585d524478aec9ee8d0c97b9caedc More progress, compatibility updates for 1.1.4, etc. diff -r 8baccbad4a55 -r a932ce8c4827 plugins/PunBB.php --- a/plugins/PunBB.php Sun Apr 06 00:35:38 2008 -0400 +++ b/plugins/PunBB.php Sun Jun 15 01:42:31 2008 -0400 @@ -43,6 +43,8 @@ } '); +$plugins->attachHook('user_registered', 'pun_handle_reg_event($user_id, $username);'); + define('PUNANO_VERSION', '0.1.3-beta'); define('PUNBB_VERSION', '1.3-beta'); define('PUN_ROOT', ENANO_ROOT . '/punbb/'); @@ -88,7 +90,7 @@ else if ( $session->auth_level < USER_LEVEL_ADMIN ) { $url = makeUrlNS('Special', 'Login/' . $paths->page, 'level=' . USER_LEVEL_ADMIN, true); - pun_redirect($url, 'Permission denied', 'You need to have an active high-privilege session to set up Punano.', 4); + redirect($url, 'Permission denied', 'You need to have an active high-privilege session to set up Punano.', 4); } $template->header(); @@ -186,7 +188,7 @@ } // Insert users - $q = $db->sql_query('SELECT user_id FROM '.table_prefix.'users WHERE user_id > 1;'); + $q = $db->sql_query('SELECT user_id, user_level FROM '.table_prefix.'users WHERE user_id > 1;'); if ( !$q ) { echo $db->get_error(); @@ -195,9 +197,15 @@ $uid_list = array(); while ( $row = $db->fetchrow_num() ) { - $uid_list[] = $row[0]; + $g_id = 4; + switch ( $row[1] ) + { + case USER_LEVEL_ADMIN: $g_id = 1; break; + case USER_LEVEL_MOD: $g_id = 3; break; + } + $uid_list[] = "{$row[0]}, {$g_id}"; } - $query = 'INSERT INTO '.table_prefix.'pun_users(id) VALUES(' . implode('),(', $uid_list) . ');'; + $query = 'INSERT INTO '.table_prefix.'pun_users(id, group_id) VALUES(' . implode('),(', $uid_list) . ');'; if ( !$db->sql_query($query) ) { @@ -283,4 +291,19 @@ } +function pun_handle_reg_event($user_id, $username) +{ + global $db, $session, $paths, $template, $plugins; // Common objects + if ( getConfig('punbb_installed') != 'yes' ) + { + return false; + } + + // register the new user in PunBB + // at this point $username has been SQL-injection-proofed already by the session manager + $q = $db->sql_query('INSERT INTO ' . table_prefix . "pun_users ( id, username ) VALUES ( $user_id, '$username' );"); + if ( !$q ) + $db->_die(); +} + ?> diff -r 8baccbad4a55 -r a932ce8c4827 punbb/admin/extensions.php --- a/punbb/admin/extensions.php Sun Apr 06 00:35:38 2008 -0400 +++ b/punbb/admin/extensions.php Sun Jun 15 01:42:31 2008 -0400 @@ -685,6 +685,11 @@

+ +
+

+
+ 'forums', @@ -106,7 +106,7 @@ ($hook = get_hook('afo_qr_delete_forum')) ? eval($hook) : null; $pun_db->query_build($query) or error(__FILE__, __LINE__); - + $query = array( 'DELETE' => 'forum_perms', 'WHERE' => 'forum_id='.$forum_to_delete @@ -114,11 +114,11 @@ ($hook = get_hook('afo_qr_delete_forum_perms')) ? eval($hook) : null; $pun_db->query_build($query) or error(__FILE__, __LINE__); - + // Regenerate the quickjump cache require_once PUN_ROOT.'include/cache.php'; generate_quickjump_cache(); - + pun_redirect(pun_link($pun_url['admin_forums']), $lang_admin['Forum deleted'].' '.$lang_admin['Redirect']); } else // If the user hasn't confirmed the delete @@ -161,9 +161,9 @@

-
+

diff -r 8baccbad4a55 -r a932ce8c4827 punbb/admin/users.php --- a/punbb/admin/users.php Sun Apr 06 00:35:38 2008 -0400 +++ b/punbb/admin/users.php Sun Jun 15 01:42:31 2008 -0400 @@ -748,8 +748,9 @@ $like_command = ($db_type == 'pgsql') ? 'ILIKE' : 'LIKE'; while (list($key, $input) = @each($form)) { + $e = ( $key == 'username' ) ? 'e' : ''; if ($input != '' && in_array($key, array('username', 'email', 'title', 'realname', 'url', 'jabber', 'icq', 'msn', 'aim', 'yahoo', 'location', 'signature', 'admin_note'))) - $conditions[] = 'u.'.$pun_db->escape($key).' '.$like_command.' \''.$pun_db->escape(str_replace('*', '%', $input)).'\''; + $conditions[] = $e . 'u.'.$pun_db->escape($key).' '.$like_command.' \''.$pun_db->escape(str_replace('*', '%', $input)).'\''; } if ($posts_greater != '') @@ -769,16 +770,23 @@ // Find any users matching the conditions $query = array( - 'SELECT' => 'u.id, u.username, u.email, u.title, u.num_posts, u.admin_note, g.g_id, g.g_user_title', - 'FROM' => 'users AS u', + 'SELECT' => 'u.id, eu.username, u.email, u.title, u.num_posts, u.admin_note, g.g_id, g.g_user_title', + 'FROM' => $pun_db->prefix . 'users AS u', 'JOINS' => array( array( - 'LEFT JOIN' => 'groups AS g', + 'LEFT JOIN' => $pun_db->prefix . 'groups AS g', 'ON' => 'g.g_id=u.group_id' - ) + ), + array( + 'LEFT JOIN' => table_prefix . 'users AS eu', + 'ON' => 'eu.user_id = u.id' + ) ), 'WHERE' => 'u.id>1 AND '.implode(' AND ', $conditions), - 'ORDER BY' => $pun_db->escape($order_by).' '.$pun_db->escape($direction) + 'ORDER BY' => $pun_db->escape($order_by).' '.$pun_db->escape($direction), + 'PARAMS' => array( + 'NO_PREFIX' => '' + ) ); ($hook = get_hook('aus_qr_find_users')) ? eval($hook) : null; diff -r 8baccbad4a55 -r a932ce8c4827 punbb/footer.php --- a/punbb/footer.php Sun Apr 06 00:35:38 2008 -0400 +++ b/punbb/footer.php Sun Jun 15 01:42:31 2008 -0400 @@ -215,7 +215,11 @@ $pun_db->close(); // Spit out the page -global $template; +global $template, $db; $template->header(); echo($tpl_main); $template->footer(); + +$db->close(); +exit(); + diff -r 8baccbad4a55 -r a932ce8c4827 punbb/header.php --- a/punbb/header.php Sun Apr 06 00:35:38 2008 -0400 +++ b/punbb/header.php Sun Jun 15 01:42:31 2008 -0400 @@ -75,9 +75,9 @@ if (strpos(PUN_PAGE, 'profile') === 0) echo ''."\n"; -?> -<?php echo generate_crumbs(true) ?> -tpl_strings['PAGE_NAME'] = generate_crumbs(true); // Should we output feed links? if (PUN_PAGE == 'viewtopic') @@ -132,8 +132,10 @@ ($hook = get_hook('hd_head')) ? eval($hook) : null; $tpl_temp = trim(ob_get_contents()); + $template->add_header($tpl_temp); ob_end_clean(); + // END SUBST - @@ -147,13 +149,13 @@ // END SUBST - // START SUBST - -$tpl_main = str_replace('', '
'."\n\t".'
'.htmlspecialchars($pun_config['o_board_title']).'
'."\n".'
'."\n", $tpl_main); +$tpl_main = str_replace('', '', $tpl_main); // '
'."\n\t".'
'.htmlspecialchars($pun_config['o_board_title']).'
'."\n".'
'."\n", $tpl_main); // END SUBST - // START SUBST - if ($pun_config['o_board_desc'] != '') - $tpl_main = str_replace('', '
'."\n\t".'
'.htmlspecialchars($pun_config['o_board_desc']).'
'."\n".'
'."\n", $tpl_main); + $tpl_main = str_replace('', '', $tpl_main); // '
'."\n\t".'
'.htmlspecialchars($pun_config['o_board_desc']).'
'."\n".'
'."\n", $tpl_main); // END SUBST - diff -r 8baccbad4a55 -r a932ce8c4827 punbb/include/common_admin.php --- a/punbb/include/common_admin.php Sun Apr 06 00:35:38 2008 -0400 +++ b/punbb/include/common_admin.php Sun Jun 15 01:42:31 2008 -0400 @@ -135,7 +135,7 @@ 'FROM' => 'topics AS t', 'WHERE' => 't.forum_id='.$forum_id ); - + if ($prune_date != -1) $query['WHERE'] .= ' AND last_post<'.$prune_date; if (!$prune_sticky) diff -r 8baccbad4a55 -r a932ce8c4827 punbb/include/essentials.php --- a/punbb/include/essentials.php Sun Apr 06 00:35:38 2008 -0400 +++ b/punbb/include/essentials.php Sun Jun 15 01:42:31 2008 -0400 @@ -24,7 +24,7 @@ // Enable DEBUG mode by removing // from the following line -define('PUN_DEBUG', 1); +// define('PUN_DEBUG', 1); // This displays all executed queries in the page footer. // DO NOT enable this in a production environment! diff -r 8baccbad4a55 -r a932ce8c4827 punbb/include/functions.php --- a/punbb/include/functions.php Sun Apr 06 00:35:38 2008 -0400 +++ b/punbb/include/functions.php Sun Jun 15 01:42:31 2008 -0400 @@ -90,7 +90,7 @@ // Check if there's a user matching $user and $password $query = array( - 'SELECT' => 'eu.username AS username_authoritative, u.*, u.username AS bla, g.*, o.logged, o.idle, o.csrf_token, o.prev_url', + 'SELECT' => 'u.*, eu.username, eu.user_id as id, g.*, o.logged, o.idle, o.csrf_token, o.prev_url', 'FROM' => $pun_db->prefix . 'users AS u', 'JOINS' => array( array( @@ -116,8 +116,13 @@ ($hook = get_hook('fn_qr_get_user')) ? eval($hook) : null; $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); + $count = $pun_db->num_rows($result); + if ( $count < 1 ) + { + set_default_user(); + return false; + } $pun_user = $pun_db->fetch_assoc($result); - $pun_user['username'] =& $pun_user['username_authoritative']; if (!$session->user_logged_in) set_default_user(); @@ -517,6 +522,7 @@ function generate_navlinks() { global $pun_config, $lang_common, $pun_url, $pun_user; + global $db, $session, $paths, $template, $plugins; // Common objects // Index should always be displayed $links[] = ''; @@ -533,7 +539,7 @@ $links[] = ''; $links[] = ''; - $links[] = ''; + $links[] = ''; } else { @@ -1832,7 +1838,7 @@ function csrf_confirm_form() { global $pun_db, $pun_url, $lang_common, $pun_config, $base_url, $pun_start, $tpl_main, $pun_user, $pun_page, $pun_updates; - + // User pressed the cancel button if (isset($_POST['confirm_cancel'])) pun_redirect(htmlspecialchars($_POST['prev_url']), $lang_common['Cancel redirect']); diff -r 8baccbad4a55 -r a932ce8c4827 punbb/install-mysql.sql --- a/punbb/install-mysql.sql Sun Apr 06 00:35:38 2008 -0400 +++ b/punbb/install-mysql.sql Sun Jun 15 01:42:31 2008 -0400 @@ -303,8 +303,8 @@ INSERT INTO {{TABLE_PREFIX}}groups (g_title, g_user_title, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_set_title, g_search, g_search_users, g_edit_subjects_interval, g_post_flood, g_search_flood) VALUES ('Administrators', 'Administrator', 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0), ('Guest', NULL, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0), - ('Members', NULL, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 300, 60, 30), - ('Moderators', 'Moderator', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0); + ('Moderators', 'Moderator', 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0), + ('Members', NULL, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 300, 60, 30); INSERT INTO {{TABLE_PREFIX}}forums (forum_name, forum_desc, num_topics, num_posts, last_post, last_post_id, last_poster, disp_position, cat_id) VALUES('Test forum', 'This is just a test forum', 1, 1, {{NOW}}, 1, 'Enano', 1, 1); INSERT INTO {{TABLE_PREFIX}}topics (poster, subject, posted, first_post_id, last_post, last_post_id, last_poster, forum_id) VALUES('Enano', 'Test post', {{NOW}}, 1, {{NOW}}, 1, 'Enano', 1); diff -r 8baccbad4a55 -r a932ce8c4827 punbb/lang/English/admin.php --- a/punbb/lang/English/admin.php Sun Apr 06 00:35:38 2008 -0400 +++ b/punbb/lang/English/admin.php Sun Jun 15 01:42:31 2008 -0400 @@ -154,6 +154,7 @@ 'Extensions available' => 'Extensions available for install', 'Installed extensions' => 'Installed extensions', 'Installed extensions warn' => 'WARNING! If you uninstall an extension, any data associated with that extension will be permanently deleted from the database and cannot be restored by re-installing the extension. If you wish to retain the data then you should disable the extension instead.', +'Installed extensions Enano compat warn' => 'WARNING! While the PunBB extension API is left mostly untouched in the Enano port, some core parts have been changed, the most prominent one being the transition from $db to $pun_db for the name of the database singleton. If you try to install an extension that hasn\'t been ported to the Enano bridge, you will likely experience problems.', 'Uninstall extension' => 'Uninstall extension', 'Uninstall' => 'Uninstall', 'Uninstall extension confirm' => 'Are you sure you want to uninstall the extension "%s"?', diff -r 8baccbad4a55 -r a932ce8c4827 punbb/rewrite.php --- a/punbb/rewrite.php Sun Apr 06 00:35:38 2008 -0400 +++ b/punbb/rewrite.php Sun Jun 15 01:42:31 2008 -0400 @@ -89,12 +89,12 @@ // If we don't know what to rewrite to, we show a bad request messsage if (empty($rewritten_url)) { - header('HTTP/1.x 404 Not Found'); + header('HTTP/1.1 404 Not Found'); // Allow an extension to override the "Bad request" message with a custom 404 page ($hook = get_hook('re_page_not_found')) ? eval($hook) : null; - exit('Bad request'); + die_friendly('Page not found', '

You have requested a forum URL that is invalid. Please press your browser\'s Back button to return to the page from whence you came, or return to the forum index.

'); } // We change $_SERVER['PHP_SELF'] so that it reflects the file we're actually loading