Esempio n. 1
0
 /**
  * This determines what to show in each column on this page: edit.php?post_type=datafeedr-productset
  */
 function column_fields($column, $post_id)
 {
     $post = $GLOBALS['post'];
     $meta = get_post_custom($post_id);
     $update_phase = intval($meta['_dfrps_cpt_update_phase'][0]);
     $next_update_time = isset($meta['_dfrps_cpt_next_update_time'][0]) ? $meta['_dfrps_cpt_next_update_time'][0] : 0;
     $started = isset($meta['_dfrps_cpt_last_update_time_started'][0]) ? $meta['_dfrps_cpt_last_update_time_started'][0] : 0;
     $completed = isset($meta['_dfrps_cpt_last_update_time_completed'][0]) ? $meta['_dfrps_cpt_last_update_time_completed'][0] : 0;
     $products_added = isset($meta['_dfrps_cpt_last_update_num_products_added'][0]) ? number_format(intval($meta['_dfrps_cpt_last_update_num_products_added'][0])) : 0;
     $api_requests = isset($meta['_dfrps_cpt_last_update_num_api_requests'][0]) ? number_format(intval($meta['_dfrps_cpt_last_update_num_api_requests'][0])) : 0;
     $products_deleted = isset($meta['_dfrps_cpt_last_update_num_products_deleted'][0]) ? number_format(intval($meta['_dfrps_cpt_last_update_num_products_deleted'][0])) : 0;
     $update_errors = isset($meta['_dfrps_cpt_errors'][0]) ? unserialize($meta['_dfrps_cpt_errors'][0]) : '';
     $registered_cpts = get_option('dfrps_registered_cpts', array());
     $type = isset($registered_cpts[$meta['_dfrps_cpt_type'][0]]['name']) ? $registered_cpts[$meta['_dfrps_cpt_type'][0]]['name'] : $meta['_dfrps_cpt_type'][0];
     $type = '<div class="dfrps_cpt_type" title="This Product Set imports into the ' . esc_attr('"' . $meta['_dfrps_cpt_type'][0] . '"') . ' post type.">' . $type . '</div>';
     // Display 'inactive' message and CSS class for any type that is no longer registered.
     $active_status = dfrps_set_is_active($meta['_dfrps_cpt_type'][0]) ? '<div class="dfrps_cpt_active" title="This Product Set is active and regularly performing product imports/updates.">Active</div>' : '<div class="dfrps_cpt_inactive" title="This Product Set is no longer importing/updating products.">Inactive</div>';
     switch ($column) {
         case 'created':
             $post_date = dfrps_date_in_two_rows($post->post_date);
             echo '<abbr title="' . __('This Product Set was created on ', DFRPS_DOMAIN) . $post->post_date . '">' . $post_date . '</abbr>';
             break;
         case 'modified':
             $post_modified = dfrps_date_in_two_rows($post->post_modified);
             echo '<abbr title="' . __('This Product Set was modified on ', DFRPS_DOMAIN) . $post->post_modified . '">' . $post_modified . '</abbr>';
             break;
         case 'post_status':
             // Most of this code taken from:
             // ~/wp-admin/includes/class-wp-posts-list-table.php
             if ('0000-00-00 00:00:00' == $post->post_date) {
                 $time_diff = 0;
             } else {
                 $time = get_post_time('G', true, $post);
                 $time_diff = time() - $time;
             }
             echo '<div class="dfrps_post_status">';
             if ('publish' == $post->post_status) {
                 _e('Published', DFRPS_DOMAIN);
             } elseif ('future' == $post->post_status) {
                 if ($time_diff > 0) {
                     echo '<strong class="attention">' . __('Missed schedule', DFRPS_DOMAIN) . '</strong>';
                 } else {
                     _e('Scheduled', DFRPS_DOMAIN);
                 }
             } else {
                 _e('Unpublished', DFRPS_DOMAIN);
             }
             _e('</div>');
             echo $type;
             echo $active_status;
             break;
         case '_dfrps_cpt_next_update_time':
             if ($post->post_status == 'publish') {
                 if ($next_update_time == 0) {
                     echo '<abbr title="' . __('This Product Set will update as soon as possible.', DFRPS_DOMAIN) . '">ASAP</abbr>';
                 } else {
                     //echo date_i18n( 'M d, g:ia', $next_update_time );
                     //$next_update_time = dfrps_date_in_two_rows( $next_update_time );
                     echo '<abbr title="' . __('This Product Set will update on (or after) ', DFRPS_DOMAIN) . date_i18n('Y-m-d G:i:s', $next_update_time) . '">' . dfrps_date_in_two_rows($next_update_time) . '</abbr>';
                 }
             } else {
                 echo '&mdash;';
             }
             break;
         case '_dfrps_cpt_last_update_time_started':
             if ($started > 0) {
                 echo '<abbr title="' . __('This Product Set\'s last update started on ', DFRPS_DOMAIN) . date_i18n('Y-m-d G:i:s', $started) . '">' . dfrps_date_in_two_rows($started) . '</abbr>';
             } else {
                 _e('Never', DFRPS_DOMAIN);
             }
             break;
         case '_dfrps_cpt_last_update_time_completed':
             if ($update_errors != '') {
                 echo dfrapi_output_api_error($update_errors);
             } else {
                 if ($update_phase == 0) {
                     if ($completed > 0) {
                         echo '<abbr title="' . __('This Product Set\'s last update completed on ', DFRPS_DOMAIN) . date_i18n('Y-m-d G:i:s', $completed) . '">' . dfrps_date_in_two_rows($completed) . '</abbr>';
                     } else {
                         _e('Never', DFRPS_DOMAIN);
                     }
                 } else {
                     $percent_complete = dfrps_percent_complete($post_id);
                     echo '<span class="dfrps_currently_updating">' . __('Updating&hellip;', DFRPS_DOMAIN) . '</span>';
                     if ($percent_complete) {
                         echo dfrps_progress_bar($percent_complete);
                     }
                 }
             }
             break;
         case '_dfrps_cpt_last_update_num_products_added':
             echo '<div class="dfrps_label dfrps_label-success" title="' . $products_added . __(' products were added during the last update of this Product Set.', DFRPS_DOMAIN) . '">' . $products_added . '</div>';
             break;
         case '_dfrps_cpt_last_update_num_products_deleted':
             echo '<div class="dfrps_label dfrps_label-danger" title="' . $products_deleted . __('  products were moved to the Trash during the last update of this Product Set.', DFRPS_DOMAIN) . '">' . $products_deleted . '</div>';
             break;
         case '_dfrps_cpt_last_update_num_api_requests':
             echo '<div class="dfrps_label dfrps_label-warning" title="' . $api_requests . __(' API requests were required during the last update of this Product Set.', DFRPS_DOMAIN) . '">' . $api_requests . '</div>';
             break;
     }
 }
Esempio n. 2
0
function dfrps_ajax_update_progress_bar()
{
    check_ajax_referer('dfrps_ajax_nonce', 'dfrps_security');
    // Set $postid variable.
    $postid = isset($_REQUEST['postid']) && $_REQUEST['postid'] > 0 ? $_REQUEST['postid'] : false;
    // If $postid doesn't validate, show error.
    if (!$postid) {
        _e('No post ID provided.  A post ID is required.', DFRPS_DOMAIN);
        die;
    }
    $percent = dfrps_percent_complete($postid);
    if (!$percent) {
        echo '';
    } else {
        echo dfrps_progress_bar($percent);
    }
    die;
}