More progress, compatibility updates for 1.1.4, etc.
authorDan
Sun, 15 Jun 2008 01:42:31 -0400
changeset 9 a932ce8c4827
parent 8 8baccbad4a55
child 10 98d80b672f3c
More progress, compatibility updates for 1.1.4, etc.
plugins/PunBB.php
punbb/admin/extensions.php
punbb/admin/forums.php
punbb/admin/users.php
punbb/footer.php
punbb/header.php
punbb/include/common_admin.php
punbb/include/essentials.php
punbb/include/functions.php
punbb/install-mysql.sql
punbb/lang/English/admin.php
punbb/rewrite.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();
+}
+
 ?>
--- 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 @@
 		<div class="frm-head">
 			<h2><span><?php echo $lang_admin['Installed extensions'] ?></span></h2>
 		</div>
+    
+    <div class="frm-info">
+			<p class="warn"><?php echo $lang_admin['Installed extensions Enano compat warn'] ?></p>
+		</div>
+    
 <?php
 
 	if (!empty($inst_exts))
--- a/punbb/admin/forums.php	Sun Apr 06 00:35:38 2008 -0400
+++ b/punbb/admin/forums.php	Sun Jun 15 01:42:31 2008 -0400
@@ -82,7 +82,7 @@
 	$forum_to_delete = intval($_GET['del_forum']);
 	if ($forum_to_delete < 1)
 		message($lang_common['Bad request']);
-
+  
 	// User pressed the cancel button
 	if (isset($_POST['del_forum_cancel']))
 		pun_redirect(pun_link($pun_url['admin_forums']), $lang_admin['Cancel redirect']);
@@ -97,7 +97,7 @@
 		prune($forum_to_delete, 1, -1);
 
 		delete_orphans();
-
+    
 		// Delete the forum and any forum specific group permissions
 		$query = array(
 			'DELETE'	=> '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 @@
 		<div class="frm-head">
 			<h2><span><?php printf($lang_admin['Confirm delete forum'], htmlspecialchars($forum_name)) ?></span></h2>
 		</div>
-		<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_forums']) ?>&amp;del_forum=<?php echo $forum_id ?>">
+		<form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo pun_link($pun_url['admin_forums']) ?>&amp;del_forum=<?php echo $forum_to_delete ?>">
 			<div class="hidden">
-				<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_forums']).'&del_forum='.$forum_id) ?>" />
+				<input type="hidden" name="csrf_token" value="<?php echo generate_form_token(pun_link($pun_url['admin_forums']).'&del_forum='.$forum_to_delete) ?>" />
 			</div>
 			<div class="frm-info">
 				<p class="warn"><?php echo $lang_admin['Delete forum warning'] ?></p>
--- 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;
--- 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();
+
--- 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 '<meta name="microid" content="mailto+http:sha1:'.sha1(sha1('mailto:'.$user['email']).sha1(pun_link($pun_url['user'], $id))).'" />'."\n";
 
-?>
-<title><?php echo generate_crumbs(true) ?></title>
-<?php
+// Generate the page title (really hackish Enano specific trick)
+$enano_template =& $GLOBALS['template'];
+$enano_template->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 - <!-- pun_head -->
 
 
@@ -147,13 +149,13 @@
 // END SUBST - <!-- pun_skip -->
 
 // START SUBST - <!-- pun_title -->
-$tpl_main = str_replace('<!-- pun_title -->', '<div id="pun-title">'."\n\t".'<div><strong>'.htmlspecialchars($pun_config['o_board_title']).'</strong></div>'."\n".'</div>'."\n", $tpl_main);
+$tpl_main = str_replace('<!-- pun_title -->', '', $tpl_main); // '<div id="pun-title">'."\n\t".'<div><strong>'.htmlspecialchars($pun_config['o_board_title']).'</strong></div>'."\n".'</div>'."\n", $tpl_main);
 // END SUBST - <!-- pun_title -->
 
 
 // START SUBST - <!-- pun_desc -->
 if ($pun_config['o_board_desc'] != '')
-	$tpl_main = str_replace('<!-- pun_desc -->', '<div id="pun-desc">'."\n\t".'<div>'.htmlspecialchars($pun_config['o_board_desc']).'</div>'."\n".'</div>'."\n", $tpl_main);
+	$tpl_main = str_replace('<!-- pun_desc -->', '', $tpl_main); // '<div id="pun-desc">'."\n\t".'<div>'.htmlspecialchars($pun_config['o_board_desc']).'</div>'."\n".'</div>'."\n", $tpl_main);
 // END SUBST - <!-- pun_desc -->
 
 
--- 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)
--- 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!
--- 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[] = '<li id="navindex"'.((PUN_PAGE == 'index') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['index']).'"><span>'.$lang_common['Index'].'</span></a></li>';
@@ -533,7 +539,7 @@
 			$links[] = '<li id="navsearch"'.((PUN_PAGE == 'search') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['search']).'"><span>'.$lang_common['Search'].'</span></a></li>';
 
 		$links[] = '<li id="navregister"'.((PUN_PAGE == 'register') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['register']).'"><span>'.$lang_common['Register'].'</span></a></li>';
-		$links[] = '<li id="navlogin"'.((PUN_PAGE == 'login') ? ' class="isactive"' : '').'><a href="'.pun_link($pun_url['login']).'"><span>'.$lang_common['Login'].'</span></a></li>';
+		$links[] = '<li id="navlogin"'.((PUN_PAGE == 'login') ? ' class="isactive"' : '').'><a href="'.makeUrlNS('Special', 'Login/' . $paths->fullpage).'" onclick="ajaxStartLogin(); return false;"><span>'.$lang_common['Login'].'</span></a></li>';
 	}
 	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']);
--- 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);
--- 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'		=>	'<strong>WARNING!</strong> 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' => '<strong>WARNING!</strong> 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"?',
--- 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', '<p>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 <a href="' . makeUrlNS('Special', 'Forum') . '">forum index</a>.</p>');
 }
 
 // We change $_SERVER['PHP_SELF'] so that it reflects the file we're actually loading