*/
/**
* documentItem class
* document object
*
* @author NAVER (developers@xpressengine.com)
* @package /modules/document
* @version 0.1
*/
class DocumentItem extends BaseObject
{
/**
* Document number
* @var int
*/
var $document_srl = 0;
/**
* Language code
* @var string
*/
var $lang_code = null;
/**
* grant
* @var bool
*/
var $grant_cache = null;
/**
* Status of allow trackback
* @var bool
*/
var $allow_trackback_status = null;
/**
* Comment page navigation
* @var object
*/
var $comment_page_navigation = null;
/**
* column list
* @var array
*/
var $columnList = array();
/**
* allow script access list
* @var array
*/
var $allowscriptaccessList = array();
/**
* allow script access key
* @var int
*/
var $allowscriptaccessKey = 0;
/**
* upload file list
* @var array
*/
var $uploadedFiles = array();
/**
* extra eids
* @var array
*/
protected $extra_eids = array();
/**
* Constructor
* @param int $document_srl
* @param bool $load_extra_vars
* @param array columnList
* @return void
*/
function __construct($document_srl = 0, $load_extra_vars = true, $columnList = array())
{
$this->document_srl = $document_srl;
$this->columnList = $columnList;
$this->_loadFromDB($load_extra_vars);
}
function setDocument($document_srl, $load_extra_vars = true)
{
$this->document_srl = $document_srl;
$this->_loadFromDB($load_extra_vars);
}
/**
* Get data from database, and set the value to documentItem object
* @param bool $load_extra_vars
* @return void
*/
function _loadFromDB($load_extra_vars = true)
{
if(!$this->document_srl)
{
return;
}
$document_item = false;
$columnList = array();
$reload_counts = true;
if ($this->columnList === false)
{
$reload_counts = false;
}
$this->columnList = array();
// cache controll
$cache_key = 'document_item:' . getNumberingPath($this->document_srl) . $this->document_srl;
$document_item = Rhymix\Framework\Cache::get($cache_key);
if($document_item)
{
$columnList = array('readed_count', 'voted_count', 'blamed_count', 'comment_count', 'trackback_count');
}
if(!$document_item || $reload_counts)
{
$args = new stdClass();
$args->document_srl = $this->document_srl;
$output = executeQuery('document.getDocument', $args, $columnList);
}
if(!$document_item)
{
$document_item = $output->data;
if($document_item)
{
Rhymix\Framework\Cache::set($cache_key, $document_item);
}
}
else
{
$document_item->readed_count = $output->data->readed_count;
$document_item->voted_count = $output->data->voted_count;
$document_item->blamed_count = $output->data->blamed_count;
$document_item->comment_count = $output->data->comment_count;
$document_item->trackback_count = $output->data->trackback_count;
}
$this->setAttribute($document_item, $load_extra_vars);
}
function setAttribute($attribute, $load_extra_vars = true)
{
if(!is_object($attribute) || !$attribute->document_srl)
{
$this->document_srl = null;
return;
}
$this->document_srl = $attribute->document_srl;
$this->lang_code = $attribute->lang_code ?? null;
$this->adds($attribute);
if(isset($attribute->module_srl))
{
$this->add('apparent_module_srl', $attribute->module_srl);
$this->add('origin_module_srl', $attribute->module_srl);
}
// set XE_DOCUMENT_LIST
$GLOBALS['XE_DOCUMENT_LIST'][$this->document_srl] = $this;
// set tags
if($this->get('tags'))
{
$this->add('tag_list', $this->getTags());
}
// set extra vars
if($load_extra_vars)
{
DocumentModel::setToAllDocumentExtraVars();
}
// set content in user language
if(isset($GLOBALS['RX_DOCUMENT_LANG'][$this->document_srl]['title']))
{
$this->add('title', $GLOBALS['RX_DOCUMENT_LANG'][$this->document_srl]['title']);
}
if(isset($GLOBALS['RX_DOCUMENT_LANG'][$this->document_srl]['content']))
{
$this->add('content', $GLOBALS['RX_DOCUMENT_LANG'][$this->document_srl]['content']);
}
}
function isExists()
{
return (bool) ($this->document_srl);
}
function isGranted()
{
if(!$this->isExists())
{
return false;
}
if (isset($_SESSION['granted_document'][$this->document_srl]))
{
return true;
}
if ($this->grant_cache !== null)
{
return $this->grant_cache;
}
$logged_info = Context::get('logged_info');
if (!$logged_info || !$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:document'))
{
return $this->grant_cache = true;
}
return $this->grant_cache = false;
}
function setGrant()
{
$this->grant_cache = true;
}
function setGrantForSession()
{
$_SESSION['granted_document'][$this->document_srl] = true;
$this->setGrant();
}
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->document_srl]) && $_SESSION['accessible'][$this->document_srl] === $this->get('last_update'))
{
return true;
}
$status_list = DocumentModel::getStatusList();
if ($this->get('status') === $status_list['public'])
{
$this->setAccessible();
return true;
}
if ($this->isGranted())
{
$this->setAccessible();
return true;
}
return false;
}
function setAccessible()
{
if(Context::getSessionStatus())
{
$_SESSION['accessible'][$this->document_srl] = $this->get('last_update');
}
if(is_array($_SESSION['accessible']) && count($_SESSION['accessible']) > 200)
{
$_SESSION['accessible'] = array_slice($_SESSION['accessible'], 100, null, true);
}
}
function allowComment()
{
// init write, document is not exists. so allow comment status is true
if(!$this->isExists())
{
return true;
}
return (bool) ($this->get('comment_status') == 'ALLOW');
}
function allowTrackback()
{
static $allow_trackback_status = null;
if(is_null($allow_trackback_status))
{
// Check the tarckback module exist
if(!getClass('trackback'))
{
$allow_trackback_status = false;
}
else
{
// If the trackback module is configured to be disabled, do not allow. Otherwise, check the setting of each module.
$trackback_config = ModuleModel::getModuleConfig('trackback');
if(!$trackback_config)
{
$trackback_config = new stdClass();
}
if(!isset($trackback_config->enable_trackback)) $trackback_config->enable_trackback = 'Y';
if($trackback_config->enable_trackback != 'Y') $allow_trackback_status = false;
else
{
$module_srl = $this->get('module_srl');
// Check settings of each module
$module_config = ModuleModel::getModulePartConfig('trackback', $module_srl);
if($module_config->enable_trackback == 'N') $allow_trackback_status = false;
else if($this->get('allow_trackback')=='Y' || !$this->isExists()) $allow_trackback_status = true;
}
}
}
return $allow_trackback_status;
}
function isLocked()
{
if(!$this->isExists())
{
return false;
}
return (bool) ($this->get('comment_status') != 'ALLOW');
}
function isEditable()
{
return (bool) (!$this->get('member_srl') || $this->isGranted());
}
function isSecret()
{
return (bool) ($this->get('status') == DocumentModel::getConfigStatus('secret'));
}
function isNotice()
{
return (bool) ($this->get('is_notice') === 'Y' || $this->get('is_notice') === 'A');
}
function useNotify()
{
return (bool) ($this->get('notify_message') == 'Y');
}
function doCart()
{
if(!$this->isExists())
{
return false;
}
$this->isCarted() ? $this->removeCart() : $this->addCart();
}
function addCart()
{
$_SESSION['document_management'][$this->document_srl] = true;
}
function removeCart()
{
unset($_SESSION['document_management'][$this->document_srl]);
}
function isCarted()
{
return isset($_SESSION['document_management'][$this->document_srl]);
}
/**
* Send notify message to document owner
* @param string $type
* @param string $content
* @return void
*/
function notify($type, $content)
{
if(!$this->isExists())
{
return;
}
// return if it is not useNotify
if(!$this->useNotify())
{
return;
}
// Pass if an author is not a logged-in user
if(!$this->get('member_srl'))
{
return;
}
// Return if the currently logged-in user is an author
$logged_info = Context::get('logged_info');
if($logged_info->member_srl == $this->get('member_srl'))
{
return;
}
// List variables
$title = ($type ? sprintf('[%s] ', $type) : '') . cut_str(strip_tags($content), 10, '...');
$content = sprintf('%s
from : %s',$content, getFullUrl('', 'document_srl', $this->document_srl), getFullUrl('', 'document_srl', $this->document_srl));
// Send a message
$sender_member_srl = $logged_info->member_srl ?: $this->get('member_srl');
getController('communication')->sendMessage($sender_member_srl, $this->get('member_srl'), $title, $content, false, null, false);
}
function getLangCode()
{
return $this->get('lang_code');
}
function getIpAddress()
{
if($this->isGranted())
{
return $this->get('ipaddress');
}
return '*' . strstr($this->get('ipaddress') ?? '', '.');
}
function isExistsHomepage()
{
return (bool) trim($this->get('homepage') ?? '');
}
function getHomepageUrl()
{
if(!$url = trim($this->get('homepage') ?? ''))
{
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 getLastUpdater()
{
return escape($this->get('last_updater'), false);
}
function getTitleText($cut_size = 0, $tail = '...')
{
if(!$this->isExists())
{
return;
}
$title = $cut_size ? cut_str($this->get('title'), $cut_size, $tail) : $this->get('title');
return escape($title, false);
}
function getVoted()
{
return $this->getMyVote();
}
function getMyVote()
{
if(!$this->isExists())
{
return false;
}
if(isset($_SESSION['voted_document'][$this->document_srl]))
{
return $_SESSION['voted_document'][$this->document_srl];
}
$logged_info = Context::get('logged_info');
if(!$logged_info->member_srl)
{
$module_info = ModuleModel::getModuleInfoByModuleSrl($this->get('module_srl'));
if($module_info->non_login_vote !== 'Y')
{
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->document_srl = $this->document_srl;
$output = executeQuery('document.getDocumentVotedLog', $args);
if(isset($output->data) && $output->data->point)
{
return $_SESSION['voted_document'][$this->document_srl] = $output->data->point;
}
return $_SESSION['voted_document'][$this->document_srl] = false;
}
/**
* 게시글에 신고한 이력이 있는지 검사
* @return bool|int
*/
function getDeclared()
{
if(!$this->isExists())
{
return false;
}
$logged_info = Context::get('logged_info');
if(!$logged_info->member_srl)
{
return false;
}
if(isset($_SESSION['declared_document'][$this->document_srl]))
{
return $_SESSION['declared_document'][$this->document_srl];
}
$args = new stdClass();
if($logged_info->member_srl)
{
$args->member_srl = $logged_info->member_srl;
}
else
{
$args->ipaddress = \RX_CLIENT_IP;
}
$args->document_srl = $this->document_srl;
$output = executeQuery('document.getDocumentDeclaredLogInfo', $args);
$declaredCount = isset($output->data) ? intval($output->data->count) : 0;
if($declaredCount > 0)
{
return $_SESSION['declared_document'][$this->document_srl] = $declaredCount;
}
return false;
}
function getTitle($cut_size = 0, $tail = '...')
{
if(!$this->isExists())
{
return false;
}
$title = $this->getTitleText($cut_size, $tail);
$this->add('title_color', trim($this->get('title_color') ?? ''));
$attrs = array();
if($this->get('title_bold') == 'Y')
{
$attrs[] = 'font-weight:bold';
}
if($this->get('title_color') && $this->get('title_color') != 'N')
{
$attrs[] = 'color:#' . ltrim($this->get('title_color') ?? '', '#');
}
if(count($attrs))
{
return sprintf('%s', implode(';', $attrs), $title);
}
return $title;
}
function getContentPlainText($strlen = 0)
{
if(!$this->isExists())
{
return;
}
if(!$this->isAccessible())
{
return lang('msg_is_secret');
}
$content = preg_replace('!(
get('content'));
$content = trim(utf8_normalize_spaces(html_entity_decode(strip_tags($content))));
if($strlen)
{
$content = cut_str($content, $strlen, '...');
}
return escape($content);
}
function getContentText($strlen = 0)
{
if(!$this->isExists())
{
return;
}
if(!$this->isAccessible())
{
return lang('msg_is_secret');
}
$content = preg_replace('!(||
get('content'));
$content = preg_replace_callback('/<(object|param|embed)[^>]*/is', array($this, '_checkAllowScriptAccess'), $content);
$content = preg_replace_callback('/