コード例 #1
0
ファイル: functions.php プロジェクト: baden03/access48
function batterUp($countdown)
{
    $children = get_children('post_type=t-countdown&post_parent=' . $countdown);
    if (empty($children)) {
        return array((int) $countdown, (int) $countdown);
    } else {
        //loop the children and calculate target
        $now = time() + get_option('gmt_offset') * 3600;
        //var_dump($now);
        $target_arr = array();
        foreach ($children as $child) {
            $countdown_arr = array();
            $custom_fields = get_post_custom($child->ID);
            foreach ($custom_fields as $field_key => $field_values) {
                if (!isset($field_values[0])) {
                    continue;
                }
                if (in_array($field_key, array("_edit_lock", "_edit_last"))) {
                    continue;
                }
                //echo $field_key . '=>' . $field_values[0];
                $countdown_arr[$field_key] = $field_values[0];
            }
            $countdown_arr['content'] = $child->post_content;
            $countdown_arr['cid'] = $child->ID;
            //var_dump($countdown_arr);
            $target = launchTarget($countdown_arr, $now);
            //var_dump($target);
            $target_arr[$child->ID] = $target[0];
        }
        //var_dump($target_arr);
        $nextup = array_keys($target_arr, min($target_arr));
        //var_dump((int)$countdown, $nextup[0]);
        return array((int) $countdown, $nextup[0]);
    }
}
コード例 #2
0
    /** Widget */
    function widget($args, $instance)
    {
        global $add_my_script;
        wp_enqueue_script('tminus-countdown-script');
        $options = get_option('WP_TMCC_options');
        extract($args);
        $countdown = empty($instance['countdown']) ? '' : apply_filters('widget_countdown', $instance['countdown']);
        //grab info from the assigned countdown element
        if ($countdown) {
            //insert some style into your life
            $style = empty($instance['style']) ? $options['style'] : apply_filters('widget_style', $instance['style']);
            wp_enqueue_style('countdown-' . $style . '-css');
            $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']);
            //now
            //$now = time() + ( get_option( 'gmt_offset' ) * 3600);
            $now = strtotime(current_time('mysql'));
            //launch meta_values
            $countdown_arr = launchDetails($countdown);
            //var_dump($countdown_arr);
            if (!empty($countdown_arr['tminus_status'])) {
                return false;
            }
            $tophtml = empty($countdown_arr['tminus_top_html']) ? ' ' : $countdown_arr['tminus_top_html'];
            $bothtml = empty($countdown_arr['tminus_bot_html']) ? ' ' : $countdown_arr['tminus_bot_html'];
            $launchhtml = empty($countdown_arr['content']) ? ' ' : $countdown_arr['content'];
            $launchtarget = empty($countdown_arr['tminus_launch_target']) ? 'none' : $countdown_arr['tminus_launch_target'];
            if ($launchtarget == 'widget') {
                $launchtarget = 'widget-swap';
            }
            $tminus_type = empty($countdown_arr['tminus_type']) ? 'single' : 'recur';
            $use_cookie = empty($countdown_arr['tminus_use_cookie']) ? '' : $countdown_arr['tminus_use_cookie'];
            $expiry_days = empty($countdown_arr['tminus_expiry_days']) ? '' : $countdown_arr['tminus_expiry_days'];
            $launchurl = empty($countdown_arr['tminus_launch_url']) ? ' ' : $countdown_arr['tminus_launch_url'];
            $weektitle = empty($instance['weektitle']) ? $options['weeks'] : apply_filters('widget_weektitle', $instance['weektitle']);
            $daytitle = empty($instance['daytitle']) ? $options['days'] : apply_filters('widget_daytitle', $instance['daytitle']);
            $hourtitle = empty($instance['hourtitle']) ? $options['hours'] : apply_filters('widget_hourtitle', $instance['hourtitle']);
            $mintitle = empty($instance['mintitle']) ? $options['minutes'] : apply_filters('widget_mintitle', $instance['mintitle']);
            $sectitle = empty($instance['sectitle']) ? $options['seconds'] : apply_filters('widget_sectitle', $instance['sectitle']);
            $omitsecs = empty($instance['omitsecs']) ? $options['omitsecs'] : apply_filters('widget_omitsecs', $instance['omitsecs']);
            $omitmins = empty($instance['omitmins']) ? $options['omitmins'] : apply_filters('widget_omitmins', $instance['omitmins']);
            $omithours = empty($instance['omithours']) ? $options['omithours'] : apply_filters('widget_omithours', $instance['omithours']);
            $omitdays = empty($instance['omitdays']) ? $options['omitdays'] : apply_filters('widget_omitdays', $instance['omitdays']);
            $omitweeks = empty($instance['omitweeks']) ? $options['omitweeks'] : apply_filters('widget_omitweeks', $instance['omitweeks']);
            $timericon = empty($instance['timericon']) ? $options['timer_icon'] : apply_filters('widget_timericon', $instance['timericon']);
            $trailingtext = empty($instance['trailingtext']) ? $options['trailingtext'] : apply_filters('widget_trailingtext', $instance['trailingtext']);
            $jsplacement = empty($instance['jsplacement']) ? 'footer' : apply_filters('widget_jsplacement', $instance['jsplacement']);
            //do we need cookies?
            if (!empty($countdown_arr['tminus_use_cookie'])) {
                wp_enqueue_script('tminus-cookie');
            }
            $target_arr = launchTarget($countdown_arr, $now);
            $target = $target_arr[0];
            $hang_time = $target_arr[1];
            //var_dump(date('Y-m-d H:i:s', $target));
            $year = date('Y', $target);
            $month = date('m', $target);
            $day = date('d', $target);
            $hour = date('H', $target);
            $min = date('i', $target);
            $sec = date('s', $target);
            //difference in seconds
            $diffSecs = $target - $now;
            //countdown digits
            $date = array();
            if ($omitweeks == 'false' && $omitdays == 'false' && $omithours == 'false' && $omitmins == 'false') {
                $date['secs'] = $diffSecs;
                $date['mins'] = 0;
                $date['hours'] = 0;
                $date['weeks'] = 0;
            } else {
                $date['secs'] = $diffSecs % 60;
                $date['mins'] = floor($diffSecs / 60) % 60;
                $date['hours'] = floor($diffSecs / 60 / 60) % 24;
                if ($omitweeks == 'false') {
                    $date['days'] = floor($diffSecs / 60 / 60 / 24) % 7;
                } else {
                    $date['days'] = floor($diffSecs / 60 / 60 / 24);
                }
                $date['weeks'] = floor($diffSecs / 60 / 60 / 24 / 7);
            }
            foreach ($date as $i => $d) {
                $d1 = $d % 10;
                //53 = 3
                //153 = 3
                if ($d < 100) {
                    $d2 = ($d - $d1) / 10;
                    //53 = 50 / 10 = 5
                    $d3 = 0;
                } else {
                    $dr = $d % 100;
                    //153 = 53
                    //345 = 45
                    $dm = $d - $dr;
                    //153 = 100
                    //345 = 300
                    $d2 = ($d - $dm - $d1) / 10;
                    //153 = 50 / 10 = 5
                    //345 = 40 / 10 = 4
                    $d3 = $dm / 100;
                }
                /* here is where the 1000's support will go... someday. */
                //now assign all the digits to the array
                $date[$i] = array((int) $d3, (int) $d2, (int) $d1, (int) $d);
            }
            echo $before_widget;
            if ($title) {
                echo $before_title . $title . $after_title;
            }
            echo '<div id="' . $args['widget_id'] . '-widget" class="tminus_countdown">';
            echo '<div id="' . $args['widget_id'] . '-tophtml" class="' . $style . '-tophtml" >';
            if ($tophtml) {
                echo stripslashes($tophtml);
            }
            echo '</div>';
            //drop in the dashboard
            echo '<div id="' . $args['widget_id'] . '-dashboard" class="' . $style . '-dashboard">';
            echo '<div class="' . $style . '-timer_icon">' . $timericon . '</div>';
            if ($omitweeks == 'false') {
                //set up correct style class for double or triple digit love
                $wclass = $style . '-dash ' . $style . '-weeks_dash';
                if ($date['weeks'][0] > 0) {
                    $wclass = $style . '-tripdash ' . $style . '-weeks_trip_dash';
                }
                echo '<div class="' . $wclass . '">
							<div class="' . $style . '-dash_title">' . $weektitle . '</div>';
                //show third week digit if the number of weeks is greater than 99
                if ($date['weeks'][0] > 0) {
                    echo '<div class="' . $style . '-digit">' . $date['weeks'][0] . '</div>';
                }
                echo '<div class="' . $style . '-digit">' . $date['weeks'][1] . '</div><div class="' . $style . '-digit">' . $date['weeks'][2] . '</div></div>';
            }
            //set up correct style class for double or triple digit love
            $dclass = $style . '-dash ' . $style . '-days_dash';
            if ($omitweeks == 'true' && $date['days'][3] > 99) {
                $dclass = $style . '-tripdash ' . $style . '-days_trip_dash';
            }
            $hidedays = '';
            if ($omitdays == 'true') {
                $hidedays = 'style="display: none;"';
            }
            $hidesecs = '';
            if ($omitsecs == 'true') {
                $hidesecs = 'style="display: none;"';
            }
            echo '<div class="' . $dclass . '" ' . $hidedays . '><div class="' . $style . '-dash_title">' . $daytitle . '</div>';
            //show third day digit if there are NO weeks and the number of days is greater that 99
            if ($omitweeks == 'true' && $date['days'][3] > 99) {
                echo '<div class="' . $style . '-digit" >' . $date['days'][0] . '</div>';
            }
            echo '<div class="' . $style . '-digit">' . $date['days'][1] . '</div>
					<div class="' . $style . '-digit">' . $date['days'][2] . '</div>
				</div>
		
				<div class="' . $style . '-dash ' . $style . '-hours_dash">
					<div class="' . $style . '-dash_title">' . $hourtitle . '</div>
					<div class="' . $style . '-digit">' . $date['hours'][1] . '</div>
					<div class="' . $style . '-digit">' . $date['hours'][2] . '</div>
				</div>
		
				<div class="' . $style . '-dash ' . $style . '-minutes_dash">
					<div class="' . $style . '-dash_title">' . $mintitle . '</div>
					<div class="' . $style . '-digit">' . $date['mins'][1] . '</div>
					<div class="' . $style . '-digit">' . $date['mins'][2] . '</div>
				</div>
		
				<div class="' . $style . '-dash ' . $style . '-seconds_dash" ' . $hidesecs . '>
					<div class="' . $style . '-dash_title">' . $sectitle . '</div>
					<div class="' . $style . '-digit">' . $date['secs'][1] . '</div>
					<div class="' . $style . '-digit">' . $date['secs'][2] . '</div>
				</div>
				<div class="' . $style . '-trailing_text">' . $trailingtext . '</div>
				<div class="t-throbTimer"></div>
			</div>';
            //close the dashboard
            echo '<div id="' . $args['widget_id'] . '-bothtml" class="' . $style . '-bothtml">';
            if ($bothtml) {
                echo stripslashes($bothtml);
            }
            echo '</div>';
            echo '</div>';
            //the countdown placeholder for when launch html needs to be displayed.
            echo '<div id="' . $args['widget_id'] . '-widget-swap" style="display:none"></div>';
            echo $after_widget;
            $lt = date('n/j/Y H:i:s', $target);
            //$t = date( 'n/j/Y H:i:s', time() + ( get_option( 'gmt_offset' ) * 3600));
            $t = date('n/j/Y H:i:s', strtotime(current_time('mysql')));
            //launch div
            $launchdiv = $launchtarget;
            //var_dump($year.'-'.$month.'-'.$day.' '.$hour.':'.$min.':'.$sec);
            if ($jsplacement == "footer") {
                $add_my_script[$id] = array('id' => $args['widget_id'], 'cdtype' => 'widget', 'day' => $day, 'month' => $month, 'year' => $year, 'hour' => $hour, 'min' => $min, 'sec' => $sec, 'launchtime' => $lt, 'tminus_type' => $tminus_type, 'use_cookie' => $use_cookie, 'expiry_days' => $expiry_days, 'localtime' => $t, 'style' => $style, 'omitweeks' => $omitweeks, 'omitdays' => $omitdays, 'omithours' => $omithours, 'omitmins' => $omitmins, 'omitsecs' => $omitsecs, 'content' => trim($launchhtml), 'launchtarget' => $launchdiv, 'launchurl' => $launchurl, 'launchwidth' => 'auto', 'launchheight' => 'auto', 'pid' => $countdown_arr['pid'], 'cid' => $countdown_arr['cid'], 'hangtime' => $hang_time);
                //var_dump($add_my_script);
            } else {
                ?>
            
				<script language="javascript" type="text/javascript">
					jQuery(document).ready(function($) {
						$('#<?php 
                echo $args['widget_id'];
                ?>
-dashboard').countDown({	
							targetDate: {
								'day': 			<?php 
                echo $day;
                ?>
,
								'month': 		<?php 
                echo $month;
                ?>
,
								'year': 		<?php 
                echo $year;
                ?>
,
								'hour': 		<?php 
                echo $hour;
                ?>
,
								'min': 			<?php 
                echo $min;
                ?>
,
								'sec': 			<?php 
                echo $sec;
                ?>
,
								'launchtime': 	'<?php 
                echo $lt;
                ?>
',
								'tminus_type':	'<?php 
                echo $tminus_type;
                ?>
',
								'use_cookie':	'<?php 
                echo $use_cookie;
                ?>
',
								'expiry_days':	'<?php 
                echo $expiry_days;
                ?>
',
								'localtime':	'<?php 
                echo $t;
                ?>
',
							},
							id: '<?php 
                echo $args['widget_id'];
                ?>
',
							cdtype: 'widget',
							style: '<?php 
                echo $style;
                ?>
',
							omitSecs: '<?php 
                echo $omitsecs;
                ?>
',
							omitMins: '<?php 
                echo $omitmins;
                ?>
',
							omitHours: '<?php 
                echo $omithours;
                ?>
',
							omitDays: '<?php 
                echo $omitdays;
                ?>
',
							omitWeeks: '<?php 
                echo $omitweeks;
                ?>
'
							<?php 
                if ($launchdiv != 'none') {
                    if ($launchhtml || $launchdiv == 'countup' || $launchdiv == 'url') {
                        echo ", launchTarget: '" . $args['widget_id'] . "-" . $launchdiv . "'";
                        if ($launchdiv == 'url') {
                            echo ", onComplete: function() { window.location = '" . $launchurl . "'; }";
                        } else {
                            echo ", onComplete: function() { \$('#" . $args['widget_id'] . "-" . $launchdiv . "').html('" . addslashes(do_shortcode($launchhtml)) . "'); }";
                        }
                    }
                }
                echo ", pid:  " . $countdown_arr['pid'];
                echo ", cid:  " . $countdown_arr['cid'];
                //if($hang_time){
                echo ", hangtime:  " . $hang_time;
                //}
                ?>
						});
					});
				</script>
				<?php 
            }
        }
    }