]>
src.bluestatic.org Git - bugdar.git/blob - includes/api_comment.php
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 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 (c)2004 - 2009, Blue Static
32 class CommentAPI
extends BSApi
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
)
53 protected $table = 'comment' ;
59 protected $prefix = TABLE_PREFIX
;
64 protected function set_dateline ()
66 $this- > set ( 'dateline' , time ());
70 * Set field: comment_parsed
72 protected function set_comment_parsed ()
74 $comment = $this- > values
[ 'comment' ];
75 if ( $this- > values
[ 'parselinks' ])
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 );
82 if ( bugdar
:: $options [ 'allowhtml' ])
84 $this- > set ( 'comment_parsed' , nl2br ( BSApp
:: $input- > unsanitize ( $comment )));
88 $this- > set ( 'comment_parsed' , nl2br ( $comment ));
95 protected function pre_update ()
97 $this- > set_comment_parsed ();
103 protected function pre_delete ()
105 if ( BSApp
:: $db- > queryFirst ( "SELECT * FROM " . TABLE_PREFIX
. "bug WHERE initialreport = " . $this- > values
[ 'commentid' ]))
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).' ));
112 * Validate: commentid
114 protected function validate_commentid ( $field )
116 return $this- > _verifyIsNotZero ( $field );
122 protected function validate_bugid ( $field )
124 return $this- > _verifyIsNotZero ( $field );
130 protected function validate_comment ( $field )
132 return $this- > _verifyIsNotEmpty ( $field );