hi
thanks for your input. i don't think your code is correct, but mine is not either...
the right condition is:
if the COOKIE does not exist, allways display (no dependence on show type)
if the COOKIE string is NOT equivalent, allways display (no depence on show type).
if the COOKIE string IS equivalent, the announcement must only be displayed, if the show_type is 2 (periodically) and the time must be expired.
conclusion:
// If cookie is set AND cookie string is identical, then only show when
// in frequency mode!
if (isset($_COOKIE['tb_cookie']) && $_COOKIE['tb_cookie'] == get_option('tb_cookie')) {
// Show only once per session
if ($tb_show_type == 1) {
return;
// Show every time the user enters the site
// This is achieved by setting the cookie expiration to 0
} elseif ($tb_show_type == 3) {
return;
} elseif ($tb_show_type == 2) { // More than once, check frequency
$days = intval(get_option('tb_show_freq'));
if ($days > 0) {
// Get beginning of the day, when it should be displayed again
$aexp = floor(($_COOKIE['tb_lastshown'] + $days*self::DAY_IN_SECONDS) / self::DAY_IN_SECONDS) * self::DAY_IN_SECONDS + 1;
if (time() < $aexp)
return;
}
}
}
else {
// Allways display
}
if ($tb_show_type == 3) {
$exp = 0; // Show every time the user enters the site
} else {
$exp = time()+self::DAY_IN_SECONDS*360; // Expires after a year
}
setcookie('tb_cookie', get_option('tb_cookie'), $exp);
setcookie('tb_lastshown', time(), $exp);
// Check announcement page
$this->checkInternalContentPage();
// Turn Announcement on
$this->showAnnouncement = true;
return;
I think, this should work for any cases. Do you agree?