'ayb_posts', 'description' => __('Show articles a certain periode of time before', 'ayb_posts')); $this -> WP_Widget('ayb_posts', __('A Year Before'), $widget_ops); add_filter('plugin_row_meta', array($this, 'ayb_set_plugin_meta'), 10, 2); } function ayb_set_plugin_meta($links, $file) { $plugin = plugin_basename(__FILE__); // create link if ($file == $plugin) { return array_merge( $links, array(sprintf('%s', __('Donate with Flattr', 'ayb_posts')))); } return $links; } function on_delete() { delete_option('ayb_posts'); } function pattern_output() { $subpattern_array = array('/%title%/', '/%date%/', '/%link%/', '/%excerpt(\d*)%/'); $var_array = array(quotemeta($this -> ptitle), $this -> datum, $this -> plink, $this -> excerpt); $r = preg_replace($subpattern_array, $var_array, $this -> pattern); return stripslashes($r); } 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 = __('
  • %date%: %title%
  • ', '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']) ? '
  • ' : $instance['before']; $after = empty($instance['after']) ? '
  • ' : $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<>'page'"; break; case 1 : $post_type = "post_type<>''"; break; default : $post_type = "post_type<>'page'"; } 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"; }//$anniv == 0 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 get_results($q, object); $post_date = $post_date_gmt; 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 = '' . date($dateformat, $ts_post_date_comp) . ""; }//$showdate 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; }//$ts_post_date != $ts_date_old && $range != 0 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 }//$result else { if (!$anniv) { if ($showdate) { $pdate = '' . date($dateformat, gmmktime(0, 0, 0, date("m", $ts) - $dmonth, date("d", $ts) - $dday, date("Y", $ts) - $dyear)) . ""; }//$showdate else { $pdate = ''; } }//!$anniv else { $pdate = '' . date($dateformat, gmmktime(0, 0, 0, date("m", $ts), date("d", $ts), date("Y", $ts))) . ""; } $this -> ayb_article_list .= $before . $pdate . ' ' . $notfound . '' . $after . "\r"; } if ($instance["no_widget"]) { echo $this -> ayb_article_list; }//$instance["no_widget"] else { extract($args); $title = attribute_escape($instance['title']); echo $before_widget . $before_title . $title . $after_title; echo ''; echo $after_widget; $this -> ayb_article_list = ''; } } function form($instance) { global $ayb_posts_domain, $pattern_default; $defaults = array('title' => __("A year before", 'ayb_posts'), 'day' => '0', 'month' => '0', 'year' => '1', 'range' => '0', 'dateformat' => __('Y-m-d', 'ayb_posts'), 'anniversary' => '0', 'showdate' => '1', 'private' => '0', 'showpages' => '0', 'posts_max' => '0', 'notfound' => __('No articles on this date.', 'ayb_posts'), 'pattern' => __($this -> pattern_dafault, 'ayb_posts')); $instance = wp_parse_args((array)$instance, $defaults); $title = strip_tags($instance['title']); $day = strip_tags($instance['day']); $month = $instance['month']; $year = $instance['year']; $showdate = $instance["showdate"]; $dateformat = $instance["dateformat"]; $notfound = $instance["notfound"]; $private = $instance["private"]; $showpages = $instance["showpages"]; $range = $instance["range"]; $anniv = $instance["anniversary"]; $posts_max = $instance["posts_max"]; $pattern_html = htmlspecialchars($instance["pattern"]); echo 'Flattr this'; echo '

    '; echo '

    '; echo '

    '; echo '

    '; echo '

    '; echo '

    '; echo '

    '; echo '

    '; echo '

    '; echo '

    '; echo '

    '; echo '

    '; } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = strip_tags(stripslashes($new_instance['title'])); $instance["day"] = strip_tags(stripslashes($new_instance['day'])); $instance["month"] = strip_tags(stripslashes($new_instance['month'])); $instance["year"] = strip_tags(stripslashes($new_instance['year'])); $instance["showdate"] = strip_tags(stripslashes($new_instance['showdate'])); $instance["dateformat"] = strip_tags(stripslashes($new_instance['dateformat'])); $instance["notfound"] = strip_tags(stripslashes($new_instance['notfound'])); $instance["range"] = strip_tags(stripslashes($new_instance['range'])); $instance["private"] = strip_tags(stripslashes($new_instance['private'])); $instance["showpages"] = strip_tags(stripslashes($new_instance['showpages'])); $instance["anniversary"] = strip_tags(stripslashes($new_instance['anniv'])); $instance["posts_max"] = strip_tags(stripslashes($new_instance['posts_max'])); $instance["pattern"] = stripslashes($new_instance['pattern']); return $instance; } } }//!class_exists('ayb_posts_class') add_action('widgets_init', create_function('', 'return register_widget("ayb_posts_class");')); // function ayb_posts($ayb_para = array()) { $ayb_parameter = explode('&', $ayb_para); foreach ($ayb_parameter as $ayb_temp) { $b = split('=', $ayb_temp); $instance[$b[0]] = $b[1]; }//$ayb_parameter as $ayb_temp $widget_arr = array(); $ayb_man = new ayb_posts_class; $instance["no_widget"] = true; $ayb_man -> widget($widget_arr, $instance); } ?>