コード例 #1
0
ファイル: makers.php プロジェクト: hansstam/makerfaire
/**
 * 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]) . ' &mdash; ' . 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;
}
コード例 #2
0
/**
 * 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) . ' &mdash; ' . 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) . ' &mdash; ' . 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;
}
コード例 #3
0
    public function meta_box($post, $args)
    {
        if (get_post_type() == 'maker') {
            $id = get_post_meta(get_the_ID(), 'mfei_record', true);
            $post = get_post(absint($id));
        }
        $bad = array('&#039;', "\\'", '&#8217;', '&#38;', '&#038;', '&#34;', '&#034;', '&#8211;', '&lt;', '&#8230;', 'u2018', 'u2019', 'u2014', 'u2022', 'u2026', '<br />rn');
        $good = array("'", "'", "'", "&", "&", '"', '"', '–', '>', '...', "'", "'", "—", '•', '...', '<br />');
        $data = json_decode(str_replace($bad, $good, $post->post_content));
        if ($args['id'] == 'mf_save') {
            $wf = get_post_meta($post->ID, '_mf_waiting_for', true);
            $wf = $wf == '' ? 'Waiting on?' : $wf;
            ?>
<div class="submitbox" id="submitpost">
					<?php 
            wp_nonce_field('mf_nonce', 'mf_submit_nonce');
            ?>
					<?php 
            $post_status_types = array('in-progress', 'proposed', 'more-info', 'wait-list', 'accepted', 'rejected', 'cancelled');
            ?>
					<input name="mf_form" type="hidden" value="1" /> <input id="id"
		name="id" type="hidden"
		value="<?php 
            echo $post->post_status != 'auto-draft' ? intval($post->ID) : 0;
            ?>
" />
	<div id="misc-publishing-actions">
		<div class="misc-pub-section">
			<label for="post_status" style="display: inline;">Status:</label> <select
				id="post_status" name="post_status">
								<?php 
            // Get an array of our select options for setting the post status
            global $edit_flow;
            if (is_object($edit_flow) && is_a($edit_flow, 'edit_flow')) {
                foreach ($edit_flow->custom_status->get_custom_statuses() as $cso) {
                    ?>
											<option value="<?php 
                    echo esc_attr($cso->slug);
                    ?>
"
					title="<?php 
                    echo esc_attr($cso->description);
                    ?>
"
					<?php 
                    selected($cso->slug, $post->post_status);
                    ?>
>
												<?php 
                    echo esc_attr($cso->name);
                    ?>
											</option>
										<?php 
                }
            }
            ?>
							</select>
			<div id="mff-post-status-display" style="padding-top: 5px;"></div>
		</div>
	</div>
	<!--[END #misc-pub-section]-->
	<div id="major-publishing-actions">
		<div id="mfquestionwait"></div>
		<div id="delete-action">
			<a href="<?php 
            echo get_delete_post_link($post->ID);
            ?>
"
				class="submitdelete deletion">Move to Trash</a>
		</div>
		<div id="publishing-action">
			<a href="<?php 
            echo post_permalink($post->ID);
            ?>
"
				class="button button-large" style="margin-bottom: 8px;"
				title="<?php 
            esc_attr(the_title());
            ?>
">View Post</a><br> <input
				type="submit" value="Save Application" accesskey="p" id="publish"
				class="button button-primary button-large" name="save">
		</div>
	</div>
	<div class="clear"></div>
	<p class="misc-pub-section num-revisions">
					<?php 
            $kids = wp_get_post_revisions(get_the_ID());
            if (count($kids) > 1) {
                printf(__('Revisions: %s'), '<b>' . number_format_i18n(absint(count($kids))) . '</b>');
                $kid = array_splice($kids, 0);
                ?>
						<a class="hide-if-no-js"
			href="<?php 
                echo esc_url(get_edit_post_link(absint($kid[0]->ID)));
                ?>
"><?php 
                _ex('Browse', 'revisions');
                ?>
</a>
					<?php 
            }
            ?>
					</p>
	<script type="text/javascript">
						(function($){
							$(document).ready(function() {

								// Check if the post status is set, if not, go ahead and run this code.
								if ( ! $('#mff-post-status-display').length )
									return true;

								$('#post_status').change(function() {
									var postStatus = $('#post_status');
									var origPost = $('#original_post_status');
									var postStatusSelected = $('option:selected', postStatus);
									var postStatusDisplay = $('#mff-post-status-display');
									var origPostStatus =origPost.val();
									var postStatusSelectedTitle=postStatusSelected.attr('title');
									var newStatus=postStatus.val();

									console.log('change: %s -> %s (%s)', origPostStatus, newStatus, postStatusSelected.val() );

									postStatusDisplay.html(postStatusSelectedTitle);

									if ( newStatus == 'more-info' ) {
										$('#mfquestionwait').html('<textarea name="mf_waitingquestion" id="mf_waitingquestion" style="width:99%"><?php 
            echo html_entity_decode(esc_textarea($wf));
            ?>
</textarea>');
									} else {
										$('#mfquestionwait').html('');
									}

								});

								setTimeout(function(){$('#post_status').change();}, 10);
							});
						})(jQuery.noConflict());
					</script>
</div>
<?php 
        } elseif ($args['id'] == 'mf_logs') {
            $post_status_log = get_post_meta($post->ID, '_mf_log', true);
            if (!is_array($post_status_log) || $post_status_log == false || sizeof($post_status_log) == 0) {
                $post_status_log = array();
                $post_status_log[] = mysql2date('m/d/y h:i a', $post->post_date) . ' - Proposed';
            }
            echo '<ul>';
            foreach (array_reverse($post_status_log) as $log) {
                echo '<li>' . esc_html($log) . '</li>';
            }
            echo "</ul>";
        } elseif ($args['id'] == 'mf_summary') {
            $jdb_success = get_post_meta($post->ID, 'mf_jdb_sync', true);
            if ($jdb_success == '') {
                $jdb_fail = get_post_meta($post->ID, 'mf_jdb_sync_fail', true);
                $jdb = '[FAILED] : N/A';
                if ($jdb_success == '') {
                    $jdb = '[FAILED] : ' . date('M jS, Y g:i A', $jdb_fail - 7 * 3600);
                }
            } else {
                $jdb = '[SUCCESS] : ' . date('M jS, Y g:i A', $jdb_success - 7 * 3600);
            }
            $photo = $data->{$this->merge_fields('form_photo', $data->form_type)};
            // Check if we are loading the public description or a short description
            if (isset($data->public_description)) {
                $main_description = $data->public_description;
            } else {
                if (isset($data->short_description)) {
                    $main_description = $data->short_description;
                } else {
                    $main_description = '';
                }
            }
            ?>
<h1><?php 
            echo esc_html($data->{$this->merge_fields('project_name', $data->form_type)});
            ?>
</h1>
<input name="form_type" type="hidden"
	value="<?php 
            echo esc_attr($data->form_type);
            ?>
" />
<table style="width: 100%">
	<tr>
		<td style="width: 210px;" valign="top"><img
			src="<?php 
            //echo esc_url( get_resized_remote_image_url( $photo, 200, 200 ) );
            ?>
"
			width="200" height="200" /></td>
		<td valign="top">
			<p><?php 
            echo Markdown(stripslashes(wp_filter_post_kses(mf_convert_newlines($main_description, "\n"))));
            ?>
</p>
			<table style="width: 100%">
				<tr>
					<td style="width: 80px;" valign="top"><strong>Type:</strong></td>
					<td valign="top"><?php 
            echo esc_attr(ucfirst($data->form_type));
            ?>
</td>
				</tr>
				<tr>
					<td style="width: 80px;" valign="top"><strong>Status:</strong></td>
					<td valign="top"><?php 
            echo esc_attr($post->post_status);
            ?>
</td>
				</tr>
							<?php 
            if ($data->form_type == 'exhibit') {
                ?>
								<tr>
					<td valign="top"><strong>Commercial Maker:</strong></td>
					<td valign="top"><?php 
                echo esc_html($data->sales == '' ? 'N/A' : $data->sales);
                ?>
</td>
				</tr>
							<?php 
            }
            ?>
							<?php 
            $wkey = $this->merge_fields('project_website', $data->form_type);
            $vkey = $this->merge_fields('project_video', $data->form_type);
            ?>
							<tr>
					<td style="width: 80px;" valign="top"><strong>Website:</strong></td>
					<td valign="top"><a
						href="<?php 
            echo esc_url($data->{$wkey});
            ?>
" target="_blank"><?php 
            echo esc_url($data->{$wkey});
            ?>
</a></td>
				</tr>
				<tr>
					<td valign="top"><strong>Video:</strong></td>
								<?php 
            echo isset($data->project_video) ? '<td valign="top"><a href="' . esc_url($data->project_video) . '" target="_blank">' . esc_url($data->project_video) . '</a></td>' : null;
            echo isset($data->performer_video) ? '<td valign="top"><a href="' . esc_url($data->performer_video) . '" target="_blank">' . esc_url($data->performer_video) . '</a></td>' : null;
            echo isset($data->video) ? '<td valign="top"><a href="' . esc_url($data->video) . '" target="_blank">' . esc_url($data->video) . '</a></td>' : '<td></td>';
            ?>
							</tr>
							<?php 
            if ($data->form_type == 'exhibit') {
                ?>
								<tr>
					<td style="width: 80px;" valign="top"><strong>Supporting Documents:</strong></td>
					<td valign="top"><a
						href="<?php 
                echo esc_url($data->supporting_documents);
                ?>
"
						target="_blank"><?php 
                echo esc_url($data->supporting_documents);
                ?>
</a></td>
				</tr>
				<tr>
					<td style="width: 80px;" valign="top"><strong>Layout:</strong></td>
					<td valign="top"><a href="<?php 
                echo esc_url($data->layout);
                ?>
"
						target="_blank"><?php 
                echo esc_url($data->layout);
                ?>
</a></td>
				</tr>
							<?php 
            }
            ?>
							<?php 
            // Store the current application ID so we can return it within the loop
            $parent_post_id = get_the_ID();
            $args = array('post_type' => 'event-items', 'orderby' => 'meta_value', 'meta_key' => 'mfei_start', 'order' => 'asc', 'posts_per_page' => '30', 'meta_query' => array(array('key' => 'mfei_record', 'value' => $post->ID)));
            $get_events = new WP_Query($args);
            // Check that we have returned our query of events, if not, give the option to schedule the event
            if ($get_events->found_posts >= 1) {
                ?>
									<tr>
					<td style="width: 80px;"><strong>Scheduled:</strong></td>
					<td valign="top">Yes</a>
				
				</tr>
									<?php 
                // Loop through theme
                while ($get_events->have_posts()) {
                    $get_events->the_post();
                    // Get an array of our event data
                    $event_record = get_post_meta(get_the_ID());
                    // Setup the edit URL and add an edit link to the admin area
                    $edit_event_url = get_edit_post_link();
                    // Show the location this event is setup for
                    if (!empty($event_record['faire_location'][0])) {
                        ?>
											<tr>
					<td style="width: 80px;" valign="top"><strong>Location:</strong></td>
					<td valign="top"><?php 
                        // echo esc_html( get_the_title( intval( unserialize( $event_record['faire_location'][0] )[0] ) ) );
                        ?>
</td>
				</tr>
										
					<?php 
                    }
                    // Check that fields are set, and display them as needed.
                    if (!empty($event_record['mfei_day'][0])) {
                        ?>
											<tr <?php 
                        post_class();
                        ?>
>
					<td style="width: 80px;" valign="top"><strong>Day:</strong></td>
					<td valign="top"><?php 
                        echo esc_html($event_record['mfei_day'][0]);
                        ?>
</td>
				</tr>
										<?php 
                    }
                    if (!empty($event_record['mfei_start'][0])) {
                        ?>
											<tr class="<?php 
                        post_class();
                        ?>
">
					<td style="width: 80px;" valign="top"><strong>Start Time:</strong></td>
					<td valign="top"><?php 
                        echo esc_html($event_record['mfei_start'][0]);
                        ?>
</td>
				</tr>
										<?php 
                    }
                    if (!empty($event_record['mfei_stop'][0])) {
                        ?>
											<tr class="<?php 
                        post_class();
                        ?>
">
					<td style="width: 80px;" valign="top"><strong>Stop Time:</strong></td>
					<td valign="top"><?php 
                        echo esc_html($event_record['mfei_stop'][0]);
                        ?>
</td>
				</tr>
										<?php 
                    }
                    if (!empty($event_record['mfei_schedule_completed'][0])) {
                        ?>
											<tr class="<?php 
                        post_class();
                        ?>
">
					<td style="width: 80px;" valign="top"><strong>Schedule Completed:</strong></td>
					<td valign="top"><?php 
                        echo esc_html($event_record['mfei_schedule_completed'][0]);
                        ?>
</td>
				</tr>
										<?php 
                    }
                    ?>
											<tr class="<?php 
                    post_class();
                    ?>
">
					<td valign="top"><strong>Edit</strong></td>
					<td><a href="<?php 
                    echo esc_url($edit_event_url);
                    ?>
"
						class="button" target="_blank">Edit the Time and Date</a>
						<button href=""
							class="deleteme button-small button-secondary delete"
							data-key="mfei_record"
							data-nonce="<?php 
                    echo esc_attr(wp_create_nonce('delete_scheduled_post'));
                    ?>
"
							data-postid="<?php 
                    echo esc_attr(get_the_id());
                    ?>
"
							data-value="<?php 
                    echo esc_attr($event_record['mfei_record'][0]);
                    ?>
"
							title="">Delete Scheduled Event</button></td>
				</tr>

									<?php 
                }
                ?>
									<tr>
					<td style="width: 80px;" valign="top"><strong>Schedule:</strong></a></td>
					<td valign="top"><a
						href="<?php 
                echo admin_url();
                ?>
post-new.php?post_type=event-items&amp;refer_id=<?php 
                echo absint($parent_post_id);
                ?>
">Schedule
							Another Event</a></td>
				</tr>
								<?php 
            } else {
                ?>
									<tr>
					<td style="width: 80px;" valign="top"><strong>Scheduled:</strong></a></td>
					<td valign="top"><a
						href="<?php 
                echo admin_url();
                ?>
post-new.php?post_type=event-items&amp;refer_id=<?php 
                echo get_the_ID();
                ?>
">Schedule
							This Event</a></td>
				</tr>
								<?php 
            }
            ?>
							<tr>
					<td style="width: 80px;" valign="middle"><strong>MF Video:</strong></td>
					<td valign="top"><input type="text" id="video-coverage"
						name="video-coverage" style="width: 25%;"
						value="<?php 
            echo !empty($event_record['mfei_coverage'][0]) ? esc_url($event_record['mfei_coverage'][0]) : '';
            ?>
" />
						<input type="hidden" name="event-id"
						value="<?php 
            echo get_the_ID();
            ?>
" /></td>
				</tr>
				<tr>
					<td valign="top"><strong>JDB Sync:</strong></td>
					<td valign="top"><?php 
            echo esc_html($jdb);
            ?>
</td>
				</tr>
			</table>
		</td>
	</tr>
</table>
<?php 
        } elseif ($args['id'] == 'mf_details') {
            // Details Metabox
            // Why do we have so much crap in this method? Let's break this up... because I'm losing my mind here :P
            $this->app_details($post, $args, $data);
        } elseif ($args['id'] == 'mf_presenter_promos') {
            // Load the presenter promo meta box for Eventbrite. This is used to store promo codes to give to Presenters
            $this->presenter_promos($post, $args, $data);
        } elseif ($args['id'] == 'mf_maker_contact') {
            // Display "Contact Info" for the contact of the application.
            $photo_thumb_key = $this->merge_fields('user_photo_thumb', $data->form_type);
            $photo_key = $this->merge_fields('user_photo', $data->form_type);
            $bio_key = $this->merge_fields('user_bio', $data->form_type);
            $photo = isset($data->{$photo_thumb_key}) ? $data->{$photo_thumb_key} : '';
            if ('' == $photo) {
                $photo = isset($data->{$photo_key}) ? $data->{$photo_key} : '';
            }
            if (is_array($photo)) {
                $photo = $photo[0];
            }
            $bio = isset($data->{$bio_key}) ? $data->{$bio_key} : '';
            if (is_array($bio)) {
                $bio = $bio[0];
            }
            ?>

<img src="<?php 
            echo esc_url($photo);
            ?>
"
	style="float: left; margin-right: 10px;" height="75" width="75" />
<div style="float: left; width: 150px;">
	<strong><?php 
            echo esc_html($data->name);
            ?>
</strong><br />
				<?php 
            echo esc_html($data->phone1);
            ?>
<br />
				<?php 
            echo esc_html($data->email);
            ?>
			</div>
<div style="clear: both; height: 15px;"></div>
<strong>ADDRESS</strong>
<br />
<?php 
            echo esc_html($data->private_address . ' ' . $data->private_address2);
            ?>
<br />
<?php 
            echo esc_html($data->private_city . ', ' . $data->private_state . ' ' . $data->private_zip . ' ' . $data->private_country);
            ?>
<br />
<br />
<strong>Bio</strong>
<br />
<?php 
            echo wp_kses_post(mf_convert_newlines($bio));
            ?>

		<?php 
        } elseif ($args['id'] == 'mf_maker_info') {
            $maker_type = !empty($data->maker) ? $data->maker : $data->form_type;
            if ($maker_type == 'One maker') {
                $result = esc_html($data->maker_name) . ' <a target="_blank" style="float:right" href="' . esc_url(admin_url('/edit.php?s=' . urlencode($data->maker_name) . '&post_status=all&post_type=maker')) . '">Lookup Maker</a>';
            } elseif ($maker_type == 'A list of makers') {
                $result = '';
                foreach ($data->m_maker_name as $maker_name) {
                    $result .= esc_html($maker_name) . ' <a target="_blank" style="float:right" href="' . esc_url(admin_url('/edit.php?s=' . urlencode($maker_name) . '&post_status=all&post_type=maker')) . '">Lookup Maker</a><br />';
                }
            } elseif ($maker_type == 'A group or association') {
                $result = esc_html($data->group_name) . ' <a target="_blank" style="float:right" href="' . esc_url(admin_url('/edit.php?s=' . urlencode($data->group_name) . '&post_status=all&post_type=maker')) . '">Lookup Maker</a>';
            } elseif ($maker_type == 'performer') {
                $result = esc_html($data->performer_name) . ' <a target="_blank" style="float:right" href="' . esc_url(admin_url('/edit.php?s=' . urlencode($data->performer_name) . '&post_status=all&post_type=maker')) . '">Lookup Maker</a>';
            } elseif ($maker_type == 'presenter') {
                if (is_array($data->presenter_name)) {
                    foreach ($data->presenter_name as $presenter) {
                        $result = esc_html($presenter) . ' <a target="_blank" style="float:right" href="' . esc_url(admin_url('/edit.php?s=' . urlencode($presenter) . '&post_status=all&post_type=maker')) . '">Lookup Maker</a>';
                    }
                } else {
                    $result = esc_html($data->presenter_name) . ' <a target="_blank" style="float:right" href="' . esc_url(admin_url('/edit.php?s=' . urlencode($data->presenter_name) . '&post_status=all&post_type=maker')) . '">Lookup Maker</a>';
                }
            } else {
                $result = 'Could not find makers to list!';
            }
            echo '<strong>' . $result . '</strong>';
        } elseif ($args['id'] == 'mf_form_type') {
            ?>

<input class="mf_form_type" name="form_type" type="radio"
	value="exhibit" />
&nbsp; Exhibit Application &nbsp;
<input class="mf_form_type" name="form_type" type="radio"
	value="performer" />
&nbsp; Performer Application &nbsp;
<input class="mf_form_type" name="form_type" type="radio"
	value="presenter" />
&nbsp; Presenter Application
<script type="text/javascript">
				(function($){
					$(document).ready(function() {
						$('#mf_exhibit, #mf_performer, #mf_presenter').hide();
						$('.mf_form_type').click(function(){
							$('#mf_exhibit, #mf_performer, #mf_presenter').hide();
							form_type = $(this).val();

							if ( form_type == 'exhibit' )
								$( '#maker input[value="One maker"]' ).click();

							$('#mf_'+form_type).show();
						} );
					} );
				} )(jQuery.noConflict())
			</script>

<?php 
        } elseif (in_array($args['id'], array('mf_exhibit', 'mf_performer', 'mf_presenter', 'mf_logistics'))) {
            if ($args['id'] != 'mf_logistics') {
                $data = array('form_type' => $args['args']['type'], 'maker_faire' => $this->maker_faire);
                foreach ($this->fields[$args['args']['type']] as $sn => $s) {
                    foreach (array_keys($s) as $k) {
                        $data[$k] = '';
                    }
                }
                $data = (object) $data;
            }
            if (!isset($data->cats)) {
                $data = (object) array_merge(array('cats' => ''), (array) $data);
            }
            if (!isset($data->tags)) {
                $data = (object) array_merge(array('tags' => ''), (array) $data);
            }
            if (!isset($data->uid)) {
                $data = (object) array_merge(array('uid' => ''), (array) $data);
            }
            $cont = array('m_maker_email', 'm_maker_gigyaid', 'm_maker_photo', 'm_maker_bio', 'presenter_email', 'presenter_gigyaid', 'presenter_bio', 'presenter_onsite_phone', 'presenter_org', 'presenter_title', 'presenter_photo', 'presenter_twitter', 'presenter_previous');
            ?>

<table style="width: 100%">

				<?php 
            foreach ((array) $data as $k => $v) {
                if (in_array($k, $cont)) {
                    continue;
                }
                ?>
					<tr class="mf-form-row" id="<?php 
                echo esc_attr($k);
                ?>
"
		<?php 
                if (strpos($k, '_thumb') !== false) {
                    ?>
		style="display: none" <?php 
                }
                ?>
>
		<td valign="top"><?php 
                echo esc_html(ucwords(str_replace('_', ' ', $k)));
                ?>
:</td>
		<td>
						<?php 
                $this->display_edit_field($data->form_type, $k, $v, (array) $data);
                ?>
					<?php 
                if ($k != 'm_maker_name' && $k != 'presenter_name') {
                    ?>
					</td>
	</tr>
					<?php 
                }
                ?>
				<?php 
            }
            ?>
				<tr>
		<td></td>
	</tr>

</table>

<?php 
            if ($args['id'] == 'mf_logistics' || $args['id'] == 'mf_presenter') {
                if (isset($data->m_maker_name) && is_array($data->m_maker_name)) {
                    $number_of_makers = count($data->m_maker_name);
                } elseif (isset($data->presenter_name) && is_array($data->presenter_name)) {
                    $number_of_makers = count($data->presenter_name);
                } else {
                    $number_of_makers = 1;
                }
                ?>
<script type="text/javascript">

					jQuery(function($) {

						form_type      = '<?php 
                echo esc_html($data->form_type);
                ?>
';
						num_makers     = <?php 
                echo intval($number_of_makers);
                ?>
;
						num_presenters = <?php 
                echo intval(isset($data->presenter_name) && is_array($data->presenter_name) ? count($data->presenter_name) + 1 : 1);
                ?>
;

						$('#maker input[type=radio]').click(function(){
							$('#maker_name, #maker_email, #maker_photo, #maker_bio, #m_maker_name, .m_maker_name, .add-maker, #group_name, #group_website, #group_photo, #group_bio, .remove-maker').hide();
							if ( $(this).val() == 'One maker' ) {
								$('#maker_name, #maker_email, #maker_photo, #maker_bio').show();
							} else if ( $(this).val() == 'A list of makers' ) {
								$('#m_maker_name, .m_maker_name, .add-maker, .remove-maker').show();
							} else {
								$('#group_name, #group_website, #group_photo, #group_bio').show();
							}
						} );

						mf_insert_add_maker_btn();

						if( form_type == 'exhibit' ) {
							$( '#maker input[value="<?php 
                echo esc_attr(isset($data->maker) ? $data->maker : 'One maker');
                ?>
"]' ).click();
						}

						function mf_insert_add_maker_btn()
						{
							html = '<tr id="'+form_type+'-add-maker" class="mf-form-row add-maker add-maker-btn">'+
										'<td colspan="2">'+
											'<input type="button" value="+Add Maker" class="button button-primary button-large"> '+
											'<div style="float:right"><a href="<?php 
                echo esc_url(admin_url('/edit.php?post_type=maker'));
                ?>
" target="_blank">Lookup GIGYA ID</a></div>'+
										'</td>'+
									'</tr>';

							$(html).insertAfter( $('#m_maker_bio, #presenter_previous') );
							$('.add-maker-btn .button').unbind('click').click(mf_add_maker);
						}

						function mf_add_maker() {

							fields = {
								exhibit : {
									m_maker_name    : 'Add. Maker Name',
									m_maker_email   : 'Add. Maker Email',
									m_maker_gigyaid : 'Add. Maker Gigyaid',
									m_maker_bio     : 'Add. Maker Bio',
									m_maker_twitter : 'Add. Maker Twitter',
									m_maker_photo   : 'Add. Maker Photo URL'
								},
								presenter : {
									presenter_name     : 'Add. Presenter Name',
									presenter_email    : 'Add. Presenter Email',
									presenter_gigyaid  : 'Add. Presenter Gigyaid',
									presenter_bio      : 'Add. Presenter Bio',
									presenter_org      : 'Add. Presenter Organization',
									presenter_title    : 'Add. Presenter Title',
									presenter_photo    : 'Add. Presenter Photo URL',
									presenter_twitter  : 'Add. Presenter Twitter',
									presenter_previous : 'Add. Presenter Previous'
								}
							};

							html  = '';
							for(i in fields[form_type]) {
								if ( i === 'presenter_bio' || i === 'm_maker_bio' ) {
									html += console.log(i);
									html += '<tr class="mf-form-row add-maker"><td valign="top">'+fields[form_type][i]+':</td><td><textarea name="' + form_type + '[' + i + '][' + num_makers + ']" id="" cols="30" rows="10"></textarea></td></tr>';
								} else {
									html += '<tr class="mf-form-row add-maker"><td valign="top">'+fields[form_type][i]+':</td><td><input type="text" name="'+form_type+'['+i+']['+num_makers+']"></td></tr>';
								}
							}
							html += '<tr class="remove-maker">'+
										'<td colspan="2">'+
											'<input type="button" onclick="mf_remove_maker( this )" value="Remove Maker Above" class="button button-primary button-large"></td></tr>';

							$(html).insertAfter($('.add-maker-btn'));

							num_makers++;
						}
					} );

					function mf_remove_maker( el ) {
						p = jQuery( el ).parent().parent();
						l = form_type == 'exhibit' ? 5 : 7;
						for( i = 0; i < l; i++ ) {
							p.prev().remove();
						}
						p.remove();
					}

				</script>

			<?php 
            }
        }
    }
コード例 #4
0
ファイル: functions.php プロジェクト: hansstam/makerfaire
/**
 * Allows us to clean the nasty garbled code that gets saved to the database for applications
 * Over time this function will phase out as we rebuild the form system
 * @param  String  $content The application content we want to clean. This should be looped through an array
 * @param  Boolean $report  Setting to true will remove any HTML formating we are correcting as we don't want that output to our reports
 * @return String
 *
 * @since L-Ron
 */
