get_option('eco_auto_which'), 'status' => get_option('eco_auto_status'), 'last' => get_option('eco_auto_last'), 'units' => get_option('eco_auto_units') ); update_option('eco_version', ECOVERSION); update_option('eco_discussion', $old_options['which']); update_option('eco_status', $old_options['status']); if ('comments' == $old_options['units']) { update_option('eco_for', 'for-comments'); update_option('eco_number-comments', $old_options['last']); } else { update_option('eco_for', 'for-last'); update_option('eco_last', $old_options['last']); update_option('eco_units', $old_options['units']); } $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'eco_auto_which'"); $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'eco_auto_status'"); $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'eco_auto_last'"); $wpdb->query("DELETE FROM $wpdb->options WHERE option_name = 'eco_auto_units'"); } $auto_check = ctype_digit(wp_next_scheduled('eco_auto')); if (false == $auto_check) { $auto_check = ( 'auto' == get_option('eco_auto') ) ? true : false; } //if ($auto_check == true) { $options = array( 'auto' => get_option('eco_auto'), 'which' => get_option('eco_discussion'), 'status' => get_option('eco_status'), 'for' => get_option('eco_for'), 'last' => get_option('eco_last'), 'units' => get_option('eco_units'), 'day' => get_option('eco_day'), 'month' => get_option('eco_month'), 'year' => get_option('eco_year'), 'beforeafter' => get_option('eco_beforeafter'), 'db_excluded_posts' => get_option('eco_excluded_posts'), 'number-comments' => get_option('eco_number-comments'), 'next_time' => wp_next_scheduled('eco_auto') ); $options['message_which'] = ($options['which'] == 'both') ? 'Comments and pings' : ucwords($options['which']); $options['opposite_status'] = ($options['status'] == 'open') ? 'closed' : 'open'; $options['status_pp'] = ($options['status'] == 'open') ? 'opened' : 'closed'; $options['opp_pp'] = ($options['opposite_status'] == 'open') ? 'opened' : 'closed'; //} function eco_extended_comments_options() { if (function_exists('add_options_page') ) add_submenu_page('edit-comments.php', 'Extended Comment Options', 'Batch Status', 8, basename(__FILE__), 'comment_conf'); // The first argument does into the
An error has occurred:
'; echo "$err_message
"; echo 'No comments or pings have been opened or closed.
'; echo 'Comment options received.
{$options['message_which']} on posts made before $date are {$options['status']} on this blog.
"; break; case 'for-last': if ('posts' == $options['units']) { echo "{$options['message_which']} are {$options['status']} on all but the last {$options['last']} posts.
"; } else { $display_units = (1 == $options['last']) ? rtrim($options['units'], 's') : $options['units']; echo "{$options['message_which']} are {$options['status']} on posts older than {$options['last']} $display_units.
"; } break; case 'for-comments': echo "{$options['message_which']} are {$options['status']} on posts with more than {$options['number-comments']} comments.
"; break; } if ( !empty($options['db_excluded_posts']) ) { echo "\tThe following posts won’t be changed
$value) {
$eco_POST_html[$key] = wp_specialchars($value);
}
echo '$_POST:'."\n"; print_r($eco_POST_html); echo "\n";
foreach ($eco_clean as $key => $value) {
$eco_clean_html[$key] = wp_specialchars($value);
}
echo '$eco_clean:'."\n"; print_r($eco_clean_html); echo "\n";
echo '$eco_html' . "\n";
print_r($eco_html);
echo "\n";
echo "These are the arguments supplied to eco_query():\n";
echo 'ECO_QUERYVARS: ' . ECO_QUERYVARS . "\n";
if ( defined('ECO_QUERYVARS2') ) {
echo 'ECO_QUERYVARS2: ' . ECO_QUERYVARS2 . "\n";
}
echo "\nSQL query(-ies) sent to the database\n";
echo 'ECO_SQL: ' . ECO_SQL . "\n";
if ( defined('ECO_SQL2') ) {
echo 'ECO_SQL2: ' . ECO_SQL2 . "\n";
}
echo "\n" . '$eco_message:' . "\n" . wp_specialchars($eco_message) . "\n\n";
if (!empty($options)) {
foreach($options as $key => $value) {
$options[$key] = wp_specialchars($value);
}
echo "\n".'$options:'."\n"; print_r($options);
}
?>12, 34, 129');
}
// If it's X comments then close, and it's not a number.
if ( ($eco_clean['for'] == 'for-comments') && ($eco_clean['number-comments'] == 'error') ) {
eco_error('Please enter the number of comments as a number.');
}
/*
*
*
* ----------------------------------------- UPDATE OPTIONS and SEND QUERY ---------------------------------------------------------
*
*
*
*/
// -------------------------------- WORKHORSE: Where the changes are actually made --------------------------------
if ('cancel-auto' != $eco_clean['for']) {
// If excluded posts have changed since they were last entered AND if the one-click options haven't been used
if ( $eco_clean['posts'] != get_option('eco_excluded_posts') ) {
update_option('eco_excluded_posts', $eco_clean['posts']);
}
update_option('eco_for', $eco_clean['for']);
}
update_option('eco_status', $eco_clean['status']);
update_option('eco_discussion', $eco_clean['which']);
$eco_auto_cancel = false;
switch ($eco_clean['for']) {
// IF CANCEL ARRANGEMENT SELECTED
case 'cancel-auto' :
eco_cancel_auto();
$eco_message = 'Your automatic arrangment has been cancelled. No comments or pings have been opened or closed.';
break;
// IF 'ALL EXISTING POSTS' SELECTED
case 'for-all' :
if (true == $eco_clean['auto']) {
default_comments_status($eco_clean['which'], $eco_clean['status']);
}
eco_query($eco_clean['which'], $eco_clean['status'], null, null, $eco_clean['posts']);
$eco_message =
"{$eco_html['message_which']} for all existing posts have been set to "
. " {$eco_html['status']}.";
break;
// IF 'BEFORE / AFTER' SELECTED
case 'for-bora' :
if ('before' == $eco_clean['beforeafter']) {
// We apply the status to the posts made before the date
eco_query($eco_clean['which'], $eco_clean['status'], 'before', $eco_clean['date'], $eco_clean['posts']);
// Then we apply the opposite to the posts made after the date, and change the default to opposite.
eco_query($eco_clean['which'], $eco_clean['opposite_status'], 'after', $eco_clean['date'], $eco_clean['posts']);
if (true == $eco_clean['auto']) {
default_comments_status($eco_clean['which'], $eco_clean['opposite_status']);
}
} elseif ('after' == $eco_clean['beforeafter']) {
// We apply the opposite status to the posts made before the date
eco_query($eco_clean['which'], $eco_clean['opposite_status'], 'before', $eco_clean['date'], $eco_clean['posts']);
// Then we apply the status to the posts made after the date, and change the default to status
eco_query($eco_clean['which'], $eco_clean['status'], 'after', $eco_clean['date'], $eco_clean['posts']);
if (true == $eco_clean['auto']) {
default_comments_status($eco_clean['which'], $eco_clean['status']);
}
}
$day = date('d', strtotime($eco_clean['date']));
$month = date('m', strtotime($eco_clean['date']));
$year = date('Y', strtotime($eco_clean['date']));
update_option('eco_day', $day);
update_option('eco_month', $month);
update_option('eco_year', $year);
update_option('eco_beforeafter', $eco_clean['beforeafter']);
$eco_message =
"{$eco_html['message_which']} for posts made "
. "{$eco_html['beforeafter']} " . date('jS F, Y', strtotime($eco_clean['date'])) . ""
. " are now {$eco_html['status']}.";
break;
// IF 'LAST X' SELECTED
case 'for-last' :
if (true == $eco_clean['auto']) {
default_comments_status($eco_clean['which'], $eco_clean['opposite_status']);
}
update_option('eco_status', $eco_clean['status']);
// Last X posts
if ( $eco_clean['units'] == 'posts' ) {
$count = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE `post_status` = 'publish' AND `post_type` = 'post'");
if ( $eco_clean['last'] > $count ) {
if ( $count == '1' ) {
eco_error("You can't change the last {$eco_html['last']} posts because there is only 1 post!");
} else {
eco_error("You can't change the last {$eco_html['last']} posts because there are only $count posts!");
}
} else {
// do the selected to all posts, then apply the opposite to the right ones
// This is because of the wording of the admin panel (STATUS all but the last ... means do STATUS to all, then OPPOSITE to the last ...)
eco_query($eco_clean['which'], $eco_clean['status'], null, null, $eco_clean['posts']);
eco_query($eco_clean['which'], $eco_clean['opposite_status'], 'last', $eco_clean['last'], $eco_clean['posts']);
update_option('eco_units', 'posts');
update_option('eco_last', $eco_clean['last']);
}
// Last X days/weeks/months/years
} else {
$eco_clean['date'] = date_from_last($eco_clean['last'], $eco_clean['units']);
eco_query($eco_clean['which'], $eco_clean['status'], 'before', $eco_clean['date'], $eco_clean['posts']);
eco_query($eco_clean['which'], $eco_clean['opposite_status'], 'after', $eco_clean['date'], $eco_clean['posts']);
update_option('eco_units', $eco_clean['units']);
update_option('eco_last', $eco_clean['last']);
}
if ('posts' == $eco_clean['units']) {
$eco_message = 'Comments and pings for the '
. "last {$eco_html['last']} {$eco_html['units']} "
. "are now {$eco_html['opposite_status']}. The rest have been {$eco_html['status_pp']}.";
} else {
if ('1' == $eco_clean['last']) {
$eco_html['units'] = rtrim($eco_html['units'], 's'); // cut off the last S if there's only 1!
}
$eco_message = "Comments and pings for posts made "
. "before " . date('jS F, Y', strtotime($eco_clean['date'])) . " ({$eco_html['last']} {$eco_html['units']} ago)"
. " are now {$eco_html['status']}.";
}
/*
Updating automatic settings
If there is already a arrangement in place, update options
If there is no arrangement, update options and schedule the arrangement if the units aren't posts
*/
// If the option for automatic hasn't been selected, or if there isn't already one in place, these won't be executed.
if (true == $eco_clean['auto'] || true == $auto_check) {
}
break;
// IF 'MORE THAN X COMMENTS' SELECTED
case 'for-comments' :
if (true == $eco_clean['auto']) {
default_comments_status($eco_clean['which'], $eco_clean['opposite_status']);
}
update_option('eco_number-comments', $eco_clean['number-comments']);
eco_query($eco_clean['which'], $eco_clean['status'], 'comments', $eco_clean['number-comments'], $eco_clean['posts']);
$eco_message =
"{$eco_html['message_which']} for posts with more than "
. "{$eco_html['number-comments']} comments and/or pings are now {$eco_html['status']}.";
break;
} //end switch
if (true == $eco_clean['auto']) {
update_option('eco_auto', 'auto');
if ('for-last' == $eco_clean['for']) {
// Only schedule the auto thing if it's a unit of time
if ('posts' == $eco_clean['units']) {
$eco_message =
"{$eco_html['message_which']} will be {$eco_html['opposite_status']} on the "
. " {$eco_html['last']} most recent posts."
. " {$eco_html['message_which']} on older posts will be {$eco_html['status_pp']} each time a new post is published.";
} else {
// If there isn't already a schedule in place, put one in place
// Can't use $auto_check because it's true at this point
if (false == ctype_digit(wp_next_scheduled('eco_auto'))) {
wp_clear_scheduled_hook('eco_auto');
wp_schedule_event(strtotime('midnight'), 'daily', 'eco_auto'); // first time to run is midnight
}
$eco_message =
"{$eco_html['message_which']} on posts older than {$eco_html['last']} {$eco_html['units']} will be ".
" {$eco_html['status_pp']} automatically.";
}
} elseif ('for-comments' == $eco_clean['for']) {
$eco_message =
"{$eco_html['message_which']} will be {$eco_html['status_pp']} "
. " on a post once {$eco_html['number-comments']} comments and/or pings have been left on it.";
}
} else {
eco_cancel_auto();
}
// -------------------------------- SHOW THE RESULTS OF THE QUERY TO THE USER --------------------------------
?>