By alexic on
Hello,
I'm running a drupal 5.x installation with phpbb module in order to achive an integration between the forum and drupal.
My problem is that i change the default home page (node) with something else, after the login drupal redirct the user to the forum profile page instead of the home page that i setted. If i leave "node" everything is fine.
I talked with the developer and we think that the problem is drupal-related and not module-related. The module implements the hook_user function.
here's the module code.
<?php
/**
* http://drupal.org/project/phpbb
* Copyright 2007, Arne Kepp 2007
* This work is licensed under the GNU GPL, see LICENSE.txt
*
* Many thanks to (Drupal.org users): Jimbo, brdwo, sfurman, maartenvg
*/
// This file contains the configuration for the link.
require_once('configuration.inc');
/**
* Implementation of hook_user
*/
function phpbb_user($op, &$edit, &$user, $category = NULL) {
global $phpbbcfg;
switch ($op) {
case 'insert':
// Inserts a new user into the phpBB database
//Check that there is no collision
if(_phpbb_knows_user($edit['uid'])) {
watchdog('phpBB', 'Attempt to insert user with id '.$edit['uid'].', but this user already exists in the phpBB database. Aborted, but you now have incosistent databases!',WATCHDOG_ERROR);
die('There is a problem with the system. Ask the administrator to check the watchdog log.');
}
// Get the board timezone
$query = "SELECT * FROM {$phpbbcfg['db_config']} WHERE `config_name` = 'board_timezone'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$row = db_fetch_array($res);
$timezone = $row['config_value'];
// Get the default language
$query = "SELECT * FROM {$phpbbcfg['db_config']} WHERE `config_name` = 'default_lang'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$row = db_fetch_array($res);
$language = $row['config_value'];
// Get the group for registered users
$query = "SELECT * FROM {$phpbbcfg['db_groups']} WHERE `group_name` = 'REGISTERED'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$row = db_fetch_array($res);
$gid = $row['group_id'];
// The stuff below is all to get hold of utf8_clean_string()
global $phpbb_root_path, $phpEx;
$phpbb_root_path = $phpbbcfg['path_rel'];
$phpEx = 'php';
@define('IN_PHPBB', true);
$utf_tool_path = $phpbbcfg['path_rel'] . 'includes/utf/';
require_once($utf_tool_path . 'utf_normalizer.php');
require_once($utf_tool_path . 'utf_tools.php');
// Insert a minimal user.
$query = "INSERT INTO {$phpbbcfg['db_users']} "
."(`user_id`,`group_id`,`username`,`username_clean`,`user_password`,"
."`user_regdate`,`user_email`,`user_options`,`user_lang`,`user_timezone`) "
." VALUES({$edit['uid']},$gid,'{$edit['name']}','".utf8_clean_string($edit['name'])."','"
.md5($edit['pass']) ."',". time() .",'{$edit['mail']}','853','$language',$timezone)";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
// Insert the user into the group_name = REGISTERED group
$query = "INSERT INTO {$phpbbcfg['db_user_group']} "
."(`group_id`,`user_id`,`group_leader`,`user_pending`)"
." VALUES( $gid, {$edit['uid']}, 0, 0)";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
// Update newest user on the front of the forum
$query = "UPDATE {$phpbbcfg['db_config']} SET `config_value` = {$edit['uid']} WHERE `config_name` = 'newest_user_id'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$query = "UPDATE {$phpbbcfg['db_config']} SET `config_value` = '{$edit['name']}' WHERE `config_name` = 'newest_username'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
// Increment total number of users
$query = "UPDATE {$phpbbcfg['db_config']} SET config_value = config_value + 1 WHERE `config_name` = 'num_users'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
break;
case 'form':
// Catches password resets, including the first one after registering.
if(! user_access('edit drupal users') ) {
if( strpos($_SERVER['HTTP_REFERER'], 'user/reset')) {
drupal_goto('phpbb/passwdreset');
} else {
header('Location: '.$phpbbcfg['path_abs'].'memberlist.php?mode=viewprofile&u='.$user->uid, TRUE, 301);
}
exit();
}
break;
case 'update':
// Unless the user has access to editing Drupal users, we redirect to the phpBB module
if(! user_access('edit drupal users') ) {
header('Location: '.$phpbbcfg['path_abs'].'memberlist.php?mode=viewprofile&u='.$user->uid, TRUE, 301);
exit();
}
break;
case 'delete':
// Code for deleting user from phpBB has been removed, difficult to mimic functionality of phpBB in Drupal
_phpbb_session_destroy();
break;
case 'login':
// If this is Drupals main admin we dont set cookies
if($edit['uid'] == 1 || $user->uid == 1) {
drupal_set_message('(The superuser is never logged into phpBB)', 'status');
return;
}
// Creates the cookies and session in phpBBs database
$phpbb_username = _phpbb_knows_user($user->uid);
// Check whether this user is known in phpBB
if(! $phpbb_username) {
watchdog('phpBB', 'Inserting previously unknown user '.$edit['uid'],WATCHDOG_NOTICE);
$new_edit = array();
$new_edit['uid'] = $user->uid;
$new_edit['mail'] = $user->mail;
$new_edit['name'] = $user->name;
phpbb_user('insert',$new_edit,$user);
// Check whether this user is in sync with phpBB
} else if($phpbb_username && $phpbb_username != $user->name) {
watchdog('phpBB', 'User with id '.$user->uid.' is '.$user->name.', but '.$phpbb_username.' in phpBB. Stopping login attempt.',WATCHDOG_ERROR);
drupal_set_message('There is a problem with the system. Ask the administrator to check the watchdog log.', 'status');
return;
}
// Everything ok, actually create the session
$session_key = _phpbb_random()._phpbb_random();
$session_key = substr($session_key,0,32); // Just in case
$phpbb_cookie_name = _phpbb_cookie_name();
_phpbb_insert_db_session($session_key);
// Fetch session_id and session_key here, so we can delete the correct sessions?
_phpbb_set_cookies($phpbb_cookie_name, $session_key);
// Don't worry about the lines below. $phpbbcfg['i1'] should be set to false.
if($phpbbcfg['i1']) {
$query = "SELECT user_primary_forum FROM {$phpbbcfg['db_users']} WHERE user_id = ".$user->uid;
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$row = db_fetch_array($res);
if(! $row['user_primary_forum'] || $row['user_primary_forum'] == "") {
require_once('forum/includes/functions_i1.php');
$query = "UPDATE {$phpbbcfg['db_users']} SET user_primary_forum = '" .$short_conv[$_SERVER['SERVER_NAME']] . "'"
." WHERE `user_id` = ".$user->uid;
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
}
}
break;
case 'logout':
// Destroys the sessions in phpBBs database and unsets the cookies.
_phpbb_session_destroy();
break;
case 'view':
// Code removed, use phpBB's profile instead
if(! user_access('edit drupal users') ) {
header('Location: '.$phpbbcfg['path_abs'].'memberlist.php?mode=viewprofile&u='.$user->uid, TRUE, 301);
exit();
}
break;
}
return $output;
}
/**
* Implementation of hook_perm().
*/
function phpbb_perm() {
return array('administer phpbb','edit drupal users');
}
/**
* Implementation of hook_block
*
*/
function phpbb_block($op = 'list', $delta = 0, $edit = array() ) {
global $phpbbcfg;
$block = array();
if ($op == 'list') {
$block[0]['info'] = $phpbbcfg['block0_title'];
$block[1]['info'] = $phpbbcfg['block1_title'];
} else if ($op == 'view') {
switch ($delta) {
case 0:
$block['subject'] = $phpbbcfg['block0_title'];
$block['content'] = _phpbb_display_block_0();
break;
case 1:
$block['subject'] = $phpbbcfg['block1_title'];
$block['content'] = _phpbb_display_block_1();
break;
//case 1:
//Not used
//break;
}
}
return $block;
}
/**
* Implementation of hook_menu().
*/
function phpbb_menu($may_cache) {
global $user, $phpbbcfg;
if ($may_cache) {
$items[] = array(
'path' => 'phpbb',
'title' => t('phpbb'),
'callback' => 'phpbb_view',
'access' => TRUE,
'type' => MENU_CALLBACK
);
} else {
$new = 0;
// Show private messages?
$new = _phpbb_pm_count($user->uid);
$items[] = array(
'path' => $phpbbcfg['path_rel'].'inbox',
'title' => t($phpbbcfg['pm_title']) . ($new ? ' ('. $new .')' : ''),
'callback' => 'phpbb_view',
'access' => $user->uid ? TRUE : FALSE,
'type' => $user->uid ? MENU_DYNAMIC_ITEM : MENU_CALLBACK
);
}
return $items;
}
/**
* Menu callback; presents the phpbbsup form and/or phpbbsup results.
* Doesn't this interfere with hook_view? At least it's confusing
*/
function phpbb_view() {
global $user, $phpbbcfg;
if(isset($_POST['username']) && isset($_POST['password'])) {
// This is a login originating from the forum
_phpbb_forum_login();
// exits by itself
}
switch(arg(1)) {
case 'logout':
// This is a logout request from somewhere, we don't care where
_phpbb_logout();
break;
case 'bypass':
// This is to let the user login users that exist only in phpbb, e.g. the main admin
$retstr =
'<form method="post" action="'.$phpbbcfg['path_abs'].'ucp.php?bypass=true&mode=login">'
.'Username:</label> <input name="username" id="username" size="10" class="inputbox" title="Username" type="text"></br>'
.'Password:</label> <input name="password" id="password" size="10" class="inputbox" title="Password" type="password"></br>'
.'<input name="login" value="Login" class="button2" type="submit">'
.'</form>';
return $retstr;
break;
case 'passwdreset':
// This is a password reset request, the user needs to be logged in
if($user->uid > 0) {
return drupal_get_form('_phpbb_form_passwd_reset');
} else {
return 'Trying to reset a password without being logged in?';
}
break;
case 'login':
//Just a login, try to redirect afterwards
header('Location: ../user/login?destination='.$phpbbcfg['path_rel'], TRUE, 302);
exit();
break;
case 'diagnostic':
return _phpbb_diagnostic();
break;
default:
if(substr(arg(1),0,5) == 'user_') {
// Just looking to be redirected to a user profile user
_phpbb_redirect_user_profile(substr(arg(1),5));
} else if($user->uid > 0) {
// We know who this is, but phpBB doesnt for some reason, create session and send them back
watchdog('user', t('phpBB rebuffed %name.', array('%name' => $user->name)));
$edit = array();
phpbb_user('logout',$edit, $user);
phpbb_user('login',$edit, $user);
drupal_goto($phpbbcfg['path_rel'] . arg(1));
} else {
return "The phpbb module is not sure what you want?";
}
}
}
function _phpbb_diagnostic() {
global $phpbbcfg, $user;
$ret = '<table>';
// Check phpbbs configuration file
$filebasepath = substr($_SERVER['SCRIPT_FILENAME'], 0, -9 ).$phpbbcfg['path_rel'];
$filename = $filebasepath.'config.php';
$ret .= "<tr><td>Relative path and phpBBs configuration file: $filename</td><td>";
(file_exists($filename)) ? $ret .= "OK" : $ret .= "FAILED";
$ret .= "</td></tr>";
$filename = $filebasepath.'includes/functions_drupal.php';
$ret .= "<tr><td>functions_drupal.php: $filename</td><td>";
(file_exists($filename)) ? $ret .= "OK" : $ret .= "FAILED";
$ret .= "</td></tr>";
$ret .= "<tr><td>Access to phpBBs database</td><td>";
$query = "SELECT * FROM {$phpbbcfg['db_groups']} WHERE `group_name` = 'REGISTERED'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$row = db_fetch_array($res);
($row['group_id']) ? $ret .= "OK" : $ret .= "FAILED";
$ret .= "</td></tr>";
$query = "SELECT * FROM {$phpbbcfg['db_config']} WHERE config_name = 'cookie_domain' LIMIT 1";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$config = db_fetch_array($res);
$ret .= "<tr><td>Raw cookie domain value in phpBBs database</td><td>";
($config['config_value']) ? $ret .= $config['config_value'] : $ret .= "[NULL]";
$ret .= "</td></tr>";
$ret .= "<tr><td>Cookie domain value module will try to use</td><td>";
(_phpbb_cookie_domain()) ? $ret .= _phpbb_cookie_domain() : $ret .= "[NULL]";
$ret .= "</td></tr>";
$ret .= '<tr><td>Current domain:</td><td>'.$_SERVER['SERVER_NAME'].'</td></tr>';
$phpbb_cookie_name = _phpbb_cookie_name();
$ret .= "<tr><td>_k cookie</td><td>";
($_COOKIE[$phpbb_cookie_name . '_k']) ? $ret .= "Present" : $ret .= "Missing!";
$ret .= "</td></tr>";
$ret .= "<tr><td>_u cookie</td><td>";
(intval($_COOKIE[$phpbb_cookie_name . '_u']) == $user->uid) ? $ret .= "UID matches" : $ret .= "UID not matching, ".$_COOKIE[$phpbb_cookie_name . '_u'];
$ret .= ", Drupal: ".$user->uid."</td></tr>";
$ret .= "<tr><td>_sid cookie (after going to the forum this should change from 1)</td><td>";
($_COOKIE[$phpbb_cookie_name . '_sid'] == 1) ? $ret .= "Still 1!" : $ret .= "OK";
$ret .= "</td></tr>";
$ret .= '<tr><td> </td><td> </td></tr>';
$ret .= '<tr><td><strong>Cookies:</strong></td><td><strong>All below: substr(string,0,32)</strong></td></tr>';
foreach($_COOKIE as $cookie => $data) {
$ret .= '<tr><td> '.$cookie.'</td><td>'.substr($data,0,32).'</td></tr>';
}
$ret .= '<tr><td> </td><td> </td></tr>';
$ret .= '<tr><td>Server software:</td><td>'.$_SERVER['SERVER_SOFTWARE'].'</td></tr>';
$ret .= '<tr><td>PHP OS:</td><td>'.PHP_OS.'</td></tr>';
$ret .= '<tr><td>PHP version:</td><td>'.PHP_VERSION.'</td></tr>';
$ret .= "</table>";
return $ret;
}
function _phpbb_forum_login() {
global $phpbbcfg;
//echo " username " . $_POST['username'] . " password " . $_POST['password'] . "</br>";
//echo $_POST['redirect'];
$user = user_authenticate($_POST['username'],$_POST['password']);
if($user && $user->uid > 0) {
$edit = array();
module_invoke_all('user', 'login', NULL, $user);
//echo ($_POST['redirect'] ? $_POST['redirect'] : "no redirect");
header('Location: '. $phpbbcfg['path_abs'] . $_POST['redirect'] , TRUE, 302);
exit();
} else {
drupal_goto('user/login',"destination={$phpbbcfg['path_rel']}");
exit();
}
}
function _phpbb_logout() {
session_destroy();
module_invoke_all('user', 'logout', NULL, $user);
// Load the anonymous user
$user = drupal_anonymous_user();
drupal_goto($phpbbcfg['path_rel']);
}
function _phpbb_redirect_user_profile($userid) {
header('Location: '.$phpbbcfg['path_abs'].'memberlist.php?mode=viewprofile&u='.$userid, TRUE, 301);
exit();
}
function _phpbb_form_passwd_reset() {
$form['#redirect'] = 'node';
$form['pass'] = array(
'#type' => 'password_confirm',
'#description' => t('Provide a password for the new account in both fields.'),
'#required' => TRUE,
'#size' => 25,
);
$form['submit'] = array('#type' => 'submit',
'#value' => t('Send'),
'#weight' => 2,
'#attributes' => array('tabindex' => '3')
);
return $form;
}
function _phpbb_form_passwd_reset_validate($form_id, $form_values) {
if( preg_replace('/[^A-Za-z0-9_]/','',$form_values['pass']) != $form_values['pass']) {
form_set_error('', t('Passwords should only contain the characters A-Z, a-z and 0-9.'));
}
if (strlen($form_values['pass']) < 6) {
form_set_error('', t('The password you have supplied is too short.'));
}
}
function _phpbb_form_passwd_reset_submit($form_id, $form_values) {
global $user, $phpbbcfg;
require_once('hash.inc');
$hash = md5($form_values['pass']);
//Update Drupal
db_query("UPDATE {users} SET pass = '$hash' WHERE uid = ".$user->uid);
$hash = phpbb_hash($form_values['pass']);
//Update phpBB
db_query("UPDATE ". $phpbbcfg['db_users'] ." SET user_password = '$hash' WHERE user_id = ".$user->uid);
drupal_set_message(t('Your password has been updated.'));
return;
}
function _phpbb_pm_count($userid) {
global $phpbbcfg;
if($userid != 0) {
$query = "SELECT user_unread_privmsg FROM {$phpbbcfg['db_users']} WHERE user_id = ". $userid;
$res = db_query($query); //or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$row = db_fetch_array($res);
$new = $row['user_unread_privmsg'];
return $new;
} else {
return false;
}
}
function _phpbb_cookie_domain() {
global $phpbbcfg;
$query = "SELECT * FROM {$phpbbcfg['db_config']} WHERE config_name = 'cookie_domain' LIMIT 1";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$config = db_fetch_array($res);
$domain = $config['config_value'];
if($domain && $domain != "") {
return "." . $domain;
} else {
return '';
}
}
function _phpbb_cookie_name() {
global $phpbbcfg;
$query = "SELECT * FROM {$phpbbcfg['db_config']} WHERE config_name = 'cookie_name' LIMIT 1";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$row = db_fetch_array($res);
return $row['config_value'];
}
function _phpbb_session_destroy() {
global $user,$phpbbcfg;
// Collect information from phpBBs cookies
$phpbb_cookie_name = _phpbb_cookie_name();
$user_id = 0;
$session_key = 0;
$session_id = 0;
_phpbb_read_cookies($phpbb_cookie_name, $user_id, $session_key, $session_id);
// Update the last logged in timestamp
$query = "UPDATE {$phpbbcfg['db_users']} SET user_lastvisit = ".time()." WHERE user_id = ".$user->uid;
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
// Delete by session id if possible, user id otherwise
if(! $phpbbcfg['sson'] && $user_id && ($session_key || $session_id)) {
//echo "going after the keys";
watchdog('phpbb',"Going after session for $user_id");
_phpbb_delete_db_session_keys($user_id, $session_id, $session_key);
} else if($user->uid) {
//echo "going after the user id";
watchdog('phpbb',"Going after all instances of $user_id");
_phpbb_delete_db_session_uid($user_id);
} else {
//echo "ooops. Where did this one come from?";
}
// Unset cookies
_phpbb_unset_cookies($phpbb_cookie_name);
}
function _phpbb_insert_db_session($session_key) {
global $user, $phpbbcfg;
//$admin_access = user_access('administer phpbb') ? 1 : 0;
//$browser = (!empty($_SERVER['HTTP_USER_AGENT'])) ? htmlspecialchars((string) $_SERVER['HTTP_USER_AGENT']) : '';
$query = "INSERT INTO {$phpbbcfg['db_sessions_keys']} (`key_id`,`user_id`,`last_ip`,`last_login`) "
."VALUES('". md5($session_key) ."',". $user->uid .",'"
. $_SERVER['REMOTE_ADDR']. "'," . time() . ")";
//echo $query;
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
}
// This one is nice if the user is known
function _phpbb_delete_db_session_uid($uid) {
global $user, $phpbbcfg;
if(! $uid)
$uid = $user->uid;
// From sessions
$query = "DELETE FROM {$phpbbcfg['db_sessions']} WHERE `session_user_id` = $uid AND `session_ip`='" .$_SERVER['REMOTE_ADDR']. "'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
// From autologin_table
$query = "DELETE FROM {$phpbbcfg['db_sessions_keys']} WHERE `user_id` = $uid AND `last_ip`='" .$_SERVER['REMOTE_ADDR']. "'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
}
// This one if we only have info from phpBBs cookies
function _phpbb_delete_db_session_keys($uid, $session_id, $session_key) {
global $phpbbcfg;
// From sessions
if($session_id) {
//echo "session id: $session_id";
$query = "DELETE FROM {$phpbbcfg['db_sessions']} WHERE `session_user_id` = $uid AND `session_id`='$session_id'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
}
// From autologin_table
if($session_key) {
//echo "session key: $session_key";
$query = "DELETE FROM {$phpbbcfg['db_sessions_keys']} WHERE `user_id` = $uid AND `key_id`='".md5($session_key)."'";
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
}
}
function _phpbb_read_cookies($phpbb_cookie_name, &$user_id, &$session_key, &$session_id) {
$session_id = $_COOKIE[$phpbb_cookie_name . '_sid'];
$session_key = $_COOKIE[$phpbb_cookie_name . '_k'];
$user_id = $_COOKIE[$phpbb_cookie_name . '_u'];
}
function _phpbb_set_cookies($phpbb_cookie_name, $session_key) {
global $user;
$domain = _phpbb_cookie_domain();
// Two weeks should be ample
setcookie($phpbb_cookie_name . '_k', $session_key, time() + 1209600, '/', $domain);
setcookie($phpbb_cookie_name . '_u', $user->uid , time() + 1209600, '/', $domain);
setcookie($phpbb_cookie_name . '_sid', '1', time() + 1209600, '/', $domain);
}
function _phpbb_unset_cookies($phpbb_cookie_name) {
$domain = _phpbb_cookie_domain();
setcookie($phpbb_cookie_name . '_k', '', time() - 14400, '/', $domain);
setcookie($phpbb_cookie_name . '_u', 0, time() - 14400, '/', $domain);
setcookie($phpbb_cookie_name . '_sid', '', time() - 14400, '/',$domain);
}
function _phpbb_knows_user($user_id) {
global $phpbbcfg;
$query = "SELECT username FROM {$phpbbcfg['db_users']} "
." WHERE `user_id` = " . $user_id;
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
if(db_num_rows($res) != 0) {
$row = db_fetch_array($res);
return $row['username'];
} else {
return false;
}
}
function _phpbb_random() {
$val = rand() . microtime();
$val = md5($val);
return substr($val, 4, 16);
}
function _phpbb_display_block_0() {
global $user, $phpbbcfg;
// short names
$tt = $phpbbcfg['db_topics'];
$tp = $phpbbcfg['db_posts'];
$tg = $phpbbcfg['db_groups'];
$ag = $phpbbcfg['db_acl_groups'];
$ar = $phpbbcfg['db_acl_roles'];
$cc = $phpbbcfg['block0_char_count'];
// Should consider caching here: http://www.lullabot.com/articles/a_beginners_guide_to_caching_data
// The key to updating the cache or not is whether the last_topic_id has changed.
// Build where clause
$where_query = '';
if($phpbbcfg['i1'] && $user->uid != 0) {
//Find out what the user does not want to see
$query = "SELECT user_ignores_feed FROM {$phpbbcfg['db_users']} WHERE user_id = ".$user->uid;
$res = db_query($query) or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$row = db_fetch_array($res);
$ignore_query = " AND $tt.forum_id NOT IN({$row['user_ignores_feed']}-1) ";
}
//Anonymous or authenticated? Should add check for search engines
($user->uid == 0) ? $gid = 'REGISTERED' : $gid = 'GUESTS';
$query = "SELECT $tt.topic_id, $tt.topic_title, $tt.topic_last_post_id "
."FROM $tt "
."LEFT JOIN $ag ON $tt.forum_id = $ag.forum_id "
."LEFT JOIN $ar ON $ag.auth_role_id = $ar.role_id "
."LEFT JOIN $tg ON $ag.group_id = $tg.group_id "
."WHERE $tg.group_name = '$gid' AND $ar.role_name IN ('ROLE_FORUM_POLLS', 'ROLE_FORUM_STANDARD', 'ROLE_FORUM_READONLY') "
. $ignore_query
." ORDER BY $tt.topic_last_post_id DESC LIMIT {$phpbbcfg['block0_count']};";
//echo $query;
$res = db_query($query); //or die('Query failed: ' . db_error() . " \n" . $query . "\n");
$list = array();
while( $a_row = db_fetch_array($res)) {
if ($cc > 0 && strlen($a_row['topic_title']) > $cc ) {
//Chop the end off at the last space before the specified length
$pos = strrpos($a_row['topic_title'], " ", -(strlen($a_row['topic_title']) - $cc));
$descstr = substr($a_row['topic_title'],0,$pos) . "...";
} else {
$descstr = $a_row['topic_title'];
}
$topic_urlstr = $phpbbcfg['path_abs'] ."viewtopic.php?t=" . $a_row['topic_id'];
$post_urlstr = $phpbbcfg['path_abs'] ."viewtopic.php?p=" . $a_row['topic_last_post_id'] . "#" . $a_row['topic_last_post_id'];
$list[] = "<a href=\"$post_urlstr\"><span class=\"pilned\"></span></a><a href=\"$topic_urlstr\" title=\"{$a_row['topic_title']}\">$descstr</a>\n";
}
return theme('item_list', $list);
}
function _phpbb_display_block_1() {
global $user, $phpbbcfg;
if($user->uid == 0 || $user->uid == 1) {
return 'Only valid for authenticated forum users';
}
$list = array();
// New messages
$new = _phpbb_pm_count($user->uid);
$list[] = '<a href="'.$phpbbcfg['path_abs'].'inbox">Private messages ('.$new.')</a>'."\n";
// New topics since last visit
$query = "SELECT COUNT(*) FROM {$phpbbcfg['db_topics']} LEFT JOIN {$phpbbcfg['db_users']} ON {$phpbbcfg['db_topics']}.topic_time > {$phpbbcfg['db_users']}.user_lastvisit WHERE user_id = ". $user->uid;
$res = db_query($query);
$row = db_fetch_array($res);
$url = $phpbbcfg['path_abs'].'search.php?search_id=newposts&sr=topics';
$list[] = "<a href=\"$url\">Unread topics ({$row['COUNT(*)']})\n";
// New posts since last visit
$query = "SELECT COUNT(*) FROM {$phpbbcfg['db_posts']} LEFT JOIN {$phpbbcfg['db_users']} ON {$phpbbcfg['db_posts']}.post_time > {$phpbbcfg['db_users']}.user_lastvisit WHERE user_id = ". $user->uid;
$res = db_query($query);
$row = db_fetch_array($res);
$url = $phpbbcfg['path_abs'].'search.php?search_id=newposts&sr=posts';
$list[] = "<a href=\"$url\">Unread posts ({$row['COUNT(*)']})\n";
return theme('item_list', $list);
}
?>
Here's the group discussion and what we did: http://groups.drupal.org/node/6710.
bye!