function wp_browser_search() { if ($_GET['apiKey'] != $this->api_key) { wp_send_json_error(array('error' => 'Invalid API Key')); } global $budget_sections; if (!empty($_GET['filter_list'])) { wp_send_json_success(array_keys($budget_sections)); } //Build our args for the search $args = array('numberposts' => 20, 'post_type' => array('doc'), 'orderby' => 'modified'); //Yay, a query! if (!empty($_GET['s'])) { //$args[ 's' ] = '"' . $_GET[ 's' ] . '"'; //We don't need to specially query by slug because the slug is the post title! //@TODO: Do we need to validate? $args['s'] = $_GET['s']; } if (!empty($_GET['filter']) && !empty($budget_sections[$_GET['filter']])) { $lineups = get_option('a1-lineups', array()); if (isset($lineups[$_GET['filter']])) { $args['post__in'] = $lineups[$_GET['filter']]; } } if (empty($posts)) { $posts = get_posts($args); } $response = array(); foreach ($posts as $post) { $status = false; if (($last_placed_meta = get_post_meta($post->ID, '_placed', true)) != false && !empty($last_placed_meta)) { $status = $last_placed_meta; } elseif (($last_placed_page = get_post_meta($post->ID, '_placed_page', true)) !== false && !empty($last_placed_page)) { $status = 'Placed ' . $last_placed_page . ' ' . date('M j Y g:i a', strtotime(get_post_meta($post->ID, '_placed_datetime', true))); } else { $statuses = get_budget_item_multi($post, 'statuses'); if (!empty($statuses)) { $status = implode(', ', $statuses); } } $wp_ids = get_post_meta($post->ID, '_wpID', false); sort($wp_ids); //@TODO: Status //@TODO: Run this from newsroom instead //@TODO: Has the story been placed already //@TODO: MD5 of contents? $response[] = array('post_id' => end($wp_ids), 'author' => get_user_by('id', $post->post_author)->display_name, 'slug' => $post->post_title, 'depth' => round(str_word_count(strip_tags($post->post_content)) / 30), 'status' => $status); } wp_send_json_success($response); }
function budget_statuses($post = false, $link = true) { if (empty($post)) { global $post; } $statuses = get_budget_item_multi($post, 'statuses'); if (!empty($statuses)) { echo implode(', ', $statuses); } }
?> <?php setup_postdata($post); ?> <?php $status = false; ?> <?php if (strtotime($post->file_time) < time() - 60 * 60 * 24) { $status = 'OVERDUE'; } elseif (strtotime($post->file_time) > time() + 60 * 60 * 36) { $status = 'Upcoming'; } ?> <tr class="<?php echo $status == 'OVERDUE' && in_array('Published', get_budget_item_multi($post, 'statuses')) ? 'already_published' : ''; ?> <?php echo $status != 'Upcoming' ? 'noborder' : 'upcoming'; echo $i % 2 ? ' alt' : ''; ?> " wp-id="<?php the_ID(); ?> "> <td colspan="100%"> <input type="radio"> <?php echo $status ? $status . ':' : ''; ?>