function wp_auto_spinner_spin_function() { $autospin = get_option('wp_auto_spin', array()); $lastrun = get_option('wp_auto_spinner_last_run', 1392146043); $timenow = time('now'); $timediff = $timenow - $lastrun; if ($timediff < 60) { return; } update_option('wp_auto_spinner_last_run', $timenow); if (in_array('OPT_AUTO_SPIN_ACTIVE', $autospin)) { // log call //wp_auto_spinner_log_new ( 'cron call', 'we should now process one waiting to be spinned article' ); // get one post deserve spin // get execluded cateogries array $execl = get_option('wp_auto_spin_execl', array()); $post_status = array('publish', 'draft'); if (in_array('OPT_AUTO_SPIN_SCHEDULED', $autospin)) { $post_status = array('publish', 'future'); } // The Query $the_query = new WP_Query(array('category__not_in' => $execl, 'post_status' => $post_status, 'posts_per_page' => 1, 'ignore_sticky_posts' => true, 'post_type' => 'any', 'meta_query' => array(array('key' => 'wp_auto_spinner_scheduled', 'compare' => 'EXISTS'), array('key' => 'spinned_cnt', 'compare' => 'NOT EXISTS')))); // The Loop if ($the_query->have_posts()) { while ($the_query->have_posts()) { $the_query->the_post(); $newid = get_the_id(); if (trim($newid) == '') { return; } wp_auto_spinner_log_new('Cron Call >> top post ', get_the_id()); $post_id = get_the_id(); wp_auto_spinner_post_spin($post_id); break; } } else { // no posts found //wp_auto_spinner_log_new ( 'Cron >> Cancel', 'No waiting to be spinned posts' ); } /* Restore original Post Data */ wp_reset_postdata(); } else { } // wp_auto_spinner_the_content_filter() }
function wp_auto_spinner_publish($post_id) { // if quick edit mode ignore it . if (stristr($_SERVER['HTTP_REFERER'], 'edit.php')) { return; } global $post; //check if already checked if yes return $checked = get_post_meta($post_id, 'wp_auto_spinner_checked', 1); if (trim($checked) != '') { return; } //set checked flag to yes update_post_meta($post_id, 'wp_auto_spinner_checked', 'yes'); //INSTANT SPIN : manual + manual spin enabled or auto + auto spin enabled + spin on publish enabled $autospin = get_option('wp_auto_spin', array()); if (isset($_POST['publish']) && in_array('OPT_AUTO_SPIN_ACTIVE_MANUAL', $autospin) || !isset($_POST['publish']) && in_array('OPT_AUTO_SPIN_ACTIVE', $autospin) && in_array('OPT_AUTO_SPIN_PUBLISH', $autospin)) { //INSTANT SPIN wp_auto_spinner_log_new('New Post >> Publish', 'New post with id {' . $post_id . '} is going to be published and deserve spinning'); $execl = get_option('wp_auto_spin_execl', array()); if (in_category($execl, $post_id)) { wp_auto_spinner_log_new('New Post >> Cancel Spin', 'Post in an execluded from spinning category . ignore post .'); return; } else { wp_auto_spinner_post_spin($post_id); } } elseif (!isset($_POST['publish']) && in_array('OPT_AUTO_SPIN_ACTIVE', $autospin)) { //SCHEDULED SPIN wp_auto_spinner_log_new('New Post >> Publish', 'New post with id {' . $post_id . '} is going to be published sent to spin queue'); //add the scheduled spin meta update_post_meta($post_id, 'wp_auto_spinner_scheduled', 'yes'); } return; //Manual post check if (isset($_POST['publish'])) { update_post_meta($post_id, 'wp_auto_spinner_manual_flag', 'manual'); } //if publish action disabled return $opt = get_option('wp_auto_spin', array()); if (!in_array('OPT_AUTO_SPIN_PUBLISH', $opt)) { return; } //get the post $post_arr = get_post($post_id); //if no spin shortcode exists if (stristr($post_arr->post_content, '{nospin}')) { echo ' post contains no spin tag'; } wp_auto_spinner_log_new('New Post >> Publish', 'New post with id {' . $post_id . '} is going to be published'); //check if auto spin is enabled or not $autospin = get_option('wp_auto_spin', array()); if (!in_array('OPT_AUTO_SPIN_ACTIVE', $autospin)) { wp_auto_spinner_log_new('New Post >> Cancel Spin', 'Automated spinning is disabled . ignore post .'); return; } //check if it is already spinned checked $spinned = get_post_meta($post_id, 'wp_auto_spinner_spinned_flag', 1); if ($spinned == 'spinned') { wp_auto_spinner_log_new('New Post >> Cancel Spin', 'Post {' . $post_id . '} already passed spinning filter . ignore it'); return; } //check if it is manual and manual spin disabled if (isset($_POST['publish'])) { if (!in_array('OPT_AUTO_SPIN_ACTIVE_MANUAL', $autospin)) { update_post_meta($post_id, 'wp_auto_spinner_spinned_flag', true); wp_auto_spinner_log_new('New Post >> Cancel Spin', 'Manual post and manual posts spinning disabled . ignore post .'); return; } } //check if deserve spin or not $execl = get_option('wp_auto_spin_execl', array()); if (in_category($execl, $post_id)) { wp_auto_spinner_log_new('New Post >> Cancel Spin', 'Post in an execluded from spinning category . ignore post .'); return; } //let's spin this post $content = $post_arr->post_content; $ttl = $post_arr->post_title; $originalcontent = $content; //spin libs require_once dirname(__FILE__) . '/inc/class.spin.php'; require_once dirname(__FILE__) . '/inc/class.spintax.php'; //spin start $spin = new wp_auto_spin_spin($post_id, $ttl, $content); $spinned = $spin->spin(); //spinned cnt $spinned_ttl = $spinned['spinned_ttl']; $spinned_cnt = $spinned['spinned_cnt']; $spintaxed_ttl = $spinned['spintaxed_ttl']; $spintaxed_cnt = $spinned['spintaxed_cnt']; $content = $spintaxed_cnt; //update the post $my_post = array(); $my_post['ID'] = $post_id; $my_post['post_content'] = $content; //update spinned title if allowed if (in_array('OPT_AUTO_SPIN_ACTIVE_TTL', $autospin)) { $my_post['post_title'] = $spintaxed_ttl; @($post->post_title = $spintaxed_ttl); } //check if we should updat the slug . if (in_array('OPT_AUTO_SPIN_SLUG', $autospin)) { $my_post['post_name'] = ''; } //update it's status to spined update_post_meta($post_id, 'wp_auto_spinner_spinned_flag', 'spinned'); wp_auto_spinner_log_new('New Post >> Do Spin', 'Post with id {' . $post_id . '} spinned successfully .'); // Update the post into the database wp_update_post($my_post); }