function wiziapp_batch_posts_processing() { $GLOBALS['WiziappLog']->write('info', "Got a request to process posts as a batch: " . print_r($_POST, TRUE), "post_install.wiziapp_batch_posts_processing"); global $wpdb; $status = TRUE; $message = ''; if (!isset($_POST['posts'])) { $status = FALSE; $message = 'incorrect usage'; } else { ob_start(); ini_set('display_errors', 0); register_shutdown_function('wiziappBatchShutdown'); $postsIds = explode(',', $_POST['posts']); foreach ($postsIds as $id) { $GLOBALS['WiziappLog']->write('info', "Processing post: {$id} inside the batch", "post_install.wiziapp_batch_posts_processing"); $GLOBALS['wiziapp_post'] = $id; wiziapp_save_post($id); $GLOBALS['WiziappLog']->write('info', "Finished processing post: {$id} inside the batch", "post_install.wiziapp_batch_posts_processing"); } } $header = array('action' => 'batch_process_posts', 'status' => $status, 'code' => $status ? 200 : 500, 'message' => $message); $GLOBALS['WiziappLog']->write('debug', "Finished processing the requested post batch, going to return: " . print_r($_POST['posts'], TRUE) . ' ' . print_r($header, TRUE), "post_install.wiziapp_batch_posts_processing"); echo json_encode(array('header' => $header)); exit; }
/** * Called from the install method, to install the base content * that will be used at first for the simulator and for building the cms * profile * * After the initial processing the user will be able to trigger the processing * via his plugin control panel or when a post is requested for the first time */ function wiziapp_generate_latest_content() { global $wpdb; $done = false; $GLOBALS['WiziappLog']->write('info', "Parsing the latest content", "content"); // Parse the latest posts $number_recents_posts = WiziappConfig::getInstance()->post_processing_batch_size; $recent_posts = wp_get_recent_posts($number_recents_posts); $last_post = -1; foreach ($recent_posts as $post) { $post_id = $post['ID']; $GLOBALS['WiziappLog']->write('info', "Processing post: {$post_id}", 'content.wiziapp_generate_latest_content'); wiziapp_save_post($post_id); $last_post = $post_id; } $GLOBALS['WiziappLog']->write('info', "Processing all pages", 'content'); $pages = get_all_page_ids(); for ($p = 0, $total = count($pages); $p < $total; ++$p) { wiziapp_save_page($pages[$p]); } // Save the fact that we processed $number_recents_posts and if the number of posts // in the blog is bigger, we need to continue $numposts = $wpdb->get_var("SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_status = 'publish'"); if ($numposts <= $number_recents_posts) { $last_post = -1; } add_option("wiziapp_last_processed", $last_post); $GLOBALS['WiziappLog']->write('info', "Finished parsing initial content", 'content'); return $done; }
<?php wiziapp_get_header(); // Before handing the content, make sure this post is scanned $processed = get_post_meta($post->ID, 'wiziapp_processed'); if (empty($processed)) { wiziapp_save_post($post); } ?> <div class="page_content"> <div class="post"> <?php $pLink = wiziapp_buildPostLink($post->ID); ?> <h2 class="pageitem"> <a id="post_title" href="<?php echo $pLink; ?> " rel="bookmark" title="<?php the_title(); ?> "> <?php the_title(); ?> </a> </h2> <div class="pageitem"> <div class="single-post-meta-top"> <div id="author_and_date"><span class="postDescriptionCellItem_author">By <a href="<?php