############################################################## 
## MOD Title: Bookmarks
## MOD Author: PhilippK < phpBB2006 <at> kordowich.net > (Philipp Kordowich) http://phpbb.kordowich.net/
## MOD Description: Keeps an internal list of bookmarks set by the user 
## MOD Version: 1.1.1i
## 
## Installation Level: Intermediate
## Installation Time: 30 Minutes 
## Files To Edit: modcp.php,
## posting.php,
## search.php,
## viewtopic.php,
## admin/admin_board.php
## admin/admin_db_utilities.php,
## admin/admin_users.php
## includes/constants.php,
## includes/functions.php,
## includes/functions_post.php,
## includes/page_header.php,
## includes/prune.php,
## includes/usercp_avatar.php,
## includes/usercp_register.php,
## language/lang_english/lang_admin.php,
## language/lang_english/lang_main.php,
## language/lang_german/lang_admin.php, (if needed)
## language/lang_german/lang_main.php, (if needed)
## templates/subSilver/overall_header.tpl, 
## templates/subSilver/posting_body.tpl, 
## templates/subSilver/profile_add_body.tpl, 
## templates/subSilver/viewtopic_body.tpl, 
## templates/subSilver/admin/board_config_body.tpl
## templates/subSilver/admin/user_edit_body.tpl
## Included Files: functions_bookmark.php,
## icon_mini_bookmark.gif,
## search_results_bookmarks.tpl,
## update_db_for_bookmarks.php 
############################################################## 
## For Security Purposes, Please Check: http://phpbb.kordowich.net/ for the 
## latest version of this MOD. Downloading this MOD from other sites could cause malicious code 
## to enter into your phpBB Forum.
############################################################## 
## Author Notes:
## Read README.txt for further information
############################################################## 
## MOD History: 
## Read README.txt for mod history
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
############################################################## 

#
#-----[ SQL ]-------------------------------------------------
#

# If you use a MySQL-Database, you can use the included script-file 'update_db_for_bookmarks.php'
# (included in files-folder) to update your database. This script will use the right prefix for
# your tabel, so you don't have to care about these things. To exececute it, just copy it to the
# phpBB-directory of your forum (the directory where you can find the config.php) an execute it by
# calling it with your browser.
# It's recomended to remove the file afterwards from the server for security reasons.
#
# If you do not use a MySQL-Database, you have to execute these two SQL-Commands. Please keep in
# mind that you need to change the tabel-prefixes if you didn't use 'phpbb'. It may be necessary
# to change the SQL-commands depending on the database you use.

CREATE TABLE phpbb_bookmarks (
	topic_id mediumint(8) unsigned NOT NULL default '0',
	user_id mediumint(8) NOT NULL default '0',
	KEY topic_id (topic_id),
	KEY user_id (user_id));
ALTER TABLE phpbb_users
	ADD user_setbm tinyint(1) NOT NULL default '0' AFTER user_attachsig;
INSERT INTO phpbb_config(config_name, config_value) VALUES ('max_link_bookmarks', '0');

#
#-----[ COPY ]------------------------------------------------
#
copy files/functions_bookmark.php to includes/functions_bookmark.php
copy files/search_results_bookmarks.tpl to templates/subSilver/search_results_bookmarks.tpl
copy files/icon_mini_bookmark.gif to templates/subSilver/images/icon_mini_bookmark.gif

#
#-----[ OPEN ]------------------------------------------------
#
modcp.php

#
#-----[ FIND ]------------------------------------------------
# 
			if ( $post_id_sql != '' )

#
#-----[ BEFORE, ADD ]-----------------------------------------
#
			$sql = "DELETE 
				FROM " . BOOKMARK_TABLE . " 
				WHERE topic_id IN ($topic_id_sql)";
			if ( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, 'Could not delete bookmarks', '', __LINE__, __FILE__, $sql);
			}


#
#-----[ OPEN ]------------------------------------------------
#
posting.php

#
#-----[ FIND ]------------------------------------------------
#
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);

#
#-----[ AFTER, ADD ]------------------------------------------
#
include($phpbb_root_path . 'includes/functions_bookmark.'.$phpEx);

#
#-----[ FIND ]------------------------------------------------
#
$attach_sig = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['attach_sig']) ) ? TRUE : 0 ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? 0 : $userdata['user_attachsig'] );

#
#-----[ AFTER, ADD ]------------------------------------------
#
$setbm = ( $submit || $refresh ) ? ( ( !empty($HTTP_POST_VARS['setbm']) ) ? TRUE : 0 ) : ( ( $userdata['user_id'] == ANONYMOUS ) ? 0 : $userdata['user_setbm'] );

#
#-----[ FIND ]------------------------------------------------
#
			user_notification($mode, $post_data, $post_info['topic_title'], $forum_id, $topic_id, $post_id, $notify_user);

#
#-----[ BEFORE, ADD ]------------------------------------------
#
			if ( $setbm )
			{
				set_bookmark($topic_id);
			}

#
#-----[ FIND ]------------------------------------------------
#
		$template->assign_block_vars('switch_notify_checkbox', array());
	}
}

#
#-----[ AFTER, ADD ]------------------------------------------
#

//
// Bookmark checkbox - only show if user is logged in and not editing a post
//
if ( $userdata['session_logged_in'] )
{
	if ( $mode != 'editpost' )
	{
		$template->assign_block_vars('switch_bookmark_checkbox', array());
	}
}

#
#-----[ FIND ]------------------------------------------------
#
	'L_ATTACH_SIGNATURE' => $lang['Attach_signature'], 

#
#-----[ AFTER, ADD ]------------------------------------------
#
	'L_SET_BOOKMARK' => $lang['Set_Bookmark'],

