/
news_api.php
118 lines (97 loc) · 3.66 KB
/
news_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
<?php
# Mantis - a php based bugtracking system
# Copyright (C) 2000 - 2002 Kenzaburo Ito - kenito@300baud.org
# Copyright (C) 2002 Mantis Team - mantisbt-dev@lists.sourceforge.net
# This program is distributed under the terms and conditions of the GPL
# See the files README and LICENSE for details
# --------------------------------------------------------
# $Id: news_api.php,v 1.3 2002-08-27 19:59:18 jfitzell Exp $
# --------------------------------------------------------
###########################################################################
# News API
###########################################################################
# --------------------
# Add a news item
function news_create( $p_project_id, $p_poster_id, $p_view_state, $p_announcement, $p_headline, $p_body ) {
$c_project_id = db_prepare_int( $p_project_id );
$c_poster_id = db_prepare_int( $p_poster_id );
$c_view_state = db_prepare_int( $p_view_state );
$c_announcement = db_prepare_bool( $p_announcement );
$c_headline = db_prepare_string( $p_headline );
$c_body = db_prepare_string( $p_body );
$t_news_table = config_get( 'mantis_news_table' );
# Add item
$query = "INSERT
INTO $t_news_table
( id, project_id, poster_id, date_posted, last_modified,
view_state, announcement, headline, body )
VALUES
( null, '$c_project_id', '$c_poster_id', NOW(), NOW(),
'$c_view_state', '$c_announcement', '$c_headline', '$c_body' )";
db_query( $query );
# db_query() errors on failure so:
return true;
}
# --------------------
# Delete the news entry
function news_delete( $p_news_id ) {
$c_news_id = db_prepare_int( $p_news_id );
$t_news_table = config_get( 'mantis_news_table' );
$query = "DELETE
FROM $t_news_table
WHERE id='$c_news_id'";
db_query( $query );
# db_query() errors on failure so:
return true;
}
# --------------------
# Update news item
function news_update( $p_news_id, $p_project_id, $p_view_state, $p_announcement, $p_headline, $p_body ) {
$c_news_id = db_prepare_int( $p_news_id );
$c_project_id = db_prepare_int( $p_project_id );
$c_view_state = db_prepare_int( $p_view_state );
$c_announcement = db_prepare_bool( $p_announcement );
$c_headline = db_prepare_string( $p_headline );
$c_body = db_prepare_string( $p_body );
$t_news_table = config_get( 'mantis_news_table' );
# Update entry
$query = "UPDATE $t_news_table
SET view_state='$c_view_state',
announcement='$c_announcement',
headline='$c_headline',
body='$c_body',
project_id='$c_project_id',
last_modified=NOW()
WHERE id='$c_news_id'";
db_query( $query );
# db_query() errors on failure so:
return true;
}
# --------------------
# Selects the news item associated with the specified id
function news_get_row( $p_news_id ) {
$c_news_id = db_prepare_int( $p_news_id );
$t_news_table = config_get( 'mantis_news_table' );
$query = "SELECT *, UNIX_TIMESTAMP(date_posted) as date_posted
FROM $t_news_table
WHERE id='$c_news_id'";
$result = db_query( $query );
if ( 0 == db_num_rows( $result ) ) {
trigger_error( ERROR_NEWS_NOT_FOUND, ERROR );
} else {
return db_fetch_array( $result );
}
}
# --------------------
# get news count (selected project plus sitewide posts)
function news_get_count( $p_project_id ) {
$c_project_id = db_prepare_int( $p_project_id );
$t_news_table = config_get( 'mantis_news_table' );
$query = "SELECT COUNT(*)
FROM $t_news_table
WHERE project_id='$c_project_id' OR project_id='0000000'";
$result = db_query( $query );
return db_result( $result, 0, 0 );
}
# --------------------
?>