###################################################################
#                                                                 #
#     Pobrane ze strony http://www.przemo.org/phpBB2/             #
#                                                                 #
###################################################################
##
## MOD Title:           Spider Friendly for phpBB 2.0.x
## MOD Author:          Crack < piotrprz@gmail.com > (n/a) n/a
## MOD Version:         1.2
##
## Installation Level:  Intermediate
## Installation Time:   30 Minutes
## Files To Edit:       13
##                      includes/constants.php
##                      includes/functions.php
##                      includes/functions_post.php
##                      includes/sessions.php
##                      includes/page_header.php
##                      includes/page_tail.php
##                      language/lang_english/lang_admin.php
##                      language/lang_polish/lang_admin.php
##                      templates/subSilver/overall_footer.tpl
##                      common.php
##                      index.php
##                      viewforum.php
##                      viewtopic.php
## Included Files:      17
##                      admin/admin_spider_friendly.php
##                      includes/bots.txt
##                      includes/map.iso-8859-1.php
##                      includes/map.iso-8859-2.php
##                      includes/map.utf-8.php
##                      includes/rewrite_config.php
##                      includes/spider_friendly.php
##                      includes/spider_log.php
##                      includes/tanuki_ad.php
##                      language/lang_english/lang_admin_sf.php
##                      language/lang_polish/lang_admin_sf.php
##                      templates/subSilver/admin/sf_config.tpl
##                      templates/subSilver/admin/sf_spider_log.tpl
##                      templates/subSilver/sitemap.tpl
##                      .htaccess
##                      robots.txt
##                      sitemap.php
##############################################################
## Author Notes
##
## Wymaga zainstalowanego moda Search META tags (misc/search_meta_tags.txt)
##
## Serwer musi mie prawa zapisu dla katalogu cache, ustaw odpowiednie prawa
## (chmod 775 lub 777).
##############################################################
## Before Adding This MOD To Your Forum, You Should Back Up All Files Related To This MOD
##############################################################
#
#-----[ COPY ]------------------------------------------
#
copy  root/admin/*                    to admin/
copy  root/includes/*                 to includes/
copy  root/language/lang_english/*    to language/lang_english/
copy  root/language/lang_polish/*     to language/lang_polish/
copy  root/templates/subSilver/*      to templates/subSilver/
copy  root/.htaccess                  to .htaccess
copy  root/robots.txt                 to robots.txt
copy  root/sitemap.php                to sitemap.php

#
#-----[ SQL ]------------------------------------------
#
INSERT INTO phpbb_config (config_name, config_value)
VALUES('sf_mod_rewrite_enabled', 1),
	('sf_spiders_only', 0),
	('sf_rewrite_all_htm', 1),
	('sf_rewrite_index', 1),
	('sf_rewrite_mode', 1),
	('sf_charset_mapping', 'auto'),
	('sf_fake_dirs', 1),
	('sf_postlink_rewrite', 1),
	('sf_max_keywords_length', 768),
	('sf_sitemap_enabled', 1),
	('sf_show_lastpost_link', 0),
	('sf_map_spiders_only', 1),
	('sf_map_index_only', 1),
	('sf_topics_per_page', 30),
	('sf_log_spiders', 1),
	('sf_spider_session_length', 3600),
	('sf_cache_refresh_mode', '10min'),
	('sf_cache_read_mode', 'memory');
CREATE TABLE phpbb_spider_log (
  log_id mediumint(9) NOT NULL auto_increment,
  spider_name varchar(255) NOT NULL default '',
  spider_firstvisit int(11) NOT NULL default '0',
  spider_lastvisit int(11) NOT NULL default '0',
  spider_hits mediumint(9) NOT NULL default '0',
  PRIMARY KEY (log_id),
  KEY spider_lastvisit (spider_lastvisit)
);

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

#
#-----[ FIND ]------------------------------------------
#
define('CONFIG_TABLE', $table_prefix.'config');

#
#-----[ AFTER, ADD ]------------------------------------------
#
define('SPIDER_LOG_TABLE', $table_prefix . 'spider_log');

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

#
#-----[ FIND ]------------------------------------------
#

	// Behave as per HTTP/1.1 spec for others

#
#-----[ AFTER, ADD ]------------------------------------------
#
	if( MRW_RELPATH && strpos($url, MRW_RELPATH) <= 1 )
	{
		$url = substr($url, strlen(MRW_RELPATH));
	}

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

#
#-----[ FIND ]------------------------------------------
#
	global $board_config, $lang, $db, $phpbb_root_path, $phpEx;

#
#-----[ IN-LINE FIND ]------------------------------------------
#
$board_config

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

#
#-----[ FIND ]------------------------------------------
#
	add_search_words('single', $post_id, stripslashes($post_message), stripslashes($post_subject));

#
#-----[ AFTER, ADD ]------------------------------------------
#
	// Spider Fiendly Post > Topic cache
	if( $sfc['postlink_rewrite'] && $sfc['cache_refresh_mode'] == 'post' && $mode != 'editpost' )
	{
		build_post_topic_cache('post', $topic_id);
	}

#
#-----[ FIND ]------------------------------------------
#
function delete_post($mode, 

#
#-----[ FIND ]------------------------------------------
#
	global $board_config, $lang, $db, $phpbb_root_path, $phpEx;

#
#-----[ IN-LINE FIND ]------------------------------------------
#
$board_config

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

#
#-----[ FIND ]------------------------------------------
#
		remove_search_post($post_id);

#
#-----[ AFTER, ADD ]------------------------------------------
#
		// Spider Fiendly Post > Topic cache
		if( $sfc['postlink_rewrite'] && $sfc['cache_refresh_mode'] == 'post' )
		{
			build_post_topic_cache('post', $topic_id);
		}

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

#
#-----[ FIND ]------------------------------------------
#
	if ( isset($HTTP_COOKIE_VARS[$cookiename . '_sid']) || isset($HTTP_COOKIE_VARS[$cookiename . '_data']) )

#
#-----[ BEFORE, ADD ]------------------------------------------
#
	if ( user_is_spider() && !defined('MRW_SPIDER_FORCED') )
	{
		// Gives the spider only one session
		$session_id = md5(get_spider_name());
		$sessiondata = array();
		$sessionmethod = SESSION_METHOD_GET;
	}

#
#-----[ IN-LINE FIND ]------------------------------------------
# dotyczy linii z ostatniego FIND
#
if

#
#-----[ IN-LINE BEFORE, ADD ]------------------------------------------
#
else

#
#-----[ FIND ]------------------------------------------
#
	if ( isset($HTTP_COOKIE_VARS[$cookiename . '_sid']) || isset($HTTP_COOKIE_VARS[$cookiename . '_data']) )

#
#-----[ BEFORE, ADD ]------------------------------------------
#
	if ( user_is_spider() && !defined('MRW_SPIDER_FORCED') )
	{
		// Gives the spider only one session
		$session_id = md5(get_spider_name());
		$sessiondata = array();
		$sessionmethod = SESSION_METHOD_GET;
	}

#
#-----[ IN-LINE FIND ]------------------------------------------
# dotyczy linii z ostatniego FIND
#
if

#
#-----[ IN-LINE BEFORE, ADD ]------------------------------------------
#
else

#
#-----[ FIND ]------------------------------------------
#
function append_sid($url, $non_html_amp = false)
{
	global $SID;

	if ( !empty($SID) && !preg_match('#sid=#', $url) )
	{
		$url .= ( ( strpos($url, '?') != false ) ?  ( ( $non_html_amp ) ? '&' : '&amp;' ) : '?' ) . $SID;
	}

#
#-----[ REPLACE WITH ]------------------------------------------
#
function append_sid($url, $non_html_amp = false)
{
	global $SID, $sfc;

	$is_spider = user_is_spider();

	if ( !defined('IN_ADMIN') && $sfc['mod_rewrite_enabled'] && (!$sfc['spiders_only'] || ($sfc['spiders_only'] && $is_spider)) )
	{
		$url = mod_rewrite_replace($url, $non_html_amp);
	}

	if ( !empty($SID) && !$is_spider && !preg_match('#sid=#', $url) )
	{
		$url .= ( ( strpos($url, '?') != false ) ?  ( ( $non_html_amp ) ? '&' : '&amp;' ) : '?' ) . $SID;
	}

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

#
#-----[ FIND ]------------------------------------------
#
//
// Parse and show the overall header.

#
#-----[ BEFORE, ADD ]------------------------------------------
#
// Start nested buffering for paths modification
ob_start('mod_rewrite_replace_url');
// and reconfig forums id needed
if( user_is_spider() )
{
	forum_reconfig();
}

#
#-----[ FIND ]------------------------------------------
#
if (defined('SHOW_ONLINE'))

#
#-----[ REPLACE WITH ]------------------------------------------
#
if (defined('SHOW_ONLINE') && !user_is_spider())

#
#-----[ FIND ]------------------------------------------
#
	'META_DESC' =>

#
#-----[ IN-LINE FIND ]------------------------------------------
#
'META_DESC' =>

#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
 get_meta_robots() . 

#
#-----[ FIND ]------------------------------------------
#
	'U_INDEX' => append_sid('index.'.$phpEx),

#
#-----[ REPLACE WITH ]------------------------------------------
#
	'U_INDEX' => append_sid(get_board_index()),
	'SITEMAP' => get_sitemap(),

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

#
#-----[ FIND ]------------------------------------------
#
$db->sql_close();

#
#-----[ AFTER, ADD ]------------------------------------------
#
//
// Flush nested buffer
//
ob_end_flush();

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

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

#
#-----[ BEFORE, ADD ]------------------------------------------
#
// BEGIN Spider Friendly
$lang['AASpider_Friendly'] = 'Spider Friendly';
$lang['Sitemap_Preview'] = 'Podgld mapy forum';
$lang['Forum_Preview'] = 'Podgld forum (robot)';
$lang['Search_Engines'] = 'Wyszukiwarki';
// END Spider Friendly

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

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

#
#-----[ BEFORE, ADD ]------------------------------------------
#
// BEGIN Spider Friendly
$lang['AASpider_Friendly'] = 'Spider Friendly';
$lang['Sitemap_Preview'] = 'Forum map preview';
$lang['Forum_Preview'] = 'Forum preview (bot)';
$lang['Search_Engines'] = 'Spiders\' log';
// END Spider Friendly

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

#
#-----[ FIND ]------------------------------------------
#
{TRANSLATION_INFO}

#
#-----[ IN-LINE FIND ]------------------------------------------
#
{TRANSLATION_INFO}

#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
{SITEMAP}

#
#-----[ OPEN ]------------------------------------------
#
common.php

#
#-----[ FIND ]------------------------------------------
#
	$board_config[$row['config_name']] = $row['config_value'];
}

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

#
#-----[ OPEN ]------------------------------------------
#
index.php

#
#-----[ FIND ]------------------------------------------
#
$forum_moderators[$row['forum_id']][] = '<a href="' . append_sid("profile

#
#-----[ IN-LINE FIND ]------------------------------------------
#
=

#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
 !user_is_spider() ?

#
#-----[ IN-LINE FIND ]------------------------------------------
#
;

#
#-----[ IN-LINE BEFORE, ADD ]------------------------------------------
#
 : $row['username']

#
#-----[ FIND ]------------------------------------------
#
$forum_moderators[$row['forum_id']][] = '<a href="' . append_sid("groupcp

#
#-----[ IN-LINE FIND ]------------------------------------------
#
=

#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
 !user_is_spider() ?

#
#-----[ IN-LINE FIND ]------------------------------------------
#
;

#
#-----[ IN-LINE BEFORE, ADD ]------------------------------------------
#
 : $row['group_name']

#
#-----[ FIND ]------------------------------------------
#
$last_post .= ( $forum_data[$j]['user_id'] == ANONYMOUS ) ?

#
#-----[ BEFORE, ADD ]------------------------------------------
#
								if ( !user_is_spider() )
								{

#
#-----[ AFTER, ADD ]------------------------------------------
#
								}
								else
								{
									$last_post .= ( $forum_data[$j]['user_id'] == ANONYMOUS ) ? ( ($forum_data[$j]['post_username'] != '' ) ? $forum_data[$j]['post_username'] . ' ' : $lang['Guest'] . ' ' ) : $forum_data[$j]['username'];								
								}

#
#-----[ OPEN ]------------------------------------------
#
viewforum.php

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

#
#-----[ BEFORE, ADD ]------------------------------------------
#
set_meta_robots('noindex, follow');

#
#-----[ FIND ]------------------------------------------
# 621
		$topic_author = ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? '<a href="'

#
#-----[ IN-LINE FIND ]------------------------------------------
#
ANONYMOUS

#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
 && !user_is_spider()

#
#-----[ FIND ]------------------------------------------
#
		$topic_author .= ( $topic_rowset[$i]['user_id'] != ANONYMOUS ) ? '</a>' : '';

#
#-----[ REPLACE WITH ]------------------------------------------
#
		$topic_author .= ( $topic_rowset[$i]['user_id'] != ANONYMOUS && !user_is_spider() ) ? '</a>' : '';

#
#-----[ FIND ]------------------------------------------
#
		$last_post_author = ( $topic_rowset[$i]['id2'] == ANONYMOUS ) ? ( ($topic_rowset[$i]['post_username2'] != '' ) ? $topic_rowset[$i]['post_username2'] . ' ' : $lang['Guest'] . ' ' ) : '<a href="' . append_sid("profile.$phpEx?mode=viewprofile&amp;" . POST_USERS_URL . '='  . $topic_rowset[$i]['id2']) . '">' . $topic_rowset[$i]['user2'] . '</a>';

		$last_post_url = '<a href="' . append_sid("viewtopic.$phpEx?"  . POST_POST_URL . '=' . $topic_rowset[$i]['topic_last_post_id']) . '#' . $topic_rowset[$i]['topic_last_post_id'] . '"><img src="' . $images['icon_latest_reply'] . '" alt="' . $lang['View_latest_post'] . '" title="' . $lang['View_latest_post'] . '" border="0" /></a>';

#
#-----[ BEFORE, ADD ]------------------------------------------
#
		if (!user_is_spider())
		{

#
#-----[ AFTER, ADD ]------------------------------------------
#
		}
		else
		{
			$last_post_author = ($topic_rowset[$i]['id2'] == ANONYMOUS) ? ( ($topic_rowset[$i]['post_username2'] != '' ) ? $topic_rowset[$i]['post_username2'] . ' ' : $lang['Guest'] . ' ' ) : $topic_rowset[$i]['user2'];
			$last_post_url = '';
		}

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

#
#-----[ FIND ]------------------------------------------
# 1062
//
// Output page header

#
#-----[ BEFORE, ADD ]------------------------------------------
#
// Prapare meta data (description, keywords)
$sql = "SELECT w.word_text 
	FROM " . TOPICS_TABLE . " t, " . SEARCH_MATCH_TABLE . " m, " . SEARCH_WORD_TABLE . " w 
	WHERE t.topic_first_post_id = m.post_id 
		AND m.word_id = w.word_id 
		AND w.word_common = 0 
		AND t.topic_id = $topic_id";
if( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not obtain keywords information.', '', __LINE__, __FILE__, $sql);
}
$meta_keywords = '';
while ( $row = $db->sql_fetchrow($result) )
{
	if( strlen($row['word_text']) > 2 )
	{
		$meta_keywords .= $row['word_text'] . ' ';
	}
}
add_meta_keywords($forum_name, $topic_title, $meta_keywords);
set_meta_description($forum_name . ' - ' . $topic_title);

#
#-----[ FIND ]------------------------------------------
#
$page_title = $lang['View_topic'] .' - ' . $topic_title;

#
#-----[ REPLACE WITH ]------------------------------------------
#
$page_title = $topic_title;

#
#-----[ FIND ]------------------------------------------
#
	$temp_url = append_sid("posting.$phpEx?mode=quote&amp;" . POST_POST_URL . "=" . $postrow[$i]['post_id']);
	$quote_img = '<a href="' . $temp_url . '"><img src="' . $images['icon_quote'] . '" alt="' . $lang['Reply_with_quote'] . '" title="' . $lang['Reply_with_quote'] . '" border="0" /></a>';
	$quote = '<a href="' . $temp_url . '">' . $lang['Reply_with_quote'] . '</a>';

#
#-----[ BEFORE, ADD ]------------------------------------------
#
	if ( $userdata['session_logged_in'] || !user_is_spider() )
	{

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

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