Ejemplo 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;
     }
 }
Ejemplo n.º 2
0
function dfrps_ajax_dashboard()
{
    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;
    }
    $html = '';
    $post_title = get_the_title($postid);
    $post_status = get_post_status($postid);
    $meta = get_post_custom($postid);
    $type = get_post_meta($postid, '_dfrps_cpt_type', TRUE);
    $update_phase = isset($meta['_dfrps_cpt_update_phase'][0]) ? intval($meta['_dfrps_cpt_update_phase'][0]) : 0;
    $next_update_time = isset($meta['_dfrps_cpt_next_update_time'][0]) ? $meta['_dfrps_cpt_next_update_time'][0] : false;
    $last_update_time = $meta['_dfrps_cpt_last_update_time_completed'][0];
    $temp_query = isset($meta['_dfrps_cpt_temp_query'][0]) ? $meta['_dfrps_cpt_temp_query'][0] : false;
    $saved_query = isset($meta['_dfrps_cpt_query'][0]) ? $meta['_dfrps_cpt_query'][0] : false;
    $term_ids = dfrps_get_cpt_terms($postid, FALSE);
    $links = array();
    $cats_query = false;
    if ($term_ids && !empty($type)) {
        $registered_cpts = get_option('dfrps_registered_cpts', array());
        $tax = $registered_cpts[$type]['taxonomy'];
        $cats_query = true;
        foreach ($term_ids as $id) {
            $term = get_term($id, $tax);
            if (is_object($term) && isset($term->count) && $term->count > 0) {
                $links[] = array('name' => $term->name, 'url' => esc_url(get_term_link($term, $tax)));
            }
        }
    }
    // Product Set 'type' is inactive. Just show message and don't show next update time or [Bump] button.
    if (!dfrps_set_is_active($type)) {
        $html .= '<div state="inactive_type"></div>';
        $html .= '<p><span class="dashicons dashicons-flag"></span> ' . __('This Product Set is inactive. To re-activate this Product Set, install and activate the importer plugin responsible for importing products into the "' . $type . '" custom post type.', DFRPS_DOMAIN) . '</p>';
    } else {
        // Status: auto-draft
        if ($post_status != 'publish' && $post_status != 'future') {
            $title_class = $post_title != '' && $post_title != __('Auto Draft') ? ' dfrps_dashboard_step_completed' : '';
            $temp_class = $temp_query != '' ? ' dfrps_dashboard_step_completed' : '';
            $saved_class = $saved_query != '' ? ' dfrps_dashboard_step_completed' : '';
            $cats_class = $cats_query ? ' dfrps_dashboard_step_completed' : '';
            $html .= '<div state="00"></div>';
            $html .= '<p><span class="dashicons dashicons-smiley"></span> ' . __('Let\'s get started on a new Product Set!', DFRPS_DOMAIN) . '</p>';
            $html .= '<ol>';
            $html .= '<li id="dfrps_step_title" class="' . $title_class . '">' . __('Title your Product Set.', DFRPS_DOMAIN) . '</li>';
            $html .= '<li id="dfrps_step_search" class="' . $temp_class . '">' . __('Search for products.', DFRPS_DOMAIN) . '</li>';
            $html .= '<li id="dfrps_step_save" class="' . $saved_class . '">' . __(' Click <strong>[Add as Saved Search]</strong> when you\'re happy with search results.', DFRPS_DOMAIN) . '</li>';
            $html .= '<li id="dfrps_step_category" class="' . $cats_class . '">' . __('Select a category to import into.', DFRPS_DOMAIN) . '</li>';
            $html .= '<li id="dfrps_step_publish">' . __('Click the <strong>[Publish]</strong> button to import these products into your site.', DFRPS_DOMAIN) . '</li>';
            $html .= '</ol>';
        }
        // Status: publish
        if ($post_status == 'publish' || $post_status == 'future') {
            if ($update_phase > 0) {
                $percent = dfrps_percent_complete($postid);
                if ($last_update_time == 0) {
                    $html .= '<div state="updating_' . $percent . '"></div>';
                    $html .= '<p><span class="dashicons dashicons-upload"></span>' . __('The products in this Product Set are currently being imported into your site.', DFRPS_DOMAIN) . '</p>';
                } else {
                    $html .= '<div state="updating_' . $percent . '"></div>';
                    $html .= '<p><span class="dashicons dashicons-upload"></span>' . __('The products in this Product Set are currently being updated.', DFRPS_DOMAIN) . '</p>';
                }
                if ($percent) {
                    $html .= dfrps_progress_bar($percent);
                }
            } elseif ($last_update_time == 0) {
                if ($post_status == 'future') {
                    $html .= '<div state="future"></div>';
                    $html .= '<p><span class="dashicons dashicons-clock"></span> ' . __('This Product Set is scheduled to be published at a future date. The products in this Set will be imported when the Set becomes published.', DFRPS_DOMAIN) . '</p>';
                } else {
                    $html .= '<div state="queued"></div>';
                    $html .= '<p><span class="dashicons dashicons-calendar"></span> ' . __('The products in this Product Set are queued to update on ', DFRPS_DOMAIN) . date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), $next_update_time) . '.</p>';
                    $html .= '<p><span class="dashicons dashicons-info"></span><em>' . __('Actual update time is determined by its place in the queue as well as the next scheduled cron.', DFRPS_DOMAIN) . '</em></p>';
                }
            } elseif ($last_update_time + 60 > date_i18n('U')) {
                $html .= '<div state="recently_completed"></div>';
                $html .= '<p><span class="dashicons dashicons-yes"></span> ' . __('This Product Set completed a full product update less than 1 minute ago.', DFRPS_DOMAIN) . '</p>';
                $num_links = count($links);
                if ($num_links > 0) {
                    $html .= '<p><span class="dashicons dashicons-welcome-view-site"></span> ' . __('View category: ', DFRPS_DOMAIN);
                    $i = 1;
                    foreach ($links as $link) {
                        $html .= '<a href="' . $link['url'] . '" target="_blank">' . $link['name'] . '</a>';
                        $i++;
                        if ($i <= $num_links) {
                            $html .= ', ';
                        }
                    }
                    $html . '</p>';
                }
            } elseif (date_i18n('U') > $next_update_time) {
                $html .= '<div state="queued"></div>';
                $html .= '<p><span class="dashicons dashicons-calendar"></span> ' . __('The products in this Product Set are queued to update on ', DFRPS_DOMAIN) . date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), $next_update_time) . '.</p>';
                $html .= '<p><span class="dashicons dashicons-info"></span><em>' . __('Actual update time is determined by its place in the queue as well as the next scheduled cron.', DFRPS_DOMAIN) . '</em></p>';
            } else {
                $html .= '<div state="scheduled"></div>';
                $html .= '<p><span class="dashicons dashicons-calendar"></span> ' . __('The products in this Product Set are scheduled to update on ', DFRPS_DOMAIN) . date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), $next_update_time) . '.</p>';
                $html .= '<p>
					<a href="#" class="button" id="dfrps_set_next_update_time_to_now">' . __('Bump', DFRPS_DOMAIN) . '</a><br />
					<small><em>' . __('Bump Product Set to front of update queue.', DFRPS_DOMAIN) . '</em></small>
				</p>';
            }
        }
    }
    echo $html;
    die;
}