From 43f235c23a7d1b885331728cf776b5a57d8fcbeb Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Sat, 4 May 2019 18:47:42 +0200 Subject: [PATCH 01/16] Show associations in REST API --- .../neuf-associations-post-type.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/plugins/neuf-associations/neuf-associations-post-type.php b/plugins/neuf-associations/neuf-associations-post-type.php index 026aff02..d399dc0a 100644 --- a/plugins/neuf-associations/neuf-associations-post-type.php +++ b/plugins/neuf-associations/neuf-associations-post-type.php @@ -22,6 +22,8 @@ function neuf_associations_post_type() { 'publicly_queryable' => true, 'query_var' => 'association', 'show_ui' => true, + 'show_in_rest' => true, + 'rest_base' => 'associations', 'capability_type' => 'post', 'supports' => array( 'title', @@ -73,4 +75,21 @@ function neuf_associations_save_postdata( $post_id ) { update_post_meta($post_id, $key, $value); } } -?> + +/** API: Add our custom fields to the events endpoint */ +add_filter('rest_prepare_association', 'neuf_associations_rest_custom_fields', 10, 3); +function neuf_associations_rest_custom_fields($response, $post, $request) { + $custom_field_data = get_post_custom($post->ID); + $field_map = array( + '_neuf_associations_type' => 'association_type', + '_neuf_associations_homepage' => 'association_homepage', + ); + foreach ($field_map as $src => $dst) { + $response->data[$dst] = $custom_field_data[$src][0]; + } + + /* Decode HTML titles */ + // $response->data['title']['decoded'] = html_entity_decode($response->data['title']['rendered'], ENT_QUOTES | ENT_HTML5, 'UTF-8'); + + return $response; +} From 0d14be60561a9cfe36785b31dc110e7fcb3a73e0 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Sat, 4 May 2019 18:49:15 +0200 Subject: [PATCH 02/16] Add namespace to neuf-events rest_prepare_event hook function --- plugins/neuf-events/neuf-events-post-types.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/neuf-events/neuf-events-post-types.php b/plugins/neuf-events/neuf-events-post-types.php index 3d3d4797..586b32a6 100644 --- a/plugins/neuf-events/neuf-events-post-types.php +++ b/plugins/neuf-events/neuf-events-post-types.php @@ -120,8 +120,8 @@ function neuf_events_the_post( &$post ) { /** API: Add our custom fields to the events endpoint */ -add_filter('rest_prepare_event', 'api_add_custom_fields', 10, 3); -function api_add_custom_fields($response, $post, $request) { +add_filter('rest_prepare_event', 'neuf_events_rest_custom_fields', 10, 3); +function neuf_events_rest_custom_fields($response, $post, $request) { $custom_field_data = get_post_custom($post->ID); $field_map = array( '_neuf_events_venue' => 'venue', From dc3c457f8d10e99c6c8f19c565f136fe30fe731f Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Sat, 4 May 2019 18:49:38 +0200 Subject: [PATCH 03/16] Show neuf-events taxonomies in REST API --- plugins/neuf-events/neuf-events-taxonomies.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/neuf-events/neuf-events-taxonomies.php b/plugins/neuf-events/neuf-events-taxonomies.php index 52bb5f1a..7ed5cb41 100644 --- a/plugins/neuf-events/neuf-events-taxonomies.php +++ b/plugins/neuf-events/neuf-events-taxonomies.php @@ -27,6 +27,8 @@ function neuf_events_register_taxonomies() { 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, + 'show_in_rest' => true, + 'rest_base' => 'event_types', 'query_var' => true, 'rewrite' => array( 'slug' => __( 'eventtype', 'neuf_event' ), @@ -80,4 +82,3 @@ function neuf_events_set_default_object_terms( $post_id, $post ) { } } add_action( 'save_post', 'neuf_events_set_default_object_terms', 100, 2 ); -?> From 0ca92815f3b592b264ed996dc695030a2a3f1753 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Sat, 4 May 2019 19:05:09 +0200 Subject: [PATCH 04/16] neuf-events: format PHP code as per PSR-2 --- plugins/neuf-events/neuf-events-admin.php | 353 +++++++++--------- .../neuf-events-json-controller.php | 72 ++-- .../neuf-events/neuf-events-post-types.php | 204 +++++----- .../neuf-events/neuf-events-taxonomies.php | 107 +++--- plugins/neuf-events/neuf-events.php | 49 +-- 5 files changed, 411 insertions(+), 374 deletions(-) diff --git a/plugins/neuf-events/neuf-events-admin.php b/plugins/neuf-events/neuf-events-admin.php index 5db4af93..b6b59ba3 100644 --- a/plugins/neuf-events/neuf-events-admin.php +++ b/plugins/neuf-events/neuf-events-admin.php @@ -1,128 +1,134 @@ '', - 'title' => __( 'Title', 'neuf_event' ), - 'starttime' => __( 'Date & Time', 'neuf_event' ), - 'endtime' => __( 'Ending Date & Time', 'neuf_event'), - 'venue' => __( 'Venue', 'neuf_event' ), - 'type' => __( 'Type', 'neuf_event' ), - 'promoperiod' => __( 'Promo Period', 'neuf_event' ), - 'date' => __( 'Date Published', 'neuf_event' ), - 'author' => __( 'Author', 'neuf_event' ), - ); - return $custom_cols; +function change_columns($cols) +{ + $custom_cols = array( + 'cb' => '', + 'title' => __('Title', 'neuf_event'), + 'starttime' => __('Date & Time', 'neuf_event'), + 'endtime' => __('Ending Date & Time', 'neuf_event'), + 'venue' => __('Venue', 'neuf_event'), + 'type' => __('Type', 'neuf_event'), + 'promoperiod' => __('Promo Period', 'neuf_event'), + 'date' => __('Date Published', 'neuf_event'), + 'author' => __('Author', 'neuf_event'), + ); + return $custom_cols; } -add_filter( "manage_event_posts_columns", "change_columns" ); +add_filter("manage_event_posts_columns", "change_columns"); // Add values to the custom columns -function custom_columns( $column, $post_id ) { - switch ( $column ) { - case "starttime": - $starttime = intval(get_post_meta( $post_id, '_neuf_events_starttime', true)); - echo format_datetime($starttime); - break; - case "endtime": - $endtime = intval(get_post_meta( $post_id, '_neuf_events_endtime', true)); - echo $endtime ? format_datetime($endtime) : __("None", 'neuf_event'); - break; - case "type": - echo the_terms( $post_id , 'event_type', '', ', ', '' ); - break; - case "venue": - echo get_post_meta( $post_id , '_neuf_events_venue', true); - break; - case "promoperiod": - echo get_post_meta( $post_id, '_neuf_events_promo_period', true); - break; - } +function custom_columns($column, $post_id) +{ + switch ($column) { + case "starttime": + $starttime = intval(get_post_meta($post_id, '_neuf_events_starttime', true)); + echo format_datetime($starttime); + break; + case "endtime": + $endtime = intval(get_post_meta($post_id, '_neuf_events_endtime', true)); + echo $endtime ? format_datetime($endtime) : __("None", 'neuf_event'); + break; + case "type": + echo the_terms($post_id, 'event_type', '', ', ', ''); + break; + case "venue": + echo get_post_meta($post_id, '_neuf_events_venue', true); + break; + case "promoperiod": + echo get_post_meta($post_id, '_neuf_events_promo_period', true); + break; + } } -add_action( "manage_posts_custom_column" , "custom_columns", 10, 2 ); +add_action("manage_posts_custom_column", "custom_columns", 10, 2); // Make these columns sortable -function sortable_columns( $cols ) { - $custom_cols = array( - 'starttime' => 'starttime', - 'endtime' => 'endtime', - 'type' => 'type', - 'venue' => 'venue', - 'promoperiod' => 'promoperiod', - ); - return array_merge($cols, $custom_cols); +function sortable_columns($cols) +{ + $custom_cols = array( + 'starttime' => 'starttime', + 'endtime' => 'endtime', + 'type' => 'type', + 'venue' => 'venue', + 'promoperiod' => 'promoperiod', + ); + return array_merge($cols, $custom_cols); } -add_filter( "manage_edit-event_sortable_columns", "sortable_columns" ); +add_filter("manage_edit-event_sortable_columns", "sortable_columns"); /* * http://scribu.net/wordpress/custom-sortable-columns.html#comment-4732 */ -function starttime_column_orderby( $vars ) { - if ( isset( $vars['orderby']) ) { - if('starttime' == $vars['orderby'] ) { - $vars = array_merge( $vars, array( +function starttime_column_orderby($vars) +{ + if (isset($vars['orderby'])) { + if ('starttime' == $vars['orderby']) { + $vars = array_merge($vars, array( 'meta_key' => '_neuf_events_starttime', - 'orderby' => 'meta_value' - ) ); + 'orderby' => 'meta_value', + )); } - if ( 'endtime' == $vars['orderby'] ) { - $vars = array_merge( $vars, array( + if ('endtime' == $vars['orderby']) { + $vars = array_merge($vars, array( 'meta_key' => '_neuf_events_endtime', - 'orderby' => 'meta_value' - ) ); + 'orderby' => 'meta_value', + )); } } return $vars; } -add_filter( 'request', 'starttime_column_orderby' ); +add_filter('request', 'starttime_column_orderby'); - -function add_admin_script_and_styles() { +function add_admin_script_and_styles() +{ // Datetime selection and form validation - // Ref: http://trentrichardson.com/examples/timepicker/ + // Ref: http://trentrichardson.com/examples/timepicker/ // Ref: http://docs.jquery.com/Plugins/Validation#API_Documentation wp_register_style('jquery-ui-css', plugins_url("neuf-events/style/jquery-ui.min.css")); - wp_register_style('jquery-ui-timepicker-css', plugins_url("neuf-events/style/jquery-ui-timepicker-addon.css"), array('jquery-ui-css')); + wp_register_style('jquery-ui-timepicker-css', plugins_url("neuf-events/style/jquery-ui-timepicker-addon.css"), array('jquery-ui-css')); - wp_register_script('jquery-ui-timepicker-addon', plugins_url("neuf-events/script/jquery-ui-timepicker-addon.js"), array('jquery-ui-slider', 'jquery-ui-datepicker') ); - wp_register_script('jquery-validate', plugins_url("neuf-events/script/jquery.validate.min.js"), array('jquery')); - wp_register_script('neuf-events', plugins_url("neuf-events/script/neuf_events.js"), array('jquery-ui-timepicker-addon', 'jquery-validate')); + wp_register_script('jquery-ui-timepicker-addon', plugins_url("neuf-events/script/jquery-ui-timepicker-addon.js"), array('jquery-ui-slider', 'jquery-ui-datepicker')); + wp_register_script('jquery-validate', plugins_url("neuf-events/script/jquery.validate.min.js"), array('jquery')); + wp_register_script('neuf-events', plugins_url("neuf-events/script/neuf_events.js"), array('jquery-ui-timepicker-addon', 'jquery-validate')); - wp_enqueue_style('jquery-ui-timepicker-css'); - wp_enqueue_script('neuf-events'); + wp_enqueue_style('jquery-ui-timepicker-css'); + wp_enqueue_script('neuf-events'); } add_action('admin_enqueue_scripts', 'add_admin_script_and_styles'); /* Add metaboxes (with styles) */ -function add_events_metaboxes() { +function add_events_metaboxes() +{ - add_meta_box( - 'neuf_events_details', - __('Event Details', 'neuf_event'), - 'neuf_event_details', - 'event', - 'side', - 'high' - ); + add_meta_box( + 'neuf_events_details', + __('Event Details', 'neuf_event'), + 'neuf_event_details', + 'event', + 'side', + 'high' + ); } -function neuf_event_details() { -?> +function neuf_event_details() +{ + ?>
- +
- +
- +
+/* Only editor or superior can set the promo period */ + if (current_user_can('publish_posts')) { + neuf_event_promoperiod(); + } + ?>
ID, '_neuf_events_starttime', true); - $end = get_post_meta($post->ID, '_neuf_events_endtime', true); + $start = get_post_meta($post->ID, '_neuf_events_starttime', true); + $end = get_post_meta($post->ID, '_neuf_events_endtime', true); - wp_nonce_field( 'neuf_events_nonce','neuf_events_nonce' ); -?> - " />
- " />
+ wp_nonce_field('neuf_events_nonce', 'neuf_events_nonce'); + ?> + " />
+ " />
ID, '_neuf_events_venue', true); - _e('Venue:', 'neuf_event'); - echo ''; - $selected = false; - foreach ($venues as $venue) { - echo ''; - } - $other = __('Elsewhere', 'neuf_event'); - if ( $selected ) - echo(''); - else - echo(''); - echo '
'; + $selected = false; + foreach ($venues as $venue) { + echo ''; + } + $other = __('Elsewhere', 'neuf_event'); + if ($selected) { + echo (''); + } else { + echo (''); + } + + echo '
'; } /* Promo period */ -function neuf_event_promoperiod(){ - global $post; +function neuf_event_promoperiod() +{ + global $post; - $promoperiod = array( - __('Default', 'neuf_event'), __('Week', 'neuf_event'), __('Month', 'neuf_event'), __('Semester', 'neuf_event'), - ); - $neuf_event_promoperiod = get_post_meta($post->ID, '_neuf_events_promo_period', true); - _e('Promo Period', 'neuf_event'); - echo ''; - foreach ($promoperiod as $period) { - echo ''; - } - echo '
'; + foreach ($promoperiod as $period) { + echo ''; + } + echo '
'; } /* Price and additional info. */ -function neuf_event_div() { - global $post; +function neuf_event_div() +{ + global $post; - $event_price_regular = get_post_meta($post->ID, '_neuf_events_price_regular') ? get_post_meta($post->ID, '_neuf_events_price_regular', true) : ""; - $event_price_member = get_post_meta($post->ID, '_neuf_events_price_member') ? get_post_meta($post->ID, '_neuf_events_price_member', true) : ""; - $event_bs = get_post_meta($post->ID, '_neuf_events_bs_url') ? get_post_meta($post->ID, '_neuf_events_bs_url', true) : ""; - $event_fb = get_post_meta($post->ID, '_neuf_events_fb_url', true); + $event_price_regular = get_post_meta($post->ID, '_neuf_events_price_regular') ? get_post_meta($post->ID, '_neuf_events_price_regular', true) : ""; + $event_price_member = get_post_meta($post->ID, '_neuf_events_price_member') ? get_post_meta($post->ID, '_neuf_events_price_member', true) : ""; + $event_bs = get_post_meta($post->ID, '_neuf_events_bs_url') ? get_post_meta($post->ID, '_neuf_events_bs_url', true) : ""; + $event_fb = get_post_meta($post->ID, '_neuf_events_fb_url', true); - ?> - + ?> +
- +
- +
- + General. */ -if( !function_exists('format_datetime') ) { - function format_datetime($timestamp) { - return date_i18n(get_option('date_format')." ".get_option('time_format'), intval($timestamp)); - } +if (!function_exists('format_datetime')) { + function format_datetime($timestamp) + { + return date_i18n(get_option('date_format') . " " . get_option('time_format'), intval($timestamp)); + } } /** * Add our stuff to the 'right now' dashboard widget. */ -function neuf_events_right_now_dashboard() { - // First, let's add a line about our events - $post_type = get_post_type_object( 'event' ); +function neuf_events_right_now_dashboard() +{ + // First, let's add a line about our events + $post_type = get_post_type_object('event'); - $num_posts = wp_count_posts( $post_type->name ); - $num = number_format_i18n( $num_posts->publish ); - $text = _n( $post_type->labels->singular_name, $post_type->labels->name , intval( $num_posts->publish ) ); - if ( current_user_can( 'edit_posts' ) ) { + $num_posts = wp_count_posts($post_type->name); + $num = number_format_i18n($num_posts->publish); + $text = _n($post_type->labels->singular_name, $post_type->labels->name, intval($num_posts->publish)); - $num = "$num"; - $text = "$text"; - } - echo '' . $num . ''; - echo '' . $text . ''; + if (current_user_can('edit_posts')) { + $num = "$num"; + $text = "$text"; + } - // Now, let's add a line about our event types - $taxonomy = get_taxonomy( 'event_type' ); + echo '' . $num . ''; + echo '' . $text . ''; - $num_terms = wp_count_terms( $taxonomy->name ); - $num = number_format_i18n( $num_terms ); - $text = _n( $taxonomy->labels->singular_name, $taxonomy->labels->name , intval( $num_terms )); - if ( current_user_can( 'manage_categories' ) ) { + // Now, let's add a line about our event types + $taxonomy = get_taxonomy('event_type'); - $num = "$num"; - $text = "$text"; - } - echo '' . $num . ''; - echo '' . $text . ''; + $num_terms = wp_count_terms($taxonomy->name); + $num = number_format_i18n($num_terms); + $text = _n($taxonomy->labels->singular_name, $taxonomy->labels->name, intval($num_terms)); + if (current_user_can('manage_categories')) { + + $num = "$num"; + $text = "$text"; + } + echo '' . $num . ''; + echo '' . $text . ''; } -add_action( 'right_now_content_table_end' , 'neuf_events_right_now_dashboard' ); +add_action('right_now_content_table_end', 'neuf_events_right_now_dashboard'); ?> diff --git a/plugins/neuf-events/neuf-events-json-controller.php b/plugins/neuf-events/neuf-events-json-controller.php index 8d7a63b0..37029ef6 100644 --- a/plugins/neuf-events/neuf-events-json-controller.php +++ b/plugins/neuf-events/neuf-events-json-controller.php @@ -3,10 +3,12 @@ /* * Custom events controller providing handy methods. */ -class JSON_API_Events_Controller { +class JSON_API_Events_Controller +{ /* /?json=events.get_today */ - public function get_today() { + public function get_today() + { global $json_api; /* Get query params */ @@ -14,20 +16,20 @@ class JSON_API_Events_Controller { $query = wp_parse_args($url['query']); $meta_query = array( - 'key' => '_neuf_events_starttime', - 'value' => array(date( 'U' , strtotime( '-8 hours' ) ), date( 'U' , strtotime( 'tomorrow' ) )), + 'key' => '_neuf_events_starttime', + 'value' => array(date('U', strtotime('-8 hours')), date('U', strtotime('tomorrow'))), 'compare' => 'BETWEEN', - 'type' => 'NUMERIC' + 'type' => 'NUMERIC', ); $defaults = array( - 'post_type' => 'event', - 'meta_query' => array( $meta_query ), - 'posts_per_page' => 300, - 'orderby' => 'meta_value_num', - 'meta_key' => '_neuf_events_starttime', - 'order' => 'ASC', - 'ignore_sticky_posts' => true + 'post_type' => 'event', + 'meta_query' => array($meta_query), + 'posts_per_page' => 300, + 'orderby' => 'meta_value_num', + 'meta_key' => '_neuf_events_starttime', + 'order' => 'ASC', + 'ignore_sticky_posts' => true, ); // Defaults can easily be overwritten @@ -49,7 +51,8 @@ class JSON_API_Events_Controller { } /* /?json=events.get_upcoming */ - public function get_upcoming() { + public function get_upcoming() + { global $json_api; /* Get query params */ @@ -57,20 +60,20 @@ class JSON_API_Events_Controller { $query = wp_parse_args($url['query']); $meta_query = array( - 'key' => '_neuf_events_starttime', - 'value' => date( 'U' , strtotime( '-8 hours' ) ), + 'key' => '_neuf_events_starttime', + 'value' => date('U', strtotime('-8 hours')), 'compare' => '>', - 'type' => 'numeric' + 'type' => 'numeric', ); $defaults = array( - 'post_type' => 'event', - 'meta_query' => array( $meta_query ), - 'posts_per_page' => 300, - 'orderby' => 'meta_value_num', - 'meta_key' => '_neuf_events_starttime', - 'order' => 'ASC', - 'ignore_sticky_posts' => true + 'post_type' => 'event', + 'meta_query' => array($meta_query), + 'posts_per_page' => 300, + 'orderby' => 'meta_value_num', + 'meta_key' => '_neuf_events_starttime', + 'order' => 'ASC', + 'ignore_sticky_posts' => true, ); // Defaults can easily be overwritten @@ -90,38 +93,42 @@ class JSON_API_Events_Controller { $events = $this->add_parent_root_event_types($events); return $this->events_result($events); } - protected function events_result($events) { + protected function events_result($events) + { global $wp_query; return array( 'count' => count($events), 'count_total' => (int) $wp_query->found_posts, 'pages' => $wp_query->max_num_pages, - 'events' => $events + 'events' => $events, ); } - protected function is_root_event_type($term) { + protected function is_root_event_type($term) + { return $term->parent == 0; } - protected function get_parent_root($term) { - if( $this->is_root_event_type($term) ) { + protected function get_parent_root($term) + { + if ($this->is_root_event_type($term)) { return $term; } $parent_term = null; - foreach($this->event_types as $type) { - if($type->term_id == $term->parent) { + foreach ($this->event_types as $type) { + if ($type->term_id == $term->parent) { $parent_term = $type; break; } } return $this->get_parent_root($parent_term); } - protected function add_parent_root_event_types($events) { + protected function add_parent_root_event_types($events) + { // taxonomy tree $this->event_types = get_terms(array('event_type')); foreach ($events as $event) { $event_types = array(); - foreach ( $event->taxonomy_event_type as $event_type ) { + foreach ($event->taxonomy_event_type as $event_type) { $event_type = $this->get_parent_root($event_type); /* Can be either JSON_API_Category or stdClass */ $name = get_class($event_type) === 'stdClass' ? $event_type->name : $event_type->title; @@ -134,4 +141,3 @@ class JSON_API_Events_Controller { } } -?> diff --git a/plugins/neuf-events/neuf-events-post-types.php b/plugins/neuf-events/neuf-events-post-types.php index 586b32a6..a7532cf7 100644 --- a/plugins/neuf-events/neuf-events-post-types.php +++ b/plugins/neuf-events/neuf-events-post-types.php @@ -6,84 +6,90 @@ */ /* Create the fields the post type should have */ -function neuf_events_post_type() { - $labels = array( - 'name' => __( 'Events', 'neuf_event'), - 'singular_name' => __( 'Event', 'neuf_event'), - 'add_new' => __( 'Add New', 'neuf_event'), - 'add_new_item' => __( 'Add New', 'neuf_event'), - 'edit_item' => __( 'Edit Event', 'neuf_event'), - 'new_item' => __( 'Add New Event', 'neuf_event'), - 'view_item' => __( 'View Event', 'neuf_event'), - 'search_items' => __( 'Search Events', 'neuf_event'), - 'not_found' => __( 'No events found', 'neuf_event'), - 'not_found_in_trash' => __( 'No events found in trash', 'neuf_event') - ); - register_post_type( - 'event', - array( - 'labels' => $labels, - 'menu_position' => 5, - 'public' => true, - 'publicly_queryable' => true, - 'query_var' => 'event', - 'show_ui' => true, - 'capability_type' => 'post', - 'supports' => array( - 'title', - 'editor', - 'author', - 'thumbnail', - 'excerpt', - 'comments', - 'revisions', - 'administrator', - 'custom-fields' - ), - 'register_meta_box_cb' => 'add_events_metaboxes', - 'rewrite' => array( - 'slug' => __( 'event', 'neuf_event' ), - ), +function neuf_events_post_type() +{ + $labels = array( + 'name' => __('Events', 'neuf_event'), + 'singular_name' => __('Event', 'neuf_event'), + 'add_new' => __('Add New', 'neuf_event'), + 'add_new_item' => __('Add New', 'neuf_event'), + 'edit_item' => __('Edit Event', 'neuf_event'), + 'new_item' => __('Add New Event', 'neuf_event'), + 'view_item' => __('View Event', 'neuf_event'), + 'search_items' => __('Search Events', 'neuf_event'), + 'not_found' => __('No events found', 'neuf_event'), + 'not_found_in_trash' => __('No events found in trash', 'neuf_event'), + ); + register_post_type( + 'event', + array( + 'labels' => $labels, + 'menu_position' => 5, + 'public' => true, + 'publicly_queryable' => true, + 'query_var' => 'event', + 'show_ui' => true, + 'capability_type' => 'post', + 'supports' => array( + 'title', + 'editor', + 'author', + 'thumbnail', + 'excerpt', + 'comments', + 'revisions', + 'administrator', + 'custom-fields', + ), + 'register_meta_box_cb' => 'add_events_metaboxes', + 'rewrite' => array( + 'slug' => __('event', 'neuf_event'), + ), 'show_in_rest' => true, 'rest_base' => 'events', 'rest_controller_class' => 'WP_REST_Posts_Controller', - ) - ); + ) + ); } - /* When the post is saved, save our custom data */ -function neuf_events_save_post( $post_id, $post ) { - // verify this came from the our screen and with proper authorization, - // because save_post can be triggered at other times - if ( !array_key_exists('neuf_events_nonce', $_POST) || !wp_verify_nonce( $_POST['neuf_events_nonce'], 'neuf_events_nonce' )) { - return $post_id; - } +function neuf_events_save_post($post_id, $post) +{ + // verify this came from the our screen and with proper authorization, + // because save_post can be triggered at other times + if (!array_key_exists('neuf_events_nonce', $_POST) || !wp_verify_nonce($_POST['neuf_events_nonce'], 'neuf_events_nonce')) { + return $post_id; + } - // If this is an auto save routine, our form has not been submitted, - // and we do nothing. - if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id; + // If this is an auto save routine, our form has not been submitted, + // and we do nothing. + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { + return $post_id; + } - // Check permissions - if ( !current_user_can( 'edit_post', $post_id ) ) return $post_id; + // Check permissions + if (!current_user_can('edit_post', $post_id)) { + return $post_id; + } - // Date strings are converted to unix time - $tosave['_neuf_events_starttime'] = strtotime( $_POST['_neuf_events_starttime'] ); - $tosave['_neuf_events_endtime'] = strtotime( $_POST['_neuf_events_endtime'] ); - $tosave['_neuf_events_price_regular'] = $_POST['_neuf_events_price_regular']; - $tosave['_neuf_events_price_member'] = $_POST['_neuf_events_price_member']; - $tosave['_neuf_events_bs_url'] = $_POST['_neuf_events_bs_url']; - $tosave['_neuf_events_fb_url'] = $_POST['_neuf_events_fb_url']; - $tosave['_neuf_events_venue'] = $_POST['_neuf_events_venue']; - $tosave['_neuf_events_promo_period'] = $_POST['_neuf_events_promo_period']; + // Date strings are converted to unix time + $tosave['_neuf_events_starttime'] = strtotime($_POST['_neuf_events_starttime']); + $tosave['_neuf_events_endtime'] = strtotime($_POST['_neuf_events_endtime']); + $tosave['_neuf_events_price_regular'] = $_POST['_neuf_events_price_regular']; + $tosave['_neuf_events_price_member'] = $_POST['_neuf_events_price_member']; + $tosave['_neuf_events_bs_url'] = $_POST['_neuf_events_bs_url']; + $tosave['_neuf_events_fb_url'] = $_POST['_neuf_events_fb_url']; + $tosave['_neuf_events_venue'] = $_POST['_neuf_events_venue']; + $tosave['_neuf_events_promo_period'] = $_POST['_neuf_events_promo_period']; - // Update or add post meta - foreach($tosave as $key=>$value) - if(!update_post_meta($post_id, $key, $value)) { - add_post_meta($post_id, $key, $value, true); - } + // Update or add post meta + foreach ($tosave as $key => $value) { + if (!update_post_meta($post_id, $key, $value)) { + add_post_meta($post_id, $key, $value, true); + } + } - return $post_id; + return $post_id; } /** @@ -91,37 +97,39 @@ function neuf_events_save_post( $post_id, $post ) { * * Add some handy variables to the global $post. Added to the 'the_post' action hook. */ -function neuf_events_the_post( &$post ) { - // Only apply to events - if ( 'event' != get_post_type() ) - return; +function neuf_events_the_post(&$post) +{ + // Only apply to events + if ('event' != get_post_type()) { + return; + } - $post->neuf_events_venue = get_post_meta( get_the_ID() , '_neuf_events_venue' , true ); - $post->neuf_events_fb_url = get_post_meta( get_the_ID() , '_neuf_events_fb_url' , true ); - $post->neuf_events_ticket_url = get_post_meta( get_the_ID() , '_neuf_events_bs_url' , true ); - $post->neuf_events_price_regular = get_post_meta( get_the_ID() , '_neuf_events_price_regular' , true ); - $post->neuf_events_price_member = get_post_meta( get_the_ID() , '_neuf_events_price_member' , true ); - $post->neuf_events_starttime = get_post_meta( get_the_ID() , '_neuf_events_starttime' , true ); - $post->neuf_events_endtime = get_post_meta( get_the_ID() , '_neuf_events_endtime' , true ); + $post->neuf_events_venue = get_post_meta(get_the_ID(), '_neuf_events_venue', true); + $post->neuf_events_fb_url = get_post_meta(get_the_ID(), '_neuf_events_fb_url', true); + $post->neuf_events_ticket_url = get_post_meta(get_the_ID(), '_neuf_events_bs_url', true); + $post->neuf_events_price_regular = get_post_meta(get_the_ID(), '_neuf_events_price_regular', true); + $post->neuf_events_price_member = get_post_meta(get_the_ID(), '_neuf_events_price_member', true); + $post->neuf_events_starttime = get_post_meta(get_the_ID(), '_neuf_events_starttime', true); + $post->neuf_events_endtime = get_post_meta(get_the_ID(), '_neuf_events_endtime', true); - $post->neuf_events_endtime = $post->neuf_events_endtime ? $post->neuf_events_endtime : $post->neuf_events_starttime + 7200; // No endtime? Assume 2 hours + $post->neuf_events_endtime = $post->neuf_events_endtime ? $post->neuf_events_endtime : $post->neuf_events_starttime + 7200; // No endtime? Assume 2 hours - $post->neuf_events_gcal_url = "http://www.google.com/calendar/event?action=TEMPLATE"; - $post->neuf_events_gcal_url .= "&text=" . rawurlencode(get_the_title()); - $post->neuf_events_gcal_url .= "&details=" . rawurlencode(get_the_excerpt()); - $post->neuf_events_gcal_url .= "&location=Det%20Norske%20Studentersamfund,%20Slemdalsveien%2015,%20Oslo"; - $post->neuf_events_gcal_url .= "&trp=true"; - $post->neuf_events_gcal_url .= "&sprop=website:" . rawurlencode(get_permalink()); - $post->neuf_events_gcal_url .= "&sprop=name:Det%20Norske%20Studentersamfund"; - $post->neuf_events_gcal_url .= "&dates=" . date( 'Ymd\THis\Z' , $post->neuf_events_starttime - ( get_option('gmt_offset') * 3600 ) ); - $post->neuf_events_gcal_url .= "/" . date( 'Ymd\THis\Z' , $post->neuf_events_starttime - ( get_option('gmt_offset') * 3600 ) ); + $post->neuf_events_gcal_url = "http://www.google.com/calendar/event?action=TEMPLATE"; + $post->neuf_events_gcal_url .= "&text=" . rawurlencode(get_the_title()); + $post->neuf_events_gcal_url .= "&details=" . rawurlencode(get_the_excerpt()); + $post->neuf_events_gcal_url .= "&location=Det%20Norske%20Studentersamfund,%20Slemdalsveien%2015,%20Oslo"; + $post->neuf_events_gcal_url .= "&trp=true"; + $post->neuf_events_gcal_url .= "&sprop=website:" . rawurlencode(get_permalink()); + $post->neuf_events_gcal_url .= "&sprop=name:Det%20Norske%20Studentersamfund"; + $post->neuf_events_gcal_url .= "&dates=" . date('Ymd\THis\Z', $post->neuf_events_starttime - (get_option('gmt_offset') * 3600)); + $post->neuf_events_gcal_url .= "/" . date('Ymd\THis\Z', $post->neuf_events_starttime - (get_option('gmt_offset') * 3600)); } - /** API: Add our custom fields to the events endpoint */ add_filter('rest_prepare_event', 'neuf_events_rest_custom_fields', 10, 3); -function neuf_events_rest_custom_fields($response, $post, $request) { +function neuf_events_rest_custom_fields($response, $post, $request) +{ $custom_field_data = get_post_custom($post->ID); $field_map = array( '_neuf_events_venue' => 'venue', @@ -130,16 +138,15 @@ function neuf_events_rest_custom_fields($response, $post, $request) { '_neuf_events_price_regular' => 'price_regular', '_neuf_events_price_member' => 'price_member', '_neuf_events_starttime' => 'start_time', - '_neuf_events_endtime' => 'end_time' - - + '_neuf_events_endtime' => 'end_time', ); + foreach ($field_map as $src => $dst) { $response->data[$dst] = $custom_field_data[$src][0]; } $offset_in_seconds = get_option('gmt_offset') * 3600; - if( !$response->data['end_time'] ) { + if (!$response->data['end_time']) { // No endtime? Assume 2 hours $response->data['end_time'] = $response->data['start_time'] + 7200; } @@ -161,7 +168,8 @@ function neuf_events_rest_custom_fields($response, $post, $request) { /** API: Order by start time */ add_filter('rest_event_query', 'api_change_query', 10, 2); -function api_change_query($args, $request) { +function api_change_query($args, $request) +{ $start_time_field = '_neuf_events_starttime'; $sligthly_in_the_past = date('U', strtotime('-8 hours')); @@ -170,18 +178,18 @@ function api_change_query($args, $request) { 'orderby' => 'meta_value_num', 'meta_key' => $start_time_field, 'order' => 'ASC', - 'ignore_sticky_posts' => true + 'ignore_sticky_posts' => true, ); /* Only show future events? */ $params = $request->get_params(); $future = $params['future'] ?? null; - if( $future ) { + if ($future) { $my_args['meta_query'] = array( 'key' => $start_time_field, 'value' => $sligthly_in_the_past, 'compare' => '>', - 'type' => 'numeric' + 'type' => 'numeric', ); } return array_merge($args, $my_args); diff --git a/plugins/neuf-events/neuf-events-taxonomies.php b/plugins/neuf-events/neuf-events-taxonomies.php index 7ed5cb41..d22afa6a 100644 --- a/plugins/neuf-events/neuf-events-taxonomies.php +++ b/plugins/neuf-events/neuf-events-taxonomies.php @@ -4,37 +4,38 @@ * * We use the taxonomy to differ between different event types, such as concerts, movie screenings and parties. The taxonomy can also be applied to regular posts, so that you can assign terms to a news story. This way, we are able to showcase relevant events alongside our news articles. */ -function neuf_events_register_taxonomies() { - $labels = array( - 'name' => __('Event Types', 'neuf_event'), //Arrangementstype - 'singular_name' => __('Event Type', 'neuf_event'), - 'search_items' => __('Search Event Types', 'neuf_event'),//'Søk etter arrangementstype', - 'all_items' => __('All Event Types', 'neuf_event'), - 'parent_item' => __('Subtype of', 'neuf_event'),//'Undertype av', - 'parent_item_colon' => __('Subtype of:', 'neuf_event'),//'Undertype av:', - 'edit_item' => __('Edit Event Type', 'neuf_event'), - 'update_item' => __('Update Event Type', 'neuf_event'), - 'add_new_item' => __('Add New Event Type', 'neuf_event'), - 'new_item_name' => __('Name', 'neuf_event'),//'Navn på ny arrangementstype', - 'menu_name' => __('Event Types', 'neuf_event'), - ); +function neuf_events_register_taxonomies() +{ + $labels = array( + 'name' => __('Event Types', 'neuf_event'), //Arrangementstype + 'singular_name' => __('Event Type', 'neuf_event'), + 'search_items' => __('Search Event Types', 'neuf_event'), //'Søk etter arrangementstype', + 'all_items' => __('All Event Types', 'neuf_event'), + 'parent_item' => __('Subtype of', 'neuf_event'), //'Undertype av', + 'parent_item_colon' => __('Subtype of:', 'neuf_event'), //'Undertype av:', + 'edit_item' => __('Edit Event Type', 'neuf_event'), + 'update_item' => __('Update Event Type', 'neuf_event'), + 'add_new_item' => __('Add New Event Type', 'neuf_event'), + 'new_item_name' => __('Name', 'neuf_event'), //'Navn på ny arrangementstype', + 'menu_name' => __('Event Types', 'neuf_event'), + ); - register_taxonomy( - 'event_type', - array( - 'event' - ), array( - 'hierarchical' => true, - 'labels' => $labels, - 'show_ui' => true, - 'show_in_rest' => true, - 'rest_base' => 'event_types', - 'query_var' => true, - 'rewrite' => array( - 'slug' => __( 'eventtype', 'neuf_event' ), - 'hierarchical' => true - ) - ) ); + register_taxonomy( + 'event_type', + array( + 'event', + ), array( + 'hierarchical' => true, + 'labels' => $labels, + 'show_ui' => true, + 'show_in_rest' => true, + 'rest_base' => 'event_types', + 'query_var' => true, + 'rewrite' => array( + 'slug' => __('eventtype', 'neuf_event'), + 'hierarchical' => true, + ), + )); } /** @@ -46,39 +47,43 @@ function neuf_events_register_taxonomies() { * * This function was originally written to be able to display different icons on different types of events. */ -function neuf_post_class_event_type( $classes ) { - global $post; +function neuf_post_class_event_type($classes) +{ + global $post; - if ( is_object_in_taxonomy( $post->post_type, 'event_type' ) ) { - foreach ( (array) get_the_terms ( $post->ID , 'event_type' ) as $event_type ) { - if ( empty( $event_type->slug ) ) - continue; - $classes[] = 'event-type-' . sanitize_html_class( $event_type->slug, $event_type->term_id); - } - } + if (is_object_in_taxonomy($post->post_type, 'event_type')) { + foreach ((array) get_the_terms($post->ID, 'event_type') as $event_type) { + if (empty($event_type->slug)) { + continue; + } - return $classes; + $classes[] = 'event-type-' . sanitize_html_class($event_type->slug, $event_type->term_id); + } + } + + return $classes; } -add_filter( 'post_class', 'neuf_post_class_event_type' ); +add_filter('post_class', 'neuf_post_class_event_type'); /* Default terms for custom taxonomies */ -function neuf_events_set_default_object_terms( $post_id, $post ) { +function neuf_events_set_default_object_terms($post_id, $post) +{ /* Make sure it's an event */ - if ( !isset($_POST['post_type']) || $_POST['post_type'] !== 'event' ) { + if (!isset($_POST['post_type']) || $_POST['post_type'] !== 'event') { return; } /* Taxonomy => array of default terms */ $defaults = array( - 'event_type' => array( 'annet' ), - ); - $taxonomies = get_object_taxonomies( $_POST['post_type'] ); - foreach ( (array) $taxonomies as $taxonomy ) { - $terms = wp_get_post_terms( $post_id, $taxonomy ); + 'event_type' => array('annet'), + ); + $taxonomies = get_object_taxonomies($_POST['post_type']); + foreach ((array) $taxonomies as $taxonomy) { + $terms = wp_get_post_terms($post_id, $taxonomy); /* No tax terms assoc with post? */ - if ( empty( $terms ) && array_key_exists( $taxonomy, $defaults ) ) { + if (empty($terms) && array_key_exists($taxonomy, $defaults)) { /* ... then add defaults */ - wp_set_object_terms( $post_id, $defaults[$taxonomy], $taxonomy ); + wp_set_object_terms($post_id, $defaults[$taxonomy], $taxonomy); } } } -add_action( 'save_post', 'neuf_events_set_default_object_terms', 100, 2 ); +add_action('save_post', 'neuf_events_set_default_object_terms', 100, 2); diff --git a/plugins/neuf-events/neuf-events.php b/plugins/neuf-events/neuf-events.php index b3a63717..08cd58e1 100644 --- a/plugins/neuf-events/neuf-events.php +++ b/plugins/neuf-events/neuf-events.php @@ -1,45 +1,48 @@ Date: Sat, 4 May 2019 19:09:33 +0200 Subject: [PATCH 05/16] neuf-associations: format PHP code as per PSR-2 --- .../neuf-associations-admin.php | 128 +++++++++--------- .../neuf-associations-post-type.php | 117 ++++++++-------- .../neuf-associations/neuf-associations.php | 32 ++--- 3 files changed, 144 insertions(+), 133 deletions(-) diff --git a/plugins/neuf-associations/neuf-associations-admin.php b/plugins/neuf-associations/neuf-associations-admin.php index 4ef80716..cf04d5c1 100644 --- a/plugins/neuf-associations/neuf-associations-admin.php +++ b/plugins/neuf-associations/neuf-associations-admin.php @@ -1,84 +1,90 @@ '', - 'title' => __( 'Association', 'neuf_assoc' ), - 'image' => __( 'Image', 'neuf_assoc' ), - 'homepage' => __( 'Website', 'neuf_assoc' ), - 'type' => __( 'Type', 'neuf_assoc' ), - ); - return $custom_cols; +function neuf_associations_change_columns($cols) +{ + $custom_cols = array( + 'cb' => '', + 'title' => __('Association', 'neuf_assoc'), + 'image' => __('Image', 'neuf_assoc'), + 'homepage' => __('Website', 'neuf_assoc'), + 'type' => __('Type', 'neuf_assoc'), + ); + return $custom_cols; } -add_filter( "manage_association_posts_columns", "neuf_associations_change_columns" ); +add_filter("manage_association_posts_columns", "neuf_associations_change_columns"); // Add values to the custom columns -function neuf_associations_custom_columns( $column, $post_id ) { - switch ( $column ) { - case "homepage": - $homepage = get_post_meta( $post_id, '_neuf_associations_homepage', true ); - // default to permalink if not set - $homepage = $homepage ? $homepage : get_permalink( $post_id ); - echo ''.$homepage.''; - break; - case "image": - $thumb = get_the_post_thumbnail( $post_id, array(100, 50) ); - $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'large' ); - echo ''.$thumb.''; - break; - case "type": - echo get_post_meta( $post_id, '_neuf_associations_type', true ); - break; - } +function neuf_associations_custom_columns($column, $post_id) +{ + switch ($column) { + case "homepage": + $homepage = get_post_meta($post_id, '_neuf_associations_homepage', true); + // default to permalink if not set + $homepage = $homepage ? $homepage : get_permalink($post_id); + echo '' . $homepage . ''; + break; + case "image": + $thumb = get_the_post_thumbnail($post_id, array(100, 50)); + $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), 'large'); + echo '' . $thumb . ''; + break; + case "type": + echo get_post_meta($post_id, '_neuf_associations_type', true); + break; + } } -add_action( "manage_posts_custom_column" , "neuf_associations_custom_columns", 10, 2 ); +add_action("manage_posts_custom_column", "neuf_associations_custom_columns", 10, 2); // Make these columns sortable -function neuf_associations_sortable_columns( $cols ) { - $custom_cols = array( - 'type' => 'type', - ); - return array_merge($custom_cols, $cols); +function neuf_associations_sortable_columns($cols) +{ + $custom_cols = array( + 'type' => 'type', + ); + return array_merge($custom_cols, $cols); } -add_filter( "manage_edit-association_sortable_columns", "neuf_associations_sortable_columns" ); +add_filter("manage_edit-association_sortable_columns", "neuf_associations_sortable_columns"); /* Add metaboxes (with styles) */ -function add_associations_metaboxes() { - add_meta_box( - 'neuf_associations_div', - __('Association details', 'neuf_assoc'), - 'neuf_associations_div', - 'association', - 'side' - ); +function add_associations_metaboxes() +{ + add_meta_box( + 'neuf_associations_div', + __('Association details', 'neuf_assoc'), + 'neuf_associations_div', + 'association', + 'side' + ); } - /* Metabox with additional info. */ -function neuf_associations_div(){ - global $post; +function neuf_associations_div() +{ + global $post; - /* Static types */ - $association_types = array('Forening', 'Utvalg'); + /* Static types */ + $association_types = array('Forening', 'Utvalg'); - $association_type = get_post_meta( $post->ID, '_neuf_associations_type', true ); - $association_homepage = get_post_meta( $post->ID, '_neuf_associations_homepage', true ); - ?> + $association_type = get_post_meta($post->ID, '_neuf_associations_type', true); + $association_homepage = get_post_meta($post->ID, '_neuf_associations_homepage', true); + ?>
- + " /> - +
- +
__( 'Associations', 'neuf_assoc'), - 'singular_name' => __( 'Association', 'neuf_assoc'), - 'add_new' => __( 'Add New', 'neuf_assoc'), - 'add_new_item' => __( 'Add New', 'neuf_assoc'), - 'edit_item' => __( 'Edit Association', 'neuf_assoc'), - 'new_item' => __( 'Add New Association', 'neuf_assoc'), - 'view_item' => __( 'View Association', 'neuf_assoc'), - 'search_items' => __( 'Search Associations', 'neuf_assoc'), - 'not_found' => __( 'No associations found', 'neuf_assoc'), - 'not_found_in_trash' => __( 'No associations found in trash', 'neuf_assoc') - ); - register_post_type( - 'association', - array( - 'labels' => $labels, - 'menu_position' => 5, - 'public' => true, - 'publicly_queryable' => true, - 'query_var' => 'association', - 'show_ui' => true, - 'show_in_rest' => true, - 'rest_base' => 'associations', - 'capability_type' => 'post', - 'supports' => array( - 'title', - 'editor', - 'author', - 'thumbnail', - 'excerpt', - 'comments', - 'revisions', - 'administrator', - 'custom-fields' - ), - 'register_meta_box_cb' => 'add_associations_metaboxes', - ) - ); - +function neuf_associations_post_type() +{ + $labels = array( + 'name' => __('Associations', 'neuf_assoc'), + 'singular_name' => __('Association', 'neuf_assoc'), + 'add_new' => __('Add New', 'neuf_assoc'), + 'add_new_item' => __('Add New', 'neuf_assoc'), + 'edit_item' => __('Edit Association', 'neuf_assoc'), + 'new_item' => __('Add New Association', 'neuf_assoc'), + 'view_item' => __('View Association', 'neuf_assoc'), + 'search_items' => __('Search Associations', 'neuf_assoc'), + 'not_found' => __('No associations found', 'neuf_assoc'), + 'not_found_in_trash' => __('No associations found in trash', 'neuf_assoc'), + ); + register_post_type( + 'association', + array( + 'labels' => $labels, + 'menu_position' => 5, + 'public' => true, + 'publicly_queryable' => true, + 'query_var' => 'association', + 'show_ui' => true, + 'show_in_rest' => true, + 'rest_base' => 'associations', + 'capability_type' => 'post', + 'supports' => array( + 'title', + 'editor', + 'author', + 'thumbnail', + 'excerpt', + 'comments', + 'revisions', + 'administrator', + 'custom-fields', + ), + 'register_meta_box_cb' => 'add_associations_metaboxes', + ) + ); } + /* When the post is saved, saves our custom data */ -function neuf_associations_save_postdata( $post_id ) { - // verify if this is an auto save routine. +function neuf_associations_save_postdata($post_id) +{ + // verify if this is an auto save routine. // If it is our form has not been submitted, so we dont want to do anything - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; + } // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times - if ( !array_key_exists('neuf_associations_nonce', $_POST) || !wp_verify_nonce( $_POST['neuf_associations_nonce'], 'neuf_associations_nonce' ) ) - return; - // Check permissions - if ( 'page' == $_POST['post_type'] ) - { - if ( !current_user_can( 'edit_page', $post_id ) ) - return; + if (!array_key_exists('neuf_associations_nonce', $_POST) || !wp_verify_nonce($_POST['neuf_associations_nonce'], 'neuf_associations_nonce')) { + return; } - else - { - if ( !current_user_can( 'edit_post', $post_id ) ) + + // Check permissions + if ('page' == $_POST['post_type']) { + if (!current_user_can('edit_page', $post_id)) { return; + } + } else { + if (!current_user_can('edit_post', $post_id)) { + return; + } } // OK, we're authenticated. // Note esc_url prefixes url with protocol if not present - $meta_data['_neuf_associations_homepage'] = esc_url( $_POST['_neuf_associations_homepage'] ); + $meta_data['_neuf_associations_homepage'] = esc_url($_POST['_neuf_associations_homepage']); $meta_data['_neuf_associations_type'] = $_POST['_neuf_associations_type']; // Update database with meta data - foreach($meta_data as $key => $value) { + foreach ($meta_data as $key => $value) { update_post_meta($post_id, $key, $value); } } /** API: Add our custom fields to the events endpoint */ add_filter('rest_prepare_association', 'neuf_associations_rest_custom_fields', 10, 3); -function neuf_associations_rest_custom_fields($response, $post, $request) { +function neuf_associations_rest_custom_fields($response, $post, $request) +{ $custom_field_data = get_post_custom($post->ID); $field_map = array( '_neuf_associations_type' => 'association_type', diff --git a/plugins/neuf-associations/neuf-associations.php b/plugins/neuf-associations/neuf-associations.php index 0fc3e7d9..66adce64 100644 --- a/plugins/neuf-associations/neuf-associations.php +++ b/plugins/neuf-associations/neuf-associations.php @@ -1,29 +1,29 @@ From d3773c6b3d666180b692b5980b55551301fc6ef3 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Sat, 4 May 2019 19:23:04 +0200 Subject: [PATCH 06/16] neuf-events: Stop assuming end date. Rename function. Prepare for pointing to venues. --- .../neuf-events/neuf-events-post-types.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/plugins/neuf-events/neuf-events-post-types.php b/plugins/neuf-events/neuf-events-post-types.php index a7532cf7..f75cde44 100644 --- a/plugins/neuf-events/neuf-events-post-types.php +++ b/plugins/neuf-events/neuf-events-post-types.php @@ -132,7 +132,10 @@ function neuf_events_rest_custom_fields($response, $post, $request) { $custom_field_data = get_post_custom($post->ID); $field_map = array( + // Deprecated text field '_neuf_events_venue' => 'venue', + // neuf-venues post ID + '_neuf_events_venue_id' => 'venue_id', '_neuf_events_fb_url' => 'facebook_url', '_neuf_events_bs_url' => 'ticket_url', '_neuf_events_price_regular' => 'price_regular', @@ -146,12 +149,14 @@ function neuf_events_rest_custom_fields($response, $post, $request) } $offset_in_seconds = get_option('gmt_offset') * 3600; - if (!$response->data['end_time']) { - // No endtime? Assume 2 hours - $response->data['end_time'] = $response->data['start_time'] + 7200; - } + //if (!$response->data['end_time']) { + // // No endtime? Assume 2 hours + // $response->data['end_time'] = $response->data['start_time'] + 7200; + //} $response->data['start_time'] = date("c", $response->data['start_time'] - $offset_in_seconds); - $response->data['end_time'] = date("c", $response->data['end_time'] - $offset_in_seconds); + if ($response->data['end_time']) { + $response->data['end_time'] = date("c", $response->data['end_time'] - $offset_in_seconds); + } /* Add thumbnail in all sizes */ $sizes = get_intermediate_image_sizes(); @@ -167,8 +172,8 @@ function neuf_events_rest_custom_fields($response, $post, $request) } /** API: Order by start time */ -add_filter('rest_event_query', 'api_change_query', 10, 2); -function api_change_query($args, $request) +add_filter('rest_event_query', 'neuf_events_api_change_query', 10, 2); +function neuf_events_api_change_query($args, $request) { $start_time_field = '_neuf_events_starttime'; $sligthly_in_the_past = date('U', strtotime('-8 hours')); From 2649ab7d13c02e41acbe3b926b36505120e5e839 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Sat, 4 May 2019 19:36:55 +0200 Subject: [PATCH 07/16] neuf-venues: WIP --- plugins/neuf-venues/LICENSE | 339 ++++++++++++++++++ .../languages/neuf_venues-nb_NO.mo | Bin 0 -> 2653 bytes .../languages/neuf_venues-nb_NO.po | 202 +++++++++++ plugins/neuf-venues/languages/neuf_venues.pot | 158 ++++++++ plugins/neuf-venues/neuf-venues-admin.php | 100 ++++++ .../neuf-venues/neuf-venues-post-types.php | 141 ++++++++ plugins/neuf-venues/neuf-venues.php | 29 ++ 7 files changed, 969 insertions(+) create mode 100644 plugins/neuf-venues/LICENSE create mode 100644 plugins/neuf-venues/languages/neuf_venues-nb_NO.mo create mode 100644 plugins/neuf-venues/languages/neuf_venues-nb_NO.po create mode 100644 plugins/neuf-venues/languages/neuf_venues.pot create mode 100644 plugins/neuf-venues/neuf-venues-admin.php create mode 100644 plugins/neuf-venues/neuf-venues-post-types.php create mode 100644 plugins/neuf-venues/neuf-venues.php diff --git a/plugins/neuf-venues/LICENSE b/plugins/neuf-venues/LICENSE new file mode 100644 index 00000000..d159169d --- /dev/null +++ b/plugins/neuf-venues/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/plugins/neuf-venues/languages/neuf_venues-nb_NO.mo b/plugins/neuf-venues/languages/neuf_venues-nb_NO.mo new file mode 100644 index 0000000000000000000000000000000000000000..930c23a817575d3230374c6e6d0c9bfc82f3b278 GIT binary patch literal 2653 zcmZ{kO>7)B6vs^oA5Hlvg|1o|WBmu?Ya2K;Fo2DEQ(72*!?I(RquJ-7?}8N3(#4ZI!PHYUU#a67mIl;Az! z1jy%Sz;W;-$mbg1cJK|5<#j;ZXwKgj+Z z1=)`iAjfqUd;)wO#3L?YV7ZqIz7MjTk3rsl1!R3+gHR=Y1lgWnK)#1xLEird$oj@$ zJnP#5vi&=Y`9YA+RY1PyqaadH)Iioh4|2Y(fJo)6u^hJHNpzOQjeUIzeK-1Z=m*jF zqCbqz@nso&56__QN9R`j650FH7&*UL=K=I*(X+ULZ2zO^>@VBO_Q5S7(b@NX=#Qgw zdo0JM@epPl6K;G5oSzdsDH{6?_ii@62QeFlvO&Wel(jX|e)CK=FAPY`CQ1G=n>sO@ z`mV8JE>05i-jQ94+ay&OT5?XDQl8`i*^K*?zb~e(Bz9d2#VP8jH1VPq#=cNDdd+p! z5=X->SrRoJ#yXN^aaeL9H!~aMDe@{#inT%jdr=sgZF1tYYE#RY-c1whM*FU4C|KAq zlK6y^9h2(t-*Xvj>8*0uZ8V8R%bwP$-y&N~mMBUS#WT}4a*=FoLa|KBw!52xR$g-0 z&?o01WZ5h0F;80_p_Zmodaa6P>=P2%C9DiW4s7mswz5h(C6SF)u^Q8`2>f~muk<0p{~&=qh{tJ2e3zA}JRJtNy)WgYn!SDL4T#Jn6=L}sK8XLL=I8l}7&dr>o z(Z@OEXrO$zDl3Q)RdVlauM*N)g~C=PyTl>2D#Jn0&OL$oX%uUhf6FhpG7_0*;v$3w zlT~?mTr5x&NgpRtUnswOFO`L_5porUp|q>K?y~eki9iJy?ao%MIBjf4dCv1K#e!=^ zRv?Ttk?bX=*CWUEMCA1XKa!3da^CPiqC;gvv4ogLWLeS3E))g3RkxVcnmm3nRE*^$ z^`0fMrl71U`yysb(n{|RS*McoFuuH)yE{5jcv{+m1Eq?S`&nQAOrroc)S4Fah^Q_H zOCrNz?Eij{v2^R#kdtB_L6Qy;6?F;|>bn6lU#u#f#F5P2voaJ6vNA+sdHq@sr_~m7 zw|?MSw5ceG75sLV-IZ!>(, YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: neuf-events\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-09-18 23:23+0100\n" +"PO-Revision-Date: 2012-09-18 23:36+0100\n" +"Last-Translator: Just Thomas Misund \n" +"Language-Team: Nikolai Kristiansen \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Language: \n" +"X-Poedit-Language: Norwegian Bokmal\n" +"X-Poedit-KeywordsList: __;_e\n" +"X-Poedit-Basepath: /home/nikolark/dev/edb/neuf-web/wp-content/plugins/neuf-events/\n" +"X-Poedit-SearchPath-0: .\n" + +#: neuf-events-post-types.php:11 +msgid "Events" +msgstr "Arrangementer" + +#: neuf-events-post-types.php:12 +msgid "Event" +msgstr "Arrangement" + +#: neuf-events-post-types.php:13 +#: neuf-events-post-types.php:14 +msgid "Add New" +msgstr "Legg til ny" + +#: neuf-events-post-types.php:15 +msgid "Edit Event" +msgstr "Rediger arrrangement" + +#: neuf-events-post-types.php:16 +msgid "Add New Event" +msgstr "Legg til nytt arrangement" + +#: neuf-events-post-types.php:17 +msgid "View Event" +msgstr "Vis arrangement" + +#: neuf-events-post-types.php:18 +msgid "Search Events" +msgstr "Søk i arrangementer" + +#: neuf-events-post-types.php:19 +msgid "No events found" +msgstr "Ingen arrangement funnet" + +#: neuf-events-post-types.php:20 +msgid "No events found in trash" +msgstr "Ingen arrangement funnet i søpla" + +#: neuf-events-post-types.php:45 +msgid "event" +msgstr "arrangement" + +#: neuf-events-admin.php:7 +msgid "Title" +msgstr "Tittel" + +#: neuf-events-admin.php:8 +msgid "Date & Time" +msgstr "Dato og klokkeslett" + +#: neuf-events-admin.php:9 +msgid "Ending Date & Time" +msgstr "Sluttdato og -klokkeslett" + +#: neuf-events-admin.php:10 +msgid "Venue" +msgstr "Sted" + +#: neuf-events-admin.php:11 +msgid "Type" +msgstr "Type" + +#: neuf-events-admin.php:12 +#: neuf-events-admin.php:167 +msgid "Promo Period" +msgstr "Promo-periode" + +#: neuf-events-admin.php:13 +msgid "Date Published" +msgstr "Publiseringsdato" + +#: neuf-events-admin.php:14 +msgid "Author" +msgstr "Forfatter" + +#: neuf-events-admin.php:29 +msgid "None" +msgstr "Ikke satt" + +#: neuf-events-admin.php:85 +msgid "Event Details" +msgstr "Arrangementsdetaljer" + +#: neuf-events-admin.php:126 +msgid "Starts" +msgstr "Start" + +#: neuf-events-admin.php:127 +msgid "Ends" +msgstr "Slutt" + +#: neuf-events-admin.php:140 +msgid "Venue:" +msgstr "Sted:" + +#: neuf-events-admin.php:152 +msgid "Elsewhere" +msgstr "Annetsteds" + +#: neuf-events-admin.php:164 +msgid "Default" +msgstr "Standard" + +#: neuf-events-admin.php:164 +msgid "Week" +msgstr "Uke" + +#: neuf-events-admin.php:164 +msgid "Month" +msgstr "Måned" + +#: neuf-events-admin.php:164 +msgid "Semester" +msgstr "Semester" + +#: neuf-events-admin.php:190 +msgid "Price Regular" +msgstr "Vanlig pris" + +#: neuf-events-admin.php:192 +msgid "Price Member" +msgstr "Medlemspris" + +#: neuf-events-admin.php:194 +msgid "Billettservice address" +msgstr "Billettservice adresse" + +#: neuf-events-admin.php:196 +msgid "Facebook address" +msgstr "Facebook adresse" + +#: neuf-events-taxonomies.php:9 +#: neuf-events-taxonomies.php:10 +msgid "Event Type" +msgstr "Arrangementstype" + +#: neuf-events-taxonomies.php:11 +msgid "Search Event Types" +msgstr "Søk i arrangementstyper" + +#: neuf-events-taxonomies.php:12 +msgid "All Event Types" +msgstr "Alle arrangementstyper" + +#: neuf-events-taxonomies.php:13 +msgid "Subtype of" +msgstr "Undertype av" + +#: neuf-events-taxonomies.php:14 +msgid "Subtype of:" +msgstr "Undertype av:" + +#: neuf-events-taxonomies.php:15 +msgid "Edit Event Type" +msgstr "Endre arrangementstype" + +#: neuf-events-taxonomies.php:16 +msgid "Update Event Type" +msgstr "Oppdater arrangementstype" + +#: neuf-events-taxonomies.php:17 +msgid "Add New Event Type" +msgstr "Legg til ny arrangementstype" + +#: neuf-events-taxonomies.php:18 +msgid "Name" +msgstr "Navn" + +#: neuf-events-taxonomies.php:19 +msgid "Event Types" +msgstr "Arrangementstyper" + +#: neuf-events-taxonomies.php:33 +msgid "eventtype" +msgstr "konsept" + +#~ msgid "" +#~ msgstr "" +#~ msgid "Price" +#~ msgstr "Pris:" + diff --git a/plugins/neuf-venues/languages/neuf_venues.pot b/plugins/neuf-venues/languages/neuf_venues.pot new file mode 100644 index 00000000..51e2cfd9 --- /dev/null +++ b/plugins/neuf-venues/languages/neuf_venues.pot @@ -0,0 +1,158 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2012-01-20 21:46+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: neuf-events-admin.php:7 +msgid "Title" +msgstr "" + +#: neuf-events-admin.php:8 +msgid "Date & Time" +msgstr "" + +#: neuf-events-admin.php:9 +msgid "Ending Date & Time" +msgstr "" + +#: neuf-events-admin.php:10 +msgid "Venue" +msgstr "" + +#: neuf-events-admin.php:11 +msgid "Type" +msgstr "" + +#: neuf-events-admin.php:12 +msgid "Date Published" +msgstr "" + +#: neuf-events-admin.php:13 +msgid "Author" +msgstr "" + +#: neuf-events-admin.php:28 +msgid "Ikke satt" +msgstr "" + +#: neuf-events-admin.php:80 +msgid "Event Details" +msgstr "" + +#: neuf-events-admin.php:113 +msgid "Starts" +msgstr "" + +#: neuf-events-admin.php:114 +msgid "Ends" +msgstr "" + +#: neuf-events-admin.php:127 +msgid "Venue:" +msgstr "" + +#: neuf-events-admin.php:137 +msgid "" +msgstr "" + +#: neuf-events-admin.php:150 +msgid "Price" +msgstr "" + +#: neuf-events-admin.php:152 +msgid "Billettservice address" +msgstr "" + +#: neuf-events-admin.php:154 +msgid "Facebook address" +msgstr "" + +#: neuf-events-post-types.php:11 +msgid "Events" +msgstr "" + +#: neuf-events-post-types.php:12 +msgid "Event" +msgstr "" + +#: neuf-events-post-types.php:13 neuf-events-post-types.php:14 +msgid "Add New" +msgstr "" + +#: neuf-events-post-types.php:15 +msgid "Edit Event" +msgstr "" + +#: neuf-events-post-types.php:16 +msgid "Add New Event" +msgstr "" + +#: neuf-events-post-types.php:17 +msgid "View Event" +msgstr "" + +#: neuf-events-post-types.php:18 +msgid "Search Events" +msgstr "" + +#: neuf-events-post-types.php:19 +msgid "No events found" +msgstr "" + +#: neuf-events-post-types.php:20 +msgid "No events found in trash" +msgstr "" + +#: neuf-events-taxonomies.php:9 neuf-events-taxonomies.php:10 +msgid "Event Type" +msgstr "" + +#: neuf-events-taxonomies.php:11 +msgid "Search Event Types" +msgstr "" + +#: neuf-events-taxonomies.php:12 +msgid "All Event Types" +msgstr "" + +#: neuf-events-taxonomies.php:13 +msgid "Subtype of" +msgstr "" + +#: neuf-events-taxonomies.php:14 +msgid "Subtype of:" +msgstr "" + +#: neuf-events-taxonomies.php:15 +msgid "Edit Event Type" +msgstr "" + +#: neuf-events-taxonomies.php:16 +msgid "Update Event Type" +msgstr "" + +#: neuf-events-taxonomies.php:17 +msgid "Add New Event Type" +msgstr "" + +#: neuf-events-taxonomies.php:18 +msgid "Name" +msgstr "" + +#: neuf-events-taxonomies.php:19 +msgid "Event Types" +msgstr "" diff --git a/plugins/neuf-venues/neuf-venues-admin.php b/plugins/neuf-venues/neuf-venues-admin.php new file mode 100644 index 00000000..df09a8cc --- /dev/null +++ b/plugins/neuf-venues/neuf-venues-admin.php @@ -0,0 +1,100 @@ + '', + 'title' => __( 'Title', 'neuf_event' ), + // 'floor' => __( 'Floor', 'neuf_venue' ), + // 'type' => __( 'Type', 'neuf_event' ), + 'date' => __( 'Date Published', 'neuf_event' ), + 'author' => __( 'Author', 'neuf_event' ), + ); + return $custom_cols; +} +add_filter( "manage_venue_posts_columns", "neuf_venues_change_columns" ); + +// Add values to the custom columns +function neuf_venues_custom_columns( $column, $post_id ) { + switch ( $column ) { + case "floor": + echo get_post_meta( $post_id , '_neuf_venues_floor', true); + break; + } +} +add_action( "manage_posts_custom_column" , "neuf_venues_custom_columns", 10, 2 ); + +// Make these columns sortable +function neuf_venues_sortable_columns( $cols ) { + $custom_cols = array( + 'floor' => 'floor', + ); + return array_merge($cols, $custom_cols); +} +add_filter( "manage_edit-venue_sortable_columns", "neuf_venues_sortable_columns" ); + + +/* Add metaboxes (with styles) */ +function add_venues_metaboxes() { + + add_meta_box( + 'neuf_venues_details', + __('Venue Details', 'neuf_venue'), + 'neuf_venue_meta_sections', + 'venue', + 'side', + 'high' + ); +} + +function neuf_venue_meta_sections() { +?> +
+ +
+ID, '_neuf_venues_floor') ? get_post_meta($post->ID, '_neuf_venues_floor', true) : ""; + $v_capacity_legal = get_post_meta($post->ID, '_neuf_venues_capacity_legal') ? get_post_meta($post->ID, '_neuf_venues_capacity_legal', true) : ""; + $v_capacity_standing = get_post_meta($post->ID, '_neuf_venues_capacity_standing') ? get_post_meta($post->ID, '_neuf_venues_capacity_standing', true) : ""; + $v_capacity_sitting = get_post_meta($post->ID, '_neuf_venues_capacity_sitting') ? get_post_meta($post->ID, '_neuf_venues_capacity_sitting', true) : ""; + $v_used_for = get_post_meta($post->ID, '_neuf_venues_used_for') ? get_post_meta($post->ID, '_neuf_venues_used_for', true) : ""; + $v_bar = get_post_meta($post->ID, '_neuf_venues_bar') ? get_post_meta($post->ID, '_neuf_venues_bar', true) : ""; + $v_audio = get_post_meta($post->ID, '_neuf_venues_audio') ? get_post_meta($post->ID, '_neuf_venues_audio', true) : ""; + $v_lighting = get_post_meta($post->ID, '_neuf_venues_lighting') ? get_post_meta($post->ID, '_neuf_venues_lighting', true) : ""; + $v_audio_video = get_post_meta($post->ID, '_neuf_venues_audio_video') ? get_post_meta($post->ID, '_neuf_venues_audio_video', true) : ""; + $v_preposition = get_post_meta($post->ID, '_neuf_venues_preposition') ? get_post_meta($post->ID, '_neuf_venues_preposition', true) : "i"; + + + ?> + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ diff --git a/plugins/neuf-venues/neuf-venues-post-types.php b/plugins/neuf-venues/neuf-venues-post-types.php new file mode 100644 index 00000000..81265948 --- /dev/null +++ b/plugins/neuf-venues/neuf-venues-post-types.php @@ -0,0 +1,141 @@ + __('Venues', 'neuf_venue'), + 'singular_name' => __('Venue', 'neuf_venue'), + 'add_new' => __('Add New', 'neuf_venue'), + 'add_new_item' => __('Add New', 'neuf_venue'), + 'edit_item' => __('Edit Venue', 'neuf_venue'), + 'new_item' => __('Add New Venue', 'neuf_venue'), + 'view_item' => __('View Venue', 'neuf_venue'), + 'search_items' => __('Search Venues', 'neuf_venue'), + 'not_found' => __('No venues found', 'neuf_venue'), + 'not_found_in_trash' => __('No venues found in trash', 'neuf_venue'), + ); + register_post_type( + 'venue', + array( + 'labels' => $labels, + 'menu_position' => 5, + 'public' => true, + 'publicly_queryable' => true, + 'query_var' => 'venue', + 'show_ui' => true, + 'capability_type' => 'post', + 'supports' => array( + 'title', + 'editor', + 'author', + 'thumbnail', + 'excerpt', + 'revisions', + 'administrator', + 'custom-fields', + ), + 'register_meta_box_cb' => 'add_venues_metaboxes', + 'rewrite' => array( + 'slug' => __('venue', 'neuf_venue'), + ), + 'show_in_rest' => true, + 'rest_base' => 'venues', + ) + ); +} + +/* When the post is saved, save our custom data */ +function neuf_venues_save_post($post_id, $post) +{ + // verify this came from the our screen and with proper authorization, + // because save_post can be triggered at other times + if (!array_key_exists('neuf_venues_nonce', $_POST) || !wp_verify_nonce($_POST['neuf_venues_nonce'], 'neuf_venues_nonce')) { + return $post_id; + } + + // If this is an auto save routine, our form has not been submitted, + // and we do nothing. + if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { + return $post_id; + } + + // Check permissions + if (!current_user_can('edit_post', $post_id)) { + return $post_id; + } + + $tosave['_neuf_venues_floor'] = $_POST['_neuf_venues_floor']; + + $fields = array( + '_neuf_venues_floor', + '_neuf_venues_capacity_legal', + '_neuf_venues_capacity_standing', + '_neuf_venues_capacity_sitting', + '_neuf_venues_used_for', + '_neuf_venues_bar', + '_neuf_venues_audio', + '_neuf_venues_lighting', + '_neuf_venues_audio_video', + '_neuf_venues_preposition', + ); + + foreach ($fields as $field_name) { + $tosave[$field_name] = $_POST[$field_name]; + } + + // Update or add post meta + foreach ($tosave as $key => $value) { + if (!update_post_meta($post_id, $key, $value)) { + add_post_meta($post_id, $key, $value, true); + } + } + + return $post_id; +} + +/** + * Set post variables. + * + * Add some handy variables to the global $post. Added to the 'the_post' action hook. + */ +function neuf_venues_the_post(&$post) +{ + // Only apply to events + if ('venue' != get_post_type()) { + return; + } + +} + +/** API: Add our custom fields to the events endpoint */ +add_filter('rest_prepare_venue', 'neuf_venues_rest_custom_fields', 10, 3); +function neuf_venues_rest_custom_fields($response, $post, $request) +{ + $custom_field_data = get_post_custom($post->ID); + $field_map = array( + '_neuf_venues_floor' => 'floor', + '_neuf_venues_capacity_legal' => 'capacity_legal', + '_neuf_venues_capacity_standing' => 'capacity_standing', + '_neuf_venues_capacity_sitting' => 'capacity_sitting', + '_neuf_venues_used_for' => 'used_for', + '_neuf_venues_bar' => 'bar', + '_neuf_venues_audio' => 'audio', + '_neuf_venues_lighting' => 'lighting', + '_neuf_venues_audio_video' => 'audio_video', + '_neuf_venues_preposition' => 'preposition', + ); + foreach ($field_map as $src => $dst) { + $response->data[$dst] = $custom_field_data[$src][0]; + } + + /* Decode HTML titles */ + $response->data['title']['decoded'] = html_entity_decode($response->data['title']['rendered'], ENT_QUOTES | ENT_HTML5, 'UTF-8'); + + return $response; +} diff --git a/plugins/neuf-venues/neuf-venues.php b/plugins/neuf-venues/neuf-venues.php new file mode 100644 index 00000000..16dbd448 --- /dev/null +++ b/plugins/neuf-venues/neuf-venues.php @@ -0,0 +1,29 @@ + Date: Mon, 6 May 2019 14:28:08 +0200 Subject: [PATCH 08/16] neuf-venues: Allow configuring which venues to show on booking page --- plugins/neuf-venues/neuf-venues-admin.php | 167 ++++++++++-------- .../neuf-venues/neuf-venues-post-types.php | 5 +- 2 files changed, 93 insertions(+), 79 deletions(-) diff --git a/plugins/neuf-venues/neuf-venues-admin.php b/plugins/neuf-venues/neuf-venues-admin.php index df09a8cc..b6cbc712 100644 --- a/plugins/neuf-venues/neuf-venues-admin.php +++ b/plugins/neuf-venues/neuf-venues-admin.php @@ -1,100 +1,113 @@ '', - 'title' => __( 'Title', 'neuf_event' ), - // 'floor' => __( 'Floor', 'neuf_venue' ), - // 'type' => __( 'Type', 'neuf_event' ), - 'date' => __( 'Date Published', 'neuf_event' ), - 'author' => __( 'Author', 'neuf_event' ), - ); - return $custom_cols; +function neuf_venues_change_columns($cols) +{ + $custom_cols = array( + 'cb' => '', + 'title' => __('Title', 'neuf_venues'), + 'show_on_booking_page' => __('Show on booking page', 'neuf_venues'), + // 'floor' => __( 'Floor', 'neuf_venues' ), + // 'type' => __( 'Type', 'neuf_venues' ), + 'date' => __('Date Published', 'neuf_venues'), + 'author' => __('Author', 'neuf_venues'), + ); + return $custom_cols; } -add_filter( "manage_venue_posts_columns", "neuf_venues_change_columns" ); +add_filter("manage_venue_posts_columns", "neuf_venues_change_columns"); // Add values to the custom columns -function neuf_venues_custom_columns( $column, $post_id ) { - switch ( $column ) { - case "floor": - echo get_post_meta( $post_id , '_neuf_venues_floor', true); - break; - } +function neuf_venues_custom_columns($column, $post_id) +{ + switch ($column) { + case "floor": + echo get_post_meta($post_id, '_neuf_venues_floor', true); + break; + case "show_on_booking_page": + echo get_post_meta($post_id, '_neuf_venues_show_on_booking_page', true) === 'true' ? '☑' : '❌'; + break; + } } -add_action( "manage_posts_custom_column" , "neuf_venues_custom_columns", 10, 2 ); +add_action("manage_posts_custom_column", "neuf_venues_custom_columns", 10, 2); // Make these columns sortable -function neuf_venues_sortable_columns( $cols ) { - $custom_cols = array( - 'floor' => 'floor', - ); - return array_merge($cols, $custom_cols); +function neuf_venues_sortable_columns($cols) +{ + $custom_cols = array( + 'floor' => 'floor', + ); + return array_merge($cols, $custom_cols); } -add_filter( "manage_edit-venue_sortable_columns", "neuf_venues_sortable_columns" ); - +add_filter("manage_edit-venue_sortable_columns", "neuf_venues_sortable_columns"); /* Add metaboxes (with styles) */ -function add_venues_metaboxes() { +function add_venues_metaboxes() +{ - add_meta_box( - 'neuf_venues_details', - __('Venue Details', 'neuf_venue'), - 'neuf_venue_meta_sections', - 'venue', - 'side', - 'high' - ); + add_meta_box( + 'neuf_venues_details', + __('Venue Details', 'neuf_venues'), + 'neuf_venues_meta_sections', + 'venue', + 'side', + 'high' + ); } -function neuf_venue_meta_sections() { -?> -
- -
+function neuf_venues_meta_sections() +{ + ?> +
+ +
ID, '_neuf_venues_floor') ? get_post_meta($post->ID, '_neuf_venues_floor', true) : ""; - $v_capacity_legal = get_post_meta($post->ID, '_neuf_venues_capacity_legal') ? get_post_meta($post->ID, '_neuf_venues_capacity_legal', true) : ""; - $v_capacity_standing = get_post_meta($post->ID, '_neuf_venues_capacity_standing') ? get_post_meta($post->ID, '_neuf_venues_capacity_standing', true) : ""; - $v_capacity_sitting = get_post_meta($post->ID, '_neuf_venues_capacity_sitting') ? get_post_meta($post->ID, '_neuf_venues_capacity_sitting', true) : ""; - $v_used_for = get_post_meta($post->ID, '_neuf_venues_used_for') ? get_post_meta($post->ID, '_neuf_venues_used_for', true) : ""; - $v_bar = get_post_meta($post->ID, '_neuf_venues_bar') ? get_post_meta($post->ID, '_neuf_venues_bar', true) : ""; - $v_audio = get_post_meta($post->ID, '_neuf_venues_audio') ? get_post_meta($post->ID, '_neuf_venues_audio', true) : ""; - $v_lighting = get_post_meta($post->ID, '_neuf_venues_lighting') ? get_post_meta($post->ID, '_neuf_venues_lighting', true) : ""; - $v_audio_video = get_post_meta($post->ID, '_neuf_venues_audio_video') ? get_post_meta($post->ID, '_neuf_venues_audio_video', true) : ""; - $v_preposition = get_post_meta($post->ID, '_neuf_venues_preposition') ? get_post_meta($post->ID, '_neuf_venues_preposition', true) : "i"; + $v_show_on_booking_page = get_post_meta($post->ID, '_neuf_venues_show_on_booking_page') ? get_post_meta($post->ID, '_neuf_venues_show_on_booking_page', true) : "false"; + $v_floor = get_post_meta($post->ID, '_neuf_venues_floor') ? get_post_meta($post->ID, '_neuf_venues_floor', true) : ""; + $v_capacity_legal = get_post_meta($post->ID, '_neuf_venues_capacity_legal') ? get_post_meta($post->ID, '_neuf_venues_capacity_legal', true) : ""; + $v_capacity_standing = get_post_meta($post->ID, '_neuf_venues_capacity_standing') ? get_post_meta($post->ID, '_neuf_venues_capacity_standing', true) : ""; + $v_capacity_sitting = get_post_meta($post->ID, '_neuf_venues_capacity_sitting') ? get_post_meta($post->ID, '_neuf_venues_capacity_sitting', true) : ""; + $v_used_for = get_post_meta($post->ID, '_neuf_venues_used_for') ? get_post_meta($post->ID, '_neuf_venues_used_for', true) : ""; + $v_bar = get_post_meta($post->ID, '_neuf_venues_bar') ? get_post_meta($post->ID, '_neuf_venues_bar', true) : ""; + $v_audio = get_post_meta($post->ID, '_neuf_venues_audio') ? get_post_meta($post->ID, '_neuf_venues_audio', true) : ""; + $v_lighting = get_post_meta($post->ID, '_neuf_venues_lighting') ? get_post_meta($post->ID, '_neuf_venues_lighting', true) : ""; + $v_audio_video = get_post_meta($post->ID, '_neuf_venues_audio_video') ? get_post_meta($post->ID, '_neuf_venues_audio_video', true) : ""; + $v_preposition = get_post_meta($post->ID, '_neuf_venues_preposition') ? get_post_meta($post->ID, '_neuf_venues_preposition', true) : "i"; - - ?> - -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- + +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+
+ +
+ diff --git a/plugins/neuf-venues/neuf-venues-post-types.php b/plugins/neuf-venues/neuf-venues-post-types.php index 81265948..86274ad9 100644 --- a/plugins/neuf-venues/neuf-venues-post-types.php +++ b/plugins/neuf-venues/neuf-venues-post-types.php @@ -70,7 +70,8 @@ function neuf_venues_save_post($post_id, $post) return $post_id; } - $tosave['_neuf_venues_floor'] = $_POST['_neuf_venues_floor']; + $v_show_on_booking_page = $_POST['_neuf_venues_show_on_booking_page'] === 'true' ? 'true' : 'false'; + $tosave['_neuf_venues_show_on_booking_page'] = $v_show_on_booking_page; $fields = array( '_neuf_venues_floor', @@ -110,7 +111,6 @@ function neuf_venues_the_post(&$post) if ('venue' != get_post_type()) { return; } - } /** API: Add our custom fields to the events endpoint */ @@ -119,6 +119,7 @@ function neuf_venues_rest_custom_fields($response, $post, $request) { $custom_field_data = get_post_custom($post->ID); $field_map = array( + '_neuf_venues_show_on_booking_page' => 'show_on_booking_page', '_neuf_venues_floor' => 'floor', '_neuf_venues_capacity_legal' => 'capacity_legal', '_neuf_venues_capacity_standing' => 'capacity_standing', From 41675c3b2da972443e5b9fd218747c8c6b195d31 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Mon, 6 May 2019 14:34:31 +0200 Subject: [PATCH 09/16] neuf-events: Integrate with neuf-venues, but allow custom free text venues. Make client side validation compatible with WP 5 and Gutenberg. --- plugins/neuf-events/neuf-events-admin.php | 120 +++++++++------ .../neuf-events-json-controller.php | 9 +- .../neuf-events/neuf-events-post-types.php | 67 ++++++++- .../neuf-events/neuf-events-taxonomies.php | 10 +- plugins/neuf-events/script/neuf_events.js | 141 ++++++++++++++---- 5 files changed, 256 insertions(+), 91 deletions(-) diff --git a/plugins/neuf-events/neuf-events-admin.php b/plugins/neuf-events/neuf-events-admin.php index b6b59ba3..0fdb2395 100644 --- a/plugins/neuf-events/neuf-events-admin.php +++ b/plugins/neuf-events/neuf-events-admin.php @@ -113,23 +113,23 @@ function add_events_metaboxes() function neuf_event_details() { ?> -
- -
-
- -
-
- -
-
+
+ +
+
+ +
+
+ +
+
-
+ /* Only editor or superior can set the promo period */ + if (current_user_can('publish_posts')) { + neuf_event_promoperiod(); + } + ?> +
- " />
- " />
+ " />
+ " />
ID, '_neuf_events_venue', true); - _e('Venue:', 'neuf_event'); - echo ''; + + $show_custom_input = false; + if (empty($current_venue) && !empty($current_custom)) { + echo ''; + $show_custom_input = true; } else { - echo (''); + echo ''; + } + + $any = (!empty($current_custom) || !empty($current_venue)); + if ($any) { + echo ''; + } else { + echo ''; + } + + foreach ($venues as $venue_id => $venue_name) { + echo ''; } echo '
'; + + ?> +
+ +
+
+ID, '_neuf_events_fb_url', true); ?> - -
- -
- -
- - - +
+ +
+ +
+ + +General. */ @@ -261,7 +286,6 @@ function neuf_events_right_now_dashboard() $num = number_format_i18n($num_terms); $text = _n($taxonomy->labels->singular_name, $taxonomy->labels->name, intval($num_terms)); if (current_user_can('manage_categories')) { - $num = "$num"; $text = "$text"; } @@ -270,4 +294,4 @@ function neuf_events_right_now_dashboard() } add_action('right_now_content_table_end', 'neuf_events_right_now_dashboard'); -?> +?> \ No newline at end of file diff --git a/plugins/neuf-events/neuf-events-json-controller.php b/plugins/neuf-events/neuf-events-json-controller.php index 37029ef6..3dd0c265 100644 --- a/plugins/neuf-events/neuf-events-json-controller.php +++ b/plugins/neuf-events/neuf-events-json-controller.php @@ -5,7 +5,6 @@ */ class JSON_API_Events_Controller { - /* /?json=events.get_today */ public function get_today() { @@ -93,21 +92,23 @@ class JSON_API_Events_Controller $events = $this->add_parent_root_event_types($events); return $this->events_result($events); } + protected function events_result($events) { global $wp_query; return array( 'count' => count($events), - 'count_total' => (int) $wp_query->found_posts, + 'count_total' => (int)$wp_query->found_posts, 'pages' => $wp_query->max_num_pages, 'events' => $events, ); } + protected function is_root_event_type($term) { return $term->parent == 0; - } + protected function get_parent_root($term) { if ($this->is_root_event_type($term)) { @@ -122,6 +123,7 @@ class JSON_API_Events_Controller } return $this->get_parent_root($parent_term); } + protected function add_parent_root_event_types($events) { // taxonomy tree @@ -139,5 +141,4 @@ class JSON_API_Events_Controller return $events; } - } diff --git a/plugins/neuf-events/neuf-events-post-types.php b/plugins/neuf-events/neuf-events-post-types.php index f75cde44..6729b3f6 100644 --- a/plugins/neuf-events/neuf-events-post-types.php +++ b/plugins/neuf-events/neuf-events-post-types.php @@ -52,6 +52,20 @@ function neuf_events_post_type() ); } +/* Build array('venue ID' => 'venue name', ...) */ +function neuf_events_get_venue_map() +{ + $venues = array(); + $venue_objects = get_posts(array( + 'post_type' => 'venue', + 'numberposts' => -1, + )); + foreach ($venue_objects as $venue) { + $venues[$venue->ID] = $venue->post_title; + } + return $venues; +} + /* When the post is saved, save our custom data */ function neuf_events_save_post($post_id, $post) { @@ -75,12 +89,50 @@ function neuf_events_save_post($post_id, $post) // Date strings are converted to unix time $tosave['_neuf_events_starttime'] = strtotime($_POST['_neuf_events_starttime']); $tosave['_neuf_events_endtime'] = strtotime($_POST['_neuf_events_endtime']); - $tosave['_neuf_events_price_regular'] = $_POST['_neuf_events_price_regular']; - $tosave['_neuf_events_price_member'] = $_POST['_neuf_events_price_member']; - $tosave['_neuf_events_bs_url'] = $_POST['_neuf_events_bs_url']; - $tosave['_neuf_events_fb_url'] = $_POST['_neuf_events_fb_url']; - $tosave['_neuf_events_venue'] = $_POST['_neuf_events_venue']; - $tosave['_neuf_events_promo_period'] = $_POST['_neuf_events_promo_period']; + + // Venue fields + $venue_custom = $_POST['_neuf_events_venue']; + $venue_id = $_POST['_neuf_events_venue_id']; + + $venues = neuf_events_get_venue_map(); + + // If the custom venue name matches a registered venue, + // use the opportunity to store the venue ID instead + if (empty($venue_id) && !empty($venue_custom)) { + $found_venue_id = array_search($venue_custom, $venues); + if ($found_venue_id) { + $venue_id = $found_venue_id; + $venue_custom = ''; + } + } + // Validate venue ID + if (!empty($venue_id) && !array_key_exists($venue_id, $venues)) { + $venue_id = ''; + } + // Strip custom venue if we have a valid venue ID + if (!empty($venue_id) && !empty($venue_custom)) { + $venue_custom = ''; + } + // Fallback to elsewhere + if (empty($venue_id) && empty($venue_custom)) { + $venue_custom = 'Annetsteds'; + } + + $tosave['_neuf_events_venue'] = $venue_custom; + $tosave['_neuf_events_venue_id'] = $venue_id; + + // Other fields are saved as-is + $fields = array( + '_neuf_events_price_regular', + '_neuf_events_price_member', + '_neuf_events_bs_url', + '_neuf_events_fb_url', + '_neuf_events_promo_period', + ); + + foreach ($fields as $field_name) { + $tosave[$field_name] = $_POST[$field_name]; + } // Update or add post meta foreach ($tosave as $key => $value) { @@ -123,7 +175,6 @@ function neuf_events_the_post(&$post) $post->neuf_events_gcal_url .= "&sprop=name:Det%20Norske%20Studentersamfund"; $post->neuf_events_gcal_url .= "&dates=" . date('Ymd\THis\Z', $post->neuf_events_starttime - (get_option('gmt_offset') * 3600)); $post->neuf_events_gcal_url .= "/" . date('Ymd\THis\Z', $post->neuf_events_starttime - (get_option('gmt_offset') * 3600)); - } /** API: Add our custom fields to the events endpoint */ @@ -132,7 +183,7 @@ function neuf_events_rest_custom_fields($response, $post, $request) { $custom_field_data = get_post_custom($post->ID); $field_map = array( - // Deprecated text field + // Text-only venue field '_neuf_events_venue' => 'venue', // neuf-venues post ID '_neuf_events_venue_id' => 'venue_id', diff --git a/plugins/neuf-events/neuf-events-taxonomies.php b/plugins/neuf-events/neuf-events-taxonomies.php index d22afa6a..bff9f78c 100644 --- a/plugins/neuf-events/neuf-events-taxonomies.php +++ b/plugins/neuf-events/neuf-events-taxonomies.php @@ -24,7 +24,8 @@ function neuf_events_register_taxonomies() 'event_type', array( 'event', - ), array( + ), + array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, @@ -35,7 +36,8 @@ function neuf_events_register_taxonomies() 'slug' => __('eventtype', 'neuf_event'), 'hierarchical' => true, ), - )); + ) + ); } /** @@ -52,7 +54,7 @@ function neuf_post_class_event_type($classes) global $post; if (is_object_in_taxonomy($post->post_type, 'event_type')) { - foreach ((array) get_the_terms($post->ID, 'event_type') as $event_type) { + foreach ((array)get_the_terms($post->ID, 'event_type') as $event_type) { if (empty($event_type->slug)) { continue; } @@ -77,7 +79,7 @@ function neuf_events_set_default_object_terms($post_id, $post) 'event_type' => array('annet'), ); $taxonomies = get_object_taxonomies($_POST['post_type']); - foreach ((array) $taxonomies as $taxonomy) { + foreach ((array)$taxonomies as $taxonomy) { $terms = wp_get_post_terms($post_id, $taxonomy); /* No tax terms assoc with post? */ if (empty($terms) && array_key_exists($taxonomy, $defaults)) { diff --git a/plugins/neuf-events/script/neuf_events.js b/plugins/neuf-events/script/neuf_events.js index 4ea5122e..a7157e0c 100644 --- a/plugins/neuf-events/script/neuf_events.js +++ b/plugins/neuf-events/script/neuf_events.js @@ -1,31 +1,118 @@ -jQuery(document).ready(function($){ - /* Datetimepicker */ - $('.datepicker').datetimepicker({ - currentText: 'Nå', - closeText: 'Ok', - hourText: 'Time', - dateFormat: 'yy-mm-dd', - timeFormat: 'HH:mm', - minuteText: 'Minutt', - timeText: 'Tid', - firstDay: 1, - monthNames: ['Januar','Februar','Mars','April','Mai','Juni','Juli','August','September','Oktober','November','Desember'], - dayNames: ['søndag','mandag','tirsdag','onsdag','torsdag','fredag','lørdag'], - dayNamesShort: ['søn','man','tir','ons','tor','fre','lør'], - dayNamesMin: ['sø','ma','ti','on','to','fr','lø'] - }); +jQuery(document).ready(function($) { + /* Only trigger for events */ + if ($("#post_type").val() !== "event") { + return; + } - /* Validation rules */ - if( $('#post_type').val() !== 'event' ) { - return; + /* Datetimepicker */ + $(".datepicker").datetimepicker({ + currentText: "Nå", + closeText: "Ok", + hourText: "Time", + dateFormat: "yy-mm-dd", + timeFormat: "HH:mm", + minuteText: "Minutt", + timeText: "Tid", + firstDay: 1, + monthNames: [ + "Januar", + "Februar", + "Mars", + "April", + "Mai", + "Juni", + "Juli", + "August", + "September", + "Oktober", + "November", + "Desember" + ], + dayNames: [ + "søndag", + "mandag", + "tirsdag", + "onsdag", + "torsdag", + "fredag", + "lørdag" + ], + dayNamesShort: ["søn", "man", "tir", "ons", "tor", "fre", "lør"], + dayNamesMin: ["sø", "ma", "ti", "on", "to", "fr", "lø"] + }); + + $("select[name='_neuf_events_venue_id']").change(function(event) { + if (event.target.value === "custom") { + $("div#_neuf_events_venue_container").show(); + } else { + $("div#_neuf_events_venue_container").hide(); + } + // + }); + + /* Validation rules */ + + /* Prior to WordPress 5 and Gutenberg we could validate the form + and simply e.preventDefault. Now we have this monster. */ + + var startTime = $( + "#neuf_events_details input[name='_neuf_events_starttime']" + ).first(); + var venueCustom = $( + "#neuf_events_details input[name='_neuf_events_venue']" + ).first(); + var venueId = $( + "#neuf_events_details select[name='_neuf_events_venue_id']" + ).first(); + + $.each([startTime, venueCustom, venueId], function(i, obj) { + obj.change(validateEvent); + }); + + function validDateTime(value) { + try { + $.datepicker.parseDateTime("yy-mm-dd", "HH:mm", value); + return true; + } catch (e) { + return false; + } + } + + function complain(errors) { + wp.data.dispatch("core/editor").lockPostSaving("neuf-venues-field-error"); + wp.data + .dispatch("core/notices") + .createNotice( + "error", + "Arrangementet mangler " + errors.join(" og ") + ".", + { + id: "neuf-venues-field-error", + isDismissible: false + } + ); + } + + function stopComplaining() { + wp.data.dispatch("core/editor").unlockPostSaving("neuf-venues-field-error"); + wp.data.dispatch("core/notices").removeNotice("neuf-venues-field-error"); + } + + function validateEvent() { + var errors = []; + + if (!validDateTime(startTime.val())) { + errors.push("starttidspunkt"); + } + if ((venueId.val() === "custom" && !venueCustom.val()) || !venueId.val()) { + errors.push("lokale"); } - $("#post").validate({ - rules: { - neuf_events_start_time: "required" - }, - messages: { - neuf_events_start_time: "Velg startdato og klokkeslett" - } - }); + if (errors.length) { + complain(errors); + } else { + stopComplaining(); + } + } + + validateEvent(); }); From 086ed05739877b0e6aaa7f0fa43dd5447c0306c8 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Mon, 6 May 2019 23:25:14 +0200 Subject: [PATCH 10/16] neuf-events: Add CLI command for migrating venue fields --- plugins/neuf-events/neuf-events-cli.php | 54 +++++++++++++++++ .../neuf-events/neuf-events-post-types.php | 60 +++++++++++-------- plugins/neuf-events/neuf-events.php | 4 ++ 3 files changed, 92 insertions(+), 26 deletions(-) create mode 100644 plugins/neuf-events/neuf-events-cli.php diff --git a/plugins/neuf-events/neuf-events-cli.php b/plugins/neuf-events/neuf-events-cli.php new file mode 100644 index 00000000..e90a29a3 --- /dev/null +++ b/plugins/neuf-events/neuf-events-cli.php @@ -0,0 +1,54 @@ +ID, '_neuf_events_venue', true); + if ($orig_venue === 'BokCaféen') { + $orig_venue = 'Bokcaféen'; + } + + // To handle running script several times + $orig_venue_id = get_post_meta($event->ID, '_neuf_events_venue_id', true); + if (!empty($orig_venue_id)) { + WP_CLI::log('Did nothing for ' . $event->ID); + return; + } + + $validated_venues = neuf_events_validate_venues(null, $orig_venue); + [$venue_id, $venue_custom] = $validated_venues; + + if ($venue_custom === $orig_venue) { + WP_CLI::log('Custom venue for ' . $event->ID . ': ' . $venue_custom); + } else { + WP_CLI::log('Found venue ID for ' . $event->ID . ': ' . $venue_id . ' (' . $orig_venue . ')'); + } + + $saved_id = update_post_meta($event->ID, '_neuf_events_venue_id', $venue_id); + $saved_custom = update_post_meta($event->ID, '_neuf_events_venue', $venue_custom); + + if ($saved_id !== false || $saved_custom !== false) { + return true; + } + return false; +} + +function neuf_events_cli_migrate_venues($args, $args_assoc) +{ + $venues = neuf_events_get_venue_map(); + $events = get_posts(array( + 'post_type' => 'event', + 'numberposts' => -1, + )); + + $changes = 0; + foreach ($events as $event) { + if (migrate_event($event)) { + $changes++; + } + } + + WP_CLI::success('Handled ' . count($events) . ' events'); + WP_CLI::success('Changed ' . $changes . ' events'); +} + +WP_CLI::add_command('neuf-events migrate-venues', 'neuf_events_cli_migrate_venues'); diff --git a/plugins/neuf-events/neuf-events-post-types.php b/plugins/neuf-events/neuf-events-post-types.php index 6729b3f6..3dd6e775 100644 --- a/plugins/neuf-events/neuf-events-post-types.php +++ b/plugins/neuf-events/neuf-events-post-types.php @@ -66,6 +66,35 @@ function neuf_events_get_venue_map() return $venues; } +function neuf_events_validate_venues($venue_id, $venue_custom) +{ + $venues = neuf_events_get_venue_map(); + + // If the custom venue name matches a registered venue, + // use the opportunity to store the venue ID instead + if (empty($venue_id) && !empty($venue_custom)) { + $found_venue_id = array_search($venue_custom, $venues); + if ($found_venue_id) { + $venue_id = $found_venue_id; + $venue_custom = ''; + } + } + // Validate venue ID + if (!empty($venue_id) && !array_key_exists($venue_id, $venues)) { + $venue_id = ''; + } + // Strip custom venue if we have a valid venue ID + if (!empty($venue_id) && !empty($venue_custom)) { + $venue_custom = ''; + } + // Fallback to elsewhere + if (empty($venue_id) && empty($venue_custom)) { + $venue_custom = 'Annetsteds'; + } + + return array($venue_id, $venue_custom); +} + /* When the post is saved, save our custom data */ function neuf_events_save_post($post_id, $post) { @@ -91,32 +120,11 @@ function neuf_events_save_post($post_id, $post) $tosave['_neuf_events_endtime'] = strtotime($_POST['_neuf_events_endtime']); // Venue fields - $venue_custom = $_POST['_neuf_events_venue']; - $venue_id = $_POST['_neuf_events_venue_id']; - - $venues = neuf_events_get_venue_map(); - - // If the custom venue name matches a registered venue, - // use the opportunity to store the venue ID instead - if (empty($venue_id) && !empty($venue_custom)) { - $found_venue_id = array_search($venue_custom, $venues); - if ($found_venue_id) { - $venue_id = $found_venue_id; - $venue_custom = ''; - } - } - // Validate venue ID - if (!empty($venue_id) && !array_key_exists($venue_id, $venues)) { - $venue_id = ''; - } - // Strip custom venue if we have a valid venue ID - if (!empty($venue_id) && !empty($venue_custom)) { - $venue_custom = ''; - } - // Fallback to elsewhere - if (empty($venue_id) && empty($venue_custom)) { - $venue_custom = 'Annetsteds'; - } + $validated_venues = neuf_events_validate_venues( + $_POST['_neuf_events_venue_id'], + $_POST['_neuf_events_venue'] + ); + [$venue_id, $venue_custom] = $validated_venues; $tosave['_neuf_events_venue'] = $venue_custom; $tosave['_neuf_events_venue_id'] = $venue_id; diff --git a/plugins/neuf-events/neuf-events.php b/plugins/neuf-events/neuf-events.php index 08cd58e1..6c6482ef 100644 --- a/plugins/neuf-events/neuf-events.php +++ b/plugins/neuf-events/neuf-events.php @@ -16,6 +16,10 @@ require_once 'neuf-events-post-types.php'; require_once 'neuf-events-admin.php'; require_once 'neuf-events-taxonomies.php'; +if (defined('WP_CLI') && WP_CLI) { + require_once 'neuf-events-cli.php'; +} + /* Register the translations */ add_action('init', 'neuf_events_i18n', 0); From 040b1828e863058cde17744906b24f41bb3536eb Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Tue, 7 May 2019 02:20:46 +0200 Subject: [PATCH 11/16] neuf-events: API: expose both venue ID and custom venue, with backward compatibility --- .../neuf-events/neuf-events-post-types.php | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/plugins/neuf-events/neuf-events-post-types.php b/plugins/neuf-events/neuf-events-post-types.php index 3dd6e775..3b1b6f52 100644 --- a/plugins/neuf-events/neuf-events-post-types.php +++ b/plugins/neuf-events/neuf-events-post-types.php @@ -191,10 +191,6 @@ function neuf_events_rest_custom_fields($response, $post, $request) { $custom_field_data = get_post_custom($post->ID); $field_map = array( - // Text-only venue field - '_neuf_events_venue' => 'venue', - // neuf-venues post ID - '_neuf_events_venue_id' => 'venue_id', '_neuf_events_fb_url' => 'facebook_url', '_neuf_events_bs_url' => 'ticket_url', '_neuf_events_price_regular' => 'price_regular', @@ -207,6 +203,25 @@ function neuf_events_rest_custom_fields($response, $post, $request) $response->data[$dst] = $custom_field_data[$src][0]; } + /* Handle venue fields */ + + /* Contains free text venue if a custom venue is set */ + $venue = $custom_field_data['_neuf_events_venue'][0]; + /* May point to a venue post ID */ + $venue_id = $custom_field_data['_neuf_events_venue_id'][0]; + + if (!empty($venue_id)) { + /* We'll need to look up the venue name for backward compatibility */ + /* TODO: can this be cached? neuf_events_get_venue_map does get_posts */ + $venues = neuf_events_get_venue_map(); + $venue = $venues[$venue_id]; + } else if (empty($venue_id) && empty($venue)) { + $venue = 'Annetsteds'; + } + + $response->data['venue'] = $venue; + $response->data['venue_id'] = $venue_id; + $offset_in_seconds = get_option('gmt_offset') * 3600; //if (!$response->data['end_time']) { // // No endtime? Assume 2 hours From 17c7f3719d07d5daa5f20d36e9f3a5784737e4e8 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Thu, 25 Jul 2019 22:24:16 +0200 Subject: [PATCH 12/16] neuf-venues: Add page-attributes to venues to allow ordering. No need for hierarchial venues. --- plugins/neuf-venues/neuf-venues-post-types.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/neuf-venues/neuf-venues-post-types.php b/plugins/neuf-venues/neuf-venues-post-types.php index 86274ad9..e0f1b41d 100644 --- a/plugins/neuf-venues/neuf-venues-post-types.php +++ b/plugins/neuf-venues/neuf-venues-post-types.php @@ -39,7 +39,9 @@ function neuf_venues_post_type() 'revisions', 'administrator', 'custom-fields', + 'page-attributes', ), + 'hierarchial' => false, 'register_meta_box_cb' => 'add_venues_metaboxes', 'rewrite' => array( 'slug' => __('venue', 'neuf_venue'), From 70f56c2968a89c1fb8ad004bcceb2ea4e2bd4725 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Thu, 25 Jul 2019 22:25:11 +0200 Subject: [PATCH 13/16] neuf-associations: Add a utility function for getting a map of associations --- .../neuf-associations-post-type.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/plugins/neuf-associations/neuf-associations-post-type.php b/plugins/neuf-associations/neuf-associations-post-type.php index 35198f23..591a6e91 100644 --- a/plugins/neuf-associations/neuf-associations-post-type.php +++ b/plugins/neuf-associations/neuf-associations-post-type.php @@ -42,6 +42,20 @@ function neuf_associations_post_type() ); } +/* Build array('association ID' => 'association name', ...) */ +function neuf_associations_get_association_map() +{ + $associations = array(); + $association_objects = get_posts(array( + 'post_type' => 'association', + 'numberposts' => -1, + )); + foreach ($association_objects as $association) { + $associations[$association->ID] = $association->post_title; + } + return $associations; +} + /* When the post is saved, saves our custom data */ function neuf_associations_save_postdata($post_id) { From ed016d3076936e625b381188ab48079eebcba67c Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Thu, 25 Jul 2019 22:25:43 +0200 Subject: [PATCH 14/16] neuf-events: Add an organizer taxonomy to events --- .../neuf-events/neuf-events-taxonomies.php | 170 ++++++++++++++++-- 1 file changed, 159 insertions(+), 11 deletions(-) diff --git a/plugins/neuf-events/neuf-events-taxonomies.php b/plugins/neuf-events/neuf-events-taxonomies.php index bff9f78c..d8f6ff97 100644 --- a/plugins/neuf-events/neuf-events-taxonomies.php +++ b/plugins/neuf-events/neuf-events-taxonomies.php @@ -5,19 +5,30 @@ * We use the taxonomy to differ between different event types, such as concerts, movie screenings and parties. The taxonomy can also be applied to regular posts, so that you can assign terms to a news story. This way, we are able to showcase relevant events alongside our news articles. */ function neuf_events_register_taxonomies() +{ + neuf_events_register_event_type_taxonomy(); + neuf_events_register_organizer_taxonomy(); +} + +function neuf_events_register_event_type_taxonomy() { $labels = array( - 'name' => __('Event Types', 'neuf_event'), //Arrangementstype - 'singular_name' => __('Event Type', 'neuf_event'), - 'search_items' => __('Search Event Types', 'neuf_event'), //'Søk etter arrangementstype', - 'all_items' => __('All Event Types', 'neuf_event'), - 'parent_item' => __('Subtype of', 'neuf_event'), //'Undertype av', - 'parent_item_colon' => __('Subtype of:', 'neuf_event'), //'Undertype av:', - 'edit_item' => __('Edit Event Type', 'neuf_event'), - 'update_item' => __('Update Event Type', 'neuf_event'), - 'add_new_item' => __('Add New Event Type', 'neuf_event'), - 'new_item_name' => __('Name', 'neuf_event'), //'Navn på ny arrangementstype', - 'menu_name' => __('Event Types', 'neuf_event'), + 'name' => __('Event Types', 'neuf_event'), //Arrangementstype + 'singular_name' => __('Event Type', 'neuf_event'), + 'search_items' => __('Search Event Types', 'neuf_event'), //'Søk etter arrangementstype', + 'popular_items' => __('Popular Event Types', 'neuf_event'), + 'all_items' => __('All Event Types', 'neuf_event'), + 'parent_item' => __('Subtype of', 'neuf_event'), //'Undertype av', + 'parent_item_colon' => __('Subtype of:', 'neuf_event'), //'Undertype av:', + 'edit_item' => __('Edit Event Type', 'neuf_event'), + 'update_item' => __('Update Event Type', 'neuf_event'), + 'add_new_item' => __('Add New Event Type', 'neuf_event'), + 'new_item_name' => __('Name', 'neuf_event'), //'Navn på ny arrangementstype', + 'separate_items_with_commas' => __('Separate event types with commas', 'neuf_event'), + 'add_or_remove_items' => __('Add or remove event types', 'neuf_event'), + 'choose_from_most_used' => __('Choose from the most used event types', 'neuf_event'), + 'not_found' => __('No event types found.', 'neuf_event'), + 'menu_name' => __('Event Types', 'neuf_event'), ); register_taxonomy( @@ -40,6 +51,45 @@ function neuf_events_register_taxonomies() ); } +function neuf_events_register_organizer_taxonomy() +{ + $labels = array( + 'name' => __('Organizers', 'neuf_event'), // Arrangører + 'singular_name' => __('Organizer', 'neuf_event'), + 'search_items' => __('Search Organizers', 'neuf_event'), + 'popular_items' => __('Popular Organizers', 'neuf_event'), + 'all_items' => __('All Organizers', 'neuf_event'), + 'edit_item' => __('Edit Organizer', 'neuf_event'), + 'update_item' => __('Update Organizer', 'neuf_event'), + 'add_new_item' => __('Add New Organizer', 'neuf_event'), + 'new_item_name' => __('Name', 'neuf_event'), + 'separate_items_with_commas' => __('Separate organizers with commas', 'neuf_event'), + 'add_or_remove_items' => __('Add or remove organizers', 'neuf_event'), + 'choose_from_most_used' => __('Choose from the most used organizers', 'neuf_event'), + 'not_found' => __('No organizers found.', 'neuf_event'), + 'menu_name' => __('Organizers', 'neuf_event'), + ); + + register_taxonomy( + 'event_organizer', + array( + 'event', + ), + array( + 'hierarchical' => true, + 'labels' => $labels, + 'show_ui' => true, + 'show_in_rest' => true, + 'rest_base' => 'event_organizers', + 'query_var' => true, + 'rewrite' => array( + 'slug' => __('organizer', 'neuf_event'), + ), + ) + ); +} + + /** * Extend post_class() to include event type classes. * @@ -89,3 +139,101 @@ function neuf_events_set_default_object_terms($post_id, $post) } } add_action('save_post', 'neuf_events_set_default_object_terms', 100, 2); + +/* Add custom meta form fields when creating new organizers */ +function neuf_events_organizer_create_meta_field($taxonomy) +{ + $associations = neuf_associations_get_association_map(); + ?> +
+ + +
+term_id, '_neuf_events_organizer_association', true); + ?> + + + + +term_id, '_neuf_events_organizer_association', true); + $response->data['association_id'] = !empty($association_id) ? absint($association_id) : null; + + return $response; +} From 51efe8e72689e6781e850497ba9fdc10038f22c4 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Wed, 31 Jul 2019 23:46:19 +0200 Subject: [PATCH 15/16] Add the dns2019 repo as a submodule tracking master --- .gitmodules | 4 ++++ dns2019 | 1 + 2 files changed, 5 insertions(+) create mode 160000 dns2019 diff --git a/.gitmodules b/.gitmodules index 12fa358c..29ff3b40 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,7 @@ [submodule "plugins/wpdirauth-posixgroup"] path = plugins/wpdirauth-posixgroup url = https://git.neuf.no/edb/wpdirauth.git +[submodule "dns2019"] + path = dns2019 + url = https://git.neuf.no/edb/dns2019.git + branch = master diff --git a/dns2019 b/dns2019 new file mode 160000 index 00000000..1002827a --- /dev/null +++ b/dns2019 @@ -0,0 +1 @@ +Subproject commit 1002827a7238ba4295c12c639f6eccbf882b046e From 61e3b14805c600c7210f275443768cc4e5823c69 Mon Sep 17 00:00:00 2001 From: Jonas Braathen Date: Mon, 5 Aug 2019 22:36:15 +0200 Subject: [PATCH 16/16] Bump dns2019 --- dns2019 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dns2019 b/dns2019 index 1002827a..4ae7527e 160000 --- a/dns2019 +++ b/dns2019 @@ -1 +1 @@ -Subproject commit 1002827a7238ba4295c12c639f6eccbf882b046e +Subproject commit 4ae7527e74a8ed114ff541022d91cdcf2945e4a3