/** * Generate the schedule for the schedule page. Based on a shortcode. Pass in the ID, and get the schedule for both days. */ function mf_schedule($atts) { extract(shortcode_atts(array(), $atts)); $output = ''; $location = isset($atts['location']) ? sanitize_text_field($atts['location']) : ''; $faire = isset($atts['faire']) ? sanitize_text_field($atts['faire']) : ''; if (!empty($location)) { $term = wpcom_vip_get_term_by('id', $location, 'location'); $url = get_term_link($term); if (!is_wp_error($url)) { $output .= '<a href="' . esc_url(home_url('/stage-schedule/?location=' . $term->slug)) . '" class="pull-right" style="position:relative; top:7px;"><img src="' . get_stylesheet_directory_uri() . '/images/print-ico.png" alt="' . __('Print this schedule', 'make-mini-mf') . '" /></a>'; $output .= '<h2><a href="' . esc_url($url) . '">' . esc_html($term->name) . '</a></h2>'; $output .= mf_stage_description($term); } } $query = wp_cache_get($location . '_saturday_schedule'); if (!isset($term->slug)) { return; } if ($query == false) { $args = array('location' => sanitize_title($term->slug), 'post_type' => 'event-items', 'orderby' => 'meta_value', 'meta_key' => 'mfei_start', 'order' => 'asc', 'posts_per_page' => '30', 'faire' => $faire, 'meta_query' => array(array('key' => 'mfei_day', 'value' => 'Saturday'))); $query = new WP_Query($args); wp_cache_set($location . '_saturday_schedule', $query, '', 300); } if ($query->found_posts >= 1) { $output .= '<table class="table table-striped table-bordered table-schedule">'; if ($faire == 'world-maker-faire-new-york-2013') { $output .= '<thead><tr><th colspan="2">September 21st, 2013</th></tr></thead>'; } while ($query->have_posts()) { $query->the_post(); $meta = get_post_meta(get_the_ID()); $sched_post = get_post($meta['mfei_record'][0]); $json = json_decode(mf_convert_newlines(str_replace("\\'", "'", $sched_post->post_content))); $day = $meta['mfei_day'][0] ? $meta['mfei_day'][0] : ''; $start = $meta['mfei_start'][0] ? $meta['mfei_start'][0] : ''; $stop = $meta['mfei_stop'][0] ? $meta['mfei_stop'][0] : ''; $output .= '<tr>'; $output .= '<td width="150" style="max-width:150px;">'; $output .= '<h5>' . esc_html($day) . '</h5>'; $output .= '<p>' . esc_html($start) . ' — ' . esc_html($stop) . '</p>'; if (isset($json->presenter_photo) or isset($json->project_photo) or isset($json->presentation_photo) or isset($json->performer_photo) or has_post_thumbnail(get_the_ID())) { if (get_the_post_thumbnail()) { $output .= '<div class="pull-left thumbnail"><a href="'; $output .= get_permalink($sched_post) . '">'; $output .= get_the_post_thumbnail(get_the_ID(), 'schedule-thumb'); $output .= '</a></div>'; } elseif (isset($json->presenter_photo[0]) && !is_array($json->presenter_photo[0]) && strlen($json->presenter_photo[0]) > 5) { $output .= '<div class="pull-left thumbnail"><a href="'; $output .= get_permalink($sched_post) . '">'; $output .= '<img src="' . wpcom_vip_get_resized_remote_image_url($json->presenter_photo[0], 140, 140) . '" alt="' . esc_attr(get_the_title($sched_post->ID)) . '" />'; $output .= '</a></div>'; } else { $output .= '<div class="pull-left thumbnail"><a href="'; $output .= get_permalink($sched_post) . '">'; $output .= '<img src="' . wpcom_vip_get_resized_remote_image_url(mf_get_the_maker_image($json), 140, 140) . '" alt="' . esc_attr(get_the_title($sched_post->ID)) . '" />'; $output .= '</a></div>'; } } $output .= '</td>'; $output .= '<td>'; $output .= '<h3><a href="' . get_permalink($sched_post) . '">' . get_the_title($sched_post->ID) . '</a></h3>'; if (!empty($json->presenter_name)) { $names = $json->presenter_name; $names_output = ''; foreach ($names as $name) { $names_output .= ', ' . $name; } $output .= '<h4>' . substr($names_output, 2) . '</h4>'; } if (!empty($json->short_description)) { $output .= Markdown(stripslashes(wp_filter_post_kses(mf_convert_newlines($json->short_description, "\n")))); } elseif (!empty($json->public_description)) { $output .= Markdown(stripslashes(wp_filter_post_kses(mf_convert_newlines($json->public_description, "\n")))); } if (!empty($meta['mfei_coverage'][0])) { $output .= '<p><a href="' . esc_url($meta['mfei_coverage'][0]) . '" class="btn btn-mini btn-primary">Watch Video</a></p>'; } // $output .= '<ul class="unstyled">'; // $terms = get_the_terms( $sched_post->ID, array( 'category', 'post_tag' ) ); // if (!empty($terms)) { // $output .= '<li>Topics: '; // $the_terms = ''; // foreach ($terms as $idx => $term) { // $the_terms .= ', <a href="' . esc_url( get_term_link( $term ) ) . '">' . $term->name . '</a>'; // } // $output .= substr( $the_terms, 2 ); // $output .= '</li>'; // } // $output .= '</ul>'; $output .= '</td>'; $output .= '</tr>'; } $output .= '</table>'; } wp_reset_postdata(); // Roll the schedule for Sunday. if ($query->found_posts >= 1) { $query = wp_cache_get($location . '_sunday_schedule'); if ($query == false) { $args = array('location' => sanitize_title($term->slug), 'post_type' => 'event-items', 'orderby' => 'meta_value', 'meta_key' => 'mfei_start', 'order' => 'asc', 'posts_per_page' => '30', 'faire' => $faire, 'meta_query' => array(array('key' => 'mfei_day', 'value' => 'Sunday'))); $query = new WP_Query($args); wp_cache_set($location . '_sunday_schedule', $query, '', 300); } $output .= '<table class="table table-striped table-bordered table-schedule">'; if ($faire == 'world-maker-faire-new-york-2013') { $output .= '<thead><tr><th colspan="2">September 22nd, 2013</th></tr></thead>'; } while ($query->have_posts()) { $query->the_post(); $meta = get_post_meta(get_the_ID()); $sched_post = get_post($meta['mfei_record'][0]); $json = json_decode(str_replace("\\'", "'", $sched_post->post_content)); $day = $meta['mfei_day'][0] ? $meta['mfei_day'][0] : ''; $start = $meta['mfei_start'][0] ? $meta['mfei_start'][0] : ''; $stop = $meta['mfei_stop'][0] ? $meta['mfei_stop'][0] : ''; $output .= '<tr>'; $output .= '<td width="150">'; $output .= '<h5>' . esc_html($day) . '</h5>'; $output .= '<p>' . esc_html($start) . ' — ' . esc_html($stop) . '</p>'; if (isset($json->presenter_photo) or isset($json->project_photo) or isset($json->presentation_photo) or isset($json->performer_photo) or has_post_thumbnail(get_the_ID())) { if (get_the_post_thumbnail()) { $output .= '<div class="pull-left thumbnail"><a href="'; $output .= get_permalink($sched_post) . '">'; $output .= get_the_post_thumbnail(get_the_ID(), 'schedule-thumb'); $output .= '</a></div>'; } elseif (isset($json->presenter_photo[0]) && !is_array($json->presenter_photo[0]) && strlen($json->presenter_photo[0]) > 5) { $output .= '<div class="pull-left thumbnail"><a href="'; $output .= get_permalink($sched_post) . '">'; $output .= '<img src="' . wpcom_vip_get_resized_remote_image_url($json->presenter_photo[0], 140, 140) . '" alt="' . esc_attr(get_the_title($sched_post->ID)) . '" />'; $output .= '</a></div>'; } else { $output .= '<div class="pull-left thumbnail"><a href="'; $output .= get_permalink($sched_post) . '">'; $output .= '<img src="' . wpcom_vip_get_resized_remote_image_url(mf_get_the_maker_image($json), 140, 140) . '" alt="' . esc_attr(get_the_title($sched_post->ID)) . '" />'; $output .= '</a></div>'; } } $output .= '</td>'; $output .= '<td>'; $output .= '<h3><a href="' . get_permalink($sched_post) . '">' . get_the_title($sched_post->ID) . '</a></h3>'; if (!empty($json->presenter_name)) { $names = $json->presenter_name; $names_output = ''; foreach ($names as $name) { $names_output .= ', ' . $name; } $output .= '<h4>' . substr($names_output, 2) . '</h4>'; } if (!empty($json->short_description)) { $output .= Markdown(stripslashes(wp_filter_post_kses(mf_convert_newlines($json->short_description, "\n")))); } elseif (!empty($json->public_description)) { $output .= Markdown(stripslashes(wp_filter_post_kses(mf_convert_newlines($json->public_description, "\n")))); } if (!empty($meta['mfei_coverage'][0])) { $output .= '<p><a href="' . esc_url($meta['mfei_coverage'][0]) . '" class="btn btn-mini btn-primary">Watch Video</a></p>'; } // $output .= '<ul class="unstyled">'; // $terms = get_the_terms( $sched_post->ID, array( 'category', 'post_tag' ) ); // if (!empty($terms)) { // $output .= '<li>Topics: '; // $the_terms = ''; // foreach ($terms as $idx => $term) { // $the_terms .= ', <a href="' . get_term_link( $term ) . '">' . $term->name . '</a>'; // } // $output .= substr( $the_terms, 2 ); // $output .= '</li>'; // } // $output .= '</ul>'; $output .= '</td>'; $output .= '</tr>'; } $output .= '</table>'; } wp_reset_postdata(); return $output; }
/** * The new and improved schedule by location shortcode. * * We wanted a better code base that is more maintainable and performant that also supports our new location architecture. * To use, pass in the location_id attribute in the shortcode with the locations ID along with what faire you want applications from. Passing the faire is necessary for future archiving. * From there we'll query all events for each day and cache them. * Now we'll loop through each day spitting out all applications scheduled for those days from 10am to closing of that day. * * @param array $atts The attributes being passed through the shortcode * @return string */ function mf_display_schedule_by_location($atts) { global $mfform; $data = shortcode_atts(array('location_id' => '', 'faire' => MF_CURRENT_FAIRE), $atts); // Get the faire date array. If the $faire_date = mf_get_faire_date(sanitize_title($data['faire'])); // Make sure we actually passed a valid faire... if (empty($faire_date)) { return '<h3>Not a valid faire!</h3>'; } // Get the location object. $location = get_post(absint($data['location_id'])); // Get Saturday events by location $saturday = wp_cache_get(sanitize_title($location->post_title) . '_saturday_schedule_' . sanitize_title($data['faire']), 'locations'); if ($saturday === false) { $events_saturday_args = array('post_type' => 'event-items', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_key' => 'mfei_start', 'posts_per_page' => 30, 'faire' => sanitize_title($data['faire']), 'meta_query' => array(array('key' => 'mfei_day', 'value' => 'Saturday'), array('key' => 'faire_location', 'value' => serialize(array(absint($data['location_id'])))))); $saturday = new WP_Query($events_saturday_args); wp_cache_set(sanitize_title($location->post_title) . '_saturday_schedule_' . sanitize_title($data['faire']), $saturday, 'locations', 300); } // Get Sunday Events by location $sunday = wp_cache_get(sanitize_title($location->post_title) . '_sunday_schedule_' . sanitize_title($data['faire']), 'locations'); if ($sunday === false) { $events_sunday_args = array('post_type' => 'event-items', 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_key' => 'mfei_start', 'posts_per_page' => 30, 'faire' => sanitize_title($data['faire']), 'meta_query' => array(array('key' => 'mfei_day', 'value' => 'Sunday'), array('key' => 'faire_location', 'value' => serialize(array(absint($data['location_id'])))))); $sunday = new WP_Query($events_sunday_args); wp_cache_set(sanitize_title($location->post_title) . '_sunday_schedule_' . sanitize_title($data['faire']), $sunday, 'locations', 300); } $output = '<div class="row"><div class="col-xs-11"><h2><a href="' . esc_url(get_permalink(absint($data['location_id'])) . '?faire=' . $data['faire']) . '">' . esc_html($location->post_title) . '</a></h2></div> <div class="col-xs-1 pull-right" style="position:relative; top:7px;"><a href="#" onclick="window.print();return false;"><img src="' . get_stylesheet_directory_uri() . '/images/print-ico.png" alt="Print this schedule" /></a></div></div>'; if (!empty($location->post_excerpt)) { $output .= '<div class="alert alert-info">' . wp_kses_post(Markdown($location->post_excerpt)) . '</div>'; } // Let's loop through each day and spit out a schedule? $days = array('saturday', 'sunday'); foreach ($days as $key => $day) { // Make sure something was actually returned if (${$day}->found_posts >= 1) { // Start the schedule $output .= '<table id="' . esc_attr($day) . '" class="table table-striped table-bordered table-schedule">'; $output .= '<thead><tr><th colspan="2">' . esc_html(date('l dS, Y', strtotime($faire_date[ucfirst($day)]))) . '</th></tr></thead>'; // Loop through the events and get the applications while (${$day}->have_posts()) { ${$day}->the_post(); $event_id = get_the_ID(); $meta = get_post_meta(absint(get_the_ID())); $app_obj = get_post(absint($meta['mfei_record'][0])); $app = json_decode(mf_convert_newlines(str_replace("\\'", "'", $app_obj->post_content))); $output .= '<tr>'; $output .= '<td width="150" style="max-width:150px;">'; $output .= '<h5>' . esc_html($meta['mfei_day'][0]) . '</h5>'; $output .= '<p>' . esc_html($meta['mfei_start'][0]) . ' — ' . esc_html($meta['mfei_stop'][0]) . '</p>'; if (isset($app->{$mfform->merge_fields('form_photo', $app->form_type)}) || has_post_thumbnail(absint($event_id)) || isset($app->{$mfform->merge_fields('user_photo', $app->form_type)})) { $output .= '<div class="pull-left">'; // We may want to over ride the photo of an application on the schedule page by checking if there is a featured image on the event item if (has_post_thumbnail(absint($event_id))) { $output .= get_the_post_thumbnail(absint($event_id), 'schedule-thumb'); } elseif ($app->form_type == 'performer' || $app->form_type == 'exhibit') { $output .= '<a href="' . get_permalink(absint($app_obj->ID)) . '"><img class="img-thumbnail" src="' . legacy_get_resized_remote_image_url($app->{$mfform->merge_fields('user_photo', $app->form_type)}, 140, 140) . '" alt="' . esc_attr($app_obj->post_title) . '"></a>'; } elseif (!empty($app->{$mfform->merge_fields('user_photo', $app->form_type)}[0])) { $output .= '<a href="' . get_permalink(absint($app_obj->ID)) . '"><img class="img-thumbnail" src="' . legacy_get_resized_remote_image_url($app->{$mfform->merge_fields('user_photo', $app->form_type)}[0], 140, 140) . '" alt="' . esc_attr($app_obj->post_title) . '"></a>'; } else { $output .= '<a href="' . get_permalink(absint($app_obj->ID)) . '"><img class="img-thumbnail" src="' . legacy_get_resized_remote_image_url(mf_get_the_maker_image($app), 140, 140) . '" alt="' . esc_attr($app_obj->post_title) . '"></a>'; } $output .= '</div>'; } $output .= '</td><td>'; $output .= '<h3><a href="' . get_permalink(absint($app_obj->ID)) . '">' . get_the_title(absint($app_obj->ID)) . '</a></h3>'; // Presenter Name(s) if (!empty($app->presenter_name)) { $output .= '<h4 class="maker-name">' . implode(', ', $app->presenter_name) . '</h4>'; } // Application Descriptions $description = $app->{$mfform->merge_fields('project_description', $app->form_type)}; if (!empty($description)) { $output .= Markdown(stripslashes(wp_filter_post_kses(mf_convert_newlines($description)))); } // Add our video link for video coverage if (!empty($meta['mfei_coverage'][0])) { $output .= '<p><a href="' . esc_url($meta['mfei_coverage'][0]) . '" class="btn btn-xs btn-primary">Watch Video</a></p>'; } $output .= '</td>'; $output .= '</tr>'; } $output .= '</table>'; wp_reset_postdata(); } } // OMG WTF JUST HAPPENED. LET'S JUST RETURN THIS. :P return $output; }
/** * Current Faire Page */ function display_current_faire_page() { //must check that the user has the required capability if (!current_user_can($this->user_capabilities)) { wp_die(__('You do not have sufficient permissions to access this page.', 'make')); } // Get any query variables if set $query_vars = $this->get_query_vars(); // Check if we are filtering our results by post type. if (empty($query_vars['post_status']) || $query_vars['post_status'] == 'all') { $post_status = array_slice($this->post_status, 1); } else { $post_status = $query_vars['post_status']; } $args = array('faire' => $this->current_faire, 'post_type' => $this->post_type, 'post_status' => $post_status, 'posts_per_page' => $query_vars['posts_per_page'], 'paged' => $query_vars['paged'], 'cat' => $query_vars['category'], 'tag' => $query_vars['tag'], 'type' => $query_vars['app_type'], 'meta_key' => $query_vars['edu_day'], 'orderby' => $query_vars['order_by'], 's' => $query_vars['search'], 'p' => $query_vars['post_id']); $query = new WP_Query($args); ?> <div class="wrap"> <h1><?php echo $this->submenu_data['page_title']; ?> </h1> <ul class="subsubsub"> <?php echo $this->count_post_status(); ?> </ul> <form method="get" class="posts-filter"> <input type="hidden" name="post_type" value="<?php echo esc_attr($_REQUEST['post_type']); ?> " /> <input type="hidden" name="page" value="<?php echo esc_attr($_REQUEST['page']); ?> " /> <?php wp_nonce_field('overview-form-save', $this->nonce_name, false); ?> <p class="search-box"> <label for="post-search-input" class="screen-reader-text">Search All Applications</label> <input type="search" id="post-search-input" name="s" value="<?php echo isset($query_vars['search']) ? esc_attr($query_vars['search']) : ''; ?> "> <input type="submit" name="" id="search-submit" class="button" value="Search All Applications"> </p> <div class="tablenav top"> <?php echo $this->application_type_dropdown(); ?> <?php echo $this->categories_dropdown(); ?> <?php echo $this->tags_dropdown(); ?> <?php echo $this->orderby_dropdown(); ?> <?php echo $this->posts_per_page_dropdown(array(20, 30, 40, 50, 60, 70, 80, 90, 100, 200, 300, 400, 1000)); ?> <label for="post-search-id" class="screen-reader-text">Search by Project ID</label> <input type="search" id="post-search-id" name="p" placeholder="Project ID" value="<?php echo isset($_GET['p']) && !empty($_GET['p']) ? esc_attr($_GET['p']) : ''; ?> "> <input type="submit" name="" id="filter-submit" class="button" value="Filter All Content"> <button class="button"><a href="<?php echo esc_url(admin_url($this->submenu_data['page_url'])); ?> ">Reset Filters</a></button> <div class="tablenav-pages"> <span class="displaying-num"><?php echo absint($query->found_posts); ?> Items</span> <?php echo $this->get_pagination_link($query->max_num_pages, $query_vars['paged']); ?> </div> </div> <table id="current-faire" class="wp-list-table widefat fixed pages"> <thead> <tr> <?php foreach ($this->columns as $column => $details) { ?> <th scope="col" id="<?php echo $column; ?> " class="manage-column column-<?php echo $column; echo $details['sortable'] ? ' table-sortable' : ''; ?> "<?php echo $this->check_screen_options($column, false, $details['default']); ?> ><?php echo $details['label']; ?> </th> <?php } ?> </tr> </thead> <tfoot> <tr> <?php foreach ($this->columns as $column => $details) { ?> <th scope="col" id="<?php echo $column; ?> " class="manage-column column-<?php echo $column; echo $details['sortable'] ? ' table-sortable' : ''; ?> "<?php echo $this->check_screen_options($column, false, $details['default']); ?> ><?php echo $details['label']; ?> </th> <?php } ?> </tr> </tfoot> <tbody id="the-list"> <?php global $post, $wp_post_statuses; if (!empty($query->posts)) { foreach ($query->posts as $post) { setup_postdata($post); // Set just a couple of variables.... :/ $json = json_decode(str_replace('\\', '\\\\', $post->post_content)); $post_id = absint($post->ID); $app_image = mf_get_the_maker_image($json); $post_status = $wp_post_statuses[get_post_status()]->label; $maker_name = !empty($json->name) ? $json->name : ''; $app_type = get_the_term_list($post_id, 'type', '', ', ', ''); $description = !empty($json->public_description) ? mf_clean_content($json->public_description) : ''; $cats = get_the_category_list(', ', '', $post_id); $tags = get_the_term_list($post_id, 'post_tag', null, ', '); $location = mf_get_locations($post_id); $featured = get_post_meta($post_id, '_ef_editorial_meta_checkbox_featured', true); $commercial = !empty($json->sales) ? sanitize_text_field($this->convert_boolean($json->sales)) : ''; $edu_day = get_post_meta($post_id, '_ef_editorial_meta_checkbox_education-day', true); echo '<tr id="post-' . absint($post->ID) . '" valign="top">'; echo '<td class="post_photo column-post_photo"' . $this->check_screen_options('post_photo', false, true) . '>'; if (!empty($app_image)) { echo '<img src="' . legacy_get_resized_remote_image_url(esc_url($app_image), 130, 130, true) . '" width="130" height="130">'; } echo '</td>'; echo '<td class="post_id column-post_id"' . $this->check_screen_options('post_id', false, true) . '>' . $post_id . '</td>'; echo '<td class="post_status column-post_status"' . $this->check_screen_options('post_status', false, true) . '>' . $post_status . '</td>'; echo '<td class="post_title column-post_title"' . $this->check_screen_options('post_title', false, true) . '><strong><a href="' . get_edit_post_link(absint($post->ID)) . '">' . esc_html(get_the_title()) . '</a></strong> <div class="row-actions"> <span class="inline hide-if-no-js"><a href="' . get_edit_post_link(absint($post->ID)) . '">Edit</a> | </span> <span class="view"><a href="' . get_permalink() . '">View</a></span> </div> </td>'; echo '<td class="post_author column-post_author"' . $this->check_screen_options('post_author', false, true) . '>' . esc_html($maker_name) . '</td>'; echo '<td class="post_type column-post_type"' . $this->check_screen_options('post_type', false, true) . '>' . $app_type . '</td>'; echo '<td class="post_description column-post_description"' . $this->check_screen_options('post_description', false, true) . '>' . wp_trim_words(Markdown(wp_kses_post($description)), 15) . '</td>'; echo '<td class="cats column-cats"' . $this->check_screen_options('cats', false, true) . '>' . $cats . '</td>'; echo '<td class="tags column-tags"' . $this->check_screen_options('tags', false, true) . '>' . $tags . '</td>'; echo '<td class="location column-location"' . $this->check_screen_options('location', false, true) . '>' . esc_html($location) . '</td>'; echo '<td class="featured_maker column-featured_maker"' . $this->check_screen_options('featured_maker', false, true) . '>' . $this->convert_boolean($featured) . '</td>'; echo '<td class="post_date column-post_date"' . $this->check_screen_options('post_date', false, true) . '>' . $this->process_dates($post->post_date, $post->post_modified) . '</td>'; echo '<td class="commercial column-commercial"' . $this->check_screen_options('commercial', false, true) . '>' . $commercial . '</td>'; echo '<td class="education_day column-education_day"' . $this->check_screen_options('education_day', false, true) . '>' . $this->convert_boolean($edu_day) . '</td>'; echo '</tr>'; } } else { echo '<tr class="no-items"><td class="colspanchange" colspan="3">No content found.</td></tr>'; } ?> </tbody> </table> <div class="tablenav bottom"> <div class="tablenav-pages"> <span class="displaying-num"><?php echo absint($query->found_posts); ?> Items</span> <?php echo $this->get_pagination_link($query->max_num_pages, $query_vars['paged']); ?> </div> </div> </form> </div> <?php }