#
#-----[ FIND ]------------------------------------------------
#
	'S_SIGNATURE_CHECKED' => ( $attach_sig ) ? 'checked="checked"' : '', 

#
#-----[ AFTER, ADD ]------------------------------------------
#
	'S_SETBM_CHECKED' => ( $setbm ) ? 'checked="checked"' : '',

#
#-----[ OPEN ]------------------------------------------------
#
search.php

#
#-----[ FIND ]------------------------------------------------
#
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);

#
#-----[ AFTER, ADD ]------------------------------------------
#
include($phpbb_root_path . 'includes/functions_bookmark.'.$phpEx);

#
#-----[ FIND ]------------------------------------------------
#
if ( $mode == 'searchuser' )

#
#-----[ BEFORE, ADD ]-----------------------------------------
#
if ( $mode == 'removebm' )
{
	// Delete Bookmarks
	$delete = ( isset($HTTP_POST_VARS['delete']) ) ? TRUE : FALSE;
	if ( $delete && isset($HTTP_POST_VARS['topic_id_list']))
	{
		$topics = $HTTP_POST_VARS['topic_id_list'];
		for($i = 0; $i < count($topics); $i++)
		{
			$topic_list .= ( ( $topic_list != '' ) ? ', ' : '' ) . intval($topics[$i]);
		}
		if ( $userdata['session_logged_in'] )
		{
			remove_bookmark($topic_list);
		}
		else
		{
			redirect(append_sid("login.$phpEx?redirect=search.$phpEx?search_id=bookmarks", true));
		}
	}
	// Reset settings
	$mode = '';
}

#
#-----[ FIND ]------------------------------------------------
#
	//
	// Cycle through options ...
	//
	if ( $search_id == 'newposts' || $search_id == 'egosearch' || $search_id == 'unanswered' || $search_keywords != '' || $search_author != '' )

#
#-----[ REPLACE WITH ]----------------------------------------
#
	//
	// Cycle through options ...
	//
	if ( $search_id == 'newposts' || $search_id == 'egosearch' || $search_id == 'unanswered' || $search_id == 'bookmarks' || $search_keywords != '' || $search_author != '' )

#
#-----[ FIND ]------------------------------------------------
#
		else
		{
			message_die(GENERAL_MESSAGE, $lang['No_search_match']);
		}

		//
		// Finish building query (for all combinations)
		// and run it ...
		//

#
#-----[ BEFORE, ADD ]-----------------------------------------
#
		else if ( $search_id == 'bookmarks' )
		{
			if ( $userdata['session_logged_in'] )
			{
				if ( $auth_sql != '' )
				{
					$sql = "SELECT t.topic_id, f.forum_id
						FROM " . TOPICS_TABLE . "  t, " . BOOKMARK_TABLE . " b, " . FORUMS_TABLE . " f
						WHERE t.topic_id = b.topic_id
							AND t.forum_id = f.forum_id
							AND b.user_id = " . $userdata['user_id'] . "
							AND $auth_sql";
				}
				else
				{
					$sql = "SELECT t.topic_id
						FROM " . TOPICS_TABLE . " t, " . BOOKMARK_TABLE . " b
						WHERE t.topic_id = b.topic_id
							AND b.user_id = " . $userdata['user_id'];
				}
			}
			else
			{
				redirect(append_sid("login.$phpEx?redirect=search.$phpEx?search_id=bookmarks", true));
			}

			if ( !($result = $db->sql_query($sql)) )
			{
				message_die(GENERAL_ERROR, 'Could not obtain post ids', '', __LINE__, __FILE__, $sql);
			}

			$search_ids = array();
			while( $row = $db->sql_fetchrow($result) )
			{
				$search_ids[] = $row['topic_id'];
			}
			$db->sql_freeresult($result);

			$total_match_count = count($search_ids);
			if ($total_match_count <= $start) // No results for the selected page
			{
				$start = $total_match_count - 1;
				$start = intval($start / $board_config['topics_per_page']) * $board_config['topics_per_page'];
			}

			//
			// Basic requirements
			//
			$show_results = 'bookmarks';
			$sort_by = 0;
			$sort_dir = 'DESC';
		}

#
#-----[ FIND ]------------------------------------------------
#
		$page_title = $lang['Search'];
		include($phpbb_root_path . 'includes/page_header.'.$phpEx);	

		if ( $show_results == 'posts' )

#
#-----[ REPLACE WITH ]----------------------------------------
#
		$page_title = $lang['Search'];
		include($phpbb_root_path . 'includes/page_header.'.$phpEx);	

		if ( $show_results == 'bookmarks' ) 
		{
			$template->set_filenames(array(
				'body' => 'search_results_bookmarks.tpl')
			);
		}
		else if ( $show_results == 'posts' )

#
#-----[ FIND ]------------------------------------------------
#
		$l_search_matches = ( $total_match_count == 1 ) ? sprintf($lang['Found_search_match'], $total_match_count) : sprintf($lang['Found_search_matches'], $total_match_count);

#
#-----[ REPLACE WITH ]----------------------------------------
#
		if ( $show_results == 'bookmarks' )
		{
			$l_search_matches = ( $total_match_count == 1 ) ? sprintf($lang['Found_bookmark'], $total_match_count) : sprintf($lang['Found_bookmarks'], $total_match_count);
			// Send variables for bookmarks
			$template->assign_vars(array(
				'L_DELETE' => $lang['Delete'],
				
				'S_BM_ACTION' => append_sid("search.$phpEx?search_id=bookmarks&start=$start"),
				'S_HIDDEN_FIELDS' => '<input type="hidden" name="mode" value="removebm" />')
			);
		}
		else
		{
			$l_search_matches = ( $total_match_count == 1 ) ? sprintf($lang['Found_search_match'], $total_match_count) : sprintf($lang['Found_search_matches'], $total_match_count);
		}

