id = absint( $company_id ); // allow a publisher to disable Schema.org markup by attaching to this filter $this->schema_org = (bool) apply_filters( 'angellist_schema_org', true, $this->id ); // allow override of default browsing context $browsing_context = apply_filters( 'angellist_browsing_context', '_blank', $this->id ); // limit browsing context to special keywords if ( ! in_array( $browsing_context, array( '', '_blank', '_self', '_parent', '_top' ), true ) ) $browsing_context = '_blank'; if ( $browsing_context ) $this->anchor_extra = ' target="' . $browsing_context . '"'; else $this->anchor_extra = ''; unset( $browsing_context ); // check for cached version of company info before we request data from AngelList $this->cache_key = $this->generate_cache_key(); $html = get_transient( $this->cache_key ); if ( empty( $html ) ) $this->populate_data(); else $this->html = $html; } /** * Request company data from AngelList. * Populate data in the class * * @since 1.0 */ private function populate_data() { if ( ! class_exists( 'AngelList_API' ) ) require_once( dirname( dirname( __FILE__ ) ) . '/api.php' ); $company = AngelList_API::get_company( $this->id ); if ( empty( $company ) ) return; // are we sharing a secret? if ( isset( $company->hidden ) && $company->hidden === true ) return; // we should at least be able to reference a startup by its name if ( isset( $company->name ) ) $this->name = trim( $company->name ); else return; // is the startup participating in AngelList and has claimed their profile? if ( isset( $company->community_profile ) && $company->community_profile === false ) $this->claimed = true; else $this->claimed = false; if ( isset( $company->company_url ) ) { $url = esc_url( $company->company_url, array( 'http', 'https' ) ); if ( $url ) $this->url = $url; unset( $url ); } if ( isset( $company->angellist_url ) ) { $url = esc_url( $company->angellist_url, array( 'http', 'https' ) ); if ( $url ) $this->profile_url = $url; unset( $url ); } if ( isset( $company->thumb_url ) && $company->thumb_url !== AngelList_API::DEFAULT_IMAGE ) { $url = AngelList_API::filter_static_asset_url( $company->thumb_url ); if ( $url ) { $image = new stdClass(); $image->url = $url; $image->width = $image->height = 100; $this->thumbnail = $image; unset( $image ); } unset( $url ); } if ( isset( $company->logo_url ) && $company->thumb_url !== AngelList_API::DEFAULT_IMAGE ) { $url = AngelList_API::filter_static_asset_url( $company->logo_url ); if ( $url ) $this->logo_url = $url; unset( $url ); } if ( isset( $company->high_concept ) ) { $concept = trim( $company->high_concept ); if ( $concept ) $this->concept = $concept; unset( $concept ); } if ( isset( $company->product_desc ) ) { $description = trim( $company->product_desc ); if ( $description ) $this->description = $description; unset( $description ); } // first location with all the data we want is considered the HQ and displayed if ( isset( $company->locations ) && is_array( $company->locations ) ) { // iterate until we find a URL + name foreach ( $company->locations as $location ) { if ( ! ( isset( $location->angellist_url ) && isset( $location->display_name ) ) ) continue; $url = esc_url( $location->angellist_url, array( 'http', 'https' ) ); if ( ! $url ) continue; $hq_location = new stdClass(); $hq_location->url = $url; unset( $url ); $hq_location->name = trim( $location->display_name ); $this->location = $hq_location; unset( $hq_location ); break; } } // first market with the data we want is considered the main market if ( isset( $company->markets ) && is_array( $company->markets ) ) { // iterate until we find a URL + name foreach ( $company->markets as $tag ) { if ( ! ( isset( $tag->angellist_url ) && isset( $tag->display_name ) ) ) continue; $url = esc_url( $tag->angellist_url, array( 'https', 'http' ) ); if ( ! $url ) continue; $main_tag = new stdClass(); $main_tag->url = $url; unset( $url ); $main_tag->name = trim( $tag->display_name ); $this->tag = $main_tag; unset( $main_tag ); break; } } } /** * Request a list of people associated with the company from the AngelList API, up to limit (default 3) * * @since 1.1 * @param int $limit maximum amount of people * @return string HTML list of people */ private function people( $limit = 3 ) { // check for garbage if ( ! is_int( $limit ) || $limit < 1 ) $limit = 3; if ( ! class_exists( 'AngelList_API' ) ) require_once( dirname( dirname( __FILE__ ) ) . '/api.php' ); $people = AngelList_API::get_roles_by_company( $this->id ); if ( ! is_array( $people ) || empty( $people ) ) return ''; if ( ! class_exists( 'AngelList_Person' ) ) require_once( dirname( __FILE__ ) . '/person.php' ); $founders = array(); $everyone_else = array(); foreach ( $people as $person ) { // only care about confirmed, active people if ( ! ( isset( $person->role ) && isset( $person->confirmed ) && $person->confirmed === true && ! isset( $person->ended_at ) ) ) continue; if ( $person->role === 'founder' ) $founders[] = $person; else if ( ! in_array( $person->role, array( 'referrer', 'attorney' ), true ) ) $everyone_else[] = $person; } unset( $people ); $top_people = array(); // founders get priority treatment if ( ! empty( $founders ) ) $top_people = AngelList_Person::order_by_follower_count( $founders, $limit ); $people_count = count( $top_people ); if ( $people_count < $limit && ! empty( $everyone_else ) ) $top_people = array_merge( $top_people, AngelList_Person::order_by_follower_count( $everyone_else, $limit - $people_count ) ); // this should not happen. just in case if ( empty( $top_people ) ) return ''; $people_html = ''; foreach ( $top_people as $person_data ) { $person = new AngelList_Person( $person_data ); if ( ! ( isset( $person->name ) && isset( $person->role ) ) ) continue; $people_html .= $person->render( $this->schema_org, $this->anchor_extra ); } if ( $people_html ) return '
, etc $paragraphs = explode( "\n\n", $this->description ); array_walk( $paragraphs, 'esc_html' ); $html .= '
' . implode( '
', $paragraphs ) . '