document의 isAccessible() 개선

This commit is contained in:
conory 2017-12-12 13:21:37 +09:00
parent 6bc8376435
commit 81986c40a9

View file

@ -157,9 +157,9 @@ class documentItem extends BaseObject
function isExists() function isExists()
{ {
return $this->document_srl ? true : false; return (bool) $this->document_srl;
} }
function isGranted() function isGranted()
{ {
if ($_SESSION['granted_document'][$this->document_srl]) if ($_SESSION['granted_document'][$this->document_srl])
@ -185,17 +185,17 @@ class documentItem extends BaseObject
{ {
return $this->grant_cache = true; return $this->grant_cache = true;
} }
$oModuleModel = getModel('module'); $oModuleModel = getModel('module');
$grant = $oModuleModel->getGrant($oModuleModel->getModuleInfoByModuleSrl($this->get('module_srl')), $logged_info); $grant = $oModuleModel->getGrant($oModuleModel->getModuleInfoByModuleSrl($this->get('module_srl')), $logged_info);
if ($grant->manager) if ($grant->manager)
{ {
return $this->grant_cache = true; return $this->grant_cache = true;
} }
return $this->grant_cache = false; return $this->grant_cache = false;
} }
function setGrant() function setGrant()
{ {
$this->grant_cache = true; $this->grant_cache = true;
@ -206,52 +206,29 @@ class documentItem extends BaseObject
$_SESSION['granted_document'][$this->document_srl] = true; $_SESSION['granted_document'][$this->document_srl] = true;
$this->setGrant(); $this->setGrant();
} }
function isAccessible() function isAccessible()
{ {
if (isset($_SESSION['accessible'][$this->document_srl]) && $_SESSION['accessible'][$this->document_srl] === $this->get('last_update')) if ($_SESSION['accessible'][$this->document_srl] === $this->get('last_update'))
{ {
return true; return true;
} }
if ($this->grant_cache === true) if ($this->get('status') === $this->getConfigStatus('public') || $this->get('status') === $this->getConfigStatus('temp'))
{ {
$this->setAccessible(); $this->setAccessible();
return true; return true;
} }
$logged_info = Context::get('logged_info'); if ($this->isGranted())
if ($logged_info->is_admin == 'Y')
{ {
$this->setAccessible(); $this->setAccessible();
return true; 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; return false;
} }
function setAccessible() function setAccessible()
{ {
if(Context::getSessionStatus()) if(Context::getSessionStatus())
@ -259,13 +236,16 @@ class documentItem extends BaseObject
$_SESSION['accessible'][$this->document_srl] = $this->get('last_update'); $_SESSION['accessible'][$this->document_srl] = $this->get('last_update');
} }
} }
function allowComment() function allowComment()
{ {
// init write, document is not exists. so allow comment status is true // init write, document is not exists. so allow comment status is true
if(!$this->isExists()) return true; if(!$this->isExists())
{
return $this->get('comment_status') == 'ALLOW' ? true : false; return true;
}
return $this->get('comment_status') == 'ALLOW';
} }
function allowTrackback() function allowTrackback()
@ -307,33 +287,34 @@ class documentItem extends BaseObject
function isLocked() function isLocked()
{ {
if(!$this->isExists()) return false; if(!$this->isExists())
{
return $this->get('comment_status') == 'ALLOW' ? false : true; return false;
}
return $this->get('comment_status') != 'ALLOW';
} }
function isEditable() function isEditable()
{ {
if($this->isGranted() || !$this->get('member_srl')) return true; return !$this->get('member_srl') || $this->isGranted();
return false;
} }
function isSecret() function isSecret()
{ {
$oDocumentModel = getModel('document'); return $this->get('status') == $this->getConfigStatus('secret');
return $this->get('status') == $oDocumentModel->getConfigStatus('secret') ? true : false;
} }
function isNotice() function isNotice()
{ {
return $this->get('is_notice') == 'Y' ? true : false; return $this->get('is_notice') == 'Y';
} }
function useNotify() function useNotify()
{ {
return $this->get('notify_message')=='Y' ? true : false; return $this->get('notify_message') == 'Y';
} }
function doCart() function doCart()
{ {
if(!$this->document_srl) return false; if(!$this->document_srl) return false;
@ -394,7 +375,7 @@ class documentItem extends BaseObject
{ {
return $this->get('ipaddress'); return $this->get('ipaddress');
} }
return '*' . strstr($this->get('ipaddress'), '.'); return '*' . strstr($this->get('ipaddress'), '.');
} }
@ -496,45 +477,48 @@ class documentItem extends BaseObject
function getContentPlainText($strlen = 0) function getContentPlainText($strlen = 0)
{ {
if(!$this->document_srl) return; if(!$this->document_srl)
if($this->isSecret() && !$this->isGranted() && !$this->isAccessible()) return lang('msg_is_secret');
$result = $this->_checkAccessibleFromStatus();
if($result && Context::getSessionStatus())
{ {
$this->setAccessible(); return;
} }
if(!$this->isAccessible())
{
return lang('msg_is_secret');
}
$content = $this->get('content'); $content = $this->get('content');
$content = trim(utf8_normalize_spaces(html_entity_decode(strip_tags($content)))); $content = trim(utf8_normalize_spaces(html_entity_decode(strip_tags($content))));
if($strlen) if($strlen)
{ {
$content = cut_str($content, $strlen, '...'); $content = cut_str($content, $strlen, '...');
} }
return escape($content); return escape($content);
} }
function getContentText($strlen = 0) function getContentText($strlen = 0)
{ {
if(!$this->document_srl) return; if(!$this->document_srl)
if($this->isSecret() && !$this->isGranted() && !$this->isAccessible()) return lang('msg_is_secret');
$result = $this->_checkAccessibleFromStatus();
if($result && Context::getSessionStatus())
{ {
$this->setAccessible(); return;
} }
if(!$this->isAccessible())
{
return lang('msg_is_secret');
}
$content = $this->get('content'); $content = $this->get('content');
$content = preg_replace_callback('/<(object|param|embed)[^>]*/is', array($this, '_checkAllowScriptAccess'), $content); $content = preg_replace_callback('/<(object|param|embed)[^>]*/is', array($this, '_checkAllowScriptAccess'), $content);
$content = preg_replace_callback('/<object[^>]*>/is', array($this, '_addAllowScriptAccess'), $content); $content = preg_replace_callback('/<object[^>]*>/is', array($this, '_addAllowScriptAccess'), $content);
if($strlen) if($strlen)
{ {
$content = trim(utf8_normalize_spaces(html_entity_decode(strip_tags($content)))); $content = trim(utf8_normalize_spaces(html_entity_decode(strip_tags($content))));
$content = cut_str($content, $strlen, '...'); $content = cut_str($content, $strlen, '...');
} }
return escape($content); return escape($content);
} }
@ -583,21 +567,24 @@ class documentItem extends BaseObject
function getContent($add_popup_menu = true, $add_content_info = true, $resource_realpath = false, $add_xe_content_class = true, $stripEmbedTagException = false) function getContent($add_popup_menu = true, $add_content_info = true, $resource_realpath = false, $add_xe_content_class = true, $stripEmbedTagException = false)
{ {
if(!$this->document_srl) return; if(!$this->document_srl)
if($this->isSecret() && !$this->isGranted() && !$this->isAccessible()) return lang('msg_is_secret');
$result = $this->_checkAccessibleFromStatus();
if($result)
{ {
$this->setAccessible(); return;
} }
if(!$this->isAccessible())
{
return lang('msg_is_secret');
}
$content = $this->get('content'); $content = $this->get('content');
if(!$stripEmbedTagException) stripEmbedTagForAdmin($content, $this->get('member_srl')); if(!$stripEmbedTagException)
{
stripEmbedTagForAdmin($content, $this->get('member_srl'));
}
// Define a link if using a rewrite module // Define a link if using a rewrite module
$oContext = &Context::getInstance(); $oContext = Context::getInstance();
if($oContext->allow_rewrite) if($oContext->allow_rewrite)
{ {
$content = preg_replace('/<a([ \t]+)href=("|\')\.\/\?/i',"<a href=\\2". Context::getRequestUri() ."?", $content); $content = preg_replace('/<a([ \t]+)href=("|\')\.\/\?/i',"<a href=\\2". Context::getRequestUri() ."?", $content);
@ -627,18 +614,18 @@ class documentItem extends BaseObject
$this->document_srl, $memberSrl, $this->document_srl, $memberSrl,
$this->document_srl, $memberSrl $this->document_srl, $memberSrl
); );
// Add xe_content class although accessing content is not required
} }
else // Add xe_content class although accessing content is not required
elseif($add_xe_content_class)
{ {
if($add_xe_content_class) $content = sprintf('<div class="xe_content">%s</div>', $content); $content = sprintf('<div class="xe_content">%s</div>', $content);
} }
// Change the image path to a valid absolute path if resource_realpath is true // Change the image path to a valid absolute path if resource_realpath is true
if($resource_realpath) if($resource_realpath)
{ {
$content = preg_replace_callback('/<img([^>]+)>/i',array($this,'replaceResourceRealPath'), $content); $content = preg_replace_callback('/<img([^>]+)>/i',array($this,'replaceResourceRealPath'), $content);
} }
return $content; return $content;
} }
@ -843,12 +830,19 @@ class documentItem extends BaseObject
function getComments() function getComments()
{ {
if(!$this->getCommentCount()) return; if(!$this->getCommentCount())
if(!$this->isGranted() && $this->isSecret()) return; {
return;
}
if(!$this->isAccessible())
{
return;
}
// cpage is a number of comment pages // cpage is a number of comment pages
$cpageStr = sprintf('%d_cpage', $this->document_srl); $cpageStr = sprintf('%d_cpage', $this->document_srl);
$cpage = Context::get($cpageStr); $cpage = Context::get($cpageStr);
if(!$cpage) if(!$cpage)
{ {
$cpage = Context::get('cpage'); $cpage = Context::get('cpage');
@ -966,11 +960,11 @@ class documentItem extends BaseObject
$thumbnail_type = $config->thumbnail_type ?: 'crop'; $thumbnail_type = $config->thumbnail_type ?: 'crop';
} }
if($this->isSecret() && !$this->isGranted()) if(!$this->isAccessible())
{ {
return; return;
} }
// If not specify its height, create a square // If not specify its height, create a square
if(!$height) $height = $width; if(!$height) $height = $width;
if($this->get('content')) if($this->get('content'))
@ -1223,25 +1217,42 @@ class documentItem extends BaseObject
function hasUploadedFiles() function hasUploadedFiles()
{ {
if(!$this->document_srl) return; if(!$this->document_srl)
{
if($this->isSecret() && !$this->isGranted()) return false; return false;
}
if(!$this->isAccessible())
{
return false;
}
return $this->get('uploaded_count')? true : false; return $this->get('uploaded_count')? true : false;
} }
function getUploadedFiles($sortIndex = 'file_srl') function getUploadedFiles($sortIndex = 'file_srl')
{ {
if(!$this->document_srl) return; if(!$this->document_srl)
{
if($this->isSecret() && !$this->isGranted()) return; return;
if(!$this->get('uploaded_count')) return; }
if(!$this->isAccessible())
{
return;
}
if(!$this->get('uploaded_count'))
{
return;
}
if(!$this->uploadedFiles[$sortIndex]) if(!$this->uploadedFiles[$sortIndex])
{ {
$oFileModel = getModel('file'); $oFileModel = getModel('file');
$this->uploadedFiles[$sortIndex] = $oFileModel->getFiles($this->document_srl, array(), $sortIndex, true); $this->uploadedFiles[$sortIndex] = $oFileModel->getFiles($this->document_srl, array(), $sortIndex, true);
} }
return $this->uploadedFiles[$sortIndex]; return $this->uploadedFiles[$sortIndex];
} }
@ -1266,9 +1277,16 @@ class documentItem extends BaseObject
function isEnableComment() function isEnableComment()
{ {
// Return false if not authorized, if a secret document, if the document is set not to allow any comment // Return false if not authorized, if a secret document, if the document is set not to allow any comment
if (!$this->allowComment()) return false; if (!$this->allowComment())
if(!$this->isGranted() && $this->isSecret()) return false; {
return false;
}
if(!$this->isAccessible())
{
return false;
}
return true; return true;
} }
@ -1336,9 +1354,8 @@ class documentItem extends BaseObject
} }
/** /**
* Check accessible by document status * Compatible function
* @param array $matches * For only XE third party
* @return mixed
*/ */
function _checkAccessibleFromStatus() function _checkAccessibleFromStatus()
{ {