#
#-----[ FIND ]------------------------------------------------
#
			'L_LASTPOST' => $lang['Last_Post'], 

#
#-----[ AFTER, ADD ]------------------------------------------
#
			'L_SELECT' => $lang['Select'],

#
#-----[ FIND ]------------------------------------------------
#
		include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
	}
	else
	{
		message_die(GENERAL_MESSAGE, $lang['No_search_match']);
	}

#
#-----[ REPLACE WITH ]----------------------------------------
#
		include($phpbb_root_path . 'includes/page_tail.'.$phpEx);
	}
	else
	{
		if ( $show_results == 'bookmarks' )
		{
			message_die(GENERAL_MESSAGE, $lang['No_Bookmarks']);
		}
		else
		{
			message_die(GENERAL_MESSAGE, $lang['No_search_match']);
		}
	}

#
#-----[ OPEN ]------------------------------------------------
#
viewtopic.php

#
#-----[ FIND ]------------------------------------------------
#
include($phpbb_root_path . 'includes/bbcode.'.$phpEx);

#
#-----[ AFTER, ADD ]------------------------------------------
#
include($phpbb_root_path . 'includes/functions_bookmark.'.$phpEx);

#
#-----[ FIND ]------------------------------------------------
#
$userdata = session_pagestart($user_ip, $forum_id);
init_userprefs($userdata);
//
// End session management
//

#
#-----[ AFTER, ADD ]------------------------------------------
#

//
// Set or remove bookmark
//
if ( isset($HTTP_GET_VARS['setbm']) || isset($HTTP_GET_VARS['removebm']) )
{
	$redirect = "viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&start=$start&postdays=$post_days&postorder=$post_order&highlight=" . $HTTP_GET_VARS['highlight'];
	if ( $userdata['session_logged_in'] )
	{
		if (isset($HTTP_GET_VARS['setbm']) && $HTTP_GET_VARS['setbm'])
		{
			set_bookmark($topic_id);
		}
		else if (isset($HTTP_GET_VARS['removebm']) && $HTTP_GET_VARS['removebm'])
		{
			remove_bookmark($topic_id);
		}
	}
	else
	{
		if (isset($HTTP_GET_VARS['setbm']) && $HTTP_GET_VARS['setbm'])
		{
			$redirect .= '&setbm=true';
		}
		else if (isset($HTTP_GET_VARS['removebm']) && $HTTP_GET_VARS['removebm'])
		{
			$redirect .= '&removebm=true';
		}
		redirect(append_sid("login.$phpEx?redirect=$redirect", true));
	}
	redirect(append_sid($redirect, true));
}

#
#-----[ FIND ]------------------------------------------------
#
		$s_watching_topic = "<a href=\"viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;watch=topic&amp;start=$start&amp;sid=" . $userdata['session_id'] . '">' . $lang['Start_watching_topic'] . '</a>';
		$s_watching_topic_img = ( isset($images['Topic_watch']) ) ? "<a href=\"viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;watch=topic&amp;start=$start&amp;sid=" . $userdata['session_id'] . '"><img src="' . $images['Topic_watch'] . '" alt="' . $lang['Start_watching_topic'] . '" title="' . $lang['Start_watching_topic'] . '" border="0"></a>' : '';
	}
}

#
#-----[ AFTER, ADD ]------------------------------------------
#

//
// Bookmark information
//
if ( $userdata['session_logged_in'] )
{
	$template->assign_block_vars('bookmark_state', array());
	// Send vars to template
	$bm_action = (is_bookmark_set($topic_id)) ? ("&amp;removebm=true") : ("&amp;setbm=true");
	$template->assign_vars(array(
		'L_BOOKMARK_ACTION' => (is_bookmark_set($topic_id)) ? ($lang['Remove_Bookmark']) : ($lang['Set_Bookmark']),
		'U_BOOKMARK_ACTION' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=$topic_id&amp;start=$start&amp;postdays=$post_days&amp;postorder=$post_order&amp;highlight=" . $HTTP_GET_VARS['highlight'] . $bm_action))
	);
}

#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_board.php

#
#-----[ FIND ]------------------------------------------------
#
	"L_ALLOW_NAME_CHANGE" => $lang['Allow_name_change'],

#
#-----[ AFTER, ADD ]------------------------------------------
#
	"L_MAX_LINK_BOOKMARKS" => $lang['Max_bookmarks_links'],
	"L_MAX_LINK_BOOKMARKS_EXPLAIN" => $lang['Max_bookmarks_links_explain'],

#
#-----[ FIND ]------------------------------------------------
#
	"NAMECHANGE_NO" => $namechange_no,

#
#-----[ AFTER, ADD ]------------------------------------------
#
	"LINK_BOOKMARKS" => $new['max_link_bookmarks'], 

#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_db_utilities.php

#
#-----[ FIND ]------------------------------------------------
#
# use next line when using phpBB 2.0.11 or earlier
#			$tables = array('auth_access', 'banlist', 'categories', 'config', 'disallow', 'forums', 'forum_prune', 'groups', 'posts', 'posts_text', 'privmsgs', 'privmsgs_text', 'ranks', 'search_results', 'search_wordlist', 'search_wordmatch', 'sessions', 'smilies', 'themes', 'themes_name', 'topics', 'topics_watch', 'user_group', 'users', 'vote_desc', 'vote_results', 'vote_voters', 'words');
# use next line when using phpBB 2.0.18 or earlier
#			$tables = array('auth_access', 'banlist', 'categories', 'config', 'disallow', 'forums', 'forum_prune', 'groups', 'posts', 'posts_text', 'privmsgs', 'privmsgs_text', 'ranks', 'search_results', 'search_wordlist', 'search_wordmatch', 'sessions', 'smilies', 'themes', 'themes_name', 'topics', 'topics_watch', 'user_group', 'users', 'vote_desc', 'vote_results', 'vote_voters', 'words', 'confirm');
			$tables = array('auth_access', 'banlist', 'categories', 'config', 'disallow', 'forums', 'forum_prune', 'groups', 'posts', 'posts_text', 'privmsgs', 'privmsgs_text', 'ranks', 'search_results', 'search_wordlist', 'search_wordmatch', 'sessions', 'smilies', 'themes', 'themes_name', 'topics', 'topics_watch', 'user_group', 'users', 'vote_desc', 'vote_results', 'vote_voters', 'words', 'confirm', 'sessions_keys');

#
#-----[ IN-LINE FIND ]----------------------------------------
#
'banlist', 

#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
'bookmarks', 

#
#-----[ OPEN ]------------------------------------------------
#
admin/admin_users.php

#
#-----[ FIND ]------------------------------------------------
#
			$sql = "DELETE FROM " . BANLIST_TABLE . "
				WHERE ban_userid = $user_id";

#
#-----[ BEFORE, ADD ]-----------------------------------------
#
			$sql = "DELETE FROM " . BOOKMARK_TABLE . "
				WHERE user_id = $user_id";
			if ( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, 'Could not delete user\'s bookmarks', '', __LINE__, __FILE__, $sql);
			}


