forked from mantisbt/mantisbt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlast_visited_api.php
103 lines (91 loc) · 3.18 KB
/
last_visited_api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
# MantisBT - A PHP based bugtracking system
# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
/**
* Last Visited API
*
* @package CoreAPI
* @subpackage LastVisitedAPI
* @copyright Copyright 2000 - 2002 Kenzaburo Ito - [email protected]
* @copyright Copyright 2002 MantisBT Team - [email protected]
* @link http://www.mantisbt.org
*
* @uses bug_api.php
* @uses config_api.php
* @uses constant_inc.php
* @uses current_user_api.php
* @uses database_api.php
* @uses tokens_api.php
*/
require_api( 'bug_api.php' );
require_api( 'config_api.php' );
require_api( 'constant_inc.php' );
require_api( 'current_user_api.php' );
require_api( 'database_api.php' );
require_api( 'tokens_api.php' );
/**
* Determine if last visited feature is enabled
*
* @return boolean true: enabled; false: otherwise.
* @access public
*/
function last_visited_enabled() {
return !( 0 == config_get( 'recently_visited_count' ) || current_user_is_anonymous() );
}
/**
* This method should be called from view, update, print pages for issues,
* mantisconnect.
*
* @param integer $p_issue_id The issue id that was just visited.
* @param integer $p_user_id The user id that visited the issue, or null for current logged in user.
* @access public
* @return void
*/
function last_visited_issue( $p_issue_id, $p_user_id = null ) {
if( !last_visited_enabled() ) {
return;
}
$t_value = token_get_value( TOKEN_LAST_VISITED, $p_user_id );
if( is_null( $t_value ) ) {
$t_value = $p_issue_id;
} else {
$t_ids = explode( ',', $p_issue_id . ',' . $t_value );
$t_ids = array_unique( $t_ids );
$t_ids = array_slice( $t_ids, 0, config_get( 'recently_visited_count' ) );
$t_value = implode( ',', $t_ids );
}
token_set( TOKEN_LAST_VISITED, $t_value, TOKEN_EXPIRY_LAST_VISITED, $p_user_id );
}
/**
* Get an array of the last visited bug ids. We intentionally don't check
* if the ids still exists to avoid performance degradation.
*
* @param integer $p_user_id The user id to get the last visited issues for, or null for current logged in user.
* @return array An array of issue ids or an empty array if none found.
* @access public
*/
function last_visited_get_array( $p_user_id = null ) {
if( !last_visited_enabled() ) {
return array();
}
$t_value = token_get_value( TOKEN_LAST_VISITED, $p_user_id );
if( is_null( $t_value ) ) {
return array();
}
# we don't slice the array here to optimise for performance. If the user reduces the number of recently
# visited to track, then he/she will get the extra entries until visiting an issue.
$t_ids = explode( ',', $t_value );
bug_cache_array_rows( $t_ids );
return $t_ids;
}