parent
e3dcf6cc91
commit
03f6da019d
5 changed files with 68 additions and 3 deletions
|
@ -3,7 +3,7 @@
|
||||||
**Donate link:** https://notiz.blog/donate/
|
**Donate link:** https://notiz.blog/donate/
|
||||||
**Tags:** OStatus, fediverse, activitypub, activitystream
|
**Tags:** OStatus, fediverse, activitypub, activitystream
|
||||||
**Requires at least:** 4.7
|
**Requires at least:** 4.7
|
||||||
**Tested up to:** 5.0.2
|
**Tested up to:** 5.0.3
|
||||||
**Stable tag:** 0.2.1
|
**Stable tag:** 0.2.1
|
||||||
**Requires PHP:** 5.6
|
**Requires PHP:** 5.6
|
||||||
**License:** MIT
|
**License:** MIT
|
||||||
|
@ -55,6 +55,10 @@ To implement:
|
||||||
|
|
||||||
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
|
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
|
||||||
|
|
||||||
|
### 0.3.0 ###
|
||||||
|
|
||||||
|
* basic hashtag support
|
||||||
|
|
||||||
### 0.2.1 ###
|
### 0.2.1 ###
|
||||||
|
|
||||||
* customizable backlink (permalink or shorturl)
|
* customizable backlink (permalink or shorturl)
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
* Initialize plugin
|
* Initialize plugin
|
||||||
*/
|
*/
|
||||||
function activitypub_init() {
|
function activitypub_init() {
|
||||||
|
defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(^|\s|>)#([^\s<>]+)\b' );
|
||||||
|
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-signature.php';
|
require_once dirname( __FILE__ ) . '/includes/class-activitypub-signature.php';
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-post.php';
|
require_once dirname( __FILE__ ) . '/includes/class-activitypub-post.php';
|
||||||
require_once dirname( __FILE__ ) . '/includes/class-activitypub-activity.php';
|
require_once dirname( __FILE__ ) . '/includes/class-activitypub-activity.php';
|
||||||
|
@ -65,6 +67,10 @@ function activitypub_init() {
|
||||||
add_action( 'admin_menu', array( 'Activitypub_Admin', 'admin_menu' ) );
|
add_action( 'admin_menu', array( 'Activitypub_Admin', 'admin_menu' ) );
|
||||||
add_action( 'admin_init', array( 'Activitypub_Admin', 'register_settings' ) );
|
add_action( 'admin_init', array( 'Activitypub_Admin', 'register_settings' ) );
|
||||||
add_action( 'show_user_profile', array( 'Activitypub_Admin', 'add_fediverse_profile' ) );
|
add_action( 'show_user_profile', array( 'Activitypub_Admin', 'add_fediverse_profile' ) );
|
||||||
|
|
||||||
|
require_once dirname( __FILE__ ) . '/includes/class-activitypub-hashtag.php';
|
||||||
|
add_filter( 'wp_insert_post', array( 'Activitypub_Hashtag', 'insert_post' ), 99, 2 );
|
||||||
|
add_filter( 'the_content', array( 'Activitypub_Hashtag', 'the_content' ), 99, 2 );
|
||||||
}
|
}
|
||||||
add_action( 'plugins_loaded', 'activitypub_init' );
|
add_action( 'plugins_loaded', 'activitypub_init' );
|
||||||
|
|
||||||
|
|
51
includes/class-activitypub-hashtag.php
Normal file
51
includes/class-activitypub-hashtag.php
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* ActivityPub Hashtag Class
|
||||||
|
*/
|
||||||
|
class Activitypub_Hashtag {
|
||||||
|
/**
|
||||||
|
* Filter to save #tags as real WordPress tags
|
||||||
|
*
|
||||||
|
* @param int $id the rev-id
|
||||||
|
* @param array $data the post-data as array
|
||||||
|
*/
|
||||||
|
public static function insert_post( $id, $data ) {
|
||||||
|
if ( preg_match_all( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', $data->post_content, $match ) ) {
|
||||||
|
$tags = implode( ', ', $match[2] );
|
||||||
|
|
||||||
|
wp_add_post_tags( $data->post_parent, $tags );
|
||||||
|
}
|
||||||
|
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter to replace the #tags in the content with links
|
||||||
|
*
|
||||||
|
* @param string $the_content the post-content
|
||||||
|
*/
|
||||||
|
public static function the_content( $the_content ) {
|
||||||
|
$the_content = preg_replace_callback( '/' . ACTIVITYPUB_HASHTAGS_REGEXP . '/i', array( 'Activitypub_Hashtag', 'replace_with_links' ), $the_content );
|
||||||
|
|
||||||
|
return $the_content;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A callback for preg_replace to build the term links
|
||||||
|
*
|
||||||
|
* @param array $result the preg_match results
|
||||||
|
* @return string the final string
|
||||||
|
*/
|
||||||
|
public static function replace_with_links( $result ) {
|
||||||
|
$tag = $result[2];
|
||||||
|
$space = $result[1];
|
||||||
|
$tag_object = get_term_by( 'name', $result[2], 'post_tag' );
|
||||||
|
|
||||||
|
if ( $tag_object ) {
|
||||||
|
$link = get_term_link( $tag_object, 'post_tag' );
|
||||||
|
return "$space<a href='$link' rel='tag'>#$tag</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $space . '#' . $tag;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ msgid ""
|
||||||
msgstr ""
|
msgstr ""
|
||||||
"Project-Id-Version: ActivityPub 0.2.1\n"
|
"Project-Id-Version: ActivityPub 0.2.1\n"
|
||||||
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
|
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/activitypub\n"
|
||||||
"POT-Creation-Date: 2019-01-16 20:52:51+00:00\n"
|
"POT-Creation-Date: 2019-01-22 19:51:00+00:00\n"
|
||||||
"MIME-Version: 1.0\n"
|
"MIME-Version: 1.0\n"
|
||||||
"Content-Type: text/plain; charset=utf-8\n"
|
"Content-Type: text/plain; charset=utf-8\n"
|
||||||
"Content-Transfer-Encoding: 8bit\n"
|
"Content-Transfer-Encoding: 8bit\n"
|
||||||
|
|
|
@ -3,7 +3,7 @@ Contributors: pfefferle
|
||||||
Donate link: https://notiz.blog/donate/
|
Donate link: https://notiz.blog/donate/
|
||||||
Tags: OStatus, fediverse, activitypub, activitystream
|
Tags: OStatus, fediverse, activitypub, activitystream
|
||||||
Requires at least: 4.7
|
Requires at least: 4.7
|
||||||
Tested up to: 5.0.2
|
Tested up to: 5.0.3
|
||||||
Stable tag: 0.2.1
|
Stable tag: 0.2.1
|
||||||
Requires PHP: 5.6
|
Requires PHP: 5.6
|
||||||
License: MIT
|
License: MIT
|
||||||
|
@ -55,6 +55,10 @@ To implement:
|
||||||
|
|
||||||
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
|
Project maintained on github at [pfefferle/wordpress-activitypub](https://github.com/pfefferle/wordpress-activitypub).
|
||||||
|
|
||||||
|
= 0.3.0 =
|
||||||
|
|
||||||
|
* basic hashtag support
|
||||||
|
|
||||||
= 0.2.1 =
|
= 0.2.1 =
|
||||||
|
|
||||||
* customizable backlink (permalink or shorturl)
|
* customizable backlink (permalink or shorturl)
|
||||||
|
|
Loading…
Reference in a new issue