diff --git a/classes/class-wpcom-liveblog-entry.php b/classes/class-wpcom-liveblog-entry.php index 8a142d5b6..024a0a6e3 100644 --- a/classes/class-wpcom-liveblog-entry.php +++ b/classes/class-wpcom-liveblog-entry.php @@ -97,10 +97,6 @@ public function get_type() { return $this->type; } - public function get_author_name() { - return get_the_author_meta( 'display_name', $this->comment->user_id ); - } - /** * Get the GMT timestamp for the comment * diff --git a/classes/class-wpcom-liveblog-schema.php b/classes/class-wpcom-liveblog-schema.php deleted file mode 100644 index 189b853c2..000000000 --- a/classes/class-wpcom-liveblog-schema.php +++ /dev/null @@ -1,173 +0,0 @@ -query = new WPCOM_Liveblog_Entry_Query( $post_id, WPCOM_Liveblog::KEY ); - $this->post_id = $post_id; - - // store permalink because it's used in a loop @ convert_entry_to_schema_blog_posting - $this->permalink = get_permalink( $this->post_id ); - } - - - /** - * Generate the full schema HTML - * - * @return string - */ - public function render() { - - $schema = $this->generate_schema(); - - if ( ! is_array( $schema ) ) { - return ''; - } - - $output = ''; - $output .= ''; - - return $output; - } - - /** - * Generate an array of all the schema properties from liveblog updates - * - * @return array|mixed|void - */ - public function generate_schema() { - - $updates = (array) $this->get_live_blog_updates(); - $start_time = $this->get_start_time( $updates ); - $end_time = $this->get_end_time( $updates ); - - $schema = array( - "@context" => "http://schema.org", - "@type" => "LiveBlogPosting", - "url" => $this->permalink, - "name" => get_the_title( $this->post_id ), - "coverageStartTime" => $start_time, - "liveBlogUpdate" => $updates, - ); - - if ( ! empty( $end_time ) ) { - $schema['coverageEndTime'] = $end_time; - } - - /** - * Filter LiveBlogPosting schema - allow schema customization - * - * @param string $schema - an array of already generated schema data - * @param int $post_id - the post_id shcema is generated for - * @param WPCOM_Liveblog_Schema $this - current schema class instance for $post_id - */ - return apply_filters( 'liveblog_schema_liveblogposting', $schema, $this->post_id, $this ); - } - - /** - * Get all Liveblog entries and convert them to Schema BlogPosting - * - * @return array - */ - public function get_live_blog_updates() { - - // `get_all_entries_asc` may return null, cast to array: - $entries = (array) $this->query->get_all_entries_asc(); - - if ( empty( $entries ) ) { - return array(); - } - - return array_map( array( $this, 'convert_entry_to_schema_blog_posting' ), $entries ); - } - - - /** - * Get the coverage start time, based on the first entry - * - * @param $entries_asc - * - * @return string - */ - public function get_start_time( $entries_asc ) { - - if ( ! is_array( $entries_asc ) || empty( $entries_asc ) ) { - return ''; - } - - $first_value = array_shift( $entries_asc ); - - if ( empty( $first_value['datePublished'] ) ) { - return ''; - } - - return $first_value['datePublished']; - } - - /** - * Get the coverage end time, based on the last entry - * - * @param $entries_asc - * - * @return string - */ - public function get_end_time( $entries_asc ) { - - // Make sure entries exist, and - // Only show end time if the Liveblog has ended ( is archived ) - if ( ! is_array( $entries_asc ) || empty( $entries_asc ) || 'archive' !== WPCOM_Liveblog::get_liveblog_state() ) { - return ''; - } - - $latest_update = array_pop($entries_asc); - if ( ! isset( $latest_update['datePublished'] ) ) { - return ''; - } - - return $latest_update['datePublished']; - } - - /** - * Convert a Liveblog entry to Schema.org BlogPosting - * @url http://schema.org/BlogPosting - * - * @param WPCOM_Liveblog_Entry $entry - * - * @return array - */ - protected function convert_entry_to_schema_blog_posting( $entry ) { - - $dateTime = new DateTime(); - - return array( - "@type" => "BlogPosting", - // ID Format can be found in the DOM ".liveblog-feed > .liveblog-entry#id_**": - "url" => $this->permalink . '#id_' . $entry->get_id(), - "datePublished" => $dateTime->setTimeStamp( $entry->get_timestamp() )->format( DateTime::ISO8601 ), - // articleBody doesn't support HTML - remove any HTML from the content - "articleBody" => wp_strip_all_tags( $entry->get_content() ), - "author" => array( - "name" => $entry->get_author_name() - ), - ); - } -} diff --git a/liveblog.php b/liveblog.php index c7c0392bc..ebd49707c 100644 --- a/liveblog.php +++ b/liveblog.php @@ -137,7 +137,6 @@ private static function includes() { require( dirname( __FILE__ ) . '/classes/class-wpcom-liveblog-socketio-loader.php' ); require( dirname( __FILE__ ) . '/classes/class-wpcom-liveblog-entry-embed.php' ); require( dirname( __FILE__ ) . '/classes/class-wpcom-liveblog-entry-embed-sdks.php' ); - require( dirname( __FILE__ ) . '/classes/class-wpcom-liveblog-schema.php' ); if ( self::use_rest_api() ) { require( dirname( __FILE__ ) . '/classes/class-wpcom-liveblog-rest-api.php' ); @@ -1145,12 +1144,6 @@ public static function add_liveblog_to_content( $content ) { return $content; } - - if ( apply_filters( 'liveblog_enable_schema', true ) ) { - $schema = new WPCOM_Liveblog_Schema( self::$post_id ); - $content .= $schema->render(); - } - $liveblog_output = '
'; $liveblog_output = apply_filters( 'liveblog_add_to_content', $liveblog_output, $content, self::$post_id );