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

TMS-1083: Change event short description to be used from API #524

Merged
merged 1 commit into from
Nov 24, 2024
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: 2 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

- TMS-1083: Change event short description to be used from API

## [1.59.2] - 2024-11-19

- TMS-1088: Add fields to redipress schema
Expand Down
26 changes: 2 additions & 24 deletions lib/Eventz.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static function normalize_event( $event ) : array {

return [
'name' => $event->name ?? null,
'short_description' => static::get_short_description( $event ) ?? null,
'short_description' => nl2br( $event->descriptionShort ) ?? null,
'description' => nl2br( $event->description ) ?? null,
'date_title' => __( 'Dates', 'tms-theme-base' ),
'date' => static::get_event_date( $event ),
Expand Down Expand Up @@ -164,7 +164,7 @@ public static function normalize_event_title( $event ) : array {
*/
public static function normalize_event_description( $event ) : array {
return [
'short_description' => static::get_short_description( $event ) ?? null,
'short_description' => nl2br( $event->descriptionShort ) ?? null,
];
}

Expand Down Expand Up @@ -607,26 +607,4 @@ public static function compare_dates( $start, $end ) {
$end_time->format( 'H.i' )
);
}

/**
* Generate short description.
*
* @param object $event Event object.
*
* @return string|null
*/
public static function get_short_description( $event ) {

if ( empty( $event->description ) ) {
return null;
}

// Define a regular expression pattern to match the first two sentences
$pattern = '/^(.*?[.!?])\s+(.*?[.!?])/';

// Use preg_match() to find the first two sentences
if ( preg_match( $pattern, $event->description, $matches ) ) {
return $matches[1] . ' ' . $matches[2];
}
}
}
Loading