jamoss
09-15-2007, 10:00 PM
Based on Sinclair's hack: https://vborg.vbsupport.ru/showthread.php?t=40557
I modified it to make it a plug-in for 3.6 +
Usage:
Users enter the code y,m,d
Example:
2007,12,25 Christmas!
ONLY ONE STEP: EASY!
Go to your admin panel and CREATE NEW PLUGIN.
- Hook Location: BBCODE_PARSE_COMPLETE
- Enter this code in the PHP code box:
preg_match("/(\[)(countdown)(])(\r\n)*([^\"]*)(\[\/countdown\])/siU", $text, $datum);
$dato=$datum[0];
$datr=explode(",",$dato);
$datr[0]=str_replace("[countdown]", "", $datr[0]);
$jahr=intval($datr[0]);
$monat=intval($datr[1]);
$tag=intval($datr[2]);
$stunde=intval($datr[3]);
$minute=intval($datr[4]);
$sekunde=intval($datr[5]);
$target = mktime($stunde,$minute,$sekunde,$monat,$tag,$jahr) ;
$todayo = mktime(0,0,0,date("m"),date("d"),date("Y"));
$diff = ($target - $todayo)/86400;
if ($todayo==$target) { $out= "TODAY "; }
else if ($diff==1) { $out = "1 day until "; }
else if ($diff==(-1)) { $out = "1 day since "; }
else {
if ($diff>0) {
$diff=round($diff,0);
$out="$diff days until ";
}
if ($diff<0) {
$diff=round(-$diff, 0);
$out="$diff days since ";
}
}
$text = preg_replace("/(\[)(countdown)(])(\r\n)*([^\"]*)(\[\/countdown\])/siU", $out, $text);
That's it! Now announce to your users they can use that code.
I modified it to make it a plug-in for 3.6 +
Usage:
Users enter the code y,m,d
Example:
2007,12,25 Christmas!
ONLY ONE STEP: EASY!
Go to your admin panel and CREATE NEW PLUGIN.
- Hook Location: BBCODE_PARSE_COMPLETE
- Enter this code in the PHP code box:
preg_match("/(\[)(countdown)(])(\r\n)*([^\"]*)(\[\/countdown\])/siU", $text, $datum);
$dato=$datum[0];
$datr=explode(",",$dato);
$datr[0]=str_replace("[countdown]", "", $datr[0]);
$jahr=intval($datr[0]);
$monat=intval($datr[1]);
$tag=intval($datr[2]);
$stunde=intval($datr[3]);
$minute=intval($datr[4]);
$sekunde=intval($datr[5]);
$target = mktime($stunde,$minute,$sekunde,$monat,$tag,$jahr) ;
$todayo = mktime(0,0,0,date("m"),date("d"),date("Y"));
$diff = ($target - $todayo)/86400;
if ($todayo==$target) { $out= "TODAY "; }
else if ($diff==1) { $out = "1 day until "; }
else if ($diff==(-1)) { $out = "1 day since "; }
else {
if ($diff>0) {
$diff=round($diff,0);
$out="$diff days until ";
}
if ($diff<0) {
$diff=round(-$diff, 0);
$out="$diff days since ";
}
}
$text = preg_replace("/(\[)(countdown)(])(\r\n)*([^\"]*)(\[\/countdown\])/siU", $out, $text);
That's it! Now announce to your users they can use that code.