├── index.php ├── languages └── index.php ├── .gitignore ├── uninstall.php ├── includes ├── types │ ├── Type.php │ ├── Job.php │ ├── Activity.php │ ├── Product.php │ ├── Company.php │ └── Person.php ├── collectors │ ├── Collector.php │ ├── Theme_Collector.php │ ├── Plugin_Collector.php │ ├── Changeset_Collector.php │ ├── Codex_Collector.php │ ├── Gravatar_Collector.php │ ├── Contribution_Collector.php │ ├── Forums_Collector.php │ ├── WordPressTv_Collector.php │ ├── Profile_Collector.php │ └── Score_Collector.php ├── core │ ├── Importer.php │ ├── Router.php │ ├── Helper.php │ └── Plugin.php ├── cmb │ └── Gmap_Field.php ├── cli │ └── Talent_Command.php └── api │ ├── Oembed_Provider.php │ ├── Jobs.php │ ├── Products.php │ └── Talents.php ├── composer.json ├── public └── template-tags.php ├── README.md ├── wptalents.php ├── js └── field-gmap.js ├── composer.lock └── LICENSE.txt /index.php: -------------------------------------------------------------------------------- 1 | post = $post; 30 | 31 | $may_renew = true; 32 | 33 | if ( 34 | ( defined( 'JSON_REQUEST' ) && JSON_REQUEST ) || 35 | ( defined( 'DOING_AJAX' ) && DOING_AJAX ) || 36 | ! is_singular() || 37 | isset( $_POST['action'] ) 38 | ) { 39 | $may_renew = false; 40 | } 41 | 42 | $this->options = array( 43 | 'username' => get_post_meta( $post->ID, 'wordpress-username', true ), 44 | 'may_renew' => $may_renew, 45 | ); 46 | 47 | $this->options = apply_filters( 'wptalents_data_collector_options', $this->options, $post ); 48 | 49 | } 50 | 51 | public abstract function get_data(); 52 | 53 | public abstract function _retrieve_data(); 54 | 55 | } -------------------------------------------------------------------------------- /public/template-tags.php: -------------------------------------------------------------------------------- 1 | post->ID, '_themes', true ); 18 | 19 | if ( ( ! $data || 20 | ( isset( $data['expiration'] ) && time() >= $data['expiration'] ) ) 21 | && $this->options['may_renew'] 22 | ) { 23 | add_action( 'shutdown', array( $this, '_retrieve_data' ) ); 24 | } 25 | 26 | if ( ! $data ) { 27 | return 0; 28 | } 29 | 30 | return $data['data']; 31 | } 32 | 33 | /** 34 | * @access protected 35 | * 36 | * @return bool 37 | */ 38 | public function _retrieve_data() { 39 | 40 | require_once ABSPATH . 'wp-admin/includes/theme.php'; 41 | 42 | $args = array( 43 | 'author' => $this->options['username'], 44 | 'per_page' => 30, 45 | 'fields' => array( 46 | 'description' => false, 47 | 'compatibility' => false, 48 | //'banners' => true, 49 | 'icons' => true, 50 | 'downloaded' => true, 51 | 'last_updated' => true, 52 | ), 53 | ); 54 | 55 | $data = themes_api( 'query_themes', $args ); 56 | 57 | if ( $data && isset( $data->themes ) ) { 58 | 59 | $data = array( 60 | 'data' => $data->themes, 61 | 'expiration' => time() + $this->expiration, 62 | ); 63 | 64 | update_post_meta( $this->post->ID, '_themes', $data ); 65 | 66 | return $data; 67 | } 68 | 69 | return false; 70 | 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /includes/collectors/Plugin_Collector.php: -------------------------------------------------------------------------------- 1 | post->ID, '_plugins', true ); 18 | 19 | if ( ( ! $data || 20 | ( isset( $data['expiration'] ) && time() >= $data['expiration'] ) ) 21 | && $this->options['may_renew'] 22 | ) { 23 | add_action( 'shutdown', array( $this, '_retrieve_data' ) ); 24 | } 25 | 26 | if ( ! $data ) { 27 | return 0; 28 | } 29 | 30 | return $data['data']; 31 | } 32 | 33 | /** 34 | * @access protected 35 | * 36 | * @return bool 37 | */ 38 | public function _retrieve_data() { 39 | 40 | require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; 41 | 42 | $args = array( 43 | 'author' => $this->options['username'], 44 | 'per_page' => 100, 45 | 'fields' => array( 46 | 'description' => false, 47 | 'compatibility' => false, 48 | //'banners' => true, 49 | 'icons' => true, 50 | 'downloaded' => true, 51 | 'last_updated' => true, 52 | ), 53 | ); 54 | 55 | $data = plugins_api( 'query_plugins', $args ); 56 | 57 | if ( $data && isset( $data->plugins ) ) { 58 | 59 | $data = array( 60 | 'data' => $data->plugins, 61 | 'expiration' => time() + $this->expiration, 62 | ); 63 | 64 | update_post_meta( $this->post->ID, '_plugins', $data ); 65 | 66 | return $data; 67 | } 68 | 69 | return false; 70 | 71 | } 72 | 73 | } -------------------------------------------------------------------------------- /includes/collectors/Changeset_Collector.php: -------------------------------------------------------------------------------- 1 | post->ID, '_changeset_count', true ); 18 | 19 | if ( ( ! $data || 20 | ( isset( $data['expiration'] ) && time() >= $data['expiration'] ) ) 21 | && $this->options['may_renew'] 22 | ) { 23 | add_action( 'shutdown', array( $this, '_retrieve_data' ) ); 24 | } 25 | 26 | if ( ! $data ) { 27 | return 0; 28 | } 29 | 30 | return $data['data']; 31 | 32 | } 33 | 34 | /** 35 | * @access protected 36 | * 37 | * @return bool 38 | */ 39 | public function _retrieve_data() { 40 | 41 | $results_url = add_query_arg( 42 | array( 43 | 'q' => 'props+' . $this->options['username'], 44 | 'noquickjump' => '1', 45 | 'changeset' => 'on', 46 | ), 47 | 'https://core.trac.wordpress.org/search' 48 | ); 49 | 50 | $results = wp_remote_retrieve_body( wp_safe_remote_get( $results_url ) ); 51 | 52 | if ( is_wp_error( $results ) ) { 53 | return false; 54 | } 55 | 56 | $pattern = '//'; 57 | 58 | preg_match( $pattern, $results, $matches ); 59 | 60 | $count = 0; 61 | 62 | if ( isset( $matches[1] ) ) { 63 | $count = intval( $matches[1] ); 64 | } 65 | 66 | $data = array( 67 | 'data' => $count, 68 | 'expiration' => time() + $this->expiration, 69 | ); 70 | 71 | update_post_meta( $this->post->ID, '_changeset_count', $data ); 72 | 73 | return $data; 74 | 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /includes/collectors/Codex_Collector.php: -------------------------------------------------------------------------------- 1 | post->ID, '_codex_count', true ); 18 | 19 | if ( ( ! $data || 20 | ( isset( $data['expiration'] ) && time() >= $data['expiration'] ) ) 21 | && $this->options['may_renew'] 22 | ) { 23 | add_action( 'shutdown', array( $this, '_retrieve_data' ) ); 24 | } 25 | 26 | if ( ! $data ) { 27 | return 0; 28 | } 29 | 30 | return $data['data']; 31 | 32 | } 33 | 34 | /** 35 | * @access protected 36 | * 37 | * @return bool 38 | */ 39 | public function _retrieve_data() { 40 | 41 | $results_url = add_query_arg( 42 | array( 43 | 'action' => 'query', 44 | 'list' => 'users', 45 | 'ususers' => $this->options['username'], 46 | 'usprop' => 'editcount', 47 | 'format' => 'json', 48 | ), 49 | 'https://codex.wordpress.org/api.php' 50 | ); 51 | 52 | $results = wp_remote_retrieve_body( wp_safe_remote_get( $results_url ) ); 53 | 54 | if ( is_wp_error( $results ) ) { 55 | return false; 56 | } 57 | 58 | $raw = json_decode( $results ); 59 | 60 | if ( isset( $raw->query->users[0]->editcount ) ) { 61 | $count = (int) $raw->query->users[0]->editcount; 62 | } else { 63 | $count = 0; 64 | } 65 | 66 | $data = array( 67 | 'data' => $count, 68 | 'expiration' => time() + $this->expiration, 69 | ); 70 | 71 | update_post_meta( $this->post->ID, '_codex_count', $data ); 72 | 73 | return $data; 74 | 75 | } 76 | 77 | } -------------------------------------------------------------------------------- /includes/types/Job.php: -------------------------------------------------------------------------------- 1 | Helper::post_type_labels( 'Job' ), 27 | 'public' => true, 28 | 'show_ui' => true, 29 | 'show_in_menu' => true, 30 | 'query_var' => true, 31 | 'rewrite' => array( 32 | 'slug' => $this->post_type, 33 | ), 34 | 'has_archive' => true, 35 | 'hierarchical' => false, 36 | 'menu_position' => 30, 37 | 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'custom-fields' ), 38 | ); 39 | 40 | register_post_type( $this->post_type, $args ); 41 | 42 | } 43 | 44 | public function register_taxonomy() {} 45 | 46 | /** 47 | * Add CMB meta boxes. 48 | * 49 | * @param array $meta_boxes 50 | * 51 | * @return array|mixed 52 | */ 53 | public function add_meta_boxes( array $meta_boxes ) { 54 | 55 | return $meta_boxes; 56 | 57 | } 58 | 59 | /** 60 | * Filters the body_class. 61 | * 62 | * @param array $classes 63 | * 64 | * @return array 65 | */ 66 | public function filter_body_class( array $classes ) { 67 | 68 | return $classes; 69 | 70 | } 71 | 72 | /** 73 | * Filters the post_class. 74 | * 75 | * @param array $classes 76 | * 77 | * @return array 78 | */ 79 | public function filter_post_class( array $classes ) { 80 | 81 | return $classes; 82 | 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WP Talents 2 | 3 | This is the main plugin used on WPTalents.com to collect and display data about WordPress talents. It features various content types and data collectors. 4 | 5 | 6 | ## Features 7 | 8 | * Registers content types 9 | * Collects data from various sources like WordPress.org and WordPress.tv 10 | * Stores this data using post meta fields and transients 11 | 12 | ## Installation 13 | 14 | 1. Install plugin via composer. 15 | 2. Done. 16 | 17 | (or download the ZIP file and upload it in your WordPress install) 18 | 19 | Note: 20 | 21 | The WP Talents plugin uses Composer to manage dependencies so make sure to familiarize with that. It is also assumed that the [WP-API](https://github.com/WP-API/WP-API) and [CMB](https://github.com/humanmade/Custom-Meta-Boxes) plugin is installed. 22 | 23 | ## License 24 | 25 | The WP Talents Plugin is licensed under the GPL v2 or later. 26 | 27 | A copy of the license is included in the root of the plugin’s directory. The file is named `LICENSE.txt`. 28 | 29 | ## Credits 30 | 31 | Some code was inspired/borrowed from Marko Heijnen’s [wpcentral-api](https://github.com/markoheijnen/wpcentral-api) project. 32 | 33 | Data is collected from these sites: 34 | 35 | * [profiles.wordpress.org](https://profiles.wordpress.org/swissspidy/) 36 | * [Trac](https://core.trac.wordpress.org) 37 | * [WordPress Codex](https://codex.wordpress.org) 38 | * [WordPress Credits API](https://api.wordpress.org/core/credits/1.1/) 39 | * [WordPress.tv](https://wordpress.tv) 40 | * [Forums](https://wordpress.org/support/) 41 | * [Themes/Plugins API](http://codex.wordpress.org/WordPress.org_API) 42 | 43 | Thanks to all of these projects without whom WP Talents wouldn’t be possible. 44 | 45 | ## Issues 46 | 47 | If you identify any errors or have an idea for improving the plugin, please open an issue. I’m excited to see what the community thinks of this project, and I would love your input! -------------------------------------------------------------------------------- /includes/types/Activity.php: -------------------------------------------------------------------------------- 1 | Helper::post_type_labels( 'Activity', 'Activities' ), 23 | 'public' => true, 24 | 'show_ui' => true, 25 | 'show_in_menu' => true, 26 | 'query_var' => true, 27 | 'rewrite' => array( 28 | 'slug' => 'activity', 29 | ), 30 | 'has_archive' => true, 31 | 'hierarchical' => false, 32 | 'menu_position' => 35, 33 | 'supports' => array( 'editor', 'custom-fields' ), 34 | ); 35 | 36 | register_post_type( $this->post_type, $args ); 37 | 38 | } 39 | 40 | public function register_taxonomy() { 41 | 42 | $args = array( 43 | 'show_ui' => true, 44 | 'show_admin_column' => true, 45 | 'update_count_callback' => '_update_post_term_count', 46 | 'public' => true, 47 | 'show_tagcloud' => false, 48 | 'rewrite' => false, 49 | ); 50 | 51 | register_taxonomy( 'activity-type', $this->post_type, $args ); 52 | 53 | } 54 | 55 | /** 56 | * @param array $meta_boxes 57 | * 58 | * @return array 59 | */ 60 | public function add_meta_boxes( array $meta_boxes ) { 61 | 62 | return $meta_boxes; 63 | 64 | } 65 | 66 | /** 67 | * @param array $classes 68 | * 69 | * @return array 70 | */ 71 | public function filter_body_class( array $classes ) { 72 | 73 | return $classes; 74 | 75 | } 76 | 77 | /** 78 | * @param array $classes 79 | * 80 | * @return array 81 | */ 82 | public function filter_post_class( array $classes ) { 83 | 84 | return $classes; 85 | 86 | } 87 | 88 | } -------------------------------------------------------------------------------- /wptalents.php: -------------------------------------------------------------------------------- 1 | 7 | * @license GPL-2.0+ 8 | * @link https://spinpress.com 9 | * @copyright 2014 WP Talents 10 | * 11 | * @wordpress-plugin 12 | * Plugin Name: WP Talents 13 | * Plugin URI: https://spinpress.com 14 | * Description: AngelList + CrunchBase + WordPress = ♥ 15 | * Version: 0.0.1 16 | * Author: Pascal Birchler 17 | * Author URI: https://spinpress.com 18 | * Text Domain: wptalents 19 | * License: GPL-2.0+ 20 | * License URI: http://www.gnu.org/licenses/gpl-2.0.txt 21 | * Domain Path: /languages 22 | */ 23 | 24 | // If this file is called directly, abort. 25 | defined( 'ABSPATH' ) or die(); 26 | 27 | // Define our constants 28 | ( ! defined( 'WP_TALENTS_DIR' ) ) && define( 'WP_TALENTS_DIR', plugin_dir_path( __FILE__ ) ); 29 | ( ! defined( 'WP_TALENTS_URL' ) ) && define( 'WP_TALENTS_URL', plugins_url( '', __FILE__ ) ); 30 | 31 | if ( file_exists( WP_TALENTS_DIR . 'vendor/autoload.php' ) ) { 32 | require_once( WP_TALENTS_DIR . 'vendor/autoload.php' ); 33 | } 34 | 35 | // WP-CLI Command 36 | if ( defined( 'WP_CLI' ) && WP_CLI ) { 37 | include( WP_TALENTS_DIR . 'includes/cli/Talent_Command.php' ); 38 | } 39 | 40 | /** 41 | * Register hooks that are fired when the plugin is activated or deactivated. 42 | * When the plugin is deleted, the uninstall.php file is loaded. 43 | */ 44 | 45 | function wptalents_activation() { 46 | 47 | $wptalents = new WPTalents\Core\Plugin(); 48 | $wptalents->activate(); 49 | 50 | } 51 | 52 | register_activation_hook( __FILE__, 'wptalents_activation' ); 53 | 54 | function wptalents_deactivation() { 55 | 56 | $wptalents = new \WPTalents\Core\Plugin(); 57 | $wptalents->deactivate(); 58 | 59 | } 60 | 61 | register_deactivation_hook( __FILE__, 'wptalents_deactivation' ); 62 | 63 | 64 | /** 65 | * Plugin Initialization 66 | */ 67 | function wptalents_startup() { 68 | require_once( 'public/template-tags.php' ); 69 | 70 | new \WPTalents\Core\Plugin(); 71 | } 72 | 73 | add_action( 'plugins_loaded', 'wptalents_startup' ); -------------------------------------------------------------------------------- /includes/collectors/Gravatar_Collector.php: -------------------------------------------------------------------------------- 1 | post ); 20 | 21 | if ( 1 >= count( $social_links ) ) { 22 | add_action( 'shutdown', array( $this, '_retrieve_data' ) ); 23 | } 24 | 25 | return $social_links; 26 | } 27 | 28 | /** 29 | * @access protected 30 | * 31 | * @return bool 32 | */ 33 | public function _retrieve_data() { 34 | 35 | $profile = Helper::get_talent_meta( $this->post, 'profile' ); 36 | 37 | $url = str_replace( 'https://secure.gravatar.com/avatar/', 'https://www.gravatar.com/', $profile['avatar'] ); 38 | 39 | $url = remove_query_arg( array( 's', 'd' ), $url ) . '.json'; 40 | 41 | $body = wp_remote_retrieve_body( wp_safe_remote_get( $url ) ); 42 | 43 | if ( '' === $body ) { 44 | return false; 45 | } 46 | 47 | $body = json_decode( $body ); 48 | 49 | if ( null === $body ) { 50 | return false; 51 | } 52 | 53 | if ( ! isset( $body->entry[0] ) ) { 54 | return false; 55 | } 56 | 57 | $social = get_post_meta( $this->post->ID, 'social', true ); 58 | 59 | if ( isset( $social[0] ) && is_array( $social[0] ) ) { 60 | foreach ( $social[0] as $key => $value ) { 61 | $social[ $key ] = $value; 62 | } 63 | 64 | unset( $social[0] ); 65 | } 66 | 67 | if ( isset( $body->entry[0]->accounts ) ) { 68 | foreach ( $body->entry[0]->accounts as $account ) { 69 | switch ( $account->shortname ) { 70 | case 'linkedin': 71 | $social['linkedin'] = $account->url; 72 | break; 73 | case 'twitter'; 74 | case 'facebook'; 75 | $social[ $account->shortname ] = $account->username; 76 | break; 77 | case 'google': 78 | $social['google-plus'] = $account->userid; 79 | break; 80 | case 'wordpress': 81 | $social['url'] = $account->url; 82 | default: 83 | break; 84 | } 85 | } 86 | } 87 | 88 | if ( ! empty( $body->entry[0]->urls ) ) { 89 | $social['url'] = $body->entry[0]->urls[0]->value; 90 | } 91 | 92 | return (bool) update_post_meta( $this->post->ID, 'social', $social ); 93 | } 94 | 95 | } -------------------------------------------------------------------------------- /includes/core/Importer.php: -------------------------------------------------------------------------------- 1 | name = (string) $username; 34 | $this->username = (string) $username; 35 | $this->type = (string) $type; 36 | 37 | if ( ! empty( $name ) ) { 38 | $this->name = $name; 39 | } 40 | } 41 | 42 | /** 43 | * Imports a talent into the site based on their WordPress.org username. 44 | * @return int|WP_Error Post ID on success, WP_Error object otherwise. 45 | */ 46 | public function import() { 47 | if ( ! post_type_exists( $this->type ) ) { 48 | return new WP_Error( 49 | 'invalid_post_type', 50 | sprintf( __( 'Invalid post type "%s"!', 'wptalents' ), $this->type ) 51 | ); 52 | } 53 | 54 | $query = new WP_Query( array( 55 | 'post_type' => $this->type, 56 | 'post_status' => 'any', 57 | 'meta_key' => 'wordpress-username', 58 | 'meta_value' => $this->username, 59 | 'posts_per_page' => 1, 60 | ) ); 61 | 62 | if ( $query->have_posts() ) { 63 | return new WP_Error( 64 | 'already_exists', 65 | sprintf( __( 'Talent already exists! (ID: %d)', 'wptalents' ), $query->posts[0]->ID ) 66 | ); 67 | } 68 | 69 | $post_id = wp_insert_post( array( 70 | 'post_title' => $this->name, 71 | 'post_type' => $this->type, 72 | ) 73 | ); 74 | 75 | if ( 0 === $post_id || is_wp_error( $post_id ) ) { 76 | return new WP_Error( 'insert_failed', sprintf( __( 'Importing %s failed!', 'wptalents' ), $this->name ) ); 77 | } 78 | 79 | update_post_meta( $post_id, 'wordpress-username', $this->username ); 80 | 81 | $collector = new Profile_Collector( get_post( $post_id ) ); 82 | $collector->_retrieve_data(); 83 | 84 | $collector = new Gravatar_Collector( get_post( $post_id ) ); 85 | $collector->_retrieve_data(); 86 | 87 | return $post_id; 88 | } 89 | 90 | } -------------------------------------------------------------------------------- /js/field-gmap.js: -------------------------------------------------------------------------------- 1 | /*jshint devel:true */ 2 | /*global google */ 3 | 4 | (function($) { 5 | 6 | var CMBGmapsInit = function( fieldEl ) { 7 | 8 | var searchInput = $('.map-search', fieldEl ).get(0); 9 | var mapCanvas = $('.map', fieldEl ).get(0); 10 | var latitude = $('.latitude', fieldEl ); 11 | var longitude = $('.longitude', fieldEl ); 12 | var elevation = $('.elevation', fieldEl ); 13 | var elevator = new google.maps.ElevationService(); 14 | 15 | var mapOptions = { 16 | center: new google.maps.LatLng( CMBGmaps.defaults.latitude, CMBGmaps.defaults.longitude ), 17 | zoom: parseInt( CMBGmaps.defaults.zoom ), 18 | mapTypeId: google.maps.MapTypeId.ROADMAP 19 | }; 20 | 21 | var map = new google.maps.Map( mapCanvas, mapOptions ); 22 | 23 | // Marker 24 | var markerOptions = { 25 | map: map, 26 | draggable: true, 27 | title: CMBGmaps.strings.markerTitle 28 | }; 29 | 30 | var marker = new google.maps.Marker( markerOptions ); 31 | marker.setPosition( mapOptions.center ); 32 | 33 | function setPosition( latLng, zoom ) { 34 | 35 | marker.setPosition( latLng ); 36 | map.setCenter( latLng ); 37 | 38 | if ( zoom ) { 39 | map.setZoom( zoom ); 40 | } 41 | 42 | latitude.val( latLng.lat() ); 43 | longitude.val( latLng.lng() ); 44 | 45 | elevator.getElevationForLocations( { locations: [ marker.getPosition() ] }, function (results, status) { 46 | if (status == google.maps.ElevationStatus.OK && results[0] ) { 47 | elevation.val( results[0].elevation ); 48 | } 49 | }); 50 | 51 | } 52 | 53 | // Set stored Coordinates 54 | if ( latitude.val() && longitude.val() ) { 55 | latLng = new google.maps.LatLng( latitude.val(), longitude.val() ); 56 | setPosition( latLng, 17 ) 57 | } 58 | 59 | google.maps.event.addListener( marker, 'dragend', function() { 60 | setPosition( marker.getPosition() ); 61 | }); 62 | 63 | // Search 64 | var autocomplete = new google.maps.places.Autocomplete(searchInput); 65 | autocomplete.bindTo('bounds', map); 66 | 67 | google.maps.event.addListener(autocomplete, 'place_changed', function() { 68 | var place = autocomplete.getPlace(); 69 | if (place.geometry.viewport) { 70 | map.fitBounds(place.geometry.viewport); 71 | } 72 | 73 | setPosition( place.geometry.location, 17 ); 74 | 75 | }); 76 | 77 | $(searchInput).keypress(function(e) { 78 | if (e.keyCode === 13) { 79 | e.preventDefault(); 80 | } 81 | }); 82 | 83 | }; 84 | 85 | CMB.addCallbackForInit( function() { 86 | $('.WPTalentsCMBGmap_Field .field-item').each(function() { 87 | CMBGmapsInit( $(this) ); 88 | }); 89 | } ); 90 | 91 | CMB.addCallbackForClonedField( ['WPTalentsCMBGmap_Field'], CMBGmapsInit ); 92 | 93 | }(jQuery)); -------------------------------------------------------------------------------- /includes/cmb/Gmap_Field.php: -------------------------------------------------------------------------------- 1 | '100%', 32 | 'field_height' => '250px', 33 | 'default_lat' => '47.3686498', 34 | 'default_long' => '8.53918250', 35 | 'default_zoom' => '8', 36 | 'string-marker-title' => __( 'Drag to set the exact location', 'wptalents' ), 37 | ) 38 | ); 39 | } 40 | 41 | public function enqueue_scripts() { 42 | 43 | parent::enqueue_scripts(); 44 | 45 | wp_deregister_script( 'cmb-google-maps-script' ); 46 | wp_enqueue_script( 'cmb-google-maps-script', trailingslashit( WP_TALENTS_URL ) . 'js/field-gmap.js', array( 'jquery', 'cmb-google-maps' ) ); 47 | 48 | wp_localize_script( 'cmb-google-maps-script', 'CMBGmaps', array( 49 | 'defaults' => array( 50 | 'latitude' => $this->args['default_lat'], 51 | 'longitude' => $this->args['default_long'], 52 | 'zoom' => $this->args['default_zoom'], 53 | ), 54 | 'strings' => array( 55 | 'markerTitle' => $this->args['string-marker-title'], 56 | ) 57 | ) ); 58 | 59 | } 60 | 61 | public function html() { 62 | /** 63 | * Ensure all args used are set 64 | */ 65 | 66 | $value = $this->get_value(); 67 | 68 | /** 69 | * Backwards Compatibility with earlier version 70 | * where location was stored as a string 71 | */ 72 | $location = ( is_string( $value ) && ! empty( $value ) ) ? $value : null; 73 | ( is_string( $value ) ) && $value = array(); 74 | 75 | $value = wp_parse_args( 76 | $value, 77 | array( 'lat' => null, 'long' => null, 'elevation' => null, 'name' => $location ) 78 | ); 79 | 80 | $style = array( 81 | sprintf( 'width: %s;', $this->args['field_width'] ), 82 | sprintf( 'height: %s;', $this->args['field_height'] ), 83 | 'border: 1px solid #eee;', 84 | 'margin-top: 8px;', 85 | ); 86 | ?> 87 | 88 | class_attr( 'map-search' ); ?> id_attr(); ?> name_attr( '[name]' ); ?> value="" /> 89 | 90 |
91 | 92 | class_attr( 'latitude' ); ?> name_attr( '[lat]' ); ?> value="" /> 93 | class_attr( 'longitude' ); ?> name_attr( '[long]' ); ?> value="" /> 94 | class_attr( 'elevation' ); ?> name_attr( '[elevation]' ); ?> value="" /> 95 | 96 | expiration = 4 * WEEK_IN_SECONDS; 21 | 22 | parent::__construct( $post ); 23 | } 24 | 25 | /** 26 | * @access public 27 | * @return mixed 28 | */ 29 | public function get_data() { 30 | 31 | return $this->_retrieve_data(); 32 | 33 | } 34 | 35 | /** 36 | * @access protected 37 | * 38 | * @return bool 39 | */ 40 | public function _retrieve_data() { 41 | 42 | global $wp_version; 43 | 44 | $contributions = array(); 45 | 46 | foreach ( range( 3.2, $wp_version, 0.1 ) as $version ) { 47 | $version = number_format( $version, 1 ); 48 | $role = $this->_loop_wp_version( $version, $this->options['username'] ); 49 | 50 | if ( $role ) { 51 | $contributions[ $version ] = $role; 52 | } 53 | } 54 | 55 | return $contributions; 56 | 57 | } 58 | 59 | /** 60 | * @param string $version The WP version to check. 61 | * 62 | * @return bool|string The user's role on success, false otherwise. 63 | */ 64 | protected function _loop_wp_version( $version ) { 65 | 66 | if ( false === ( $credits = get_transient( 'wordpress-credits-' . $version ) ) ) { 67 | $credits = $this->_get_credits( $version ); 68 | } 69 | 70 | if ( $credits ) { 71 | 72 | foreach ( $credits['groups'] as $group_slug => $group_data ) { 73 | if ( 'libraries' == $group_data['type'] ) { 74 | continue; 75 | } 76 | 77 | foreach ( $group_data['data'] as $person_username => $person_data ) { 78 | if ( strtolower( $person_username ) == $this->options['username'] ) { 79 | if ( 'titles' == $group_data['type'] ) { 80 | if ( $person_data[3] ) { 81 | $role = $person_data[3]; 82 | } else if ( $group_data['name'] ) { 83 | $role = $group_data['name']; 84 | } else { 85 | $role = ucfirst( str_replace( '-', ' ', $group_slug ) ); 86 | } 87 | 88 | $role = rtrim( $role, 's' ); 89 | } else { 90 | $role = __( 'Core Contributor', 'wptalents' ); 91 | } 92 | 93 | return $role; 94 | } 95 | } 96 | } 97 | } 98 | 99 | return false; 100 | 101 | } 102 | 103 | /** 104 | * Retrieve the contributor credits. 105 | * 106 | * @param string $wp_version The WordPress version. 107 | * @param string $locale Locale to get translation data for 108 | * 109 | * @return array|bool A list of all of the contributors, or false on error. 110 | */ 111 | protected function _get_credits( $wp_version, $locale = '' ) { 112 | 113 | $response = wp_remote_retrieve_body( wp_safe_remote_get( 114 | 'https://api.wordpress.org/core/credits/1.1/?version=' . $wp_version . '&locale=' . $locale 115 | ) ); 116 | 117 | if ( '' === $response ) { 118 | return false; 119 | } 120 | 121 | $results = json_decode( $response, true ); 122 | 123 | if ( ! is_array( $results ) || $results['data']['version'] != (string) $wp_version ) { 124 | return false; 125 | } 126 | 127 | set_transient( 'wordpress-credits-' . $wp_version, $results, $this->expiration ); 128 | 129 | return $results; 130 | 131 | } 132 | 133 | } -------------------------------------------------------------------------------- /includes/collectors/Forums_Collector.php: -------------------------------------------------------------------------------- 1 | post->ID, '_forums', true ); 21 | 22 | if ( ( ! $data || 23 | ( isset( $data['expiration'] ) && time() >= $data['expiration'] ) ) 24 | && $this->options['may_renew'] 25 | ) { 26 | add_action( 'shutdown', array( $this, '_retrieve_data' ) ); 27 | } 28 | 29 | if ( ! $data ) { 30 | return 0; 31 | } 32 | 33 | return $data['data']; 34 | 35 | } 36 | 37 | /** 38 | * @access protected 39 | * 40 | * @return bool 41 | */ 42 | public function _retrieve_data() { 43 | 44 | $url = 'https://wordpress.org/support/profile/' . $this->options['username']; 45 | 46 | $body = wp_remote_retrieve_body( wp_safe_remote_get( $url ) ); 47 | 48 | if ( '' === $body ) { 49 | return false; 50 | } 51 | 52 | $dom = new DOMDocument(); 53 | 54 | libxml_use_internal_errors( true ); 55 | $dom->loadHTML( $body ); 56 | libxml_clear_errors(); 57 | 58 | $finder = new DOMXPath( $dom ); 59 | 60 | $recent_replies = $finder->query( '//div[@id="user-replies"]/ol/li' ); 61 | $threads_started = $finder->query( '//div[@id="user-threads"]/ol/li' ); 62 | $page_numbers = $finder->query( '//*[contains(@class, "page-numbers")]' ); 63 | 64 | $data = array( 65 | 'replies' => '', 66 | 'threads' => '', 67 | 'total_replies' => '', 68 | ); 69 | 70 | if ( $page_numbers->length ) { 71 | 72 | $total_pages = $page_numbers->item( $page_numbers->length / 2 - 2 )->nodeValue; 73 | 74 | // It's not 100% accurate, as there may be not so many replies on the last page 75 | $data['total_replies'] = $total_pages * $recent_replies->length; 76 | 77 | } else { 78 | $data['total_replies'] = $recent_replies->length; 79 | } 80 | 81 | /** @var $reply \DOMNode */ 82 | foreach ( $recent_replies as $reply ) { 83 | $a_text = $finder->query( 'a', $reply )->item( 0 )->nodeValue; 84 | $a_href = $finder->query( 'a', $reply )->item( 0 )->getAttribute( 'href' ); 85 | 86 | $node_text = $finder->query( 'text()', $reply )->item( 1 )->nodeValue; 87 | preg_match( '/((([^ ]*)[\s.]+){3})$/', $node_text, $matches ); 88 | 89 | $data['replies'][] = array( 90 | 'title' => $a_text, 91 | 'url' => esc_url_raw( $a_href ), 92 | 'date' => str_replace( '.', '', trim( $matches[0] ) ) 93 | ); 94 | } 95 | 96 | foreach ( $threads_started as $thread ) { 97 | $a_text = $finder->query( 'a', $thread )->item( 0 )->nodeValue; 98 | $a_href = $finder->query( 'a', $thread )->item( 0 )->getAttribute( 'href' ); 99 | 100 | $node_text = $finder->query( 'text()', $thread )->item( 1 )->nodeValue; 101 | preg_match( '/((([^ ]*)[\s.]+){3})$/', $node_text, $matches ); 102 | 103 | $data['threads'][] = array( 104 | 'title' => $a_text, 105 | 'url' => esc_url_raw( $a_href ), 106 | 'date' => str_replace( '.', '', trim( $matches[0] ) ) 107 | ); 108 | } 109 | 110 | $data = array( 111 | 'data' => $data, 112 | 'expiration' => time() + $this->expiration, 113 | ); 114 | 115 | update_post_meta( $this->post->ID, '_forums', $data ); 116 | 117 | return $data; 118 | 119 | } 120 | 121 | } -------------------------------------------------------------------------------- /includes/collectors/WordPressTv_Collector.php: -------------------------------------------------------------------------------- 1 | post->ID, '_wordpresstv', true ); 22 | 23 | if ( ( ! $data || 24 | ( isset( $data['expiration'] ) && time() >= $data['expiration'] ) ) 25 | && $this->options['may_renew'] 26 | ) { 27 | add_action( 'shutdown', array( $this, '_retrieve_data' ) ); 28 | } 29 | 30 | if ( ! $data ) { 31 | return 0; 32 | } 33 | 34 | return $data['data']; 35 | 36 | } 37 | 38 | /** 39 | * @access protected 40 | * 41 | * @return bool 42 | */ 43 | public function _retrieve_data() { 44 | 45 | $url = trailingslashit( 'https://wordpress.tv/speakers/' . $this->post->post_name ); 46 | 47 | $data = $this->_retrieve_videos( $url ); 48 | 49 | $data = array( 50 | 'data' => $data, 51 | 'expiration' => time() + $this->expiration, 52 | ); 53 | 54 | update_post_meta( $this->post->ID, '_wordpresstv', $data ); 55 | 56 | return $data; 57 | 58 | } 59 | 60 | /** 61 | * Load the videos from a specified page. Is partly recursive. 62 | * 63 | * @param $url 64 | * 65 | * @return array 66 | */ 67 | public function _retrieve_videos( $url ) { 68 | 69 | $body = wp_remote_retrieve_body( wp_safe_remote_get( $url ) ); 70 | 71 | if ( '' === $body ) { 72 | return false; 73 | } 74 | 75 | $dom = new DOMDocument(); 76 | 77 | libxml_use_internal_errors( true ); 78 | $dom->loadHTML( $body ); 79 | libxml_clear_errors(); 80 | 81 | $finder = new DOMXPath( $dom ); 82 | 83 | $videos = $finder->query( '//*[contains(@class, "video-list")]/li' ); 84 | $older_videos = $finder->query( '//*[contains(@class, "nav-previous")]/a' ); 85 | 86 | $data = array( 87 | 'videos' => '', 88 | 'total_videos' => $videos->length, 89 | ); 90 | 91 | /** @var $reply \DOMNode */ 92 | foreach ( $videos as $video ) { 93 | $img = $finder->query( '*[contains(@class, "video-thumbnail")]/img', $video )->item( 0 )->getAttribute( 'src' ); 94 | $a_text = $finder->query( '*[contains(@class, "video-description")]/h4/a', $video )->item( 0 )->nodeValue; 95 | $a_href = $finder->query( '*[contains(@class, "video-description")]/h4/a', $video )->item( 0 )->getAttribute( 'href' ); 96 | 97 | $event = $finder->query( '*[contains(@class, "video-description")]/*[contains(@class, "video-events")]/a', $video )->item( 0 )->nodeValue; 98 | 99 | $description = $finder->query( '*[contains(@class, "video-description")]/*[contains(@class, "video-excerpt")]/p', $video )->item( 0 )->nodeValue; 100 | preg_match( '/^((?:\S+\s+){2}\S+).*/', $description, $matches ); 101 | 102 | $description = str_replace( '—', '–', $description ); 103 | 104 | $date = new DateTime( $matches[1] ); 105 | 106 | $data['videos'][] = array( 107 | 'title' => $a_text, 108 | 'date' => $date->format( 'Y-m-d' ), 109 | 'url' => $a_href, 110 | 'image' => $img, 111 | 'event' => $event, 112 | 'description' => $description, 113 | ); 114 | } 115 | 116 | if ( $older_videos->length ) { 117 | $more_videos = $this->_retrieve_videos( $older_videos->item( 0 )->getAttribute( 'href' ) ); 118 | $data['videos'] = array_merge( $data['videos'], $more_videos['videos'] ); 119 | $data['total_videos'] += $more_videos['total_videos']; 120 | } 121 | 122 | return $data; 123 | } 124 | 125 | } -------------------------------------------------------------------------------- /includes/core/Router.php: -------------------------------------------------------------------------------- 1 | post_type; 79 | 80 | if ( 'page' === $post->post_type ) { 81 | $query_vars['pagename'] = $query_vars['talent']; 82 | unset( $query_vars['name'] ); 83 | } 84 | } 85 | 86 | // Unset the unused query var 87 | unset( $query_vars['talent'] ); 88 | 89 | return $query_vars; 90 | 91 | } 92 | 93 | public function template_redirect() { 94 | 95 | global $wp_query, $post; 96 | 97 | if ( ! isset( $wp_query->query_vars['embed'] ) || ! in_array( 98 | $wp_query->query_vars['post_type'], 99 | array( 'company', 'person', 'product' ) ) 100 | ) { 101 | return; 102 | } 103 | 104 | do_action( 'wptalents_oembed_output', $post ); 105 | exit; 106 | 107 | } 108 | 109 | /** 110 | * Filter the path of the current template before including it. 111 | * 112 | * @param string $template The path of the template to include. 113 | * 114 | * @return string The template to include. 115 | */ 116 | public function template_include( $template ) { 117 | 118 | $post_types = array_filter( (array) get_query_var( 'post_type' ) ); 119 | 120 | if ( in_array( 'person', $post_types ) && in_array( 'company', $post_types ) ) { 121 | return locate_template( 'archive-talent.php' ); 122 | } 123 | 124 | return $template; 125 | 126 | } 127 | 128 | /** 129 | * @param \WP_Query $query 130 | */ 131 | public function pre_get_posts( $query ) { 132 | 133 | if ( ! $query->is_main_query() || is_admin() ) { 134 | return; 135 | } 136 | 137 | $post_types = apply_filters( 'wptalents_archive_post_types', array() ); 138 | 139 | if ( is_post_type_archive( 'company' ) ) { 140 | $query->set( 'post_type', $post_types ); 141 | $query->set( 'orderby', 'name' ); 142 | $query->set( 'order', 'ASC' ); 143 | } 144 | 145 | } 146 | 147 | } -------------------------------------------------------------------------------- /includes/types/Product.php: -------------------------------------------------------------------------------- 1 | Helper::post_type_labels( 'Product' ), 27 | 'public' => true, 28 | 'show_ui' => true, 29 | 'show_in_menu' => true, 30 | 'query_var' => true, 31 | 'rewrite' => array( 32 | 'slug' => $this->post_type, 33 | ), 34 | 'has_archive' => true, 35 | 'hierarchical' => false, 36 | 'menu_position' => 30, 37 | 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'custom-fields' ), 38 | ); 39 | 40 | register_post_type( $this->post_type, $args ); 41 | 42 | } 43 | 44 | public function register_taxonomy() { 45 | 46 | $args = array( 47 | 'labels' => Helper::post_type_labels( 'Category', 'Categories' ), 48 | 'hierarchical' => true, 49 | 'show_ui' => true, 50 | 'show_admin_column' => true, 51 | 'update_count_callback' => '_update_post_term_count', 52 | 'public' => true, 53 | 'show_tagcloud' => false, 54 | 'rewrite' => false, 55 | ); 56 | 57 | register_taxonomy( 'product-category', $this->post_type, $args ); 58 | 59 | } 60 | 61 | /** 62 | * Add CMB meta boxes. 63 | * 64 | * @param array $meta_boxes 65 | * 66 | * @return array|mixed 67 | */ 68 | public function add_meta_boxes( array $meta_boxes ) { 69 | 70 | $product_details = array( 71 | array( 72 | 'id' => 'byline', 73 | 'name' => __( 'Byline', 'wptalents' ), 74 | 'type' => 'text', 75 | 'cols' => 4, 76 | ), 77 | ); 78 | 79 | $social_profiles = array( 80 | array( 81 | 'id' => 'social', 82 | 'name' => __( 'Social', 'wptalents' ), 83 | 'type' => 'group', 84 | 'fields' => array( 85 | array( 86 | 'id' => 'url', 87 | 'name' => __( 'Website URL', 'wptalents' ), 88 | 'type' => 'text_url', 89 | 'cols' => 4, 90 | ), 91 | array( 92 | 'id' => 'crunchbase', 93 | 'name' => __( 'CrunchBase URL', 'wptalents' ), 94 | 'type' => 'text_url', 95 | 'cols' => 4, 96 | ), 97 | ), 98 | ), 99 | ); 100 | 101 | $meta_boxes[] = array( 102 | 'title' => __( 'Product Details', 'wptalents' ), 103 | 'pages' => $this->post_type, 104 | 'context' => 'advanced', 105 | 'priority' => 'high', 106 | 'fields' => array_merge( $product_details, $social_profiles ), 107 | ); 108 | 109 | return $meta_boxes; 110 | 111 | } 112 | 113 | /** 114 | * Filters the body_class. 115 | * 116 | * @param array $classes 117 | * 118 | * @return array 119 | */ 120 | public function filter_body_class( array $classes ) { 121 | 122 | return $classes; 123 | 124 | } 125 | 126 | /** 127 | * Filters the post_class. 128 | * 129 | * @param array $classes 130 | * 131 | * @return array 132 | */ 133 | public function filter_post_class( array $classes ) { 134 | 135 | /** @var \WP_Post $post */ 136 | global $post; 137 | 138 | if ( $this->post_type !== $post->post_type ) { 139 | return $classes; 140 | } 141 | 142 | // Add default classes 143 | $classes[] = 'talent'; 144 | 145 | if ( $post !== get_queried_object() || wptalents_is_oembed() ) { 146 | $classes[] = 'talent--small'; 147 | } 148 | 149 | return $classes; 150 | 151 | } 152 | 153 | } -------------------------------------------------------------------------------- /includes/cli/Talent_Command.php: -------------------------------------------------------------------------------- 1 | ... 25 | * : One or more WordPress.org usernames to import. 26 | * 27 | * [--name] 28 | * : Overwrite the talent's full name (only works when importing 1 talent). 29 | * 30 | * [--type] 31 | * : The talent type (person or company). 32 | * 33 | * ## EXAMPLES 34 | * 35 | * wp talent add johndoe --name=John Doe --type=person 36 | * wp talent add johndoe janedoe 37 | */ 38 | public function add( $args, $assoc_args ) { 39 | $defaults = array( 40 | 'type' => 'person', 41 | 'name' => '', 42 | ); 43 | 44 | $assoc_args = wp_parse_args( $assoc_args, $defaults ); 45 | 46 | // Only person and company are allowed values 47 | if ( 'person' !== $assoc_args['type'] ) { 48 | $assoc_args['type'] = 'company'; 49 | } 50 | 51 | // Only works if provided a single username 52 | if ( 1 < count( $assoc_args ) ) { 53 | $assoc_args['name'] = ''; 54 | } 55 | 56 | foreach ( $args as $talent ) { 57 | $this->import( $talent, $assoc_args['name'], $assoc_args['type'] ); 58 | } 59 | } 60 | 61 | /** 62 | * @param string $username WordPress.org username. 63 | * @param string $name Talent's full name. 64 | * @param string $type Talent type (person or company). 65 | */ 66 | protected function import( $username, $name, $type ) { 67 | $importer = new Importer( $username, $name, $type ); 68 | WP_CLI::line( 'Importing ' . $username . '...' ); 69 | 70 | $result = $importer->import(); 71 | 72 | if ( is_wp_error( $result ) ) { 73 | /** @var \WP_Error $status */ 74 | WP_CLI::warning( $result->get_error_message() ); 75 | } else { 76 | WP_CLI::success( sprintf( 'Successfully imported %s. Post ID: %s', get_the_title( $result ), $result ) ); 77 | } 78 | } 79 | 80 | /** 81 | * Update the talent's data. 82 | * 83 | * ## OPTIONS 84 | * 85 | * 86 | * : The talent's WordPress.org username 87 | * 88 | * [--force-update] 89 | * : Update even data that hasn't expired yet. 90 | * 91 | * ## EXAMPLES 92 | * 93 | * wp talent update johndoe --force-update 94 | * wp talent update automattic 95 | * 96 | * @synopsis [--force-update] 97 | */ 98 | public function update( $args, $assoc_args ) { 99 | list( $username ) = $args; 100 | 101 | $defaults = array( 102 | 'force-update' => false, 103 | ); 104 | 105 | $assoc_args = wp_parse_args( $assoc_args, $defaults ); 106 | 107 | $query = new \WP_Query( array( 108 | 'post_type' => array( 'person', 'company' ), 109 | 'post_status' => 'any', 110 | 'meta_key' => 'wordpress-username', 111 | 'meta_value' => $username, 112 | 'posts_per_page' => 1, 113 | ) ); 114 | 115 | if ( ! $query->have_posts() ) { 116 | WP_CLI::warning( __( 'Talent does not exist!', 'wptalents' ) ); 117 | 118 | return; 119 | } 120 | 121 | /** @var \WP_Post $post */ 122 | $post = $query->posts[0]; 123 | 124 | WP_CLI::line( sprintf( __( 'Updating %s (ID: %d)...', 'wptalents' ), $post->post_title, $post->ID ) ); 125 | 126 | $collectors = array( 127 | 'Changeset_Collector', 128 | 'Codex_Collector', 129 | 'Contribution_Collector', 130 | 'Forums_Collector', 131 | 'Gravatar_Collector', 132 | 'Plugin_Collector', 133 | 'Profile_Collector', 134 | 'Score_Collector', 135 | 'Theme_Collector', 136 | 'WordPressTv_Collector', 137 | ); 138 | 139 | /** @var \WPTalents\Collector\Collector $collector */ 140 | foreach ( $collectors as $collector ) { 141 | $collector = '\\WPTalents\\Collector\\' . $collector; 142 | $collector = new $collector( $post ); 143 | 144 | if ( true === $assoc_args['force-update'] ) { 145 | $collector->_retrieve_data(); 146 | } 147 | } 148 | 149 | WP_CLI::success( __( 'Talent successfully updated!', 'wptalents' ) ); 150 | } 151 | 152 | } 153 | 154 | WP_CLI::add_command( 'talent', 'WPTalents\CLI\Talent_Command' ); -------------------------------------------------------------------------------- /includes/collectors/Profile_Collector.php: -------------------------------------------------------------------------------- 1 | post->ID, '_profile', true ); 22 | 23 | if ( ( ! $data || 24 | ( isset( $data['expiration'] ) && time() >= $data['expiration'] ) ) 25 | && $this->options['may_renew'] 26 | ) { 27 | add_action( 'shutdown', array( $this, '_retrieve_data' ) ); 28 | } 29 | 30 | if ( ! $data ) { 31 | return 0; 32 | } 33 | 34 | return $data['data']; 35 | } 36 | 37 | /** 38 | * @access protected 39 | * 40 | * @return bool 41 | */ 42 | public function _retrieve_data() { 43 | 44 | $url = 'https://profiles.wordpress.org/' . $this->options['username']; 45 | 46 | $body = wp_remote_retrieve_body( wp_safe_remote_get( $url ) ); 47 | 48 | if ( '' === $body ) { 49 | return false; 50 | } 51 | 52 | $dom = new DOMDocument(); 53 | 54 | libxml_use_internal_errors( true ); 55 | $dom->loadHTML( $body ); 56 | libxml_clear_errors(); 57 | 58 | $finder = new DOMXPath( $dom ); 59 | 60 | $name = $finder->query( '//h2[@class="fn"]' ); 61 | $avatar = $finder->query( '//div[@id="meta-status-badge-container"]/a/img' ); 62 | $description = $finder->query( '//div[@class="item-meta-about"]' ); 63 | $location = $finder->query( '//li[@id="user-location"]' ); 64 | $member_since = $finder->query( '//li[@id="user-member-since"]' ); 65 | $website = $finder->query( '//li[@id="user-website"]/a' ); 66 | $company = $finder->query( '//li[@id="user-company"]' ); 67 | $badges = $finder->query( '//ul[@id="user-badges"]/li/div' ); 68 | 69 | $data = array( 70 | 'name' => trim( $name->item( 0 )->nodeValue ), 71 | 'avatar' => strtok( $avatar->item( 0 )->getAttribute( 'src' ), '?' ), 72 | 'location' => '', 73 | 'company' => '', 74 | 'member_since' => '', 75 | 'website' => '', 76 | 'badges' => array(), 77 | ); 78 | 79 | preg_match( '/((([^ ]*)[\s.]+){3})$/', $member_since->item( 0 )->nodeValue, $matches ); 80 | 81 | $date = new DateTime( $matches[0] ); 82 | $data['member_since'] = $date->format( 'Y-m-d' ); 83 | 84 | if ( $description->length ) { 85 | $description = trim( $description->item( 0 )->nodeValue ); 86 | } else { 87 | $description = ''; 88 | } 89 | 90 | if ( $location->length ) { 91 | $data['location'] = trim( $location->item( 0 )->nodeValue ); 92 | } 93 | 94 | if ( $company->length ) { 95 | $data['company'] = trim( preg_replace( '/\t+/', '', $company->item( 0 )->nodeValue ) ); 96 | } 97 | 98 | if ( $website->length ) { 99 | $data['website'] = trim( $website->item( 0 )->getAttribute( 'href' ) ); 100 | } 101 | 102 | foreach ( $badges as $badge ) { 103 | $data['badges'][] = $badge->getAttribute( 'title' ); 104 | } 105 | 106 | $location = get_post_meta( $this->post->ID, 'location' ); 107 | 108 | if ( empty( $location ) ) { 109 | update_post_meta( $this->post->ID, 'location', $data['location'] ); 110 | } 111 | 112 | $social = (array) get_post_meta( $this->post->ID, 'social' ); 113 | 114 | if ( ! isset( $social['url'] ) && isset( $data['website'] ) ) { 115 | $social['url'] = $data['website']; 116 | update_post_meta( $this->post->ID, 'social', $social ); 117 | } 118 | 119 | if ( $this->post->post_title === $this->options['username'] && ! empty( $data['name'] ) ) { 120 | $this->post->post_title = (string) $data['name']; 121 | 122 | if ( empty( $this->post->post_name ) ) { 123 | $this->post->post_name = sanitize_title( $this->post->post_title ); 124 | } 125 | } 126 | 127 | if ( '' === $this->post->post_content ) { 128 | $this->post->post_content = $description; 129 | } 130 | 131 | wp_update_post( $this->post ); 132 | 133 | if ( ! empty( $data['company'] ) && 'person' === $this->post->post_type ) { 134 | if ( '' === get_post_meta( $this->post->ID, 'job', true ) ) { 135 | update_post_meta( $this->post->ID, 'job', $data['company'] ); 136 | } 137 | } 138 | 139 | $data = array( 140 | 'data' => $data, 141 | 'expiration' => time() + $this->expiration, 142 | ); 143 | 144 | update_post_meta( $this->post->ID, '_profile', $data ); 145 | 146 | return $data; 147 | 148 | } 149 | 150 | } -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "313d4daee2d974eb60d1be2c2cf676a5", 8 | "packages": [ 9 | { 10 | "name": "composer/installers", 11 | "version": "v1.0.18", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/composer/installers.git", 15 | "reference": "74fb0a7a1a23696d9c8cc2fba5903f6711cdd067" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/composer/installers/zipball/74fb0a7a1a23696d9c8cc2fba5903f6711cdd067", 20 | "reference": "74fb0a7a1a23696d9c8cc2fba5903f6711cdd067", 21 | "shasum": "" 22 | }, 23 | "replace": { 24 | "roundcube/plugin-installer": "*", 25 | "shama/baton": "*" 26 | }, 27 | "require-dev": { 28 | "composer/composer": "1.0.*@dev", 29 | "phpunit/phpunit": "4.1.*" 30 | }, 31 | "type": "composer-installer", 32 | "extra": { 33 | "class": "Composer\\Installers\\Installer", 34 | "branch-alias": { 35 | "dev-master": "1.0-dev" 36 | } 37 | }, 38 | "autoload": { 39 | "psr-0": { 40 | "Composer\\Installers\\": "src/" 41 | } 42 | }, 43 | "notification-url": "https://packagist.org/downloads/", 44 | "license": [ 45 | "MIT" 46 | ], 47 | "authors": [ 48 | { 49 | "name": "Kyle Robinson Young", 50 | "email": "kyle@dontkry.com", 51 | "homepage": "https://github.com/shama" 52 | } 53 | ], 54 | "description": "A multi-framework Composer library installer", 55 | "homepage": "http://composer.github.com/installers/", 56 | "keywords": [ 57 | "Craft", 58 | "Dolibarr", 59 | "Hurad", 60 | "MODX Evo", 61 | "OXID", 62 | "WolfCMS", 63 | "agl", 64 | "annotatecms", 65 | "bitrix", 66 | "cakephp", 67 | "chef", 68 | "codeigniter", 69 | "concrete5", 70 | "croogo", 71 | "drupal", 72 | "elgg", 73 | "fuelphp", 74 | "installer", 75 | "joomla", 76 | "kohana", 77 | "laravel", 78 | "lithium", 79 | "magento", 80 | "mako", 81 | "mediawiki", 82 | "modulework", 83 | "moodle", 84 | "phpbb", 85 | "piwik", 86 | "ppi", 87 | "puppet", 88 | "roundcube", 89 | "shopware", 90 | "silverstripe", 91 | "symfony", 92 | "typo3", 93 | "wordpress", 94 | "zend", 95 | "zikula" 96 | ], 97 | "time": "2014-08-18 20:00:12" 98 | }, 99 | { 100 | "name": "humanmade/custom-meta-boxes", 101 | "version": "dev-post-type-check", 102 | "source": { 103 | "type": "git", 104 | "url": "https://github.com/swissspidy/Custom-Meta-Boxes", 105 | "reference": "a46a86df103f2bcdf9b68ba87eb9b0aebcded8b3" 106 | }, 107 | "require": { 108 | "composer/installers": "~1.0" 109 | }, 110 | "type": "library", 111 | "autoload": { 112 | "files": [ 113 | "custom-meta-boxes.php" 114 | ] 115 | }, 116 | "license": [ 117 | "GPL-2.0+" 118 | ], 119 | "authors": [ 120 | { 121 | "name": "Human Made Limited", 122 | "email": "support@humanmade.co.uk", 123 | "homepage": "http://hmn.md/" 124 | } 125 | ], 126 | "description": "Lets you easily create metaboxes with custom fields that will blow your mind.", 127 | "homepage": "https://github.com/humanmade/Custom-Meta-Boxes", 128 | "keywords": [ 129 | "wordpress" 130 | ], 131 | "time": "2014-11-10 08:57:21" 132 | } 133 | ], 134 | "packages-dev": [], 135 | "aliases": [], 136 | "minimum-stability": "stable", 137 | "stability-flags": { 138 | "humanmade/custom-meta-boxes": 20 139 | }, 140 | "prefer-stable": false, 141 | "platform": [], 142 | "platform-dev": [] 143 | } 144 | -------------------------------------------------------------------------------- /includes/api/Oembed_Provider.php: -------------------------------------------------------------------------------- 1 | server = $server; 50 | 51 | add_filter( 'json_endpoints', array( $this, 'register_routes' ) ); 52 | 53 | } 54 | 55 | /** 56 | * Register the routes for the talents 57 | * 58 | * @param array $routes Routes for the post type 59 | * 60 | * @return array Modified routes 61 | */ 62 | public function register_routes( $routes ) { 63 | 64 | $routes[ $this->base ] = array( 65 | array( 66 | array( $this, 'get_oembed_response' ), 67 | WP_JSON_Server::READABLE, 68 | ), 69 | ); 70 | 71 | return $routes; 72 | 73 | } 74 | 75 | /** 76 | * @param string $url 77 | * @param string $format 78 | * @param int $maxwidth 79 | * @param int $maxheight 80 | * @param string $callback 81 | * 82 | * @return array|WP_JSON_Response|WP_Error 83 | */ 84 | public function get_oembed_response( $url, $format = 'json', $maxwidth = 640, $maxheight = 420, $callback = '' ) { 85 | 86 | if ( 'json' !== $format ) { 87 | return new WP_Error( 'json_oembed_invalid_format', __( 'Format not supported.' ), array( 'status' => 501 ) ); 88 | } 89 | 90 | $id = Helper::url_to_postid( $url ); 91 | 92 | if ( 0 === $id || ! in_array( get_post_type( $id ), $this->type ) ) { 93 | return new WP_Error( 'json_oembed_invalid_url', __( 'Invalid URL.' ), array( 'status' => 404 ) ); 94 | } 95 | 96 | if ( 320 > $maxwidth || 180 > $maxheight ) { 97 | return new WP_Error( 'json_oembed_invalid_dimensions', __( 'Not implemented.' ), array( 'status' => 501 ) ); 98 | } 99 | 100 | /** @var array $post */ 101 | $post = get_post( $id, ARRAY_A ); 102 | 103 | // Link headers (see RFC 5988) 104 | 105 | $response = new WP_JSON_Response(); 106 | $response->header( 'Last-Modified', mysql2date( 'D, d M Y H:i:s', $post['post_modified_gmt'] ) . 'GMT' ); 107 | 108 | $post = $this->prepare_response( $post, $maxwidth, $maxheight ); 109 | 110 | if ( is_wp_error( $post ) ) { 111 | return $post; 112 | } 113 | 114 | $response->link_header( 'alternate', get_permalink( $id ), array( 'type' => 'text/html' ) ); 115 | $response->set_data( $post ); 116 | 117 | if ( '' !== $callback ) { 118 | $_GET['_jsonp'] = $callback; 119 | } 120 | 121 | return $response; 122 | 123 | } 124 | 125 | /** 126 | * Prepare oEmbed response. 127 | * 128 | * @param array $post The unprepared post data 129 | * @param int $maxwidth 130 | * @param int $maxheight 131 | * 132 | * @return array The prepared post data 133 | */ 134 | protected function prepare_response( $post, $maxwidth, $maxheight ) { 135 | 136 | $post_obj = get_post( $post['ID'] ); 137 | 138 | $GLOBALS['post'] = $post_obj; 139 | setup_postdata( $post_obj ); 140 | 141 | // Prepare common post fields 142 | $response_fields = array( 143 | 'version' => '1.0', 144 | 'provider_name' => get_bloginfo( 'name' ), 145 | 'provider_url' => get_home_url(), 146 | 'title' => $post_obj->post_title, 147 | 'type' => 'rich', 148 | 'cache_age' => WEEK_IN_SECONDS, 149 | 'html' => $this->get_oembed_html( $post_obj, $maxwidth, $maxheight ), 150 | 'thumbnail_url' => Helper::get_avatar_url( $post_obj, 512 ), 151 | 'thumbnail_width' => 512, 152 | 'thumbnail_height' => 512, 153 | ); 154 | 155 | return apply_filters( 'json_prepare_oembed', $response_fields, $post, $maxwidth, $maxheight ); 156 | } 157 | 158 | /** 159 | * @param WP_Post $post 160 | * @param int $maxwidth 161 | * @param int $maxheight 162 | * 163 | * @return string 164 | */ 165 | protected function get_oembed_html( $post, $maxwidth, $maxheight ) { 166 | 167 | $output = ''; 168 | 169 | // Default dimensions 170 | $width = 640; 171 | $height = 420; 172 | 173 | if ( $maxwidth !== $width ) { 174 | $height = $height / $width * $maxwidth; 175 | $width = $maxwidth; 176 | } else if ( $maxheight !== $height ) { 177 | $width = $width / $height * $maxheight; 178 | $height = $maxheight; 179 | } 180 | 181 | $output = sprintf( 182 | '', 183 | trailingslashit( get_permalink( $post ) ) . user_trailingslashit( 'embed' ), 184 | $width, 185 | $height 186 | ); 187 | 188 | return apply_filters( 'json_oembed_html', $output, $post, $maxwidth, $maxheight ); 189 | 190 | } 191 | 192 | } -------------------------------------------------------------------------------- /includes/api/Jobs.php: -------------------------------------------------------------------------------- 1 | base ] = array( 56 | array( array( $this, 'get_posts' ), WP_JSON_Server::READABLE ), 57 | ); 58 | 59 | $routes[ $this->base . '/(?P\d+)' ] = array( 60 | array( array( $this, 'get_post' ), WP_JSON_Server::READABLE ), 61 | ); 62 | 63 | return $routes; 64 | 65 | } 66 | 67 | /** 68 | * @param array $filter 69 | * @param string $context 70 | * @param null $type 71 | * @param int $page 72 | * 73 | * @return WP_Error|array 74 | */ 75 | public function get_posts( $filter = array(), $context = 'view', $type = null, $page = 1 ) { 76 | if ( ! empty( $type ) && $type !== $this->type ) { 77 | return new WP_Error( 'json_post_invalid_type', __( 'Invalid post type' ), array( 'status' => 400 ) ); 78 | } 79 | 80 | return parent::get_posts( $filter, $context, $this->type, $page ); 81 | } 82 | 83 | /** 84 | * Retrieve a post 85 | * 86 | * @see WP_JSON_Posts::get_post() 87 | * 88 | * @param $id 89 | * @param string $context 90 | * 91 | * @return \WP_JSON_Response 92 | */ 93 | public function get_post( $id, $context = 'view' ) { 94 | $id = (int) $id; 95 | 96 | if ( empty( $id ) ) { 97 | return new WP_Error( 'json_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) ); 98 | } 99 | 100 | /** @var array $post */ 101 | $post = get_post( $id, ARRAY_A ); 102 | 103 | if ( $this->type !== $post['post_type'] ) { 104 | return new WP_Error( 'json_post_invalid_type', __( 'Invalid post type' ), array( 'status' => 400 ) ); 105 | } 106 | 107 | if ( ! $this->check_read_permission( $post ) ) { 108 | return new WP_Error( 'json_user_cannot_read', __( 'Sorry, you cannot read this post.' ), array( 'status' => 401 ) ); 109 | } 110 | 111 | // Link headers (see RFC 5988) 112 | 113 | $response = new \WP_JSON_Response(); 114 | $response->header( 'Last-Modified', mysql2date( 'D, d M Y H:i:s', $post['post_modified_gmt'] ) . 'GMT' ); 115 | 116 | $post = $this->prepare_post( $post, $context ); 117 | 118 | if ( is_wp_error( $post ) ) { 119 | return $post; 120 | } 121 | 122 | foreach ( $post['meta']['links'] as $rel => $url ) { 123 | $response->link_header( $rel, $url ); 124 | } 125 | 126 | $response->link_header( 'alternate', get_permalink( $id ), array( 'type' => 'text/html' ) ); 127 | $response->set_data( $post ); 128 | 129 | return $response; 130 | } 131 | 132 | /** 133 | * Prepare post data 134 | * 135 | * @param array $post The unprepared post data 136 | * @param string $context The context for the prepared post. (view|view-revision|edit|embed|single-parent) 137 | * 138 | * @return array The prepared post data 139 | */ 140 | protected function prepare_post( $post, $context = 'view' ) { 141 | // Holds the data for this post. 142 | $_post = array( 'ID' => absint( $post['ID'] ) ); 143 | 144 | if ( ! $this->check_read_permission( $post ) ) { 145 | return new WP_Error( 'json_user_cannot_read', __( 'Sorry, you cannot read this post.' ), array( 'status' => 401 ) ); 146 | } 147 | 148 | $post_obj = get_post( $post['ID'] ); 149 | 150 | $GLOBALS['post'] = $post_obj; 151 | setup_postdata( $post_obj ); 152 | 153 | // Prepare common post fields 154 | $post_fields = array( 155 | 'title' => get_the_title( $post['ID'] ), // $post['post_title'], 156 | 'type' => $post['post_type'], 157 | 'link' => get_permalink( $post['ID'] ), 158 | ); 159 | 160 | $post_fields_extended = array( 161 | 'slug' => $post['post_name'], 162 | 'avatar' => Helper::get_avatar_url( $post['ID'], 512 ), 163 | 'excerpt' => $this->prepare_excerpt( $post['post_excerpt'] ), 164 | 'content' => apply_filters( 'the_content', $post['post_content'] ), 165 | 'byline' => esc_html( get_post_meta( $post['ID'], 'byline', true ) ), 166 | ); 167 | 168 | // Get connected company 169 | $companies = get_posts( array( 170 | 'connected_type' => 'hiring', 171 | 'connected_items' => $post, 172 | 'posts_per_page' => - 1, 173 | 'suppress_filters' => false, 174 | ) ); 175 | 176 | $post_fields_extended['company'] = array( 177 | 'ID' => absint( $companies[0]->ID ), 178 | 'title' => get_the_title( $companies[0]->ID ), 179 | 'link' => get_permalink( $companies[0]->ID ), 180 | 'slug' => $companies[0]->post_name, 181 | 'excerpt' => $this->prepare_excerpt( $companies[0]->post_excerpt ), 182 | 'meta' => array( 183 | 'self' => json_url( '/talents/' . $companies[0]->ID ), 184 | 'collection' => json_url( '/talents' ), 185 | ), 186 | ); 187 | 188 | // Dates 189 | if ( '0000-00-00 00:00:00' === $post['post_date_gmt'] ) { 190 | $post_fields['date'] = null; 191 | $post_fields_extended['date_gmt'] = null; 192 | } else { 193 | $post_fields['date'] = json_mysql_to_rfc3339( $post['post_date'] ); 194 | $post_fields_extended['date_gmt'] = json_mysql_to_rfc3339( $post['post_date_gmt'] ); 195 | } 196 | 197 | if ( '0000-00-00 00:00:00' === $post['post_modified_gmt'] ) { 198 | $post_fields['modified'] = null; 199 | $post_fields_extended['modified_gmt'] = null; 200 | } else { 201 | $post_fields['modified'] = json_mysql_to_rfc3339( $post['post_modified'] ); 202 | $post_fields_extended['modified_gmt'] = json_mysql_to_rfc3339( $post['post_modified_gmt'] ); 203 | } 204 | 205 | // Merge requested $post_fields fields into $_post 206 | $_post = array_merge( $_post, $post_fields ); 207 | 208 | // Include extended fields. We might come back to this. 209 | $_post = array_merge( $_post, $post_fields_extended ); 210 | 211 | // Entity meta 212 | $links = array( 213 | 'self' => json_url( '/jobs/' . $post['ID'] ), 214 | 'collection' => json_url( '/jobs' ), 215 | ); 216 | 217 | $_post['meta'] = array( 'links' => $links ); 218 | 219 | return apply_filters( 'json_prepare_talent', $_post, $post, $context ); 220 | } 221 | 222 | } -------------------------------------------------------------------------------- /includes/api/Products.php: -------------------------------------------------------------------------------- 1 | base ] = array( 54 | array( array( $this, 'get_posts' ), WP_JSON_Server::READABLE ), 55 | ); 56 | 57 | $routes[ $this->base . '/(?P\d+)' ] = array( 58 | array( array( $this, 'get_post' ), WP_JSON_Server::READABLE ), 59 | ); 60 | 61 | return $routes; 62 | 63 | } 64 | 65 | /** 66 | * @param array $filter 67 | * @param string $context 68 | * @param null $type 69 | * @param int $page 70 | * 71 | * @return WP_Error|array 72 | */ 73 | public function get_posts( $filter = array(), $context = 'view', $type = null, $page = 1 ) { 74 | if ( ! empty( $type ) && $type !== $this->type ) { 75 | return new WP_Error( 'json_post_invalid_type', __( 'Invalid post type' ), array( 'status' => 400 ) ); 76 | } 77 | 78 | return parent::get_posts( $filter, $context, $this->type, $page ); 79 | } 80 | 81 | /** 82 | * Retrieve a post 83 | * 84 | * @see WP_JSON_Posts::get_post() 85 | * 86 | * @param $id 87 | * @param string $context 88 | * 89 | * @return \WP_JSON_Response 90 | */ 91 | public function get_post( $id, $context = 'view' ) { 92 | $id = (int) $id; 93 | 94 | if ( empty( $id ) ) { 95 | return new WP_Error( 'json_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) ); 96 | } 97 | 98 | /** @var array $post */ 99 | $post = get_post( $id, ARRAY_A ); 100 | 101 | if ( $this->type !== $post['post_type'] ) { 102 | return new WP_Error( 'json_post_invalid_type', __( 'Invalid post type' ), array( 'status' => 400 ) ); 103 | } 104 | 105 | if ( ! $this->check_read_permission( $post ) ) { 106 | return new WP_Error( 'json_user_cannot_read', __( 'Sorry, you cannot read this post.' ), array( 'status' => 401 ) ); 107 | } 108 | 109 | // Link headers (see RFC 5988) 110 | 111 | $response = new \WP_JSON_Response(); 112 | $response->header( 'Last-Modified', mysql2date( 'D, d M Y H:i:s', $post['post_modified_gmt'] ) . 'GMT' ); 113 | 114 | $post = $this->prepare_post( $post, $context ); 115 | 116 | if ( is_wp_error( $post ) ) { 117 | return $post; 118 | } 119 | 120 | foreach ( $post['meta']['links'] as $rel => $url ) { 121 | $response->link_header( $rel, $url ); 122 | } 123 | 124 | $response->link_header( 'alternate', get_permalink( $id ), array( 'type' => 'text/html' ) ); 125 | $response->set_data( $post ); 126 | 127 | return $response; 128 | } 129 | 130 | /** 131 | * Prepare post data 132 | * 133 | * @param array $post The unprepared post data 134 | * @param string $context The context for the prepared post. (view|view-revision|edit|embed|single-parent) 135 | * 136 | * @return array The prepared post data 137 | */ 138 | protected function prepare_post( $post, $context = 'view' ) { 139 | // Holds the data for this post. 140 | $_post = array( 'ID' => absint( $post['ID'] ) ); 141 | 142 | if ( ! $this->check_read_permission( $post ) ) { 143 | return new WP_Error( 'json_user_cannot_read', __( 'Sorry, you cannot read this post.' ), array( 'status' => 401 ) ); 144 | } 145 | 146 | $post_obj = get_post( $post['ID'] ); 147 | 148 | $GLOBALS['post'] = $post_obj; 149 | setup_postdata( $post_obj ); 150 | 151 | // Prepare common post fields 152 | $post_fields = array( 153 | 'title' => get_the_title( $post['ID'] ), // $post['post_title'], 154 | 'type' => $post['post_type'], 155 | 'link' => get_permalink( $post['ID'] ), 156 | ); 157 | 158 | $thumbnail = ''; 159 | if ( has_post_thumbnail( $post['ID'] ) ) { 160 | $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post['ID'] ), 'full' ); 161 | if ( $image ) { 162 | $thumbnail = $image[0]; 163 | } 164 | } 165 | 166 | $post_fields_extended = array( 167 | 'slug' => $post['post_name'], 168 | 'image' => $thumbnail, 169 | 'excerpt' => $this->prepare_excerpt( $post['post_excerpt'] ), 170 | 'content' => apply_filters( 'the_content', $post['post_content'] ), 171 | 'byline' => esc_html( get_post_meta( $post['ID'], 'byline', true ) ), 172 | ); 173 | 174 | // Get connected company 175 | $companies = get_posts( array( 176 | 'connected_type' => 'product_owner', 177 | 'connected_items' => $post, 178 | 'posts_per_page' => - 1, 179 | 'suppress_filters' => false, 180 | ) ); 181 | 182 | $post_fields_extended[ $companies[0]->post_type ] = array( 183 | 'ID' => absint( $companies[0]->ID ), 184 | 'title' => get_the_title( $companies[0]->ID ), 185 | 'link' => get_permalink( $companies[0]->ID ), 186 | 'slug' => $companies[0]->post_name, 187 | 'excerpt' => $this->prepare_excerpt( $companies[0]->post_excerpt ), 188 | 'meta' => array( 189 | 'self' => json_url( '/talents/' . $companies[0]->ID ), 190 | 'collection' => json_url( '/talents' ), 191 | ), 192 | ); 193 | 194 | // Dates 195 | if ( '0000-00-00 00:00:00' === $post['post_date_gmt'] ) { 196 | $post_fields['date'] = null; 197 | $post_fields_extended['date_gmt'] = null; 198 | } else { 199 | $post_fields['date'] = json_mysql_to_rfc3339( $post['post_date'] ); 200 | $post_fields_extended['date_gmt'] = json_mysql_to_rfc3339( $post['post_date_gmt'] ); 201 | } 202 | 203 | if ( '0000-00-00 00:00:00' === $post['post_modified_gmt'] ) { 204 | $post_fields['modified'] = null; 205 | $post_fields_extended['modified_gmt'] = null; 206 | } else { 207 | $post_fields['modified'] = json_mysql_to_rfc3339( $post['post_modified'] ); 208 | $post_fields_extended['modified_gmt'] = json_mysql_to_rfc3339( $post['post_modified_gmt'] ); 209 | } 210 | 211 | // Merge requested $post_fields fields into $_post 212 | $_post = array_merge( $_post, $post_fields ); 213 | 214 | // Include extended fields. We might come back to this. 215 | $_post = array_merge( $_post, $post_fields_extended ); 216 | 217 | // Entity meta 218 | $links = array( 219 | 'self' => json_url( '/jobs/' . $post['ID'] ), 220 | 'collection' => json_url( '/jobs' ), 221 | ); 222 | 223 | $_post['meta'] = array( 'links' => $links ); 224 | 225 | return apply_filters( 'json_prepare_talent', $_post, $post, $context ); 226 | } 227 | 228 | } -------------------------------------------------------------------------------- /includes/types/Company.php: -------------------------------------------------------------------------------- 1 | post_type; 39 | 40 | return $post_types; 41 | 42 | } 43 | 44 | /** 45 | * Filters the permalinks for companies and people. 46 | * 47 | * Removes the rewrite slug from the permalink 48 | * so the permalinks are on the top-level. 49 | * 50 | * Example: example.com/company/xy/ becomes example.com/xy/ 51 | * 52 | * @param string $permalink The current permalink of the post. 53 | * @param WP_Post $post The current post object 54 | * @param bool $leavename Whether to keep the post name. 55 | * 56 | * @return string The modified permalink. 57 | */ 58 | public function filter_post_type_link( $permalink, $post, $leavename ) { 59 | 60 | if ( $this->post_type === $post->post_type ) { 61 | $permalink = esc_url( home_url( user_trailingslashit( "%$post->post_type%" ) ) ); 62 | } 63 | 64 | if ( ! $leavename ) { 65 | $permalink = str_replace( "%$post->post_type%", $post->post_name, $permalink ); 66 | } 67 | 68 | return $permalink; 69 | 70 | } 71 | 72 | public function register_post_type() { 73 | 74 | $args = array( 75 | 'labels' => Helper::post_type_labels( 'Company', 'Companies' ), 76 | 'public' => true, 77 | 'show_ui' => true, 78 | 'show_in_menu' => true, 79 | 'query_var' => true, 80 | 'rewrite' => false, 81 | 'has_archive' => true, 82 | 'hierarchical' => false, 83 | 'menu_position' => 30, 84 | 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'custom-fields' ), 85 | ); 86 | 87 | register_post_type( $this->post_type, $args ); 88 | 89 | } 90 | 91 | public function register_taxonomy() { 92 | 93 | if ( taxonomy_exists( 'region' ) ) { 94 | 95 | register_taxonomy_for_object_type( 'region', $this->post_type ); 96 | 97 | } else { 98 | 99 | $region_args = array( 100 | 'labels' => Helper::post_type_labels( 'Region', 'Regions' ), 101 | 'hierarchical' => true, 102 | 'show_ui' => true, 103 | 'show_admin_column' => true, 104 | 'update_count_callback' => '_update_post_term_count', 105 | 'public' => true, 106 | 'show_tagcloud' => false, 107 | 'rewrite' => false, 108 | ); 109 | 110 | register_taxonomy( 'region', $this->post_type, $region_args ); 111 | 112 | } 113 | 114 | if ( taxonomy_exists( 'service' ) ) { 115 | 116 | register_taxonomy_for_object_type( 'service', $this->post_type ); 117 | 118 | } else { 119 | 120 | $region_args = array( 121 | 'labels' => Helper::post_type_labels( 'Service' ), 122 | 'hierarchical' => true, 123 | 'show_ui' => true, 124 | 'show_admin_column' => true, 125 | 'update_count_callback' => '_update_post_term_count', 126 | 'public' => true, 127 | 'show_tagcloud' => false, 128 | 'rewrite' => false, 129 | ); 130 | 131 | register_taxonomy( 'service', $this->post_type, $region_args ); 132 | 133 | } 134 | 135 | } 136 | 137 | /** 138 | * @param array $meta_boxes 139 | * 140 | * @return array 141 | */ 142 | public function add_meta_boxes( array $meta_boxes ) { 143 | 144 | $talent_details = array( 145 | array( 146 | 'id' => 'wordpress-username', 147 | 'name' => __( 'WordPress.org username', 'wptalents' ), 148 | 'type' => 'text', 149 | 'cols' => 4, 150 | ), 151 | array( 152 | 'id' => 'byline', 153 | 'name' => __( 'Byline', 'wptalents' ), 154 | 'type' => 'text', 155 | 'cols' => 4, 156 | ), 157 | array( 158 | 'id' => 'wordpress-com-vip', 159 | 'name' => __( 'WordPress.com VIP partner', 'wptalents' ), 160 | 'type' => 'checkbox', 161 | 'cols' => 4, 162 | ), 163 | ); 164 | 165 | $social_profiles = array( 166 | array( 167 | 'id' => 'social', 168 | 'name' => __( 'Social', 'wptalents' ), 169 | 'type' => 'group', 170 | 'fields' => array( 171 | array( 172 | 'id' => 'url', 173 | 'name' => __( 'Website URL', 'wptalents' ), 174 | 'type' => 'text_url', 175 | 'cols' => 4, 176 | ), 177 | array( 178 | 'id' => 'github', 179 | 'name' => __( 'Github Username', 'wptalents' ), 180 | 'type' => 'text', 181 | 'cols' => 4, 182 | ), 183 | array( 184 | 'id' => 'twitter', 185 | 'name' => __( 'Twitter Username', 'wptalents' ), 186 | 'type' => 'text', 187 | 'cols' => 4, 188 | ), 189 | array( 190 | 'id' => 'facebook', 191 | 'name' => __( 'Facebook (Vanity URL)', 'wptalents' ), 192 | 'type' => 'text', 193 | 'cols' => 4, 194 | ), 195 | array( 196 | 'id' => 'google-plus', 197 | 'name' => __( 'Google+ (ID)', 'wptalents' ), 198 | 'type' => 'text', 199 | 'cols' => 4, 200 | ), 201 | array( 202 | 'id' => 'linkedin', 203 | 'name' => __( 'LinkedIn URL', 'wptalents' ), 204 | 'type' => 'text_url', 205 | 'cols' => 4, 206 | ), 207 | array( 208 | 'id' => 'crunchbase', 209 | 'name' => __( 'CrunchBase URL', 'wptalents' ), 210 | 'type' => 'text_url', 211 | 'cols' => 4, 212 | ), 213 | ), 214 | ), 215 | ); 216 | 217 | $location = array( 218 | array( 219 | 'id' => 'location', 220 | 'name' => __( 'Location', 'wptalents' ), 221 | 'desc' => __( 'Stores name, coordinates and elevation.', 'wptalents' ), 222 | 'type' => 'gmap', 223 | ), 224 | ); 225 | 226 | $meta_boxes[] = array( 227 | 'title' => __( 'Location', 'wptalents' ), 228 | 'pages' => $this->post_type, 229 | 'context' => 'advanced', 230 | 'priority' => 'high', 231 | 'fields' => $location, 232 | ); 233 | 234 | $meta_boxes[] = array( 235 | 'title' => __( 'Talent Details', 'wptalents' ), 236 | 'pages' => $this->post_type, 237 | 'context' => 'advanced', 238 | 'priority' => 'high', 239 | 'fields' => array_merge( $talent_details, $social_profiles ), 240 | ); 241 | 242 | return $meta_boxes; 243 | 244 | } 245 | 246 | /** 247 | * @param array $classes 248 | * 249 | * @return array 250 | */ 251 | public function filter_body_class( array $classes ) { 252 | 253 | /** @var WP_Post $post */ 254 | global $post; 255 | 256 | if ( ! is_a( $post, 'WP_Post' ) ) { 257 | return $classes; 258 | } 259 | 260 | if ( $this->post_type === $post->post_type ) { 261 | // Add default classes 262 | $classes[] = 'talent'; 263 | 264 | if ( has_post_thumbnail( $post->ID ) ) { 265 | 266 | $thumbnail = get_attached_file( get_post_thumbnail_id( $post->ID ) ); 267 | 268 | // Add map thumbnail class 269 | if ( $thumbnail && 0 === strpos( basename( $thumbnail ), $post->post_name . '-map' ) ) { 270 | $classes[] = 'has-post-thumbnail-map'; 271 | } 272 | } 273 | } 274 | 275 | return $classes; 276 | 277 | } 278 | 279 | /** 280 | * @param array $classes 281 | * 282 | * @return array 283 | */ 284 | public function filter_post_class( array $classes ) { 285 | 286 | /** @var WP_Post $post */ 287 | global $post; 288 | 289 | if ( $this->post_type !== $post->post_type ) { 290 | return $classes; 291 | } 292 | 293 | // Add default classes 294 | $classes[] = 'talent'; 295 | 296 | if ( $post !== get_queried_object() || wptalents_is_oembed() ) { 297 | $classes[] = 'talent--small'; 298 | } 299 | 300 | if ( has_post_thumbnail( $post->ID ) ) { 301 | 302 | $thumbnail = get_attached_file( get_post_thumbnail_id( $post->ID ) ); 303 | 304 | // Add map thumbnail class 305 | if ( $thumbnail && 0 === strpos( basename( $thumbnail ), $post->post_name . '-map' ) ) { 306 | $classes[] = 'has-post-thumbnail-map'; 307 | } 308 | } 309 | 310 | return $classes; 311 | 312 | } 313 | 314 | /** 315 | * Filter the post type archive permalink. 316 | * 317 | * @since 3.1.0 318 | * 319 | * @param string $link The post type archive permalink. 320 | * @param string $post_type Post type name. 321 | * 322 | * @return string 323 | */ 324 | public function filter_post_type_archive_link( $link, $post_type ) { 325 | 326 | if ( $this->post_type === $post_type ) { 327 | return home_url( user_trailingslashit( 'talents', 'post_type_archive' ) ); 328 | } 329 | 330 | return $link; 331 | 332 | } 333 | 334 | } -------------------------------------------------------------------------------- /includes/types/Person.php: -------------------------------------------------------------------------------- 1 | post_type; 40 | 41 | return $post_types; 42 | 43 | } 44 | 45 | /** 46 | * Filters the permalinks for companies and people. 47 | * 48 | * Removes the rewrite slug from the permalink 49 | * so the permalinks are on the top-level. 50 | * 51 | * Example: example.com/company/xy/ becomes example.com/xy/ 52 | * 53 | * @param string $permalink The current permalink of the post. 54 | * @param WP_Post $post The current post object 55 | * @param bool $leavename Whether to keep the post name. 56 | * 57 | * @return string The modified permalink. 58 | */ 59 | public function filter_post_type_link( $permalink, $post, $leavename ) { 60 | 61 | if ( $this->post_type === $post->post_type ) { 62 | $permalink = esc_url( home_url( user_trailingslashit( "%$post->post_type%" ) ) ); 63 | } 64 | 65 | if ( ! $leavename ) { 66 | $permalink = str_replace( "%$post->post_type%", $post->post_name, $permalink ); 67 | } 68 | 69 | return $permalink; 70 | 71 | } 72 | 73 | public function register_post_type() { 74 | 75 | $args = array( 76 | 'labels' => Helper::post_type_labels( 'Person', 'People' ), 77 | 'public' => true, 78 | 'show_ui' => true, 79 | 'show_in_menu' => true, 80 | 'query_var' => true, 81 | 'rewrite' => false, 82 | 'has_archive' => true, 83 | 'hierarchical' => false, 84 | 'menu_position' => 30, 85 | 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'revisions', 'custom-fields' ), 86 | ); 87 | 88 | register_post_type( $this->post_type, $args ); 89 | 90 | } 91 | 92 | public function register_taxonomy() { 93 | 94 | if ( taxonomy_exists( 'region' ) ) { 95 | 96 | register_taxonomy_for_object_type( 'region', $this->post_type ); 97 | 98 | } else { 99 | 100 | $region_args = array( 101 | 'labels' => Helper::post_type_labels( 'Region', 'Regions' ), 102 | 'hierarchical' => true, 103 | 'show_ui' => true, 104 | 'show_admin_column' => true, 105 | 'update_count_callback' => '_update_post_term_count', 106 | 'public' => true, 107 | 'show_tagcloud' => false, 108 | 'rewrite' => false, 109 | ); 110 | 111 | register_taxonomy( 'region', $this->post_type, $region_args ); 112 | 113 | } 114 | 115 | if ( taxonomy_exists( 'service' ) ) { 116 | 117 | register_taxonomy_for_object_type( 'service', $this->post_type ); 118 | 119 | } else { 120 | 121 | $region_args = array( 122 | 'labels' => Helper::post_type_labels( 'Service' ), 123 | 'hierarchical' => true, 124 | 'show_ui' => true, 125 | 'show_admin_column' => true, 126 | 'update_count_callback' => '_update_post_term_count', 127 | 'public' => true, 128 | 'show_tagcloud' => false, 129 | 'rewrite' => false, 130 | ); 131 | 132 | register_taxonomy( 'service', $this->post_type, $region_args ); 133 | 134 | } 135 | 136 | } 137 | 138 | /** 139 | * Add CMB meta boxes. 140 | * 141 | * @param array $meta_boxes 142 | * 143 | * @return array|mixed 144 | */ 145 | public function add_meta_boxes( array $meta_boxes ) { 146 | 147 | $talent_details = array( 148 | array( 149 | 'id' => 'wordpress-username', 150 | 'name' => __( 'WordPress.org username', 'wptalents' ), 151 | 'type' => 'text', 152 | 'cols' => 4, 153 | ), 154 | array( 155 | 'id' => 'byline', 156 | 'name' => __( 'Byline', 'wptalents' ), 157 | 'type' => 'text', 158 | 'cols' => 4, 159 | ), 160 | array( 161 | 'id' => 'job', 162 | 'name' => __( 'Job Title', 'wptalents' ), 163 | 'type' => 'text', 164 | 'cols' => 4, 165 | ), 166 | ); 167 | 168 | $social_profiles = array( 169 | array( 170 | 'id' => 'social', 171 | 'name' => __( 'Social', 'wptalents' ), 172 | 'type' => 'group', 173 | 'fields' => array( 174 | array( 175 | 'id' => 'url', 176 | 'name' => __( 'Website URL', 'wptalents' ), 177 | 'type' => 'text_url', 178 | 'cols' => 4, 179 | ), 180 | array( 181 | 'id' => 'github', 182 | 'name' => __( 'Github Username', 'wptalents' ), 183 | 'type' => 'text', 184 | 'cols' => 4, 185 | ), 186 | array( 187 | 'id' => 'twitter', 188 | 'name' => __( 'Twitter Username', 'wptalents' ), 189 | 'type' => 'text', 190 | 'cols' => 4, 191 | ), 192 | array( 193 | 'id' => 'facebook', 194 | 'name' => __( 'Facebook (Vanity URL)', 'wptalents' ), 195 | 'type' => 'text', 196 | 'cols' => 4, 197 | ), 198 | array( 199 | 'id' => 'google-plus', 200 | 'name' => __( 'Google+ (ID)', 'wptalents' ), 201 | 'type' => 'text', 202 | 'cols' => 4, 203 | ), 204 | array( 205 | 'id' => 'linkedin', 206 | 'name' => __( 'LinkedIn URL', 'wptalents' ), 207 | 'type' => 'text_url', 208 | 'cols' => 4, 209 | ), 210 | array( 211 | 'id' => 'crunchbase', 212 | 'name' => __( 'CrunchBase URL', 'wptalents' ), 213 | 'type' => 'text_url', 214 | 'cols' => 4, 215 | ), 216 | ), 217 | ), 218 | ); 219 | 220 | $dawn_patrol = array( 221 | array( 222 | 'id' => 'dawnpatrol', 223 | 'name' => __( 'Dawn Patrol URL', 'wptalents' ), 224 | 'type' => 'url', 225 | 'cols' => 6, 226 | ), 227 | array( 228 | 'id' => 'dawnpatrol-video', 229 | 'name' => __( 'Dawn Patrol Video URL', 'wptalents' ), 230 | 'type' => 'url', 231 | 'cols' => 6, 232 | ), 233 | ); 234 | 235 | $location = array( 236 | array( 237 | 'id' => 'location', 238 | 'name' => __( 'Location', 'wptalents' ), 239 | 'desc' => __( 'Stores name, coordinates and elevation.', 'wptalents' ), 240 | 'type' => 'gmap', 241 | ), 242 | ); 243 | 244 | $meta_boxes[] = array( 245 | 'id' => 'location', 246 | 'title' => __( 'Location', 'wptalents' ), 247 | 'pages' => $this->post_type, 248 | 'context' => 'advanced', 249 | 'priority' => 'high', 250 | 'fields' => $location, 251 | ); 252 | 253 | $meta_boxes[] = array( 254 | 'id' => 'talent-details', 255 | 'title' => __( 'Talent Details', 'wptalents' ), 256 | 'pages' => $this->post_type, 257 | 'context' => 'advanced', 258 | 'priority' => 'high', 259 | 'fields' => array_merge( $talent_details, $social_profiles ), 260 | ); 261 | 262 | $meta_boxes[] = array( 263 | 'id' => 'dawnpatrol', 264 | 'title' => __( 'Dawn Patrol', 'wptalents' ), 265 | 'pages' => $this->post_type, 266 | 'context' => 'advanced', 267 | 'priority' => 'high', 268 | 'fields' => $dawn_patrol, 269 | ); 270 | 271 | return $meta_boxes; 272 | 273 | } 274 | 275 | /** 276 | * Filters the body_class. 277 | * 278 | * @param array $classes 279 | * 280 | * @return array 281 | */ 282 | public function filter_body_class( array $classes ) { 283 | 284 | /** @var WP_Post $post */ 285 | global $post; 286 | 287 | if ( ! is_a( $post, 'WP_Post' ) ) { 288 | return $classes; 289 | } 290 | 291 | if ( $this->post_type === $post->post_type ) { 292 | // Add default classes 293 | $classes[] = 'talent'; 294 | 295 | if ( has_post_thumbnail( $post->ID ) ) { 296 | 297 | $thumbnail = get_attached_file( get_post_thumbnail_id( $post->ID ) ); 298 | 299 | // Add map thumbnail class 300 | if ( $thumbnail && 0 === strpos( basename( $thumbnail ), $post->post_name . '-map' ) ) { 301 | $classes[] = 'has-post-thumbnail-map'; 302 | } 303 | } 304 | } 305 | 306 | if ( is_post_type_archive( $this->post_type ) ) { 307 | $classes[] = 'archive-talents'; 308 | } 309 | 310 | return $classes; 311 | 312 | } 313 | 314 | /** 315 | * Filters the post_class. 316 | * 317 | * @param array $classes 318 | * 319 | * @return array 320 | */ 321 | public function filter_post_class( array $classes ) { 322 | 323 | /** @var WP_Post $post */ 324 | global $post; 325 | 326 | if ( $this->post_type !== $post->post_type ) { 327 | return $classes; 328 | } 329 | 330 | // Add default classes 331 | $classes[] = 'talent'; 332 | 333 | if ( $post !== get_queried_object() || wptalents_is_oembed() ) { 334 | $classes[] = 'talent--small'; 335 | } 336 | 337 | if ( has_post_thumbnail( $post->ID ) ) { 338 | 339 | $thumbnail = get_attached_file( get_post_thumbnail_id( $post->ID ) ); 340 | 341 | // Add map thumbnail class 342 | if ( $thumbnail && 0 === strpos( basename( $thumbnail ), $post->post_name . '-map' ) ) { 343 | $classes[] = 'has-post-thumbnail-map'; 344 | } 345 | } 346 | 347 | return $classes; 348 | 349 | } 350 | 351 | /** 352 | * Filter the post type archive title. 353 | * 354 | * @param string $name The post type archive title. 355 | * @param string $post_type Post type name. 356 | * 357 | * @return string 358 | */ 359 | public static function filter_post_type_archive_title( $name, $post_type ) { 360 | 361 | if ( 'person' === $post_type ) { 362 | return __( 'Talents', 'wptalents' ); 363 | } 364 | 365 | return $name; 366 | 367 | } 368 | 369 | /** 370 | * Filter the post type archive permalink. 371 | * 372 | * @since 3.1.0 373 | * 374 | * @param string $link The post type archive permalink. 375 | * @param string $post_type Post type name. 376 | * 377 | * @return string 378 | */ 379 | public function filter_post_type_archive_link( $link, $post_type ) { 380 | 381 | if ( $this->post_type === $post_type ) { 382 | return home_url( user_trailingslashit( 'talents', 'post_type_archive' ) ); 383 | } 384 | 385 | return $link; 386 | 387 | } 388 | 389 | } -------------------------------------------------------------------------------- /includes/collectors/Score_Collector.php: -------------------------------------------------------------------------------- 1 | post->ID, '_score', true ); 21 | $score_exp = get_post_meta( $this->post->ID, '_score_expiration', true ); 22 | 23 | if ( ( ! ( $score || $score_exp ) || 24 | ( isset( $score_exp ) && time() >= $score_exp ) ) 25 | && $this->options['may_renew'] 26 | ) { 27 | add_action( 'shutdown', array( $this, '_retrieve_data' ) ); 28 | } 29 | 30 | $score = apply_filters( 'wptalents_score', $score ); 31 | 32 | if ( ! $score ) { 33 | return 1; 34 | } 35 | 36 | return absint( $score ); 37 | 38 | } 39 | 40 | /** 41 | * @access protected 42 | * 43 | * @return bool 44 | */ 45 | public function _retrieve_data() { 46 | 47 | $talent_meta = Helper::get_talent_meta( $this->post ); 48 | 49 | // Minimum value 50 | $score = 1; 51 | 52 | // Calculate plugins score 53 | $score += $this->_calculate_plugin_score( $talent_meta['plugins'] ); 54 | 55 | // Calculate themes score 56 | $score += $this->_calculate_theme_score( $talent_meta['themes'] ); 57 | 58 | // Calculate WordPress.org profile data score 59 | $score += $this->_calculate_badge_score( $talent_meta['profile']['badges'] ); 60 | 61 | // Adjust score based on number of core contributions 62 | 63 | if ( isset( $talent_meta['contribution_count'] ) ) { 64 | $score += $this->_calculate_contribution_score( 65 | $talent_meta['contributions'], 66 | $talent_meta['codex_count'], 67 | $talent_meta['contribution_count'] 68 | ); 69 | } 70 | 71 | // Adjust score based on number of WordPress.tv videos 72 | $score += $this->_calculate_wordpresstv_score( $talent_meta['wordpresstv'] ); 73 | 74 | $score += $this->_calculate_forums_score( $talent_meta['forums'] ); 75 | 76 | // Get median score for the company 77 | if ( 'company' === get_post_type( $this->post ) ) { 78 | if ( 1 == get_post_meta( $this->post->ID, 'wordpress_vip' ) ) { 79 | $score += 10; 80 | } 81 | 82 | $team_score = $this->_calculate_team_score(); 83 | 84 | if ( $team_score ) { 85 | $score = ( $team_score + $score ) / 2; 86 | } 87 | } 88 | 89 | update_post_meta( $this->post->ID, '_score', absint( $score ) ); 90 | update_post_meta( $this->post->ID, '_score_expiration', time() + $this->expiration ); 91 | 92 | return $score; 93 | 94 | } 95 | 96 | /** 97 | * Calculate score based on a user's plugins. 98 | * 99 | * @param array $plugins 100 | * 101 | * @return int 102 | */ 103 | public function _calculate_plugin_score( $plugins ) { 104 | 105 | $score = 0; 106 | 107 | if ( ! is_array( $plugins ) || 1 > count( $plugins ) ) { 108 | return $score; 109 | } 110 | 111 | // Store the download counts in this array 112 | $total_downloads = array(); 113 | 114 | // Set today's date 115 | $now = new DateTime( 'now' ); 116 | 117 | // Loop through plugins 118 | foreach ( $plugins as $plugin ) { 119 | // Check when the plugin was last updated 120 | $plugin_updated = new DateTime( $plugin->last_updated ); 121 | $date_diff = $now->diff( $plugin_updated ); 122 | 123 | // Don't take into account plugins that haven't been updated for 2+ years 124 | if ( 2 >= $date_diff->format( '%y' ) ) { 125 | continue; 126 | } 127 | 128 | // Adjust score based on the plugin's rating 129 | $score += 1 + 1 * ( $plugin->rating / 100 ); 130 | 131 | // Add to downloads array 132 | $total_downloads[] = $plugin->downloaded; 133 | } 134 | 135 | // Check the average downloads count using the median value 136 | sort( $total_downloads, SORT_NUMERIC ); 137 | 138 | if ( ! empty( $total_downloads ) ) { 139 | $avg_downloads = $total_downloads[ (int) round( ( count( $total_downloads ) ) / 2 ) - 1 ]; 140 | } else { 141 | $avg_downloads = 0; 142 | } 143 | 144 | // Adjust score based on average downloads 145 | if ( $avg_downloads > 100000 ) { 146 | $score += 10; 147 | } else if ( $avg_downloads > 50000 ) { 148 | $score += 7; 149 | } else if ( $avg_downloads > 10000 ) { 150 | $score += 4; 151 | } else if ( $avg_downloads > 1000 ) { 152 | $score += 2; 153 | } else { 154 | $score += 1; 155 | } 156 | 157 | return $score; 158 | 159 | } 160 | 161 | /** 162 | * Calculate score based on a user's themes. 163 | * 164 | * @param $themes 165 | * 166 | * @return int 167 | */ 168 | public function _calculate_theme_score( $themes ) { 169 | 170 | $score = 0; 171 | 172 | if ( ! is_array( $themes ) || 1 > count( $themes ) ) { 173 | return $score; 174 | } 175 | 176 | // Store the download counts in this array 177 | $total_downloads = array(); 178 | 179 | // Loop through themes 180 | foreach ( $themes as $theme ) { 181 | // Adjust score based on the theme's rating 182 | $score += 1 + 1 * ( $theme->rating / 100 ); 183 | 184 | // Add to downloads array 185 | $total_downloads[] = $theme->downloaded; 186 | } 187 | 188 | // Check the average downloads count using the median value 189 | sort( $total_downloads, SORT_NUMERIC ); 190 | 191 | if ( ! empty( $total_downloads ) ) { 192 | $avg_downloads = $total_downloads[ (int) round( count( $total_downloads ) / 2 ) - 1 ]; 193 | } else { 194 | $avg_downloads = 0; 195 | } 196 | 197 | // Adjust score based on average downloads 198 | if ( $avg_downloads > 100000 ) { 199 | $score += 15; 200 | } else if ( $avg_downloads > 50000 ) { 201 | $score += 9; 202 | } else if ( $avg_downloads > 10000 ) { 203 | $score += 5; 204 | } else if ( $avg_downloads > 1000 ) { 205 | $score += 3; 206 | } else { 207 | $score += 1; 208 | } 209 | 210 | return $score; 211 | 212 | } 213 | 214 | /** 215 | * Calculate the score for all the user's badges. 216 | * 217 | * @param array $badges 218 | * 219 | * @return int 220 | */ 221 | public function _calculate_badge_score( $badges ) { 222 | 223 | $score = 0; 224 | 225 | // Loop through badges, adjust score depending on type 226 | foreach ( $badges as $badge ) { 227 | switch ( $badge ) { 228 | case 'Core Team': 229 | $score += 50; 230 | break; 231 | case 'Meta Team': 232 | $score += 25; 233 | break; 234 | case 'Plugin Developer': 235 | $score += 15; 236 | break; 237 | case 'Theme Developer': 238 | $score += 15; 239 | break; 240 | case 'Community Team': 241 | $score += 10; 242 | break; 243 | case 'WordCamp Speaker': 244 | $score += 10; 245 | break; 246 | case 'Theme Review Team': 247 | $score += 5; 248 | break; 249 | default: 250 | $score += 2; 251 | break; 252 | } 253 | } 254 | 255 | return $score; 256 | 257 | } 258 | 259 | /** 260 | * Calculate the score for all the users' contributions. 261 | * 262 | * @param array $contributions 263 | * @param int $codex_count 264 | * @param int $changeset_count 265 | * 266 | * @return int 267 | */ 268 | public function _calculate_contribution_score( $contributions, $codex_count = 0, $changeset_count = 0 ) { 269 | 270 | $score = 0; 271 | 272 | $contribution_types = array(); 273 | 274 | // Save number of contributions in this array 275 | foreach ( $contributions as $contribution ) { 276 | $contribution_types[ $contribution ] ++; 277 | } 278 | 279 | // Depending on role the score will be higher or lower 280 | foreach ( $contribution_types as $type => $count ) { 281 | switch ( $type ) { 282 | case 'Core Contributor': 283 | $factor = 2; 284 | break; 285 | case 'Core Committer': 286 | $factor = 3; 287 | break; 288 | case 'Core Developer': 289 | $factor = 4; 290 | break; 291 | case 'Lead Developer': 292 | $factor = 5; 293 | break; 294 | case 'Release Lead': 295 | $factor = 6; 296 | break; 297 | default: 298 | $factor = 1; 299 | break; 300 | } 301 | 302 | $score += $factor * $count; 303 | } 304 | 305 | // Adjust score based on number of codex contributions 306 | $score += ( $codex_count / 20 < 20 ) ? $codex_count / 20 : 20; 307 | 308 | // Adjust score based on number of props 309 | $score += ( $changeset_count / 20 < 20 ) ? $changeset_count / 20 : 20; 310 | 311 | return absint( $score ); 312 | 313 | } 314 | 315 | /** 316 | * Calculate the overall team score. 317 | * 318 | * @return bool|int 319 | */ 320 | public function _calculate_team_score() { 321 | 322 | $score = 0; 323 | 324 | // Find connected posts 325 | $people = get_posts( array( 326 | 'connected_type' => 'team', 327 | 'connected_items' => $this->post, 328 | 'posts_per_page' => - 1, 329 | 'suppress_filters' => false, 330 | ) ); 331 | 332 | /** @var \WP_Post $person */ 333 | foreach ( $people as $person ) { 334 | $person_collector = new self( $person ); 335 | $score += $person_collector->get_data(); 336 | 337 | unset( $person_collector ); 338 | } 339 | 340 | if ( $people ) { 341 | return absint( $score / count( $people ) ); 342 | } 343 | 344 | return false; 345 | 346 | } 347 | 348 | /** 349 | * Calculate score based on a user's videos on WordPress.tv. 350 | * 351 | * @param array $videos 352 | * 353 | * @return int 354 | */ 355 | public function _calculate_wordpresstv_score( $videos ) { 356 | 357 | $score = 0; 358 | 359 | $videos = count( $videos ); 360 | 361 | // Adjust score based on average downloads 362 | if ( $videos > 20 ) { 363 | $score += 20; 364 | } else if ( $videos > 15 ) { 365 | $score += 15; 366 | } else if ( $videos > 10 ) { 367 | $score += 9; 368 | } else if ( $videos > 3 ) { 369 | $score += 3; 370 | } else { 371 | $score += 1; 372 | } 373 | 374 | return $score; 375 | 376 | } 377 | 378 | /** 379 | * Calculate score based on a user's forums contributions. 380 | * 381 | * @param array $forums 382 | * 383 | * @return int 384 | */ 385 | public function _calculate_forums_score( $forums ) { 386 | 387 | $score = 0; 388 | 389 | $total_replies = $forums['total_replies']; 390 | $threads = count( $forums['threads'] ); 391 | 392 | if ( $total_replies >= 1000 ) { 393 | $score = 50; 394 | } else if ( $total_replies > 750 ) { 395 | $score = 37; 396 | } else if ( $total_replies >= 490 ) { 397 | $score = 25; 398 | } else if ( $total_replies >= 90 ) { 399 | $score = 10; 400 | } else if ( $total_replies > 10 ) { 401 | $score = 2; 402 | } 403 | 404 | if ( $threads > 5 ) { 405 | $score += 5; 406 | } 407 | 408 | return $score; 409 | 410 | } 411 | 412 | } -------------------------------------------------------------------------------- /includes/api/Talents.php: -------------------------------------------------------------------------------- 1 | base ] = array( 57 | array( array( $this, 'get_posts' ), WP_JSON_Server::READABLE ), 58 | ); 59 | 60 | $routes[ $this->base . '/(?P\d+)' ] = array( 61 | array( array( $this, 'get_post' ), WP_JSON_Server::READABLE ), 62 | ); 63 | 64 | return $routes; 65 | 66 | } 67 | 68 | /** 69 | * @param array $filter 70 | * @param string $context 71 | * @param null $type 72 | * @param int $page 73 | * 74 | * @return \WP_Error|array 75 | */ 76 | public function get_posts( $filter = array(), $context = 'view', $type = null, $page = 1 ) { 77 | if ( ! empty( $type ) && $type !== $this->type ) { 78 | return new WP_Error( 'json_post_invalid_type', __( 'Invalid post type' ), array( 'status' => 400 ) ); 79 | } 80 | 81 | return parent::get_posts( $filter, $context, $this->type, $page ); 82 | } 83 | 84 | /** 85 | * Retrieve a post 86 | * 87 | * @see WP_JSON_Posts::get_post() 88 | * 89 | * @param $id 90 | * @param string $context 91 | * 92 | * @return \WP_JSON_Response 93 | */ 94 | public function get_post( $id, $context = 'view' ) { 95 | $id = (int) $id; 96 | 97 | if ( empty( $id ) ) { 98 | return new WP_Error( 'json_post_invalid_id', __( 'Invalid post ID.' ), array( 'status' => 404 ) ); 99 | } 100 | 101 | /** @var array $post */ 102 | $post = get_post( $id, ARRAY_A ); 103 | 104 | if ( ! in_array( $post['post_type'], $this->type ) ) { 105 | return new WP_Error( 'json_post_invalid_type', __( 'Invalid post type' ), array( 'status' => 400 ) ); 106 | } 107 | 108 | if ( ! $this->check_read_permission( $post ) ) { 109 | return new WP_Error( 'json_user_cannot_read', __( 'Sorry, you cannot read this post.' ), array( 'status' => 401 ) ); 110 | } 111 | 112 | // Link headers (see RFC 5988) 113 | 114 | $response = new WP_JSON_Response(); 115 | $response->header( 'Last-Modified', mysql2date( 'D, d M Y H:i:s', $post['post_modified_gmt'] ) . 'GMT' ); 116 | 117 | $post = $this->prepare_post( $post, $context ); 118 | 119 | if ( is_wp_error( $post ) ) { 120 | return $post; 121 | } 122 | 123 | foreach ( $post['meta']['links'] as $rel => $url ) { 124 | $response->link_header( $rel, $url ); 125 | } 126 | 127 | $response->link_header( 'alternate', get_permalink( $id ), array( 'type' => 'text/html' ) ); 128 | $response->set_data( $post ); 129 | 130 | return $response; 131 | } 132 | 133 | /** 134 | * Prepare post data 135 | * 136 | * @param array $post The unprepared post data 137 | * @param string $context The context for the prepared post. (view|view-revision|edit|embed|single-parent) 138 | * 139 | * @return array The prepared post data 140 | */ 141 | protected function prepare_post( $post, $context = 'view' ) { 142 | // Holds the data for this post. 143 | $_post = array( 'ID' => absint( $post['ID'] ) ); 144 | 145 | if ( ! $this->check_read_permission( $post ) ) { 146 | return new WP_Error( 'json_user_cannot_read', __( 'Sorry, you cannot read this post.' ), array( 'status' => 401 ) ); 147 | } 148 | 149 | $post_obj = get_post( $post['ID'] ); 150 | 151 | $GLOBALS['post'] = $post_obj; 152 | setup_postdata( $post_obj ); 153 | 154 | // Fetch our talent meta 155 | $talent_meta = Helper::get_talent_meta( $post_obj ); 156 | 157 | // Prepare common post fields 158 | $post_fields = array( 159 | 'title' => get_the_title( $post['ID'] ), // $post['post_title'], 160 | 'type' => $post['post_type'], 161 | 'link' => get_permalink( $post['ID'] ), 162 | ); 163 | 164 | $post_fields_extended = array( 165 | 'slug' => $post['post_name'], 166 | 'avatar' => Helper::get_avatar_url( $post['ID'], 512 ), 167 | 'excerpt' => $this->prepare_excerpt( $post['post_excerpt'] ), 168 | 'content' => apply_filters( 'the_content', $post['post_content'] ), 169 | 'byline' => esc_html( get_post_meta( $post['ID'], 'byline', true ) ), 170 | 'job' => (string) get_post_meta( $post['ID'], 'job', true ), 171 | 'wordpress_vip' => ( 1 == get_post_meta( $post['ID'], 'wordpress_vip', true ) ) ? true : false, 172 | 'location' => $talent_meta['map'], 173 | 'score' => $talent_meta['score'], 174 | 'social' => $talent_meta['social'], 175 | 'badges' => $talent_meta['profile']['badges'], 176 | 'contributions' => array( 177 | 'codex' => array( 'count' => $talent_meta['codex_count'] ), 178 | 'props' => array( 'count' => $talent_meta['changeset_count'] ), 179 | 'core' => $talent_meta['contributions'], 180 | ), 181 | 'plugins' => $talent_meta['plugins'], 182 | 'themes' => $talent_meta['themes'], 183 | //'sticky' => ( $post['post_type'] === 'post' && is_sticky( $post['ID'] ) ), 184 | ); 185 | 186 | // A person can't be a WordPress.com VIP 187 | if ( 'person' === $post['post_type'] ) { 188 | unset( $post_fields_extended['wordpress_vip'] ); 189 | } 190 | 191 | if ( 'company' === $post['post_type'] ) { 192 | // Company itself has no job 193 | unset( $post_fields_extended['job'] ); 194 | 195 | // Find connected team members 196 | $people = get_posts( array( 197 | 'connected_type' => 'team', 198 | 'connected_items' => $post, 199 | 'posts_per_page' => - 1, 200 | 'suppress_filters' => false, 201 | ) ); 202 | 203 | /** @var \WP_Post $person */ 204 | foreach ( $people as $person ) { 205 | // Fetch our talent meta 206 | $person_meta = Helper::get_talent_meta( $person ); 207 | 208 | $post_fields_extended['team'][] = array( 209 | 'ID' => absint( $person->ID ), 210 | 'title' => get_the_title( $person->ID ), 211 | 'type' => $person->post_type, 212 | 'link' => get_permalink( $person->ID ), 213 | 'slug' => $person->post_name, 214 | 'avatar' => Helper::get_avatar_url( $person, 512 ), 215 | 'excerpt' => $this->prepare_excerpt( $person->post_excerpt ), 216 | 'byline' => esc_html( get_post_meta( $person->ID, 'byline', true ) ), 217 | 'job' => (string) get_post_meta( $person->ID, 'job', true ), 218 | 'location' => $person_meta['map'], 219 | 'score' => $person_meta['score'], 220 | 'meta' => array( 221 | 'self' => json_url( '/talents/' . $person->ID ), 222 | 'collection' => json_url( '/talents' ), 223 | ), 224 | ); 225 | } 226 | } 227 | 228 | // Company itself has no job 229 | unset( $post_fields_extended['job'] ); 230 | 231 | // Find connected team members 232 | $products = get_posts( array( 233 | 'connected_type' => 'product_owner', 234 | 'connected_items' => $post, 235 | 'posts_per_page' => - 1, 236 | 'suppress_filters' => false, 237 | ) ); 238 | 239 | /** @var \WP_Post $product */ 240 | foreach ( $products as $product ) { 241 | $thumbnail = ''; 242 | if ( has_post_thumbnail( $product ) ) { 243 | $image = wp_get_attachment_image_src( get_post_thumbnail_id( $product ), 'large' ); 244 | if ( $image ) { 245 | $thumbnail = $image[0]; 246 | } 247 | } 248 | $post_fields_extended['products'][] = array( 249 | 'ID' => absint( $product->ID ), 250 | 'title' => get_the_title( $product->ID ), 251 | 'link' => get_permalink( $product->ID ), 252 | 'slug' => $product->post_name, 253 | 'image' => $thumbnail, 254 | 'excerpt' => $this->prepare_excerpt( $product->post_excerpt ), 255 | 'byline' => esc_html( get_post_meta( $product->ID, 'byline', true ) ), 256 | 'meta' => array( 257 | 'self' => json_url( '/products/' . $product->ID ), 258 | 'collection' => json_url( '/products' ), 259 | ), 260 | ); 261 | } 262 | 263 | // Find connected jobs 264 | $jobs = get_posts( array( 265 | 'connected_type' => 'hiring', 266 | 'connected_items' => $post, 267 | 'posts_per_page' => - 1, 268 | 'suppress_filters' => false, 269 | ) ); 270 | 271 | /** @var \WP_Post $job */ 272 | foreach ( $jobs as $job ) { 273 | $post_fields_extended['jobs'][] = array( 274 | 'ID' => absint( $job->ID ), 275 | 'title' => get_the_title( $job->ID ), 276 | 'link' => get_permalink( $job->ID ), 277 | 'slug' => $job->post_name, 278 | 'excerpt' => $this->prepare_excerpt( $job->post_excerpt ), 279 | 'meta' => array( 280 | 'self' => json_url( '/jobs/' . $job->ID ), 281 | 'collection' => json_url( '/jobs' ), 282 | ), 283 | ); 284 | } 285 | 286 | // Dates 287 | if ( '0000-00-00 00:00:00' === $post['post_date_gmt'] ) { 288 | $post_fields['date'] = null; 289 | $post_fields_extended['date_gmt'] = null; 290 | } else { 291 | $post_fields['date'] = json_mysql_to_rfc3339( $post['post_date'] ); 292 | $post_fields_extended['date_gmt'] = json_mysql_to_rfc3339( $post['post_date_gmt'] ); 293 | } 294 | 295 | if ( '0000-00-00 00:00:00' === $post['post_modified_gmt'] ) { 296 | $post_fields['modified'] = null; 297 | $post_fields_extended['modified_gmt'] = null; 298 | } else { 299 | $post_fields['modified'] = json_mysql_to_rfc3339( $post['post_modified'] ); 300 | $post_fields_extended['modified_gmt'] = json_mysql_to_rfc3339( $post['post_modified_gmt'] ); 301 | } 302 | 303 | // Merge requested $post_fields fields into $_post 304 | $_post = array_merge( $_post, $post_fields ); 305 | 306 | // Include extended fields. We might come back to this. 307 | $_post = array_merge( $_post, $post_fields_extended ); 308 | 309 | // Entity meta 310 | $links = array( 311 | 'self' => json_url( '/talents/' . $post['ID'] ), 312 | 'collection' => json_url( '/talents' ), 313 | ); 314 | 315 | $_post['meta'] = array( 'links' => $links ); 316 | 317 | return apply_filters( 'json_prepare_talent', $_post, $post, $context ); 318 | } 319 | 320 | } -------------------------------------------------------------------------------- /includes/core/Helper.php: -------------------------------------------------------------------------------- 1 | sprintf( _x( '%s', 'post type general name', 'wptalents' ), $plural ), 39 | 'singular_name' => sprintf( _x( '%s', 'post type singular name', 'wptalents' ), $singular ), 40 | 'add_new' => __( 'Add New', 'wptalents-theme' ), 41 | 'add_new_item' => sprintf( __( 'Add New %s', 'wptalents' ), $singular ), 42 | 'edit_item' => sprintf( __( 'Edit %s', 'wptalents' ), $singular ), 43 | 'new_item' => sprintf( __( 'New %s', 'wptalents' ), $singular ), 44 | 'view_item' => sprintf( __( 'View %s', 'wptalents' ), $singular ), 45 | 'search_items' => sprintf( __( 'Search %s', 'wptalents' ), $plural ), 46 | 'not_found' => sprintf( __( 'No %s found', 'wptalents' ), $plural ), 47 | 'not_found_in_trash' => sprintf( __( 'No %s found in Trash', 'wptalents' ), $plural ), 48 | 'parent_item_colon' => '', 49 | ); 50 | 51 | } 52 | 53 | /** 54 | * Determine if a post exists based on post_name (slug) and post_type. 55 | * 56 | * @param string $post_name The post slug. 57 | * @param array|string $post_type Post Type. Defaults to post 58 | * 59 | * @return object|null The resulting row on success, null on failure. 60 | */ 61 | public static function post_exists( $post_name, $post_type = 'post' ) { 62 | 63 | /** @var wpdb $wpdb */ 64 | global $wpdb; 65 | 66 | $query = "SELECT ID, post_type FROM $wpdb->posts WHERE 1=1 AND post_status IN ( 'publish', 'draft' ) "; 67 | $args = array(); 68 | 69 | if ( ! empty( $post_name ) ) { 70 | $query .= ' AND post_name LIKE \'%s\' '; 71 | $args[] = $post_name; 72 | } 73 | if ( ! empty( $post_type ) ) { 74 | $post_type_in = implode( ', ', array_fill( 0, count( (array) $post_type ), '%s' ) ); 75 | 76 | $query .= " AND post_type IN ( $post_type_in )"; 77 | foreach ( (array) $post_type as $type ) { 78 | $args[] = $type; 79 | } 80 | } 81 | 82 | $query .= ' LIMIT 1'; 83 | 84 | $result = $wpdb->get_row( $wpdb->prepare( $query, $args ) ); 85 | 86 | if ( null === $result ) { 87 | return false; 88 | } 89 | 90 | return $result; 91 | 92 | } 93 | 94 | /** 95 | * @param WP_Post $post The post object or ID. 96 | * @param string $type The meta to retrieve. Defaults to all. 97 | * Possible values are: 98 | * - profile 99 | * - plugins 100 | * - themes 101 | * 102 | * @return mixed The required meta if available, 103 | * false if the post does not exist. 104 | */ 105 | public static function get_talent_meta( WP_Post $post, $type = 'all' ) { 106 | 107 | switch ( $type ) { 108 | case 'profile': 109 | $collector = new Profile_Collector( $post ); 110 | 111 | return $collector->get_data(); 112 | break; 113 | case 'badges': 114 | $collector = new Profile_Collector( $post ); 115 | 116 | return $collector->get_data()['badges']; 117 | break; 118 | case 'plugins': 119 | $collector = new Plugin_Collector( $post ); 120 | 121 | return $collector->get_data(); 122 | break; 123 | case 'themes': 124 | $collector = new Theme_Collector( $post ); 125 | 126 | return $collector->get_data(); 127 | break; 128 | case 'score': 129 | $collector = new Score_Collector( $post ); 130 | 131 | return $collector->get_data(); 132 | break; 133 | case 'forums': 134 | $collector = new Forums_Collector( $post ); 135 | 136 | return $collector->get_data(); 137 | break; 138 | case 'wordpresstv': 139 | $collector = new WordPressTv_Collector( $post ); 140 | 141 | return $collector->get_data(); 142 | break; 143 | case 'contributions': 144 | $collector = new Contribution_Collector( $post ); 145 | 146 | return $collector->get_data(); 147 | break; 148 | case 'social': 149 | return self::get_social_links( $post ); 150 | break; 151 | case 'dawnpatrol': 152 | if ( ! $profile = esc_url( get_post_meta( $post->ID, 'dawnpatrol', true ) ) ) { 153 | return false; 154 | } 155 | 156 | return array( 157 | 'profile' => $profile, 158 | 'video' => esc_url( get_post_meta( $post->ID, 'dawnpatrol-video', true ) ), 159 | ); 160 | case 'map': 161 | return self::get_map_data( $post ); 162 | break; 163 | case 'location': 164 | $location = get_post_meta( $post->ID, 'location', true ); 165 | 166 | if ( is_string( $location ) ) { 167 | return array( 168 | 'name' => $location, 169 | ); 170 | } 171 | 172 | return $location; 173 | break; 174 | default: 175 | // Return all meta 176 | 177 | $theme_collector = new Theme_Collector( $post ); 178 | $plugin_collector = new Plugin_Collector( $post ); 179 | $profile_collector = new Profile_Collector( $post ); 180 | $contribution_collector = new Contribution_Collector( $post ); 181 | $codex_collector = new Codex_Collector( $post ); 182 | $changeset_collector = new Changeset_Collector( $post ); 183 | $score_collector = new Score_Collector( $post ); 184 | $forums_collector = new Forums_Collector( $post ); 185 | $wordpresstv_collector = new WordPressTv_Collector( $post ); 186 | 187 | return array( 188 | 'score' => $score_collector->get_data(), 189 | 'social' => self::get_social_links( $post ), 190 | 'dawnpatrol' => self::get_talent_meta( $post, 'dawnpatrol' ), 191 | 'profile' => $profile_collector->get_data(), 192 | 'map' => self::get_map_data( $post ), 193 | 'plugins' => $plugin_collector->get_data(), 194 | 'themes' => $theme_collector->get_data(), 195 | 'contributions' => $contribution_collector->get_data(), 196 | 'codex_count' => $codex_collector->get_data(), 197 | 'changeset_count' => $changeset_collector->get_data(), 198 | 'forums' => $forums_collector->get_data(), 199 | 'wordpresstv' => $wordpresstv_collector->get_data(), 200 | ); 201 | break; 202 | 203 | } 204 | } 205 | 206 | /** 207 | * Get the avatar URL of a talent. 208 | * 209 | * @param \WP_Post|int $post The post object or ID. 210 | * 211 | * @param int $size Size of the avatar image. 212 | * 213 | * @return string The avatar URL. 214 | */ 215 | public static function get_avatar_url( $post, $size ) { 216 | 217 | /** @var \WP_Post $post */ 218 | $post = get_post( $post ); 219 | 220 | $profile = self::get_talent_meta( $post, 'profile' ); 221 | 222 | if ( ! isset( $profile['avatar'] ) ) { 223 | $profile = array( 'avatar' => 'https://secure.gravatar.com/avatar/' ); 224 | } 225 | 226 | // Add size parameter 227 | $avatar = add_query_arg( array( 's' => absint( $size ), 'd' => 'mm' ), $profile['avatar'] ); 228 | 229 | return esc_url( $avatar ); 230 | 231 | } 232 | 233 | /** 234 | * Get the avatar of a talent. 235 | * 236 | * @param \WP_Post|int $post The post object or ID. 237 | * 238 | * @param int $size 239 | * 240 | * @return mixed The avatar img tag on success, 241 | * false if the post does not exist. 242 | */ 243 | public static function get_avatar( WP_Post $post, $size = 144 ) { 244 | 245 | $avatar = self::get_avatar_url( $post, $size ); 246 | 247 | return sprintf( 248 | '%2$s', 249 | esc_url( $avatar ), 250 | esc_attr( get_the_title( $post ) ), 251 | absint( $size ) 252 | ); 253 | 254 | } 255 | 256 | /** 257 | * @param \WP_Post $post 258 | * 259 | * @return array 260 | */ 261 | public static function get_social_links( WP_Post $post ) { 262 | 263 | $social_links = array(); 264 | 265 | $meta_fields = array_merge( 266 | array( 'wordpressdotorg' => get_post_meta( $post->ID, 'wordpress-username', true ) ), 267 | (array) get_post_meta( $post->ID, 'social', true ) 268 | ); 269 | 270 | foreach ( $meta_fields as $field => $value ) { 271 | if ( '' === $value || is_array( $value ) ) { 272 | continue; 273 | } 274 | 275 | switch ( $field ) { 276 | case 'wordpressdotorg': 277 | $social_links[ $field ] = array( 278 | 'name' => __( 'WordPress.org', 'wptalents' ), 279 | 'url' => esc_url( 'https://profiles.wordpress.org/' . $value ), 280 | ); 281 | break; 282 | case 'url': 283 | $social_links[ $field ] = array( 284 | 'name' => __( 'Website', 'wptalents' ), 285 | 'url' => esc_url( $value ), 286 | ); 287 | break; 288 | case 'linkedin': 289 | $social_links[ $field ] = array( 290 | 'name' => __( 'LinkedIn', 'wptalents' ), 291 | 'url' => esc_url( $value ), 292 | ); 293 | break; 294 | case 'github': 295 | $social_links[ $field ] = array( 296 | 'name' => __( 'GitHub', 'wptalents' ), 297 | 'url' => esc_url( 'https://github.com/' . $value ), 298 | ); 299 | break; 300 | case 'twitter': 301 | $social_links[ $field ] = array( 302 | 'name' => __( 'Twitter', 'wptalents' ), 303 | 'url' => esc_url( 'https://twitter.com/' . $value ), 304 | ); 305 | break; 306 | case 'facebook': 307 | $social_links[ $field ] = array( 308 | 'name' => __( 'Facebook', 'wptalents' ), 309 | 'url' => esc_url( 'https://www.facebook.com/' . $value ), 310 | ); 311 | break; 312 | case 'google-plus': 313 | $social_links[ $field ] = array( 314 | 'name' => __( 'Google+', 'wptalents' ), 315 | 'url' => esc_url( 'https://plus.google.com/' . $value ), 316 | ); 317 | break; 318 | default: 319 | break; 320 | } 321 | } 322 | 323 | return $social_links; 324 | 325 | } 326 | 327 | /** 328 | * Gets the map data of a talent. 329 | * 330 | * If it's a company, it returns the locations of all 331 | * team members so we can show one big map. 332 | * 333 | * @param WP_Post $post The post object. 334 | * 335 | * @return array Location data as an array 336 | */ 337 | public static function get_map_data( WP_Post $post ) { 338 | 339 | $location = self::get_talent_meta( $post, 'location' ); 340 | 341 | if ( empty( $location['lat'] ) || empty( $location['long'] ) || empty( $location['name'] ) ) { 342 | return false; 343 | } 344 | 345 | $thumbnail = ''; 346 | if ( has_post_thumbnail( $post->ID ) ) { 347 | $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' ); 348 | if ( $image ) { 349 | $thumbnail = $image[0]; 350 | } 351 | } 352 | 353 | return array( 354 | 'name' => $location['name'], 355 | 'lat' => $location['lat'], 356 | 'long' => $location['long'], 357 | 'image' => $thumbnail, 358 | ); 359 | 360 | } 361 | 362 | /** 363 | * Get the URL of an attachment based on its ID. 364 | * 365 | * @param int $attachment 366 | * @param string $size 367 | * 368 | * @return bool|string 369 | */ 370 | public static function get_attachment_url( $attachment, $size = 'full' ) { 371 | 372 | $image = wp_get_attachment_image_src( $attachment, $size ); 373 | 374 | if ( $image ) { 375 | return esc_url( $image[0] ); 376 | } 377 | 378 | return false; 379 | 380 | } 381 | 382 | /** 383 | * Examine a url and try to determine the post ID it represents. 384 | * 385 | * Checks are supposedly from the hosted site blog. 386 | * 387 | * Extends the url_to_postid() function from WordPress to work 388 | * with WP Talents' permalink structure. 389 | * 390 | * @param string $url Permalink to check. 391 | * 392 | * @return int Post ID, or 0 on failure. 393 | */ 394 | public static function url_to_postid( $url ) { 395 | global $wp_rewrite; 396 | 397 | /** 398 | * Filter the URL to derive the post ID from. 399 | * 400 | * @since 2.2.0 401 | * 402 | * @param string $url The URL to derive the post ID from. 403 | */ 404 | $url = apply_filters( 'url_to_postid', $url ); 405 | 406 | // First, check to see if there is a 'p=N' or 'page_id=N' to match against 407 | if ( preg_match( '#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values ) ) { 408 | $id = absint( $values[2] ); 409 | if ( $id ) { 410 | return $id; 411 | } 412 | } 413 | 414 | // Check to see if we are using rewrite rules 415 | $rewrite = $wp_rewrite->wp_rewrite_rules(); 416 | 417 | // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options 418 | if ( empty( $rewrite ) ) { 419 | return 0; 420 | } 421 | 422 | // Get rid of the #anchor 423 | $url_split = explode( '#', $url ); 424 | $url = $url_split[0]; 425 | 426 | // Get rid of URL ?query=string 427 | $url_split = explode( '?', $url ); 428 | $url = $url_split[0]; 429 | 430 | // Add 'www.' if it is absent and should be there 431 | if ( false !== strpos( home_url(), '://www.' ) && false === strpos( $url, '://www.' ) ) { 432 | $url = str_replace( '://', '://www.', $url ); 433 | } 434 | 435 | // Strip 'www.' if it is present and shouldn't be 436 | if ( false === strpos( home_url(), '://www.' ) ) { 437 | $url = str_replace( '://www.', '://', $url ); 438 | } 439 | 440 | // Strip 'index.php/' if we're not using path info permalinks 441 | if ( ! $wp_rewrite->using_index_permalinks() ) { 442 | $url = str_replace( $wp_rewrite->index . '/', '', $url ); 443 | } 444 | 445 | if ( false !== strpos( trailingslashit( $url ), home_url( '/' ) ) ) { 446 | // Chop off http://domain.com/[path] 447 | $url = str_replace( home_url(), '', $url ); 448 | } else { 449 | // Chop off /path/to/blog 450 | $home_path = parse_url( home_url( '/' ) ); 451 | $home_path = isset( $home_path['path'] ) ? $home_path['path'] : ''; 452 | $url = preg_replace( sprintf( '#^%s#', preg_quote( $home_path ) ), '', trailingslashit( $url ) ); 453 | } 454 | 455 | // Trim leading and lagging slashes 456 | $url = trim( $url, '/' ); 457 | 458 | $request = $url; 459 | $post_type_query_vars = array(); 460 | 461 | foreach ( get_post_types( array(), 'objects' ) as $post_type => $t ) { 462 | if ( ! empty( $t->query_var ) ) { 463 | $post_type_query_vars[ $t->query_var ] = $post_type; 464 | } 465 | } 466 | 467 | // Look for matches. 468 | $request_match = $request; 469 | foreach ( (array) $rewrite as $match => $query ) { 470 | 471 | // If the requesting file is the anchor of the match, prepend it 472 | // to the path info. 473 | if ( ! empty( $url ) && ( $url != $request ) && ( 0 === strpos( $match, $url ) ) ) { 474 | $request_match = $url . '/' . $request; 475 | } 476 | 477 | if ( preg_match( "#^$match#", $request_match, $matches ) ) { 478 | 479 | if ( $wp_rewrite->use_verbose_page_rules && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) { 480 | // this is a verbose page match, lets check to be sure about it 481 | if ( ! get_page_by_path( $matches[ $varmatch[1] ] ) ) { 482 | continue; 483 | } 484 | } 485 | 486 | // Got a match. 487 | // Trim the query of everything up to the '?'. 488 | $query = preg_replace( '!^.+\?!', '', $query ); 489 | 490 | // Substitute the substring matches into the query. 491 | $query = addslashes( \WP_MatchesMapRegex::apply( $query, $matches ) ); 492 | 493 | // Filter out non-public query vars 494 | global $wp; 495 | parse_str( $query, $query_vars ); 496 | $query = array(); 497 | foreach ( (array) $query_vars as $key => $value ) { 498 | if ( in_array( $key, $wp->public_query_vars ) ) { 499 | $query[ $key ] = $value; 500 | if ( isset( $post_type_query_vars[ $key ] ) ) { 501 | $query['post_type'] = $post_type_query_vars[ $key ]; 502 | $query['name'] = $value; 503 | } else if ( 'talent' === $key ) { 504 | $query['post_type'] = array( 'person', 'company', 'product' ); 505 | $query['name'] = $value; 506 | } 507 | } 508 | } 509 | 510 | // Do the query 511 | $query = new \WP_Query( $query ); 512 | if ( ! empty( $query->posts ) && $query->is_singular ) { 513 | return $query->post->ID; 514 | } else { 515 | return 0; 516 | } 517 | } 518 | } 519 | 520 | return 0; 521 | } 522 | 523 | } -------------------------------------------------------------------------------- /includes/core/Plugin.php: -------------------------------------------------------------------------------- 1 | router = new Router(); 43 | 44 | add_action( 'init', array( $this, 'load_plugin_textdomain' ), 4 ); 45 | 46 | add_action( 'init', array( $this, 'add_types' ), 8 ); 47 | 48 | add_action( 'init', array( $this, 'add_rewrite_rules' ) ); 49 | 50 | add_action( 'init', array( $this, 'register_post_types' ) ); 51 | 52 | add_action( 'init', array( $this, 'register_taxonomies' ) ); 53 | 54 | add_action( 'p2p_init', array( $this, 'register_connections' ) ); 55 | 56 | add_action( 'init', array( $this, 'filter_body_class' ) ); 57 | 58 | add_action( 'init', array( $this, 'filter_post_class' ) ); 59 | 60 | add_action( 'init', array( $this, 'add_meta_boxes' ) ); 61 | 62 | add_action( 'save_post', array( $this, 'add_map_on_save_post' ) ); 63 | 64 | add_filter( 'cmb_field_types', array( $this, 'add_cmb_field_types' ) ); 65 | 66 | // FacetWP 67 | 68 | add_filter( 'facetwp_sort_options', array( __CLASS__, 'facetwp_sort_options' ) ); 69 | 70 | add_filter( 'facetwp_pager_html', array( __CLASS__, 'facetwp_pager_html' ), 10, 2 ); 71 | 72 | // JSON API 73 | 74 | add_filter( 'json_url_prefix', array( __CLASS__, 'api_url_prefix' ) ); 75 | 76 | add_action( 'wp_json_server_before_serve', array( __CLASS__, 'api_init' ) ); 77 | 78 | add_action( 'wp_head', array( $this, 'add_oembed_links' ) ); 79 | 80 | } 81 | 82 | /** 83 | * Add rewrite rules for the plugin. 84 | */ 85 | public function add_rewrite_rules() { 86 | 87 | add_rewrite_rule( '([^/]+)?/?$', 'index.php?talent=$matches[1]', 'top' ); 88 | add_rewrite_rule( '([^/]+)?/embed(/(.*))?/?$', 'index.php?talent=$matches[1]&embed=$matches[2]', 'top' ); 89 | 90 | add_rewrite_endpoint( 'embed', EP_PERMALINK ); 91 | 92 | } 93 | 94 | /** 95 | * Load the plugin text domain for translation. 96 | */ 97 | public function load_plugin_textdomain() { 98 | 99 | $locale = apply_filters( 'plugin_locale', get_locale(), 'wptalents' ); 100 | 101 | load_textdomain( 102 | 'wptalents', 103 | trailingslashit( WP_LANG_DIR ) . 'wptalents/wptalents' . $locale . '.mo' 104 | ); 105 | 106 | load_plugin_textdomain( 107 | 'wptalents', 108 | false, 109 | basename( plugin_dir_path( dirname( __FILE__ ) ) ) . '/languages/' 110 | ); 111 | 112 | } 113 | 114 | /** 115 | * Fired when the plugin is activated. 116 | */ 117 | public function activate() { 118 | 119 | // Register post types 120 | $this->register_post_types(); 121 | 122 | // Register taxonomies 123 | $this->register_taxonomies(); 124 | 125 | // Change JSON API URL prefix 126 | add_filter( 'json_url_prefix', array( __CLASS__, 'api_url_prefix' ) ); 127 | 128 | // Update the rewrite rules 129 | flush_rewrite_rules(); 130 | 131 | } 132 | 133 | /** 134 | * Fired when the plugin is deactivated. 135 | */ 136 | public function deactivate() { 137 | 138 | flush_rewrite_rules(); 139 | 140 | } 141 | 142 | /** 143 | * Initialize all the content types. 144 | */ 145 | public function add_types() { 146 | 147 | $this->types = apply_filters( 'wptalents_types', array( 148 | 'person' => new Person(), 149 | 'company' => new Company(), 150 | 'activity' => new Activity(), 151 | 'product' => new Product(), 152 | 'job' => new Job(), 153 | ) ); 154 | 155 | } 156 | 157 | /** 158 | * Register all post types. 159 | */ 160 | public function register_post_types() { 161 | 162 | /** @var $type \WPTalents\Types\Type */ 163 | foreach ( $this->types as $type ) { 164 | $type->register_post_type(); 165 | } 166 | 167 | } 168 | 169 | /** 170 | * Register all taxonomies. 171 | */ 172 | public function register_taxonomies() { 173 | 174 | /** @var $type \WPTalents\Types\Type */ 175 | foreach ( $this->types as $type ) { 176 | $type->register_taxonomy(); 177 | } 178 | 179 | } 180 | 181 | /** 182 | * Registers our connections using Posts 2 Posts. 183 | * 184 | * @uses p2p_register_connection_type() 185 | */ 186 | public static function register_connections() { 187 | 188 | p2p_register_connection_type( array( 189 | 'name' => 'talent_activity', 190 | 'from' => 'activity', 191 | 'to' => array( 'company', 'person', 'product' ), 192 | 'cardinality' => 'many-to-many', 193 | 'title' => __( 'Connected', 'wptalents' ), 194 | 'admin_box' => array( 195 | 'show' => 'from', 196 | 'context' => 'side', 197 | ), 198 | 'can_create_post' => false, 199 | 'to_query_vars' => array( 'post_status' => 'any' ), 200 | 'from_query_vars' => array( 'post_status' => 'any' ), 201 | ) ); 202 | 203 | p2p_register_connection_type( array( 204 | 'name' => 'product_owner', 205 | 'from' => 'product', 206 | 'to' => array( 'person', 'company' ), 207 | 'cardinality' => 'many-to-many', 208 | 'title' => array( 209 | 'from' => __( 'Owner', 'wptalents' ), 210 | 'to' => __( 'Products', 'wptalents' ) 211 | ), 212 | 'admin_box' => array( 213 | 'show' => 'any', 214 | 'context' => 'side', 215 | ), 216 | 'can_create_post' => false, 217 | 'to_query_vars' => array( 'post_status' => 'any' ), 218 | 'from_query_vars' => array( 'post_status' => 'any' ), 219 | ) ); 220 | 221 | p2p_register_connection_type( array( 222 | 'name' => 'team', 223 | 'from' => 'company', 224 | 'to' => 'person', 225 | 'cardinality' => 'many-to-many', 226 | 'title' => __( 'Employees', 'wptalents' ), 227 | 'admin_box' => array( 228 | 'show' => 'any', 229 | 'context' => 'advanced', 230 | ), 231 | 'fields' => array( 232 | 'role' => array( 233 | 'title' => __( 'Role', 'wptalents' ), 234 | 'values' => array( 235 | 'ceo' => __( 'CEO', 'wptalents' ), 236 | 'cto' => __( 'CTO', 'wptalents' ), 237 | 'founder' => __( 'Founder', 'wptalents' ), 238 | 'employee' => __( 'Employee', 'wptalents' ) 239 | ), 240 | 'default' => 'employee', 241 | ), 242 | 'from' => array( 243 | 'title' => __( 'From', 'wptalents' ), 244 | 'type' => 'date', 245 | 'default' => '', 246 | ), 247 | 'to' => array( 248 | 'title' => __( 'To', 'wptalents' ), 249 | 'type' => 'date', 250 | 'default' => '', 251 | ), 252 | ), 253 | 'can_create_post' => false, 254 | 'to_query_vars' => array( 'post_status' => 'any' ), 255 | 'from_query_vars' => array( 'post_status' => 'any' ), 256 | ) ); 257 | 258 | p2p_register_connection_type( array( 259 | 'name' => 'hiring', 260 | 'from' => 'company', 261 | 'to' => 'job', 262 | 'cardinality' => 'one-to-many', 263 | 'title' => array( 264 | 'from' => __( 'Open Jobs', 'wptalents' ), 265 | 'to' => __( 'Company', 'wptalents' ), 266 | ), 267 | 'admin_box' => array( 268 | 'show' => 'from', 269 | 'context' => 'side', 270 | ), 271 | 'can_create_post' => false, 272 | 'to_query_vars' => array( 'post_status' => 'any' ), 273 | 'from_query_vars' => array( 'post_status' => 'any' ), 274 | ) ); 275 | 276 | } 277 | 278 | public function add_meta_boxes() { 279 | 280 | /** @var $type WP_Talents_Type */ 281 | foreach ( $this->types as $type ) { 282 | add_filter( 'cmb_meta_boxes', array( $type, 'add_meta_boxes' ) ); 283 | } 284 | 285 | } 286 | 287 | /** 288 | * Add our custom CMB field types. 289 | * 290 | * @param array $cmb_field_types 291 | * 292 | * @return array 293 | */ 294 | public function add_cmb_field_types( array $cmb_field_types ) { 295 | 296 | $cmb_field_types['gmap'] = 'WPTalents\CMB\Gmap_Field'; 297 | 298 | return $cmb_field_types; 299 | 300 | } 301 | 302 | /** 303 | * Activate each type's body_class filter. 304 | */ 305 | public function filter_body_class() { 306 | 307 | /** @var $type WP_Talents_Type */ 308 | foreach ( $this->types as $type ) { 309 | add_filter( 'body_class', array( $type, 'filter_body_class' ) ); 310 | } 311 | 312 | } 313 | 314 | /** 315 | * Activate each type's post_class filter 316 | */ 317 | public function filter_post_class() { 318 | 319 | /** @var $type WP_Talents_Type */ 320 | foreach ( $this->types as $type ) { 321 | add_filter( 'post_class', array( $type, 'filter_post_class' ) ); 322 | } 323 | 324 | } 325 | 326 | /** 327 | * Add oEmbed discovery links to single talent & product pages 328 | */ 329 | public function add_oembed_links() { 330 | 331 | if ( is_singular( array( 'company', 'person', 'product' ) ) ) { 332 | echo '' . "\n"; 333 | } 334 | 335 | } 336 | 337 | /** 338 | * Fetches the map of the talent's location from Google Maps 339 | * and sets it as the post thumbnail. 340 | * 341 | * It also replaces all intermediate image sizes with 342 | * the file from Google Maps, as they are from better quality 343 | * and way smaller than the generated ones. 344 | * 345 | * @param int $post_id The ID of the current post. 346 | */ 347 | public function add_map_on_save_post( $post_id ) { 348 | 349 | // If this is just a revision or the post already has a thumbnail, don't proceed 350 | if ( wp_is_post_revision( $post_id ) || has_post_thumbnail( $post_id ) ) { 351 | return; 352 | } 353 | 354 | if ( ! in_array( get_post_type( $post_id ), array_keys( $this->types ) ) ) { 355 | return; 356 | } 357 | 358 | // Get the talent's location data 359 | $location = Helper::get_talent_meta( get_post( $post_id ), 'location' ); 360 | 361 | if ( empty( $location['name'] ) ) { 362 | return; 363 | } 364 | 365 | $map_retina = sprintf( 366 | 'https://maps.googleapis.com/maps/api/staticmap?center=%s&scale=2&zoom=6&size=600x320&maptype=roadmap', 367 | urlencode( $location['name'] ) 368 | ); 369 | 370 | $tmp_retina = download_url( $map_retina ); 371 | 372 | $slug = get_post( $post_id )->post_name; 373 | 374 | if ( '' === $slug ) { 375 | $slug = sanitize_title( get_the_title( $post_id ) ); 376 | } 377 | 378 | // Set variables for storage 379 | $file_array = array( 380 | 'name' => $slug . '-map.png', 381 | 'tmp_name' => $tmp_retina, 382 | ); 383 | 384 | // If error storing temporarily, unlink 385 | if ( is_wp_error( $tmp_retina ) ) { 386 | return; 387 | } 388 | 389 | // do the validation and storage stuff 390 | $attachment_id = media_handle_sideload( $file_array, $post_id, $location['name'] ); 391 | 392 | // If error storing permanently, unlink 393 | if ( is_wp_error( $attachment_id ) ) { 394 | unlink( $file_array['tmp_name'] ); 395 | 396 | return; 397 | } 398 | 399 | // Set map as post thumbnail 400 | set_post_thumbnail( $post_id, $attachment_id ); 401 | 402 | // Add Normal image as image size of the attachment 403 | 404 | $metadata = wp_get_attachment_metadata( $attachment_id ); 405 | 406 | $attachment_path = get_attached_file( $attachment_id ); 407 | $attachment_file = basename( $attachment_path ); 408 | 409 | foreach ( $this->get_image_sizes() as $size => $values ) { 410 | 411 | $map = sprintf( 412 | 'https://maps.googleapis.com/maps/api/staticmap?center=%s&scale=1&zoom=6&size=%s&maptype=roadmap', 413 | urlencode( $location['name'] ), 414 | $values['width'] . 'x' . $values['height'] 415 | ); 416 | 417 | $tmp = download_url( $map ); 418 | 419 | // Set variables for storage 420 | $file_array = array( 421 | 'name' => $metadata['sizes'][ $size ]['file'], 422 | 'tmp_name' => $tmp, 423 | ); 424 | 425 | // If error storing temporarily, unlink 426 | if ( is_wp_error( $tmp ) ) { 427 | unlink( $file_array['tmp_name'] ); 428 | 429 | continue; 430 | } 431 | 432 | unlink( str_replace( $attachment_file, $metadata['sizes'][ $size ]['file'], $attachment_path ) ); 433 | 434 | $post = get_post( $post_id ); 435 | $time = $post->post_date; 436 | 437 | $file = wp_handle_sideload( $file_array, array( 'test_form' => false ), $time ); 438 | 439 | if ( isset( $file['error'] ) ) { 440 | unlink( $file_array['tmp_name'] ); 441 | } 442 | } 443 | 444 | } 445 | 446 | public function get_image_sizes( $size = '' ) { 447 | 448 | global $_wp_additional_image_sizes; 449 | 450 | $sizes = array(); 451 | $get_intermediate_image_sizes = get_intermediate_image_sizes(); 452 | 453 | // Create the full array with sizes and crop info 454 | foreach ( $get_intermediate_image_sizes as $_size ) { 455 | 456 | if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ) ) ) { 457 | 458 | $sizes[ $_size ]['width'] = get_option( $_size . '_size_w' ); 459 | $sizes[ $_size ]['height'] = get_option( $_size . '_size_h' ); 460 | $sizes[ $_size ]['crop'] = (bool) get_option( $_size . '_crop' ); 461 | 462 | } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) { 463 | 464 | $sizes[ $_size ] = array( 465 | 'width' => $_wp_additional_image_sizes[ $_size ]['width'], 466 | 'height' => $_wp_additional_image_sizes[ $_size ]['height'], 467 | 'crop' => $_wp_additional_image_sizes[ $_size ]['crop'] 468 | ); 469 | 470 | } 471 | 472 | } 473 | 474 | // Get only 1 size if found 475 | if ( $size ) { 476 | 477 | if ( isset( $sizes[ $size ] ) ) { 478 | return $sizes[ $size ]; 479 | } else { 480 | return false; 481 | } 482 | 483 | } 484 | 485 | return $sizes; 486 | } 487 | 488 | /** 489 | * Filter the FacetWP sort options. 490 | * 491 | * @param array $options 492 | * 493 | * @return array 494 | */ 495 | public static function facetwp_sort_options( $options ) { 496 | 497 | $options['score_desc'] = array( 498 | 'label' => __( 'Score (Highest)', 'wptalents' ), 499 | 'query_args' => array( 500 | 'orderby' => 'meta_value_num', 501 | 'order' => 'DESC', 502 | 'meta_key' => '_score', 503 | ) 504 | ); 505 | 506 | $options['score_asc'] = array( 507 | 'label' => __( 'Score (Lowest)', 'wptalents' ), 508 | 'query_args' => array( 509 | 'orderby' => 'meta_value_num', 510 | 'order' => 'ASC', 511 | 'meta_key' => '_score', 512 | ) 513 | ); 514 | 515 | unset( $options['date_desc'] ); 516 | unset( $options['date_asc'] ); 517 | 518 | return $options; 519 | 520 | } 521 | 522 | /** 523 | * Filter the FacetWP pagination output. 524 | * 525 | * @param string $output 526 | * @param array $params 527 | * 528 | * @return string 529 | */ 530 | public static function facetwp_pager_html( $output, $params ) { 531 | 532 | unset( $output ); 533 | $output = ''; 534 | 535 | $page = (int) $params['page']; 536 | $per_page = (int) $params['per_page']; 537 | $total_rows = (int) $params['total_rows']; 538 | 539 | // Prevent division by zero 540 | if ( $per_page < 1 ) { 541 | $total_pages = 0; 542 | } else { 543 | $total_pages = ceil( $total_rows / $per_page ); 544 | } 545 | 546 | // Only show pagination when > 1 page 547 | if ( 1 >= $total_pages ) { 548 | return $output; 549 | } 550 | 551 | if ( 3 < $page ) { 552 | $output .= '«'; 553 | } 554 | 555 | if ( 1 < $page ) { 556 | $output .= ''; 557 | } 558 | 559 | if ( 1 < ( $page - 10 ) ) { 560 | $output .= '' . ( $page - 10 ) . ''; 561 | } 562 | 563 | for ( $i = 2; $i > 0; $i -- ) { 564 | if ( 0 < ( $page - $i ) ) { 565 | $output .= '' . ( $page - $i ) . ''; 566 | } 567 | } 568 | 569 | // Current page 570 | $output .= '' . $page . ''; 571 | 572 | for ( $i = 1; $i <= 2; $i ++ ) { 573 | if ( $total_pages >= ( $page + $i ) ) { 574 | $output .= '' . ( $page + $i ) . ''; 575 | } 576 | } 577 | 578 | if ( $total_pages > ( $page + 10 ) ) { 579 | $output .= '' . ( $page + 10 ) . ''; 580 | } 581 | 582 | if ( $page < $total_pages && $total_pages > 1 ) { 583 | $output .= ''; 584 | } 585 | 586 | if ( $total_pages > ( $page + 2 ) ) { 587 | $output .= '»'; 588 | } 589 | 590 | return $output; 591 | 592 | } 593 | 594 | /** 595 | * Initialize our API endpoint. 596 | * 597 | * @param \WP_JSON_Server $server 598 | */ 599 | public static function api_init( \WP_JSON_Server $server ) { 600 | 601 | new Talents( $server ); 602 | new Products( $server ); 603 | new Jobs( $server ); 604 | new Oembed_Provider( $server ); 605 | 606 | } 607 | 608 | /** 609 | * @return string The WP-API prefix. 610 | */ 611 | public static function api_url_prefix() { 612 | return 'api'; 613 | } 614 | 615 | } -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | , 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. --------------------------------------------------------------------------------