/**
  * Download a CSV
  */
 public function csv_handler()
 {
     if (!empty($_GET['download-csv'])) {
         $job_id = absint($_REQUEST['job_id']);
         $job = get_post($job_id);
         // Permissions
         if (!job_manager_user_can_edit_job($job)) {
             return;
         }
         $args = apply_filters('job_manager_job_applications_args', array('post_type' => 'job_application', 'post_status' => array_merge(array_keys(get_job_application_statuses()), array('publish')), 'ignore_sticky_posts' => 1, 'posts_per_page' => -1, 'post_parent' => $job_id));
         // Filters
         $application_status = !empty($_GET['application_status']) ? sanitize_text_field($_GET['application_status']) : '';
         $application_orderby = !empty($_GET['application_orderby']) ? sanitize_text_field($_GET['application_orderby']) : '';
         if ($application_status) {
             $args['post_status'] = $application_status;
         }
         switch ($application_orderby) {
             case 'name':
                 $args['order'] = 'ASC';
                 $args['orderby'] = 'post_title';
                 break;
             case 'rating':
                 $args['order'] = 'DESC';
                 $args['orderby'] = 'meta_value';
                 $args['meta_key'] = '_rating';
                 break;
             default:
                 $args['order'] = 'DESC';
                 $args['orderby'] = 'date';
                 break;
         }
         $applications = get_posts($args);
         @set_time_limit(0);
         if (function_exists('apache_setenv')) {
             @apache_setenv('no-gzip', 1);
         }
         @ini_set('zlib.output_compression', 0);
         @ob_clean();
         header('Content-Type: text/csv; charset=UTF-8');
         header('Content-Disposition: attachment; filename=' . __('applications', 'wp-job-manager-applications') . '.csv');
         header('Pragma: no-cache');
         header('Expires: 0');
         $fp = fopen('php://output', 'w');
         $row = array_map(__CLASS__ . '::wrap_column', array(__('Application date', 'wp-job-manager-applications'), __('Application status', 'wp-job-manager-applications'), __('Applicant name', 'wp-job-manager-applications'), __('Applicant email', 'wp-job-manager-applications'), __('Job applied for', 'wp-job-manager-applications'), __('Attachment', 'wp-job-manager-applications'), __('Applicant message', 'wp-job-manager-applications'), __('Rating', 'wp-job-manager-applications')));
         // Other custom fields
         $custom_fields = array();
         foreach ($applications as $application) {
             $custom_fields = array_merge($custom_fields, array_keys(get_post_custom($application->ID)));
         }
         $custom_fields = array_unique($custom_fields);
         $custom_fields = array_diff($custom_fields, array('_edit_lock', '_attachment', '_attachment_file', '_job_applied_for', '_candidate_email', '_candidate_user_id', '_rating', '_application_source', '_secret_dir'));
         foreach ($custom_fields as $custom_field) {
             $row[] = $custom_field;
         }
         fwrite($fp, implode(',', $row) . "\n");
         foreach ($applications as $application) {
             $row = array();
             $row[] = date_i18n(get_option('date_format'), strtotime($application->post_date));
             $row[] = $application->post_status;
             $row[] = $application->post_title;
             $row[] = get_job_application_email($application->ID);
             $row[] = get_the_title($application->post_parent);
             $row[] = get_post_meta($application->ID, '_attachment', true);
             $row[] = $application->post_content;
             $row[] = get_job_application_rating($application->ID);
             foreach ($custom_fields as $custom_field) {
                 $row[] = get_post_meta($application->ID, $custom_field, true);
             }
             $row = array_map(__CLASS__ . '::wrap_column', $row);
             fwrite($fp, implode(',', $row) . "\n");
         }
         fclose($fp);
         exit;
     }
 }
 /**
  * Output get_job_application_avatar
  * @param  object $application_id
  */
 function get_job_application_avatar($application_id, $size = 42)
 {
     $email = get_job_application_email($application_id);
     return $email ? get_avatar($email, $size) : '';
 }
 /**
  * Output get_job_application_avatar
  * @param  object $application_id
  */
 function get_job_application_avatar($application_id, $size = 42)
 {
     $email = get_job_application_email($application_id);
     $resume_id = get_job_application_resume_id($application_id);
     if ($resume_id && 'publish' === get_post_status($resume_id) && function_exists('get_the_candidate_photo')) {
         return '<img src="' . esc_attr(get_the_candidate_photo($resume_id)) . '" height="' . esc_attr($size) . '" />';
     }
     return $email ? get_avatar($email, $size) : '';
 }
_e('Edit', 'wp-job-manager-applications');
?>
</a></li>
	<li class="notes <?php 
echo get_comments_number($application->ID) ? 'has-notes' : '';
?>
"><a href="#" title="<?php 
_e('Notes', 'wp-job-manager-applications');
?>
" class="job-application-toggle-notes"><?php 
_e('Notes', 'wp-job-manager-applications');
?>
</a></li>

	<?php 
if ($email = get_job_application_email($application->ID)) {
    ?>
		<li class="email"><a href="mailto:<?php 
    echo esc_attr($email);
    ?>
?subject=<?php 
    echo esc_attr(sprintf(__('Your job application for %s', 'wp-job-manager-applications'), strip_tags(get_the_title($job_id))));
    ?>
&amp;body=<?php 
    echo esc_attr(sprintf(__('Hello %s', 'wp-job-manager-applications'), get_the_title($application->ID)));
    ?>
" title="<?php 
    _e('Email', 'wp-job-manager-applications');
    ?>
" class="job-application-contact"><?php 
    _e('Email', 'wp-job-manager-applications');