0) && ($hours_passed <= $onlyafter)) {
return;
}
global $wpdb;
$tp = $wpdb->prefix;
// Currently using a work-around for the version system
// determines if pre or post 2.3 from wp_term_taxonomy
$ver = 2.2;
$wpv = $wpdb->get_results("show tables like '{$tp}term_taxonomy'");
if (count($wpv) > 0) {
$ver = 2.3;
}
$the_cat = '(' . trim(get_option('ddps_cat'), ',') . ')';
if ($the_cat == "()") {
$oldest_post = $wpdb->get_var("
SELECT ID
FROM {$tp}posts
WHERE post_type = 'post'
AND post_status = 'publish'
GROUP BY post_date asc
");
} else {
if ($ver < 2.3) {
$oldest_post = $wpdb->get_var("
SELECT ID
FROM {$tp}posts, {$tp}post2cat
WHERE {$tp}post2cat.category_id IN " . $the_cat . "
AND post_type = 'post'
AND {$tp}posts.post_status = 'publish'
AND {$tp}post2cat.post_id = {$tp}posts.ID
GROUP BY post_date asc
");
} else { // post 2.3+
$oldest_post = $wpdb->get_var("
SELECT ID
FROM {$tp}posts, {$tp}term_relationships, {$tp}term_taxonomy
WHERE {$tp}term_taxonomy.term_id IN " . $the_cat . "
AND {$tp}term_taxonomy.term_taxonomy_id = {$tp}term_relationships.term_taxonomy_id
AND {$tp}term_relationships.object_id = {$tp}posts.ID
AND {$tp}posts.post_type = 'post'
AND {$tp}posts.post_status = 'publish'
GROUP BY post_date asc
");
}
}
if ($oldest_post > 0) { # we have a post to shift
# what wordpress func to call for setting post_name instead?
$post_title = $wpdb->get_var("
SELECT post_title
FROM {$tp}posts
WHERE ID = '$oldest_post'
");
# what wordpress func to call for setting post_name instead?
$new_time = date('Y-m-d H:i:s');
$wpdb->query("UPDATE $wpdb->posts SET post_date = '$new_time' WHERE ID = '$oldest_post'");
wp_publish_post($oldest_post);
SDP_log(strftime("%D %T") . "\t" . $tp . "\tPOST id " . $selected_draft . " SHIFTED '" . $post_title . "'\n");
} else {
PS_log(strftime("%D %T") . "\t\t" . $tp . "\tUnable to find a post to shift.\n");
}
}
function more_reccurences() {
return array(
'ddps_schedule' => array('interval' => ((int)get_option('ddps_delay') * 3600), 'display' => 'Post Shift Schedule')
);
}
function PS_log($PS_log_output)
{
$logfile=get_option('ddps_logfile');
$fh = @fopen($logfile, "a");
@fwrite($fh, $PS_log_output);
@fclose($fh);
}
function PS_get_last_log_entries()
{
$logfile=get_option('ddps_logfile');
$lines = @file($logfile);
if($lines === false){
echo "Error reading log file (".$logfile.").