<?php

# PLUGIN PREVIEW BY TEXTPATTERN.INFO

function smd_countdown($atts$thing=NULL) {
    global 
$thisarticle$smd_timer;

    
extract(lAtts(array(
        
'to' => 'posted',
        
'debug' => 0,
    ),
$atts));

    
$destime '';

    if (
$to == 'posted' || $to == 'expires' || $to == 'modified') {
        
assert_article();
        
$destime $thisarticle[$to];
    } else if (
strpos($to"?") === 0) {
        
assert_article();
        
$fldname substr(strtolower($to), 1);
        if (isset(
$thisarticle[$fldname])) {
            
$destime = (is_numeric($thisarticle[$fldname])) ? $thisarticle[$fldname] : strtotime($thisarticle[$fldname]);
        }
    } else if (
$to != '') {
        
$destime strtotime($to);
    }

    if (
$debug) {
        echo 
'++ DESTINATION ++';
        
dmp($destime);
        
dmp(date('d M Y H:i:s',$destime));
    }

    if (
$destime) {
        
$now time();

        
// Split into years/months/weeks/days/hrs/minutes/seconds
        
$diff $destime $now;
        
$absdiff = ($diff>0) ? $diff $now $destime;
        
$smd_timer['difference'] = $diff;
        
$smd_timer['abs_difference'] = $absdiff;
        
$smd_timer['destination'] = $destime;

        
$lookup = array(
            
'year' => array(60 60 24 365),
            
'month' => array(60 60 24 3012), // month(ish)
            
'week' => array(60 60 24 752),
            
'day' => array(60 60 247),
            
'hour' => array(60 6024),
            
'minute' => array(6060),
            
'second' => array(160),
        );

        foreach (
$lookup as $item => $bloc) {
            
$qty floor($absdiff $bloc[0]);
            
$smd_timer[$item] = (isset($bloc[1])) ? $qty $bloc[1] : $qty;
            
$smd_timer[$item.'_total'] = $qty;
        }

        if (
$debug) {
            echo 
'++ TIMER ++';
            
dmp($smd_timer);
        }

        
$result = ($diff>0) ? false true// True if destination reached, false otherwise

        
return parse(EvalElse($thing$result));
    } else {
        return 
'';
    }
}

function 
smd_time_info($atts) {
    global 
$smd_timer;

    
extract(lAtts(array(
        
'display' => '',
        
'show_zeros' => '1',
        
'pad' => '2,0',
        
'label' => '',
        
'labeltag' => '',
        
'labelafter' => 0,
        
'labelspacer' => '',
        
'wraptag' => '',
        
'class' => __FUNCTION__,
        
'break' => '',
        
'debug' => 0,
    ),
$atts));

    
$display do_list($display);
    
$label do_list($label);
    
$pad do_list($pad);
    
$pad[0] = (empty($pad[0])) ? '1' $pad[0];
    
$pad[1] = (count($pad)==1) ? '0' $pad[1];

    
$out = array();
    
$use_plural false;

    foreach (
$display as $item) {
        if (isset(
$smd_timer[$item])) {
            if (
$smd_timer[$item] > || ($smd_timer[$item] == && (!empty($out) || $show_zeros))) {
                
$out[] = str_pad($smd_timer[$item], $pad[0], $pad[1], STR_PAD_LEFT);
            }
            
$use_plural = ($smd_timer[$item] != 1) ? true false;
        }
    }

    
$theLabel = ($use_plural && isset($label[1])) ? $label[1] : $label[0];

    return (
$out)
            ? ((
$labelafter==0) ? doLabel($theLabel.$labelspacer$labeltag) : '').
                
doWrap($out$wraptag$break$class).
                ((
$labelafter==1) ? doLabel($labelspacer.$theLabel$labeltag) : '')
            : 
'';
}