코드 정리

This commit is contained in:
conory 2017-12-13 21:10:46 +09:00
parent 48c818d7de
commit f93ad9c0f6
5 changed files with 163 additions and 102 deletions

View file

@ -233,7 +233,7 @@ if($called_position == 'before_module_proc')
{ {
$oDocumentModel = getModel('document'); $oDocumentModel = getModel('document');
$oDocument = $oDocumentModel->getDocument($document_srl); $oDocument = $oDocumentModel->getDocument($document_srl);
if(!$oDocument->isExists() || !$oDocument->isGranted()) if(!$oDocument->isGranted())
{ {
printContent(getXmlRpcFailure(1, 'no permission')); printContent(getXmlRpcFailure(1, 'no permission'));
} }

View file

@ -782,7 +782,7 @@ class boardView extends board
// if the document is not granted, then back to the password input form // if the document is not granted, then back to the password input form
$oModuleModel = getModel('module'); $oModuleModel = getModel('module');
if($oDocument->isExists()&&!$oDocument->isGranted()) if($oDocument->isExists() && !$oDocument->isGranted())
{ {
return $this->setTemplateFile('input_password_form'); return $this->setTemplateFile('input_password_form');
} }

View file

@ -1257,7 +1257,7 @@ class commentController extends comment
$oDocument = $oDocumentModel->getDocument($document_srl); $oDocument = $oDocumentModel->getDocument($document_srl);
} }
if(!$oDocument->isExists() || !$oDocument->isGranted()) if(!$oDocument->isGranted())
{ {
return new BaseObject(-1, 'msg_not_permitted'); return new BaseObject(-1, 'msg_not_permitted');
} }

View file

