Esempio n. 1
0
 /**
  * Prepare post data
  *
  * @param array  $post    The unprepared post data
  * @param string $context The context for the prepared post. (view|view-revision|edit|embed|single-parent)
  *
  * @return array The prepared post data
  */
 protected function prepare_post($post, $context = 'view')
 {
     // Holds the data for this post.
     $_post = array('ID' => absint($post['ID']));
     if (!$this->check_read_permission($post)) {
         return new WP_Error('json_user_cannot_read', __('Sorry, you cannot read this post.'), array('status' => 401));
     }
     $post_obj = get_post($post['ID']);
     $GLOBALS['post'] = $post_obj;
     setup_postdata($post_obj);
     // Prepare common post fields
     $post_fields = array('title' => get_the_title($post['ID']), 'type' => $post['post_type'], 'link' => get_permalink($post['ID']));
     $post_fields_extended = array('slug' => $post['post_name'], 'avatar' => Helper::get_avatar_url($post['ID'], 512), 'excerpt' => $this->prepare_excerpt($post['post_excerpt']), 'content' => apply_filters('the_content', $post['post_content']), 'byline' => esc_html(get_post_meta($post['ID'], 'byline', true)));
     // Get connected company
     $companies = get_posts(array('connected_type' => 'hiring', 'connected_items' => $post, 'posts_per_page' => -1, 'suppress_filters' => false));
     $post_fields_extended['company'] = array('ID' => absint($companies[0]->ID), 'title' => get_the_title($companies[0]->ID), 'link' => get_permalink($companies[0]->ID), 'slug' => $companies[0]->post_name, 'excerpt' => $this->prepare_excerpt($companies[0]->post_excerpt), 'meta' => array('self' => json_url('/talents/' . $companies[0]->ID), 'collection' => json_url('/talents')));
     // Dates
     if ('0000-00-00 00:00:00' === $post['post_date_gmt']) {
         $post_fields['date'] = null;
         $post_fields_extended['date_gmt'] = null;
     } else {
         $post_fields['date'] = json_mysql_to_rfc3339($post['post_date']);
         $post_fields_extended['date_gmt'] = json_mysql_to_rfc3339($post['post_date_gmt']);
     }
     if ('0000-00-00 00:00:00' === $post['post_modified_gmt']) {
         $post_fields['modified'] = null;
         $post_fields_extended['modified_gmt'] = null;
     } else {
         $post_fields['modified'] = json_mysql_to_rfc3339($post['post_modified']);
         $post_fields_extended['modified_gmt'] = json_mysql_to_rfc3339($post['post_modified_gmt']);
     }
     // Merge requested $post_fields fields into $_post
     $_post = array_merge($_post, $post_fields);
     // Include extended fields. We might come back to this.
     $_post = array_merge($_post, $post_fields_extended);
     // Entity meta
     $links = array('self' => json_url('/jobs/' . $post['ID']), 'collection' => json_url('/jobs'));
     $_post['meta'] = array('links' => $links);
     return apply_filters('json_prepare_talent', $_post, $post, $context);
 }
Esempio n. 2
0
 /**
  * Prepare oEmbed response.
  *
  * @param array $post The unprepared post data
  * @param int   $maxwidth
  * @param int   $maxheight
  *
  * @return array The prepared post data
  */
 protected function prepare_response($post, $maxwidth, $maxheight)
 {
     $post_obj = get_post($post['ID']);
     $GLOBALS['post'] = $post_obj;
     setup_postdata($post_obj);
     // Prepare common post fields
     $response_fields = array('version' => '1.0', 'provider_name' => get_bloginfo('name'), 'provider_url' => get_home_url(), 'title' => $post_obj->post_title, 'type' => 'rich', 'cache_age' => WEEK_IN_SECONDS, 'html' => $this->get_oembed_html($post_obj, $maxwidth, $maxheight), 'thumbnail_url' => Helper::get_avatar_url($post_obj, 512), 'thumbnail_width' => 512, 'thumbnail_height' => 512);
     return apply_filters('json_prepare_oembed', $response_fields, $post, $maxwidth, $maxheight);
 }
