Skip to content

Commit

Permalink
Merge 2.5.2 Fixes (#88)
Browse files Browse the repository at this point in the history
* Create new unified string function

* Refinements and adding of URL

* Improve Strings

* Remove Response Kind Function as No Longer in Use

* Improve settings descriptions

* Finish conversion to new string functions and refinements related.

* Enhance Micropub to Cover More of Post Kind Discovery

* Only Update Post Format on Initial Save Not Update

* Changed using site_url to rest_url due issues.

* Auto setting of Post Formats for Micropub

* Remove Stray Reference to Old Function

* Fixed issue found in testing.

* Bug Fixes

* Final Fixes for 2.5.2
  • Loading branch information
dshanske authored Apr 14, 2017
1 parent a59b045 commit e6d151b
Show file tree
Hide file tree
Showing 11 changed files with 863 additions and 599 deletions.
69 changes: 34 additions & 35 deletions includes/class-kind-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,80 +36,80 @@ public static function admin_init() {
'type' => 'array',
'description' => 'Kinds Enabled on This Site',
'show_in_rest' => true,
'default' => array( 'article', 'reply', 'bookmark' )
'default' => array( 'article', 'reply', 'bookmark' ),
);
register_setting( 'iwt_options', 'kind_termslist', $args );
$args = array(
'type' => 'string',
'description' => 'Default Kind',
'show_in_rest' => true,
'default' => 'note'
'default' => 'note',
);
register_setting( 'iwt_options', 'kind_default', $args );
$args = array(
'type' => 'boolean',
'description' => 'Rich Embed Support for Whitelisted Sites',
'show_in_rest' => true,
'default' => 1
'default' => 1,
);
register_setting( 'iwt_options', 'kind_embeds', $args );
$args = array(
'type' => 'boolean',
'description' => 'Disable Content Protection on Responses',
'show_in_rest' => true,
'default' => 0
'default' => 0,
);
register_setting( 'iwt_options', 'kind_protection', $args );
$args = array(
'type' => 'string',
'description' => 'KSES Content Protection on Responses',
'show_in_rest' => true,
'default' => str_replace( '},"',"},\r\n\"", wp_json_encode( wp_kses_allowed_html( 'post' ), JSON_PRETTY_PRINT ) )
'default' => str_replace( '},"',"},\r\n\"", wp_json_encode( wp_kses_allowed_html( 'post' ), JSON_PRETTY_PRINT ) ),
);
register_setting( 'iwt_options', 'kind_kses', $args );
add_settings_section(
'iwt-content',
__( 'Content Options',
'indieweb-post-kinds' ),
array( 'Kind_Config', 'options_callback' ),
'iwt_options'
add_settings_section(
'iwt-content',
__( 'Content Options',
'indieweb-post-kinds' ),
array( 'Kind_Config', 'options_callback' ),
'iwt_options'
);
add_settings_field(
'termslist',
add_settings_field(
'termslist',
__( 'Select All Kinds You Wish to Use', 'indieweb-post-kinds' ),
array( 'Kind_Config', 'termcheck_callback' ),
'iwt_options',
'iwt-content'
'iwt-content'
);
add_settings_field(
'defaultkind',
add_settings_field(
'defaultkind',
__( 'Default Kind', 'indieweb-post-kinds' ),
array( 'Kind_Config', 'defaultkind_callback' ),
'iwt_options',
'iwt-content'
);

add_settings_field(
'embeds',
__( 'Add Rich Embed Support for Whitelisted Sites', 'indieweb-post-kinds' ),
array( 'Kind_Config', 'checkbox_callback' ),
'iwt_options', 'iwt-content' , array( 'name' => 'kind_embeds' )
add_settings_field(
'embeds',
__( 'Use Rich Embed Support for Responses to Whitelisted Sites', 'indieweb-post-kinds' ),
array( 'Kind_Config', 'checkbox_callback' ),
'iwt_options', 'iwt-content' , array( 'name' => 'kind_embeds' )
);

add_settings_field(
'protection',
__( 'Disable Content Protection on Responses', 'indieweb-post-kinds' ),
add_settings_field(
'protection',
__( 'Disable KSES Content Protection on Responses(Advanced Feature)', 'indieweb-post-kinds' ),
array( 'Kind_Config', 'checkbox_callback' ),
'iwt_options',
'iwt-content',
array( 'name' => 'kind_protection' )
);
if ( 1 == get_option( 'kind_protection' ) ) {
add_settings_field(
'contentelements',
__( 'Response Content Allowed Html Elements', 'indieweb-post-kinds' ) . ' <a href="http://codex.wordpress.org/Function_Reference/wp_kses">*</a>',
add_settings_field(
'contentelements',
__( 'Response Content Allowed Html Elements', 'indieweb-post-kinds' ) . ' <a href="http://codex.wordpress.org/Function_Reference/wp_kses">*</a>',
array( 'Kind_Config', 'textbox_callback' ),
'iwt_options',
'iwt_options',
'iwt-content',
array( 'name' => 'kind_kses' )
);
Expand Down Expand Up @@ -194,15 +194,15 @@ public static function textbox_callback( array $args ) {
* @access public
*/
public static function termcheck_callback() {
$terms = Kind_Taxonomy::get_strings();
$terms = Kind_Taxonomy::get_kind_info( 'all', 'all' );
// Hide these terms until ready for use for now.
$hide = array( 'note', 'weather', 'exercise', 'travel', 'itinerary', 'tag', 'follow', 'drink', 'eat', 'trip', 'checkin', 'recipe', 'mood' );
foreach ( $hide as $hid ) {
unset( $terms[ $hid ] );
}
$termslist = get_option('kind_termslist');
$termslist = get_option( 'kind_termslist' );
foreach ( $terms as $key => $value ) {
echo "<input name='kind_termslist[]' type='checkbox' value='" . $key . "' " . checked( in_array( $key, $termslist ), true, false ) . ' />' . $value . '<br />';
echo "<input name='kind_termslist[]' type='checkbox' value='" . $key . "' " . checked( in_array( $key, $termslist ), true, false ) . ' /><strong>' . $value['singular_name'] . '</strong> - ' . $value['description'] . '<br />';
}
}

Expand All @@ -213,14 +213,13 @@ public static function termcheck_callback() {
* @access public
*/
public static function defaultkind_callback() {
$terms = get_option('kind_termslist');
$terms = get_option( 'kind_termslist' );
$terms[] = 'note';
$strings = Kind_Taxonomy::get_strings();

$defaultkind = get_option('kind_default');
$defaultkind = get_option( 'kind_default' );

foreach ( $terms as $term ) {
echo '<input id="kind_default" name="kind_default" type="radio" value="' . $term . '" '. checked( $term, $defaultkind, false ) . ' />' . $strings[$term] . '<br />';
echo '<input id="kind_default" name="kind_default" type="radio" value="' . $term . '" '. checked( $term, $defaultkind, false ) . ' />' . Kind_Taxonomy::get_kind_info( $term, 'singular_name' ) . '<br />';
}
}

Expand Down
36 changes: 17 additions & 19 deletions includes/class-kind-meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public static function sanitize_content( $value ) {
if ( 1 == get_option( 'kind_protection' ) ) {
$allowed = json_decode( get_option( 'kind_kses' ), true );
}
return wp_kses( ( string ) $value , $allowed );
return wp_kses( $value , $allowed );
}

public static function sanitize_text( $value ) {
Expand All @@ -168,17 +168,17 @@ public static function sanitize_text( $value ) {
public function build_meta( $raw ) {
$raw = apply_filters( 'kind_build_meta', $raw );
$kind = get_post_kind_slug( $this->post );
$property = Kind_Taxonomy::get_kind_info( $kind, 'property' );
if ( isset( $raw['url'] ) ) {
/**
* Allows additional changes to the kind data after parsing.
*
* @param array $raw An array of properties.
*/
$map = array_filter( Kind_Taxonomy::get_kind_properties() );
if ( isset( $kind ) ) {
if ( array_key_exists( $kind, $map ) ) {
$this->meta[ $map[ $kind ] ] = $raw['url'];
unset( $raw['url'] );
if ( ! empty( $property ) ) {
$this->meta[ $property ] = $raw['url'];
unset( $raw['url'] );
}
}
}
Expand All @@ -195,7 +195,7 @@ public function get_url( ) {
return false;
}
$kind = get_post_kind_slug( $this->post );
$map = Kind_Taxonomy::get_kind_properties();
$property = Kind_Taxonomy::get_kind_info( $kind, 'property' );
if ( array_key_exists( 'cite', $this->meta ) ) {
if ( array_key_exists( 'url', $this->meta['cite'] ) ) {
return $this->meta['cite']['url'];
Expand All @@ -204,14 +204,14 @@ public function get_url( ) {
if ( ! $kind ) {
return false;
}
if ( array_key_exists( $kind, $map ) ) {
if ( array_key_exists( $map[ $kind ], $this->meta ) ) {
if ( is_string( $this->meta[ $map[ $kind ] ] ) ) {
return $this->meta[ $map[ $kind ] ];
if ( ! empty( $property ) ) {
if ( array_key_exists( $property, $this->meta ) ) {
if ( is_string( $this->meta[ $property ] ) ) {
return $this->meta[ $property ];
}
if ( is_array( $this->meta[ $property ] ) ) {
return $this->meta[ $property ][0];
}
if ( is_array( $this->meta[ $map[ $kind ] ] ) ) {
return $this->meta[ $map [ $kind ] ][0];
}
}
}
return false;
Expand All @@ -228,11 +228,9 @@ public function set_url( $url ) {
}
$url = self::sanitize_text( $url );
$kind = get_post_kind_slug( $this->post );
$map = array_diff( Kind_Taxonomy::get_kind_properties(), array( '' ) );
if ( $kind ) {
if ( array_key_exists( $kind, $map ) ) {
$this->meta[ $map[ $kind ] ] = array( $url );
}
$property = Kind_Taxonomy::get_kind_info( $kind, 'property' );
if ( ! empty ( $property ) ) {
$this->meta[ $property ] = array( $url );
}
if ( ! array_key_exists( 'cite', $this->meta ) ) {
$this->meta['url'] = $url;
Expand Down Expand Up @@ -436,7 +434,7 @@ public function get( $key ) {
}

public function set( $key, $value) {
$this->meta[$key] = self::sanitize_text( $value );
$this->meta[ $key ] = self::sanitize_text( $value );
}

public function del( $key ) {
Expand Down
141 changes: 141 additions & 0 deletions includes/class-kind-plugins.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
<?php

/**
* Post Kind Plugins Class
*
* Custom Functions for Specific Other Pugins
*
* @package Post Kinds
*/
class Kind_Plugins {
public static function init() {
// Set Post Kind for Micropub Inputs.
add_action( 'after_micropub', array( 'Kind_Plugins', 'micropub_set_kind' ), 10, 2 );
add_action( 'after_micropub', array( 'Kind_Plugins', 'post_formats' ), 11, 2 );
// Override Post Type in Semantic Linkbacks.
add_filter( 'semantic_linkbacks_post_type', array( 'Kind_Plugins', 'semantic_post_type' ), 11, 2 );

// Remove the Automatic Post Generation that the Micropub Plugin Offers
remove_filter( 'before_micropub', array( 'Micropub', 'generate_post_content' ) );

}

// Replaces need for Replacing the Entire Excerpt
public static function semantic_post_type($post_type, $post_id) {
return _x( 'this', 'indieweb-post-kinds' ) . ' ' . strtolower( get_post_kind( $post_id ) );
}

// Replacement for the Semantic Linkbacks Comment Excerpt
public static function comment_text_excerpt($text, $comment = null, $args = array()) {
// only change text for pingbacks/trackbacks/webmentions
if ( ! $comment || '' === $comment->comment_type || ! get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_canonical', true ) ) {
return $text;
}
// check comment type
$comment_type = get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_type', true );
if ( ! $comment_type || ! in_array( $comment_type, array_keys( SemanticLinkbacksPlugin::get_comment_type_strings() ) ) ) {
$comment_type = 'mention';
}
$_kind = get_the_terms( $comment->comment_post_ID, 'kind' );
if ( ! empty( $_kind ) ) {
$kind = array_shift( $_kind );
$kindstrings = self::get_strings();
$post_format = $kindstrings[ $kind->slug ];
} else {
$post_format = get_post_format( $comment->comment_post_ID );
// replace "standard" with "Article"
if ( ! $post_format || 'standard' === $post_format ) {
$post_format = 'Article';
} else {
$post_formatstrings = get_post_format_strings();
// get the "nice" name
$post_format = $post_formatstrings[ $post_format ];
}
}
// generate the verb, for example "mentioned" or "liked"
$comment_type_excerpts = SemanticLinkbacksPlugin::get_comment_type_excerpts();
// get URL canonical url...
$url = get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_canonical', true );
// ...or fall back to source
if ( ! $url ) {
$url = get_comment_meta( $comment->comment_ID, 'semantic_linkbacks_source', true );
}
// parse host
$host = parse_url( $url, PHP_URL_HOST );
// strip leading www, if any
$host = preg_replace( '/^www\./', '', $host );
// generate output
$text = sprintf( $comment_type_excerpts[ $comment_type ], get_comment_author_link( $comment->comment_ID ), 'this ' . $post_format, $url, $host );
return apply_filters( 'semantic_linkbacks_excerpt', $text );
}

/**
* Take mf2 properties and set a post kind
*
* @param array $input Micropub Request in JSON
* @param array $wp_args Arguments passed to insert or update posts
*/

public static function micropub_set_kind( $input, $wp_args ) {
// Only continue if create or update
if ( ! $wp_args ) {
return;
}
if ( isset( $input['properties']['rsvp'] ) ) {
set_post_kind( $wp_args['ID'], 'rsvp' );
return;
}
if ( isset( $input['properties']['in-reply-to'] ) ) {
set_post_kind( $wp_args['ID'], 'reply' );
return;
}

if ( isset( $input['properties']['repost-of'] ) ) {
set_post_kind( $wp_args['ID'], 'repost' );
return;
}

if ( isset( $input['properties']['like-of'] ) ) {
set_post_kind( $wp_args['ID'], 'like' );
return;
}
if ( isset( $input['properties']['photo'] ) ) {
set_post_kind( $wp_args['ID'], 'photo' );
return;
}

if ( isset( $input['properties']['bookmark-of'] ) || isset( $input['properties']['bookmark'] ) ) {
set_post_kind( $wp_args['ID'], 'bookmark' );
return;
}

// This basically adds Teacup support
if ( isset( $input['properties']['p3k-food'] ) ) {
if ( isset( $input['properties']['p3k-type'] ) ) {
if ( 'drink' === $input['properties']['p3k-type'] ) {
set_post_kind( $wp_args['ID'], 'drink' );
return;
}
set_post_kind( $wp_args['ID'], 'eat' );
return;
}
}
if ( ! empty( $input['properties']['name'] ) ) {
$name = trim( $input['properties']['name'] );
$content = trim( $input['properties']['content']);
if ( 0 !== strpos( $content, $name ) ) {
set_post_kind( $wp_args['ID'], 'article' );
return;
}
}
set_post_kind( $wp_args['ID'], 'note' );
}

public static function post_formats( $input, $wp_args ) {
$kind = get_post_kind_slug( $wp_args['ID'] );
set_post_format( $wp_args['ID'], Kind_Taxonomy::get_kind_info( $kind, 'property' ) );
}

} // End Class Kind_Plugins

?>
2 changes: 1 addition & 1 deletion includes/class-kind-tabmeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static function enqueue_admin_scripts() {
wp_localize_script( 'kindmeta-response', 'rest_object',
array(
'api_nonce' => wp_create_nonce( 'wp_rest' ),
'api_url' => site_url('/wp-json/link-preview/1.0/'),
'api_url' => rest_url('/link-preview/1.0/'),
'link_preview_success_message' => __( 'Your URL has been successfully retrieved and parsed', 'indieweb-post-kinds' )
)
);
Expand Down
Loading

0 comments on commit e6d151b

Please sign in to comment.