##########################################################################################
## MOD Title: Tag System Mod
## MOD Author: Centurion ( http://centurion.sadistic.pl )
##                                            
## MOD Description: This mod allows you to tag topics on your forum for better indexing in 
##		    google search engine. It cooperates with Spider Friendly mod!
##                   
## MOD Version: 1.0.1                                   
##                                           
## Installation Level: Intermediate                           
## Installation Time: 20 minutes
##                                            
## Included files: 7
##	      - tags.php
##	      - includes/functions_tags.php
##	      - language/lang_polish/lang_tags.php
##	      - language/lang_english/lang_tags.php
##	      - templates/xxx/tags_body.tpl
##	      - templates/xxx/admin/admin_tags_body.tpl
##	      - templates/xxx/portal_modules/tags_menu.tpl
##
## Files to Edit: 17                                  
##            - common.php                           
##            - index.php                           
##            - portal.php                           
##            - posting.php                           
##            - viewtopic.php                           
##            - admin/modules_data.php                           
##            - admin/admin_portal.php                           
##            - includes/constants.php                           
##            - includes/functions_post.php                           
##            - includes/functions_remove.php                           
##            - languages/lang_polish/lang_admin.php                           
##            - languages/lang_polish/lang_main.php                           
##            - languages/lang_english/lang_admin.php                           
##            - languages/lang_english/lang_main.php                           
##            - templates/xxx/index_body.tpl                   
##            - templates/xxx/posting_body.tpl                   
##            - templates/xxx/viewtopic_body.tpl                   
##                                           
##########################################################################################
##                                           
## License: http://www.gnu.org/licenses/gpl.html (GPL 2)                   
##                                           
########################################################################################## 
#
#---[ SQL ]---
#
ALTER TABLE phpbb_topics ADD topic_tag VARCHAR(255) NOT NULL DEFAULT '';

INSERT INTO phpbb_config VALUES ('tags_per_page', '20');
INSERT INTO phpbb_config VALUES ('tags_auth', '1');
INSERT INTO phpbb_config VALUES ('tags_default_show', '20');
INSERT INTO phpbb_config VALUES ('tags_default_method', 'r');
INSERT INTO phpbb_config VALUES ('tags_min_lenght', '3');
INSERT INTO phpbb_config VALUES ('tags_max_lenght', '30');
INSERT INTO phpbb_config VALUES ('tags_separator', ' ');
INSERT INTO phpbb_config VALUES ('tags_resizer', '1');
INSERT INTO phpbb_config VALUES ('tags_max_size', '20');


CREATE TABLE `phpbb_tags` (
  `tag_id` int(10) NOT NULL auto_increment,
  `tag_name` varchar(80) NOT NULL default '',
  `tag_occur` smallint(3) NOT NULL default '0',
  PRIMARY KEY  (`tag_id`)
);

CREATE TABLE `phpbb_tag_match` (
  `tagm_id` bigint(15) NOT NULL auto_increment,
  `tagm_topic_id` int(10) NOT NULL default '0',
  `tagm_tag_id` int(10) NOT NULL default '0',
  PRIMARY KEY  (`tagm_id`),
  KEY `tagm_tag_id` (`tagm_tag_id`)
);

#
#---[ OPEN ]---
#
common.php
#
#
#---[ FIND ]---
#
$db->sql_freeresult($result);
#
#---[ BEFORE ADD ]---
#
require($phpbb_root_path . 'includes/functions_tags.'.$phpEx);
#
#---[ OPEN ]---
#
admin/modules_data.php
#
#---[ FIND ]---
#
		'Advert_title' => array("admin_advert.$phpEx", 11),
#
#---[ AFTER ADD ]---
#
		'Tags' => array("admin_tags.$phpEx", 777),
#
#---[ OPEN ]---
#
admin/admin_portal.php
#
#---[ FIND ]---
#
'blank_module2', 'blank_module3', 'blank_module4',
#
#---[ AFTER ADD ]---
#
'tags',
#
#---[ FIND ]---
#
$lang['custom_blank_mod'] . ' 3', $lang['custom_blank_mod'] . ' 4',
#
#---[ AFTER ADD ]---
#
$lang['tags'],
#
#---[ OPEN ]---
#
index.php
#
#---[ FIND ]---
#
	'U_VIEWONLINE' => append_sid('viewonline.'.$phpEx),
#
#---[ AFTER ADD ]---
#
'L_TAGS' => $lang['Tags'],
'TAG_CLOUD' => tag_cloud(),
#
#---[ OPEN ]---
#
portal.php
#
#---[ FIND ]---
#
if ( in_array('register_menu', $modules) && !$userdata['session_logged_in'])
#
#---[ BEFORE ADD ]---
#
if ( in_array('tags', $modules) )
{
	$template->assign_vars(array(
		'L_TAGS' => $lang['Tags'],
		'TAG_CLOUD' => tag_cloud())
	);
	$template->set_filenames(array(
		'tags_menu' => 'portal_modules/tags_menu.tpl')
	);
	$template->assign_var_from_handle($module_names['tags'], 'tags_menu');
}
#
#---[ OPEN ]---
#
posting.php
#
#---[ FIND ]---
#
$select_sql = ( !$submit ) ? ", t.topic_title, t.topic_title_e,
#
#---[ AFTER ADD ]---
#
t.topic_tag, 
#
#---[ FIND ]---
#
		$subject_e = ( !empty($HTTP_POST_VARS['subject_e']) ) ? trim($HTTP_POST_VARS['subject_e']) : '';
