mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-09 03:32:00 +09:00
Fix #632 inconsistent application of view count option
This commit is contained in:
parent
4d22112582
commit
b0ad6b3027
3 changed files with 56 additions and 41 deletions
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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__'];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue