*/
/**
* documentItem class
* document object
*
* @author NAVER (developers@xpressengine.com)
* @package /modules/document
* @version 0.1
*/
class documentItem extends Object
{
/**
* 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;
/**
* 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();
/**
* 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;
$cache_put = 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(!$attribute->document_srl)
{
$this->document_srl = null;
return;
}
$this->document_srl = $attribute->document_srl;
$this->lang_code = $attribute->lang_code;
$this->adds($attribute);
// Tags
if($this->get('tags'))
{
$tag_list = explode(',', $this->get('tags'));
$tag_list = array_map('utf8_trim', $tag_list);
$this->add('tag_list', $tag_list);
}
$oDocumentModel = getModel('document');
if($load_extra_vars)
{
$GLOBALS['XE_DOCUMENT_LIST'][$attribute->document_srl] = $this;
$oDocumentModel->setToAllDocumentExtraVars();
}
$GLOBALS['XE_DOCUMENT_LIST'][$this->document_srl] = $this;
}
function isExists()
{
return $this->document_srl ? true : false;
}
function isGranted()
{
if ($_SESSION['granted_document'][$this->document_srl])
{
return $this->grant_cache = 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;
}
$oModuleModel = getModel('module');
$grant = $oModuleModel->getGrant($oModuleModel->getModuleInfoByModuleSrl($this->get('module_srl')), $logged_info);
if ($grant->manager)
{
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()
{
if (isset($_SESSION['accessible'][$this->document_srl]) && $_SESSION['accessible'][$this->document_srl] === $this->get('last_update'))
{
return true;
}
if ($this->grant_cache === true)
{
$this->setAccessible();
return true;
}
$logged_info = Context::get('logged_info');
if ($logged_info->is_admin == 'Y')
{
$this->setAccessible();
return true;
}
$status = $this->get('status');
if (empty($status))
{
return false;
}
$configStatusList = getModel('document')->getStatusList();
if ($status == $configStatusList['public'] || $status == $configStatusList['publish'])
{
$this->setAccessible();
return true;
}
elseif ($status == $configStatusList['private'] || $status == $configStatusList['secret'])
{
if ($this->get('member_srl') == $logged_info->member_srl)
{
$this->setAccessible();
return true;
}
}
return false;
}
function setAccessible()
{
if(Context::getSessionStatus())
{
$_SESSION['accessible'][$this->document_srl] = $this->get('last_update');
}
}
function allowComment()
{
// init write, document is not exists. so allow comment status is true
if(!$this->isExists()) return true;
return $this->get('comment_status') == 'ALLOW' ? true : false;
}
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.
$oModuleModel = getModel('module');
$trackback_config = $oModuleModel->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 = $oModuleModel->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 $this->get('comment_status') == 'ALLOW' ? false : true;
}
function isEditable()
{
if($this->isGranted() || !$this->get('member_srl')) return true;
return false;
}
function isSecret()
{
$oDocumentModel = getModel('document');
return $this->get('status') == $oDocumentModel->getConfigStatus('secret') ? true : false;
}
function isNotice()
{
return $this->get('is_notice') == 'Y' ? true : false;
}
function useNotify()
{
return $this->get('notify_message')=='Y' ? true : false;
}
function doCart()
{
if(!$this->document_srl) return false;
if($this->isCarted()) $this->removeCart();
else $this->addCart();
}
function addCart()
{
$_SESSION['document_management'][$this->document_srl] = true;
}
function removeCart()
{
unset($_SESSION['document_management'][$this->document_srl]);
}
function isCarted()
{
return $_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->document_srl) 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
if($type) $title = "[".$type."] ";
$title .= cut_str(strip_tags($content), 10, '...');
$content = sprintf('%s
from : %s',$content, getFullUrl('','document_srl',$this->document_srl), getFullUrl('','document_srl',$this->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);
}
function getLangCode()
{
return $this->get('lang_code');
}
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(strncasecmp('http://', $url, 7) !== 0 && strncasecmp('https://', $url, 8) !== 0) $url = 'http://' . $url;
return $url;
}
function getMemberSrl()
{
return $this->get('member_srl');
}
function getUserID()
{
return htmlspecialchars($this->get('user_id'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
}
function getUserName()
{
return htmlspecialchars($this->get('user_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
}
function getNickName()
{
return htmlspecialchars($this->get('nick_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
}
function getLastUpdater()
{
return htmlspecialchars($this->get('last_updater'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
}
function getTitleText($cut_size = 0, $tail='...')
{
if(!$this->document_srl) return;
if($cut_size) $title = cut_str($this->get('title'), $cut_size, $tail);
else $title = $this->get('title');
return $title;
}
function getVoted()
{
if(!$this->document_srl) 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) return false;
$args = new stdClass();
$args->member_srl = $logged_info->member_srl;
$args->document_srl = $this->document_srl;
$output = executeQuery('document.getDocumentVotedLog', $args);
if($output->data->point)
{
return $_SESSION['voted_document'][$this->document_srl] = $output->data->point;
}
return $_SESSION['voted_document'][$this->document_srl] = false;
}
function getTitle($cut_size = 0, $tail='...')
{
if(!$this->document_srl) return;
$title = $this->getTitleText($cut_size, $tail);
$attrs = array();
$this->add('title_color', trim($this->get('title_color')));
if($this->get('title_bold')=='Y') $attrs[] = "font-weight:bold;";
if($this->get('title_color') && $this->get('title_color') != 'N') $attrs[] = "color:#".$this->get('title_color');
if(count($attrs))
{
return sprintf("%s", implode(';', $attrs), escape($title, false));
}
else
{
return escape($title, false);
}
}
function getContentPlainText($strlen = 0)
{
if(!$this->document_srl) return;
if($this->isSecret() && !$this->isGranted() && !$this->isAccessible()) return lang('msg_is_secret');
$result = $this->_checkAccessibleFromStatus();
if($result && Context::getSessionStatus())
{
$this->setAccessible();
}
$content = $this->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->document_srl) return;
if($this->isSecret() && !$this->isGranted() && !$this->isAccessible()) return lang('msg_is_secret');
$result = $this->_checkAccessibleFromStatus();
if($result && Context::getSessionStatus())
{
$this->setAccessible();
}
$content = $this->get('content');
$content = preg_replace_callback('/<(object|param|embed)[^>]*/is', array($this, '_checkAllowScriptAccess'), $content);
$content = preg_replace_callback('/