Talk martial arts at KarateForums.com

Bookmark and Share

Disable Author View Counting

Disable Author View Counting

Postby Thoul » November 27th 2004, 7:07 pm

Usually, topics are viewed most often by the person that started the topic. If you feel that this artificially inflates the number of views counted for topics, or just plain dislike the behavior, you can prevent it with these changes.

These changes only disable counting of multiple views by the original poster of the topic. To stop counting the views of all posters in a topic, skip to the second post. Please note that this code does not account for guest posters - they are nearly impossible to track for this purpose.
Code: Select all
##
##----------[ OPEN ]-------------------------------------

##

viewtopic.php

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

$sql = "UPDATE " . TOPICS_TABLE . "
	SET topic_views = topic_views + 1
	WHERE topic_id = $topic_id";
if ( !$db->sql_query($sql) )
{
	message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql);
}

##
##----------[ REPLACE WITH ]-----------------------------
##

/*-------------------------------------------------------------------
//  Disable Author View Counting - Begin ORIGINAL phpBB Code
//

$sql = "UPDATE " . TOPICS_TABLE . "
	SET topic_views = topic_views + 1
	WHERE topic_id = $topic_id";
if ( !$db->sql_query($sql) )
{
	message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql);
}

//
//  Disable Author View Counting - End ORIGINAL phpBB Code
//-------------------------------------------------------------------*/

//-------------------------------------------------------------------
//  Disable Author View Counting - Begin Code Addition
//
if ( $userdata['user_id'] == ANONYMOUS || $userdata['user_id'] != $postrow[0]['user_id'] )
{
	$sql = "UPDATE " . TOPICS_TABLE . "
		SET topic_views = topic_views + 1
		WHERE topic_id = $topic_id";
	if ( !$db->sql_query($sql) )
	{
		message_die(GENERAL_ERROR, 'Could not update topic views.', '', __LINE__, __FILE__, $sql);
	}
}
//
//  Disable Author View Counting - End Code Addition
//-------------------------------------------------------------------
Last edited by Thoul on May 6th 2005, 10:25 am, edited 1 time in total.
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA

Disable Poster View Counting

Postby Thoul » November 27th 2004, 7:16 pm

The above code only disables View counting for the first poster in a topic. To disable view counting for all posters in a topic, use this method instead. Again, this does not take guest posters into account. Also, this code can only be used if running phpBB on PHP 4 or later.

Code: Select all
##
##----------[ OPEN ]-------------------------------------
##

viewtopic.php

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

$sql = "UPDATE " . TOPICS_TABLE . "
	SET topic_views = topic_views + 1
	WHERE topic_id = $topic_id";
if ( !$db->sql_query($sql) )
{
	message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql);
}

##
##----------[ REPLACE WITH ]-----------------------------
##

/*-------------------------------------------------------------------
//  Disable Poster View Counting - Begin ORIGINAL phpBB Code
//

$sql = "UPDATE " . TOPICS_TABLE . "
	SET topic_views = topic_views + 1
	WHERE topic_id = $topic_id";
if ( !$db->sql_query($sql) )
{
	message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql);
}

//
//  Disable Poster View Counting - End ORIGINAL phpBB Code
//-------------------------------------------------------------------*/

//-------------------------------------------------------------------
//  Disable Poster View Counting - Begin Code Addition
//

$sql = 'SELECT poster_id FROM ' . POSTS_TABLE . '
		WHERE topic_id = ' . $topic_id . '
			AND poster_id <> ' . ANONYMOUS;
if ( $posters_result = $db->sql_query($sql) )
{
	$authors = array();
	while( $posters = $db->sql_fetchrow($posters_result) )
	{
		$authors[] = intval($posters['poster_id']);
	}

	if ( $userdata['user_id'] == ANONYMOUS || !in_array($userdata['user_id'], $authors) )
	{
		$sql = "UPDATE " . TOPICS_TABLE . "
			SET topic_views = topic_views + 1
			WHERE topic_id = $topic_id";
		if ( !$db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, 'Could not update topic views.', '', __LINE__, __FILE__, $sql);
		}
	}
}
else
{
	$sql = "UPDATE " . TOPICS_TABLE . "
		SET topic_views = topic_views + 1
		WHERE topic_id = $topic_id";
	if ( !$db->sql_query($sql) )
	{
		message_die(GENERAL_ERROR, "Could not update topic views.", '', __LINE__, __FILE__, $sql);
	}
}
//
//  Disable Poster View Counting - End Code Addition
//-------------------------------------------------------------------
User avatar
Thoul
Admin/Webmaster
 
Posts: 18551
Joined: July 30th 2002, 11:30 am
Location: USA


Return to phpBB 2: Customizing Your phpBB

Who is online

Users browsing this forum: No registered users and 0 guests