/**
  * Show the history
  *
  * @param WP_Post $post
  * @param array   $metabox
  * @return
  */
 public static function show_client_history_view($post, $metabox)
 {
     if ('auto-draft' === $post->post_status) {
         printf('<p>%s</p>', sc__('No history available.'));
         return;
     }
     $client = Sprout_Client::get_instance($post->ID);
     $type = isset($_REQUEST['history_type']) ? $_REQUEST['history_type'] : '';
     self::load_view('admin/meta-boxes/clients/history', array('id' => $post->ID, 'post' => $post, 'client' => $client, 'history' => $client->get_history($type), 'pagination' => self::get_pagination()), false);
 }
 public static function show_twitter_feed()
 {
     $client = Sprout_Client::get_instance(get_the_id());
     if (!is_a($client, 'Sprout_Client')) {
         return;
     }
     if ('' === $client->get_twitter()) {
         self::_e('No twitter username assigned.');
         return;
     }
     printf('<a class="twitter-timeline" href="https://twitter.com/%1$s" data-widget-id="%2$s" data-screen-name="%1$s">Tweets by %1$s</a><script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?"http":"https";if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>', $client->get_twitter(), apply_filters('sc_twitter_widget_id', '492426361349234688'));
 }
    function sc_get_status_select($client_id = 0)
    {
        if (!$client_id) {
            $client_id = get_the_ID();
        }
        $client = Sprout_Client::get_instance($client_id);
        $statuses = $client->get_statuses();
        $all_statuses = sc_get_client_statuses();
        $status_terms = get_terms(Sprout_Client::STATUS_TAXONOMY, array('hide_empty' => false));
        $status_ids = !empty($statuses) ? wp_list_pluck($statuses, 'term_id') : array();
        ob_start();
        ?>
		<div id="statuses_<?php 
        echo (int) $client_id;
        ?>
" class="sc_statuses_update">
			<span class="status_change_button" data-sa-dropdown="#add_status_<?php 
        echo (int) $client_id;
        ?>
">
				<?php 
        printf('<button class="sc_add_status button" title="%1$s">%1$s&nbsp;<span class="dashicons dashicons-arrow-down"></span></button>', esc_attr(sc__('Status')));
        ?>
			</span>&nbsp;<span class="helptip client_status_help" data-sa-dropdown="#client_status_select_help_<?php 
        echo (int) $client_id;
        ?>
"></span>
			<div id="client_status_select_help_<?php 
        echo (int) $client_id;
        ?>
" class="sa-dropdown sa-dropdown-tip sa-dropdown-relative ">
				<div class="sa-dropdown-panel">
					<?php 
        sc_e('Select all statuses that currently fit this contact.');
        ?>
				</div>
			</div>
			<div id="add_status_<?php 
        echo (int) $client_id;
        ?>
" class="sa-dropdown sa-dropdown-tip sa-dropdown-relative status_change_selection" data-item-id="<?php 
        echo (int) $client_id;
        ?>
" data-nonce="<?php 
        echo esc_attr(wp_create_nonce(SC_Controller::NONCE));
        ?>
" data-vertical-offset="50">
				<ul class="sa-dropdown-menu">
					<?php 
        foreach ($all_statuses as $term_id => $label) {
            ?>
						<?php 
            $checked = !empty($statuses) && in_array($term_id, $status_ids) ? 'checked="checked"' : '';
            printf('<li><label><input type="checkbox" value="%1$s" %3$s/><b>%2$s</b></label></li>', (int) $term_id, esc_html($label), esc_attr($checked));
            ?>
					
					<?php 
        }
        ?>
					<li class="sa-dropdown-divider"></li>
					<li><a href="<?php 
        echo esc_url(admin_url('edit-tags.php?taxonomy=sc_client_status&post_type=sa_client'));
        ?>
"><?php 
        sc_e('Add/Edit Client Statuses');
        ?>
</a></li>
				</ul>
			</div>
		</div>
		<div id="current_statuses_<?php 
        echo (int) $client_id;
        ?>
" class="sc_current_statuses">
			<?php 
        foreach ($status_terms as $term) {
            ?>
				<?php 
            $current_status = !empty($statuses) && in_array($term->term_id, $status_ids) ? 'current' : '';
            $url = add_query_arg(array('post_type' => Sprout_Client::POST_TYPE, Sprout_Client::STATUS_TAXONOMY => $term->slug), admin_url('edit.php'));
            ?>
				<?php 
            printf('<a href="%4$s" class="button button-small sc_status %2$s status_id_%3$s" title="%1$s">%1$s</a>', esc_attr($term->name), esc_attr($current_status), (int) $term->term_id, esc_url_raw($url));
            ?>
			<?php 
        }
        ?>
		</div>
		<?php 
        $view = ob_get_clean();
        return apply_filters('sc_get_status_select', $view, $client_id);
    }
 /**
  * Meta box view
  * Abstracted to be called via AJAX
  * @param int $client_id
  *
  */
 public static function associated_users_meta_box_view($client_id = 0)
 {
     if (!current_user_can('edit_posts')) {
         self::ajax_fail('User cannot create new posts!');
     }
     if (!$client_id && isset($_REQUEST['client_id'])) {
         $client_id = $_REQUEST['client_id'];
     }
     $client = Sprout_Client::get_instance($client_id);
     if (!is_a($client, 'Sprout_Client')) {
         self::ajax_fail('Client not found.');
     }
     global $post;
     setup_postdata($client->get_post());
     print SC_Clients_Admin_Meta_Boxes::show_people_meta_box($client->get_post());
     exit;
 }
 /**
  * Display the content for the column
  *
  * @param string  $column_name
  * @param int     $id          post_id
  * @return string
  */
 public static function column_display($column_name, $id)
 {
     $client = Sprout_Client::get_instance($id);
     if (!is_a($client, 'Sprout_Client')) {
         return;
         // return for that temp post
     }
     switch ($column_name) {
         case 'sc_client_type':
             sc_type_select($id);
             break;
         case 'sc_client_status':
             sc_status_select($id);
             break;
         case 'lead_info':
             echo '<p>';
             $address = si_format_address($client->get_address(), 'string', '<br/>');
             print $address;
             if ('' !== $address) {
                 echo '<br/>';
             }
             echo make_clickable(esc_url($client->get_website()));
             echo '</p>';
             break;
         case 'contacts':
             $associated_users = $client->get_associated_users();
             echo '<p>';
             printf('<b>%s</b>: ', sc__('User Contacts'));
             if (!empty($associated_users)) {
                 $users_print = array();
                 foreach ($associated_users as $user_id) {
                     $user = get_userdata($user_id);
                     if (!is_a($user, 'WP_User')) {
                         $client->remove_associated_user($user_id);
                         continue;
                     }
                     $users_print[] = sprintf('<span class="associated_user"><a href="%s">%s</a></span>', get_edit_user_link($user_id), sc_get_users_full_name($user_id));
                 }
             }
             if (!empty($users_print)) {
                 print implode(', ', $users_print);
             } else {
                 sc_e('No associated people/users.');
             }
             echo '</p>';
             break;
         default:
             // code...
             break;
     }
 }