Soon...
=')) add_action('wp_dashboard_setup', 'dashboard_atd_init');
add_action( 'plugins_loaded', 'widget_atd_init' );
function around_this_date( $daysbefore, $daysafter, $mode, $yearsago, $lastxyears, $sinceyear, $limit, $none, $showyear, $showdate, $dateformat, $showexcerpt) {
$outputlist = ''; // empty the 'outputlist' string
$outputlist .= '
';
switch ($mode) {
case 1: // "classic" mode
$start_ago = (365*$yearsago)+$daysbefore;
$end_ago = (365*$yearsago)-$daysafter;
$year = date("Y")-$yearsago;
$liststart = '- ';
$listend = '
';
if ($showyear) {
$liststart .= $year;
}
$outputlist .= $liststart;
$outputlist .= get_old_posts( $start_ago, $end_ago, $limit, $none, $showyear, $showdate, $dateformat, $showexcerpt);
$outputlist .= $listend;
break;
case 2: // last x years mode
for($year = 1; $year <= $lastxyears; $year++) {
$start_ago = (365*$year)+$daysbefore;
$end_ago = (365*$year)-$daysafter;
$liststart = '- ';
$listend = '
';
if ($showyear) {
$liststart .= (date("Y")-$year);
}
$outputlist .= $liststart;
$outputlist .= get_old_posts( $start_ago, $end_ago, $limit, $none, $showyear, $showdate, $dateformat, $showexcerpt);
$outputlist .= $listend;
}
break;
case 3: // since year x mode
for($year = 1; $year <= (date("Y")-$sinceyear); $year++)
{
$start_ago = (365*$year)+$daysbefore;
$end_ago = (365*$year)-$daysafter;
$liststart = '- ';
$listend = '
';
if ($showyear) {
$liststart .= (date("Y")-$year);
}
$outputlist .= $liststart;
$outputlist .= get_old_posts( $start_ago, $end_ago, $limit, $none, $showyear, $showdate, $dateformat, $showexcerpt);
$outputlist .= $listend;
}
break;
}
$outputlist .= '
';
echo $outputlist;
}
function get_old_posts( $start_ago, $end_ago, $limit, $none, $showyear, $showdate, $dateformat, $showexcerpt )
{
global $wpdb;
global $wp_version;
$q = "SELECT ID, post_title, post_date, post_excerpt, post_content FROM $wpdb->posts ";
$q .= " WHERE post_status = 'publish'";
if (version_compare($wp_version, '2.1', '>='))
$q .= " AND post_type = 'post'";
$q .= $wpdb->prepare(" AND (( TO_DAYS( NOW() ) - TO_DAYS( post_date ) ) BETWEEN %d AND %d )", $end_ago, $start_ago);
$q .= " ORDER BY post_date ASC";
$q .= $wpdb->prepare(" LIMIT %d", $limit);
$entries = $wpdb->get_results($q);
$output = ''; // empty the 'output' string
$output .= '';
if (!empty($entries))
{
foreach ($entries as $entry) {
$title = htmlspecialchars($entry->post_title);
$title = str_replace('"' || '"e;', '',$title);
if($showdate) {
$postdate = ' - ' .mysql2date($dateformat,$entry->post_date). '';
} else {
$postdate = '';
}
if($showexcerpt) {
if (empty($entry->post_excerpt))
{
$entry->post_excerpt = explode(" ",strrev(substr(strip_tags($entry->post_content), 0, 100)),2);
$entry->post_excerpt = strrev($entry->post_excerpt[1]);
$entry->post_excerpt.= " [...]";
}
$postexcerpt = htmlspecialchars($entry->post_excerpt);
$postexcerpt = '
' . $postexcerpt . '';
} else {
$postexcerpt = $entry->post_excerpt;
}
$postexcerpt = preg_replace( '|\[(.+?)\](.+?\[/\\1\])?|s', '', $postexcerpt );
$classes = ' atd-y'. mysql2date('Y',$entry->post_date). ' atd-m'. mysql2date('m',$entry->post_date). ' atd-d' .
mysql2date('d',$entry->post_date) . ' atd-' . mysql2date('Ymd',$entry->post_date) . '';
$output .= '- ' . htmlspecialchars($entry->post_title) . ' ' . $postdate . ' ' . $postexcerpt . '
';
}
} else {
$output .= '- ' . $none. '
';
}
$output .= '
';
return $output;
}
/* Widget options */
function widget_atd_options() {
$defaults = array(
'title' => 'This week last year...',
'daysbefore' => 3,
'daysafter' => 3,
'mode' => 1,
'yearsago' => 1,
'lastxyears' => 1,
'sinceyear' => 2006,
'limit' => 4,
'none' => 'none',
'showyear' => true,
'showdate' => false,
'dateformat' => 'F j',
'showexcerpt' => false
);
$options = (array) get_option('widget_atd');
foreach ( $defaults as $key => $value )
if ( !isset($options[$key]) )
$options[$key] = $defaults[$key];
return $options;
}
function widget_atd_display( $args ) {
extract( $args );
$options = widget_atd_options();
echo $before_widget . $before_title . $options['title'] . $after_title;
around_this_date( $options['daysbefore'], $options['daysafter'], $options['mode'], $options['yearsago'], $options['lastxyears'],
$options['sinceyear'], $options['limit'], $options['none'], $options['showyear'], $options['showdate'], $options['dateformat'],
$options['showexcerpt'] );
echo $after_widget;
}
function widget_atd_control() {
$options = $newoptions = widget_atd_options();
if ($_POST['atd-submit'])
{
$newoptions['title'] = strip_tags(stripslashes($_POST['atd-title']));
$newoptions['daysbefore'] = strip_tags(stripslashes($_POST['atd-daysbefore']));
$newoptions['daysafter'] = strip_tags(stripslashes($_POST['atd-daysafter']));
$newoptions['mode'] = strip_tags(stripslashes($_POST['atd-mode']));
$newoptions['yearsago'] = strip_tags(stripslashes($_POST['atd-yearsago']));
$newoptions['sinceyear'] = strip_tags(stripslashes($_POST['atd-sinceyear']));
$newoptions['lastxyears'] = strip_tags(stripslashes($_POST['atd-lastxyears']));
$newoptions['limit'] = strip_tags(stripslashes($_POST['atd-limit']));
$newoptions['none'] = strip_tags(stripslashes($_POST['atd-none']));
$newoptions['showyear'] = isset($_POST['atd-showyear']);
$newoptions['showdate'] = isset($_POST['atd-showdate']);
$newoptions['dateformat'] = strip_tags(stripslashes($_POST['atd-dateformat']));
$newoptions['showexcerpt'] = isset($_POST['atd-showexcerpt']);
}
if ( $options != $newoptions )
{
$options = $newoptions;
update_option('widget_atd', $options);
}
$title = attribute_escape($options['title']);
$daysbefore = (int) $options['daysbefore'];
$daysafter = (int) $options['daysafter'];
$mode = (int) $options['mode'];
$yearsago = (int) $options['yearsago'];
$sinceyear = (int) $options['sinceyear'];
$lastxyears = (int) $options['lastxyears'];
$limit = (int) $options['limit'];
$none = attribute_escape($options['none']);
$showyear = ($options['showyear'] ? 'checked="checked"' : '');
$showdate = ($options['showdate'] ? 'checked="checked"' : '');
$dateformat = attribute_escape($options['dateformat']);
$showexcerpt = ($options['showexcerpt'] ? 'checked="checked"' : '');
?>