Exemplo n.º 1
0
 public function trigger_source_data()
 {
     $feed_go = get_option(PF_SLUG . '_feeds_go_switch', 0);
     $feed_iteration = get_option(PF_SLUG . '_feeds_iteration', 0);
     $retrieval_state = get_option(PF_SLUG . '_iterate_going_switch', 0);
     $chunk_state = get_option(PF_SLUG . '_ready_to_chunk', 1);
     pf_log('Invoked: PF_Feed_Retrieve::trigger_source_data()');
     pf_log('Feeds go?: ' . $feed_go);
     pf_log('Feed iteration: ' . $feed_iteration);
     pf_log('Retrieval state: ' . $retrieval_state);
     pf_log('Chunk state: ' . $chunk_state);
     if ($feed_iteration == 0 && $retrieval_state == 0 && $chunk_state == 1) {
         $status = update_option(PF_SLUG . '_iterate_going_switch', 1);
         # Echo to the user.
         pf_log(__('Beginning the retrieval process', 'pf'), true, true);
         pf_iterate_cycle_state('retrieval_cycles_begun', true);
         if ($status) {
             pf_log(__('Iterate switched to going.', 'pf'));
         } else {
             pf_log(__('Iterate option not switched.', 'pf'));
         }
         pressforward()->pf_feed_items->assemble_feed_for_pull();
     } else {
         $feeds_meta_state = get_option(PF_SLUG . '_feeds_meta_state', array());
         if (empty($feeds_meta_state)) {
             $feeds_meta_state = array('feed_go' => $feed_go, 'feed_iteration' => $feed_iteration, 'retrieval_state' => $retrieval_state, 'chunk_state' => $chunk_state, 'retrigger' => time() + 2 * 60 * 60);
             update_option(PF_SLUG . '_feeds_meta_state', $feeds_meta_state);
             pf_log(__('Created new metastate.', 'pf'), true);
         } else {
             pf_log(__('Metastate saved and active for check.', 'pf'), true);
             pf_log($feeds_meta_state);
         }
         if ($feeds_meta_state['retrigger'] > time()) {
             pf_log(__('The sources are already being retrieved.', 'pf'), true);
         } else {
             if ($feed_go == $feeds_meta_state['feed_go'] && $feed_iteration == $feeds_meta_state['feed_iteration'] && $retrieval_state == $feeds_meta_state['retrieval_state'] && $chunk_state == $feeds_meta_state['chunk_state']) {
                 pf_log(__('The sources are stuck.', 'pf'), true);
                 # Wipe the checking option for use next time.
                 update_option(PF_SLUG . '_feeds_meta_state', array());
                 update_option(PF_SLUG . '_ready_to_chunk', 1);
                 update_option(PF_SLUG . '_iterate_going_switch', 1);
                 pressforward()->pf_feed_items->assemble_feed_for_pull();
             } elseif ($feeds_meta_state['retrigger'] < time() + 86400 && !empty($feeds_meta_state)) {
                 # If it has been more than 24 hours and retrieval has been frozen in place
                 # and the retrieval state hasn't been reset, reset the check values and reset
                 # the meta state. If it is actually mid-process things should progress.
                 # Otherwise next meta-state check will iterate forward.
                 update_option(PF_SLUG . '_feeds_go_switch', 0);
                 update_option(PF_SLUG . '_ready_to_chunk', 1);
                 update_option(PF_SLUG . '_feeds_meta_state', array());
                 update_option(PF_SLUG . '_iterate_going_switch', 0);
                 update_option(PF_SLUG . '_feeds_iteration', 0);
                 $double_check = array('feed_go' => 0, 'feed_iteration' => 0, 'retrieval_state' => 0, 'chunk_state' => 1, 'retrigger' => $feeds_meta_state['retrigger']);
                 update_option(PF_SLUG . '_feeds_meta_state', $double_check);
                 pf_log(__('The meta-state is too old. It is now reset. Next time, we should start over.', 'pf'), true);
             } else {
                 $double_check = array('feed_go' => $feeds_meta_state['feed_go'], 'feed_iteration' => $feed_iteration, 'retrieval_state' => $feeds_meta_state['retrieval_state'], 'chunk_state' => $feeds_meta_state['chunk_state'], 'retrigger' => $feeds_meta_state['retrigger']);
                 update_option(PF_SLUG . '_feeds_meta_state', $double_check);
                 pf_log($double_check);
                 pf_log(__('The sources are already being retrieved.', 'pf'), true);
             }
         }
     }
 }
