Example #1
0
/**
 * Remove our scheduled function from WP and stop the IMAP loop.
 */
function bp_rbe_deactivate()
{
    // stop IMAP connection if active
    if (bp_rbe_is_connected()) {
        bp_rbe_stop_imap();
        // give plugin a chance to stop IMAP connection as it could be sleeping
        sleep(10);
        bp_rbe_log('Daisy, Daisy, give me your answer, do...');
    }
    // remove remnants from any previous failed attempts to stop the inbox
    bp_rbe_cleanup();
    bp_rbe_log('Plugin deactivated!');
}
Example #2
0
    /**
     * Outputs next scheduled run of the (pseudo) cron.
     */
    protected function schedule()
    {
        // only show the following if required fields are filled in correctly
        if (bp_rbe_is_required_completed() && !bp_rbe_is_inbound()) {
            $is_connected = bp_rbe_is_connected();
            ?>
		<h3><?php 
            _e('Connection Info', 'bp-rbe');
            ?>
</h3>

		<p class="<?php 
            echo $is_connected ? 'connected' : 'not-connected';
            ?>
">
			<?php 
            if ($is_connected) {
                ?>
				<?php 
                _e('<strong>Reply By Email</strong> is currently <span>CONNECTED</span> and checking your inbox continuously.', 'bp-rbe');
                ?>
			<?php 
            } else {
                ?>
				<?php 
                _e('<strong>Reply By Email</strong> is currently <span>NOT CONNECTED</span>.  Please refresh the page to initiate a connection.', 'bp-rbe');
                ?>
			<?php 
            }
            ?>
		</p>

	<?php 
        }
    }
/**
 * Listens to requests to check the IMAP inbox.
 *
 * If a POST request is made to check the IMAP inbox, RBE will actually
 * process this request in this function.  We also make sure that WP-cron is
 * running before pinging the IMAP inbox.
 *
 * @since 1.0-RC3
 *
 * @see bp_rbe_spawn_inbox_check()
 */
function bp_rbe_run_inbox_listener()
{
    if (empty($_POST['_bp_rbe_check'])) {
        return;
    }
    // make sure WP-cron isn't running
    if (defined('DOING_CRON') || isset($_GET['doing_wp_cron'])) {
        return;
    }
    if (bp_rbe_is_connecting(array('clearcache' => true))) {
        return;
    }
    if (bp_rbe_is_connected()) {
        return;
    }
    bp_rbe_add_imap_lock();
    // run our inbox check
    $imap = BP_Reply_By_Email_IMAP::init();
    $imap = $imap->run();
    // Do not run the inbox check again on failure.
    if (false === $imap) {
        remove_action('shutdown', 'bp_rbe_spawn_inbox_check');
    }
    // kill the rest of this page
    die;
}
 /**
  * Connects to the IMAP inbox.
  *
  * @return bool
  */
 private function connect()
 {
     bp_rbe_log('--- Attempting to start new connection... ---');
     // if our DB marker says we're already connected, stop now!
     // this is an extra precaution
     if (bp_rbe_is_connected()) {
         bp_rbe_log('--- RBE is already connected! ---');
         return false;
     }
     // Let's open the IMAP stream!
     $this->connection = BP_Reply_By_Email_Connect::init();
     // couldn't connect :(
     if ($this->connection === false) {
         bp_rbe_log('Cannot connect: ' . imap_last_error());
         bp_rbe_remove_imap_lock();
         bp_rbe_remove_imap_connection_marker();
         return false;
     }
     // add an entry in the DB to say that we're connected
     //bp_update_option( 'bp_rbe_is_connected', time() + bp_rbe_get_execution_time() );
     bp_rbe_add_imap_connection_marker();
     bp_rbe_log('--- Connection successful! ---');
     return true;
 }