From 76f33766702765b2516885dace35a1973aa6a0a8 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 20 Apr 2021 22:38:42 +0900 Subject: [PATCH] Add getStatus() and getStatusText() methods to document and comment for easy management --- common/constants.php | 1 + modules/comment/comment.item.php | 44 ++++++++++++++++++++++++- modules/comment/lang/en.php | 2 ++ modules/document/document.class.php | 20 +++++++++-- modules/document/document.item.php | 28 ++++++++++++++-- modules/document/lang/en.php | 7 ++++ modules/document/lang/ko.php | 7 ++++ modules/document/tpl/document_list.html | 2 +- 8 files changed, 105 insertions(+), 6 deletions(-) diff --git a/common/constants.php b/common/constants.php index 5ec176634..10598904e 100644 --- a/common/constants.php +++ b/common/constants.php @@ -144,6 +144,7 @@ define('_XE_PATH_', RX_BASEDIR); * Status constants for various content types. */ define('RX_STATUS_TEMP', 0); +define('RX_STATUS_PRIVATE', 10); define('RX_STATUS_PUBLIC', 1); define('RX_STATUS_SECRET', 2); define('RX_STATUS_EMBARGO', 3); diff --git a/modules/comment/comment.item.php b/modules/comment/comment.item.php index 4b538d5a4..aaa37f9fd 100644 --- a/modules/comment/comment.item.php +++ b/modules/comment/comment.item.php @@ -146,6 +146,48 @@ class commentItem extends BaseObject $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() { if(!$this->isExists()) @@ -195,7 +237,7 @@ class commentItem extends BaseObject function isSecret() { - return $this->get('is_secret') == 'Y'; + return $this->get('status') == RX_STATUS_SECRET || $this->get('is_secret') == 'Y'; } function isDeleted() diff --git a/modules/comment/lang/en.php b/modules/comment/lang/en.php index cab0e7db8..1b2b14b20 100644 --- a/modules/comment/lang/en.php +++ b/modules/comment/lang/en.php @@ -63,6 +63,8 @@ $lang->improper_comment_reasons['pornography'] = 'Pornography.'; $lang->improper_comment_reasons['privacy'] = 'Privacy issue.'; $lang->improper_comment_reasons['others'] = 'Others (Write your own)'; $lang->about_improper_comment_declare = 'Write here why you report this comment as an improper thing.'; +$lang->msg_censored_comment = 'This comment has been hidden.'; +$lang->msg_admin_censored_comment = 'This comment has been hidden by an administrator.'; $lang->msg_deleted_comment = 'This comment has been deleted.'; $lang->msg_admin_deleted_comment = 'This comment has been deleted by an administrator.'; $lang->msg_no_text_comment = 'This comment contains no text.'; diff --git a/modules/document/document.class.php b/modules/document/document.class.php index 6e56b22f2..dbd653886 100644 --- a/modules/document/document.class.php +++ b/modules/document/document.class.php @@ -19,10 +19,26 @@ class document extends ModuleObject public $search_option = array('title', 'content', 'title_content', 'user_name'); /** - * Status list + * List of status texts supported by Rhymix. + * + * Also see status constants in common/constants.php + * and integer status codes used in the comment module. + * * @var array */ - public static $statusList = array('private' => 'PRIVATE', 'public' => 'PUBLIC', 'secret' => 'SECRET', 'temp' => 'TEMP'); + public static $statusList = array( + 'temp' => 'TEMP', + 'private' => 'PRIVATE', + 'public' => 'PUBLIC', + 'secret' => 'SECRET', + 'embargo' => 'EMBARGO', + 'trash' => 'TRASH', + 'censored' => 'CENSORED', + 'censored_by_admin' => 'CENSORED_BY_ADMIN', + 'deleted' => 'DELETED', + 'deleted_by_admin' => 'DELETED_BY_ADMIN', + 'other' => 'OTHER', + ); /** * Implement if additional tasks are necessary when installing diff --git a/modules/document/document.item.php b/modules/document/document.item.php index dd53bb477..693af7d66 100644 --- a/modules/document/document.item.php +++ b/modules/document/document.item.php @@ -1308,10 +1308,34 @@ class documentItem extends BaseObject return $buffs; } + /** + * Return the status code. + * + * @return string + */ function getStatus() { - if(!$this->get('status')) return getClass('document')->getDefaultStatus(); - return $this->get('status'); + $status = $this->get('status'); + return $status ?: Document::getDefaultStatus(); + } + + /** + * Return the status in human-readable text. + * + * @return string + */ + function getStatusText() + { + $status = $this->get('status'); + $statusList = lang('document.status_name_list'); + if ($status && isset($statusList[$status])) + { + return $statusList[$status]; + } + else + { + return $statusList[Document::getDefaultStatus()]; + } } /** diff --git a/modules/document/lang/en.php b/modules/document/lang/en.php index c624f5015..6a9b2a3b5 100644 --- a/modules/document/lang/en.php +++ b/modules/document/lang/en.php @@ -79,6 +79,13 @@ $lang->status_name_list['PRIVATE'] = 'Private'; $lang->status_name_list['PUBLIC'] = 'Public'; $lang->status_name_list['SECRET'] = 'Secret'; $lang->status_name_list['TEMP'] = 'Temporary'; +$lang->status_name_list['TRASH'] = 'Trash'; +$lang->status_name_list['EMBARGO'] = 'Embargo'; +$lang->status_name_list['CENSORED'] = 'Hidden'; +$lang->status_name_list['CENSORED_BY_ADMIN'] = 'Hidden by Admin'; +$lang->status_name_list['DELETED'] = 'Deleted'; +$lang->status_name_list['DELETED_BY_ADMIN'] = 'Deleted by Admin'; +$lang->status_name_list['OTHER'] = 'Other'; $lang->document_manager = 'Manage selected articles'; $lang->selected_document = 'Selected articles'; $lang->selected_document_move = 'You can move or copy the selected articles to the following position.'; diff --git a/modules/document/lang/ko.php b/modules/document/lang/ko.php index d6967ac0b..2b844e6da 100644 --- a/modules/document/lang/ko.php +++ b/modules/document/lang/ko.php @@ -78,6 +78,13 @@ $lang->status_name_list['PRIVATE'] = '비공개'; $lang->status_name_list['PUBLIC'] = '공개'; $lang->status_name_list['SECRET'] = '비밀'; $lang->status_name_list['TEMP'] = '임시'; +$lang->status_name_list['TRASH'] = '휴지통'; +$lang->status_name_list['EMBARGO'] = '엠바고'; +$lang->status_name_list['CENSORED'] = '블라인드'; +$lang->status_name_list['CENSORED_BY_ADMIN'] = '관리자 블라인드'; +$lang->status_name_list['DELETED'] = '삭제'; +$lang->status_name_list['DELETED_BY_ADMIN'] = '관리자 삭제'; +$lang->status_name_list['OTHER'] = '기타'; $lang->document_manager = '선택한 글 관리'; $lang->selected_document = '선택한 글'; $lang->selected_document_move = '선택한 글을 다음 위치로 옮기거나 복사할 수 있습니다.'; diff --git a/modules/document/tpl/document_list.html b/modules/document/tpl/document_list.html index 22729f4d4..aadbe5380 100644 --- a/modules/document/tpl/document_list.html +++ b/modules/document/tpl/document_list.html @@ -68,7 +68,7 @@ xe.lang.msg_empty_search_keyword = '{$lang->msg_empty_search_keyword}'; {$oDocument->getRegdate($oDocument->getRegdateTime() > time() - 86400 ? 'H:i' : 'm-d')} {$oDocument->get('ipaddress')} - {$status_name_list[$oDocument->get('status')]} + {$oDocument->getStatusText()}