Esempio n. 3
0
 /**
  * Prepare post data
  *
  * @param array  $post    The unprepared post data
  * @param string $context The context for the prepared post. (view|view-revision|edit|embed|single-parent)
  *
  * @return array The prepared post data
  */
 protected function prepare_post($post, $context = 'view')
 {
     // Holds the data for this post.
     $_post = array('ID' => absint($post['ID']));
     if (!$this->check_read_permission($post)) {
         return new WP_Error('json_user_cannot_read', __('Sorry, you cannot read this post.'), array('status' => 401));
     }
     $post_obj = get_post($post['ID']);
     $GLOBALS['post'] = $post_obj;
     setup_postdata($post_obj);
     // Fetch our talent meta
     $talent_meta = Helper::get_talent_meta($post_obj);
     // Prepare common post fields
     $post_fields = array('title' => get_the_title($post['ID']), 'type' => $post['post_type'], 'link' => get_permalink($post['ID']));
     $post_fields_extended = array('slug' => $post['post_name'], 'avatar' => Helper::get_avatar_url($post['ID'], 512), 'excerpt' => $this->prepare_excerpt($post['post_excerpt']), 'content' => apply_filters('the_content', $post['post_content']), 'byline' => esc_html(get_post_meta($post['ID'], 'byline', true)), 'job' => (string) get_post_meta($post['ID'], 'job', true), 'wordpress_vip' => 1 == get_post_meta($post['ID'], 'wordpress_vip', true) ? true : false, 'location' => $talent_meta['map'], 'score' => $talent_meta['score'], 'social' => $talent_meta['social'], 'badges' => $talent_meta['profile']['badges'], 'contributions' => array('codex' => array('count' => $talent_meta['codex_count']), 'props' => array('count' => $talent_meta['changeset_count']), 'core' => $talent_meta['contributions']), 'plugins' => $talent_meta['plugins'], 'themes' => $talent_meta['themes']);
     // A person can't be a WordPress.com VIP
     if ('person' === $post['post_type']) {
         unset($post_fields_extended['wordpress_vip']);
     }
     if ('company' === $post['post_type']) {
         // Company itself has no job
         unset($post_fields_extended['job']);
         // Find connected team members
         $people = get_posts(array('connected_type' => 'team', 'connected_items' => $post, 'posts_per_page' => -1, 'suppress_filters' => false));
         /** @var \WP_Post $person */
         foreach ($people as $person) {
             // Fetch our talent meta
             $person_meta = Helper::get_talent_meta($person);
             $post_fields_extended['team'][] = array('ID' => absint($person->ID), 'title' => get_the_title($person->ID), 'type' => $person->post_type, 'link' => get_permalink($person->ID), 'slug' => $person->post_name, 'avatar' => Helper::get_avatar_url($person, 512), 'excerpt' => $this->prepare_excerpt($person->post_excerpt), 'byline' => esc_html(get_post_meta($person->ID, 'byline', true)), 'job' => (string) get_post_meta($person->ID, 'job', true), 'location' => $person_meta['map'], 'score' => $person_meta['score'], 'meta' => array('self' => json_url('/talents/' . $person->ID), 'collection' => json_url('/talents')));
         }
     }
     // Company itself has no job
     unset($post_fields_extended['job']);
     // Find connected team members
     $products = get_posts(array('connected_type' => 'product_owner', 'connected_items' => $post, 'posts_per_page' => -1, 'suppress_filters' => false));
     /** @var \WP_Post $product */
     foreach ($products as $product) {
         $thumbnail = '';
         if (has_post_thumbnail($product)) {
             $image = wp_get_attachment_image_src(get_post_thumbnail_id($product), 'large');
             if ($image) {
                 $thumbnail = $image[0];
             }
         }
         $post_fields_extended['products'][] = array('ID' => absint($product->ID), 'title' => get_the_title($product->ID), 'link' => get_permalink($product->ID), 'slug' => $product->post_name, 'image' => $thumbnail, 'excerpt' => $this->prepare_excerpt($product->post_excerpt), 'byline' => esc_html(get_post_meta($product->ID, 'byline', true)), 'meta' => array('self' => json_url('/products/' . $product->ID), 'collection' => json_url('/products')));
     }
     // Find connected jobs
     $jobs = get_posts(array('connected_type' => 'hiring', 'connected_items' => $post, 'posts_per_page' => -1, 'suppress_filters' => false));
     /** @var \WP_Post $job */
     foreach ($jobs as $job) {
         $post_fields_extended['jobs'][] = array('ID' => absint($job->ID), 'title' => get_the_title($job->ID), 'link' => get_permalink($job->ID), 'slug' => $job->post_name, 'excerpt' => $this->prepare_excerpt($job->post_excerpt), 'meta' => array('self' => json_url('/jobs/' . $job->ID), 'collection' => json_url('/jobs')));
     }
     // Dates
     if ('0000-00-00 00:00:00' === $post['post_date_gmt']) {
         $post_fields['date'] = null;
         $post_fields_extended['date_gmt'] = null;
     } else {
         $post_fields['date'] = json_mysql_to_rfc3339($post['post_date']);
         $post_fields_extended['date_gmt'] = json_mysql_to_rfc3339($post['post_date_gmt']);
     }
     if ('0000-00-00 00:00:00' === $post['post_modified_gmt']) {
         $post_fields['modified'] = null;
         $post_fields_extended['modified_gmt'] = null;
     } else {
         $post_fields['modified'] = json_mysql_to_rfc3339($post['post_modified']);
         $post_fields_extended['modified_gmt'] = json_mysql_to_rfc3339($post['post_modified_gmt']);
     }
     // Merge requested $post_fields fields into $_post
     $_post = array_merge($_post, $post_fields);
     // Include extended fields. We might come back to this.
     $_post = array_merge($_post, $post_fields_extended);
     // Entity meta
     $links = array('self' => json_url('/talents/' . $post['ID']), 'collection' => json_url('/talents'));
     $_post['meta'] = array('links' => $links);
     return apply_filters('json_prepare_talent', $_post, $post, $context);
 }