#
#-----[ FIND ]------------------------------------------------
#
		$attachsig = ( isset( $HTTP_POST_VARS['attachsig']) ) ? ( ( $HTTP_POST_VARS['attachsig'] ) ? TRUE : 0 ) : 0;

#
#-----[ AFTER, ADD ]------------------------------------------
#
		$setbm = ( isset( $HTTP_POST_VARS['setbm']) ) ? ( ( $HTTP_POST_VARS['setbm'] ) ? TRUE : 0 ) : 0;

#
#-----[ FIND ]------------------------------------------------
#
			$sql = "UPDATE " . USERS_TABLE . "
				SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) . "', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", $aim) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_sig_bbcode_uid = '$signature_bbcode_uid', user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowavatar = $user_allowavatar, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_allow_pm = $user_allowpm, user_notify_pm = $notifypm, user_popup_pm = $popuppm, user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_active = $user_status, user_rank = $user_rank" . $avatar_sql . "
				WHERE user_id = $user_id";

#
#-----[ IN-LINE FIND ]----------------------------------------
#
user_attachsig = $attachsig, 

#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
user_setbm = $setbm, 

#
#-----[ FIND ]------------------------------------------------
#
		$attachsig = $this_userdata['user_attachsig'];

#
#-----[ AFTER, ADD ]------------------------------------------
#
		$setbm = $this_userdata['user_setbm'];

#
#-----[ FIND ]------------------------------------------------
#
			$s_hidden_fields .= '<input type="hidden" name="attachsig" value="' . $attachsig . '" />';

#
#-----[ AFTER, ADD ]------------------------------------------
#
			$s_hidden_fields .= '<input type="hidden" name="setbm" value="' . $setbm . '" />';

#
#-----[ FIND ]------------------------------------------------
#
			'ALWAYS_ADD_SIGNATURE_NO' => (!$attachsig) ? 'checked="checked"' : '',

#
#-----[ AFTER, ADD ]------------------------------------------
#
			'ALWAYS_SET_BOOKMARK_YES' => ( $setbm ) ? 'checked="checked"' : '',
			'ALWAYS_SET_BOOKMARK_NO' => ( !$setbm ) ? 'checked="checked"' : '',

#
#-----[ FIND ]------------------------------------------------
#
			'L_ALWAYS_ADD_SIGNATURE' => $lang['Always_add_sig'],

#
#-----[ AFTER, ADD ]------------------------------------------
#
			'L_ALWAYS_SET_BOOKMARK' => $lang['Always_set_bm'],

#
#-----[ OPEN ]------------------------------------------------
#
includes/functions.php

#
#-----[ FIND ]------------------------------------------------
#
	global $nav_links;

#
#-----[ AFTER, ADD ]------------------------------------------
#
	global $db;

#
#-----[ FIND ]------------------------------------------------
#
	//
	// Set up style
	//
	if ( !$board_config['override_user_style'] )
	{
		if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 )
		{
			if ( $theme = setup_style($userdata['user_style']) )
			{
				return;
			}
		}
	}

	$theme = setup_style($board_config['default_style']);

	//
	// Mozilla navigation bar

#
#-----[ REPLACE WITH ]----------------------------------------
#
	//
	// Mozilla navigation bar

#
#-----[ FIND ]------------------------------------------------
#
	$nav_links['author'] = array ( 
		'url' => append_sid($phpbb_root_path . 'memberlist.' . $phpEx),
		'title' => $lang['Memberlist']
	);

