/** * @access protected * * @return bool */ public function _retrieve_data() { $talent_meta = Helper::get_talent_meta($this->post); // Minimum value $score = 1; // Calculate plugins score $score += $this->_calculate_plugin_score($talent_meta['plugins']); // Calculate themes score $score += $this->_calculate_theme_score($talent_meta['themes']); // Calculate WordPress.org profile data score $score += $this->_calculate_badge_score($talent_meta['profile']['badges']); // Adjust score based on number of core contributions if (isset($talent_meta['contribution_count'])) { $score += $this->_calculate_contribution_score($talent_meta['contributions'], $talent_meta['codex_count'], $talent_meta['contribution_count']); } // Adjust score based on number of WordPress.tv videos $score += $this->_calculate_wordpresstv_score($talent_meta['wordpresstv']); $score += $this->_calculate_forums_score($talent_meta['forums']); // Get median score for the company if ('company' === get_post_type($this->post)) { if (1 == get_post_meta($this->post->ID, 'wordpress_vip')) { $score += 10; } $team_score = $this->_calculate_team_score(); if ($team_score) { $score = ($team_score + $score) / 2; } } update_post_meta($this->post->ID, '_score', absint($score)); update_post_meta($this->post->ID, '_score_expiration', time() + $this->expiration); return $score; }
public function register_taxonomy() { if (taxonomy_exists('region')) { register_taxonomy_for_object_type('region', $this->post_type); } else { $region_args = array('labels' => Helper::post_type_labels('Region', 'Regions'), 'hierarchical' => true, 'show_ui' => true, 'show_admin_column' => true, 'update_count_callback' => '_update_post_term_count', 'public' => true, 'show_tagcloud' => false, 'rewrite' => false); register_taxonomy('region', $this->post_type, $region_args); } if (taxonomy_exists('service')) { register_taxonomy_for_object_type('service', $this->post_type); } else { $region_args = array('labels' => Helper::post_type_labels('Service'), 'hierarchical' => true, 'show_ui' => true, 'show_admin_column' => true, 'update_count_callback' => '_update_post_term_count', 'public' => true, 'show_tagcloud' => false, 'rewrite' => false); register_taxonomy('service', $this->post_type, $region_args); } }
/** * @access protected * * @return bool */ public function _retrieve_data() { $profile = Helper::get_talent_meta($this->post, 'profile'); $url = str_replace('https://secure.gravatar.com/avatar/', 'https://www.gravatar.com/', $profile['avatar']); $url = remove_query_arg(array('s', 'd'), $url) . '.json'; $body = wp_remote_retrieve_body(wp_safe_remote_get($url)); if ('' === $body) { return false; } $body = json_decode($body); if (null === $body) { return false; } if (!isset($body->entry[0])) { return false; } $social = get_post_meta($this->post->ID, 'social', true); if (isset($social[0]) && is_array($social[0])) { foreach ($social[0] as $key => $value) { $social[$key] = $value; } unset($social[0]); } if (isset($body->entry[0]->accounts)) { foreach ($body->entry[0]->accounts as $account) { switch ($account->shortname) { case 'linkedin': $social['linkedin'] = $account->url; break; case 'twitter': case 'facebook': $social[$account->shortname] = $account->username; break; case 'google': $social['google-plus'] = $account->userid; break; case 'wordpress': $social['url'] = $account->url; default: break; } } } if (!empty($body->entry[0]->urls)) { $social['url'] = $body->entry[0]->urls[0]->value; } return (bool) update_post_meta($this->post->ID, 'social', $social); }
/** * 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); }
public function register_taxonomy() { $args = array('labels' => Helper::post_type_labels('Category', 'Categories'), 'hierarchical' => true, 'show_ui' => true, 'show_admin_column' => true, 'update_count_callback' => '_update_post_term_count', 'public' => true, 'show_tagcloud' => false, 'rewrite' => false); register_taxonomy('product-category', $this->post_type, $args); }
/** * @param WP_Post|int $post The post object or ID. * @param string $type The meta to retrieve. Defaults to all. * Possible values are: * - profile * - plugins * - themes * * @return mixed The required meta if available, * false if the post does not exist. */ function wptalents_get_talent_meta($post = null, $type = 'all') { return Helper::get_talent_meta(get_post($post), $type); }
/** * 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); }
/** * Fetches the map of the talent's location from Google Maps * and sets it as the post thumbnail. * * It also replaces all intermediate image sizes with * the file from Google Maps, as they are from better quality * and way smaller than the generated ones. * * @param int $post_id The ID of the current post. */ public function add_map_on_save_post($post_id) { // If this is just a revision or the post already has a thumbnail, don't proceed if (wp_is_post_revision($post_id) || has_post_thumbnail($post_id)) { return; } if (!in_array(get_post_type($post_id), array_keys($this->types))) { return; } // Get the talent's location data $location = Helper::get_talent_meta(get_post($post_id), 'location'); if (empty($location['name'])) { return; } $map_retina = sprintf('https://maps.googleapis.com/maps/api/staticmap?center=%s&scale=2&zoom=6&size=600x320&maptype=roadmap', urlencode($location['name'])); $tmp_retina = download_url($map_retina); $slug = get_post($post_id)->post_name; if ('' === $slug) { $slug = sanitize_title(get_the_title($post_id)); } // Set variables for storage $file_array = array('name' => $slug . '-map.png', 'tmp_name' => $tmp_retina); // If error storing temporarily, unlink if (is_wp_error($tmp_retina)) { return; } // do the validation and storage stuff $attachment_id = media_handle_sideload($file_array, $post_id, $location['name']); // If error storing permanently, unlink if (is_wp_error($attachment_id)) { unlink($file_array['tmp_name']); return; } // Set map as post thumbnail set_post_thumbnail($post_id, $attachment_id); // Add Normal image as image size of the attachment $metadata = wp_get_attachment_metadata($attachment_id); $attachment_path = get_attached_file($attachment_id); $attachment_file = basename($attachment_path); foreach ($this->get_image_sizes() as $size => $values) { $map = sprintf('https://maps.googleapis.com/maps/api/staticmap?center=%s&scale=1&zoom=6&size=%s&maptype=roadmap', urlencode($location['name']), $values['width'] . 'x' . $values['height']); $tmp = download_url($map); // Set variables for storage $file_array = array('name' => $metadata['sizes'][$size]['file'], 'tmp_name' => $tmp); // If error storing temporarily, unlink if (is_wp_error($tmp)) { unlink($file_array['tmp_name']); continue; } unlink(str_replace($attachment_file, $metadata['sizes'][$size]['file'], $attachment_path)); $post = get_post($post_id); $time = $post->post_date; $file = wp_handle_sideload($file_array, array('test_form' => false), $time); if (isset($file['error'])) { unlink($file_array['tmp_name']); } } }
/** * 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); }
public function register_post_type() { $args = array('labels' => Helper::post_type_labels('Job'), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array('slug' => $this->post_type), 'has_archive' => true, 'hierarchical' => false, 'menu_position' => 30, 'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'custom-fields')); register_post_type($this->post_type, $args); }
public function register_post_type() { $args = array('labels' => Helper::post_type_labels('Activity', 'Activities'), 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array('slug' => 'activity'), 'has_archive' => true, 'hierarchical' => false, 'menu_position' => 35, 'supports' => array('editor', 'custom-fields')); register_post_type($this->post_type, $args); }