Update api_comment.php
[bugdar.git] / includes / api_comment.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©2002-2007 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 ©2002 - 2007, Blue Static
29 * @version $Revision$
30 * @package Bugdar
31 *
32 */
33 class CommentAPI extends BSApi
34 {
35 /**
36 * Fields
37 * @var array
38 */
39 protected $fields = array(
40 'commentid' => array(TYPE_UINT, REQ_AUTO),
41 'bugid' => array(TYPE_UINT, REQ_YES),
42 'userid' => array(TYPE_UINT, REQ_NO),
43 'dateline' => array(TYPE_UINT, REQ_SET),
44 'parselinks' => array(TYPE_BOOL, REQ_NO),
45 'comment' => array(TYPE_STR, REQ_YES),
46 'comment_parsed' => array(TYPE_NONE, REQ_SET),
47 'hidden' => array(TYPE_BOOL, REQ_NO)
48 );
49
50 /**
51 * Database table
52 * @var string
53 */
54 protected $table = 'comment';
55
56 /**
57 * Table prefix
58 * @var string
59 */
60 protected $prefix = TABLE_PREFIX;
61
62 /**
63 * Set field: dateline
64 */
65 protected function set_dateline()
66 {
67 $this->set('dateline', time());
68 }
69
70 /**
71 * Set field: comment_parsed
72 */
73 protected function set_comment_parsed()
74 {
75 $comment = $this->values['comment'];
76 if ($this->values['parselinks'])
77 {
78 $comment = str_replace('bug://new', '<a href="newreport.php">' . T('New Bug') . '</a>', $comment);
79 $comment = preg_replace('#bug://((report|problem)/)?([0-9]*)#i', '<a href="showreport.php?bugid=\3">bug \3</a>', $comment);
80 $comment = preg_replace('#(https?://|www\.)\S+#i', '<a href="\0">\0</a>', $comment);
81 }
82
83 if (bugdar::$options['allowhtml'])
84 {
85 $this->set('comment_parsed', nl2br(BSApp::$input->unsanitize($comment)));
86 }
87 else
88 {
89 $this->set('comment_parsed', nl2br($comment));
90 }
91 }
92
93 /**
94 * Pre-update
95 */
96 protected function pre_update()
97 {
98 $this->set_comment_parsed();
99 }
100
101 /**
102 * Pre-delete
103 */
104 protected function pre_delete()
105 {
106 if (BSApp::$db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "bug WHERE initialreport = " . $this->values['commentid']))
107 {
108 $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).'));
109 }
110 }
111
112 /**
113 * Validate: commentid
114 */
115 protected function validate_commentid($field)
116 {
117 return $this->_verifyIsNotZero($field);
118 }
119
120 /**
121 * Validate: Bug ID
122 */
123 protected function validate_bugid($field)
124 {
125 return $this->_verifyIsNotZero($field);
126 }
127
128 /**
129 * Validate: comment
130 */
131 protected function validate_comment($field)
132 {
133 return $this->_verifyIsNotEmpty($field);
134 }
135 }
136
137 /*=====================================================================*\
138 || ###################################################################
139 || # $HeadURL$
140 || # $Id$
141 || ###################################################################
142 \*=====================================================================*/
143 ?>