* @package WordPress * @subpackage Importer Plugin * @since 1.0 */ get_header(); $import_options = get_option('importer_settings'); $hashtag = $import_options['hashtag']; ?> <div id="primary" class="content-area"> <div id="content" class="site-content" role="main"> <?php while (have_posts()) { the_post(); $session = new ONA_Session(get_the_ID()); $now = time() - 18000; if ($now < $session->get_start_time() - 300) { $time = 'before'; } else { if ($now > $session->get_end_time() + 300) { $time = 'past'; } else { $time = 'during'; } } ?> <article class="post session"> <ul class="session-meta"> <li class="track">
<div class="session-start-time"><?php echo $start_time; ?> </div> <ul class="session-list session-count-<?php echo count($posts); ?> "> <?php foreach ($posts as $post) { setup_postdata($post); $av_content = get_post_meta(get_the_ID(), '_av_content'); if ($av_content) { $av_content = $av_content[0]; } $session = new ONA_Session(get_the_ID()); ?> <a href="<?php the_permalink(); ?> "> <?php if ($session->get_session_type_name() == '') { $session_type = "Other"; } else { $session_type = $session->get_session_type_name(); } ?> <li class="single-session <?php echo $session_type; ?>
/** * Import or update sessions from CSV. */ public static function import_sessions($file, $output_callback) { $import_options = get_option('importer_settings'); $schedule_tab = $import_options['schedule_doc_tab']; // If this is a table, we need to turn it into a CSV if (!($data = self::check_if_table($file, $output_callback, $schedule_tab))) { // Otherwise, it's already a CSV $data = self::get_file_data($file, $output_callback); } $csv_rows = self::parse_csv_from_string($data, $output_callback); foreach ($csv_rows as $i => $csv_session) { // Uh oh, someone messed up the rows if (empty($csv_session['session_ID'])) { continue; } // If the session doesn't exist, let's create it first. $session_slug = sanitize_key($csv_session['session_ID']); if (false === ($session = ONA_Session::get_by_slug($session_slug))) { $post_id = wp_insert_post(array('post_type' => ONA_Session::$post_type, 'post_name' => $session_slug, 'post_status' => 'publish')); $session = new ONA_Session($post_id); $output_callback(sprintf("Inserting session '%s' as post #%d", $session_slug, $session->get_id())); } else { $output_callback(sprintf("Updating session '%s' (post #%d)", $session_slug, $session->get_id())); } foreach ($csv_session as $key => $value) { foreach (self::$session_fields as $session_field) { if ($session_field['csv_field'] != $key) { continue; } if (isset($session_field['pre_sanitize_callback']) && is_callable($session_field['pre_sanitize_callback'])) { $value = call_user_func_array($session_field['pre_sanitize_callback'], array($value, $csv_session)); } if (is_callable($session_field['sanitize_callback'])) { $new_value = call_user_func_array($session_field['sanitize_callback'], array($value)); } else { $new_value = $value; } $get_method = 'get_' . $session_field['object_field']; $set_method = 'set_' . $session_field['object_field']; // See whether the values should be updated if (isset($session_field['comparison_callback']) && is_callable($session_field['comparison_callback'])) { $update = call_user_func_array($session_field['comparison_callback'], array($new_value, $session->{$get_method}())); } else { $update = $new_value != $session->{$get_method}(); } if ($update) { $session->{$set_method}($new_value); self::output_diff($key, $new_value, $output_callback); } else { self::output_diff($key, false, $output_callback); } } } $output_callback(); // Line break $output_callback(); // Line break } if (!empty($tmp_file)) { @unlink($tmp_file); } $output_callback("Import complete", 'Success'); }