1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
|
<?php
/**
* This file implements comments
*
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
*
* @package evocore
*/
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
/**
* Includes:
*/
require_once dirname(__FILE__). '/_class_dataobject.php';
/**
* Comment Class
*
* @package evocore
*/
class Comment extends DataObject
{
/**
* @access protected
*/
var $Item = NULL;
var $author_User = NULL;
var $type;
var $status;
var $author;
var $author_email;
var $author_url;
var $author_ip;
var $date;
var $content;
var $karma;
/*
* Comment::Comment(-)
*
* Constructor
*/
function Comment( $db_row = NULL )
{
global $tablecomments, $ItemCache;
// Call parent constructor:
parent::DataObject( $tablecomments, 'comment_', 'comment_ID' );
if( $db_row == NULL )
{
echo 'null comment';
}
else
{
$this->ID = $db_row['comment_ID'];
// Get parent Item
$this->Item = $ItemCache->get_by_ID( $db_row['comment_post_ID'] );
// Get Author User
$author_ID = $db_row['comment_author_ID'];
if( !empty($author_ID) )
{
$authordata = get_userdata( $author_ID );
$this->author_User = new User( $authordata ); // COPY!
}
$this->type = $db_row['comment_type'];
$this->status = $db_row['comment_status'];
$this->author = $db_row['comment_author'];
$this->author_email = $db_row['comment_author_email'];
$url = trim( $db_row['comment_author_url'] );
$url = preg_replace('#&([^amp\;])#is', '&$1', $url); // Escape &
$this->author_url = (!stristr($url, '://')) ? 'http://'.$url : $url;
$this->author_ip = $db_row['comment_author_IP'];
$this->date = $db_row['comment_date'];
$this->content = $db_row['comment_content'];
$this->karma = $db_row['comment_karma'];
}
}
/*
* Comment::set(-)
*
* Set param value
*/
function set( $parname, $parvalue )
{
switch( $parname )
{
case 'Item':
die ('coment->Post assignement not handled');
case 'karma':
parent::set_param( $parname, 'number', $parvalue );
break;
default:
parent::set_param( $parname, 'string', $parvalue );
}
}
/**
* Template function: display anchor for permalinks to refer to
*
* {@internal Comment::anchor(-) }}
*/
function anchor()
{
echo '<a name="c'.$this->ID.'"></a>';
}
/**
* Template function: display author of comment
*
* {@internal Comment::author(-) }}
*
* @param string String to display before author name if not a user
* @param string String to display after author name if not a user
* @param string String to display before author name if he's a user
* @param string String to display after author name if he's a user
* @param string Output format, see {@link format_to_output()}
* @param boolean true for link, false if you want NO html link
*/
function author( $before = '', $after = '#', $before_user = '', $after_user = '#',
$format = 'htmlbody', $makelink = false )
{
if( $this->author_User !== NULL )
{ // Author is a user
if( $after_user == '#' ) $after_user = ' ['.T_('Member').']';
echo $before_user;
$this->author_User->prefered_name( $format );
echo $after_user;
}
else
{ // Display info recorded at edit time:
if( strlen( $this->author_url ) <= 10 ) $makelink = false;
if( $after == '#' ) $after = ' ['.T_('Visitor').']';
echo $before;
if( $makelink ) echo '<a href="'.$this->author_url.'">';
$this->disp( 'author', $format );
if( $makelink ) echo '</a>';
echo $after;
}
}
/**
* Template function: display comment's author's IP
*
* {@internal Comment::author_ip(-) }}
*
* @param string String to display before IP, if IP exists
* @param string String to display after IP, if IP exists
*/
function author_ip( $before='', $after='' )
{
if( !empty( $this->author_ip ) )
{
echo $before;
echo $this->author_ip;
echo $after;
}
}
/**
* Template function: display link to comment author's provided email
*
* {@internal Comment::author_email(-) }}
*
* @param string String to display for link: leave empty to display email
* @param string String to display before email, if email exists
* @param string String to display after email, if email exists
* @param boolean false if you want NO html link
*/
function author_email( $linktext='', $before='', $after='', $makelink = true )
{
if( $this->author_User !== NULL )
{ // Author is a user
$email = $this->author_User->get('email');
}
else
{
$email = $this->author_email;
}
if( strlen( $email ) > 5 )
{ // If email exists:
echo $before;
if( $makelink ) echo '<a href="mailto:'.$email.'">';
echo ($linktext != '') ? $linktext : $email;
if( $makelink ) echo '</a>';
echo $after;
}
}
/**
* Template function: display link to comment author's provided URL
*
* {@internal Comment::author_url(-) }}
*
* @param string String to display for link: leave empty to display URL
* @param string String to display before link, if link exists
* @param string String to display after link, if link exists
* @param boolean false if you want NO html link
* @return boolean true if URL has been displayed
*/
function author_url( $linktext='', $before='', $after='', $makelink = true )
{
if( $this->author_User !== NULL )
{ // Author is a user
$url = $this->author_User->get('url');
}
else
{
$url = $this->author_url;
}
if( strlen( $url ) > 10 )
{ // If URL exists:
echo $before;
if( $makelink ) echo '<a href="'.$url.'" rel="nofollow">';
echo ($linktext != '') ? $linktext : $url;
if( $makelink ) echo '</a>';
echo $after;
return true;
}
return false;
}
/**
* Provide link to edit a comment if user has edit rights
*
* {@internal Comment::edit_link(-)}}
*
* @param string to display before link
* @param string to display after link
* @param string link text
* @param string link title
* @param string class name
*/
function edit_link( $before = ' ', $after = ' ', $text = '#', $title = '#', $class = '' )
{
global $current_User, $admin_url;
if( ! is_logged_in() ) return false;
if( ! $current_User->check_perm( 'blog_comments', '', false, $this->Item->get( 'blog_ID' ) ) )
{ // If User has no permission to edit comments:
return false;
}
if( $text == '#' ) $text = T_('Edit');
if( $title == '#' ) $title = T_('Edit this comment');
echo $before;
echo '<a href="'.$admin_url.'/b2edit.php?action=editcomment&comment='.$this->ID;
echo '" title="'.$title.'"';
if( !empty( $class ) ) echo ' class="'.$class.'"';
echo '>'.$text.'</a>';
echo $after;
return true;
}
/**
* Displays button for deleeing the Comment if user has proper rights
*
* {@internal Comment::delete_link(-)}}
*
* @param string to display before link
* @param string to display after link
* @param string link text
* @param string link title
* @param string class name
* @param boolean true to make this a button instead of a link
*/
function delete_link( $before = ' ', $after = ' ', $text = '#', $title = '#', $class = '', $button = false )
{
global $current_User, $admin_url;
if( ! is_logged_in() ) return false;
if( ! $current_User->check_perm( 'blog_comments', '', false, $this->Item->get( 'blog_ID' ) ) )
{ // If User has permission to edit comments:
return false;
}
if( $text == '#' ) $text = T_('Delete');
if( $title == '#' ) $title = T_('Delete this comment');
$url = $admin_url.'/edit_actions.php?action=deletecomment&comment_ID='.$this->ID;
echo $before;
if( $button )
{ // Display as button
echo '<input type="button"';
echo ' value="'.$text.'" title="'.$title.'" onclick="if ( confirm(\'';
/* TRANS: Warning this is a javascript string */
echo T_('You are about to delete this comment!\\n\\\'Cancel\\\' to stop, \\\'OK\\\' to delete.');
echo '\') ) { document.location.href=\''.$url.'\' }"';
if( !empty( $class ) ) echo ' class="'.$class.'"';
echo '/>';
}
else
{ // Display as link
echo '<a href="'.$url.'" title="'.$title.'" onclick="return confirm(\'';
/* TRANS: Warning this is a javascript string */
echo T_('You are about to delete this comment!\\n\\\'Cancel\\\' to stop, \\\'OK\\\' to delete.');
echo '\')"';
if( !empty( $class ) ) echo ' class="'.$class.'"';
echo '>'.$text.'</a>';
}
echo $after;
return true;
}
/**
* Template function: display permalink to this comment
*
* {@internal Comment::permalink(-) }}
*
* @param string 'urltitle', 'pid', 'archive#id' or 'archive#title'
* @param string url to use
*/
function permalink( $mode = '', $blogurl='' )
{
global $Settings;
if( empty( $mode ) )
$mode = $Settings->get( 'permalink_type' );
// some permalink modes are not acceptable here:
switch( $mode )
{
case 'archive#id':
case 'archive#title':
$mode = 'pid';
}
$post_permalink = $this->Item->gen_permalink( $mode, $blogurl );
echo $post_permalink.'#c'.$this->ID;
}
/**
* Template function: display content of comment
*
* {@internal Comment::content(-) }}
*
* @param string Output format, see {@link format_to_output()}
*/
function content( $format = 'htmlbody' )
{
$comment = $this->content;
$comment = str_replace('<trackback />', '', $comment);
$comment = str_replace('<pingback />', '', $comment);
$comment = format_to_output( $comment, $format );
echo $comment;
}
/**
* Template function: display date (datetime) of comment
*
* {@internal Comment::date(-) }}
*
* @param string date/time format: leave empty to use locale default date format
* @param boolean true if you want GMT
*/
function date( $format='', $useGM = false )
{
if( empty($format) )
echo mysql2date( locale_datefmt(), $this->date, $useGM);
else
echo mysql2date( $format, $this->date, $useGM);
}
/**
* Template function: display time (datetime) of comment
*
* {@internal Comment::time(-) }}
*
* @param string date/time format: leave empty to use locale default time format
* @param boolean true if you want GMT
*/
function time( $format='', $useGM = false )
{
if( empty($format) )
echo mysql2date( locale_timefmt(), $this->date, $useGM );
else
echo mysql2date( $format, $this->date, $useGM );
}
}
?>
|