Donate/Spenden: Flattr */ if (!defined('WP_CONTENT_URL')) define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); if (!defined('WP_CONTENT_DIR')) define('WP_CONTENT_DIR', ABSPATH . 'wp-content'); if (!defined('WP_PLUGIN_URL')) define('WP_PLUGIN_URL', WP_CONTENT_URL . '/plugins'); if (!defined('WP_PLUGIN_DIR')) define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins'); if (!defined('WP_LANG_DIR')) define('WP_LANG_DIR', WP_CONTENT_DIR . '/languages'); if (!class_exists('ayb_posts_class')) { class ayb_posts_class extends WP_Widget { var $pattern ; var $ayb_posts_domain = 'ayb_posts'; var $excerpt_length=140; function ayb_posts_class() { load_plugin_textdomain( 'ayb_posts', false, dirname(plugin_basename(__FILE__)) . '' ); if (function_exists('register_uninstall_hook')) register_uninstall_hook(__FILE__, array( &$this, 'on_delete' )); $widget_ops = array( 'classname' => 'ayb_posts', 'description' => __('Show articles a certain periode of time before', 'ayb_posts') ); $this->WP_Widget('ayb_posts', __('A Year Before'), $widget_ops); } function on_delete() { delete_option('ayb_posts'); } function pattern_output() { $subpattern_array = array( '/\%title\%/', '/\%date\%/', '/\%link\%/', '/\%excerpt(\d*)\%/' ); $var_array = array( $this->ptitle, $this->datum, $this->plink, $this->excerpt ); $r= preg_replace($subpattern_array, $var_array, $this->pattern); return $r; } function widget($args, $instance) { global $wpdb, $ayb_posts_domain; 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"]; 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; } //$key } //$instance as $key => $value $this->pattern = empty($instance['pattern']) ? __('
  • On %date%: Read %title% (%date%)
  • ', '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']); if ($dday == 0 && $dmonth == 0 && $dyear == 0) { $dyear = 1; } //$dday == 0 && $dmonth == 0 && $dyear == 0 $ts= current_time_fixed('timestamp',0); //$ayb_tz = ayb_sgn(get_option('gmt_offset') * (-1)) . get_option('gmt_offset') . " hour"; $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_dateget_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; 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; $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', 'notfound' => __('No articles on this date.','ayb_posts'), 'pattern' => $this->pattern ); $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"]; $pattern = htmlspecialchars($instance["pattern"]); echo 'Flattr this'; echo '

    '; 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["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) { $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); } ?>