eligibility = $eligibility; } public function validate( array $ids, $current_id, $surface = 'archive' ) { $ids = array_slice( array_values( array_unique( array_filter( array_map( 'absint', $ids ) ) ) ), 0, 200 ); $valid = array(); foreach ( $ids as $id ) { if ( $this->eligibility->resolve( $id, new EligibilityContext( $surface ) )->eligible() ) { $valid[] = $id; } } $position = array_search( (int) $current_id, $valid, true ); return array( 'ids' => $valid, 'position' => false === $position ? -1 : $position ); } public function neighbors( array $ids, $current_id, $surface, $wrap = false ) { $collection = $this->validate( $ids, $current_id, $surface ); $count = count( $collection['ids'] ); $at = $collection['position']; if ( $at < 0 || ! $count ) { return array( 'previous' => 0, 'next' => 0 ); } return array( 'previous' => $at > 0 ? $collection['ids'][ $at - 1 ] : ( $wrap && $count > 1 ? $collection['ids'][ $count - 1 ] : 0 ), 'next' => $at < $count - 1 ? $collection['ids'][ $at + 1 ] : ( $wrap && $count > 1 ? $collection['ids'][0] : 0 ) ); } }