Navigation Menu

Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
dshanske committed Aug 2, 2020
1 parent 8182c01 commit da4ef7d
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 38 deletions.
68 changes: 54 additions & 14 deletions lib/parse-this/includes/class-rest-parse-this.php
Expand Up @@ -39,28 +39,68 @@ public static function debug() {
?>
<div class="wrap">
<h2> <?php esc_html_e( 'Parse This Debugger', 'indieweb-post-kinds' ); ?> </h2>
<p> <?php esc_html_e( 'Test the Parse Tools Debugger. You can report sites to the developer for possibly improvement in future', 'parse-this' ); ?>
<p> <?php esc_html_e( 'Test the Parse Tools Debugger. You can report sites to the developer for possibly improvement in future.', 'parse-this' ); ?>
<a href="https://github.com/dshanske/parse-this/issues"><?php esc_html_e( 'Open an Issue', 'parse-this' ); ?></a>
</p>
<a href="https://github.com/dshanske/parse-this/issues"><?php esc_html_e( 'Open an Issue', 'parse-this' ); ?></a>
<p>

<p>
<?php
if ( is_plugin_active( 'parse-this/parse-this.php' ) ) {
esc_html_e( 'You are using the plugin version of Parse This as opposed to a version built into any plugin', 'parse-this' );
}
?>
<hr />
<form method="get" action="<?php echo esc_url( rest_url( '/parse-this/1.0/parse/' ) ); ?> ">
<p><label for="url"><?php esc_html_e( 'URL', 'indieweb-post-kinds' ); ?></label><input type="url" class="widefat" name="url" id="url" /></p>
<p><label for="mf2"><?php esc_html_e( 'MF2', 'indieweb-post-kinds' ); ?></label><input type="checkbox" name="mf2" id="mf2" /></p>
<p><label for="discovery"><?php esc_html_e( 'Feed Discovery', 'indieweb-post-kinds' ); ?></label><input type="checkbox" name="discovery" id="discovery" /></p>
<p><label for="discovery"><?php esc_html_e( 'References', 'indieweb-post-kinds' ); ?></label><input type="checkbox" name="references" id="references" checked /></p>
<p><label for"return"><?php esc_html_e( 'Return Type', 'indieweb-post-kinds' ); ?></label>
<select name="return">
<option value="single"><?php esc_html_e( 'Single', 'indieweb-post-kinds' ); ?></option>
<option value="feed"><?php esc_html_e( 'Feed', 'indieweb-post-kinds' ); ?></option>
</select>
</p>
<p><label for="follow"><?php esc_html_e( 'Follow Author Links', 'indieweb-post-kinds' ); ?></label><input type="checkbox" name="follow" id="follow" /></p>
<p>
<label for="url"><?php esc_html_e( 'URL', 'indieweb-post-kinds' ); ?></label><input type="url" class="widefat" name="url" id="url" />
</p>
<table class="form-table" role="presentation">
<tbody>
<tr>
<th scope="row">
<label for="mf2"><?php esc_html_e( 'MF2', 'indieweb-post-kinds' ); ?></label>
</th>
<td>
<input type="checkbox" name="mf2" id="mf2" />
</td>
</tr>
<tr>
<th scope="row">
<label for="discovery"><?php esc_html_e( 'Feed Discovery', 'indieweb-post-kinds' ); ?></label>
</th>
<td>
<input type="checkbox" name="discovery" id="discovery" />
</td>
</tr>
<tr>
<th scope="row">
<label for="discovery"><?php esc_html_e( 'References', 'indieweb-post-kinds' ); ?></label>
</th>
<td>
<input type="checkbox" name="references" id="references" checked />
</td>
</tr>
<tr>
<th scope="row">
<label for"return"><?php esc_html_e( 'Return Type', 'indieweb-post-kinds' ); ?></label>
</th>
<td>
<select name="return">
<option value="single"><?php esc_html_e( 'Single', 'indieweb-post-kinds' ); ?></option>
<option value="feed"><?php esc_html_e( 'Feed', 'indieweb-post-kinds' ); ?></option>
</select>
</td>
</tr>
<tr>
<th scope="row">
<label for="follow"><?php esc_html_e( 'Follow Author Links', 'indieweb-post-kinds' ); ?></label>
</th>
<td>
<input type="checkbox" name="follow" id="follow" />
</td>
</tr>
</tbody>
</table>
<?php wp_nonce_field( 'wp_rest' ); ?>
<?php submit_button( __( 'Parse', 'indieweb-post-kinds' ) ); ?>
</form>
Expand Down
49 changes: 25 additions & 24 deletions lib/parse-this/includes/functions.php
Expand Up @@ -37,43 +37,44 @@ function jf2_to_mf2( $entry ) {
if ( ! function_exists( 'mf2_to_jf2' ) ) {

function mf2_to_jf2( $entry ) {
if ( empty( $entry ) || is_string( $entry ) ) {

// Check if string.
if ( is_string( $entry ) ) {
return $entry;
}
$jf2 = array();

// If it is a numeric array, run this function through each item
if ( wp_is_numeric_array( $entry ) ) {
$jf2 = array_map( 'mf2_to_jf2', $entry );
if ( 1 === count( $jf2 ) ) {
return array_pop( $jf2 );
}
return $jf2;
}
$jf2 = array();

if ( isset( $entry['items'] ) ) {
$jf2['items'] = array_map( 'mf2_to_jf2', $entry['items'] );
}

if ( isset( $entry['type'] ) ) {
// Check if this has a type and properties indicating a microformats array.
if ( array_key_exists( 'type', $entry ) && array_key_exists( 'properties', $entry ) ) {
if ( isset( $entry['items'] ) ) {
$jf2['items'] = array_map( 'mf2_to_jf2', $entry['items'] );
}
$type = is_array( $entry['type'] ) ? array_pop( $entry['type'] ) : $entry['type'];

$jf2['type'] = str_replace( 'h-', '', $type );
}
if ( isset( $entry['properties'] ) ) {

foreach ( $entry['properties'] as $key => $value ) {
if ( is_array( $value ) ) {
if ( wp_is_numeric_array( $value ) ) {
$value = array_map( 'mf2_to_jf2', $value );
if ( is_countable( $value ) && 1 === count( $value ) ) {
$value = array_pop( $value );
}
} elseif ( isset( $value['type'] ) ) {
$value = mf2_to_jf2( $value );
if ( wp_is_numeric_array( $value ) ) {
$value = array_map( 'mf2_to_jf2', $value );
if ( is_countable( $value ) && 1 === count( $value ) ) {
$value = array_pop( $value );
}
} else if ( is_array( $value ) && array_key_exists( 'type', $value ) && array_key_exists( 'properties', $value ) ) {
$value = mf2_to_jf2( $value );
}
$jf2[ $key ] = $value;
}
} else if ( wp_is_numeric_array( $entry ) ) {
// If it is a numeric array, run this function through each item
$jf2 = array_map( 'mf2_to_jf2', $entry );
if ( 1 === count( $jf2 ) ) {
return array_pop( $jf2 );
}
return $jf2;
}

return $jf2;
}
}
Expand Down

0 comments on commit da4ef7d

Please sign in to comment.