From 5690a909f59b62ce9a7e50a6376b812cea01b670 Mon Sep 17 00:00:00 2001 From: Sorin Marta Date: Thu, 29 Oct 2026 11:20:00 +0200 Subject: [PATCH 1/2] Show the date listings are sorted by in the default listings layout Fixes Strategy11/awpcp#3118 --- frontend/ad-functions.php | 34 +++++++++++++++++--- frontend/placeholders.php | 5 +++ includes/helpers/class-listing-renderer.php | 25 ++++++++++++++ includes/settings/class-display-settings.php | 2 +- tests/suite/frontend/test-placeholders.php | 28 ++++++++++++++++ 5 files changed, 88 insertions(+), 6 deletions(-) diff --git a/frontend/ad-functions.php b/frontend/ad-functions.php index 06d18ff99..384357687 100644 --- a/frontend/ad-functions.php +++ b/frontend/ad-functions.php @@ -193,6 +193,34 @@ function awpcp_ad_posted_user_email( $ad, $transaction = null, $message='' ) { return $email; } +/** + * Returns the layout used to render each listing in lists of listings. + * + * A saved layout identical to the default shipped before the + * $most_recent_start_date placeholder was added is treated as the default, + * so listings show the same date the date-based orders use. + * + * @since x.x + * + * @return string + */ +function awpcp_get_listings_layout() { + $layout = get_awpcp_option( 'displayadlayoutcode' ); + $default_layout = (string) awpcp()->settings->get_option_default_value( 'displayadlayoutcode' ); + + if ( empty( $layout ) ) { + return $default_layout; + } + + $previous_default_layout = str_replace( '$most_recent_start_date
', '$awpcpadpostdate', $default_layout ); + + if ( preg_replace( '/\s+/', '', $layout ) === preg_replace( '/\s+/', '', $previous_default_layout ) ) { + return $default_layout; + } + + return $layout; +} + /** * Renders each listing using the layout configured in the plugin * settings. @@ -206,11 +234,7 @@ function awpcp_ad_posted_user_email( $ad, $transaction = null, $message='' ) { */ function awpcp_render_listings_items( $listings, $context, $options = array() ) { $parity = array( 'displayaditemseven', 'displayaditemsodd' ); - $layout = get_awpcp_option('displayadlayoutcode'); - - if ( empty( $layout ) ) { - $layout = awpcp()->settings->get_option_default_value( 'displayadlayoutcode' ); - } + $layout = awpcp_get_listings_layout(); $listing_renderer = awpcp_listing_renderer(); diff --git a/frontend/placeholders.php b/frontend/placeholders.php index e1ebb64d5..cf4417815 100644 --- a/frontend/placeholders.php +++ b/frontend/placeholders.php @@ -209,6 +209,9 @@ function awpcp_content_placeholders() { 'renewed_date' => array( 'callback' => 'awpcp_do_placeholder_dates', ), + 'most_recent_start_date' => array( + 'callback' => 'awpcp_do_placeholder_dates', + ), 'featured_image' => array( 'callback' => 'awpcp_do_placeholder_images', @@ -543,6 +546,8 @@ function awpcp_do_placeholder_dates( $ad, $placeholder ) { $replacements['posted_date_time'] = $listing_renderer->get_posted_date_and_time_formatted( $ad ); $replacements['last_updated_date'] = $listing_renderer->get_last_updated_date_formatted( $ad ); + $replacements['most_recent_start_date'] = $listing_renderer->get_most_recent_start_date_formatted( $ad ); + $verification_date = $listing_renderer->get_verification_date( $ad ); if ( ! empty( $verification_date ) ) { diff --git a/includes/helpers/class-listing-renderer.php b/includes/helpers/class-listing-renderer.php index c89b2d2c8..be5f312a9 100644 --- a/includes/helpers/class-listing-renderer.php +++ b/includes/helpers/class-listing-renderer.php @@ -202,6 +202,31 @@ public function get_posted_date_formatted( $listing ) { return $this->get_formatted_date( $listing->post_date ); } + /** + * Returns the date used by the date-based listing orders: the renewed + * date if the listing was renewed after it started, or its start date. + * + * @since x.x + */ + public function get_most_recent_start_date_formatted( $listing ) { + $date = $this->wordpress->get_post_meta( $listing->ID, '_awpcp_most_recent_start_date', true ); + + if ( empty( $date ) ) { + $date = $this->get_plain_start_date( $listing ); + $renewed_date = $this->get_renewed_date( $listing ); + + if ( $renewed_date && strtotime( $renewed_date ) > strtotime( (string) $date ) ) { + $date = $renewed_date; + } + } + + if ( empty( $date ) ) { + $date = $listing->post_date; + } + + return $this->get_formatted_date( $date ); + } + /** * @since 4.0.0 */ diff --git a/includes/settings/class-display-settings.php b/includes/settings/class-display-settings.php index 86d8b58d6..961ed18b1 100644 --- a/includes/settings/class-display-settings.php +++ b/includes/settings/class-display-settings.php @@ -99,7 +99,7 @@ private function register_layout_and_presentation_settings( $settings_manager )
$excerpt
- $awpcpadpostdate + $most_recent_start_date
$awpcp_city_display $awpcp_state_display $awpcp_display_adviews diff --git a/tests/suite/frontend/test-placeholders.php b/tests/suite/frontend/test-placeholders.php index 518e9ad47..febaaa578 100644 --- a/tests/suite/frontend/test-placeholders.php +++ b/tests/suite/frontend/test-placeholders.php @@ -54,6 +54,34 @@ public function test_renewed_date_placeholder_returns_posted_date_if_listing_has $this->assertEquals( $expected_value, awpcp_do_placeholders( $ad, '$renewed_date', 'listings' ) ); } + public function test_most_recent_start_date_placeholder() { + awpcp()->settings->set_or_update_option( 'date-format', 'F d, Y' ); + + $ad = awpcp_tests_create_listing(); + $ad->post_date = '2013-10-24 12:34:56'; + + update_post_meta( $ad->ID, '_awpcp_start_date', '2013-10-24 12:34:56' ); + update_post_meta( $ad->ID, '_awpcp_most_recent_start_date', '2013-11-05 08:00:00' ); + + $this->assertEquals( 'November 05, 2013', awpcp_do_placeholders( $ad, '$most_recent_start_date', 'listings' ) ); + } + + public function test_most_recent_start_date_placeholder_falls_back_to_start_date_and_posted_date() { + awpcp()->settings->set_or_update_option( 'date-format', 'F d, Y' ); + + $ad = awpcp_tests_create_listing(); + $ad->post_date = '2013-10-24 12:34:56'; + + delete_post_meta( $ad->ID, '_awpcp_most_recent_start_date' ); + update_post_meta( $ad->ID, '_awpcp_start_date', '2013-10-25 12:34:56' ); + + $this->assertEquals( 'October 25, 2013', awpcp_do_placeholders( $ad, '$most_recent_start_date', 'listings' ) ); + + delete_post_meta( $ad->ID, '_awpcp_start_date' ); + + $this->assertEquals( 'October 24, 2013', awpcp_do_placeholders( $ad, '$most_recent_start_date', 'listings' ) ); + } + public function test_price_placeholder() { awpcp()->settings->set_or_update_option( 'displaypricefield', true ); awpcp()->settings->set_or_update_option( 'price-field-is-restricted', false ); From 80e31d3996fbc123dc62d4e48164eb9d71fff74d Mon Sep 17 00:00:00 2001 From: Sorin Marta Date: Thu, 29 Oct 2026 11:33:29 +0200 Subject: [PATCH 2/2] Replace finfo_close() and imagedestroy() with unset() Both functions have been no-ops since PHP 8.0 and are deprecated in PHP 8.5, which fails the PHPCS inspection. --- includes/functions/deprecated.php | 3 +-- includes/media/class-mime-types.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/includes/functions/deprecated.php b/includes/functions/deprecated.php index 955f4177a..3e6c3a9c3 100644 --- a/includes/functions/deprecated.php +++ b/includes/functions/deprecated.php @@ -830,8 +830,7 @@ function awpcp_resizer($filename, $dir) { break; } - imagedestroy($src); - imagedestroy($tmp); + unset( $src, $tmp ); return true; } diff --git a/includes/media/class-mime-types.php b/includes/media/class-mime-types.php index 65e5aa26c..82131fc95 100644 --- a/includes/media/class-mime-types.php +++ b/includes/media/class-mime-types.php @@ -39,7 +39,7 @@ private function get_file_mime_type_with_fileinfo( $filepath ) { $fileinfo = finfo_open( defined( 'FILEINFO_MIME_TYPE' ) ? FILEINFO_MIME_TYPE : FILEINFO_MIME ); $mime_type = finfo_file( $fileinfo, $filepath ); $mime_type_parts = explode( ';', $mime_type ); - finfo_close( $fileinfo ); + unset( $fileinfo ); return array_shift( $mime_type_parts ); }