function mf_clean_content($content, $report = false)
{
    $bad = array('&#039;', "\\'", '\\"', '&#8217;', 'u2019', '&#38;', '&#038;', '&amp;', '&#34;', '&#034;', 'u201c', 'u201d', '&#8211;', '&lt;', '&#8230;', 'u00a0', 'u2013', '00ae', 'u016f', 'u0161', 'u00e1', 'u2122', 'u00a9');
    $good = array("'", "'", '"', "'", "'", '&', '&', '&', '"', '"', '"', '"', '–', '>', '...', ' ', '-', '®', 'ů', 'š', 'á', '™', '©');
    // If we are are correct HTML, let's add that here as reports we don't want HTML shown in here
    if ($report) {
        array_push($bad, '<br />\\rn', '<br />rn', '<br />nn', 'rnrn', '<br />', '\\rn', '.rn');
        array_push($good, ' ', ' ', ' ', ' ', ' ', ' ', ' ');
    } else {
        array_push($bad, '<br />\\rn', '<br />rn', '<br />nn', 'rnrn', '.rn');
        array_push($good, '<br /><br />', '<br /><br />', '<br /><br />', '<br /><br />', '.<br /><br />');
    }
    $cleaned = str_replace($bad, $good, htmlspecialchars_decode(mf_convert_newlines($content)));
    return $cleaned;
}