@ -92,14 +92,19 @@ class commentItem extends BaseObject
function isExists() function isExists()
{ {
return (bool) $this->comment_srl; return (bool) ($this->comment_srl);
} }
function isGranted() function isGranted()
{ {
if ($_SESSION['granted_comment'][$this->comment_srl]) if(!$this->isExists())
{ {
return $this->grant_cache = true; return false;
}
if (isset($_SESSION['granted_comment'][$this->comment_srl]))
{
return true;
} }
if ($this->grant_cache !== null) if ($this->grant_cache !== null)
@ -144,7 +149,12 @@ class commentItem extends BaseObject
function isAccessible() function isAccessible()
{ {
if ($_SESSION['accessible'][$this->comment_srl] === $this->get('last_update')) if(!$this->isExists())
{
return false;
}
if (isset($_SESSION['accessible'][$this->comment_srl]) && $_SESSION['accessible'][$this->comment_srl] === $this->get('last_update'))
{ {
return true; return true;
} }
@ -162,7 +172,7 @@ class commentItem extends BaseObject
} }
$oDocument = getModel('document')->getDocument($this->get('document_srl')); $oDocument = getModel('document')->getDocument($this->get('document_srl'));
if ($oDocument->isExists() && $oDocument->isGranted()) if ($oDocument->isGranted())
{ {
$this->setAccessible(); $this->setAccessible();
return true; return true;
@ -515,25 +525,26 @@ class commentItem extends BaseObject
function hasUploadedFiles() function hasUploadedFiles()
{ {
if(($this->isSecret() && !$this->isAccessible()) && !$this->isGranted()) if(!$this->isAccessible())
{ {
return FALSE; return false;
} }
return $this->get('uploaded_count') ? TRUE : FALSE; return $this->get('uploaded_count') ? TRUE : FALSE;
} }
function getUploadedFiles() function getUploadedFiles()
{ {
if(($this->isSecret() && !$this->isAccessible()) && !$this->isGranted()) if(!$this->isAccessible())
{ {
return; return;
} }
if(!$this->get('uploaded_count')) if(!$this->get('uploaded_count'))
{ {
return; return;
} }
$oFileModel = getModel('file'); $oFileModel = getModel('file');
$file_list = $oFileModel->getFiles($this->comment_srl, array(), 'file_srl', TRUE); $file_list = $oFileModel->getFiles($this->comment_srl, array(), 'file_srl', TRUE);
return $file_list; return $file_list;
@ -646,11 +657,11 @@ class commentItem 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 signiture height setting is omitted, create a square // If signiture height setting is omitted, create a square
if(!$height) if(!$height)
{ {

View file

@ -62,7 +62,6 @@ class documentItem extends BaseObject
{ {
$this->document_srl = $document_srl; $this->document_srl = $document_srl;
$this->columnList = $columnList; $this->columnList = $columnList;
$this->_loadFromDB($load_extra_vars); $this->_loadFromDB($load_extra_vars);
} }
@ -79,10 +78,12 @@ class documentItem extends BaseObject
*/ */
function _loadFromDB($load_extra_vars = true) function _loadFromDB($load_extra_vars = true)
{ {
if(!$this->document_srl) return; if(!$this->document_srl)
{
return;
}
$document_item = false; $document_item = false;
$cache_put = false;
$columnList = array(); $columnList = array();
$reload_counts = true; $reload_counts = true;
@ -127,17 +128,18 @@ class documentItem extends BaseObject
$this->setAttribute($document_item, $load_extra_vars); $this->setAttribute($document_item, $load_extra_vars);
} }
function setAttribute($attribute, $load_extra_vars=true) function setAttribute($attribute, $load_extra_vars = true)
{ {
if(!$attribute->document_srl) if(!$attribute->document_srl)
{ {
$this->document_srl = null; $this->document_srl = null;
return; return;
} }
$this->document_srl = $attribute->document_srl; $this->document_srl = $attribute->document_srl;
$this->lang_code = $attribute->lang_code; $this->lang_code = $attribute->lang_code;
$this->adds($attribute); $this->adds($attribute);
// Tags // Tags
if($this->get('tags')) if($this->get('tags'))
{ {
@ -145,26 +147,30 @@ class documentItem extends BaseObject
$tag_list = array_map('utf8_trim', $tag_list); $tag_list = array_map('utf8_trim', $tag_list);
$this->add('tag_list', $tag_list); $this->add('tag_list', $tag_list);
} }
$oDocumentModel = getModel('document');
if($load_extra_vars) if($load_extra_vars)
{ {
$GLOBALS['XE_DOCUMENT_LIST'][$attribute->document_srl] = $this; getModel('document')->setToAllDocumentExtraVars();
$oDocumentModel->setToAllDocumentExtraVars();
} }
$GLOBALS['XE_DOCUMENT_LIST'][$this->document_srl] = $this; $GLOBALS['XE_DOCUMENT_LIST'][$this->document_srl] = $this;
} }
function isExists() function isExists()
{ {
return (bool) $this->document_srl; return (bool) ($this->document_srl);
} }
function isGranted() function isGranted()
{ {
if ($_SESSION['granted_document'][$this->document_srl]) if(!$this->isExists())
{ {
return $this->grant_cache = true; return false;
}
if (isset($_SESSION['granted_document'][$this->document_srl]))
{
return true;
} }
if ($this->grant_cache !== null) if ($this->grant_cache !== null)
@ -209,13 +215,18 @@ class documentItem extends BaseObject
function isAccessible() function isAccessible()
{ {
if ($_SESSION['accessible'][$this->document_srl] === $this->get('last_update')) if(!$this->isExists())
{
return false;
}
if (isset($_SESSION['accessible'][$this->document_srl]) && $_SESSION['accessible'][$this->document_srl] === $this->get('last_update'))
{ {
return true; return true;
} }
$status_list = getModel('document')->getStatusList(); $status_list = getModel('document')->getStatusList();
if ($this->get('status') === $status_list['public'] || $this->get('status') === $status_list['temp']) if ($this->get('status') === $status_list['public'])
{ {
$this->setAccessible(); $this->setAccessible();
return true; return true;
@ -246,7 +257,7 @@ class documentItem extends BaseObject
return true; return true;
} }
return $this->get('comment_status') == 'ALLOW'; return (bool) ($this->get('comment_status') == 'ALLOW');
} }
function allowTrackback() function allowTrackback()
@ -293,34 +304,37 @@ class documentItem extends BaseObject
return false; return false;
} }
return $this->get('comment_status') != 'ALLOW'; return (bool) ($this->get('comment_status') != 'ALLOW');
} }
function isEditable() function isEditable()
{ {
return !$this->get('member_srl') || $this->isGranted(); return (bool) (!$this->get('member_srl') || $this->isGranted());
} }
function isSecret() function isSecret()
{ {
return $this->get('status') == getModel('document')->getConfigStatus('secret'); return (bool) ($this->get('status') == getModel('document')->getConfigStatus('secret'));
} }
function isNotice() function isNotice()
{ {
return $this->get('is_notice') == 'Y'; return (bool) ($this->get('is_notice') == 'Y');
} }
function useNotify() function useNotify()
{ {
return $this->get('notify_message') == 'Y'; return (bool) ($this->get('notify_message') == 'Y');
} }
function doCart() function doCart()
{ {
if(!$this->document_srl) return false; if(!$this->isExists())
if($this->isCarted()) $this->removeCart(); {
else $this->addCart(); return false;
}
$this->isCarted() ? $this->removeCart() : $this->addCart();
} }
function addCart() function addCart()
@ -335,7 +349,7 @@ class documentItem extends BaseObject
function isCarted() function isCarted()
{ {
return $_SESSION['document_management'][$this->document_srl]; return isset($_SESSION['document_management'][$this->document_srl]);
} }
/** /**
@ -346,23 +360,35 @@ class documentItem extends BaseObject
*/ */
function notify($type, $content) function notify($type, $content)
{ {
if(!$this->document_srl) return; if(!$this->isExists())
{
return;
}
// return if it is not useNotify // return if it is not useNotify
if(!$this->useNotify()) return; if(!$this->useNotify())
{
return;
}
// Pass if an author is not a logged-in user // Pass if an author is not a logged-in user
if(!$this->get('member_srl')) return; if(!$this->get('member_srl'))
{
return;
}
// Return if the currently logged-in user is an author // Return if the currently logged-in user is an author
$logged_info = Context::get('logged_info'); $logged_info = Context::get('logged_info');
if($logged_info->member_srl == $this->get('member_srl')) return; if($logged_info->member_srl == $this->get('member_srl'))
{
return;
}
// List variables // List variables
if($type) $title = "[".$type."] "; $title = ($type ? sprintf('[%s] ', $type) : '') . cut_str(strip_tags($content), 10, '...');
$title .= cut_str(strip_tags($content), 10, '...'); $content = sprintf('%s<br><br>from : <a href="%s" target="_blank">%s</a>',$content, getFullUrl('', 'document_srl', $this->document_srl), getFullUrl('', 'document_srl', $this->document_srl));
$content = sprintf('%s<br /><br />from : <a href="%s" target="_blank">%s</a>',$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 // Send a message
$oCommunicationController = getController('communication'); $sender_member_srl = $logged_info->member_srl ?: $this->get('member_srl');
$oCommunicationController->sendMessage($sender_member_srl, $receiver_srl, $title, $content, false); getController('communication')->sendMessage($sender_member_srl, $this->get('member_srl'), $title, $content, false);
} }
function getLangCode() function getLangCode()
@ -382,17 +408,21 @@ class documentItem extends BaseObject
function isExistsHomepage() function isExistsHomepage()
{ {
if(trim($this->get('homepage'))) return true; return (bool) trim($this->get('homepage'));
return false;
} }
function getHomepageUrl() function getHomepageUrl()
{ {
$url = trim($this->get('homepage')); if(!$url = trim($this->get('homepage')))
if(!$url) return; {
return;
if(strncasecmp('http://', $url, 7) !== 0 && strncasecmp('https://', $url, 8) !== 0) $url = 'http://' . $url; }
if(!preg_match('@^[a-z]+://@i', $url))
{
$url = 'http://' . $url;
}
return $url; return $url;
} }
@ -403,82 +433,94 @@ class documentItem extends BaseObject
function getUserID() function getUserID()
{ {
return htmlspecialchars($this->get('user_id'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); return escape($this->get('user_id'), false);
} }
function getUserName() function getUserName()
{ {
return htmlspecialchars($this->get('user_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); return escape($this->get('user_name'), false);
} }
function getNickName() function getNickName()
{ {
return htmlspecialchars($this->get('nick_name'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); return escape($this->get('nick_name'), false);
} }
function getLastUpdater() function getLastUpdater()
{ {
return htmlspecialchars($this->get('last_updater'), ENT_COMPAT | ENT_HTML401, 'UTF-8', false); return escape($this->get('last_updater'), false);
} }
function getTitleText($cut_size = 0, $tail='...') function getTitleText($cut_size = 0, $tail = '...')
{ {
if(!$this->document_srl) return; if(!$this->isExists())
{
if($cut_size) $title = cut_str($this->get('title'), $cut_size, $tail); return;
else $title = $this->get('title'); }
return $title; return $cut_size ? cut_str($this->get('title'), $cut_size, $tail) : $this->get('title');
} }
function getVoted() function getVoted()
{ {
if(!$this->document_srl) return false; if(!$this->isExists())
{
return false;
}
$logged_info = Context::get('logged_info');
if(!$logged_info->member_srl)
{
return false;
}
if(isset($_SESSION['voted_document'][$this->document_srl])) if(isset($_SESSION['voted_document'][$this->document_srl]))
{ {
return $_SESSION['voted_document'][$this->document_srl]; return $_SESSION['voted_document'][$this->document_srl];
} }
$logged_info = Context::get('logged_info'); $args = new stdClass;
if(!$logged_info->member_srl) return false;
$args = new stdClass();
$args->member_srl = $logged_info->member_srl; $args->member_srl = $logged_info->member_srl;
$args->document_srl = $this->document_srl; $args->document_srl = $this->document_srl;
$output = executeQuery('document.getDocumentVotedLog', $args); $output = executeQuery('document.getDocumentVotedLog', $args);
if($output->data->point) if($output->data->point)
{ {
return $_SESSION['voted_document'][$this->document_srl] = $output->data->point; return $_SESSION['voted_document'][$this->document_srl] = $output->data->point;
} }
return $_SESSION['voted_document'][$this->document_srl] = false; return $_SESSION['voted_document'][$this->document_srl] = false;
} }
function getTitle($cut_size = 0, $tail='...') function getTitle($cut_size = 0, $tail = '...')
{ {
if(!$this->document_srl) return; if(!$this->isExists())
{
$title = $this->getTitleText($cut_size, $tail); return false;
}
$attrs = array();
$title = escape($this->getTitleText($cut_size, $tail), false);
$this->add('title_color', trim($this->get('title_color'))); $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:#".ltrim($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)) if(count($attrs))
{ {
return sprintf("<span style=\"%s\">%s</span>", implode(';', $attrs), escape($title, false)); return sprintf('<span style="%s">%s</span>', implode(';', $attrs), $title);
}
else
{
return escape($title, false);
} }
return $title;
} }
function getContentPlainText($strlen = 0) function getContentPlainText($strlen = 0)
{ {
if(!$this->document_srl) if(!$this->isExists())
{ {
return; return;
} }
@ -500,7 +542,7 @@ class documentItem extends BaseObject
function getContentText($strlen = 0) function getContentText($strlen = 0)
{ {
if(!$this->document_srl) if(!$this->isExists())
{ {
return; return;
} }
@ -568,7 +610,7 @@ 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) if(!$this->isExists())
{ {
return; return;
} }
@ -640,11 +682,14 @@ class documentItem extends BaseObject
*/ */
function getTransContent($add_popup_menu = true, $add_content_info = true, $resource_realpath = false, $add_xe_content_class = true) function getTransContent($add_popup_menu = true, $add_content_info = true, $resource_realpath = false, $add_xe_content_class = true)
{ {
$oEditorController = getController('editor'); if(!$this->isExists())
{
return;
}
$content = $this->getContent($add_popup_menu, $add_content_info, $resource_realpath, $add_xe_content_class); $content = $this->getContent($add_popup_menu, $add_content_info, $resource_realpath, $add_xe_content_class);
$content = $oEditorController->transComponent($content); $content = getController('editor')->transComponent($content);
return $content; return $content;
} }
@ -712,11 +757,16 @@ class documentItem extends BaseObject
function getTrackbackUrl() function getTrackbackUrl()
{ {
if(!$this->document_srl) return; if(!$this->isExists())
{
return;
}
// Generate a key to prevent spams // Generate a key to prevent spams
$oTrackbackModel = getModel('trackback'); if($oTrackbackModel = getModel('trackback'))
if($oTrackbackModel) return $oTrackbackModel->getTrackbackUrl($this->document_srl, $this->getDocumentMid()); {
return $oTrackbackModel->getTrackbackUrl($this->document_srl, $this->getDocumentMid());
}
} }
/** /**