#
#---[ AFTER ADD ]---
#
		$topic_tags = ( !empty($HTTP_POST_VARS['topic_tags']) ) ? trim($HTTP_POST_VARS['topic_tags']) : '';
#
#---[ FIND ]---
#
		    prepare_post($mode, $post_data, $bbcode_on, $html_on, $smilies_on, $error_msg, $username, $bbcode_uid, $subject, $subject_e,
#
#---[ AFTER ADD ]---
#
$topic_tags, 
#
#---[ FIND ]---
#
			$str_replace_subject_e = str_replace("\'", "''", $subject_e);
#
#---[ AFTER ADD ]---
#
			$str_replace_topic_tags = str_replace("\'", "''", $topic_tags);
#
#---[ FIND ]---
#
$is_mod_forum, $is_jr_admin
#
#---[ AFTER ADD ]---
#
, $str_replace_topic_tags
#
#---[ FIND ]---
#
		$subject_e = (!empty($HTTP_POST_VARS['subject_e'])) ? trim($HTTP_POST_VARS['subject_e']) : '';
#
#---[ AFTER ADD ]---
#
		$topic_tags = (!empty($HTTP_POST_VARS['topic_tags'])) ? trim($HTTP_POST_VARS['topic_tags']) : '';
#
#---[ FIND ]---
#
		prepare_post($mode, $post_data, $bbcode_on, $html_on, $smilies_on, $error_msg, $username, $bbcode_uid, $subject, $subject_e,
#
#---[ AFTER ADD ]---
#
$topic_tags, 
#
#---[ FIND ]---
#
			$str_replace_subject_e = str_replace("\'", "''", $subject_e);
#
#---[ AFTER ADD ]---
#
			$str_replace_topic_tags = str_replace("\'", "''", $topic_tags);
#
#---[ FIND ]---
#
$is_mod_forum, $is_jr_admin
#
#---[ AFTER ADD ]---
#
, $str_replace_topic_tags
#
#---[ FIND ]---
#
	$subject_e = ( !empty($HTTP_POST_VARS['subject_e']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['subject_e']))) : '';
#
#---[ AFTER ADD ]---
#
	$topic_tags = ( !empty($HTTP_POST_VARS['topic_tags']) ) ? htmlspecialchars(trim(stripslashes($HTTP_POST_VARS['topic_tags']))) : '';
#
#---[ FIND ]---
#
		$preview_subject_e = $subject_e;
#
#---[ AFTER ADD ]---
#
		$preview_topic_tags = $topic_tags;
#
#---[ FIND ]---
#
		$subject_e = '';
#
#---[ AFTER ADD ]---
#
		$topic_tags = '';
#
#---[ FIND ]---
#
		$subject_e = '';
#
#---[ AFTER ADD ]---
#
		$topic_tags = '';
#
#---[ FIND ]---
#
		$subject_e = ($post_data['first_post']) ? $post_info['topic_title_e'] : '';
#
#---[ AFTER ADD ]---
#
		$topic_tags = ($post_data['first_post']) ? $post_info['topic_tag'] : '';
#
#---[ FIND ]---
#
	'L_FONT_COLOR' => $lang['Font_color'],
#
#---[ AFTER ADD ]---
#
	'L_TAGS' => $lang['Tags'],
	'L_TAGS_EXPLAIN' => $lang['Tags_explain'],
	'TOPIC_TAGS' => $topic_tags,

#
#---[ FIND ]---
#
	$template->assign_block_vars('topic_explain', array());
}
#
#---[ AFTER ADD ]---
#
if ( $mode != 'reply' && $mode != 'quote' && $post_data['first_post'] && !$comment )
{
//checking tag permisions
	$tag_allowed = false;
	
	if($userdata['user_level'] == ADMIN || $board_config['tags_auth'] == 0)
	$tag_allowed = true;
	else if($board_config['tags_auth'] == 1 && ($is_auth['auth_mod'] || $userdata['user_jr']))
	$tag_allowed = true;
	else if($board_config['tags_auth'] == 2 && $userdata['user_jr'])
	$tag_allowed = true;
	else
	$tag_allowed = false;
	
	if($tag_allowed)
	$template->assign_block_vars('topic_tag', array());
}
#
#---[ OPEN ]---
#
viewtopic.php
#
#---[ FIND ]---
#
$topic_title = $forum_topic_data['topic_title'];
#
#---[ AFTER ADD ]---
#
$topic_tags = get_topic_tags($topic_id);
#
#---[ FIND ]---
#
//
// Does this topic contain a poll?
#
#---[ BEFORE ADD ]---
#
if($topic_tags)
{
$template->assign_block_vars('topic_tag', array(
'TOPIC_TAGS' => $topic_tags
));
}
#
#---[ OPEN ]---
#
includes/constants.php
#
#---[ FIND ]---
#
?>
#
#---[ BEFORE ADD ]---
#
define('TAGS_TABLE', $table_prefix . 'tags');
define('TAG_MATCH_TABLE', $table_prefix . 'tag_match');
#
#---[ OPEN ]---
#
includes/function_post.php
#
#---[ FIND ]---
#
function prepare_post(&$mode, &$post_data, &$bbcode_on, &$html_on, &$smilies_on, &$error_msg, &$username, &$bbcode_uid, &$subject, &$subject_e,
#
#---[ AFTER ADD ]---
#
&$topic_tags,
#
#---[ FIND ]---
#
&$is_mod, &$is_jr_admin
#
#---[ AFTER ADD ]---
#
, &$topic_tags
#
#---[ FIND ]---
#
			$topic_id = $db->sql_nextid();
		}
