]>
src.bluestatic.org Git - bugdar.git/blob - api_comment.php
c191dfe65a443b1a31e355122a7f2d2eb3de3a1b
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 Blue Static
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.
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
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 \*=====================================================================*/
22 require_once ISSO
. '/Api.php' ;
28 * @copyright Copyright ©2002 - 2007, Blue Static
33 class CommentAPI
extends BSApi
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
)
54 protected $table = 'comment' ;
60 protected $prefix = TABLE_PREFIX
;
65 protected function set_dateline ()
67 $this- > set ( 'dateline' , time ());
71 * Set field: comment_parsed
73 protected function set_comment_parsed ()
75 $comment = $this- > values
[ 'comment' ];
76 if ( $this- > values
[ 'parselinks' ])
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 );
83 if ( bugdar
:: $options [ 'allowhtml' ])
85 $this- > set ( 'comment_parsed' , nl2br ( BSApp
:: $input- > unsanitize ( $comment )));
89 $this- > set ( 'comment_parsed' , nl2br ( $comment ));
96 protected function pre_update ()
98 $this- > set_comment_parsed ();
104 protected function pre_delete ()
106 if ( BSApp
:: $db- > queryFirst ( "SELECT * FROM " . TABLE_PREFIX
. "bug WHERE initialreport = " . $this- > values
[ 'commentid' ]))
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).' ));
113 * Validate: commentid
115 protected function validate_commentid ( $field )
117 return $this- > _verifyIsNotZero ( $field );
123 protected function validate_bugid ( $field )
125 return $this- > _verifyIsNotZero ( $field );
131 protected function validate_comment ( $field )
133 return $this- > _verifyIsNotEmpty ( $field );
137 /*=====================================================================*\
138 || ###################################################################
141 || ###################################################################
142 \*=====================================================================*/