activitystrea.ms) Feeds * Author: Matthias Pfefferle * Author URI: https://notiz.blog * Version: 1.3.2 * License: MIT * License URI: https://opensource.org/licenses/MIT * Text Domain: activitystream-extension */ add_action( 'init', array( 'ActivityStreamExtensionPlugin', 'init' ) ); register_activation_hook( __FILE__, array( 'ActivityStreamExtensionPlugin', 'flush_rewrite_rules' ) ); register_deactivation_hook( __FILE__, array( 'ActivityStreamExtensionPlugin', 'flush_rewrite_rules' ) ); /** * ActivityStream Extension * * @author Matthias Pfefferle */ class ActivityStreamExtensionPlugin { /** * Init function */ public static function init() { require_once dirname( __FILE__ ) . '/includes/functions.php'; add_filter( 'query_vars', array( 'ActivityStreamExtensionPlugin', 'query_vars' ) ); add_filter( 'feed_content_type', array( 'ActivityStreamExtensionPlugin', 'feed_content_type' ), 10, 2 ); // add the as1 feed add_feed( 'as1', array( 'ActivityStreamExtensionPlugin', 'do_feed_as1' ) ); add_action( 'do_feed_as1', array( 'ActivityStreamExtensionPlugin', 'do_feed_as1' ), 10, 1 ); add_filter( 'as1_object_type', array( 'ActivityStreamExtensionPlugin', 'post_as1_object_type' ), 10, 2 ); // add the as2 feed add_feed( 'as2', array( 'ActivityStreamExtensionPlugin', 'do_feed_as2' ) ); add_action( 'do_feed_as2', array( 'ActivityStreamExtensionPlugin', 'do_feed_as2' ), 10, 1 ); add_filter( 'as2_object_type', array( 'ActivityStreamExtensionPlugin', 'post_as2_object_type' ), 10, 2 ); // push json feed add_filter( 'pshb_feed_urls', array( 'ActivityStreamExtensionPlugin', 'publish_to_hub' ) ); // extend core feeds with AS1 add_action( 'atom_ns', array( 'ActivityStreamExtensionPlugin', 'add_atom_activity_namespace' ) ); add_action( 'atom_entry', array( 'ActivityStreamExtensionPlugin', 'add_atom_activity_object' ) ); add_action( 'atom_entry', array( 'ActivityStreamExtensionPlugin', 'add_atom_enclosure' ) ); add_action( 'atom_author', array( 'ActivityStreamExtensionPlugin', 'add_atom_activity_author' ) ); // run before output add_action( 'comment_atom_ns', array( 'ActivityStreamExtensionPlugin', 'add_atom_activity_namespace' ) ); add_action( 'comment_atom_entry', array( 'ActivityStreamExtensionPlugin', 'add_comment_atom_activity_object' ) ); // discovery add_action( 'wp_head', array( 'ActivityStreamExtensionPlugin', 'add_html_header' ), 5 ); add_action( 'host_meta', array( 'ActivityStreamExtensionPlugin', 'add_host_meta_links' ) ); add_action( 'webfinger_user_data', array( 'ActivityStreamExtensionPlugin', 'add_webfinger_links' ), 10, 3 ); } /** * Add 'callback' as a valid query variables. * * @param array $vars * @return array */ public static function query_vars( $vars ) { $vars[] = 'callback'; $vars[] = 'feed'; $vars[] = 'pretty'; return $vars; } /** * Adds "as1" content-type * * @param string $content_type the default content-type * @param string $type the feed-type * @return string the as1 content-type */ public static function feed_content_type( $content_type, $type ) { if ( 'as1' == $type ) { return 'application/stream+json'; } if ( 'as2' == $type ) { return 'application/activity+json'; } return $content_type; } /** * Reset rewrite rules */ public static function flush_rewrite_rules() { global $wp_rewrite; $wp_rewrite->flush_rules(); } /** * Echos autodiscovery links */ public static function add_html_header() { // check if theme author want to display feed links if ( ! current_theme_supports( 'automatic-feed-links' ) ) { return; } ?> comment_count > 0 ) { ?> 'feed', 'type' => esc_attr( feed_content_type( 'as1' ) ), 'title' => esc_attr( __( 'Activity-Streams 1.0 Feed', 'activitystream_extension' ) ), 'href' => esc_url( get_feed_link( 'as1' ) ) ); $jrd['links'][] = array( 'rel' => 'feed', 'type' => esc_attr( feed_content_type( 'as1' ) ), 'title' => esc_attr( __( 'Activity-Streams 1.0 Comments Feed ', 'activitystream_extension' ) ), 'href' => esc_url( get_feed_link( 'comments_as1' ) ) ); $jrd['links'][] = array( 'rel' => 'feed', 'type' => esc_attr( feed_content_type( 'as2' ) ), 'title' => esc_attr( __( 'Activity-Streams 2.0 Feed', 'activitystream_extension' ) ), 'href' => esc_url( get_feed_link( 'as2' ) ) ); $jrd['links'][] = array( 'rel' => 'feed', 'type' => esc_attr( feed_content_type( 'as2' ) ), 'title' => esc_attr( __( 'Activity-Streams 2.0 Comments Feed ', 'activitystream_extension' ) ), 'href' => esc_url( get_feed_link( 'comments_as2' ) ) ); return $jrd; } /** * Add AS links to the webfinger file * * @param array $jrd the WebFinger JRD array * * @return array the filtered array */ public static function add_webfinger_links( $jrd, $acct, $user ) { $jrd['links'][] = array( 'rel' => 'feed', 'type' => esc_attr( feed_content_type( 'as1' ) ), 'title' => esc_attr( __( 'Activity-Streams 1.0 Feed', 'activitystream_extension' ) ), 'href' => esc_url( get_author_feed_link( $user->ID, 'as1' ) ) ); $jrd['links'][] = array( 'rel' => 'feed', 'type' => esc_attr( feed_content_type( 'as2' ) ), 'title' => esc_attr( __( 'Activity-Streams 2.0 Feed', 'activitystream_extension' ) ), 'href' => esc_url( get_author_feed_link( $user->ID, 'as2' ) ) ); return $jrd; } /** * Echos the activitystream namespace */ public static function add_atom_activity_namespace() { echo 'xmlns:activity="http://activitystrea.ms/spec/1.0/"'."\n"; } /** * Echos the activity verb and object for the wordpress entries */ public static function add_atom_activity_object() { /* * The object type of the current post in the Activity Streams 1 feed * * @param Object $comment_post The current post */ $object_type = apply_filters( 'as1_object_type', 'article', get_post() ); ?> http://activitystrea.ms/schema/1.0/post http://activitystrea.ms/schema/1.0/ <![CDATA[<?php the_title(); ?>]]> ]]> http://activitystrea.ms/schema/1.0/post http://activitystrea.ms/schema/1.0/comment ]]> http://activitystrea.ms/schema/1.0/article <![CDATA[<?php the_title(); ?>]]> ]]> http://activitystrea.ms/schema/1.0/person