*/
/**
* commentItem class
* comment Object
*
* @author NAVER (developers@xpressengine.com)
* @package /modules/comment
* @version 0.1
*/
class CommentItem extends BaseObject
{
/**
* comment number
* @var int
*/
var $comment_srl = 0;
/**
* grant
* @var bool
*/
var $grant_cache = null;
/**
* Get the column list int the table
* @var array
*/
var $columnList = array();
/**
* Constructor
* @param int $comment_srl
* @param array $columnList
* @return void
*/
function __construct($comment_srl = 0, $columnList = array())
{
$this->comment_srl = $comment_srl;
$this->columnList = $columnList;
$this->_loadFromDB();
}
function setComment($comment_srl)
{
$this->comment_srl = $comment_srl;
$this->_loadFromDB();
}
/**
* Load comment data from DB and set to commentItem object
* @return void
*/
function _loadFromDB()
{
if(!$this->comment_srl)
{
return;
}
$args = new stdClass();
$args->comment_srl = $this->comment_srl;
$output = executeQuery('comment.getComment', $args, $this->columnList);
$this->setAttribute($output->data);
}
/**
* Comment attribute set to Object object
* @return void
*/
function setAttribute($attribute)
{
if(!is_object($attribute) || !$attribute->comment_srl)
{
$this->comment_srl = NULL;
return;
}
$this->comment_srl = $attribute->comment_srl;
$this->adds($attribute);
// define vars on the object for backward compatibility of skins
if(countobj($attribute))
{
foreach($attribute as $key => $val)
{
$this->{$key} = $val;
}
}
}
function isExists()
{
return (bool) ($this->comment_srl);
}
function isGranted()
{
if(!$this->isExists())
{
return false;
}
if (isset($_SESSION['granted_comment'][$this->comment_srl]))
{
return true;
}
if ($this->grant_cache !== null)
{
return $this->grant_cache;
}
$logged_info = Context::get('logged_info');
if (!$logged_info->member_srl)
{
return $this->grant_cache = false;
}
if ($logged_info->is_admin == 'Y')
{
return $this->grant_cache = true;
}
if ($this->get('member_srl') && abs($this->get('member_srl')) == $logged_info->member_srl)
{
return $this->grant_cache = true;
}
$grant = ModuleModel::getGrant(ModuleModel::getModuleInfoByModuleSrl($this->get('module_srl')), $logged_info);
if ($grant->manager && $grant->can('moderate:comment'))
{
return $this->grant_cache = true;
}
return $this->grant_cache = false;
}
function setGrant()
{
$this->grant_cache = true;
}
function setGrantForSession()
{
$_SESSION['granted_comment'][$this->comment_srl] = true;
$this->setGrant();
}
/**
* Return the status code.
*
* @return string
*/
public function getStatus()
{
switch ($this->get('status'))
{
case RX_STATUS_TEMP: return 'TEMP';
case RX_STATUS_PUBLIC: return $this->get('is_secret') !== 'Y' ? 'PUBLIC' : 'SECRET';
case RX_STATUS_SECRET: return 'SECRET';
case RX_STATUS_EMBARGO: return 'EMBARGO';
case RX_STATUS_TRASH: return 'TRASH';
case RX_STATUS_CENSORED: return 'CENSORED';
case RX_STATUS_CENSORED_BY_ADMIN: return 'CENSORED_BY_ADMIN';
case RX_STATUS_DELETED: return 'DELETED';
case RX_STATUS_DELETED_BY_ADMIN: return 'DELETED_BY_ADMIN';
case RX_STATUS_OTHER: return 'OTHER';
default: return 'OTHER';
}
}
/**
* Return the status in human-readable text.
*
* @return string
*/
public function getStatusText()
{
$status = $this->getStatus();
$statusList = lang('document.status_name_list');
if ($status && isset($statusList[$status]))
{
return $statusList[$status];
}
else
{
return $statusList['OTHER'];
}
}
function isAccessible($strict = false)
{
if(!$this->isExists())
{
return false;
}
if ($strict)
{
$module_info = ModuleModel::getModuleInfoByModuleSrl($this->get('module_srl'));
if (!$module_info)
{
return false;
}
$grant = ModuleModel::getGrant($module_info, Context::get('logged_info'));
if (isset($grant->list) && isset($grant->view) && ($grant->list !== true || $grant->view !== true))
{
return false;
}
}
if (isset($_SESSION['accessible'][$this->comment_srl]) && $_SESSION['accessible'][$this->comment_srl] === $this->get('last_update'))
{
return true;
}
if ($this->get('status') == RX_STATUS_PUBLIC && $this->get('is_secret') !== 'Y')
{
$this->setAccessible();
return true;
}
if ($this->isGranted())
{
$this->setAccessible();
return true;
}
$oDocument = DocumentModel::getDocument($this->get('document_srl'));
if ($oDocument->isGranted())
{
$this->setAccessible();
return true;
}
return false;
}
function setAccessible()
{
if(Context::getSessionStatus())
{
$_SESSION['accessible'][$this->comment_srl] = $this->get('last_update');
}
if(is_array($_SESSION['accessible']) && count($_SESSION['accessible']) > 200)
{
$_SESSION['accessible'] = array_slice($_SESSION['accessible'], 100, null, true);
}
}
function isEditable()
{
return !$this->get('member_srl') || $this->isGranted();
}
function isSecret()
{
return $this->get('status') == RX_STATUS_SECRET || $this->get('is_secret') == 'Y';
}
function isDeleted()
{
return $this->get('status') == RX_STATUS_DELETED || $this->get('status') == RX_STATUS_DELETED_BY_ADMIN;
}
function isDeletedByAdmin()
{
return $this->get('status') == RX_STATUS_DELETED_BY_ADMIN;
}
function useNotify()
{
return $this->get('notify_message') == 'Y';
}
/**
* Notify to comment owner
* @return void
*/
function notify($type, $content)
{
// return if not useNotify
if(!$this->useNotify())
{
return;
}
// pass if the author is not logged-in user
if(!$this->get('member_srl'))
{
return;
}
// return if the currently logged-in user is an author of the comment.
$logged_info = Context::get('logged_info');
if($logged_info->member_srl == $this->get('member_srl'))
{
return;
}
// Variables
if($type)
{
$title = "[" . $type . "] ";
}
$title .= cut_str(strip_tags($content), 30, '...');
$content = sprintf('%s
from : %s', $content, getFullUrl('', 'document_srl', $this->get('document_srl')), $this->get('comment_srl'), getFullUrl('', 'document_srl', $this->get('document_srl')));
$receiver_srl = $this->get('member_srl');
$sender_member_srl = $logged_info->member_srl;
// send a message
$oCommunicationController = getController('communication');
$oCommunicationController->sendMessage($sender_member_srl, $receiver_srl, $title, $content, false, null, false);
}
function getIpAddress()
{
if($this->isGranted())
{
return $this->get('ipaddress');
}
return '*' . strstr($this->get('ipaddress'), '.');
}
function isExistsHomepage()
{
if(trim($this->get('homepage') ?? ''))
{
return TRUE;
}
return FALSE;
}
function getHomepageUrl()
{
$url = trim($this->get('homepage') ?? '');
if(!$url)
{
return;
}
if(!preg_match('@^[a-z]+://@i', $url))
{
$url = 'http://' . $url;
}
return escape($url, false);
}
function getMemberSrl()
{
return $this->get('member_srl');
}
function getUserID()
{
return escape($this->get('user_id'), false);
}
function getUserName()
{
return escape($this->get('user_name'), false);
}
function getNickName()
{
return escape($this->get('nick_name'), false);
}
function getVote()
{
return $this->getMyVote();
}
function getMyVote()
{
if(!$this->comment_srl) return false;
if(isset($_SESSION['voted_comment'][$this->comment_srl]))
{
return $_SESSION['voted_comment'][$this->comment_srl];
}
$logged_info = Context::get('logged_info');
if(!$logged_info->member_srl) return false;
$args = new stdClass();
if($logged_info->member_srl)
{
$args->member_srl = $logged_info->member_srl;
}
else
{
$args->member_srl = 0;
$args->ipaddress = \RX_CLIENT_IP;
}
$args->comment_srl = $this->comment_srl;
$output = executeQuery('comment.getCommentVotedLog', $args);
if(isset($output->data) && $output->data->point)
{
return $_SESSION['voted_comment'][$this->comment_srl] = $output->data->point;
}
return $_SESSION['voted_comment'][$this->comment_srl] = false;
}
function getDeclared()
{
if (!$this->isExists())
{
return false;
}
$logged_info = Context::get('logged_info');
if (!$logged_info->member_srl)
{
return false;
}
if (isset($_SESSION['declared_comment'][$this->comment_srl]))
{
return $_SESSION['declared_comment'][$this->comment_srl];
}
$args = new stdClass();
if ($logged_info->member_srl)
{
$args->member_srl = $logged_info->member_srl;
}
else
{
$args->ipaddress = \RX_CLIENT_IP;
}
$args->comment_srl = $this->comment_srl;
$output = executeQuery('comment.getCommentDeclaredLogInfo', $args);
$declared_count = isset($output->data) ? intval($output->data->count) : 0;
if ($declared_count > 0)
{
return $_SESSION['declared_comment'][$this->comment_srl] = $declared_count;
}
return false;
}
function getContentPlainText($strlen = 0, $default_content = '')
{
if($this->isDeletedByAdmin())
{
$content = lang('msg_admin_deleted_comment');
}
elseif($this->isDeleted())
{
$content = lang('msg_deleted_comment');
}
elseif($this->isSecret() && !$this->isAccessible())
{
$content = lang('msg_is_secret');
}
else
{
$content = $this->get('content');
}
$content = preg_replace('!(