global $user_info, $modSettings;
$actCounter = false; // boolean : true = different counter for each action, false = same counter for every action
$buttonName = !empty($actCounter) ? 'Page Views' : 'Visitors';
// allow a reset option for speicific users -> use array(0) for all admins, user id# for specific admin [ ie. array(1) ] or multiple user id#'s for specific users [ ie. array (1,3,8) ]
// requires $adminReset to be true else it will be ignored
$adminId = array(1);
$adminReset = true;
if (empty($user_info['is_guest']) && !empty($adminReset)) {
$allowReset = empty($adminId[0]) && !empty($user_info['is_admin']) ? true : (in_array($user_info['id'], $adminId) ? true : false);
}
list($title, $title2, $cursor, $ask, $ask2, $ask3, $visitCount, $data) = !empty($adminReset) && !empty($allowReset) ?
array('Click to reset the counter', 'Click to reset the current action counter', 'help', 'Reset the page visit counter?', 'Reset the page visit counter for this action?', 'Reset the page visit counter for all actions?', array(), array()) :
array('Page views', '', 'crosshair', '', '', '', array(), array());
// don't bother changing code below this comment
$allAction = !empty($_REQUEST['visitorReset']) && is_string($_REQUEST['visitorReset']) && $_REQUEST['visitorReset'] == 'all' ? true : false;
$action = !empty($_REQUEST['action']) && !empty($actCounter) && is_string($_REQUEST['action']) ? strtolower($_REQUEST['action']) . '_count' : 'visitor_count';
$reset = !empty($_REQUEST['visitorReset']) && is_string($_REQUEST['visitorReset']) && $_REQUEST['visitorReset'] == $action && !empty($allowReset) ? true : false;
$data = !empty($modSettings['website_visitor_count']) && empty($allAction) ? json_decode($modSettings['website_visitor_count'], true, JSON_OBJECT_AS_ARRAY | JSON_NUMERIC_CHECK) : array('visitor_count' => 1);
$visitCount[$action] = empty($reset) && !empty($data) && !empty($data[$action]) ? intval($data[$action]) + 1 : 1;
$data[$action] = $visitCount[$action];
$setting = json_encode($data, JSON_FORCE_OBJECT | JSON_NUMERIC_CHECK);
updateSettings(array('website_visitor_count' => $setting));
echo '
<div class="visitor_data_body">
<div>' . $buttonName . '</div>
<div class="website_visit_counter"></div>
</div>
<script>
$(document).ready(function() {
$(".visitor_data_body").css({"display":"flex","justify-content":"center","align-items":"center","flex-direction":"column"});
$(".website_visit_counter").prop("title", "' . (empty($actCounter) ? $title : $title2) . '");
$(".website_visit_counter").css({
"display":"flex",
"justify-content":"center",
"align-items":"center",
"flex-direction":"column",
"background-color":"#ff4957",
"height":"30px",
"width":"50px",
"color":"white",
"border-radius":"30px",
"font-weight":"700",
"font-size":"15px",
"margin-top":"10px",
"cursor" : "' . $cursor . '"
});
});
var posthash, visitCount = Number("' . $visitCount[$action] . '");
$(".website_visit_counter").html(visitCount);' . (!empty($allowReset) ? '
$( ".website_visit_counter" ).on( "click", function() {' . (!empty($actCounter) ? '
if (confirm("' . ($ask3) . '") == true) {
posthash = location.hash.replace("#", "");
if(posthash != ""){
location.hash = "";
}
window.location.href = window.location.href.replace(/\;visitorReset=\d+/g,"").replace(/\;+$/, "").replace(/\#+$/, "") + ";visitorReset=all";
}
else ' : '') . '
if (confirm("' . (empty($actCounter) ? $ask : $ask2) . '") == true) {
posthash = location.hash.replace("#", "");
if(posthash != ""){
location.hash = "";
}
window.location.href = window.location.href.replace(/\;visitorReset=\d+/g,"").replace(/\;+$/, "").replace(/\#+$/, "") + ";visitorReset=' . $action . '";
} else {
return false;
}
});' : '') . '
</script>';
Quote from: Dave on Today at 02:14:06 AMYes that works OK with PHP8.3 but nothing less, but as I said before it's your choice if you don't want it to work with less
Quote from: Chen Zhen on December 05, 2024, 06:14:44 PMThe contents are in the sp_parameters table.
Quote from: Chen Zhen on December 05, 2024, 06:34:07 PMTry this PHP block:
global $user_info, $modSettings;
$actCounter = false; // boolean : true = different counter for each action, false = same counter for every action
$buttonName = !empty($actCounter) ? 'Page Views' : 'Visitors';
// allow a reset option for speicific users -> use array(0) for all admins, user id# for specific admin [ ie. array(1) ] or multiple user id#'s for specific users [ ie. array (1,3,8) ]
// requires $adminReset to be true else it will be ignored
$adminId = array(1);
$adminReset = true;
if (empty($user_info['is_guest']) && !empty($adminReset)) {
$allowReset = empty($adminId[0]) && !empty($user_info['is_admin']) ? true : (in_array($user_info['id'], $adminId) ? true : false);
}
list($title, $title2, $cursor, $ask, $ask2, $ask3, $visitCount, $data) = !empty($adminReset) && !empty($allowReset) ?
array('Click to reset the counter', 'Click to reset the current action counter', 'help', 'Reset the page visit counter?', 'Reset the page visit counter for this action?', 'Reset the page visit counter for all actions?', array(), array()) :
array('Page views', '', 'crosshair', '', '', '', array(), array());
// don't bother changing code below this comment
$allAction = !empty($_REQUEST['visitorReset']) && is_string($_REQUEST['visitorReset']) && $_REQUEST['visitorReset'] == 'all' ? true : false;
$action = !empty($_REQUEST['action']) && !empty($actCounter) && is_string($_REQUEST['action']) ? strtolower($_REQUEST['action']) . '_count' : 'visitor_count';
$reset = !empty($_REQUEST['visitorReset']) && is_string($_REQUEST['visitorReset']) && $_REQUEST['visitorReset'] == $action && !empty($allowReset) ? true : false;
$data = !empty($modSettings['website_visitor_count']) && json_validate($modSettings['website_visitor_count']) && empty($allAction) ? json_decode($modSettings['website_visitor_count'], true, JSON_OBJECT_AS_ARRAY | JSON_NUMERIC_CHECK) : array('visitor_count' => 1);
$visitCount[$action] = empty($reset) && !empty($data) && !empty($data[$action]) ? intval($data[$action]) + 1 : 1;
$data[$action] = $visitCount[$action];
$setting = json_encode($data, JSON_FORCE_OBJECT | JSON_NUMERIC_CHECK);
updateSettings(array('website_visitor_count' => $setting));
echo '
<div class="visitor_data_body">
<div>' . $buttonName . '</div>
<div class="website_visit_counter"></div>
</div>
<script>
$(document).ready(function() {
$(".visitor_data_body").css({"display":"flex","justify-content":"center","align-items":"center","flex-direction":"column"});
$(".website_visit_counter").prop("title", "' . (empty($actCounter) ? $title : $title2) . '");
$(".website_visit_counter").css({
"display":"flex",
"justify-content":"center",
"align-items":"center",
"flex-direction":"column",
"background-color":"#ff4957",
"height":"30px",
"width":"50px",
"color":"white",
"border-radius":"30px",
"font-weight":"700",
"font-size":"15px",
"margin-top":"10px",
"cursor" : "' . $cursor . '"
});
});
var posthash, visitCount = Number("' . $visitCount[$action] . '");
$(".website_visit_counter").html(visitCount);' . (!empty($allowReset) ? '
$( ".website_visit_counter" ).on( "click", function() {' . (!empty($actCounter) ? '
if (confirm("' . ($ask3) . '") == true) {
posthash = location.hash.replace("#", "");
if(posthash != ""){
location.hash = "";
}
window.location.href = window.location.href.replace(/\;visitorReset=\d+/g,"").replace(/\;+$/, "").replace(/\#+$/, "") + ";visitorReset=all";
}
else ' : '') . '
if (confirm("' . (empty($actCounter) ? $ask : $ask2) . '") == true) {
posthash = location.hash.replace("#", "");
if(posthash != ""){
location.hash = "";
}
window.location.href = window.location.href.replace(/\;visitorReset=\d+/g,"").replace(/\;+$/, "").replace(/\#+$/, "") + ";visitorReset=' . $action . '";
} else {
return false;
}
});' : '') . '
</script>';
(1, 'User Info', 'sp_userInfo', 1, 1, 3, '', '', 1, 0, 0, 0, '', '', ''),
(2, 'Who's Online', 'sp_whosOnline', 1, 2, 3, '', '', 1, 0, 0, 0, '', '', ''),
(3, 'Board Stats', 'sp_boardStats', 1, 3, 3, '', '', 1, 0, 0, 0, '', '', ''),
(4, 'Theme Select', 'sp_theme_select', 1, 4, 3, '', '', 1, 0, 0, 0, '', '', ''),
(5, 'Search', 'sp_quickSearch', 1, 5, 3, '', '', 1, 0, 0, 0, '', '', ''),
(6, 'News', 'sp_news', 2, 1, 3, '', '', 1, 0, 0, 0, '', '', 'title_default_class~|title_custom_class~|title_custom_style~|body_default_class~windowbg|body_custom_class~|body_custom_style~|no_title~1|no_body~'),
(7, 'Welcome', 'sp_html', 2, 2, 3, '', '', 1, 0, 0, 0, 'sportal', '', 'title_default_class~|title_custom_class~|title_custom_style~|body_default_class~windowbg|body_custom_class~|body_custom_style~|no_title~1|no_body~'),
(8, 'Board News', 'sp_boardNews', 2, 3, 3, '', '', 1, 0, 0, 0, '', '', ''),
(9, 'Recent Topics', 'sp_recent', 3, 1, 3, '', '', 1, 0, 0, 0, '', '', ''),
(10, 'Top Poster', 'sp_topPoster', 4, 1, 3, '', '', 1, 0, 0, 0, '', '', ''),
(11, 'Recent Posts', 'sp_recent', 4, 2, 3, '', '', 1, 0, 0, 0, '', '', ''),
(12, 'Forum Staff', 'sp_staff', 4, 3, 3, '', '', 1, 0, 0, 0, '', '', ''),
(13, 'Calendar', 'sp_calendar', 4, 4, 3, '', '', 1, 0, 0, 0, '', '', ''),
(14, 'Top Boards', 'sp_topBoards', 4, 5, 3, '', '', 1, 0, 0, 0, '', '', ''),
(15, 'Visitors', 'sp_php', 6, 1, 3, '', '', 1, 0, 0, 0, 'sportal', '', 'title_default_class~catbg|title_custom_class~|title_custom_style~|body_default_class~|body_custom_class~|body_custom_style~|no_title~|no_body~1');
website_visitor_count {"visitor_count_":1}
variable for it. Then added the code to a new block again and did a preview and the counter shows, see attached image, but as soon as you click on 'Add Block' the error Database error in block code. Please check the code.
comes back .website_visitor_count {"visitor_count_":994}
it's the same except for the numbers