From b0ad6b302789ffd7274196bd85b2d37c3f406dbd Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 8 Nov 2016 22:17:31 +0900 Subject: [PATCH] Fix #632 inconsistent application of view count option --- modules/admin/admin.admin.controller.php | 7 +- modules/document/document.controller.php | 89 ++++++++++++++---------- modules/document/document.model.php | 1 - 3 files changed, 56 insertions(+), 41 deletions(-) diff --git a/modules/admin/admin.admin.controller.php b/modules/admin/admin.admin.controller.php index b682caea9..2696fc87f 100644 --- a/modules/admin/admin.admin.controller.php +++ b/modules/admin/admin.admin.controller.php @@ -700,10 +700,11 @@ class adminAdminController extends admin } // Thumbnail settings - $args = new stdClass; - $args->thumbnail_type = $vars->thumbnail_type === 'ratio' ? 'ratio' : 'crop'; + $oDocumentModel = getModel('document'); + $document_config = $oDocumentModel->getDocumentConfig(); + $document_config->thumbnail_type = $vars->thumbnail_type === 'ratio' ? 'ratio' : 'crop'; $oModuleController = getController('module'); - $oModuleController->insertModuleConfig('document', $args); + $oModuleController->insertModuleConfig('document', $document_config); // Other settings Rhymix\Framework\Config::set('use_rewrite', $vars->use_rewrite === 'Y'); diff --git a/modules/document/document.controller.php b/modules/document/document.controller.php index e5af1370e..8b2ae1116 100644 --- a/modules/document/document.controller.php +++ b/modules/document/document.controller.php @@ -1052,63 +1052,78 @@ class documentController extends document return false; } + // Get the view count option, and use the default if the value is empty or invalid. + $valid_options = array( + 'all' => true, + 'some' => true, + 'once' => true, + 'none' => true, + ); + $oDocumentModel = getModel('document'); $config = $oDocumentModel->getDocumentConfig(); + if (!$config->view_count_option || !isset($valid_options[$config->view_count_option])) + { + $config->view_count_option = 'once'; + } - if($config->view_count_option == 'none') return false; - + // If not counting, return now. + if ($config->view_count_option == 'none') + { + return false; + } + + // Get document and user information. $document_srl = $oDocument->document_srl; $member_srl = $oDocument->get('member_srl'); $logged_info = Context::get('logged_info'); + + // Option 'some': only count once per session. + if ($config->view_count_option != 'all' && $_SESSION['readed_document'][$document_srl]) + { + if (Context::getSessionStatus()) + { + $_SESSION['readed_document'][$document_srl] = true; + } + return false; + } + + // Option 'once': check member_srl and IP address. + if ($config->view_count_option == 'once') + { + // Pass if the author's IP address is as same as visitor's. + if($oDocument->get('ipaddress') == $_SERVER['REMOTE_ADDR']) + { + if (Context::getSessionStatus()) + { + $_SESSION['readed_document'][$document_srl] = true; + } + return false; + } + + // Pass if the author's member_srl is the same as the visitor's. + if($member_srl && $logged_info->member_srl && $logged_info->member_srl == $member_srl) + { + $_SESSION['readed_document'][$document_srl] = true; + return false; + } + } // Call a trigger when the read count is updated (before) $trigger_output = ModuleHandler::triggerCall('document.updateReadedCount', 'before', $oDocument); if(!$trigger_output->toBool()) return $trigger_output; - - // Pass if read count is increaded on the session information - if($_SESSION['readed_document'][$document_srl] && $config->view_count_option == 'once') - { - return false; - } - else if($config->view_count_option == 'some') - { - if($_SESSION['readed_document'][$document_srl]) - { - return false; - } - } - - if($config->view_count_option == 'once') - { - // Pass if the author's IP address is as same as visitor's. - if($oDocument->get('ipaddress') == $_SERVER['REMOTE_ADDR'] && Context::getSessionStatus()) - { - $_SESSION['readed_document'][$document_srl] = true; - return false; - } - // Pass ater registering sesscion if the author is a member and has same information as the currently logged-in user. - if($member_srl && $logged_info->member_srl == $member_srl) - { - $_SESSION['readed_document'][$document_srl] = true; - return false; - } - } + + // Update read counts $oDB = DB::getInstance(); $oDB->begin(); - - // Update read counts $args = new stdClass; $args->document_srl = $document_srl; executeQuery('document.updateReadedCount', $args); // Call a trigger when the read count is updated (after) ModuleHandler::triggerCall('document.updateReadedCount', 'after', $oDocument); - $oDB->commit(); - //remove document item from cache - Rhymix\Framework\Cache::delete('document_item:' . getNumberingPath($document_srl) . $document_srl); - // Register session if(!$_SESSION['banned_document'][$document_srl] && Context::getSessionStatus()) { diff --git a/modules/document/document.model.php b/modules/document/document.model.php index 77756ab14..2d9a8857b 100644 --- a/modules/document/document.model.php +++ b/modules/document/document.model.php @@ -928,7 +928,6 @@ class documentModel extends document $config = $oModuleModel->getModuleConfig('document'); if(!$config) $config = new stdClass(); - if(!$config->view_count_option) $config->view_count_option = 'once'; $GLOBALS['__document_config__'] = $config; } return $GLOBALS['__document_config__'];