Skip to content

Commit

Permalink
Merge pull request #413 from paulschreiber/fix/cli
Browse files Browse the repository at this point in the history
PHPCS: allow file_get_contents() for CLI command
  • Loading branch information
philipjohn authored Apr 27, 2018
2 parents 0e7e4c6 + 6bba9ca commit 669f2a5
Show file tree
Hide file tree
Showing 31 changed files with 1,775 additions and 1,666 deletions.
2 changes: 1 addition & 1 deletion classes/class-wpcom-liveblog-entry-embed-sdks.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static function enqueue() {
* @return type
*/
public static function add_async_attribute( $tag, $handle ) {
if ( ! in_array( $handle, array_keys( self::$sdks ) ) ) {
if ( ! in_array( $handle, array_keys( self::$sdks ), true ) ) {
return $tag;
}
return str_replace( ' src', ' async="async" src', $tag );
Expand Down
58 changes: 29 additions & 29 deletions classes/class-wpcom-liveblog-entry-embed.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function __construct() {
* being created on the fly on frontend
*/
public function maybe_run_ajax_cache() {
return;
}

/**
Expand Down Expand Up @@ -71,8 +70,8 @@ public function shortcode( $attr, $url = '', $comment = null ) {
$handlers = $this->handlers;
//check for handlers registered for wp_embed class using all the helper functions
if ( true === isset( $GLOBALS['wp_embed'] )
&& is_a( $GLOBALS['wp_embed'], 'WP_Embed' )
&& is_array( $GLOBALS['wp_embed']->handlers )
&& is_a( $GLOBALS['wp_embed'], 'WP_Embed' )
&& is_array( $GLOBALS['wp_embed']->handlers )
) {
//marge those in a single array
$handlers = array_replace_recursive( $GLOBALS['wp_embed']->handlers, $this->handlers );
Expand All @@ -81,7 +80,8 @@ public function shortcode( $attr, $url = '', $comment = null ) {
foreach ( $handlers as $priority => $handlers ) {
foreach ( $handlers as $id => $handler ) {
if ( preg_match( $handler['regex'], $url, $matches ) && is_callable( $handler['callback'] ) ) {
if ( false !== $return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr ) ) {
$return = call_user_func( $handler['callback'], $matches, $attr, $url, $rawattr );
if ( false !== $return ) {
/**
* Filter the returned embed handler.
*
Expand All @@ -97,16 +97,16 @@ public function shortcode( $attr, $url = '', $comment = null ) {
}
}

$comment_ID = ( ! empty( $comment->comment_ID ) ) ? $comment->comment_ID : null;
$comment_id = ( ! empty( $comment->comment_ID ) ) ? $comment->comment_ID : null;
if ( ! empty( $this->comment_ID ) ) { // Potentially set by WPCOM_Comments_Embed::autoembed()
$comment_ID = $this->comment_ID;
$comment_id = $this->comment_ID;
}

// Unknown URL format. Let oEmbed have a go.
if ( $comment_ID ) {
if ( $comment_id ) {

// Check for a cached result (stored in the comment meta)
$key_suffix = md5( $url . serialize( $attr ) );
$key_suffix = md5( $url . wp_json_encode( $attr ) );
$cachekey = '_oembed_' . $key_suffix;
$cachekey_time = '_oembed_time_' . $key_suffix;

Expand All @@ -116,12 +116,12 @@ public function shortcode( $attr, $url = '', $comment = null ) {
* @param int $time Time to live (in seconds).
* @param string $url The attempted embed URL.
* @param array $attr An array of shortcode attributes.
* @param int $comment_ID Comment ID.
* @param int $comment_id Comment ID.
*/
$ttl = apply_filters( 'oembed_ttl', DAY_IN_SECONDS, $url, $attr, $comment_ID );
$ttl = apply_filters( 'oembed_ttl', DAY_IN_SECONDS, $url, $attr, $comment_id );

$cache = get_comment_meta( $comment_ID, $cachekey, true );
$cache_time = get_comment_meta( $comment_ID, $cachekey_time, true );
$cache = get_comment_meta( $comment_id, $cachekey, true );
$cache_time = get_comment_meta( $comment_id, $cachekey_time, true );

/**
* Check post meta in case there is no existing comment meta
Expand All @@ -130,7 +130,7 @@ public function shortcode( $attr, $url = '', $comment = null ) {
* before we fully transition to comment meta caching
*/
if ( true === empty( $cache_time ) && true === empty( $cache ) ) {
$comment = get_comment( $comment_ID );
$comment = get_comment( $comment_id );
if ( true === is_a( $comment, 'WP_Comment' ) ) {
$post_id = $comment->comment_post_ID;
$cache = get_post_meta( $post_id, $cachekey, true );
Expand Down Expand Up @@ -159,9 +159,9 @@ public function shortcode( $attr, $url = '', $comment = null ) {
* @param mixed $cache The cached HTML result, stored in comment meta.
* @param string $url The attempted embed URL.
* @param array $attr An array of shortcode attributes.
* @param int $comment_ID Comment ID.
* @param int $comment_id Comment ID.
*/
return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $comment_ID );
return apply_filters( 'embed_oembed_html', $cache, $url, $attr, $comment_id );
}
}

Expand All @@ -179,10 +179,10 @@ public function shortcode( $attr, $url = '', $comment = null ) {

// Maybe cache the result
if ( $html ) {
update_comment_meta( $comment_ID, $cachekey, $html );
update_comment_meta( $comment_ID, $cachekey_time, time() );
update_comment_meta( $comment_id, $cachekey, $html );
update_comment_meta( $comment_id, $cachekey_time, time() );
} elseif ( ! $cache ) {
update_comment_meta( $comment_ID, $cachekey, '{{unknown}}' );
update_comment_meta( $comment_id, $cachekey, '{{unknown}}' );
}

// If there was a result, return it
Expand All @@ -195,9 +195,9 @@ public function shortcode( $attr, $url = '', $comment = null ) {
* @param mixed $cache The cached HTML result, stored in post meta.
* @param string $url The attempted embed URL.
* @param array $attr An array of shortcode attributes.
* @param int $comment_ID Comment ID.
* @param int $comment_id Comment ID.
*/
return apply_filters( 'embed_oembed_html', $html, $url, $attr, $comment_ID );
return apply_filters( 'embed_oembed_html', $html, $url, $attr, $comment_id );
}
}

Expand All @@ -208,26 +208,27 @@ public function shortcode( $attr, $url = '', $comment = null ) {
/**
* Delete all Comment oEmbed caches.
*
* @param int $comment_ID Comment ID to delete the caches for.
* @param int $comment_id Comment ID to delete the caches for.
*/
public function delete_oembed_caches( $comment_ID = 0 ) {
public function delete_oembed_caches( $comment_id = 0 ) {
if ( ! $comment_id ) {
$comment_id = get_comment_ID();
}
$comment_metas = get_comment_meta( $comment_ID );
$comment_metas = get_comment_meta( $comment_id );
if ( empty( $comment_metas ) ) {
return;
}
if ( ! is_array( $comment_metas ) ) {
return;
}
if ( ! $comment_meta_keys = array_keys( $comment_metas ) ) {
$comment_meta_keys = array_keys( $comment_metas );
if ( ! $comment_meta_keys ) {
return;
}

foreach ( $comment_meta_keys as $comment_meta_key ) {
if ( '_oembed_' == substr( $comment_meta_key, 0, 8 ) ) {
delete_comment_meta( $comment_ID, $comment_meta_key );
if ( '_oembed_' === substr( $comment_meta_key, 0, 8 ) ) {
delete_comment_meta( $comment_id, $comment_meta_key );
}
}
}
Expand All @@ -239,10 +240,9 @@ public function delete_oembed_caches( $comment_ID = 0 ) {
* parent class' one. We don't need to pre-populate cache
* for comments are they are being created on the fly.
*
* @param int $comment_ID Comment ID to do the caching for.
* @param int $comment_id Comment ID to do the caching for.
*/
public function cache_oembed( $comment_ID ) {
return;
public function cache_oembed( $comment_id ) {
}

/**
Expand Down
8 changes: 4 additions & 4 deletions classes/class-wpcom-liveblog-entry-extend-feature-authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function preg_replace_callback( $match ) {

// If the match isn't actually an author then we can
// safely say that this doesn't need to be matched.
if ( ! in_array( $author, $this->authors ) ) {
if ( ! in_array( $author, $this->authors, true ) ) {
return $match[0];
}

Expand Down Expand Up @@ -195,7 +195,7 @@ public function add_author_class_to_entry( $classes, $class, $comment_id ) {
$comment = get_comment( $comment_id );

// Check if the comment is a live blog comment.
if ( WPCOM_Liveblog::key == $comment->comment_type ) {
if ( WPCOM_Liveblog::KEY === $comment->comment_type ) {

// Grab all the prefixed classes applied.
preg_match_all( '/(?<!\w)' . preg_quote( $this->class_prefix ) . '\w+/', $comment->comment_content, $authors );
Expand All @@ -215,8 +215,8 @@ public function add_author_class_to_entry( $classes, $class, $comment_id ) {
public function ajax_authors() {

//Sanitize the input safely.
if ( isset( $_GET['autocomplete'] ) ) {
$term = sanitize_text_field( $_GET['autocomplete'] );
if ( isset( $_GET['autocomplete'] ) ) { // input var ok
$term = sanitize_text_field( wp_unslash( $_GET['autocomplete'] ) ); // input var ok
} else {
$term = '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function preg_replace_callback( $match ) {
$type = apply_filters( 'liveblog_command_type', $match[2] );

// If it's not a command that's been registered then skip it.
if ( ! in_array( $type, $this->commands ) ) {
if ( ! in_array( $type, $this->commands, true ) ) {
return $match[0];
}

Expand Down Expand Up @@ -190,7 +190,7 @@ public function add_type_class_to_entry( $classes, $class, $comment_id ) {
$comment = get_comment( $comment_id );

// Check if the comment is a live blog comment.
if ( WPCOM_Liveblog::key == $comment->comment_type ) {
if ( WPCOM_Liveblog::KEY === $comment->comment_type ) {

// Grab all the prefixed classes applied.
preg_match_all( '/(?<!\w)' . $this->class_prefix_local . '\w+/', $comment->comment_content, $types );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ public function add_emoji_class_to_entry( $classes, $class, $comment_id ) {
$comment = get_comment( $comment_id );

// Check if the comment is a live blog comment.
if ( WPCOM_Liveblog::key == $comment->comment_type ) {
if ( WPCOM_Liveblog::KEY === $comment->comment_type ) {

// Grab all the prefixed classes applied.
preg_match_all( '/(?<!\w)' . preg_quote( $this->class_prefix ) . '\w+/', $comment->comment_content, $emojis );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function add_term_class_to_entry( $classes, $class, $comment_id ) {
$comment = get_comment( $comment_id );

// Check if the comment is a live blog comment.
if ( WPCOM_Liveblog::key == $comment->comment_type ) {
if ( WPCOM_Liveblog::KEY === $comment->comment_type ) {

// Grab all the prefixed classes applied.
preg_match_all( '/(?<!\w)' . preg_quote( $this->class_prefix ) . '(\w\-?)+/', $comment->comment_content, $terms );
Expand All @@ -197,8 +197,8 @@ public function add_term_class_to_entry( $classes, $class, $comment_id ) {
public function ajax_terms() {

//Sanitize the input safely.
if ( isset( $_GET['autocomplete'] ) ) {
$search_term = sanitize_text_field( $_GET['autocomplete'] );
if ( isset( $_GET['autocomplete'] ) ) { // input var ok
$search_term = sanitize_text_field( wp_unslash( $_GET['autocomplete'] ) ); // input var ok
} else {
$search_term = '';
}
Expand Down
12 changes: 6 additions & 6 deletions classes/class-wpcom-liveblog-entry-key-events-widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ public function widget( $args, $instance ) {
return;
}

echo $args['before_widget'];
echo wp_kses_post( $args['before_widget'] );

if ( ! empty( $instance['title'] ) ) {
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'];
echo wp_kses_post( $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ) . $args['after_title'] );
}

echo $shortcode_output;
echo $args['after_widget'];
echo wp_kses_post( $shortcode_output );
echo wp_kses_post( $args['after_widget'] );
}

/**
Expand All @@ -77,8 +77,8 @@ public function form( $instance ) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : '';
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php esc_html_e( 'Title:', 'liveblog' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
<label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'liveblog' ); ?></label>
<input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>">
</p>
<p class="description">
<?php esc_html_e( 'Note: the number of key events displayed in the widget is defined in the Liveblog configuration inside each post.', 'liveblog' ); ?>
Expand Down
Loading

0 comments on commit 669f2a5

Please sign in to comment.