Exemplo n.º 2
0
 public static function get_the_feed_object()
 {
     pf_log('Invoked: PF_Feed_Item::get_the_feed_object()');
     #$PF_Feed_Retrieve = new PF_Feed_Retrieve();
     # This pulls the RSS feed into a set of predetermined objects.
     # The rss_object function takes care of all the feed pulling and item arraying so we can just do stuff with the feed output.
     $theFeed = pressforward()->pf_retrieve->step_through_feedlist();
     if (!$theFeed || is_wp_error($theFeed)) {
         pf_log('The feed is false, exit process. [THIS SHOULD NOT OCCUR except at the conclusion of feeds retrieval.]');
         pf_iterate_cycle_state('retrieval_cycles_ended', true);
         # Wipe the checking option for use next time.
         update_option(PF_SLUG . '_feeds_meta_state', array());
         $chunk_state = update_option(PF_SLUG . '_ready_to_chunk', 1);
         exit;
     }
     return $theFeed;
 }
Exemplo n.º 3
0
    function admin_menu_callback()
    {
        global $wpdb;
        // Default log location is in the uploads directory
        if (!defined('PF_DEBUG_LOG')) {
            $upload_dir = wp_upload_dir();
            $log_path = $upload_dir['basedir'] . '/pressforward.log';
        } else {
            $log_path = PF_DEBUG_LOG;
        }
        $action_count = $wpdb->get_results("SELECT COUNT(*) FROM {$wpdb->prefix}pf_relationships", ARRAY_A);
        $ntp_args = array('posts_per_page' => -1, 'meta_key' => 'item_link');
        $nominated_to_posts = get_posts($ntp_args);
        $nomed_posts = count($nominated_to_posts);
        ?>
		<div class="wrap">
			<h2>Current Log</h2>
			<?php 
        #var_dump($feed_items_query->post_count);
        ?>
			<p>Does not update in real time.</p>
			<p>Total Current Feed Items:
			<?php 
        $feed_item = 'pf_feed_item';
        echo wp_count_posts($feed_item)->publish;
        #var_dump(wp_count_posts($feed_item));
        #var_dump(wp_count_posts('post'));
        ?>
<br />
			<?php 
        $feed_item = 'pf_feed_item';
        echo 'Month to date Feed Items: ' . $this->count_the_posts($feed_item);
        echo '<br />Last month Feed Items: ' . $this->count_the_posts($feed_item, -1);
        #var_dump(wp_count_posts($feed_item));
        #var_dump(wp_count_posts('post'));
        ?>
			</p>
			<p>Total Current Nominations:
			<?php 
        # var_dump(wp_count_posts('nomination'));
        echo wp_count_posts('nomination')->draft;
        echo '<br />Month to date Nominations: ' . $this->count_the_posts('nomination');
        echo '<br />Last month Nominations: ' . $this->count_the_posts('nomination', -1);
        ?>
			</p>
			<p>Total Actions Taken:
			<?php 
        echo current($action_count[0]);
        #echo $action_count;
        ?>
			</p>
			<p>Total Nominations Published:
			<?php 
        echo $nomed_posts;
        #var_dump($nomed_posts );
        ?>
			</p>
			<p>Total Retrieval Chunks Begun This:
			<?php 
        pf_iterate_cycle_state('retrieval_chunks_begun', false, true);
        #var_dump($nomed_posts );
        ?>
			</p>
			<p>Total Retrieval Cycles Begun This:
			<?php 
        pf_iterate_cycle_state('retrieval_cycles_begun', false, true);
        #var_dump($nomed_posts );
        ?>
			</p>
			<p>Total Retrieval Cycles Ended This:
			<?php 
        pf_iterate_cycle_state('retrieval_cycles_ended', false, true);
        #var_dump($nomed_posts );
        ?>
			</p>
			<br /><br />
			<?php 
        if (file_exists($log_path)) {
            echo '<pre>';
            echo file_get_contents($log_path);
            echo '</pre>';
        } else {
            echo "The log does not exist.";
        }
        ?>
		</div>
		<?php 
    }