#
#---[ AFTER ADD ]---
#
//checking tag permisions
	$tag_allowed = false;
	
	if($userdata['user_level'] == ADMIN || $board_config['tags_auth'] == 0)
	$tag_allowed = true;
	else if($board_config['tags_auth'] == 1 && ($is_mod || $is_jr_admin))
	$tag_allowed = true;
	else if($board_config['tags_auth'] == 2 && $is_jr_admin)
	$tag_allowed = true;
	else
	$tag_allowed = false;

	if($tag_allowed)
	update_topic_tags($topic_id, $topic_tags);

#                                                                                                                                                            
#---[ OPEN ]---                                                                                                                                              
# 
includes/functions_remove.php
#                                                                                                                                                            
#---[ FIND ]---                                                                                                                                              
#
// Got all required info so go ahead and start deleting everything
#
#---[ BEFORE ADD ]---
#
	    $removed_topics = @explode(",", $topics_id);
	    for($j = 0; $j < count($removed_topics); $j++)
	    {
	    $blank_tag = '';
	    update_topic_tags($removed_topics[$j], $blank_tag);
	    }
#
#---[ OPEN ]---
#
language/lang_polish/lang_admin.php
#
#---[ FIND ]---
#
?>
#
#---[ BEFORE ADD ]---
#
$lang['Tags'] = 'Tagi';
#
#---[ OPEN ]---
#
language/lang_polish/lang_main.php
#
#---[ FIND ]---
#
?>
#
#---[ BEFORE ADD ]---
#
$lang['Tags'] = 'Tagi';
$lang['Tags_explain'] = 'Tagi tematu rozdzielone przecinkami';
#
#---[ OPEN ]---
#
language/lang_english/lang_admin.php
#
#---[ FIND ]---
#
?>
#
#---[ BEFORE ADD ]---
#
$lang['Tags'] = 'Tags';
#
#---[ OPEN ]---
#
language/lang_english/lang_main.php
#
#---[ FIND ]---
#
?>
#
#---[ BEFORE ADD ]---
#
$lang['Tags'] = 'Tags';
$lang['Tags_explain'] = 'Topic tags separated by comma';
#
#---[ OPEN ]---
#
templates/subSilver/index_body.tpl
#
#---[ FIND ]---
#
	{SHOUTBOX_DISPLAY}
#
#---[ BEFORE ADD ]---
#
   <br clear="all" />
   <table cellspacing="3" border="0" align="center" cellpadding="0" width="100%">
    <tr><td><fieldset><legend>{L_TAGS}</legend>{TAG_CLOUD}</fieldset></td></tr>
    </table>
#
#---[ OPEN ]---
#
templates/subSilver/posting_body.tpl
#
#---[ FIND ]---
#
	<!-- END topic_explain -->
#
#---[ AFTER ADD ]---
#
	<!-- BEGIN topic_tag -->
	<tr>
		<td class="row1" width="22%"><span class="gen"><b>{L_TAGS}</b></span> <span class="gensmall">({L_TAGS_EXPLAIN})</span></td>
		<td class="row2" width="78%"><span class="gen"><input type="text" name="topic_tags" size="45" maxlength="255" style="width:550px;height:17px;font-size:9px;" tabindex="2" class="post" onFocus="Active(this)" onBlur="NotActive(this)" value="{TOPIC_TAGS}" /></span></td>
	</tr>
	<!-- END topic_tag -->
#
#---[ OPEN ]---
#
templates/subSilver/viewtopic_body.tpl
#
#---[ FIND ]---
#
   <!-- END postrow -->
#
#---[ AFTER ADD ]---
#
<!-- BEGIN topic_tag -->
<tr><td align="left" colspan="2" class="row3"><span class="nav">{topic_tag.TOPIC_TAGS}</span></td></tr>
<!-- END topic_tag -->

### EOF ###
