function _wpr_postseries_process() { global $wpdb; $last_cron_status = get_option("_wpr_postseries_process_status"); $currentTime = time(); set_time_limit(3600); /* When the cron is running the _wpr_postseries_process_status is set to the timestamp at which the cron processing was started. Before shutting down the _wpr_postseries_process_status is set to 'stopped'. This cron will run only if the _wpr_postseries_process_status option is set to "stopped" or is empty. */ $timeOfStart = time(); $timeMaximumExecutionTimeAgo = $timeOfStart - WPR_MAX_POSTSERIES_PROCESS_EXECUTION_TIME; if (!empty($last_cron_status) && $last_cron_status != "stopped") { $last_cron_status = intval($last_cron_status); if ($last_cron_status != 0 && $last_cron_status > $timeMaximumExecutionTimeAgo) { return; } } update_option("_wpr_postseries_process_status", $timeOfStart); $prefix = $wpdb->prefix; $getActiveFollowupSubscriptionsQuery = "SELECT a.*, b.id sid, FLOOR(({$currentTime} - a.doc)/86400) daysSinceSubscribing FROM `" . $prefix . "wpr_followup_subscriptions` a, `" . $prefix . "wpr_subscribers` b WHERE a.type='postseries' AND a.sequence < FLOOR(({$currentTime} - a.doc)/86400) AND a.sequence <> -2 AND a.sid=b.id AND b.active=1 AND b.confirmed=1 LIMIT 1000;"; $postseriesSubscriptionList = $wpdb->get_results($getActiveFollowupSubscriptionsQuery); foreach ($postseriesSubscriptionList as $psubscription) { $sid = $psubscription->sid; $query = "SELECT nid from " . $wpdb->prefix . "wpr_subscribers where id=" . $sid; $results = $wpdb->get_results($query); if (count($results) != 1) { //where's the newsletter?!! continue; } $nid = $results[0]->nid; $subscriber = _wpr_subscriber_get($psubscription->sid); //how many days since subscribing? $daysSinceSubscribing = floor((time() - $psubscription->doc) / 86400); //get the post series as an object $postseries = _wpr_postseries_get($psubscription->eid); //get the posts in the post series $posts = get_postseries_posts($postseries->catid, $nid); $numberOfPosts = count($posts); if ($numberOfPosts == 0) { _wpr_expire_followup($psubscription->id); continue; } $timeBetweenPosts = $postseries->frequency; $last_post = $psubscription->sequence; $currentIndex = floor($daysSinceSubscribing / $timeBetweenPosts); if ($currentIndex == $last_post) { continue; } //all posts have been sent. expire the post series subscription if ($last_post >= count($posts) - 1) { _wpr_expire_followup($psubscription->id); continue; } $indexToDeliver = $last_post + 1; $category = $psubscription->eid; $postToSend = $posts[$indexToDeliver]; $sitename = get_bloginfo("name"); $meta_key = sprintf("PS-%s-%s-%s", $psubscription->eid, $psubscription->sid, $postToSend->ID); $additionalParams = array('meta_key' => $meta_key); deliverBlogPost($sid, $postToSend->ID, "You are receiving this blog post as a part of a post series at {$name}.", true, true, $additionalParams); $query = "UPDATE " . $prefix . "wpr_followup_subscriptions set sequence={$indexToDeliver} , last_date='" . time() . "' where id='" . $psubscription->id . "';"; $wpdb->query($query); $timeThisInstant = time(); $timeSinceStart = $timeThisInstant - $timeOfStart; if ($timeSinceStart > WPR_MAX_POSTSERIES_PROCESS_EXECUTION_TIME) { return; } } update_option("_wpr_postseries_process_status", "stopped"); }
function _wpr_subscriptionforms_list() { global $wpdb; $tprefix = $wpdb->prefix; $query = "SELECT a.* FROM " . $tprefix . "wpr_subscription_form a, " . $tprefix . "wpr_newsletters b where a.nid=b.id;"; $forms = $wpdb->get_results($query); ?> <div class="wrap"> <h2>Subscription Forms</h2> </div> <script> function selectAllFormsCheckBox(state) { jQuery(".forms_check").attr({ checked: state}); } </script> <ul style="padding:20px;"> <li>Click on <em>Create New Form</em> button below to create a new subscription form. To place the newly created subscription form in the sidebar of your blog, go to the <a href="widgets.php">Widgets section</a>. To place the subscription form in a separate page or another website, copy the generated HTML code for the form and paste the code it in your own HTML page. </ul> <form name="formslist" action="admin.php?page=wpresponder/subscriptionforms.php&action=delete" method="post"> <table class="widefat" style="margin: 10px; margin:10px 0px;;"> <thead> <tr> <th><input type="checkbox" name="selectall" value="1" onclick="selectAllFormsCheckBox(this.checked);" /></th> <th scope="col">Name</th> <th>Newsletter</th> <th>Follow-Up</th> <th>Blog Subscription</th> <th scope="col">Actions</th> </tr> </thead> <?php if (count($forms) > 0) { foreach ($forms as $form) { ?> <tr> <td align="center"width="20"><input type="checkbox" name="forms[]" class="forms_check" value="<?php echo $form->id; ?> " /></td> <td><?php echo $form->name; ?> </td> <td><a href="admin.php?page=wpresponder/subscribers.php&action=nmanage&nid=<?php echo $form->nid; ?> "> <?php $newsletter = _wpr_newsletter_get($form->nid); echo $newsletter->name; ?> </a></td> <td><?php switch ($form->followup_type) { case 'postseries': $postseries = _wpr_postseries_get($form->followup_id); echo "Subscribe to the '" . $postseries->name . "' post series"; break; case 'autoresponder': $autoresponder = Autoresponder::getAutoresponder((int) $form->followup_id); echo sprintf("Subscribe to the '%s' autoresponder.", $autoresponder->getName()); break; case 'none': echo "None"; break; } ?> </td> <td><?php switch ($form->blogsubscription_type) { case 'cat': $category = get_category($form->blogsubscription_id); echo "Posts in the " . $category->name . " category"; break; case 'all': echo "All Blog Posts "; break; case 'none': echo "No blog subscription"; break; } ?> <td><a href="admin.php?page=wpresponder/subscriptionforms.php&action=edit&fid=<?php echo $form->id; ?> " class="button">Edit</a> <a href="admin.php?page=wpresponder/subscriptionforms.php&action=form&fid=<?php echo $form->id; ?> " class="button">Get Form HTML</a></td> </tr> <?php } } else { ?> <tr> <td colspan="10"><div align="center"><big>--No subscription forms defined. <a href="admin.php?page=wpresponder/subscriptionforms.php&action=create">Click here</a> to create one now--</big> </div></td> </tr> <?php } ?> </td></td> </table> <input type="submit" name="submit" value="Delete Forms" class="button" onclick="return confirm('Are you sure you want to delete the selected subscription forms?');" /> <input type="button" onclick="window.location='admin.php?page=wpresponder/subscriptionforms.php&action=create';" class="button" value="Create New Form"> </form> <?php }