term_id; $valid_filters[] = $folder_key; $folder_map[ $folder_key ] = $folder; } if ( ! in_array( $filter, $valid_filters, true ) ) { $filter = 'all'; } $sort = isset( $_GET['sort'] ) ? sanitize_key( $_GET['sort'] ) : 'name'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended if ( ! in_array( $sort, array( 'name', 'newest', 'oldest', 'posts' ), true ) ) { $sort = 'name'; } $search_term = isset( $_GET['q'] ) ? trim( wp_unslash( $_GET['q'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.MissingUnslash,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized Friends\Friends::template_loader()->get_template_part( 'frontend/header', null, $args ); ?>
get_results(); $total = count( $all_subscriptions ); // Filter. if ( 'starred' === $filter ) { $filtered = array_filter( $all_subscriptions, function ( $s ) { return $s instanceof Friends\Subscription && $s->is_starred(); } ); } elseif ( isset( $folder_map[ $filter ] ) ) { $folder_term_id = $folder_map[ $filter ]->term_id; $filtered = array_filter( $all_subscriptions, function ( $s ) use ( $folder_term_id ) { if ( ! ( $s instanceof Friends\Subscription ) ) { return false; } $folder = $s->get_folder(); return $folder && $folder->term_id === $folder_term_id; } ); } else { $filtered = $all_subscriptions; } // Search (applied after category filter so the top-of-page totals stay accurate). if ( '' !== $search_term ) { $search_term_lc = function_exists( 'mb_strtolower' ) ? mb_strtolower( $search_term ) : strtolower( $search_term ); $filtered = array_filter( $filtered, function ( $s ) use ( $search_term_lc ) { $haystack = ''; if ( isset( $s->display_name ) ) { $haystack .= $s->display_name . ' '; } if ( isset( $s->user_login ) ) { $haystack .= $s->user_login . ' '; } if ( isset( $s->user_url ) ) { $haystack .= $s->user_url . ' '; } if ( isset( $s->description ) ) { $haystack .= wp_strip_all_tags( $s->description ); } $haystack = function_exists( 'mb_strtolower' ) ? mb_strtolower( $haystack ) : strtolower( $haystack ); return false !== strpos( $haystack, $search_term_lc ); } ); } // Sort. $filtered = array_values( $filtered ); if ( 'newest' === $sort ) { usort( $filtered, function ( $a, $b ) { return strtotime( $b->user_registered ) - strtotime( $a->user_registered ); } ); } elseif ( 'oldest' === $sort ) { usort( $filtered, function ( $a, $b ) { return strtotime( $a->user_registered ) - strtotime( $b->user_registered ); } ); } elseif ( 'posts' === $sort ) { usort( $filtered, function ( $a, $b ) { $a_stats = $a->get_post_stats(); $b_stats = $b->get_post_stats(); return intval( $b_stats['post_count'] ) - intval( $a_stats['post_count'] ); } ); } else { usort( $filtered, function ( $a, $b ) { return strnatcasecmp( $a->display_name, $b->display_name ); } ); } // Paginate. $filtered_total = count( $filtered ); $subscriptions_per_page = 20; $current_page = isset( $_GET['spage'] ) ? max( 1, absint( $_GET['spage'] ) ) : 1; // phpcs:ignore WordPress.Security.NonceVerification.Recommended $page_subscriptions = array_slice( $filtered, ( $current_page - 1 ) * $subscriptions_per_page, $subscriptions_per_page ); // Categorize subscriptions: people (ActivityPub) vs feeds (RSS/Atom). $people_count = 0; $feed_count = 0; foreach ( $all_subscriptions as $sub ) { $is_person = false; if ( $sub instanceof Friends\Subscription ) { foreach ( $sub->get_active_feeds() as $active_feed ) { if ( 'activitypub' === $active_feed->get_parser() ) { $is_person = true; break; } } } if ( $is_person ) { ++$people_count; } else { ++$feed_count; } } $base_url = strtok( $_SERVER['REQUEST_URI'], '?' ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput $link_args = array(); if ( 'all' !== $filter ) { $link_args['filter'] = $filter; } if ( 'name' !== $sort ) { $link_args['sort'] = $sort; } if ( '' !== $search_term ) { $link_args['q'] = $search_term; } ?>

__( 'All', 'friends' ), 'starred' => __( 'Starred', 'friends' ), ); foreach ( $folders as $folder ) { $filters[ 'folder-' . $folder->term_id ] = $folder->name; } $filter_links = array(); foreach ( $filters as $filter_key => $filter_label ) { $url = $base_url; $f_args = $link_args; if ( 'all' !== $filter_key ) { $f_args['filter'] = $filter_key; } else { unset( $f_args['filter'] ); } if ( $f_args ) { $url = add_query_arg( $f_args, $url ); } if ( $filter === $filter_key ) { $filter_links[] = '' . esc_html( $filter_label ) . ''; } else { $filter_links[] = '' . esc_html( $filter_label ) . ''; } } echo wp_kses( implode( ' | ', $filter_links ), array( 'strong' => array(), 'a' => array( 'href' => array() ), ) ); ?>    __( 'Name', 'friends' ), 'newest' => __( 'Newest', 'friends' ), 'oldest' => __( 'Oldest', 'friends' ), 'posts' => __( 'Most Posts', 'friends' ), ); $sort_links = array(); foreach ( $sorts as $sort_key => $sort_label ) { $url = $base_url; $s_args = $link_args; if ( 'name' !== $sort_key ) { $s_args['sort'] = $sort_key; } else { unset( $s_args['sort'] ); } if ( $s_args ) { $url = add_query_arg( $s_args, $url ); } if ( $sort === $sort_key ) { $sort_links[] = '' . esc_html( $sort_label ) . ''; } else { $sort_links[] = '' . esc_html( $sort_label ) . ''; } } echo wp_kses( implode( ' | ', $sort_links ), array( 'strong' => array(), 'a' => array( 'href' => array() ), ) ); ?>

1 ) { $pagination_args = array( 'base' => add_query_arg( 'spage', '%#%' ), 'format' => '', 'current' => $current_page, 'total' => $total_pages, ); if ( $link_args ) { $pagination_args['add_args'] = $link_args; } echo ''; } ?>
get_template_part( 'frontend/footer', null, $args );