Skip to content

Commit

Permalink
Small fixes php warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
eyalacato committed Mar 4, 2024
1 parent e809737 commit 26131c5
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 31 deletions.
Binary file modified languages/openagenda-base-nl_NL.mo
Binary file not shown.
5 changes: 5 additions & 0 deletions languages/openagenda-base-nl_NL.po
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,11 @@ msgctxt "last as in every last monday of the month"
msgid "last"
msgstr "laatste"

#: src/admin/class-event-dates.php:488
msgctxt "every as in every monday of the month"
msgid "every"
msgstr "elke"

#. translators: %1$s and %2$s are the start and end of a run of consecutive items, for example monday and friday to become "monday through friday".
#: src/admin/class-event-dates.php:501 src/admin/class-event-dates.php:828
msgctxt "As monday through friday"
Expand Down
5 changes: 5 additions & 0 deletions languages/openagenda-base.pot
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,11 @@ msgctxt "last as in every last monday of the month"
msgid "last"
msgstr ""

#: src/admin/class-event-dates.php:488
msgctxt "every as in every monday of the month"
msgid "every"
msgstr ""

#. translators: %1$s and %2$s are the start and end of a run of consecutive items, for example monday and friday to become "monday through friday".
#: src/admin/class-event-dates.php:501
#: src/admin/class-event-dates.php:828
Expand Down
13 changes: 7 additions & 6 deletions src/admin/class-event-dates.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private function create_date_list( $post_id, $format = 'timestamp', $internal_me

// Holds all months this event is on.
$triggered_months = self::all_months();
if ( isset ( $meta[ $prefix . 'complex_months' ] ) && count( $meta[ $prefix . 'complex_months' ] ) > 0 ) {
if ( isset( $meta[ $prefix . 'complex_months' ] ) && count( $meta[ $prefix . 'complex_months' ] ) > 0 ) {
$triggered_months = array_intersect( $triggered_months, $meta[ $prefix . 'complex_months' ] );
}

Expand All @@ -185,16 +185,16 @@ private function create_date_list( $post_id, $format = 'timestamp', $internal_me
}

// Start and End of the list, absolute boundaries to prevent over-taxing.
$absolute_first_date = gmdate( 'Y' ) - 1 . '-01-01';
$absolute_last_date = gmdate( 'Y' ) + 1 . '-12-31';
$absolute_first_date = (int) gmdate( 'Y' ) - 1 . '-01-01';
$absolute_last_date = (int) gmdate( 'Y' ) + 1 . '-12-31';
$absolute_first_timestamp = strtotime( $absolute_first_date );
$absolute_last_timestamp = strtotime( $absolute_last_date );

// Boundaries.
$first_date_to_process = $meta[ $prefix . 'complex_start_date' ] ? $meta[ $prefix . 'complex_start_date' ] : false;
$first_date_to_process = isset( $meta[ $prefix . 'complex_start_date' ] ) ? $meta[ $prefix . 'complex_start_date' ] : false;
$first_date_to_process = $first_date_to_process ? $first_date_to_process : $absolute_first_date;
$first_timestamp_to_process = strtotime( $first_date_to_process );
$last_date_to_process = $meta[ $prefix . 'complex_end_date' ] ? $meta[ $prefix . 'complex_end_date' ] : false;
$last_date_to_process = isset( $meta[ $prefix . 'complex_end_date' ] ) ? $meta[ $prefix . 'complex_end_date' ] : false;
$last_date_to_process = $last_date_to_process ? $last_date_to_process : $absolute_last_date;
$last_timestamp_to_process = strtotime( $last_date_to_process );

Expand Down Expand Up @@ -485,6 +485,7 @@ private function translate_occurrence( $occurrence_string ) {
'third' => _x( 'third', 'third as in every third monday of the month', 'openagenda-base' ),
'fourth' => _x( 'fourth', 'fourth as in every fourth monday of the month', 'openagenda-base' ),
'last' => _x( 'last', 'last as in every last monday of the month', 'openagenda-base' ),
'every' => _x( 'every', 'every as in every monday of the month', 'openagenda-base' ),
);

return $occurrence_strings[ $occurrence_string ] ? $occurrence_strings[ $occurrence_string ] : '';
Expand Down Expand Up @@ -779,7 +780,7 @@ public function date_string( $post_id, $long_format = true, $short_format_for_th
++$string_index;

$type = $dates_type;
$meta['repeat_days'] = $meta[ $prefix . 'complex_weekdays' ] ? $meta[ $prefix . 'complex_weekdays' ] : array();
$meta['repeat_days'] = isset( $meta[ $prefix . 'complex_weekdays' ] ) ? $meta[ $prefix . 'complex_weekdays' ] : array();
if ( empty( $meta['repeat_days'] ) ) {
$meta['repeat_days'] = self::all_days();
}
Expand Down
35 changes: 18 additions & 17 deletions src/admin/class-taxonomies.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function create_taxonomies() {
$event_taxonomies_json = get_option( 'event_taxonomies' );
$event_taxonomies_array = json_decode( $event_taxonomies_json, true );

if ( isset( $_POST['new_taxonomy'] ) ) {
if ( ! empty( $_POST['new_taxonomy'] ) ) {
$new_taxonomy = sanitize_text_field( $_POST['new_taxonomy'] );
$new_taxonomy = str_replace( "\\'", "'", $new_taxonomy );

Expand Down Expand Up @@ -143,19 +143,20 @@ public function create_taxonomies() {

update_option( 'event_taxonomies', $event_taxonomies_json );

$delete_taxonomy_text = implode( ', ', $delete_taxonomy);
$delete_taxonomy_text = implode( ', ', $delete_taxonomy );

/* translators: %s: taxonomy name */
if( 1 === count( $delete_taxonomy ) ) {
echo '<div class="updated"><p><strong>' . sprintf( esc_html__( '%s taxonomy deleted', 'openagenda-base' ), esc_html( $delete_taxonomy[0] ) ) . '</strong></p></div>';
} else {
echo '<div class="updated"><p><strong>' . sprintf( esc_html__( '%s taxonomies deleted', 'openagenda-base' ), esc_html( $delete_taxonomy_text ) ) . '</strong></p></div>';
}
if ( 1 === count( $delete_taxonomy ) ) {
/* translators: %s: taxonomy name */
echo '<div class="updated"><p><strong>' . sprintf( esc_html__( '%s taxonomy deleted', 'openagenda-base' ), esc_html( $delete_taxonomy[0] ) ) . '</strong></p></div>';
} else {
/* translators: %s: taxonomies names */
echo '<div class="updated"><p><strong>' . sprintf( esc_html__( '%s taxonomies deleted', 'openagenda-base' ), esc_html( $delete_taxonomy_text ) ) . '</strong></p></div>';
}
}

// Create new taxonomies array after succesfull creation or deletion of taxonomies.
$event_taxonomies_json = get_option( 'event_taxonomies' );
$event_taxonomies_array = json_decode( $event_taxonomies_json, true );
// Create new taxonomies array after succesfull creation or deletion of taxonomies.
$event_taxonomies_json = get_option( 'event_taxonomies' );
$event_taxonomies_array = json_decode( $event_taxonomies_json, true );
?>
<div class="wrap">
<h2>Create Taxonomies</h2>
Expand All @@ -177,12 +178,12 @@ public function create_taxonomies() {
<?php
foreach ( $event_taxonomies_array as $taxonomy ) :
// Try to get the term count for the current taxonomy and if it fails, set it to 0.
$terms = get_terms( strtolower( $taxonomy ) );
if ( is_wp_error( $terms ) ) {
$term_count = 0;
} else {
$term_count = count( $terms );
}
$terms = get_terms( strtolower( $taxonomy ) );
if ( is_wp_error( $terms ) ) {
$term_count = 0;
} else {
$term_count = count( $terms );
}
?>
<tr valign="top">
<th scope="row"><?php echo esc_html( $taxonomy ); ?></th>
Expand Down
19 changes: 11 additions & 8 deletions src/rest_api/class-openagenda-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ public function get_items_locations( $request ) {
'limit' => (int) $posts_query->query_vars['posts_per_page'],
'pages' => array(
'total' => ceil( $posts_query->found_posts / (int) $posts_query->query_vars['posts_per_page'] ),
'current' => (int) $query_args['paged'],
'current' => isset( $query_args['paged'] ) ? (int) $query_args['paged'] : 1,
),
),
'_links' => array(),
Expand Down Expand Up @@ -1561,15 +1561,18 @@ function ( $a, $b ) {
$a_date = $a['next_date'];
$b_date = $b['next_date'];

if ( $a_date['date'] === $b_date['date'] ) {
$a_start_time = $a_date['start_time'];
$b_start_time = $b_date['start_time'];
if ( $a_start_time === $b_start_time ) {
return strcmp( $a['title'], $b['title'] );
if ( isset( $a_date['date'] ) && isset( $b_date['date'] ) ) {
if ( $a_date['date'] === $b_date['date'] ) {
$a_start_time = $a_date['start_time'];
$b_start_time = $b_date['start_time'];
if ( $a_start_time === $b_start_time ) {
return strcmp( $a['title'], $b['title'] );
}
return strcmp( $a_start_time, $b_start_time );
}
return strcmp( $a_start_time, $b_start_time );
return strcmp( $a_date['date'], $b_date['date'] );
}
return strcmp( $a_date['date'], $b_date['date'] );
return 0;
}
);

Expand Down

0 comments on commit 26131c5

Please sign in to comment.