/
rss_api.php
149 lines (119 loc) · 4.31 KB
/
rss_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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 - 2007 Mantis Team - mantisbt-dev@lists.sourceforge.net
# Mantis 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.
#
# Mantis 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 Mantis. If not, see <http://www.gnu.org/licenses/>.
# --------------------------------------------------------
# $Id: rss_api.php,v 1.1.4.1 2007-10-13 22:35:42 giallu Exp $
# --------------------------------------------------------
### RSS API ###
# --------------------
# Calculates a key to be used for RSS authentication based on user name, cookie and password.
# if the user changes his user name or password, then the key becomes invalid.
function rss_calculate_key( $p_user_id = null ) {
if ( $p_user_id === null ) {
$t_user_id = auth_get_current_user_id();
} else {
$t_user_id = $p_user_id;
}
$t_seed = config_get_global( 'rss_key_seed' );
$t_username = user_get_field( $t_user_id, 'username' );
$t_password = user_get_field( $t_user_id, 'password' );
$t_cookie = user_get_field( $t_user_id, 'cookie_string' );
return md5( $t_seed . $t_username . $t_cookie . $t_password );
}
# --------------------
# Given the user name and the rss key, this method attempts to login the user. If successful, it
# return true, otherwise, returns false.
function rss_login( $p_username, $p_key ) {
if ( ( $p_username === null ) || ( $p_key === null ) ) {
return false;
}
$t_user_id = user_get_id_by_name( $p_username );
$t_correct_key = rss_calculate_key( $t_user_id );
if ( $p_key != $t_correct_key ) {
return false;
}
if ( !auth_attempt_script_login( $p_username ) ) {
return false;
}
return true;
}
# --------------------
function rss_get_issues_feed_url( $p_project_id = null, $p_username = null, $p_filter_id = null, $p_relative = true ) {
if ( $p_username === null ) {
$t_username = current_user_get_field( 'username' );
} else {
$t_username = $p_username;
}
if ( $p_project_id === null ) {
$t_project_id = helper_get_current_project();
} else {
$t_project_id = (integer)$p_project_id;
}
$t_user_id = user_get_id_by_name( $t_username );
if ( $p_relative ) {
$t_url = config_get( 'path' );
} else {
$t_url = '';
}
if ( $t_username == config_get( 'anonymous_account' ) ) {
$t_url .= 'issues_rss.php?';
if ( $t_project_id == ALL_PROJECTS ) {
$t_url .= 'project_id=' . $t_project_id;
}
} else {
$t_url .= 'issues_rss.php?username=' . $t_username . '&key=' . rss_calculate_key( $t_user_id );
if ( $t_project_id != ALL_PROJECTS ) {
$t_url .= '&project_id=' . $t_project_id;
}
}
if ( $p_filter_id !== null ) {
$t_url .= '&filter_id=' . $p_filter_id;
}
return $t_url;
}
# --------------------
function rss_get_news_feed_url( $p_project_id = null, $p_username = null, $p_relative = true ) {
if ( $p_username === null ) {
$t_username = current_user_get_field( 'username' );
} else {
$t_username = $p_username;
}
if ( $p_project_id === null ) {
$t_project_id = helper_get_current_project();
} else {
$t_project_id = (integer)$p_project_id;
}
if ( $p_relative ) {
$t_rss_link = '';
} else {
$t_rss_link = config_get( 'path' );
}
$t_user_id = user_get_id_by_name( $t_username );
// If we have a logged in user then they can be given a 'proper' feed, complete with auth string.
if ( $t_username == config_get( 'anonymous_account' ) ) {
$t_rss_link .= "news_rss.php?";
if ( $t_project_id != ALL_PROJECTS ) {
$t_rss_link .= "news_rss.php?project_id=" . $t_project_id;
}
} else {
$t_rss_link .= "news_rss.php?username=" . $t_username . "&key=" . rss_calculate_key( $t_user_id );
if ( $t_project_id != ALL_PROJECTS ) {
$t_rss_link .= "&project_id=" . $t_project_id;
}
}
return $t_rss_link;
}
?>