#
#-----[ AFTER, ADD ]------------------------------------------
#
	//
	// Add bookmarks to Navigation bar
	//
	if ($userdata['session_logged_in'] && $board_config['max_link_bookmarks'] > 0)
	{
		$auth_sql = '';
		$is_auth_ary = auth(AUTH_READ, AUTH_LIST_ALL, $userdata); 

		$ignore_forum_sql = '';
		while( list($key, $value) = each($is_auth_ary) )
		{
			if ( !$value['auth_read'] )
			{
				$ignore_forum_sql .= ( ( $ignore_forum_sql != '' ) ? ', ' : '' ) . $key;
			}
		}

		if ( $ignore_forum_sql != '' )
		{
			$auth_sql .= ( $auth_sql != '' ) ? " AND f.forum_id NOT IN ($ignore_forum_sql) " : "f.forum_id NOT IN ($ignore_forum_sql) ";
		}
		if ( $auth_sql != '' )
		{
			$sql = "SELECT t.topic_id, t.topic_title, f.forum_id
				FROM " . TOPICS_TABLE . "  t, " . BOOKMARK_TABLE . " b, " . FORUMS_TABLE . " f, " . POSTS_TABLE . " p
				WHERE t.topic_id = b.topic_id
					AND t.forum_id = f.forum_id
					AND t.topic_last_post_id = p.post_id
					AND b.user_id = " . $userdata['user_id'] . "
					AND $auth_sql
				ORDER BY p.post_time DESC
				LIMIT " . (intval($board_config['max_link_bookmarks']) + 1);
		}
		else
		{
			$sql = "SELECT t.topic_id, t.topic_title
				FROM " . TOPICS_TABLE . " t, " . BOOKMARK_TABLE . " b, " . POSTS_TABLE . " p
				WHERE t.topic_id = b.topic_id
					AND t.topic_last_post_id = p.post_id
					AND b.user_id = " . $userdata['user_id'] . "
				ORDER BY p.post_time DESC
				LIMIT " . (intval($board_config['max_link_bookmarks']) + 1);
		}
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, 'Could not obtain post ids', '', __LINE__, __FILE__, $sql);
		}
		$post_rows = array();
		while ( $row = $db->sql_fetchrow($result) )
		{
			$post_rows[] = $row;
		}
		$db->sql_freeresult($result);

		if ( $total_posts = count($post_rows) )
		{
			//
			// Define censored word matches
			//
			$orig_word = array();
			$replacement_word = array();
			obtain_word_list($orig_word, $replacement_word);

			for($i = 0; $i < min($total_posts, $board_config['max_link_bookmarks']); $i++)
			{
				$topic_title = ( count($orig_word) ) ? preg_replace($orig_word, $replacement_word, $post_rows[$i]['topic_title']) : $post_rows[$i]['topic_title'];
				//
				// Add an array to $nav_links for the Mozilla navigation bar.
				// 'bookmarks' can create multiple items, therefore we are using a nested array.
				//
				$nav_links['bookmark'][$i] = array (
					'url' => append_sid("viewtopic.$phpEx?" . POST_TOPIC_URL . "=" . $post_rows[$i]['topic_id']),
					'title' => $topic_title
				);
			}
			if ($total_posts > $board_config['max_link_bookmarks'])
			{
				$start = intval($board_config['max_link_bookmarks'] / $board_config['topics_per_page']) * $board_config['topics_per_page'];
				$nav_links['bookmark'][$i] = array (
					'url' => append_sid("search.$phpEx?search_id=bookmarks&start=$start"),
					'title' => $lang['More_bookmarks']
				);
			}
		}
	}

	//
	// Set up style
	//
	if ( !$board_config['override_user_style'] )
	{
		if ( $userdata['user_id'] != ANONYMOUS && $userdata['user_style'] > 0 )
		{
			if ( $theme = setup_style($userdata['user_style']) )
			{
				return;
			}
		}
	}

	$theme = setup_style($board_config['default_style']);

#
#-----[ OPEN ]------------------------------------------------
#
includes/constants.php

#
#-----[ FIND ]------------------------------------------------
#
define('BANLIST_TABLE', $table_prefix.'banlist');

#
#-----[ AFTER, ADD ]------------------------------------------
#
define('BOOKMARK_TABLE', $table_prefix.'bookmarks');

#
#-----[ OPEN ]------------------------------------------------
#
includes/functions_post.php

#
#-----[ FIND ]------------------------------------------------
#
				$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . "
					WHERE topic_id = $topic_id";
				if ( !$db->sql_query($sql) )
				{
					message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
				}

#
#-----[ AFTER, ADD ]------------------------------------------
#

				$sql = "DELETE FROM " . BOOKMARK_TABLE . "
					WHERE topic_id = $topic_id";
				if ( !$db->sql_query($sql) )
				{
					message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql);
				}

#
#-----[ OPEN ]------------------------------------------------
#
includes/page_header.php

#
#-----[ FIND ]------------------------------------------------
#
	'L_SEARCH' => $lang['Search'],

#
#-----[ AFTER, ADD ]------------------------------------------
#
	'L_BOOKMARKS' => $lang['Bookmarks'],

#
#-----[ FIND ]------------------------------------------------
#
	'U_SEARCH' => append_sid('search.'.$phpEx),

#
#-----[ AFTER, ADD ]------------------------------------------
#
	'U_BOOKMARKS' => append_sid('search.'.$phpEx.'?search_id=bookmarks'),

#
#-----[ OPEN ]------------------------------------------------
#
includes/prune.php

#
#-----[ FIND ]------------------------------------------------
#
			$pruned_topics = $db->sql_affectedrows();

#
#-----[ AFTER, ADD ]------------------------------------------
#

			$sql = "DELETE FROM " . BOOKMARK_TABLE . " 
				WHERE topic_id IN ($sql_topics)";
			if ( !$db->sql_query($sql) )
			{
				message_die(GENERAL_ERROR, 'Could not delete bookmarks during prune', '', __LINE__, __FILE__, $sql);
			}

#
#-----[ OPEN ]------------------------------------------------
#
includes/usercp_avatar.php

