Blame Extras/Mantis/1.1.2-1.fc9/core/last_visited_api.php

4c79b5
4c79b5
# Mantis - a php based bugtracking system
4c79b5
4c79b5
# Copyright (C) 2000 - 2002  Kenzaburo Ito - kenito@300baud.org
4c79b5
# Copyright (C) 2002 - 2007  Mantis Team   - mantisbt-dev@lists.sourceforge.net
4c79b5
4c79b5
# Mantis is free software: you can redistribute it and/or modify
4c79b5
# it under the terms of the GNU General Public License as published by
4c79b5
# the Free Software Foundation, either version 2 of the License, or
4c79b5
# (at your option) any later version.
4c79b5
#
4c79b5
# Mantis is distributed in the hope that it will be useful,
4c79b5
# but WITHOUT ANY WARRANTY; without even the implied warranty of
4c79b5
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4c79b5
# GNU General Public License for more details.
4c79b5
#
4c79b5
# You should have received a copy of the GNU General Public License
4c79b5
# along with Mantis.  If not, see <http://www.gnu.org/licenses/>.
4c79b5
4c79b5
	#------------------------------
4c79b5
	#   $Revision: 2643 $
4c79b5
	#     $Author: al $    
4c79b5
	#       $Date: 2009-06-18 19:06:27 -0400 (Thu, 18 Jun 2009) $  
4c79b5
	#------------------------------
4c79b5
4c79b5
	$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
4c79b5
4c79b5
	require_once( $t_core_dir . 'tokens_api.php' );
4c79b5
4c79b5
	#---------------------------------
4c79b5
	# Determine if last visited feature is enabled
4c79b5
	function last_visited_enabled() {
4c79b5
		return !( OFF == config_get( 'recently_visited' ) || current_user_is_anonymous() );
4c79b5
	}
4c79b5
4c79b5
	#---------------------------------
4c79b5
	# This method should be called from view, update, print pages for issues, mantisconnect.
4c79b5
	function last_visited_issue( $p_issue_id, $p_user_id = null ) {
4c79b5
		if ( !last_visited_enabled() ) {
4c79b5
			return;
4c79b5
		}
4c79b5
4c79b5
		$c_issue_id = db_prepare_int( $p_issue_id );
4c79b5
4c79b5
		$t_value = token_get_value( TOKEN_LAST_VISITED, $p_user_id );
4c79b5
		if ( is_null( $t_value ) ) {
4c79b5
			$t_value = $c_issue_id;
4c79b5
		} else {
4c79b5
			$t_ids = explode( ',', $p_issue_id . ',' . $t_value );
4c79b5
			$t_ids = array_unique( $t_ids );
4c79b5
			$t_ids = array_slice( $t_ids, 0, config_get( 'recently_visited_count' ) );
4c79b5
			$t_value = implode( ',', $t_ids );
4c79b5
		}
4c79b5
		
4c79b5
		token_set( TOKEN_LAST_VISITED, $t_value, TOKEN_EXPIRY_LAST_VISITED, $p_user_id );
4c79b5
	}
4c79b5
	
4c79b5
	#---------------------------------
4c79b5
	# Get an array of the last visited bug ids.  We intentionally don't check if the ids still exists to avoid performance
4c79b5
	# degradation.
4c79b5
	function last_visited_get_array( $p_user_id = null ) {
4c79b5
		$t_value = token_get_value( TOKEN_LAST_VISITED, $p_user_id );
4c79b5
4c79b5
		if ( is_null( $t_value ) ) {
4c79b5
			return array();
4c79b5
		}
4c79b5
4c79b5
		# we don't slice the array here to optimise for performance.  If the user reduces the number of recently
4c79b5
		# visited to track, then he/she will get the extra entries until visiting an issue.
4c79b5
		$t_ids = explode( ',', $t_value );
4c79b5
4c79b5
		return $t_ids;
4c79b5
	}
4c79b5
?>