function widget($args, $instance) { extract($args); echo $before_widget; $title = apply_filters('widget_title', $instance['title']); $open_time = empty($instance['open_time']) ? '' : $instance['open_time']; $open_img = empty($instance['open_img']) ? '' : $instance['open_img']; $close_time = empty($instance['close_time']) ? '' : $instance['close_time']; $close_img = empty($instance['close_img']) ? '' : $instance['close_img']; $clock_html = empty($instance['clock_html']) ? ' ' : $instance['clock_html']; $forum_closed = empty($instance['forum_closed']) ? ' ' : $instance['forum_closed']; $forum_closed_text = empty($instance['forum_closed_text']) ? ' ' : $instance['forum_closed_text']; $forum_open_text = empty($instance['forum_open_text']) ? ' ' : $instance['forum_open_text']; $display_hours = empty($instance['display_hours']) ? ' ' : $instance['display_hours']; $closed_weekends = empty($instance['closed_weekends']) ? ' ' : $instance['closed_weekends']; $gmt = 0; $closed = ''; $open = ''; //formate all the times ready to compaire them $time = current_time_fixed('mysql', $gmt); $day = bbps_current_date('mysql', $gmt); $time = str_replace(':', '', $time); $open_time_raw = str_replace(':', '', $open_time); $close_time_raw = str_replace(':', '', $close_time); echo '<div id="supportwrapper">'; if (!empty($title)) { echo $before_title . $title . $after_title; } // need to compare open and close times first becuse the open number can be bigger than the close time and the other way around - both have a different condition to check. if ($forum_closed == 'on' || $closed_weekends == 'on' && $day == 'Saturday' || $closed_weekends == 'on' && $day == 'Sunday') { $closed = true; } else { if ($open_time_raw < $close_time_raw && ($time >= $open_time_raw && !($time >= $close_time_raw)) || $open_time_raw > $close_time_raw && ($time >= $open_time_raw && !($time <= $close_time_raw))) { $open = true; } else { $closed = true; } } if ($open == true) { echo '<span class="forum_text">' . $forum_open_text . '</span><br />'; if ($open_img != '') { echo '<img src="' . BBPS_WIDGETS_URL . '/images/' . $open_img . '">'; } if ($display_hours == 'on') { echo '<div class="forum_hours"> Our forum hours are: <br />' . bbps_format_time($open_time_raw) . ' - ' . bbps_format_time($close_time_raw) . '</div>'; } } if ($closed == true) { echo '<span class="forum_text">' . $forum_closed_text . '</span><br />'; if ($close_img != '') { echo '<img src="' . BBPS_WIDGETS_URL . '/images/' . $close_img . '">'; } if ($display_hours == 'on') { echo '<div class="forum_hours"> Our forum hours are: <br />' . bbps_format_time($open_time_raw) . ' - ' . bbps_format_time($close_time_raw) . '</div>'; } } echo '<div id="html_clock">' . $clock_html . '</div></div>'; echo $after_widget; //has the user manually set the forums to closed? /* if( $forum_closed == 'on' ){ echo '<span class="forum_text">'.$forum_closed_text .'</span>'; echo '<img src="'.WP_PLUGIN_URL .'/support-hours/images/'.$close_img.'">'; }else{ if($open_time < $close_time){ if ($time >= $open_time && !($time >= $close_time) ){ echo '<span class="forum_text">'.$forum_open_text.'</span>'; echo '<img src="'.WP_PLUGIN_URL .'/support-hours/images/'.$open_img.'">'; }else{ echo '<span class="forum_text">'.$forum_closed_text .'</span>'; echo '<img src="'.WP_PLUGIN_URL .'/support-hours/images/'.$close_img.'">'; } } if ($open_time > $close_time){ if ($time >= $open_time && !($time <= $close_time) ){ echo '<span class="forum_text">'.$forum_open_text .'</span>'; echo '<img src="'.WP_PLUGIN_URL .'/support-hours/images/'.$open_img.'">'; }else{ echo '<span class="forum_text">'. $forum_closed_text .'</span>'; echo '<img src="'.WP_PLUGIN_URL .'/support-hours/images/'.$close_img.'">'; } } } */ }
function widget($args, $instance) { global $wpdb, $ayb_posts_domain, $pattern_dafault, $pattern; if (!function_exists('ayb_sgn')) { function ayb_sgn($number) { if ($number > 0) { return "+"; } if ($number < 0) { return "-"; } if ($number == 0) { return ""; } } function current_time_fixed($type, $gmt = 0) { $t = $gmt ? gmdate('Y-m-d H:i:s') : gmdate('Y-m-d H:i:s', time() + get_option('gmt_offset') * 3600); switch ($type) { case 'mysql': return $t; break; case 'timestamp': return strtotime($t); break; } } } //!function_exists('ayb_sgn') $title = $instance['title']; $day = $instance['day']; $month = $instance['month']; $year = $instance['year']; $showdate = $instance["showdate"]; $dateformat = $instance["dateformat"]; $notfound = $instance["notfound"]; $range = $instance["range"]; $private = $instance["private"]; $showpages = $instance["showpages"]; $anniv = $instance["anniversary"]; $posts_max = $instance['posts_max']; foreach ($instance as $key => $value) { switch ($key) { case "day": $dday = urldecode($value); break; case "month": $dmonth = urldecode($value); break; case "year": $dyear = urldecode($value); break; case "before": $before = urldecode($value); break; case "after": $after = urldecode($value); break; case "notfound": $notfound = htmlspecialchars(urldecode($value)); break; case "showdate": $showdate = urldecode($value); break; case "dateformat": $dateformat = urldecode($value); break; case "range": $range = urldecode($value); break; case "anniversary": $anniv = urldecode($value); break; case "private": $private = urldecode($value); break; case "showpages": $showpages = urldecode($value); break; case "posts_max": $posts_max = urldecode($value); break; } //$key } //$instance as $key => $value if (empty($instance['pattern'])) { $this->pattern = __('<li>%date%: <a href="%link%" title="%excerpt%">%title%</a></li>', 'ayb_posts'); } else { $this->pattern = $instance['pattern']; } //$this -> pattern = empty($instance['pattern']) ? __($this->pattern_default, 'ayb_posts') : $instance['pattern']; $instance['pattern'] = $this->pattern; $ex = preg_match('/\\%excerpt(\\d*)\\%/', $this->pattern, $matches); if ($matches[1] > 0) { $this->excerpt_length = $matches[1]; } $dateformat = empty($instance['dateformat']) ? __('Y-m-d', 'ayb_posts') : $instance['dateformat']; $showdate = empty($instance['showdate']) ? '1' : $instance['showdate']; $notfound = empty($instance['notfound']) ? __("No articles on this date.", 'ayb_posts') : $instance['notfound']; $before = empty($instance['before']) ? '<li>' : $instance['before']; $after = empty($instance['after']) ? '</li>' : $instance['after']; $excerpt_length = empty($instance['excerpt_length']) ? 140 : $instance['excerpt_length']; $title = empty($instance['title']) ? __('A year before', 'ayb_posts') : apply_filters('widget_title', $instance['title']); $posts_max = empty($instance['posts_max']) ? 0 : $instance['posts_max']; if ($dday == 0 && $dmonth == 0 && $dyear == 0) { $dyear = 1; } //$dday == 0 && $dmonth == 0 && $dyear == 0 $ts = current_time_fixed('timestamp', 0); $ayb_tz = "now"; $ayb_tz_sec = get_option('gmt_offset') * 360000; $range_date1 = date("Y-m-d H:i:00", strtotime($ayb_tz, mktime(0, 0, 0, date("m", $ts) - $dmonth, date("d", $ts) - $dday, date("Y", $ts) - $dyear))); $range_date2 = date("Y-m-d H:i:59", strtotime($ayb_tz, mktime(23, 59, 59, date("m", $ts) - $dmonth, date("d", $ts) - $dday + $range, date("Y", $ts) - $dyear))); $month_day = date("m", $ts) . "-" . date("d", $ts); //$month_day= gmdate('m'). "-" . gmdate("d"); switch ($private) { case 1: $post_status = "(post_status='publish' OR post_status='private')"; break; case 2: $post_status = "post_status='private'"; break; default: $post_status = "post_status='publish'"; } switch ($showpages) { case 0: $post_type = "post_type='post'"; break; case 1: $post_type = "(post_type='page' OR post_type='post')"; break; default: $post_type = "post_type='post'"; } if ($anniv == 0) { $q = "SELECT ID, post_content, post_excerpt, post_title, post_date_gmt FROM {$wpdb->posts} WHERE {$post_status} AND {$post_type} AND post_password='' AND (post_date_gmt >= '" . $range_date1 . "' AND post_date_gmt <= '" . $range_date2 . "') ORDER BY post_date_gmt ASC"; } else { $q = "SELECT ID, post_content, post_excerpt, post_title, post_date_gmt FROM {$wpdb->posts} WHERE {$post_status} AND {$post_type} AND post_password='' AND SUBSTRING(post_date,6,5) = '" . $month_day . "' AND post_date<CURDATE() ORDER BY post_date_gmt DESC"; } $result = $wpdb->get_results($q, object); $post_date = $post_date_gmt = false; if ($result) { $post_date = $result[0]->post_date_gmt; $ts_post_date = gmmktime(0, 0, 0, substr($post_date, 5, 2), substr($post_date, 8, 2), substr($post_date, 0, 4)); $ts_date_old = $ts_post_date; // Anzahl der Posts if ($posts_max > 0 && sizeof($result) > $posts_max) { $akey = array_rand($result, $posts_max); for ($i = 0; $i < sizeof($akey); $i++) { $temp_arr[] = $result[$akey[$i]]; } $result = $temp_arr; } foreach ($result as $post) { $post_date = $post->post_date_gmt; $this->excerpt = $post->post_excerpt; if (empty($this->excerpt)) { $this->excerpt = wp_html_excerpt(htmlspecialchars(strip_tags($post->post_content)), $this->excerpt_length) . " …"; } if ($showdate) { $post_date = $post->post_date_gmt; $ts_post_date_comp = gmmktime(substr($post_date, 11, 2), substr($post_date, 14, 2), 0, substr($post_date, 5, 2), substr($post_date, 8, 2), substr($post_date, 0, 4)); $pdate = '<span class="ayb_date">' . date($dateformat, $ts_post_date_comp) . "</span>"; } else { $pdate = ''; } $ts_post_date = gmmktime(0, 0, 0, substr($post_date, 5, 2), substr($post_date, 8, 2), substr($post_date, 0, 4)); if ($ts_post_date != $ts_date_old && $range != 0) { //break; } else { $ts_date_old = $ts_post_date; } $this->datum = $pdate; $this->plink = get_permalink($post->ID); $this->ptitle = $post->post_title; $this->ayb_article_list .= $this->pattern_output(); } //$result as $post } else { if (!$anniv) { if ($showdate) { $pdate = '<span class="ayb_date">' . date($dateformat, gmmktime(0, 0, 0, date("m", $ts) - $dmonth, date("d", $ts) - $dday, date("Y", $ts) - $dyear)) . "</span>"; } else { $pdate = ''; } } else { $pdate = '<span class="ayb_date">' . date($dateformat, gmmktime(0, 0, 0, date("m", $ts), date("d", $ts), date("Y", $ts))) . "</span>"; } $this->ayb_article_list .= $before . $pdate . '<span class="ayb_notfound"> ' . $notfound . '</span>' . $after . "\r"; } if (isset($instance["no_widget"]) && $instance["no_widget"]) { echo $this->ayb_article_list; } else { extract($args); $title = esc_attr($instance['title']); echo $before_widget . $before_title . $title . $after_title; echo '<ul>' . $this->ayb_article_list . '</ul>'; echo $after_widget; $this->ayb_article_list = ''; } }