#
#-----[ FIND ]------------------------------------------------
#
function display_avatar_gallery($mode, &$category, &$user_id, &$email, &$current_email, &$coppa, &$username, &$email, &$new_password, &$cur_password, &$password_confirm, &$icq, &$aim, &$msn, &$yim, &$website, &$location, &$occupation, &$interests, &$signature, &$viewemail, &$notifypm, &$popup_pm, &$notifyreply, &$attachsig, &$allowhtml, &$allowbbcode, &$allowsmilies, &$hideonline, &$style, &$language, &$timezone, &$dateformat, &$session_id)

#
#-----[ IN-LINE FIND ]----------------------------------------
#
&$attachsig, 

#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
&$setbm, 

#
#-----[ FIND ]------------------------------------------------
#
	$params = array('coppa', 'user_id', 'username', 'email', 'current_email', 'cur_password', 'new_password', 'password_confirm', 'icq', 'aim', 'msn', 'yim', 'website', 'location', 'occupation', 'interests', 'signature', 'viewemail', 'notifypm', 'popup_pm', 'notifyreply', 'attachsig', 'allowhtml', 'allowbbcode', 'allowsmilies', 'hideonline', 'style', 'language', 'timezone', 'dateformat');

#
#-----[ IN-LINE FIND ]----------------------------------------
#
'attachsig', 

#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
'setbm', 

#
#-----[ OPEN ]------------------------------------------------
#
includes/usercp_register.php

#
#-----[ FIND ]------------------------------------------------
#
	$popup_pm = ( isset($HTTP_POST_VARS['popup_pm']) ) ? ( ($HTTP_POST_VARS['popup_pm']) ? TRUE : 0 ) : TRUE;

#
#-----[ AFTER, ADD ]------------------------------------------
#
	$setbm = ( isset($HTTP_POST_VARS['setbm']) ) ? ( ($HTTP_POST_VARS['setbm']) ? TRUE : 0 ) : 0;

#
#-----[ FIND ]------------------------------------------------
#
			$sql = "UPDATE " . USERS_TABLE . "
				SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) ."', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_sig_bbcode_uid = '$signature_bbcode_uid', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_notify_pm = $notifypm, user_popup_pm = $popup_pm, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_active = $user_active, user_actkey = '" . str_replace("\'", "''", $user_actkey) . "'" . $avatar_sql . "
				WHERE user_id = $user_id";

#
#-----[ IN-LINE FIND ]----------------------------------------
#
user_attachsig = $attachsig, 

#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
user_setbm = $setbm, 

