﻿diff -uprbB ./faq.php ../phpBB-embed-3.0.9/faq.php
--- ./faq.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/faq.php	2010-03-03 14:00:53.000000000 +0300
@@ -2,7 +2,7 @@
 /**
 *
 * @package phpBB3
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -11,10 +11,15 @@
 /**
 * @ignore
 */
+//***VB***
+if (!defined('PHPBB_API_EMBEDDED'))
+{
 define('IN_PHPBB', true);
 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);
 include($phpbb_root_path . 'common.' . $phpEx);
+}
+//***VB***
 
 // Start session management
 $user->session_begin();
diff -uprbB ./feed.php ../phpBB-embed-3.0.9/feed.php
--- ./feed.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/feed.php	2010-11-21 11:13:17.000000000 +0300
@@ -15,10 +15,15 @@
 /**
 * @ignore
 **/
+//***VB***
+if (!defined('PHPBB_API_EMBEDDED'))
+{
 define('IN_PHPBB', true);
 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);
 include($phpbb_root_path . 'common.' . $phpEx);
+}
+//***VB***
 
 if (!$config['feed_enable'])
 {
@@ -138,7 +143,12 @@ $global_vars = array_merge($global_vars,
 $feed->close();
 
 // Output page
-
+//***VB***
+if (defined('PHPBB_API_EMBEDDED')) {
+  ob_start();
+}
+else
+//***VB***
 // gzip_compression
 if ($config['gzip_compress'])
 {
diff -uprbB ./includes/functions_display.php ../phpBB-embed-3.0.9/includes/functions_display.php
--- ./includes/functions_display.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/functions_display.php	2010-11-21 11:55:53.000000000 +0300
@@ -258,6 +258,12 @@ function display_forums($root_data = '',
 	if ($mark_read == 'forums' || $mark_read == 'all')
 	{
 		$redirect = build_url(array('mark', 'hash'));
+    //***VB***
+    if (defined('PHPBB_API_EMBEDDED'))
+    {
+      $redirect = _phpbbforum_replace_urls($redirect);
+    }
+    //***VB***
 		$token = request_var('hash', '');
 		if (check_link_hash($token, 'global'))
 		{
diff -uprbB ./includes/functions_messenger.php ../phpBB-embed-3.0.9/includes/functions_messenger.php
--- ./includes/functions_messenger.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/functions_messenger.php	2010-11-21 11:56:55.000000000 +0300
@@ -307,7 +307,13 @@ class messenger
 		{
 			return true;
 		}
-
+    //***VB***
+    if (defined('PHPBB_API_EMBEDDED'))
+    {
+      $this->subject = _phpbbforum_replace_msg_links($this->subject);
+      $this->msg = _phpbbforum_replace_msg_links($this->msg);
+    }
+    //***VB***
 		switch ($method)
 		{
 			case NOTIFY_EMAIL:
diff -uprbB ./includes/functions_module.php ../phpBB-embed-3.0.9/includes/functions_module.php
--- ./includes/functions_module.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/functions_module.php	2010-03-03 14:00:53.000000000 +0300
@@ -2,7 +2,7 @@
 /**
 *
 * @package phpBB3
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -446,7 +446,16 @@ class p_master
 				trigger_error("Cannot find module $module_path/{$this->p_class}_$this->p_name.$phpEx", E_USER_ERROR);
 			}
 
+      //***VB***
+      if (!defined('PHPBB_API_EMBEDDED'))
+      {
 			include("$module_path/{$this->p_class}_$this->p_name.$phpEx");
+      }
+      else
+      {
+        include_once("$module_path/{$this->p_class}_$this->p_name.$phpEx");
+      }
+      //***VB***
 
 			if (!class_exists("{$this->p_class}_$this->p_name"))
 			{
@@ -496,7 +505,14 @@ class p_master
 			{
 				$this->module->u_action .= $this->module_ary[$this->active_module_row_id]['url_extra'];
 			}
-
+      //***VB***
+      if (defined('PHPBB_API_EMBEDDED'))
+      {
+        //if ($this->p_class != 'acp') {
+          $this->module->u_action = _phpbbforum_replace_cp_action($this->p_class, $this->module->u_action);
+        //}
+      }
+      //***VB***
 			// Assign the module path for re-usage
 			$this->module->module_path = $module_path . '/';
 
diff -uprbB ./includes/functions.php ../phpBB-embed-3.0.9/includes/functions.php
--- ./includes/functions.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/functions.php	2011-02-12 17:25:40.000000000 +0300
@@ -2471,7 +2471,12 @@ function redirect($url, $return = false,
 	{
 		return $url;
 	}
-
+  //***VB***
+  if (defined('PHPBB_API_EMBEDDED'))
+  {
+    phpbbforum_redirect($url);
+  }
+  //***VB***
 	// Redirect via an HTML form for PITA webservers
 	if (@preg_match('#Microsoft|WebSTAR|Xitami#', getenv('SERVER_SOFTWARE')))
 	{
@@ -2616,7 +2621,21 @@ function meta_refresh($time, $url, $disa
 	global $template;
 
 	$url = redirect($url, true, $disable_cd_check);
+	//***VB***
+  if (defined('PHPBB_API_EMBEDDED'))
+  {
+    global $_phpbb_embed_mode;
+    if ($_phpbb_embed_mode['redirect'])
+      redirect($url);
+  }
+  //***VB***
 	$url = str_replace('&', '&amp;', $url);
+  //***VB***
+  if (defined('PHPBB_API_EMBEDDED'))
+  {
+    $url = phpbbforum_redirect($url, $time);
+  }
+  //***VB***
 
 	// For XHTML compatibility we change back & to &amp;
 	$template->assign_vars(array(
@@ -2862,7 +2881,12 @@ function confirm_box($check, $title = ''
 	$use_page = ($u_action) ? $phpbb_root_path . $u_action : $phpbb_root_path . str_replace('&', '&amp;', $user->page['page']);
 	$u_action = reapply_sid($use_page);
 	$u_action .= ((strpos($u_action, '?') === false) ? '?' : '&amp;') . 'confirm_key=' . $confirm_key;
-
+  //***VB***
+  if (defined('PHPBB_API_EMBEDDED'))
+  {
+    $u_action = _phpbbforum_replace_urls($u_action, true);
+  }
+  //***VB***
 	$template->assign_vars(array(
 		'MESSAGE_TITLE'		=> (!isset($user->lang[$title])) ? $user->lang['CONFIRM'] : $user->lang[$title],
 		'MESSAGE_TEXT'		=> (!isset($user->lang[$title . '_CONFIRM'])) ? $title : $user->lang[$title . '_CONFIRM'],
@@ -2895,8 +2919,17 @@ function login_box($redirect = '', $l_ex
 
 	if (!class_exists('phpbb_captcha_factory'))
 	{
+		//***VB***
+    if (defined('PHPBB_API_EMBEDDED')) 
+    {
+      include_once($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
+    }
+    else
+    {
 		include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
 	}
+    //***VB***
+	}
 
 	$err = '';
 
@@ -2981,6 +3014,13 @@ function login_box($redirect = '', $l_ex
 		if ($result['status'] == LOGIN_SUCCESS)
 		{
 			$redirect = request_var('redirect', "{$phpbb_root_path}index.$phpEx");
+      //***VB***
+      if (defined('PHPBB_API_EMBEDDED'))
+      {
+        if ($redirect == "index.$phpEx")
+          $redirect = "{$phpbb_root_path}index.$phpEx";
+      }
+      //***VB***
 			$message = ($l_success) ? $l_success : $user->lang['LOGIN_REDIRECT'];
 			$l_redirect = ($admin) ? $user->lang['PROCEED_TO_ACP'] : (($redirect === "{$phpbb_root_path}index.$phpEx" || $redirect === "index.$phpEx") ? $user->lang['RETURN_INDEX'] : $user->lang['RETURN_PAGE']);
 
@@ -2992,7 +3032,12 @@ function login_box($redirect = '', $l_ex
 			{
 				return;
 			}
-
+      //***VB***
+      if (defined('PHPBB_API_EMBEDDED'))
+      {
+        _phpbb_api_hook('login', array('username' => $username, 'password' => $password, 'redirect' => $redirect));
+      }
+      //***VB***
 			$redirect = meta_refresh(3, $redirect);
 			trigger_error($message . '<br /><br />' . sprintf($l_redirect, '<a href="' . $redirect . '">', '</a>'));
 		}
@@ -4340,12 +4385,30 @@ function page_header($page_title = '', $
 	// Generate logged in/logged out status
 	if ($user->data['user_id'] != ANONYMOUS)
 	{
+		//VB
+    if (function_exists('phpbbforum_get_drupal_login_url'))
+    {
+      $u_login_logout = phpbbforum_get_drupal_login_url('logout');
+    }  
+    else 
+    {
 		$u_login_logout = append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=logout', true, $user->session_id);
+    }
+    //\VB
 		$l_login_logout = sprintf($user->lang['LOGOUT_USER'], $user->data['username']);
 	}
 	else
 	{
+		//VB
+    if (function_exists('phpbbforum_get_drupal_login_url'))
+    {
+      $u_login_logout = phpbbforum_get_drupal_login_url('user/login');
+    }  
+    else 
+    {
 		$u_login_logout = append_sid("{$phpbb_root_path}ucp.$phpEx", 'mode=login');
+    }
+    //\VB
 		$l_login_logout = $user->lang['LOGIN'];
 	}
 
@@ -4582,12 +4645,22 @@ function page_header($page_title = '', $
 		'A_COOKIE_SETTINGS'		=> addslashes('; path=' . $config['cookie_path'] . ((!$config['cookie_domain'] || $config['cookie_domain'] == 'localhost' || $config['cookie_domain'] == '127.0.0.1') ? '' : '; domain=' . $config['cookie_domain']) . ((!$config['cookie_secure']) ? '' : '; secure')),
 	));
 
+  //***VB***
+	if (!defined('PHPBB_API_EMBEDDED'))
+	{
 	// application/xhtml+xml not used because of IE
 	header('Content-type: text/html; charset=UTF-8');
 
 	header('Cache-Control: private, no-cache="set-cookie"');
 	header('Expires: 0');
 	header('Pragma: no-cache');
+	}
+  else
+  {
+    global $_phpbb_result;
+    $_phpbb_result['page_title'] = $page_title;
+  }
+  //***VB***
 
 	return;
 }
@@ -4696,7 +4769,11 @@ function page_footer($run_cron = true)
 			$template->assign_var('RUN_CRON_TASK', '<img src="' . append_sid($phpbb_root_path . 'cron.' . $phpEx, 'cron_type=' . $cron_type) . '" width="1" height="1" alt="cron" />');
 		}
 	}
-
+  //***VB***
+  if (defined('PHPBB_API_EMBEDDED')) {
+    ob_start();
+  }  
+  //***VB***
 	$template->display('body');
 
 	garbage_collection();
@@ -4717,11 +4794,16 @@ function garbage_collection()
 		$cache->unload();
 	}
 
+	//***VB***
+  if (!defined('PHPBB_API_EMBEDDED'))
+	{
 	// Close our DB connection.
 	if (!empty($db))
 	{
 		$db->sql_close();
 	}
+  }
+  //***VB***
 }
 
 /**
diff -uprbB ./includes/functions_user.php ../phpBB-embed-3.0.9/includes/functions_user.php
--- ./includes/functions_user.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/functions_user.php	2010-11-21 12:30:07.000000000 +0300
@@ -331,6 +331,328 @@ function user_add($user_row, $cp_data = 
 /**
 * Remove User
 */
+/***VB***/
+if (defined('PHPBB_DRUPAL_MODULE')) 
+{
+function phpbb_user_delete($mode, $user_id, $post_username = false)
+{
+	global $cache, $config, $db, $user, $auth;
+	global $phpbb_root_path, $phpEx;
+
+	$sql = 'SELECT *
+		FROM ' . USERS_TABLE . '
+		WHERE user_id = ' . $user_id;
+	$result = $db->sql_query($sql);
+	$user_row = $db->sql_fetchrow($result);
+	$db->sql_freeresult($result);
+
+	if (!$user_row)
+	{
+		return false;
+	}
+
+	// Before we begin, we will remove the reports the user issued.
+	$sql = 'SELECT r.post_id, p.topic_id
+		FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p
+		WHERE r.user_id = ' . $user_id . '
+			AND p.post_id = r.post_id';
+	$result = $db->sql_query($sql);
+
+	$report_posts = $report_topics = array();
+	while ($row = $db->sql_fetchrow($result))
+	{
+		$report_posts[] = $row['post_id'];
+		$report_topics[] = $row['topic_id'];
+	}
+	$db->sql_freeresult($result);
+
+	if (sizeof($report_posts))
+	{
+		$report_posts = array_unique($report_posts);
+		$report_topics = array_unique($report_topics);
+
+		// Get a list of topics that still contain reported posts
+		$sql = 'SELECT DISTINCT topic_id
+			FROM ' . POSTS_TABLE . '
+			WHERE ' . $db->sql_in_set('topic_id', $report_topics) . '
+				AND post_reported = 1
+				AND ' . $db->sql_in_set('post_id', $report_posts, true);
+		$result = $db->sql_query($sql);
+
+		$keep_report_topics = array();
+		while ($row = $db->sql_fetchrow($result))
+		{
+			$keep_report_topics[] = $row['topic_id'];
+		}
+		$db->sql_freeresult($result);
+
+		if (sizeof($keep_report_topics))
+		{
+			$report_topics = array_diff($report_topics, $keep_report_topics);
+		}
+		unset($keep_report_topics);
+
+		// Now set the flags back
+		$sql = 'UPDATE ' . POSTS_TABLE . '
+			SET post_reported = 0
+			WHERE ' . $db->sql_in_set('post_id', $report_posts);
+		$db->sql_query($sql);
+
+		if (sizeof($report_topics))
+		{
+			$sql = 'UPDATE ' . TOPICS_TABLE . '
+				SET topic_reported = 0
+				WHERE ' . $db->sql_in_set('topic_id', $report_topics);
+			$db->sql_query($sql);
+		}
+	}
+
+	// Remove reports
+	$db->sql_query('DELETE FROM ' . REPORTS_TABLE . ' WHERE user_id = ' . $user_id);
+
+	if ($user_row['user_avatar'] && $user_row['user_avatar_type'] == AVATAR_UPLOAD)
+	{
+		avatar_delete('user', $user_row);
+	}
+
+	switch ($mode)
+	{
+		case 'retain':
+
+			$db->sql_transaction('begin');
+
+			if ($post_username === false)
+			{
+				$post_username = $user->lang['GUEST'];
+			}
+
+			// If the user is inactive and newly registered we assume no posts from this user being there...
+			if ($user_row['user_type'] == USER_INACTIVE && $user_row['user_inactive_reason'] == INACTIVE_REGISTER && !$user_row['user_posts'])
+			{
+			}
+			else
+			{
+				$sql = 'UPDATE ' . FORUMS_TABLE . '
+					SET forum_last_poster_id = ' . ANONYMOUS . ", forum_last_poster_name = '" . $db->sql_escape($post_username) . "', forum_last_poster_colour = ''
+					WHERE forum_last_poster_id = $user_id";
+				$db->sql_query($sql);
+
+				$sql = 'UPDATE ' . POSTS_TABLE . '
+					SET poster_id = ' . ANONYMOUS . ", post_username = '" . $db->sql_escape($post_username) . "'
+					WHERE poster_id = $user_id";
+				$db->sql_query($sql);
+
+				$sql = 'UPDATE ' . POSTS_TABLE . '
+					SET post_edit_user = ' . ANONYMOUS . "
+					WHERE post_edit_user = $user_id";
+				$db->sql_query($sql);
+
+				$sql = 'UPDATE ' . TOPICS_TABLE . '
+					SET topic_poster = ' . ANONYMOUS . ", topic_first_poster_name = '" . $db->sql_escape($post_username) . "', topic_first_poster_colour = ''
+					WHERE topic_poster = $user_id";
+				$db->sql_query($sql);
+
+				$sql = 'UPDATE ' . TOPICS_TABLE . '
+					SET topic_last_poster_id = ' . ANONYMOUS . ", topic_last_poster_name = '" . $db->sql_escape($post_username) . "', topic_last_poster_colour = ''
+					WHERE topic_last_poster_id = $user_id";
+				$db->sql_query($sql);
+
+				$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
+					SET poster_id = ' . ANONYMOUS . "
+					WHERE poster_id = $user_id";
+				$db->sql_query($sql);
+
+				// Since we change every post by this author, we need to count this amount towards the anonymous user
+
+				// Update the post count for the anonymous user
+				if ($user_row['user_posts'])
+				{
+					$sql = 'UPDATE ' . USERS_TABLE . '
+						SET user_posts = user_posts + ' . $user_row['user_posts'] . '
+						WHERE user_id = ' . ANONYMOUS;
+					$db->sql_query($sql);
+				}
+			}
+
+			$db->sql_transaction('commit');
+
+		break;
+
+		case 'remove':
+
+			if (!function_exists('delete_posts'))
+			{
+				include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
+			}
+
+			$sql = 'SELECT topic_id, COUNT(post_id) AS total_posts
+				FROM ' . POSTS_TABLE . "
+				WHERE poster_id = $user_id
+				GROUP BY topic_id";
+			$result = $db->sql_query($sql);
+
+			$topic_id_ary = array();
+			while ($row = $db->sql_fetchrow($result))
+			{
+				$topic_id_ary[$row['topic_id']] = $row['total_posts'];
+			}
+			$db->sql_freeresult($result);
+
+			if (sizeof($topic_id_ary))
+			{
+				$sql = 'SELECT topic_id, topic_replies, topic_replies_real
+					FROM ' . TOPICS_TABLE . '
+					WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary));
+				$result = $db->sql_query($sql);
+
+				$del_topic_ary = array();
+				while ($row = $db->sql_fetchrow($result))
+				{
+					if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']])
+					{
+						$del_topic_ary[] = $row['topic_id'];
+					}
+				}
+				$db->sql_freeresult($result);
+
+				if (sizeof($del_topic_ary))
+				{
+					$sql = 'DELETE FROM ' . TOPICS_TABLE . '
+						WHERE ' . $db->sql_in_set('topic_id', $del_topic_ary);
+					$db->sql_query($sql);
+				}
+			}
+
+			// Delete posts, attachments, etc.
+			delete_posts('poster_id', $user_id);
+
+		break;
+	}
+
+	$db->sql_transaction('begin');
+
+	$table_ary = array(USERS_TABLE, USER_GROUP_TABLE, TOPICS_WATCH_TABLE, FORUMS_WATCH_TABLE, ACL_USERS_TABLE, TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, FORUMS_TRACK_TABLE, PROFILE_FIELDS_DATA_TABLE, MODERATOR_CACHE_TABLE, DRAFTS_TABLE, BOOKMARKS_TABLE, SESSIONS_KEYS_TABLE, PRIVMSGS_FOLDER_TABLE, PRIVMSGS_RULES_TABLE);
+
+	foreach ($table_ary as $table)
+	{
+		$sql = "DELETE FROM $table
+			WHERE user_id = $user_id";
+		$db->sql_query($sql);
+	}
+
+	$cache->destroy('sql', MODERATOR_CACHE_TABLE);
+
+	// Delete user log entries about this user
+	$sql = 'DELETE FROM ' . LOG_TABLE . '
+		WHERE reportee_id = ' . $user_id;
+	$db->sql_query($sql);
+
+	// Change user_id to anonymous for this users triggered events
+	$sql = 'UPDATE ' . LOG_TABLE . '
+		SET user_id = ' . ANONYMOUS . '
+		WHERE user_id = ' . $user_id;
+	$db->sql_query($sql);
+
+	// Delete the user_id from the zebra table
+	$sql = 'DELETE FROM ' . ZEBRA_TABLE . '
+		WHERE user_id = ' . $user_id . '
+			OR zebra_id = ' . $user_id;
+	$db->sql_query($sql);
+
+	// Delete the user_id from the banlist
+	$sql = 'DELETE FROM ' . BANLIST_TABLE . '
+		WHERE ban_userid = ' . $user_id;
+	$db->sql_query($sql);
+
+	// Delete the user_id from the session table
+	$sql = 'DELETE FROM ' . SESSIONS_TABLE . '
+		WHERE session_user_id = ' . $user_id;
+	$db->sql_query($sql);
+
+	// Remove any undelivered mails...
+	$sql = 'SELECT msg_id, user_id
+		FROM ' . PRIVMSGS_TO_TABLE . '
+		WHERE author_id = ' . $user_id . '
+			AND folder_id = ' . PRIVMSGS_NO_BOX;
+	$result = $db->sql_query($sql);
+
+	$undelivered_msg = $undelivered_user = array();
+	while ($row = $db->sql_fetchrow($result))
+	{
+		$undelivered_msg[] = $row['msg_id'];
+		$undelivered_user[$row['user_id']][] = true;
+	}
+	$db->sql_freeresult($result);
+
+	if (sizeof($undelivered_msg))
+	{
+		$sql = 'DELETE FROM ' . PRIVMSGS_TABLE . '
+			WHERE ' . $db->sql_in_set('msg_id', $undelivered_msg);
+		$db->sql_query($sql);
+	}
+
+	$sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . '
+		WHERE author_id = ' . $user_id . '
+			AND folder_id = ' . PRIVMSGS_NO_BOX;
+	$db->sql_query($sql);
+
+	// Delete all to-information
+	$sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . '
+		WHERE user_id = ' . $user_id;
+	$db->sql_query($sql);
+
+	// Set the remaining author id to anonymous - this way users are still able to read messages from users being removed
+	$sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . '
+		SET author_id = ' . ANONYMOUS . '
+		WHERE author_id = ' . $user_id;
+	$db->sql_query($sql);
+
+	$sql = 'UPDATE ' . PRIVMSGS_TABLE . '
+		SET author_id = ' . ANONYMOUS . '
+		WHERE author_id = ' . $user_id;
+	$db->sql_query($sql);
+
+	foreach ($undelivered_user as $_user_id => $ary)
+	{
+		if ($_user_id == $user_id)
+		{
+			continue;
+		}
+
+		$sql = 'UPDATE ' . USERS_TABLE . '
+			SET user_new_privmsg = user_new_privmsg - ' . sizeof($ary) . ',
+				user_unread_privmsg = user_unread_privmsg - ' . sizeof($ary) . '
+			WHERE user_id = ' . $_user_id;
+		$db->sql_query($sql);
+	}
+
+	$db->sql_transaction('commit');
+
+	// Reset newest user info if appropriate
+	if ($config['newest_user_id'] == $user_id)
+	{
+		update_last_username();
+	}
+
+	// Decrement number of users if this user is active
+	if ($user_row['user_type'] != USER_INACTIVE && $user_row['user_type'] != USER_IGNORE)
+	{
+		set_config_count('num_users', -1, true);
+	}
+
+	//_phpbb_api_hook('user_delete', array('username' => $user_row['username'], 'user_id' => $user_id));
+  /***VB***/ 
+  // PHPBB_DRUPAL_MODULE needs true
+	return true;
+}
+/***VB***/
+}
+else //if (!defined('PHPBB_DRUPAL_MODULE'))
+{
+/***VB***/
+/**
+* Remove User
+*/
 function user_delete($mode, $user_id, $post_username = false)
 {
 	global $cache, $config, $db, $user, $auth;
@@ -601,6 +923,9 @@ function user_delete($mode, $user_id, $p
 
 	return false;
 }
+/***VB***/
+} // end if (defined('PHPBB_DRUPAL_MODULE'))
+/***VB***/
 
 /**
 * Flips user_type from active to inactive and vice versa, handles group membership updates
@@ -2717,8 +3042,16 @@ function group_delete($group_id, $group_
 	// Re-cache moderators
 	if (!function_exists('cache_moderators'))
 	{
+    /***VB***/
+		if (defined('PHPBB_DRUPAL_MODULE')) 
+    {
+		include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
+		}
+		else
+		{
 		include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
 	}
+	}
 
 	cache_moderators();
 
@@ -3498,8 +3831,16 @@ function group_update_listings($group_id
 		if (!function_exists('cache_moderators'))
 		{
 			global $phpbb_root_path, $phpEx;
+      /***VB***/
+			if (defined('PHPBB_DRUPAL_MODULE')) 
+      {
+		  include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
+		  }
+		  else
+		  {
 			include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
 		}
+		}
 		cache_moderators();
 	}
 
@@ -3508,8 +3849,16 @@ function group_update_listings($group_id
 		if (!function_exists('update_foes'))
 		{
 			global $phpbb_root_path, $phpEx;
+      /***VB***/
+			if (defined('PHPBB_DRUPAL_MODULE')) 
+      {
+		  include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
+		  }
+		  else
+		  {
 			include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
 		}
+		}
 		update_foes(array($group_id));
 	}
 }
diff -uprbB ./includes/mcp/mcp_ban.php ../phpBB-embed-3.0.9/includes/mcp/mcp_ban.php
--- ./includes/mcp/mcp_ban.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/mcp/mcp_ban.php	2010-03-03 14:00:53.000000000 +0300
@@ -2,7 +2,7 @@
 /**
 *
 * @package mcp
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -28,11 +28,27 @@ class mcp_ban
 		global $config, $db, $user, $auth, $template, $cache;
 		global $phpbb_root_path, $phpEx;
 
+    //***VB***
+    if (!defined('PHPBB_API_EMBEDDED'))
+    {
 		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
-
+    }
+    else
+    {
+      include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+    }
+    //***VB***
 		// Include the admin banning interface...
+    //***VB***
+    if (!defined('PHPBB_API_EMBEDDED'))
+    {
 		include($phpbb_root_path . 'includes/acp/acp_ban.' . $phpEx);
-
+    }
+    else
+    {
+      include_once($phpbb_root_path . 'includes/acp/acp_ban.' . $phpEx);
+    }
+    //***VB***
 		$bansubmit		= (isset($_POST['bansubmit'])) ? true : false;
 		$unbansubmit	= (isset($_POST['unbansubmit'])) ? true : false;
 		$current_time	= time();
diff -uprbB ./includes/mcp/mcp_forum.php ../phpBB-embed-3.0.9/includes/mcp/mcp_forum.php
--- ./includes/mcp/mcp_forum.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/mcp/mcp_forum.php	2010-03-03 14:00:53.000000000 +0300
@@ -2,7 +2,7 @@
 /**
 *
 * @package mcp
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -23,7 +23,12 @@ function mcp_forum_view($id, $mode, $act
 {
 	global $template, $db, $user, $auth, $cache, $module;
 	global $phpEx, $phpbb_root_path, $config;
-
+  //***VB***
+  if (defined('PHPBB_API_EMBEDDED'))
+  {
+    $action =_phpbbforum_get_cp_action_request($action);
+  }
+  //***VB***
 	$user->add_lang(array('viewtopic', 'viewforum'));
 
 	include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
diff -uprbB ./includes/mcp/mcp_front.php ../phpBB-embed-3.0.9/includes/mcp/mcp_front.php
--- ./includes/mcp/mcp_front.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/mcp/mcp_front.php	2010-03-03 14:00:53.000000000 +0300
@@ -2,7 +2,7 @@
 /**
 *
 * @package mcp
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -267,7 +267,17 @@ function mcp_front_view($id, $mode, $act
 
 		if ($total)
 		{
+			
+      //***VB***
+      if (!defined('PHPBB_API_EMBEDDED'))
+      {
 			include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
+      }
+      else
+      {
+      include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
+      }
+      //***VB***
 
 			$sql = $db->sql_build_query('SELECT', array(
 				'SELECT'	=> 'r.report_id, r.report_time, p.msg_id, p.message_subject, p.message_time, p.to_address, p.bcc_address, u.username, u.username_clean, u.user_colour, u.user_id, u2.username as author_name, u2.username_clean as author_name_clean, u2.user_colour as author_colour, u2.user_id as author_id',
diff -uprbB ./includes/mcp/mcp_main.php ../phpBB-embed-3.0.9/includes/mcp/mcp_main.php
--- ./includes/mcp/mcp_main.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/mcp/mcp_main.php	2010-11-21 12:57:18.000000000 +0300
@@ -35,6 +35,12 @@ class mcp_main
 	{
 		global $auth, $db, $user, $template, $action;
 		global $config, $phpbb_root_path, $phpEx;
+    //***VB***
+    if (defined('PHPBB_API_EMBEDDED'))
+    {
+      $action =_phpbbforum_get_cp_action_request($action);
+    }
+    //***VB***
 
 		$quickmod = ($mode == 'quickmod') ? true : false;
 
@@ -136,7 +142,16 @@ class mcp_main
 		switch ($mode)
 		{
 			case 'front':
+				//***VB***
+        if (!defined('PHPBB_API_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/mcp/mcp_front.' . $phpEx);
+        }
+        else
+        {
+          include_once($phpbb_root_path . 'includes/mcp/mcp_front.' . $phpEx);
+        }
+        //***VB***
 
 				$user->add_lang('acp/common');
 
@@ -147,7 +162,16 @@ class mcp_main
 			break;
 
 			case 'forum_view':
+				//***VB***
+        if (!defined('PHPBB_API_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx);
+        }
+        else
+        {
+          include_once($phpbb_root_path . 'includes/mcp/mcp_forum.' . $phpEx);
+        }
+        //***VB***
 
 				$user->add_lang('viewforum');
 
@@ -170,7 +194,16 @@ class mcp_main
 			break;
 
 			case 'topic_view':
+				//***VB***
+        if (!defined('PHPBB_API_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/mcp/mcp_topic.' . $phpEx);
+        }
+        else
+        {
+          include_once($phpbb_root_path . 'includes/mcp/mcp_topic.' . $phpEx);
+        }
+        //***VB***
 
 				mcp_topic_view($id, $mode, $action);
 
@@ -179,7 +212,16 @@ class mcp_main
 			break;
 
 			case 'post_details':
+				//***VB***
+        if (!defined('PHPBB_API_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/mcp/mcp_post.' . $phpEx);
+        }
+        else
+        {
+          include_once($phpbb_root_path . 'includes/mcp/mcp_post.' . $phpEx);
+        }
+        //***VB***
 
 				mcp_post_details($id, $mode, $action);
 
@@ -880,8 +922,17 @@ function mcp_delete_post($post_ids)
 	{
 		if (!function_exists('delete_posts'))
 		{
+      //***VB***
+      if (!defined('PHPBB_API_EMBEDDED'))
+      {
 			include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
 		}
+      else
+      {
+        include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
+      }
+      //***VB***
+		}
 
 		// Count the number of topics that are affected
 		// I did not use COUNT(DISTINCT ...) because I remember having problems
@@ -1063,7 +1114,16 @@
 
 				if (!class_exists($search_type))
 				{
-					include("{$phpbb_root_path}includes/search/$search_type.$phpEx");
+					//***VB***
+					if (!defined('PHPBB_API_EMBEDDED'))
+					{
+						include("{$phpbb_root_path}includes/search/$search_type.$phpEx");
+					}
+					else
+					{
+						include_once("{$phpbb_root_path}includes/search/$search_type.$phpEx");
+					}
+					//***VB***
 				}
 
 				$error = false;
diff -uprbB ./includes/mcp/mcp_notes.php ../phpBB-embed-3.0.9/includes/mcp/mcp_notes.php
--- ./includes/mcp/mcp_notes.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/mcp/mcp_notes.php	2010-03-03 14:00:53.000000000 +0300
@@ -2,7 +2,7 @@
 /**
 *
 * @package mcp
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -176,8 +176,17 @@ class mcp_notes
 		// Generate the appropriate user information for the user we are looking at
 		if (!function_exists('get_user_avatar'))
 		{
+			//***VB***
+      if (!defined('PHPBB_API_EMBEDDED'))
+      {
 			include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 		}
+      else
+      {
+      include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+      }
+      //***VB***
+		}
 
 		$rank_title = $rank_img = '';
 		$avatar_img = get_user_avatar($userrow['user_avatar'], $userrow['user_avatar_type'], $userrow['user_avatar_width'], $userrow['user_avatar_height']);
diff -uprbB ./includes/mcp/mcp_pm_reports.php ../phpBB-embed-3.0.9/includes/mcp/mcp_pm_reports.php
--- ./includes/mcp/mcp_pm_reports.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/mcp/mcp_pm_reports.php	2010-03-03 14:00:53.000000000 +0300
@@ -2,7 +2,7 @@
 /**
 *
 * @package mcp
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -58,8 +58,17 @@ class mcp_pm_reports
 
 				if (!function_exists('close_report'))
 				{
+          //***VB***
+          if (!defined('PHPBB_API_EMBEDDED'))
+          {
 					include($phpbb_root_path . 'includes/mcp/mcp_reports.' . $phpEx);
 				}
+          else
+          {
+          include_once($phpbb_root_path . 'includes/mcp/mcp_reports.' . $phpEx);
+          }
+          //***VB***
+				}
 
 				close_report($report_id_list, $mode, $action, true);
 
diff -uprbB ./includes/mcp/mcp_post.php ../phpBB-embed-3.0.9/includes/mcp/mcp_post.php
--- ./includes/mcp/mcp_post.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/mcp/mcp_post.php	2010-11-21 12:59:18.000000000 +0300
@@ -23,7 +23,12 @@ function mcp_post_details($id, $mode, $a
 {
 	global $phpEx, $phpbb_root_path, $config;
 	global $template, $db, $user, $auth, $cache;
-
+  //***VB***
+  if (defined('PHPBB_API_EMBEDDED'))
+  {
+    $action =_phpbbforum_get_cp_action_request($action);
+  }
+  //***VB***
 	$user->add_lang('posting');
 
 	$post_id = request_var('p', 0);
@@ -49,7 +54,16 @@ function mcp_post_details($id, $mode, $a
 			if ($auth->acl_get('m_info', $post_info['forum_id']))
 			{
 				$ip = request_var('ip', '');
+				//***VB***
+        if (!defined('PHPBB_API_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+        }
+        else
+        {
+          include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+        }
+        //***VB***
 
 				$template->assign_vars(array(
 					'RETURN_POST'	=> sprintf($user->lang['RETURN_POST'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", "i=$id&amp;mode=$mode&amp;p=$post_id") . '">', '</a>'),
@@ -469,7 +483,16 @@ function change_poster(&$post_info, $use
 
 	if (file_exists($phpbb_root_path . 'includes/search/' . $search_type . '.' . $phpEx))
 	{
+		//***VB***
+    if (!defined('PHPBB_API_EMBEDDED'))
+    {
 		require("{$phpbb_root_path}includes/search/$search_type.$phpEx");
+    }
+    else
+    {
+    require_once("{$phpbb_root_path}includes/search/$search_type.$phpEx");
+    }
+    //***VB***
 
 		// We do some additional checks in the module to ensure it can actually be utilised
 		$error = false;
diff -uprbB ./includes/mcp/mcp_queue.php ../phpBB-embed-3.0.9/includes/mcp/mcp_queue.php
--- ./includes/mcp/mcp_queue.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/mcp/mcp_queue.php	2010-11-21 13:01:48.000000000 +0300
@@ -35,7 +35,12 @@ class mcp_queue
 	{
 		global $auth, $db, $user, $template, $cache;
 		global $config, $phpbb_root_path, $phpEx, $action;
-
+    //***VB***
+    if (defined('PHPBB_API_EMBEDDED'))
+    {
+      $action =_phpbbforum_get_cp_action_request($action);
+    }
+    //***VB***
 		include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 
 		$forum_id = request_var('f', 0);
@@ -900,7 +905,16 @@ function disapprove_post($post_id_list, 
 						{
 							// Load up the language pack
 							$lang = array();
+							//***VB***
+              if (!defined('PHPBB_API_EMBEDDED'))
+              {
 							@include($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
+              }
+              else
+              {
+              @include_once($phpbb_root_path . '/language/' . basename($post_data['user_lang']) . '/mcp.' . $phpEx);
+              }
+              //***VB***
 
 							// If we find the reason in this language pack use it
 							if (isset($lang['report_reasons']['DESCRIPTION'][$disapprove_reason_lang]))
diff -uprbB ./includes/mcp/mcp_reports.php ../phpBB-embed-3.0.9/includes/mcp/mcp_reports.php
--- ./includes/mcp/mcp_reports.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/mcp/mcp_reports.php	2010-11-21 13:02:38.000000000 +0300
@@ -35,7 +35,12 @@ class mcp_reports
 	{
 		global $auth, $db, $user, $template, $cache;
 		global $config, $phpbb_root_path, $phpEx, $action;
-
+    //***VB***
+    if (defined('PHPBB_API_EMBEDDED'))
+    {
+      $action =_phpbbforum_get_cp_action_request($action);
+    }
+    //***VB***
 		include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 
 		$forum_id = request_var('f', 0);
diff -uprbB ./includes/mcp/mcp_topic.php ../phpBB-embed-3.0.9/includes/mcp/mcp_topic.php
--- ./includes/mcp/mcp_topic.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/mcp/mcp_topic.php	2010-11-21 13:04:20.000000000 +0300
@@ -23,6 +23,12 @@ function mcp_topic_view($id, $mode, $act
 {
 	global $phpEx, $phpbb_root_path, $config;
 	global $template, $db, $user, $auth, $cache;
+  //***VB***
+  if (defined('PHPBB_API_EMBEDDED'))
+  {
+    $action =_phpbbforum_get_cp_action_request($action);
+  }
+  //***VB***
 
 	$url = append_sid("{$phpbb_root_path}mcp.$phpEx?" . extra_url());
 
@@ -78,7 +84,16 @@ function mcp_topic_view($id, $mode, $act
 	// Approve posts?
 	if ($action == 'approve' && $auth->acl_get('m_approve', $topic_info['forum_id']))
 	{
+		//***VB***
+    if (!defined('PHPBB_API_EMBEDDED'))
+    {
 		include($phpbb_root_path . 'includes/mcp/mcp_queue.' . $phpEx);
+    }
+    else
+    {
+    include_once($phpbb_root_path . 'includes/mcp/mcp_queue.' . $phpEx);
+    }
+    //***VB***
 		include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 		include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
 
diff -uprbB ./includes/mcp/mcp_warn.php ../phpBB-embed-3.0.9/includes/mcp/mcp_warn.php
--- ./includes/mcp/mcp_warn.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/mcp/mcp_warn.php	2010-03-03 14:00:53.000000000 +0300
@@ -2,7 +2,7 @@
 /**
 *
 * @package mcp
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -305,8 +305,17 @@ class mcp_warn
 		// Generate the appropriate user information for the user we are looking at
 		if (!function_exists('get_user_avatar'))
 		{
+			//***VB***
+      if (!defined('PHPBB_API_EMBEDDED'))
+      {
 			include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 		}
+      else
+      {
+      include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+      }
+      //***VB***
+		}
 
 		$rank_title = $rank_img = '';
 		$avatar_img = get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']);
@@ -410,8 +419,17 @@ class mcp_warn
 		// Generate the appropriate user information for the user we are looking at
 		if (!function_exists('get_user_avatar'))
 		{
+			//***VB***
+      if (!defined('PHPBB_API_EMBEDDED'))
+      {
 			include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 		}
+      else
+      {
+      include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+      }
+      //***VB***
+		}
 
 		$rank_title = $rank_img = '';
 		$avatar_img = get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']);
@@ -454,7 +472,16 @@ function add_warning($user_row, $warning
 		include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
 
 		$user_row['user_lang'] = (file_exists($phpbb_root_path . 'language/' . $user_row['user_lang'] . "/mcp.$phpEx")) ? $user_row['user_lang'] : $config['default_lang'];
+    //***VB***
+    if (!defined('PHPBB_API_EMBEDDED'))
+    {
 		include($phpbb_root_path . 'language/' . basename($user_row['user_lang']) . "/mcp.$phpEx");
+    }
+    else
+    {
+    include_once($phpbb_root_path . 'language/' . basename($user_row['user_lang']) . "/mcp.$phpEx");
+    }
+    //***VB***
 
 		$message_parser = new parse_message();
 
diff -uprbB ./includes/session.php ../phpBB-embed-3.0.9/includes/session.php
--- ./includes/session.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/session.php	2010-11-21 12:32:47.000000000 +0300
@@ -1620,6 +1620,12 @@ class user extends session
 		{
 			// Set up style
 			$style = ($style) ? $style : ((!$config['override_user_style']) ? $this->data['user_style'] : $config['default_style']);
+      //***VB***
+      if (defined('PHPBB_API_EMBEDDED'))
+      {
+        $style = phpbb_get_embed_style($style);
+      }
+      //***VB***
 		}
 
 		$sql = 'SELECT s.style_id, t.template_storedb, t.template_path, t.template_id, t.bbcode_bitfield, t.template_inherits_id, t.template_inherit_path, c.theme_path, c.theme_name, c.theme_storedb, c.theme_id, i.imageset_path, i.imageset_id, i.imageset_name
@@ -2256,7 +2262,17 @@ class user extends session
 	function img($img, $alt = '', $width = false, $suffix = '', $type = 'full_tag')
 	{
 		static $imgs;
+		//***VB***
+    if (defined('PHPBB_API_EMBEDDED')) 
+    {
+      global $phpbb_config;
+      $phpbb_root_path = $phpbb_config['forum_url'] .'/';
+    }
+    else
+    {
 		global $phpbb_root_path;
+    }
+    //***VB***
 
 		$img_data = &$imgs[$img];
 
@@ -2398,8 +2414,17 @@ class user extends session
 		{
 			global $phpbb_root_path, $phpEx;
 
+      //***VB***
+      if (!defined('PHPBB_API_EMBEDDED'))
+      {
 			include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
 		}
+      else
+      {
+      include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+      }  
+      //***VB***
+		}
 		if ($group = remove_newly_registered($this->data['user_id'], $this->data))
 		{
 			$this->data['group_id'] = $group;
diff -uprbB ./includes/ucp/ucp_confirm.php ../phpBB-embed-3.0.9/includes/ucp/ucp_confirm.php
--- ./includes/ucp/ucp_confirm.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/ucp/ucp_confirm.php	2010-03-03 14:00:53.000000000 +0300
@@ -2,7 +2,7 @@
 /**
 *
 * @package VC
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 2008 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -37,7 +37,16 @@ class ucp_confirm
 	{
 		global $db, $user, $phpbb_root_path, $config, $phpEx;
 
+    //***VB***
+    if (!defined('PHPBB_EMBEDDED'))
+    {
 		include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
+    }
+    else
+    {
+    include_once($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
+    }
+    //***VB***
 		$captcha = phpbb_captcha_factory::get_instance($config['captcha_plugin']);
 		$captcha->init(request_var('type', 0));
 		$captcha->execute();
diff -uprbB ./includes/ucp/ucp_groups.php ../phpBB-embed-3.0.9/includes/ucp/ucp_groups.php
--- ./includes/ucp/ucp_groups.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/ucp/ucp_groups.php	2010-11-21 13:05:40.000000000 +0300
@@ -415,7 +415,16 @@ class ucp_groups
 				$action		= (isset($_POST['addusers'])) ? 'addusers' : request_var('action', '');
 				$group_id	= request_var('g', 0);
 
+				//***VB***
+        if (!defined('PHPBB_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+        }
+        else
+        {
+        include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+        }
+        //***VB***
 
 				add_form_key('ucp_groups');
 
diff -uprbB ./includes/ucp/ucp_main.php ../phpBB-embed-3.0.9/includes/ucp/ucp_main.php
--- ./includes/ucp/ucp_main.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/ucp/ucp_main.php	2010-11-21 13:07:01.000000000 +0300
@@ -198,7 +198,16 @@ class ucp_main
 
 			case 'subscribed':
 
+				//***VB***			
+        if (!defined('PHPBB_API_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+        }
+        else
+        {
+        include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+        }
+        //***VB***
 
 				$user->add_lang('viewforum');
 
@@ -383,7 +392,16 @@ class ucp_main
 					break;
 				}
 
+				//***VB***			
+        if (!defined('PHPBB_API_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+        }
+        else
+        {
+        include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+        }
+        //***VB***
 
 				$user->add_lang('viewforum');
 
diff -uprbB ./includes/ucp/ucp_pm_compose.php ../phpBB-embed-3.0.9/includes/ucp/ucp_pm_compose.php
--- ./includes/ucp/ucp_pm_compose.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/ucp/ucp_pm_compose.php	2010-11-21 13:07:58.000000000 +0300
@@ -29,9 +29,20 @@ function compose_pm($id, $mode, $action)
 	// Needed for handle_message_list_actions()
 	global $refresh, $submit, $preview;
 
+	//***VB***
+  if (!defined('PHPBB_API_EMBEDDED'))
+  {
 	include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 	include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 	include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
+  }
+  else
+  {
+  include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
+  include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+  include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
+  }
+  //***VB***
 
 	if (!$action)
 	{
diff -uprbB ./includes/ucp/ucp_pm.php ../phpBB-embed-3.0.9/includes/ucp/ucp_pm.php
--- ./includes/ucp/ucp_pm.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/ucp/ucp_pm.php	2010-03-03 14:00:53.000000000 +0300
@@ -1,7 +1,7 @@
 <?php
 /**
 * @package ucp
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -80,7 +80,16 @@ class ucp_pm
 			$mode = 'view';
 		}
 
+		//***VB***
+    if (!defined('PHPBB_EMBEDDED'))
+    {
 		include($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
+    }
+    else
+    {
+    include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
+    }
+    //***VB***
 
 		switch ($mode)
 		{
@@ -129,7 +138,16 @@ class ucp_pm
 					break;
 				}
 
+				//***VB***
+        if (!defined('PHPBB_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/ucp/ucp_pm_compose.' . $phpEx);
+        }
+        else
+        {
+        include_once($phpbb_root_path . 'includes/ucp/ucp_pm_compose.' . $phpEx);
+        }
+        //***VB***
 				compose_pm($id, $mode, $action, $user_folders);
 
 				$tpl_file = 'posting_body';
@@ -139,7 +157,16 @@ class ucp_pm
 				set_user_message_limit();
 				get_folder($user->data['user_id']);
 
+				//***VB***
+        if (!defined('PHPBB_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/ucp/ucp_pm_options.' . $phpEx);
+        }
+        else
+        {
+        include_once($phpbb_root_path . 'includes/ucp/ucp_pm_options.' . $phpEx);
+        }
+        //***VB***
 				message_options($id, $mode, $global_privmsgs_rules, $global_rule_conditions);
 
 				$tpl_file = 'ucp_pm_options';
@@ -151,7 +178,16 @@ class ucp_pm
 				$this->p_name = 'pm';
 
 				// Call another module... please do not try this at home... Hoochie Coochie Man
+				//***VB***
+        if (!defined('PHPBB_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/ucp/ucp_main.' . $phpEx);
+        }
+        else
+        {
+        include_once($phpbb_root_path . 'includes/ucp/ucp_main.' . $phpEx);
+        }
+        //***VB***
 
 				$module = new ucp_main($this);
 				$module->u_action = $this->u_action;
@@ -372,7 +408,16 @@ class ucp_pm
 
 				if ($action == 'view_folder')
 				{
+					//***VB***
+          if (!defined('PHPBB_EMBEDDED'))
+          {
 					include($phpbb_root_path . 'includes/ucp/ucp_pm_viewfolder.' . $phpEx);
+          }
+          else
+          {
+          include_once($phpbb_root_path . 'includes/ucp/ucp_pm_viewfolder.' . $phpEx);
+          }
+          //***VB***
 					view_folder($id, $mode, $folder_id, $folder);
 
 					$tpl_file = 'ucp_pm_viewfolder';
@@ -389,7 +434,16 @@ class ucp_pm
 						trigger_error('NO_MESSAGE');
 					}
 
+					//***VB***
+          if (!defined('PHPBB_EMBEDDED'))
+          {
 					include($phpbb_root_path . 'includes/ucp/ucp_pm_viewmessage.' . $phpEx);
+          }
+          else
+          {
+          include_once($phpbb_root_path . 'includes/ucp/ucp_pm_viewmessage.' . $phpEx);
+          }
+          //***VB***
 					view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row);
 
 					$tpl_file = ($view == 'print') ? 'ucp_pm_viewmessage_print' : 'ucp_pm_viewmessage';
diff -uprbB ./includes/ucp/ucp_pm_viewmessage.php ../phpBB-embed-3.0.9/includes/ucp/ucp_pm_viewmessage.php
--- ./includes/ucp/ucp_pm_viewmessage.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/ucp/ucp_pm_viewmessage.php	2010-11-21 13:11:36.000000000 +0300
@@ -55,7 +55,16 @@ function view_message($id, $mode, $folde
 	// Instantiate BBCode if need be
 	if ($message_row['bbcode_bitfield'])
 	{
+		//***VB***
+    if (!defined('PHPBB_EMBEDDED'))
+    {
 		include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
+    }
+    else
+    {
+    include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
+    }
+    //***VB***
 		$bbcode = new bbcode($message_row['bbcode_bitfield']);
 	}
 
@@ -156,7 +165,16 @@ function view_message($id, $mode, $folde
 		{
 			if ($bbcode === false)
 			{
+				//***VB***
+        if (!defined('PHPBB_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
+        }
+        else
+        {
+        include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
+        }
+        //***VB***
 				$bbcode = new bbcode($user_info['user_sig_bbcode_bitfield']);
 			}
 
@@ -305,8 +323,17 @@ function get_user_information($user_id, 
 
 	if (!function_exists('get_user_avatar'))
 	{
+		//***VB***
+    if (!defined('PHPBB_EMBEDDED'))
+    {
 		include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 	}
+    else
+    {
+    include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+    }
+    //***VB***
+	}
 
 	$user_row['avatar'] = ($user->optionget('viewavatars')) ? get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']) : '';
 
diff -uprbB ./includes/ucp/ucp_profile.php ../phpBB-embed-3.0.9/includes/ucp/ucp_profile.php
--- ./includes/ucp/ucp_profile.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/ucp/ucp_profile.php	2010-11-21 13:14:01.000000000 +0300
@@ -262,7 +262,16 @@ class ucp_profile
 
 			case 'profile_info':
 
+				//***VB***			
+        if (!defined('PHPBB_API_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
+        }
+        else
+        {
+        include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
+        }
+        //***VB***
 
 				$cp = new custom_profile();
 
@@ -450,8 +459,18 @@ class ucp_profile
 					trigger_error('NO_AUTH_SIGNATURE');
 				}
 
+				//***VB***			
+        if (!defined('PHPBB_API_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 				include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+        }
+        else
+        {
+        include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
+				include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+        }
+        //***VB***
 
 				$enable_bbcode	= ($config['allow_sig_bbcode']) ? (bool) $user->optionget('sig_bbcode') : false;
 				$enable_smilies	= ($config['allow_sig_smilies']) ? (bool) $user->optionget('sig_smilies') : false;
@@ -463,7 +482,16 @@ class ucp_profile
 
 				if ($submit || $preview)
 				{
+					//***VB***			
+          if (!defined('PHPBB_API_EMBEDDED'))
+          {
 					include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
+          }
+          else
+          {
+          include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
+          }
+          //***VB***
 
 					$enable_bbcode	= ($config['allow_sig_bbcode']) ? ((request_var('disable_bbcode', false)) ? false : true) : false;
 					$enable_smilies	= ($config['allow_sig_smilies']) ? ((request_var('disable_smilies', false)) ? false : true) : false;
@@ -555,7 +583,16 @@ class ucp_profile
 
 			case 'avatar':
 
+				//***VB***			
+        if (!defined('PHPBB_API_EMBEDDED'))
+        {
 				include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+        }
+        else
+        {
+        include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+        }
+        //***VB***
 
 				$display_gallery = request_var('display_gallery', '0');
 				$avatar_select = basename(request_var('avatar_select', ''));
diff -uprbB ./includes/ucp/ucp_register.php ../phpBB-embed-3.0.9/includes/ucp/ucp_register.php
--- ./includes/ucp/ucp_register.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/includes/ucp/ucp_register.php	2010-11-21 13:15:31.000000000 +0300
@@ -35,7 +35,16 @@ class ucp_register
 			trigger_error('UCP_REGISTER_DISABLE');
 		}
 
+		//***VB***
+    if (!defined('PHPBB_API_EMBEDDED'))
+    {
 		include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
+    }
+    else
+    {
+    include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
+    }
+    //***VB***
 
 		$coppa			= (isset($_REQUEST['coppa'])) ? ((!empty($_REQUEST['coppa'])) ? 1 : 0) : false;
 		$agreed			= (!empty($_POST['agreed'])) ? 1 : 0;
@@ -160,7 +169,16 @@ class ucp_register
 		// The CAPTCHA kicks in here. We can't help that the information gets lost on language change. 
 		if ($config['enable_confirm'])
 		{
+			//***VB***
+      if (!defined('PHPBB_API_EMBEDDED'))
+      {
 			include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
+      }
+      else
+      {
+      include_once($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
+      }
+      //***VB***
 			$captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
 			$captcha->init(CONFIRM_REG);
 		}
diff -uprbB ./index.php ../phpBB-embed-3.0.9/index.php
--- ./index.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/index.php	2010-11-21 11:15:36.000000000 +0300
@@ -14,11 +14,20 @@
 /**
 * @ignore
 */
+//***VB***
+if (!defined('PHPBB_API_EMBEDDED'))
+{
 define('IN_PHPBB', true);
 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);
 include($phpbb_root_path . 'common.' . $phpEx);
 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+}
+else
+{
+include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+}
+//***VB***
 
 // Start session management
 $user->session_begin();
diff -uprbB ./mcp.php ../phpBB-embed-3.0.9/mcp.php
--- ./mcp.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/mcp.php	2010-03-03 14:00:53.000000000 +0300
@@ -2,7 +2,7 @@
 /**
 *
 * @package mcp
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -11,12 +11,22 @@
 /**
 * @ignore
 */
+//***VB***
+if (!defined('PHPBB_API_EMBEDDED'))
+{
 define('IN_PHPBB', true);
 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);
 include($phpbb_root_path . 'common.' . $phpEx);
 include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
 require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
+}
+else
+{
+include_once($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
+require_once($phpbb_root_path . 'includes/functions_module.' . $phpEx);
+}
+//***VB***
 
 // Start session management
 $user->session_begin();
diff -uprbB ./memberlist.php ../phpBB-embed-3.0.9/memberlist.php
--- ./memberlist.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/memberlist.php	2010-11-21 11:20:38.000000000 +0300
@@ -11,11 +11,20 @@
 /**
 * @ignore
 */
+//***VB***
+if (!defined('PHPBB_API_EMBEDDED'))
+{
 define('IN_PHPBB', true);
 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);
 include($phpbb_root_path . 'common.' . $phpEx);
 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+}
+else
+{
+include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+}
+//***VB***
 
 // Start session management
 $user->session_begin();
@@ -72,7 +81,16 @@ switch ($mode)
 {
 	case 'leaders':
 		// Display a listing of board admins, moderators
+		//***VB***
+    if (!defined('PHPBB_EMBEDDED'))
+    {
 		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+    }
+    else
+    {
+    include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+    }
+    //***VB***
 
 		$page_title = $user->lang['THE_TEAM'];
 		$template_html = 'memberlist_leaders.html';
Только в .: phpBB-embed-3.0.9.patch
diff -uprbB ./posting.php ../phpBB-embed-3.0.9/posting.php
--- ./posting.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/posting.php	2010-11-21 11:23:51.000000000 +0300
@@ -11,6 +11,9 @@
 /**
 * @ignore
 */
+//***VB***
+if (!defined('PHPBB_API_EMBEDDED'))
+{
 define('IN_PHPBB', true);
 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);
@@ -18,7 +21,14 @@ include($phpbb_root_path . 'common.' . $
 include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
-
+}
+else
+{
+include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
+include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
+}
+//***VB***
 
 // Start session management
 $user->session_begin();
@@ -181,7 +191,16 @@ $user->setup(array('posting', 'mcp', 'vi
 
 if ($config['enable_post_confirm'] && !$user->data['is_registered'])
 {
+	//***VB***
+  if (!defined('PHPBB_API_EMBEDDED'))
+  {
 	include($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
+  }
+  else
+  {
+  include_once($phpbb_root_path . 'includes/captcha/captcha_factory.' . $phpEx);
+  }  
+  //***VB***
 	$captcha =& phpbb_captcha_factory::get_instance($config['captcha_plugin']);
 	$captcha->init(CONFIRM_POST);
 }
@@ -831,7 +850,16 @@
 	// Validate username
 	if (($post_data['username'] && !$user->data['is_registered']) || ($mode == 'edit' && $post_data['poster_id'] == ANONYMOUS && $post_data['username'] && $post_data['post_username'] && $post_data['post_username'] != $post_data['username']))
 	{
-		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+		//***VB***
+		if (!defined('PHPBB_API_EMBEDDED'))
+		{
+			include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+		}
+		else
+		{
+			include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+		}  
+		//***VB***
 
 		$user->add_lang('ucp');
 
diff -uprbB ./report.php ../phpBB-embed-3.0.9/report.php
--- ./report.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/report.php	2010-03-03 14:00:53.000000000 +0300
@@ -2,7 +2,7 @@
 /**
 *
 * @package phpBB3
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -11,11 +11,20 @@
 /**
 * @ignore
 */
+//***VB***
+if (!defined('PHPBB_API_EMBEDDED'))
+{
 define('IN_PHPBB', true);
 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);
 include($phpbb_root_path . 'common.' . $phpEx);
 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+}
+else
+{
+include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+}
+//***VB***
 
 // Start session management
 $user->session_begin();
diff -uprbB ./search.php ../phpBB-embed-3.0.9/search.php
--- ./search.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/search.php	2010-11-21 11:45:05.000000000 +0300
@@ -11,10 +11,15 @@
 /**
 * @ignore
 */
+//***VB***
+if (!defined('PHPBB_API_EMBEDDED'))
+{
 define('IN_PHPBB', true);
 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);
 include($phpbb_root_path . 'common.' . $phpEx);
+}
+//***VB***
 
 // Start session management
 $user->session_begin();
@@ -280,7 +285,16 @@ if ($keywords || $author || $author_id |
 		trigger_error('NO_SUCH_SEARCH_MODULE');
 	}
 
+	//***VB***
+  if (!defined('PHPBB_API_EMBEDDED'))
+  {
 	require("{$phpbb_root_path}includes/search/$search_type.$phpEx");
+  }
+  else
+  {
+    require_once("{$phpbb_root_path}includes/search/$search_type.$phpEx");
+  }
+  //***VB***
 
 	// We do some additional checks in the module to ensure it can actually be utilised
 	$error = false;
@@ -530,12 +544,30 @@ if ($keywords || $author || $author_id |
 
 	if ($show_results == 'posts')
 	{
+    //***VB***
+    if (defined('PHPBB_API_EMBEDDED'))
+    {
+      include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
+    }
+    else
+    {
 		include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
 	}
+    //***VB***
+	}
+	else
+	{
+    //***VB***
+    if (defined('PHPBB_API_EMBEDDED'))
+    {
+      include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+    }
 	else
 	{
 		include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 	}
+    //***VB***
+	}
 
 	$user->add_lang('viewtopic');
 
diff -uprbB ./ucp.php ../phpBB-embed-3.0.9/ucp.php
--- ./ucp.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/ucp.php	2010-11-21 11:48:15.000000000 +0300
@@ -11,12 +11,22 @@
 /**
 * @ignore
 */
+//***VB***
+if (!defined('PHPBB_API_EMBEDDED'))
+{
 define('IN_PHPBB', true);
 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);
 require($phpbb_root_path . 'common.' . $phpEx);
 require($phpbb_root_path . 'includes/functions_user.' . $phpEx);
 require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
+}
+else
+{
+require_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+require_once($phpbb_root_path . 'includes/functions_module.' . $phpEx);
+}
+//***VB***
 
 // Basic parameter data
 $id 	= request_var('i', '');
@@ -92,6 +102,12 @@ switch ($mode)
 		{
 			$message = ($user->data['user_id'] == ANONYMOUS) ? $user->lang['LOGOUT_REDIRECT'] : $user->lang['LOGOUT_FAILED'];
 		}
+    //***VB***
+    if (defined('PHPBB_API_EMBEDDED'))
+    {
+      _phpbb_api_hook('logout', array('username' => $user->data['username'], 'user_id' => $user->data['user_id'], 'redirect' => append_sid("{$phpbb_root_path}index.$phpEx")));
+    }
+    //***VB***
 		meta_refresh(3, append_sid("{$phpbb_root_path}index.$phpEx"));
 
 		$message = $message . '<br /><br />' . sprintf($user->lang['RETURN_INDEX'], '<a href="' . append_sid("{$phpbb_root_path}index.$phpEx") . '">', '</a> ');
@@ -197,7 +213,16 @@ switch ($mode)
 			redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
 		}
 
+		//***VB***			
+    if (!defined('PHPBB_API_EMBEDDED'))
+    {
 		include($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
+    }
+    else
+    {
+    include_once($phpbb_root_path . 'includes/acp/auth.' . $phpEx);
+    }
+    //***VB***
 
 		$auth_admin = new auth_admin();
 		if (!$auth_admin->ghost_permissions($user_id, $user->data['user_id']))
diff -uprbB ./viewforum.php ../phpBB-embed-3.0.9/viewforum.php
--- ./viewforum.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/viewforum.php	2010-11-21 11:48:55.000000000 +0300
@@ -11,11 +11,20 @@
 /**
 * @ignore
 */
+//***VB***
+if (!defined('PHPBB_API_EMBEDDED'))
+{
 define('IN_PHPBB', true);
 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);
-include($phpbb_root_path . 'common.' . $phpEx);
+include($phpbb_root_path . 'common.'.$phpEx);
 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+}
+else
+{
+include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+}
+//***VB***
 
 // Start session
 $user->session_begin();
diff -uprbB ./viewonline.php ../phpBB-embed-3.0.9/viewonline.php
--- ./viewonline.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/viewonline.php	2010-03-03 14:00:53.000000000 +0300
@@ -2,7 +2,7 @@
 /**
 *
 * @package phpBB3
-* @version $Id$
+* @version $Id$
 * @copyright (c) 2005 phpBB Group
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 *
@@ -11,10 +11,15 @@
 /**
 * @ignore
 */
+//***VB***
+if (!defined('PHPBB_API_EMBEDDED'))
+{
 define('IN_PHPBB', true);
 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);
 include($phpbb_root_path . 'common.' . $phpEx);
+}
+//***VB***
 
 // Start session management
 $user->session_begin();
@@ -54,7 +59,16 @@ $order_by = $sort_key_sql[$sort_key] . '
 // Whois requested
 if ($mode == 'whois' && $auth->acl_get('a_') && $session_id)
 {
+	//***VB***
+  if (!defined('PHPBB_API_EMBEDDED'))
+  {
 	include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+  }
+  else
+  {
+  include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
+  }
+  //***VB***
 
 	$sql = 'SELECT u.user_id, u.username, u.user_type, s.session_ip
 		FROM ' . USERS_TABLE . ' u, ' . SESSIONS_TABLE . " s
@@ -409,9 +423,13 @@ while ($row = $db->sql_fetchrow($result)
 }
 $db->sql_freeresult($result);
 
+//***VB***
+if (!defined('PHPBB_API_EMBEDDED'))
+{
 // Refreshing the page every 60 seconds...
 meta_refresh(60, append_sid("{$phpbb_root_path}viewonline.$phpEx", "sg=$show_guests&amp;sk=$sort_key&amp;sd=$sort_dir&amp;start=$start"));
-
+}
+//***VB***
 // Send data to template
 $template->assign_vars(array(
 	'TOTAL_REGISTERED_USERS_ONLINE'	=> sprintf($l_r_user_s, $logged_visible_online) . sprintf($l_h_user_s, $logged_hidden_online),
diff -uprbB ./viewtopic.php ../phpBB-embed-3.0.9/viewtopic.php
--- ./viewtopic.php	2010-11-19 15:22:36.000000000 +0300
+++ ../phpBB-embed-3.0.9/viewtopic.php	2010-11-21 11:53:33.000000000 +0300
@@ -11,12 +11,22 @@
 /**
 * @ignore
 */
+//***VB***
+if (!defined('PHPBB_EMBEDDED'))
+{
 define('IN_PHPBB', true);
 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
 $phpEx = substr(strrchr(__FILE__, '.'), 1);
 include($phpbb_root_path . 'common.' . $phpEx);
 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
+}
+else
+{
+include_once($phpbb_root_path . 'includes/functions_display.' . $phpEx);
+include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
+}
+//***VB***
 
 // Start session management
 $user->session_begin();
@@ -1203,10 +1213,23 @@ $db->sql_freeresult($result);
 // Load custom profile fields
 if ($config['load_cpf_viewtopic'])
 {
+	//***VB***
+  if (!defined('PHPBB_API_EMBEDDED'))
+  {
 	if (!class_exists('custom_profile'))
 	{
 		include($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
 	}
+  }
+  else
+  {
+    if (!class_exists('custom_profile'))
+    {
+      include_once($phpbb_root_path . 'includes/functions_profile_fields.' . $phpEx);
+    }
+  }
+  //***VB***
+	
 	$cp = new custom_profile();
 
 	// Grab all profile fields from users in id cache for later use - similar to the poster cache
@@ -1609,6 +1632,29 @@ for ($i = 0, $end = sizeof($post_list); 
 unset($rowset, $user_cache);
 
 // Update topic view and if necessary attachment view counters ... but only for humans and if this is the first 'page view'
+//***VB***
+if (defined('PHPBB_API_EMBEDDED'))
+{
+  global $_phpbb_embed_mode;
+  if (isset($user->data['session_page']) && !$user->data['is_bot'] && (strpos($user->data['session_page'], '&t=' . $topic_id) === false || isset($user->data['session_created']) || $_phpbb_embed_mode['update_topic_view']))
+  {
+    $sql = 'UPDATE ' . TOPICS_TABLE . '
+  		SET topic_views = topic_views + 1, topic_last_view_time = ' . time() . "
+  		WHERE topic_id = $topic_id";
+  	$db->sql_query($sql);
+
+  	// Update the attachment download counts
+  	if (sizeof($update_count))
+  	{
+  		$sql = 'UPDATE ' . ATTACHMENTS_TABLE . '
+  			SET download_count = download_count + 1
+  			WHERE ' . $db->sql_in_set('attach_id', array_unique($update_count));
+  		$db->sql_query($sql);
+  	}
+  }
+}
+else
+//***VB***
 if (isset($user->data['session_page']) && !$user->data['is_bot'] && (strpos($user->data['session_page'], '&t=' . $topic_id) === false || isset($user->data['session_created'])))
 {
 	$sql = 'UPDATE ' . TOPICS_TABLE . '
