Fix DB_MySQL_PDO::escape_binary().
[bugdar.git] / includes / api_comment.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)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 $GLOBALS['isso:callback']->load('api', null);
23
24 /**
25 * API: Comment
26 *
27 * @author Blue Static
28 * @copyright Copyright (c)2002 - 2007, Blue Static
29 * @version $Revision$
30 * @package Bugdar
31 *
32 */
33 class CommentAPI extends API
34 {
35 /**
36 * Fields
37 * @var array
38 * @access private
39 */
40 var $fields = array(
41 'commentid' => array(TYPE_UINT, REQ_AUTO, 'verify_nozero'),
42 'bugid' => array(TYPE_UINT, REQ_YES, 'verify_nozero'),
43 'userid' => array(TYPE_UINT, REQ_NO),
44 'dateline' => array(TYPE_UINT, REQ_SET),
45 'parselinks' => array(TYPE_BOOL, REQ_NO),
46 'comment' => array(TYPE_STR, REQ_YES, 'verify_noempty'),
47 'comment_parsed' => array(TYPE_NONE, REQ_SET),
48 'hidden' => array(TYPE_BOOL, REQ_NO)
49 );
50
51 /**
52 * Database table
53 * @var string
54 * @access private
55 */
56 var $table = 'comment';
57
58 /**
59 * Table prefix
60 * @var string
61 * @access private
62 */
63 var $prefix = TABLE_PREFIX;
64
65 // ###################################################################
66 /**
67 * Set field: dateline
68 *
69 * @access private
70 */
71 function set_dateline()
72 {
73 $this->set('dateline', time());
74 }
75
76 // ###################################################################
77 /**
78 * Set field: comment_parsed
79 *
80 * @access private
81 */
82 function set_comment_parsed()
83 {
84 $comment = $this->values['comment'];
85 if ($this->values['parselinks'])
86 {
87 $comment = str_replace('bug://new', '<a href="newreport.php">' . T('New Bug') . '</a>', $comment);
88 $comment = preg_replace('#bug://((report|problem)/)?([0-9]*)#i', '<a href="showreport.php?bugid=\3">bug \3</a>', $comment);
89 $comment = preg_replace('#(https?://|www\.)\S+#i', '<a href="\0">\0</a>', $comment);
90 }
91
92 if ($this->registry->options['allowhtml'])
93 {
94 $this->set('comment_parsed', nl2br($this->registry->unsanitize($comment)));
95 }
96 else
97 {
98 $this->set('comment_parsed', nl2br($comment));
99 }
100 }
101
102 // ###################################################################
103 /**
104 * Pre-update
105 *
106 * @access private
107 */
108 function pre_update()
109 {
110 $this->set_comment_parsed();
111 }
112
113 // ###################################################################
114 /**
115 * Pre-delete
116 *
117 * @access private
118 */
119 function pre_delete()
120 {
121 if ($this->registry->db->query_first("SELECT * FROM " . TABLE_PREFIX . "bug WHERE initialreport = " . $this->values['commentid']))
122 {
123 $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).'));
124 }
125 }
126 }
127