Happy 2009! Updating copyright years.
[bugdar.git] / includes / api_comment.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2009 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 require_once ISSO . '/Api.php';
23
24 /**
25 * API: Comment
26 *
27 * @author Blue Static
28 * @copyright Copyright (c)2004 - 2009, Blue Static
29 * @package Bugdar
30 *
31 */
32 class CommentAPI extends BSApi
33 {
34 /**
35 * Fields
36 * @var array
37 */
38 protected $fields = array(
39 'commentid' => array(TYPE_UINT, REQ_AUTO),
40 'bugid' => array(TYPE_UINT, REQ_YES),
41 'userid' => array(TYPE_UINT, REQ_NO),
42 'dateline' => array(TYPE_UINT, REQ_SET),
43 'parselinks' => array(TYPE_BOOL, REQ_NO),
44 'comment' => array(TYPE_STR, REQ_YES),
45 'comment_parsed' => array(TYPE_NONE, REQ_SET),
46 'hidden' => array(TYPE_BOOL, REQ_NO)
47 );
48
49 /**
50 * Database table
51 * @var string
52 */
53 protected $table = 'comment';
54
55 /**
56 * Table prefix
57 * @var string
58 */
59 protected $prefix = TABLE_PREFIX;
60
61 /**
62 * Set field: dateline
63 */
64 protected function set_dateline()
65 {
66 $this->set('dateline', time());
67 }
68
69 /**
70 * Set field: comment_parsed
71 */
72 protected function set_comment_parsed()
73 {
74 $comment = $this->values['comment'];
75 if ($this->values['parselinks'])
76 {
77 $comment = str_replace('bug://new', '<a href="newreport.php">' . T('New Bug') . '</a>', $comment);
78 $comment = preg_replace('#bug://((report|problem)/)?([0-9]*)#i', '<a href="showreport.php?bugid=\3">bug \3</a>', $comment);
79 $comment = preg_replace('#(https?://|www\.)\S+#i', '<a href="\0">\0</a>', $comment);
80 }
81
82 if (bugdar::$options['allowhtml'])
83 {
84 $this->set('comment_parsed', nl2br(BSApp::$input->unsanitize($comment)));
85 }
86 else
87 {
88 $this->set('comment_parsed', nl2br($comment));
89 }
90 }
91
92 /**
93 * Pre-update
94 */
95 protected function pre_update()
96 {
97 $this->set_comment_parsed();
98 }
99
100 /**
101 * Pre-delete
102 */
103 protected function pre_delete()
104 {
105 if (BSApp::$db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE initialreport = " . $this->values['commentid']))
106 {
107 $this->error(T('You cannot delete this comment because it is attached to the bug as the first comment. You have to delete the entire bug instead (which is not recommended unless it is spam).'));
108 }
109 }
110
111 /**
112 * Validate: commentid
113 */
114 protected function validate_commentid($field)
115 {
116 return $this->_verifyIsNotZero($field);
117 }
118
119 /**
120 * Validate: Bug ID
121 */
122 protected function validate_bugid($field)
123 {
124 return $this->_verifyIsNotZero($field);
125 }
126
127 /**
128 * Validate: comment
129 */
130 protected function validate_comment($field)
131 {
132 return $this->_verifyIsNotEmpty($field);
133 }
134 }
135
136 ?>