Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error checking regarding post formats and missing ActivityPub metadata #271

Merged
merged 2 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion feed-parsers/class-feed-parser-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public function discover_available_feeds( $content, $url ) {
$discovered_feeds = array();

$meta = self::get_metadata( $url );
if ( $meta && ! is_wp_error( $meta ) ) {
if ( $meta && ! is_wp_error( $meta ) && isset( $meta['id'] ) ) {
$discovered_feeds[ $meta['id'] ] = array(
'type' => 'application/activity+json',
'rel' => 'self',
Expand Down
70 changes: 36 additions & 34 deletions includes/class-subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,42 +296,44 @@ public function get_post_count_by_post_format() {
)
);

$post_format_counts = $wpdb->get_results(
$wpdb->prepare(
sprintf(
"SELECT relationships_post_format.term_taxonomy_id AS post_format_id, COUNT(relationships_post_format.term_taxonomy_id) AS count
FROM %s AS posts
JOIN %s AS relationships_post_format
JOIN %s AS taxonomy_author
JOIN %s AS relationships_author

WHERE posts.post_status IN ( 'publish', 'private' )
AND posts.post_type IN ( %s )
AND relationships_post_format.object_id = posts.ID
AND relationships_post_format.term_taxonomy_id IN ( %s )
AND relationships_author.object_id = posts.ID
AND taxonomy_author.term_taxonomy_id = relationships_author.term_taxonomy_id
AND taxonomy_author.term_id = %s
GROUP BY relationships_post_format.term_taxonomy_id",
$wpdb->posts,
$wpdb->term_relationships,
$wpdb->term_taxonomy,
$wpdb->term_relationships,
implode( ',', array_fill( 0, count( $post_types ), '%s' ) ),
implode( ',', array_fill( 0, count( $post_formats_term_ids ), '%d' ) ),
'%d'
),
array_merge(
$post_types,
array_keys( $post_formats_term_ids ),
array( $this->get_term_id() )
if ( ! empty( $post_formats_term_ids ) ) {
$post_format_counts = $wpdb->get_results(
$wpdb->prepare(
sprintf(
"SELECT relationships_post_format.term_taxonomy_id AS post_format_id, COUNT(relationships_post_format.term_taxonomy_id) AS count
FROM %s AS posts
JOIN %s AS relationships_post_format
JOIN %s AS taxonomy_author
JOIN %s AS relationships_author

WHERE posts.post_status IN ( 'publish', 'private' )
AND posts.post_type IN ( %s )
AND relationships_post_format.object_id = posts.ID
AND relationships_post_format.term_taxonomy_id IN ( %s )
AND relationships_author.object_id = posts.ID
AND taxonomy_author.term_taxonomy_id = relationships_author.term_taxonomy_id
AND taxonomy_author.term_id = %s
GROUP BY relationships_post_format.term_taxonomy_id",
$wpdb->posts,
$wpdb->term_relationships,
$wpdb->term_taxonomy,
$wpdb->term_relationships,
implode( ',', array_fill( 0, count( $post_types ), '%s' ) ),
implode( ',', array_fill( 0, count( $post_formats_term_ids ), '%d' ) ),
'%d'
),
array_merge(
$post_types,
array_keys( $post_formats_term_ids ),
array( $this->get_term_id() )
)
)
)
);
);

foreach ( $post_format_counts as $row ) {
$counts[ $post_formats_term_ids[ $row->post_format_id ] ] = $row->count;
$counts['standard'] -= $row->count;
foreach ( $post_format_counts as $row ) {
$counts[ $post_formats_term_ids[ $row->post_format_id ] ] = $row->count;
$counts['standard'] -= $row->count;
}
}

$counts = array_filter( $counts );
Expand Down
58 changes: 30 additions & 28 deletions includes/class-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -765,36 +765,38 @@ public function get_post_count_by_post_format() {
)
);

$post_format_counts = $wpdb->get_results(
$wpdb->prepare(
sprintf(
"SELECT relationships_post_format.term_taxonomy_id AS post_format_id, COUNT(relationships_post_format.term_taxonomy_id) AS count
FROM %s AS posts
JOIN %s AS relationships_post_format

WHERE posts.post_author = %s
AND posts.post_status IN ( 'publish', 'private' )
AND posts.post_type IN ( %s )
AND relationships_post_format.object_id = posts.ID
AND relationships_post_format.term_taxonomy_id IN ( %s )
GROUP BY relationships_post_format.term_taxonomy_id",
$wpdb->posts,
$wpdb->term_relationships,
'%d',
implode( ',', array_fill( 0, count( $post_types ), '%s' ) ),
implode( ',', array_fill( 0, count( $post_formats_term_ids ), '%d' ) )
),
array_merge(
array( $this->ID ),
$post_types,
array_keys( $post_formats_term_ids )
if ( ! empty( $post_formats_term_ids ) ) {
$post_format_counts = $wpdb->get_results(
$wpdb->prepare(
sprintf(
"SELECT relationships_post_format.term_taxonomy_id AS post_format_id, COUNT(relationships_post_format.term_taxonomy_id) AS count
FROM %s AS posts
JOIN %s AS relationships_post_format

WHERE posts.post_author = %s
AND posts.post_status IN ( 'publish', 'private' )
AND posts.post_type IN ( %s )
AND relationships_post_format.object_id = posts.ID
AND relationships_post_format.term_taxonomy_id IN ( %s )
GROUP BY relationships_post_format.term_taxonomy_id",
$wpdb->posts,
$wpdb->term_relationships,
'%d',
implode( ',', array_fill( 0, count( $post_types ), '%s' ) ),
implode( ',', array_fill( 0, count( $post_formats_term_ids ), '%d' ) )
),
array_merge(
array( $this->ID ),
$post_types,
array_keys( $post_formats_term_ids )
)
)
)
);
);

foreach ( $post_format_counts as $row ) {
$counts[ $post_formats_term_ids[ $row->post_format_id ] ] = $row->count;
$counts['standard'] -= $row->count;
foreach ( $post_format_counts as $row ) {
$counts[ $post_formats_term_ids[ $row->post_format_id ] ] = $row->count;
$counts['standard'] -= $row->count;
}
}

$counts = array_filter( $counts );
Expand Down