Merge branch 'dns2019' into 'master'

DNS2019

See merge request edb/studentersamfundet-no!1
This commit is contained in:
ponas committed 2019-08-05 22:37:50 +02:00
commit 36c3b1294c
19 files changed
+2030 -559

No files matched your search

+4
View File
@@ -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
Submodule
+1
Submodule dns2019 added at 4ae7527e74.
@@ -1,84 +1,90 @@
<?php
/* Add custom columns. */
function neuf_associations_change_columns( $cols ) {
$custom_cols = array(
'cb' => '<input type="checkbox" />',
'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' => '<input type="checkbox" />',
'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 '<a href="'.$homepage.'" alt="'.$homepage.'" target="_blank">'.$homepage.'</a>';
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 '<a href="'.$large_image_url[0].'" alt="'.$large_image_url[0].'">'.$thumb.'</a>';
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 '<a href="' . $homepage . '" alt="' . $homepage . '" target="_blank">' . $homepage . '</a>';
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 '<a href="' . $large_image_url[0] . '" alt="' . $large_image_url[0] . '">' . $thumb . '</a>';
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);
?>
<div class="misc-pub-section misc-pub-section-last">
<label for="_neuf_associations_homepage"><?php _e( 'Website', 'neuf_assoc' ); ?></label>
<label for="_neuf_associations_homepage"><?php _e('Website', 'neuf_assoc');?></label>
<input type="text" name="_neuf_associations_homepage" value="<?php echo $association_homepage ? $association_homepage : ""; ?>" />
<label for="_neuf_associations_type"><?php _e( 'Type', 'neuf_assoc' ); ?>:</label>
<label for="_neuf_associations_type"><?php _e('Type', 'neuf_assoc');?>:</label>
<select name="_neuf_associations_type">
<?php foreach ($association_types as $type) {
echo '<option value="'.$type.'"';
if($type== $association_type) {
echo ' selected="selected"';
}
echo '>'.$type.'</option>';
}
?>
<?php
foreach ($association_types as $type) {
echo '<option value="' . $type . '"';
if ($type == $association_type) {
echo ' selected="selected"';
}
echo '>' . $type . '</option>';
}
?>
</select><br />
<?php wp_nonce_field( 'neuf_associations_nonce', 'neuf_associations_nonce' ); ?>
<?php wp_nonce_field('neuf_associations_nonce', 'neuf_associations_nonce');?>
</div>
<?php
}
@@ -1,76 +1,114 @@
<?php
/* Setup the custom post type */
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,
'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',
)
);
}
/* 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 ) {
// 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)
{
$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;
}
+16 -16
View File
@@ -1,29 +1,29 @@
<?php
/*
Plugin Name: neuf-associations
Plugin URI: http://www.studentersamfundet.no
Description: Association custom post type
Version: 0.2
Author: EDB-web
Author URI: http://www.studentersamfundet.no
License: GPL v2 or later
Text Domain: neuf_assoc
Plugin Name: neuf-associations
Plugin URI: http://www.studentersamfundet.no
Description: Association custom post type
Version: 0.2
Author: EDB-web
Author URI: http://www.studentersamfundet.no
License: GPL v2 or later
Text Domain: neuf_assoc
*/
/* TODO (nikolark):
* - Pickup stuff from: http://codex.wordpress.org/Post_Types
*/
require_once( 'neuf-associations-post-type.php' );
require_once( 'neuf-associations-admin.php' );
require_once 'neuf-associations-post-type.php';
require_once 'neuf-associations-admin.php';
/* Register the translations */
add_action( 'init' , 'neuf_associations_i18n' , 0 );
add_action('init', 'neuf_associations_i18n', 0);
/* Register the post type */
add_action( 'init' , 'neuf_associations_post_type' , 0 );
add_action( 'save_post' , 'neuf_associations_save_postdata');
add_action('init', 'neuf_associations_post_type', 0);
add_action('save_post', 'neuf_associations_save_postdata');
//add_action( 'publish_post' , 'neuf_associations_save_postdata' );
function neuf_associations_i18n() {
load_plugin_textdomain( 'neuf_assoc', false, dirname( plugin_basename( __FILE__ ) ) .'/languages' );
function neuf_associations_i18n()
{
load_plugin_textdomain('neuf_assoc', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
?>
+224 -185
View File
@@ -1,258 +1,297 @@
<?php
/* Add custom columns. */
function change_columns( $cols ) {
$custom_cols = array(
'cb' => '<input type="checkbox" />',
'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' => '<input type="checkbox" />',
'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() {
?>
<div class="misc-pub-section">
<?php neuf_date_details(); ?>
</div>
<div class="misc-pub-section ">
<?php neuf_event_venue(); ?>
</div>
<div class="misc-pub-section ">
<?php neuf_event_div(); ?>
</div>
<div class="misc-pub-section misc-pub-section-last">
function neuf_event_details()
{
?>
<div class="misc-pub-section">
<?php neuf_date_details(); ?>
</div>
<div class="misc-pub-section ">
<?php neuf_event_venue(); ?>
</div>
<div class="misc-pub-section ">
<?php neuf_event_div(); ?>
</div>
<div class="misc-pub-section misc-pub-section-last">
<?php
/* Only editor or superior can set the promo period */
if ( current_user_can('publish_posts') ) {
neuf_event_promoperiod();
}
/* Only editor or superior can set the promo period */
if (current_user_can('publish_posts')) {
neuf_event_promoperiod();
}
?>
</div>
</div>
<?php
}
/*
* Date & Time
* Note: Jquery datetimepickers is loaded in scripts/timepickdef.js
*/
function neuf_date_details() {
global $post;
function neuf_date_details()
{
global $post;
$start = get_post_meta($post->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' );
?>
<label for="_neuf_events_starttime"><?php _e('Starts', 'neuf_event'); ?>:</label><input type="text" class="datepicker required" name="_neuf_events_starttime" value="<?php echo $start ? date("Y-m-d H:i", $start) : "" ?>" /><br />
<label for="_neuf_events_endtime"><?php _e('Ends', 'neuf_event'); ?>:</label><input name="_neuf_events_endtime" type="text" class="datepicker" value="<?php echo $end ? date("Y-m-d H:i", $end) : "" ?>" /><br />
wp_nonce_field('neuf_events_nonce', 'neuf_events_nonce');
?>
<label for="_neuf_events_starttime"><?php _e('Starts', 'neuf_event'); ?>:</label><input type="text" class="datepicker required" name="_neuf_events_starttime" value="<?php echo $start ? date("Y-m-d H:i", $start) : "" ?>" /><br />
<label for="_neuf_events_endtime"><?php _e('Ends', 'neuf_event'); ?>:</label><input name="_neuf_events_endtime" type="text" class="datepicker" value="<?php echo $end ? date("Y-m-d H:i", $end) : "" ?>" /><br />
<?php
}
/* Venue */
function neuf_event_venue(){
global $post;
function neuf_event_venue()
{
global $post;
$venues = array(
'Betong', 'Glassbaren', 'Betonghaven', 'Biblioteket', 'BokCaféen',
'Foajeen', 'Galleriet', 'Klubbscenen', 'Lillesalen',
'M&oslash;rkerommet', 'Teaterscenen', 'Storsalen', 'Hele huset',
);
$neuf_event_venue = get_post_meta($post->ID, '_neuf_events_venue', true);
_e('Venue:', 'neuf_event');
echo '<select name="_neuf_events_venue">';
$current_custom = get_post_meta($post->ID, '_neuf_events_venue', true);
$current_venue = get_post_meta($post->ID, '_neuf_events_venue_id', true);
$venues = neuf_events_get_venue_map();
// If the custom venue name matches a registered venue,
// show the right venue as selected
if (empty($current_venue) && !empty($current_custom)) {
$found_venue_id = array_search($current_custom, $venues);
if ($found_venue_id) {
$current_venue = $found_venue_id;
$current_custom = '';
}
}
_e('Venue:', 'neuf_event');
echo '<select name="_neuf_events_venue_id">';
$show_custom_input = false;
if (empty($current_venue) && !empty($current_custom)) {
echo '<option value="custom" selected="selected">Fritekst</option>';
$show_custom_input = true;
} else {
echo '<option value="custom">Fritekst</option>';
}
$any = (!empty($current_custom) || !empty($current_venue));
if ($any) {
echo '<option value=""></option>';
} else {
echo '<option value="" selected="selected"></option>';
}
foreach ($venues as $venue_id => $venue_name) {
echo '<option value="' . $venue_id . '"';
if ($venue_id == $current_venue) {
echo ' selected="selected"';
}
echo '>' . $venue_name . '</option>';
}
echo '</select><br />';
?>
<div id="_neuf_events_venue_container" style="<?php echo $show_custom_input ? '' : 'display:none'; ?>">
<label for="_neuf_events_venue"><?php _e("Custom venue:", 'neuf_event'); ?></label>
<input name="_neuf_events_venue" type="text" value="<?php echo $current_custom; ?>"></input><br />
</div>
<?php
$selected = false;
foreach ($venues as $venue) {
echo '<option value="'.$venue.'"';
if($venue == $neuf_event_venue) {
echo ' selected="selected"';
$selected = true;
}
echo '>'.$venue.'</option>';
}
$other = __('Elsewhere', 'neuf_event');
if ( $selected )
echo('<option value="' . $other . '">' . $other . '</option>');
else
echo('<option value="' . $other . '" selected="selected">' . $other . '</option>');
echo '</select><br />';
}
/* 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 '<select name="_neuf_events_promo_period">';
$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 '<select name="_neuf_events_promo_period">';
foreach ($promoperiod as $period) {
echo '<option value="'.$period.'"';
if($period == $neuf_event_promoperiod) {
echo ' selected="selected"';
}
echo '>'.$period.'</option>';
}
echo '</select><br />';
foreach ($promoperiod as $period) {
echo '<option value="' . $period . '"';
if ($period == $neuf_event_promoperiod) {
echo ' selected="selected"';
}
echo '>' . $period . '</option>';
}
echo '</select><br />';
}
/* 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);
?>
<label for="_neuf_events_price_regular"><?php _e("Price Regular", 'neuf_event'); ?></label>
<input name="_neuf_events_price_regular" type="text" value="<?php echo $event_price_regular; ?>"></input><br />
<label for="_neuf_events_price_member"><?php _e("Price Member", 'neuf_event'); ?></label>
<input name="_neuf_events_price_member" type="text" value="<?php echo $event_price_member; ?>"></input><br />
<label for="_neuf_events_bs_url"><?php _e("Billettservice address", 'neuf_event'); ?>:</label>
<input type="text" name="_neuf_events_bs_url" value="<?php echo $event_bs; ?>" /><br />
<label for="_neuf_events_fb_url"><?php _e("Facebook address", 'neuf_event'); ?>:</label>
<input type="text" name="_neuf_events_fb_url" value="<?php echo $event_fb; ?>" />
<?php
?>
<label for="_neuf_events_price_regular"><?php _e("Price Regular", 'neuf_event'); ?></label>
<input name="_neuf_events_price_regular" type="text" value="<?php echo $event_price_regular; ?>"></input><br />
<label for="_neuf_events_price_member"><?php _e("Price Member", 'neuf_event'); ?></label>
<input name="_neuf_events_price_member" type="text" value="<?php echo $event_price_member; ?>"></input><br />
<label for="_neuf_events_bs_url"><?php _e("Billettservice address", 'neuf_event'); ?>:</label>
<input type="text" name="_neuf_events_bs_url" value="<?php echo $event_bs; ?>" /><br />
<label for="_neuf_events_fb_url"><?php _e("Facebook address", 'neuf_event'); ?>:</label>
<input type="text" name="_neuf_events_fb_url" value="<?php echo $event_fb; ?>" />
<?php
}
/* Format a unix timestamp respecting the options set in Settings->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 = "<a href='edit.php?post_type=$post_type->name'>$num</a>";
$text = "<a href='edit.php?post_type=$post_type->name'>$text</a>";
}
echo '<tr><td class="first b b-' . $post_type->name . '">' . $num . '</td>';
echo '<td class="t ' . $post_type->name . '">' . $text . '</td></tr>';
if (current_user_can('edit_posts')) {
$num = "<a href='edit.php?post_type=$post_type->name'>$num</a>";
$text = "<a href='edit.php?post_type=$post_type->name'>$text</a>";
}
// Now, let's add a line about our event types
$taxonomy = get_taxonomy( 'event_type' );
echo '<tr><td class="first b b-' . $post_type->name . '">' . $num . '</td>';
echo '<td class="t ' . $post_type->name . '">' . $text . '</td></tr>';
$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 = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>";
$text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>";
}
echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>';
echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>';
$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 = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$num</a>";
$text = "<a href='edit-tags.php?taxonomy=$taxonomy->name'>$text</a>";
}
echo '<tr><td class="first b b-' . $taxonomy->name . '">' . $num . '</td>';
echo '<td class="t ' . $taxonomy->name . '">' . $text . '</td></tr>';
}
add_action( 'right_now_content_table_end' , 'neuf_events_right_now_dashboard' );
add_action('right_now_content_table_end', 'neuf_events_right_now_dashboard');
?>
?>
+54
View File
@@ -0,0 +1,54 @@
<?php
function migrate_event($event)
{
$orig_venue = get_post_meta($event->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');
@@ -3,10 +3,11 @@
/*
* 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 +15,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 +50,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 +59,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 +92,45 @@ 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,
'count_total' => (int)$wp_query->found_posts,
'pages' => $wp_query->max_num_pages,
'events' => $events
'events' => $events,
);
}
protected function is_root_event_type($term) {
return $term->parent == 0;
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;
@@ -132,6 +141,4 @@ class JSON_API_Events_Controller {
return $events;
}
}
?>
+192 -105
View File
@@ -6,84 +6,150 @@
*/
/* 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',
)
);
)
);
}
/* 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;
}
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 ) {
// 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']);
// 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);
}
// Venue fields
$validated_venues = neuf_events_validate_venues(
$_POST['_neuf_events_venue_id'],
$_POST['_neuf_events_venue']
);
[$venue_id, $venue_custom] = $validated_venues;
return $post_id;
$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) {
if (!update_post_meta($post_id, $key, $value)) {
add_post_meta($post_id, $key, $value, true);
}
}
return $post_id;
}
/**
@@ -91,60 +157,80 @@ 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_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_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));
}
/** 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',
'_neuf_events_fb_url' => 'facebook_url',
'_neuf_events_bs_url' => 'ticket_url',
'_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'] ) {
// No endtime? Assume 2 hours
$response->data['end_time'] = $response->data['start_time'] + 7200;
/* 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
// $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();
@@ -160,8 +246,9 @@ function api_add_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'));
@@ -170,18 +257,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);
+207 -51
View File
@@ -4,37 +4,92 @@
*
* 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&oslash;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&aring; ny arrangementstype',
'menu_name' => __('Event Types', 'neuf_event'),
);
register_taxonomy(
'event_type',
array(
'event'
), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array(
'slug' => __( 'eventtype', 'neuf_event' ),
'hierarchical' => true
)
) );
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&oslash;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&aring; 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(
'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,
),
)
);
}
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.
*
@@ -44,40 +99,141 @@ 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);
/* Add custom meta form fields when creating new organizers */
function neuf_events_organizer_create_meta_field($taxonomy)
{
$associations = neuf_associations_get_association_map();
?>
<div class="form-field term-group">
<label for="_neuf_events_organizer_association"><?php _e('Association', 'neuf_event'); ?></label>
<select class="postform" id="_neuf_events_organizer_association" name="_neuf_events_organizer_association">
<option value=""></option>
<?php foreach ($associations as $id => $name) : ?>
<option value="<?php echo $id; ?>" class=""><?php echo $name; ?></option>
<?php endforeach; ?>
</select>
</div>
<?php
}
add_action('event_organizer_add_form_fields', 'neuf_events_organizer_create_meta_field', 10, 2);
/* Save custom meta values when creating a new organizer */
function neuf_events_organizer_create_save_meta($term_id, $tt_id)
{
$field_name = '_neuf_events_organizer_association';
$association_id = $_POST[$field_name];
if (!empty($association_id)) {
add_term_meta($term_id, $field_name, $association_id, true);
}
}
add_action('created_event_organizer', 'neuf_events_organizer_create_save_meta', 10, 2);
/* Add custom meta form fields when editing an organizer */
function neuf_events_organizer_edit_meta_field($term, $taxonomy)
{
$associations = neuf_associations_get_association_map();
$current_association = get_term_meta($term->term_id, '_neuf_events_organizer_association', true);
?>
<tr class="form-field term-group-wrap">
<th scope="row"><label for="_neuf_events_organizer_association"><?php _e('Association', 'neuf_event'); ?></label></th>
<td><select class="postform" id="_neuf_events_organizer_association" name="_neuf_events_organizer_association">
<option value=""></option>
<?php foreach ($associations as $id => $name) : ?>
<option value="<?php echo $id; ?>" <?php selected($id, $current_association); ?>><?php echo $name; ?></option>
<?php endforeach; ?>
</select></td>
</tr>
<?php
}
add_action('event_organizer_edit_form_fields', 'neuf_events_organizer_edit_meta_field', 10, 2);
/* Save custom meta values when editing an organizer */
function neuf_events_organizer_edit_save_meta($term_id, $tt_id)
{
$field_name = '_neuf_events_organizer_association';
$association_id = $_POST[$field_name];
update_term_meta($term_id, $field_name, $association_id);
}
add_action('edited_event_organizer', 'neuf_events_organizer_edit_save_meta', 10, 2);
function neuf_events_event_organizer_add_association_column($columns)
{
$columns['_neuf_events_organizer_association'] = __('Association', 'neuf_event');
return $columns;
}
add_filter('manage_edit-event_organizer_columns', 'neuf_events_event_organizer_add_association_column');
function neuf_events_event_organizer_show_association_content($content, $column_name, $term_id)
{
$associations = neuf_associations_get_association_map();
if ($column_name !== '_neuf_events_organizer_association') {
return $content;
}
$term_id = absint($term_id);
$association_id = get_term_meta($term_id, '_neuf_events_organizer_association', true);
if (!empty($association_id)) {
$content .= esc_attr($associations[$association_id]);
}
return $content;
}
add_filter('manage_event_organizer_custom_column', 'neuf_events_event_organizer_show_association_content', 10, 3);
/** API: Add our custom fields to the event organizers endpoint */
add_filter('rest_prepare_event_organizer', 'neuf_events_rest_organizers_custom_fields', 10, 3);
function neuf_events_rest_organizers_custom_fields($response, $item, $request)
{
$association_id = get_term_meta($item->term_id, '_neuf_events_organizer_association', true);
$response->data['association_id'] = !empty($association_id) ? absint($association_id) : null;
return $response;
}
+30 -23
View File
@@ -1,45 +1,52 @@
<?php
/*
Plugin Name: neuf-events
Plugin URI: http://www.studentersamfundet.no
Description: Events custom post type
Version: 0.3
Author: EDB-web
Author URI: http://www.studentersamfundet.no
License: GPL v2 or later
Plugin Name: neuf-events
Plugin URI: http://www.studentersamfundet.no
Description: Events custom post type
Version: 0.3
Author: EDB-web
Author URI: http://www.studentersamfundet.no
License: GPL v2 or later
*/
/* TODO (nikolark):
* - Pickup stuff from: http://codex.wordpress.org/Post_Types
*/
require_once( 'neuf-events-post-types.php' );
require_once( 'neuf-events-admin.php' );
require_once( 'neuf-events-taxonomies.php' );
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 );
add_action('init', 'neuf_events_i18n', 0);
/* Register the event post type */
add_action( 'init' , 'neuf_events_post_type' , 0 );
add_action( 'save_post' , 'neuf_events_save_post', 100, 2);
add_action( 'publish_neuf_events' , 'neuf_events_publish' );
add_action( 'the_post' , 'neuf_events_the_post' );
add_action('init', 'neuf_events_post_type', 0);
add_action('save_post', 'neuf_events_save_post', 100, 2);
add_action('publish_neuf_events', 'neuf_events_publish');
add_action('the_post', 'neuf_events_the_post');
/* Register taxonomies */
add_action( 'init' , 'neuf_events_register_taxonomies', 1 );
add_action('init', 'neuf_events_register_taxonomies', 1);
function neuf_events_i18n() {
load_plugin_textdomain( 'neuf_event', false, dirname( plugin_basename( __FILE__ ) ) .'/languages' );
function neuf_events_i18n()
{
load_plugin_textdomain('neuf_event', false, dirname(plugin_basename(__FILE__)) . '/languages');
}
/* JSON API controller */
function add_events_controller($controllers) {
$controllers[] = 'events';
return $controllers;
function add_events_controller($controllers)
{
$controllers[] = 'events';
return $controllers;
}
add_filter('json_api_controllers', 'add_events_controller');
function set_events_controller_path() {
return WP_PLUGIN_DIR."/".dirname( plugin_basename( __FILE__ ))."/neuf-events-json-controller.php";
function set_events_controller_path()
{
return WP_PLUGIN_DIR . "/" . dirname(plugin_basename(__FILE__)) . "/neuf-events-json-controller.php";
}
add_filter('json_api_events_controller_path', 'set_events_controller_path');
+114 -27
View File
@@ -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();
});
+339
View File
@@ -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.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
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.
<signature of Ty Coon>, 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.
Binary file not shown.
@@ -0,0 +1,202 @@
# 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 <EMAIL@ADDRESS>, 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 <t@studentersamfundet.no>\n"
"Language-Team: Nikolai Kristiansen <nikolai@studentersamfundet.no>\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 "<option value=\"Annet\">Other</option>"
#~ msgstr "<option value=\"Annet\">Annet</option>"
#~ msgid "Price"
#~ msgstr "Pris:"
@@ -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 <EMAIL@ADDRESS>, 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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 "<option value=\"Annet\">Other</option>"
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 ""
+113
View File
@@ -0,0 +1,113 @@
<?php
/* Add custom columns. */
function neuf_venues_change_columns($cols)
{
$custom_cols = array(
'cb' => '<input type="checkbox" />',
'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 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;
case "show_on_booking_page":
echo get_post_meta($post_id, '_neuf_venues_show_on_booking_page', true) === 'true' ? '&#9745;' : '&#10060;';
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_venues'),
'neuf_venues_meta_sections',
'venue',
'side',
'high'
);
}
function neuf_venues_meta_sections()
{
?>
<div class="misc-pub-section">
<?php neuf_venues_details(); ?>
</div>
<?php
}
/* Custom fields */
function neuf_venues_details()
{
global $post;
wp_nonce_field('neuf_venues_nonce', 'neuf_venues_nonce');
$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";
?>
<label for="_neuf_venues_floor"><?php _e("Floor", 'neuf_venues'); ?></label>
<input name="_neuf_venues_floor" type="text" value="<?php echo $v_floor; ?>"></input><br />
<label for="_neuf_venues_capacity_legal"><?php _e("Legal capacity", 'neuf_venues'); ?></label>
<input name="_neuf_venues_capacity_legal" type="text" value="<?php echo $v_capacity_legal; ?>"></input><br />
<label for="_neuf_venues_capacity_standing"><?php _e("Standing", 'neuf_venues'); ?></label>
<input name="_neuf_venues_capacity_standing" type="text" value="<?php echo $v_capacity_standing; ?>"></input><br />
<label for="_neuf_venues_capacity_sitting"><?php _e("Sitting", 'neuf_venues'); ?></label>
<input name="_neuf_venues_capacity_sitting" type="text" value="<?php echo $v_capacity_sitting; ?>"></input><br />
<label for="_neuf_venues_used_for"><?php _e("Used for", 'neuf_venues'); ?></label>
<input name="_neuf_venues_used_for" type="text" value="<?php echo $v_used_for; ?>"></input><br />
<label for="_neuf_venues_bar"><?php _e("Bar", 'neuf_venues'); ?></label>
<input name="_neuf_venues_bar" type="text" value="<?php echo $v_bar; ?>"></input><br />
<label for="_neuf_venues_audio"><?php _e("Audio", 'neuf_venues'); ?></label>
<input name="_neuf_venues_audio" type="text" value="<?php echo $v_audio; ?>"></input><br />
<label for="_neuf_venues_lighting"><?php _e("Lighting", 'neuf_venue_lighting'); ?></label>
<input name="_neuf_venues_lighting" type="text" value="<?php echo $v_lighting; ?>"></input><br />
<label for="_neuf_venues_audio_video"><?php _e("A/V", 'neuf_venues'); ?></label>
<input name="_neuf_venues_audio_video" type="text" value="<?php echo $v_audio_video; ?>"></input><br />
<label for="_neuf_venues_preposition"><?php _e("Preposition", 'neuf_venues'); ?></label>
<input name="_neuf_venues_preposition" type="text" value="<?php echo $v_preposition; ?>"></input><br />
<br />
<label for="_neuf_venues_show_on_booking_page">
<input type="checkbox" value="true" <?php checked($v_show_on_booking_page, 'true', true); ?> name="_neuf_venues_show_on_booking_page" />
<?php _e('Show on booking page', 'neuf_venues'); ?>
</label>
<br />
<?php
}
@@ -0,0 +1,144 @@
<?php
/**
* Registers the event post type.
*
* This post type will be used to store events to our system. With events, we mean such events as concerts, movie screenings, parties and so on (as opposed to MouseOverEvents and the like).
*/
/* Create the fields the post type should have */
function neuf_venues_post_type()
{
$labels = array(
'name' => __('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',
'page-attributes',
),
'hierarchial' => false,
'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;
}
$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',
'_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_show_on_booking_page' => 'show_on_booking_page',
'_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;
}
+29
View File
@@ -0,0 +1,29 @@
<?php
/*
Plugin Name: neuf-venues
Plugin URI: https://www.studentersamfundet.no
Description: Venues custom post type
Version: 0.1
Author: EDB
Author URI: https://edb.neuf.no
License: GPL v2 or later
*/
require_once 'neuf-venues-post-types.php';
require_once 'neuf-venues-admin.php';
/* Register the translations */
// add_action( 'init' , 'neuf_venues_i18n' , 0 );
/* Register the event post type */
add_action('init', 'neuf_venues_post_type', 0);
add_action('save_post', 'neuf_venues_save_post', 100, 2);
add_action('publish_neuf_venues', 'neuf_venues_publish');
add_action('the_post', 'neuf_venues_the_post');
/* Register taxonomies */
// add_action( 'init' , 'neuf_events_register_taxonomies', 1 );
// function neuf_events_i18n() {
// load_plugin_textdomain( 'neuf_venues', false, dirname( plugin_basename( __FILE__ ) ) .'/languages' );
// }