Skip to content

Commit

Permalink
Link Preview Branch Merge (#75)
Browse files Browse the repository at this point in the history
* Introduce New Parse This Class as Part of Link Preview Refactor

* Refactoring into New Configuration

* Switch from admin-ajax to REST API ajax

* Add nonce and pass rest URL

* Improve the Interface

* Final Mockup of Post Properties UI Changes - Need to Refactor save and retrieve next

* Switch to function to generate all fields

* Fix Saving of Settings including new ones

* Store URL as array to match Micropub but only store single value regardless

* Fix Duration Calculation

* Document work so far in README

* Begin Switching to More Conventional Templating using Output Buffering

* If summary equals name unset name

* Remove Facebook Manual Embed as WordPress now supports it as of 4.7

* Rich Embed Feature will only embed whitelisted sites by default if enabled

* Set Post Format based on Post Kind

* Final Cleanup Before Pause for Testing

* Fix tags and use semicolon separated over line separated

* Adjust appearance of form boxes

* Settings redo

* Update help section

* Update Mood SVG and accessibility test

* Fix Issues with Mood SVG that Blanked All Icons in Sprite

* Cleanup before merge
  • Loading branch information
dshanske authored Mar 5, 2017
1 parent 14a011b commit 1d1e8b1
Show file tree
Hide file tree
Showing 29 changed files with 1,941 additions and 1,614 deletions.
201 changes: 92 additions & 109 deletions includes/class-kind-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,6 @@
* @package Post Kinds
*/
class Kind_Config {
public static function Defaults() {
return array(
'embeds' => '0',
'disableformats' => '0',
'protection' => '0',
'contentelements' => '',
'defaultkind' => 'article',
'termslist' => array( 'article', 'reply', 'bookmark' ),
'themecompat' => '0',
);

}

/**
* Function to Initialize the Configuration.
Expand All @@ -46,12 +34,39 @@ public static function init() {
public static function admin_init() {
$args = array(
'type' => 'array',
'description' => 'Post Kind Options',
'description' => 'Kinds Enabled on This Site',
'show_in_rest' => true,
'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'
);
register_setting( 'iwt_options', 'kind_default', $args );
$args = array(
'type' => 'boolean',
'description' => 'Rich Embed Support for Whitelisted Sites',
'show_in_rest' => true,
'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
);
register_setting( 'iwt_options', 'kind_protection', $args );
$args = array(
'type' => 'string',
'description' => 'KSES Content Protection on Responses',
'show_in_rest' => true,
'default' => self::Defaults(),
'default' => str_replace( '},"',"},\r\n\"", wp_json_encode( wp_kses_allowed_html( 'post' ), JSON_PRETTY_PRINT ) )
);
register_setting( 'iwt_options', 'iwt_options', $args );
$options = get_option( 'iwt_options' );
register_setting( 'iwt_options', 'kind_kses', $args );
add_settings_section(
'iwt-content',
__( 'Content Options',
Expand All @@ -60,59 +75,45 @@ public static function admin_init() {
'iwt_options'
);
add_settings_field(
'embeds',
__( 'Add Rich Embed Support for Facebook, Google Plus, Instagram, etc', 'indieweb-post-kinds' ),
array( 'Kind_Config', 'checkbox_callback' ),
'iwt_options', 'iwt-content' , array( 'name' => 'embeds' )
'termslist',
__( 'Select All Kinds You Wish to Use', 'indieweb-post-kinds' ),
array( 'Kind_Config', 'termcheck_callback' ),
'iwt_options',
'iwt-content'
);
add_settings_field( 'themecompat',
__( 'Extra Styling for Themes That May Not Support Post Kinds. Includes hiding of titles on kinds that do not usually have an explicit title.', 'indieweb-post-kinds' ),
array( 'Kind_Config', 'checkbox_callback' ),
'iwt_options',
'iwt-content' ,
array( 'name' => 'themecompat' )
add_settings_field(
'defaultkind',
__( 'Default Kind', 'indieweb-post-kinds' ),
array( 'Kind_Config', 'defaultkind_callback' ),
'iwt_options',
'iwt-content'
);

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

add_settings_field(
'protection',
__( 'Disable Content Protection on Responses', 'indieweb-post-kinds' ),
array( 'Kind_Config', 'checkbox_callback' ),
'iwt_options',
'iwt-content',
array( 'name' => 'protection' )
array( 'name' => 'kind_protection' )
);
if ( array_key_exists( 'protection', $options ) && 1 === $options['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>',
array( 'Kind_Config', 'textbox_callback' ),
'iwt_options',
'iwt-content',
array( 'name' => 'contentelements' )
array( 'name' => 'kind_kses' )
);
}
add_settings_field(
'termslist',
__( 'Select All Kinds You Wish to Use', 'indieweb-post-kinds' ),
array( 'Kind_Config', 'termlist_callback' ),
'iwt_options',
'iwt-content'
);
add_settings_field(
'defaultkind',
__( 'Default Kind', 'indieweb-post-kinds' ),
array( 'Kind_Config', 'defaultkind_callback' ),
'iwt_options',
'iwt-content'
);
// Add Query Var to Admin
add_filter( 'query_vars', array( 'Kind_Config', 'query_var' ) );

Expand Down Expand Up @@ -164,11 +165,10 @@ public static function options_callback() {
* @type string $name Checkbox Name.
*/
public static function checkbox_callback( array $args ) {
$options = get_option( 'iwt_options', self::Defaults() );
$name = $args['name'];
$checked = ifset( $options[ $name ] );
echo "<input name='iwt_options[" . esc_html( $name ) . "]' type='hidden' value='0' />";
echo "<input name='iwt_options[" . esc_html( $name ) . "]' type='checkbox' value='1' " . checked( 1, $checked, false ) . ' /> ';
$option = get_option( $args['name'] );
$checked = ifset( $option );
echo "<input name='" . $args['name'] . "' type='hidden' value='0' />";
echo "<input name='" . $args['name'] . "' type='checkbox' value='1' " . checked( 1, $checked, false ) . ' /> ';
}

/**
Expand All @@ -181,60 +181,47 @@ public static function checkbox_callback( array $args ) {
* @type string $name Textbox Name.
*/
public static function textbox_callback( array $args ) {
$options = get_option( 'iwt_options', self::Defaults() );
$name = $args['name'];
$val = '';
if ( 'contentelements' === $name && ! array_key_exists( 'contentelements', $options ) ) {
$val = str_replace( '},"',"},\r\n\"", wp_json_encode( wp_kses_allowed_html( 'post' ), JSON_PRETTY_PRINT ) );
} else {
$val = $options[ $name ];
$option = get_option( $args['name'] );
if ( is_array( $option ) ) {
$option = print_r( $option, true );
}
echo "<textarea rows='10' cols='50' class='large-text code' name='iwt_options[" . esc_html( $name ) . "]'>". esc_textarea( print_r( $val,true ) ) . '</textarea> ';
echo "<textarea rows='10' cols='50' class='large-text code' name='" . $args['name'] . "'>". $option . '</textarea> ';
}

/**
* Generate a Term List.
*
* @access public
*/
public static function termlist_callback() {
$options = get_option( 'iwt_options', self::Defaults() );
public static function termcheck_callback() {
$terms = Kind_Taxonomy::get_strings();
// Hide these terms until ready for use for now.
$hide = array( 'note', 'weather', 'exercise', 'travel', 'rsvp', 'tag', 'follow', 'drink', 'eat' );
// Hide checkin option unless Simple Location is active.
if ( ! class_exists( 'loc_config' ) ) {
$hide[] = 'checkin';
}
$hide = array( 'note', 'weather', 'exercise', 'travel', 'itinerary', 'tag', 'follow', 'drink', 'eat', 'trip', 'checkin', 'recipe', 'mood' );
foreach ( $hide as $hid ) {
unset( $terms[ $hid ] );
}
$termslist = $options['termslist'];
echo '<select id="termslist" name="iwt_options[termslist][]" multiple>';
$termslist = get_option('kind_termslist');
foreach ( $terms as $key => $value ) {
echo '<option value="' . $key . '" '. selected( in_array( $key, $termslist ) ) . '>' . $value . '</option>';
echo "<input name='kind_termslist[]' type='checkbox' value='" . $key . "' " . checked( in_array( $key, $termslist ), true, false ) . ' />' . $value . '<br />';
}
echo '</select>';
}


/**
* Generate a Term List.
*
* @access public
*/
public static function defaultkind_callback() {
$options = get_option( 'iwt_options', self::Defaults() );
$terms = $options['termslist'];
$terms = get_option('kind_termslist');
$terms[] = 'note';
$strings = Kind_Taxonomy::get_strings();

$defaultkind = $options['defaultkind'];
$defaultkind = get_option('kind_default');

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


Expand All @@ -258,41 +245,37 @@ public static function options_form() {
echo '</form></div>';
}

/**
* Disable Post Formats.
*
* @access public
*/
public static function remove_post_formats() {
$options = get_option( 'iwt_option', self::Defaults() );
if ( 1 === ifset( $options['disableformats'] ) ) { remove_theme_support( 'post-formats' ); }
}

public static function add_post_help_tab() {
get_current_screen()->add_help_tab( array(
'id' => 'post_kind_help',
'title' => __( 'Post Properties', 'indieweb-post-kinds' ),
'content' => __('
<p> The Post Properties tab represents the Microformats properties of a Post. For different kinds of posts, the different
fields mean something different. Example: Artist Name vs Author Name</p>
<ul><strong>Response</strong>
<li><strong>URL</strong> - The URL the post is responding to</li>
<li><strong>Name/Title</strong> - The name of what is being responded to</li>
</ul>
<ul><strong>Citation</strong>
<li><strong>Summary</strong> - Summary of what the post is responding to</li>
<li><strong>Site Name/Publication/Album</strong></li>
<li><strong>Featured Image</strong> - The URL of a featured image of what is being responded to </li>
<li><strong>Author/Artist Name</strong> </li>
<li><strong>Author/Artist URL</strong></li>
<li><strong>Author Photo URL</strong></li>
</ul>
<ul><strong>Time</strong>
<li><strong>Start/Published Time</strong></li>
<li><strong>End/Updated Time</strong></li>
</ul>
<p> The Post Properties tab represents the Microformats properties of a Post. For different kinds of posts, the different
fields mean something different. Example: Artist Name vs Author Name</p>
<ul><strong>Main</strong>
<li><strong>URL</strong> - The URL the post is responding to</li>
<li><strong>Name/Title</strong> - The name of what is being responded to</li>
<li><strong>Summary/Quote</strong> - Summary of what the post is responding to or quote</li>
<li><strong>Tags</strong> - Tags or categories for the piece to be displayed as hashtags</li>
</ul>
<ul><strong>Details</strong>
<li><strong>Site Name/Publication/Album</strong></li>
<li><strong>Featured Image/Site Icon</strong> - The URL of a featured image of what is being responded to or a site icon</li>
<li><strong>Published Time</strong></li>
<li><strong>Updated Time</strong></li>
</ul>
<ul><strong>Author</strong>
<li><strong>Author/Artist Name</strong> </li>
<li><strong>Author/Artist URL</strong></li>
<li><strong>Author/Artist Photo URL</strong></li>
</ul>
<ul><strong>Other</strong>
<li><strong>Start Time</strong></li>
<li><strong>End Time</strong></li>
<li><strong>Duration</strong> - Duration is calculated based on the difference between start and end time. You may just use the time field,
omitting date and timezone and setting start time to 0:00:00 to set a simple duration.</li>
<li><strong>RSVP</strong> - For RSVP posts, you can specify whether you are attending, not attending, unsure, or simply interested.</li>
</ul>
', 'indieweb-post-kinds'),
) );
}
Expand Down
Loading

0 comments on commit 1d1e8b1

Please sign in to comment.