#
#-----[ FIND ]------------------------------------------------
#
			$sql = "INSERT INTO " . USERS_TABLE . "	(user_id, username, user_regdate, user_password, user_email, user_icq, user_website, user_occ, user_from, user_interests, user_sig, user_sig_bbcode_uid, user_avatar, user_avatar_type, user_viewemail, user_aim, user_yim, user_msnm, user_attachsig, user_allowsmile, user_allowhtml, user_allowbbcode, user_allow_viewonline, user_notify, user_notify_pm, user_popup_pm, user_timezone, user_dateformat, user_lang, user_style, user_level, user_allow_pm, user_active, user_actkey)
				VALUES ($user_id, '" . str_replace("\'", "''", $username) . "', " . time() . ", '" . str_replace("\'", "''", $new_password) . "', '" . str_replace("\'", "''", $email) . "', '" . str_replace("\'", "''", $icq) . "', '" . str_replace("\'", "''", $website) . "', '" . str_replace("\'", "''", $occupation) . "', '" . str_replace("\'", "''", $location) . "', '" . str_replace("\'", "''", $interests) . "', '" . str_replace("\'", "''", $signature) . "', '$signature_bbcode_uid', $avatar_sql, $viewemail, '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', '" . str_replace("\'", "''", $yim) . "', '" . str_replace("\'", "''", $msn) . "', $attachsig, $allowsmilies, $allowhtml, $allowbbcode, $allowviewonline, $notifyreply, $notifypm, $popup_pm, $user_timezone, '" . str_replace("\'", "''", $user_dateformat) . "', '" . str_replace("\'", "''", $user_lang) . "', $user_style, 0, 1, ";

#
#-----[ IN-LINE FIND ]----------------------------------------
#
user_attachsig, 

#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
user_setbm, 

#
#-----[ IN-LINE FIND ]----------------------------------------
#
$attachsig, 

#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
$setbm, 

#
#-----[ FIND ]------------------------------------------------
#
	$attachsig = $userdata['user_attachsig'];

#
#-----[ AFTER, ADD ]------------------------------------------
#
	$setbm = $userdata['user_setbm'];

#
#-----[ FIND ]------------------------------------------------
#
	display_avatar_gallery($mode, $avatar_category, $user_id, $email, $current_email, $coppa, $username, $email, $new_password, $cur_password, $password_confirm, $icq, $aim, $msn, $yim, $website, $location, $occupation, $interests, $signature, $viewemail, $notifypm, $popup_pm, $notifyreply, $attachsig, $allowhtml, $allowbbcode, $allowsmilies, $allowviewonline, $user_style, $user_lang, $user_timezone, $user_dateformat, $userdata['session_id']);

#
#-----[ IN-LINE FIND ]----------------------------------------
#
$attachsig, 

#
#-----[ IN-LINE AFTER, ADD ]----------------------------------
#
$setbm, 

#
#-----[ FIND ]------------------------------------------------
#
		'ALWAYS_ADD_SIGNATURE_NO' => ( !$attachsig ) ? 'checked="checked"' : '',

#
#-----[ AFTER, ADD ]------------------------------------------
#
		'ALWAYS_SET_BOOKMARK_YES' => ( $setbm ) ? 'checked="checked"' : '',
		'ALWAYS_SET_BOOKMARK_NO' => ( !$setbm ) ? 'checked="checked"' : '',

#
#-----[ FIND ]------------------------------------------------
#
		'L_ALWAYS_ADD_SIGNATURE' => $lang['Always_add_sig'],

#
#-----[ AFTER, ADD ]------------------------------------------
#
		'L_ALWAYS_SET_BOOKMARK' => $lang['Always_set_bm'],

#
#-----[ OPEN ]------------------------------------------------
#
language/lang_english/lang_admin.php

#
#-----[ FIND ]------------------------------------------------
#
//
// That's all Folks!

#
#-----[ BEFORE, ADD ]------------------------------------------
#
//
// Bookmark Mod
//
$lang['Max_bookmarks_links'] = 'Maximum bookmarks send in link-tag';
$lang['Max_bookmarks_links_explain'] = 'Number of bookmarks maximal send in link-tag at the beginning of the document. This information is e.g. used by Mozilla. Enter 0 to disable this function.';


#
#-----[ OPEN ]------------------------------------------------
#
language/lang_english/lang_main.php

#
#-----[ FIND ]------------------------------------------------
#
//
// That's all, Folks!

#
#-----[ BEFORE, ADD ]------------------------------------------
#
//
// Bookmark Mod
//
$lang['Bookmarks'] = 'Bookmarks';
$lang['Set_Bookmark'] = 'Set a bookmark for this topic';
$lang['Remove_Bookmark'] = 'Remove the bookmark for this topic';
$lang['No_Bookmarks'] = 'You do not have set a bookmark';
$lang['Always_set_bm'] = 'Set bookmark automatically when posting';
$lang['Found_bookmark'] = 'You have set %d bookmark.'; // eg. Search found 1 match
$lang['Found_bookmarks'] = 'You have set %d bookmarks.'; // eg. Search found 24 matches
$lang['More_bookmarks'] = 'More bookmarks...'; // For mozilla navigation bar


#
#-----[ OPEN ]------------------------------------------------
#
# For Information only
# language/lang_german/lang_admin.php

#
#-----[ FIND ]------------------------------------------------
#
# // That's all Folks!

#
#-----[ BEFORE, ADD ]------------------------------------------
#
# //
# // Bookmark Mod
# //
# $lang['Max_bookmarks_links'] = 'Maximale Lesezeichen im link-Tag';
# $lang['Max_bookmarks_links_explain'] = 'Maximale Zahl von Lesezeichen, die zu Beginn des Dokumentes im link-Tag gesendet werden. Dies wird z.B. von Mozilla ausgewertet. Bei Eingabe von 0 werden keine Tags gesendet.';
#

#
#-----[ OPEN ]------------------------------------------------
#
# For Information only
# language/lang_german/lang_main.php

#
#-----[ FIND ]------------------------------------------------
#
# //
# // That's all, Folks!

#
#-----[ BEFORE, ADD ]------------------------------------------
#
# //
# // Bookmark Mod
# //
# $lang['Bookmarks'] = 'Lesezeichen';
# $lang['Set_Bookmark'] = 'Lesezeichen fr diesen Beitrag setzen';
# $lang['Remove_Bookmark'] = 'Lesezeichen fr diesen Beitrag enfernen';
# $lang['No_Bookmarks'] = 'Du hast keine Lesezeichen gesetzt';
# $lang['Always_set_bm'] = 'Lesezeichen automatisch bei Erstellung eines Beitrages setzen';
# $lang['Found_bookmark'] = 'Du hast %d Lesezeichen gesetzt.'; // eg. Search found 1 match
# $lang['Found_bookmarks'] = 'Du hast %d Lesezeichen gesetzt.'; // eg. Search found 24 matches
# $lang['More_bookmarks'] = 'Mehr Lesezeichen...'; // For mozilla navigation bar
#

#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/overall_header.tpl

#
#-----[ FIND ]------------------------------------------------
#
						<td align="center" valign="top" nowrap="nowrap"><span class="mainmenu">&nbsp;<a href="{U_FAQ}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_faq.gif" width="12" height="13" border="0" alt="{L_FAQ}" hspace="3" />{L_FAQ}</a>&nbsp; &nbsp;<a href="{U_SEARCH}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_search.gif" width="12" height="13" border="0" alt="{L_SEARCH}" hspace="3" />{L_SEARCH}</a>&nbsp; &nbsp;<a href="{U_MEMBERLIST}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_members.gif" width="12" height="13" border="0" alt="{L_MEMBERLIST}" hspace="3" />{L_MEMBERLIST}</a>&nbsp; &nbsp;<a href="{U_GROUP_CP}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_groups.gif" width="12" height="13" border="0" alt="{L_USERGROUPS}" hspace="3" />{L_USERGROUPS}</a>&nbsp; 

#
#-----[ REPLACE WITH ]----------------------------------------
#
						<td align="center" valign="top" nowrap="nowrap"><span class="mainmenu">&nbsp;<a href="{U_FAQ}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_faq.gif" width="12" height="13" border="0" alt="{L_FAQ}" hspace="3" />{L_FAQ}</a></span><span class="mainmenu">&nbsp; &nbsp;<a href="{U_SEARCH}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_search.gif" width="12" height="13" border="0" alt="{L_SEARCH}" hspace="3" />{L_SEARCH}</a>&nbsp;
						<!-- BEGIN switch_user_logged_in -->
						&nbsp;<a href="{U_BOOKMARKS}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_bookmark.gif" width="12" height="13" border="0" alt="{L_BOOKMARKS}" hspace="3" />{L_BOOKMARKS}</a>&nbsp;
						<!-- END switch_user_logged_in -->
						&nbsp;<a href="{U_MEMBERLIST}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_members.gif" width="12" height="13" border="0" alt="{L_MEMBERLIST}" hspace="3" />{L_MEMBERLIST}</a>&nbsp; &nbsp;<a href="{U_GROUP_CP}" class="mainmenu"><img src="templates/subSilver/images/icon_mini_groups.gif" width="12" height="13" border="0" alt="{L_USERGROUPS}" hspace="3" />{L_USERGROUPS}</a>&nbsp; 

#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/posting_body.tpl

#
#-----[ FIND ]------------------------------------------------
#
		  <!-- END switch_signature_checkbox -->

#
#-----[ AFTER, ADD ]------------------------------------------
#
		  <!-- BEGIN switch_bookmark_checkbox -->
		  <tr> 
			<td> 
			  <input type="checkbox" name="setbm" {S_SETBM_CHECKED} />
			</td>
			<td><span class="gen">{L_SET_BOOKMARK}</span></td>
		  </tr>
		  <!-- END switch_bookmark_checkbox -->

#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/profile_add_body.tpl

#
#-----[ FIND ]------------------------------------------------
#
	<tr> 
	  <td class="row1"><span class="gen">{L_ALWAYS_ADD_SIGNATURE}:</span></td>
	  <td class="row2"> 
		<input type="radio" name="attachsig" value="1" {ALWAYS_ADD_SIGNATURE_YES} />
		<span class="gen">{L_YES}</span>&nbsp;&nbsp; 
		<input type="radio" name="attachsig" value="0" {ALWAYS_ADD_SIGNATURE_NO} />
		<span class="gen">{L_NO}</span></td>
	</tr>

#
#-----[ AFTER, ADD ]------------------------------------------
#
	<tr> 
	  <td class="row1"><span class="gen">{L_ALWAYS_SET_BOOKMARK}:</span></td>
	  <td class="row2"> 
		<input type="radio" name="setbm" value="1" {ALWAYS_SET_BOOKMARK_YES} />
		<span class="gen">{L_YES}</span>&nbsp;&nbsp; 
		<input type="radio" name="setbm" value="0" {ALWAYS_SET_BOOKMARK_NO} />
		<span class="gen">{L_NO}</span></td>
	</tr>

#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/viewtopic_body.tpl

#
#-----[ FIND ]------------------------------------------------
#
	<tr align="right">
		<td class="catHead" colspan="2" height="28"><span class="nav"><a href="{U_VIEW_OLDER_TOPIC}" class="nav">{L_VIEW_PREVIOUS_TOPIC}</a> :: <a href="{U_VIEW_NEWER_TOPIC}" class="nav">{L_VIEW_NEXT_TOPIC}</a> &nbsp;</span></td>
	</tr>

#
#-----[ AFTER, ADD ]------------------------------------------
#
	<!-- BEGIN bookmark_state -->
	<tr align="left">
		<td class="row2" colspan="2" height="20"><span class="genmed"><a href="{U_BOOKMARK_ACTION}" class="genmed">{L_BOOKMARK_ACTION}</a></span></td>
	</tr>
	<!-- END bookmark_state -->

#
#-----[ FIND ]------------------------------------------------
#
	<!-- END postrow -->

#
#-----[ AFTER, ADD ]------------------------------------------
#
	<!-- BEGIN bookmark_state -->
	<tr align="left">
		<td class="row2" colspan="2" height="20"><span class="genmed"><a href="{U_BOOKMARK_ACTION}" class="genmed">{L_BOOKMARK_ACTION}</a></span></td>
	</tr>
	<!-- END bookmark_state -->

#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/admin/board_config_body.tpl

#
#-----[ FIND ]------------------------------------------------
#
	<tr>
		<td class="row1">{L_ALLOW_NAME_CHANGE}</td>
		<td class="row2"><input type="radio" name="allow_namechange" value="1" {NAMECHANGE_YES} /> {L_YES}&nbsp;&nbsp;<input type="radio" name="allow_namechange" value="0" {NAMECHANGE_NO} /> {L_NO}</td>
	</tr>

#
#-----[ AFTER, ADD ]------------------------------------------
#
	<tr>
		<td class="row1">{L_MAX_LINK_BOOKMARKS}<br /><span class="gensmall">{L_MAX_LINK_BOOKMARKS_EXPLAIN}</span></td>
		<td class="row2"><input class="post" type="text" size="4" maxlength="3" name="max_link_bookmarks" value="{LINK_BOOKMARKS}" /></td>
	</tr>

#
#-----[ OPEN ]------------------------------------------------
#
templates/subSilver/admin/user_edit_body.tpl

#
#-----[ FIND ]------------------------------------------------
#
	<tr> 
	  <td class="row1"><span class="gen">{L_ALWAYS_ADD_SIGNATURE}</span></td>
	  <td class="row2"> 
		<input type="radio" name="attachsig" value="1" {ALWAYS_ADD_SIGNATURE_YES} />
		<span class="gen">{L_YES}</span>&nbsp;&nbsp; 
		<input type="radio" name="attachsig" value="0" {ALWAYS_ADD_SIGNATURE_NO} />
		<span class="gen">{L_NO}</span></td>
	</tr>

#
#-----[ AFTER, ADD ]------------------------------------------
#
	<tr> 
	  <td class="row1"><span class="gen">{L_ALWAYS_SET_BOOKMARK}</span></td>
	  <td class="row2"> 
		<input type="radio" name="setbm" value="1" {ALWAYS_SET_BOOKMARK_YES} />
		<span class="gen">{L_YES}</span>&nbsp;&nbsp; 
		<input type="radio" name="setbm" value="0" {ALWAYS_SET_BOOKMARK_NO} />
		<span class="gen">{L_NO}</span></td>
	</tr>

#
#-----[ SAVE/CLOSE ALL FILES ]--------------------------------
#
# EoM