Skip to content

Commit

Permalink
more code optim
Browse files Browse the repository at this point in the history
  • Loading branch information
liedekef committed Feb 22, 2024
1 parent ee5b018 commit 6ab5fff
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion eme-calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function eme_get_calendar( $args = '' ) {
// we'll look for events in the requested month and 7 days before and after
$calbegin = "$iPrevYear-$iPrevMonth-$iPrevShowFrom";
$calend = "$iNextYear-$iNextMonth-07";
$events = eme_get_events( 0, "$calbegin--$calend", 'ASC', 0, $location_id, $category, $author, $contact_person, 1, $notcategory );
$events = eme_get_events( scope: "$calbegin--$calend", location_id: $location_id, category: $category, author: $author, contact_person: $contact_person, notcategory: $notcategory );

$eventful_days = [];
if ( $events ) {
Expand Down
2 changes: 1 addition & 1 deletion eme-categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ function eme_get_categories( $eventful = false, $scope = 'future', $extra_condit
$categories = [];
$order_by = ' ORDER BY category_name ASC';
if ( $eventful ) {
$events = eme_get_events( 0, $scope, 'ASC' );
$events = eme_get_events( scope: $scope, order: 'ASC' );
if ( $events ) {
foreach ( $events as $event ) {
if ( ! empty( $event['event_category_ids'] ) ) {
Expand Down
61 changes: 31 additions & 30 deletions eme-events.php
Original file line number Diff line number Diff line change
Expand Up @@ -4069,7 +4069,7 @@ function eme_replace_notes_placeholders( $format, $event = '', $target = 'html'
}

// TEMPLATE TAGS
function eme_get_events_list( $limit, $scope = 'future', $order = 'ASC', $format = '', $format_header = '', $format_footer = '', $echo = 0, $category = '', $showperiod = '', $long_events = 0, $author = '', $contact_person = '', $paging = 0, $event_ids = '', $location_id = '', $user_registered_only = 0, $show_ongoing = 1, $link_showperiod = 0, $notcategory = '', $show_recurrent_events_once = 0, $template_id = 0, $template_id_header = 0, $template_id_footer = 0, $no_events_message = '', $template_id_no_events = 0, $limit_offset = 0 ) {
function eme_get_events_list( $limit, $scope = 'future', $order = 'ASC', $format = '', $format_header = '', $format_footer = '', $echo = 0, $category = '', $showperiod = '', $long_events = 0, $author = '', $contact_person = '', $paging = 0, $event_ids = '', $location_ids = '', $user_registered_only = 0, $show_ongoing = 1, $link_showperiod = 0, $notcategory = '', $show_recurrent_events_once = 0, $template_id = 0, $template_id_header = 0, $template_id_footer = 0, $no_events_message = '', $template_id_no_events = 0, $limit_offset = 0 ) {
global $post;
if ( $limit === '' ) {
$limit = intval(get_option( 'eme_event_list_number_items' ));
Expand Down Expand Up @@ -4203,9 +4203,9 @@ function eme_get_events_list( $limit, $scope = 'future', $order = 'ASC', $format
}
// We request $limit+1 events, so we know if we need to show the pagination link or not.
if ( $limit == 0 ) {
$events = eme_get_events( 0, $scope, $order, $limit_offset, $location_id, $category, $author, $contact_person, $show_ongoing, $notcategory, $show_recurrent_events_once, $extra_conditions );
$events = eme_get_events( scope: $scope, order: $order, offset: $limit_offset, location_id: $location_ids, category: $category, author: $author, contact_person: $contact_person, show_ongoing: $show_ongoing, notcategory: $notcategory, show_recurrent_events_once: $show_recurrent_events_once, extra_conditions: $extra_conditions );
} else {
$events = eme_get_events( $limit + 1, $scope, $order, $limit_offset, $location_id, $category, $author, $contact_person, $show_ongoing, $notcategory, $show_recurrent_events_once, $extra_conditions );
$events = eme_get_events( limit: $limit + 1, scope: $scope, order: $order, offset: $limit_offset, location_id: $location_ids, category: $category, author: $author, contact_person: $contact_person, show_ongoing: $show_ongoing, notcategory: $notcategory, show_recurrent_events_once: $show_recurrent_events_once, extra_conditions: $extra_conditions );
}
$events_count = count( $events );

Expand All @@ -4218,7 +4218,7 @@ function eme_get_events_list( $limit, $scope = 'future', $order = 'ASC', $format
// for normal paging and there're no events, we go back to offset=0 and try again
if ( $events_count == 0 ) {
$limit_offset = 0;
$events = eme_get_events( $limit + 1, $scope, $order, $limit_offset, $location_id, $category, $author, $contact_person, $show_ongoing, $notcategory, $show_recurrent_events_once, $extra_conditions );
$events = eme_get_events( limit: $limit + 1, scope: $scope, order: $order, offset: $limit_offset, location_id: $location_ids, category: $category, author: $author, contact_person: $contact_person, show_ongoing: $show_ongoing, notcategory: $notcategory, show_recurrent_events_once: $show_recurrent_events_once, extra_conditions: $extra_conditions );
$events_count = count( $events );
}
$prev_text = __( 'Previous page', 'events-made-easy' );
Expand Down Expand Up @@ -4308,8 +4308,8 @@ function eme_get_events_list( $limit, $scope = 'future', $order = 'ASC', $format

// to prevent going on indefinitely and thus allowing search bots to go on for ever,
// we stop providing links if there are no more events left
$count_older_events = eme_get_events( 1, '--' . $limit_start, $order, 0, $location_id, $category, $author, $contact_person, $show_ongoing, $notcategory, $show_recurrent_events_once, $extra_conditions, 1 );
$count_newer_events = eme_get_events( 1, '++' . $limit_end, $order, 0, $location_id, $category, $author, $contact_person, $show_ongoing, $notcategory, $show_recurrent_events_once, $extra_conditions, 1 );
$count_older_events = eme_get_events( limit: 1, scope: '--' . $limit_start, order: $order, location_id: $location_ids, category: $category, author: $author, contact_person: $contact_person, show_ongoing: $show_ongoing, notcategory: $notcategory, show_recurrent_events_once: $show_recurrent_events_once, extra_conditions: $extra_conditions, count: 1 );
$count_newer_events = eme_get_events( limit: 1, scope: '++' . $limit_end, order: $order, location_id: $location_ids, category: $category, author: $author, contact_person: $contact_person, show_ongoing: $show_ongoing, notcategory: $notcategory, show_recurrent_events_once: $show_recurrent_events_once, extra_conditions: $extra_conditions, count: 1 );
if ( $count_older_events > 0 ) {
$pagination_top .= "<a class='eme_nav_left' href='" . add_query_arg( [ 'eme_offset' => $prev_offset ], $this_page_url ) . "'>&lt;&lt; $prev_text</a>";
} else {
Expand Down Expand Up @@ -4618,7 +4618,7 @@ function eme_get_events_list_shortcode( $atts ) {
// "#_" here
$format = preg_replace( '/#OTHER/', '#', $format );

$result = eme_get_events_list( $limit, $scope, $order, $format, '', '', 0, $category, $showperiod, $long_events, $author, $contact_person, $paging, $event_id, $location_id, $user_registered_only, $show_ongoing, $link_showperiod, $notcategory, $show_recurrent_events_once, $template_id, $template_id_header, $template_id_footer, $no_events_message, $template_id_no_events, $offset );
$result = eme_get_events_list( limit: $limit, scope: $scope, order: $order, format: $format, category: $category, showperiod: $showperiod, long_events: $long_events, author: $author, contact_person: $contact_person, paging: $paging, event_ids: $event_id, location_id: $location_id, user_registered_only: $user_registered_only, show_ongoing: $show_ongoing, link_showperiod: $link_showperiod, notcategory: $notcategory, show_recurrent_events_once: $show_recurrent_events_once, template_id: $template_id, template_id_header: $template_id_header, template_id_footer: $template_id_footer, no_events_message: $no_events_message, template_id_no_events: $template_id_no_events, limit_offset: $offset );
return $result;
}

Expand Down Expand Up @@ -4684,8 +4684,7 @@ function eme_are_events_available( $scope = 'future', $order = 'ASC', $location_
if ( $scope == '' ) {
$scope = 'future';
}
$events = eme_get_events( 1, $scope, $order, 0, $location_id, $category, $author, $contact_person );

$events = eme_get_events( limit: 1, scope: $scope, order: $order, location_id: $location_id, category: $category, author: $author, contact_person: $contact_person, count: 1 );
if ( empty( $events ) ) {
return false;
} else {
Expand Down Expand Up @@ -4767,26 +4766,28 @@ function eme_get_events( $limit = 0, $scope = 'future', $order = 'ASC', $offset
$orderby = '';
// remove trailing ','
$order = preg_replace( '/,$/', '', $order );
if ( $order == 'ASC' || $order == 'DESC' ) {
$orderby = "ORDER BY event_start $order, event_name $order";
} elseif ( ! eme_is_empty_string( $order ) && preg_match( '/^[\w_\-\, ]+$/', $order ) ) {
$order_arr = [];
$order_by = '';
if ( preg_match( '/^[\w_\-\, ]+$/', $order ) ) {
$order_tmp_arr = explode( ',', $order );
foreach ( $order_tmp_arr as $order_ell ) {
$asc_desc = 'ASC';
if ( preg_match( '/DESC$/', $order_ell ) ) {
$asc_desc = 'DESC';
}
$order_ell = trim( preg_replace( '/ASC$|DESC$|\s/', '', $order_ell ) );
$order_arr[] = "$order_ell $asc_desc";
}
}
if ( ! empty( $order_arr ) ) {
$orderby = 'ORDER BY ' . join( ', ', $order_arr );
} else {
$orderby = 'ORDER BY event_start ASC, event_name ASC';
if ( ! eme_is_empty_string( $order )) {
if ( $order == 'ASC' || $order == 'DESC' ) {
$orderby = "ORDER BY event_start $order, event_name $order";
} elseif ( preg_match( '/^[\w_\-\, ]+$/', $order ) ) {
$order_arr = [];
$order_by = '';
if ( preg_match( '/^[\w_\-\, ]+$/', $order ) ) {
$order_tmp_arr = explode( ',', $order );
foreach ( $order_tmp_arr as $order_ell ) {
$asc_desc = 'ASC';
if ( preg_match( '/DESC$/', $order_ell ) ) {
$asc_desc = 'DESC';
}
$order_ell = trim( preg_replace( '/ASC$|DESC$|\s/', '', $order_ell ) );
$order_arr[] = "$order_ell $asc_desc";
}
}
if ( ! empty( $order_arr ) ) {
$orderby = 'ORDER BY ' . join( ', ', $order_arr );
} else {
$orderby = 'ORDER BY event_start ASC, event_name ASC';
}
}
}

Expand Down Expand Up @@ -10043,7 +10044,7 @@ function eme_ajax_events_list() {
}


$events_count = eme_get_events( scope: $scope, location_id: $location_ids, category: $category, extra_conditions: $where, count: $count_only, include_customformfields: 1, search_customfieldids: $field_ids, search_customfields: $search_customfields );
$events_count = eme_get_events( scope: $scope, order: '', location_id: $location_ids, category: $category, extra_conditions: $where, count: $count_only, include_customformfields: 1, search_customfieldids: $field_ids, search_customfields: $search_customfields );

// datetime is a column in the javascript definition of the events jtable, but of course the db doesn't know this
// so we need to change this into something known, but since eme_get_events can work with "ASC/DESC" only and
Expand Down
4 changes: 2 additions & 2 deletions eme-ical.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function eme_ical() {
$scope = isset( $_GET['scope'] ) ? eme_sanitize_request( urldecode( $_GET['scope'] ) ) : '';
$author = isset( $_GET['author'] ) ? eme_sanitize_request( urldecode( $_GET['author'] ) ) : '';
$contact_person = isset( $_GET['contact_person'] ) ? eme_sanitize_request( urldecode( $_GET['contact_person'] ) ) : '';
$events = eme_get_events( 0, $scope, 'ASC', 0, $location_id, $category, $author, $contact_person, 1, $notcategory );
$events = eme_get_events( scope: $scope, location_id: $location_id, category: $category, author: $author, contact_person: $contact_person, show_ongoing: 1, notcategory: $notcategory );
foreach ( $events as $event ) {
echo eme_ical_single_event( $event, $title_format, $description_format, $location_format );
}
Expand All @@ -232,7 +232,7 @@ function eme_sitemap() {
header( 'Content-type: text/xml; charset=utf-8' );
header( 'Content-Disposition: inline; filename=eme_public.xml' );
echo '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">' . "\n";
$events = eme_get_events( 5000, 'all', 'DESC' );
$events = eme_get_events( limit: 5000, scope: 'all', order: 'DESC' );
if ( ! empty( $events ) ) {
foreach ( $events as $event ) {
// Build Sitemap Elements
Expand Down
2 changes: 1 addition & 1 deletion eme-tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,7 @@ function eme_tasks_signups_shortcode( $atts ) {
}

$extra_conditions_arr[] = 'event_tasks = 1';
$events = eme_get_events( 0, $scope, $order, 0, $location_id, $category, $author, $contact_person, $show_ongoing, $notcategory, $show_recurrent_events_once, $extra_conditions );
$events = eme_get_events( scope: $scope, order: $order, location_id: $location_id, category: $category, author: $author, contact_person: $contact_person, show_ongoing: $show_ongoing, notcategory: $notcategory, show_recurrent_events_once: $show_recurrent_events_once, extra_conditions: $extra_conditions );

foreach ( $events as $event ) {
$tasks = eme_get_event_tasks( $event['event_id'] );
Expand Down

0 comments on commit 6ab5fff

Please sign in to comment.