first commit
This commit is contained in:
1
wp-content/plugins/unyson/framework/extensions/events/.gitignore
vendored
Normal file
1
wp-content/plugins/unyson/framework/extensions/events/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
extensions/event-tickets/
|
||||
@@ -0,0 +1,583 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
class FW_Extension_Events extends FW_Extension {
|
||||
private $post_type_name = 'fw-event';
|
||||
private $post_type_slug = 'fw-event-slug';
|
||||
private $taxonomy_name = 'fw-event-taxonomy-name';
|
||||
private $taxonomy_slug = 'fw-event-taxonomy-slug';
|
||||
private $taxonomy_tag_name = 'fw-event-tag';
|
||||
private $taxonomy_tag_slug = 'event-tag';
|
||||
|
||||
/**
|
||||
* @var string main option key
|
||||
*/
|
||||
private $event_option_id = 'general-event';
|
||||
|
||||
public function get_event_option_id() {
|
||||
return $this->event_option_id;
|
||||
}
|
||||
|
||||
public function fw_get_post_type_slug() {
|
||||
return $this->post_type_slug;
|
||||
}
|
||||
|
||||
public function get_post_type_name() {
|
||||
return $this->post_type_name;
|
||||
}
|
||||
|
||||
public function get_taxonomy_name() {
|
||||
return $this->taxonomy_name;
|
||||
}
|
||||
|
||||
public function _get_link() {
|
||||
return self_admin_url( 'edit.php?post_type=' . $this->get_post_type_name() );
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected function _init() {
|
||||
$this->define_slugs();
|
||||
$this->register_post_type();
|
||||
$this->register_taxonomy();
|
||||
|
||||
if ( is_admin() ) {
|
||||
$this->save_permalink_structure();
|
||||
$this->add_admin_filters();
|
||||
$this->add_admin_actions();
|
||||
} else {
|
||||
$this->add_theme_actions();
|
||||
}
|
||||
|
||||
add_filter( 'fw_post_options', array( $this, '_filter_fw_post_options' ), 10, 2 );
|
||||
}
|
||||
|
||||
private function save_permalink_structure() {
|
||||
if ( ! isset( $_POST['permalink_structure'] ) && ! isset( $_POST['category_base'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->set_db_data(
|
||||
'permalinks/post',
|
||||
FW_Request::POST(
|
||||
'fw_ext_events_event_slug',
|
||||
apply_filters( 'fw_ext_' . $this->get_name() . '_post_slug', $this->post_type_slug )
|
||||
)
|
||||
);
|
||||
$this->set_db_data(
|
||||
'permalinks/taxonomy',
|
||||
FW_Request::POST(
|
||||
'fw_ext_events_taxonomy_slug',
|
||||
apply_filters( 'fw_ext_' . $this->get_name() . '_taxonomy_slug', $this->taxonomy_slug )
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
**/
|
||||
public function _action_add_permalink_in_settings() {
|
||||
add_settings_field(
|
||||
'fw_ext_events_event_slug',
|
||||
__( 'Event base', 'fw' ),
|
||||
array( $this, '_event_slug_input' ),
|
||||
'permalink',
|
||||
'optional'
|
||||
);
|
||||
|
||||
add_settings_field(
|
||||
'fw_ext_events_taxonomy_slug',
|
||||
__( 'Events category base', 'fw' ),
|
||||
array( $this, '_taxonomy_slug_input' ),
|
||||
'permalink',
|
||||
'optional'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _event_slug_input() {
|
||||
?>
|
||||
<input type="text" name="fw_ext_events_event_slug" value="<?php echo $this->post_type_slug; ?>">
|
||||
<code>/my-event</code>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _taxonomy_slug_input() {
|
||||
?>
|
||||
<input type="text" name="fw_ext_events_taxonomy_slug" value="<?php echo $this->taxonomy_slug; ?>">
|
||||
<code>/my-events-category</code>
|
||||
<?php
|
||||
}
|
||||
|
||||
private function define_slugs() {
|
||||
$this->post_type_slug = $this->get_db_data(
|
||||
'permalinks/post',
|
||||
apply_filters( 'fw_ext_' . $this->get_name() . '_post_slug', $this->post_type_slug )
|
||||
);
|
||||
$this->taxonomy_slug = $this->get_db_data(
|
||||
'permalinks/taxonomy',
|
||||
apply_filters( 'fw_ext_' . $this->get_name() . '_taxonomy_slug', $this->taxonomy_slug )
|
||||
);
|
||||
}
|
||||
|
||||
private function register_post_type() {
|
||||
$post_names = apply_filters( 'fw_ext_' . $this->get_name() . '_post_type_name',
|
||||
array(
|
||||
'singular' => __( 'Event', 'fw' ),
|
||||
'plural' => __( 'Events', 'fw' )
|
||||
) );
|
||||
|
||||
register_post_type( $this->post_type_name,
|
||||
array(
|
||||
'labels' => array(
|
||||
'name' => __( 'Events', 'fw' ),
|
||||
'singular_name' => __( 'Event', 'fw' ),
|
||||
'add_new' => __( 'Add New', 'fw' ),
|
||||
'add_new_item' => sprintf( __( 'Add New %s', 'fw' ), $post_names['singular'] ),
|
||||
'edit' => __( 'Edit', 'fw' ),
|
||||
'edit_item' => sprintf( __( 'Edit %s', 'fw' ), $post_names['singular'] ),
|
||||
'new_item' => sprintf( __( 'New %s', 'fw' ), $post_names['singular'] ),
|
||||
'all_items' => sprintf( __( 'All %s', 'fw' ), $post_names['plural'] ),
|
||||
'view' => sprintf( __( 'View %s', 'fw' ), $post_names['singular'] ),
|
||||
'view_item' => sprintf( __( 'View %s', 'fw' ), $post_names['singular'] ),
|
||||
'search_items' => sprintf( __( 'Search %s', 'fw' ), $post_names['plural'] ),
|
||||
'not_found' => sprintf( __( 'No %s Found', 'fw' ), $post_names['plural'] ),
|
||||
'not_found_in_trash' => sprintf( __( 'No %s Found In Trash', 'fw' ), $post_names['plural'] ),
|
||||
'parent_item_colon' => '' /* text for parent types */
|
||||
),
|
||||
'description' => __( 'Create a event item', 'fw' ),
|
||||
'public' => true,
|
||||
'show_ui' => true,
|
||||
'show_in_menu' => true,
|
||||
'publicly_queryable' => true,
|
||||
/* queries can be performed on the front end */
|
||||
'has_archive' => true,
|
||||
'rewrite' => array(
|
||||
'slug' => $this->post_type_slug
|
||||
),
|
||||
'menu_position' => 5,
|
||||
'show_in_nav_menus' => true,
|
||||
'menu_icon' => 'dashicons-calendar',
|
||||
'hierarchical' => false,
|
||||
'query_var' => true,
|
||||
/* Sets the query_var key for this post type. Default: true - set to $post_type */
|
||||
'supports' => array(
|
||||
'title', /* Text input field to create a post title. */
|
||||
'editor',
|
||||
'thumbnail', /* Displays a box for featured image. */
|
||||
'revisions'
|
||||
)
|
||||
) );
|
||||
}
|
||||
|
||||
private function register_taxonomy() {
|
||||
$category_names = apply_filters( 'fw_ext_' . $this->get_name() . '_category_name',
|
||||
array(
|
||||
'singular' => __( 'Category', 'fw' ),
|
||||
'plural' => __( 'Categories', 'fw' )
|
||||
) );
|
||||
|
||||
register_taxonomy( $this->taxonomy_name, $this->post_type_name, array(
|
||||
'labels' => array(
|
||||
'name' => sprintf( _x( 'Event %s', 'taxonomy general name', 'fw' ),
|
||||
$category_names['plural'] ),
|
||||
'singular_name' => sprintf( _x( 'Event %s', 'taxonomy singular name', 'fw' ),
|
||||
$category_names['singular'] ),
|
||||
'search_items' => sprintf( __( 'Search %s', 'fw' ), $category_names['plural'] ),
|
||||
'all_items' => sprintf( __( 'All %s', 'fw' ), $category_names['plural'] ),
|
||||
'parent_item' => sprintf( __( 'Parent %s', 'fw' ), $category_names['singular'] ),
|
||||
'parent_item_colon' => sprintf( __( 'Parent %s:', 'fw' ), $category_names['singular'] ),
|
||||
'edit_item' => sprintf( __( 'Edit %s', 'fw' ), $category_names['singular'] ),
|
||||
'update_item' => sprintf( __( 'Update %s', 'fw' ), $category_names['singular'] ),
|
||||
'add_new_item' => sprintf( __( 'Add New %s', 'fw' ), $category_names['singular'] ),
|
||||
'new_item_name' => sprintf( __( 'New %s Name', 'fw' ), $category_names['singular'] ),
|
||||
'menu_name' => sprintf( __( '%s', 'fw' ), $category_names['plural'] )
|
||||
),
|
||||
'public' => true,
|
||||
'hierarchical' => true,
|
||||
'show_ui' => true,
|
||||
'show_admin_column' => true,
|
||||
'query_var' => true,
|
||||
'show_in_nav_menus' => true,
|
||||
'show_tagcloud' => false,
|
||||
'rewrite' => array(
|
||||
'slug' => $this->taxonomy_slug
|
||||
),
|
||||
) );
|
||||
|
||||
/**
|
||||
* @since 1.0.11
|
||||
*/
|
||||
if ( apply_filters('fw:ext:events:enable-tags', false) ) {
|
||||
$tag_names = apply_filters( 'fw_ext_events_tag_name', array(
|
||||
'singular' => __( 'Tag', 'fw' ),
|
||||
'plural' => __( 'Tags', 'fw' )
|
||||
) );
|
||||
|
||||
register_taxonomy($this->taxonomy_tag_name, $this->post_type_name, array(
|
||||
'hierarchical' => false,
|
||||
'labels' => array(
|
||||
'name' => $tag_names['plural'],
|
||||
'singular_name' => $tag_names['singular'],
|
||||
'search_items' => sprintf( __('Search %s','fw'), $tag_names['plural']),
|
||||
'popular_items' => sprintf( __( 'Popular %s','fw' ), $tag_names['plural']),
|
||||
'all_items' => sprintf( __('All %s','fw'), $tag_names['plural']),
|
||||
'parent_item' => null,
|
||||
'parent_item_colon' => null,
|
||||
'edit_item' => sprintf( __('Edit %s','fw'), $tag_names['singular'] ),
|
||||
'update_item' => sprintf( __('Update %s','fw'), $tag_names['singular'] ),
|
||||
'add_new_item' => sprintf( __('Add New %s','fw'), $tag_names['singular'] ),
|
||||
'new_item_name' => sprintf( __('New %s Name','fw'), $tag_names['singular'] ),
|
||||
'separate_items_with_commas' => sprintf( __( 'Separate %s with commas','fw' ), strtolower($tag_names['plural'])),
|
||||
'add_or_remove_items' => sprintf( __( 'Add or remove %s','fw' ), strtolower($tag_names['plural'])),
|
||||
'choose_from_most_used' => sprintf( __( 'Choose from the most used %s','fw' ), strtolower($tag_names['plural'])),
|
||||
),
|
||||
'public' => true,
|
||||
'show_ui' => true,
|
||||
'query_var' => true,
|
||||
'rewrite' => array(
|
||||
'slug' => $this->taxonomy_tag_slug
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
private function add_admin_filters() {
|
||||
add_filter(
|
||||
'manage_' . $this->get_post_type_name() . '_posts_columns',
|
||||
array( $this, '_filter_add_columns' ),
|
||||
10,
|
||||
1
|
||||
);
|
||||
add_filter( 'months_dropdown_results', array( $this, '_filter_months_dropdown_results' ) );
|
||||
}
|
||||
|
||||
private function add_admin_actions() {
|
||||
add_action(
|
||||
'manage_' . $this->get_post_type_name() . '_posts_custom_column',
|
||||
array( $this, '_action_manage_custom_column' ),
|
||||
10,
|
||||
2
|
||||
);
|
||||
add_action( 'admin_enqueue_scripts', array( $this, '_action_enqueue_scripts' ) );
|
||||
add_action( 'admin_head', array( $this, '_action_initial_nav_menu_meta_boxes' ), 999 );
|
||||
add_action( 'admin_init', array( $this, '_action_add_permalink_in_settings' ) );
|
||||
}
|
||||
|
||||
private function add_theme_actions() {
|
||||
add_action( 'wp', array( $this, '_action_calendar_export' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Modifies table structure for 'All Events' admin page
|
||||
*
|
||||
* @param $columns
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _filter_add_columns( $columns ) {
|
||||
unset( $columns['date'], $columns[ 'taxonomy-' . $this->taxonomy_name ] );
|
||||
|
||||
return array_merge( $columns,
|
||||
array(
|
||||
'event_date' => __( 'Date', 'fw' ),
|
||||
'event_location' => __( 'Location', 'fw' )
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds event options for it's custom post type
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @param $post_options
|
||||
* @param $post_type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function _filter_fw_post_options( $post_options, $post_type ) {
|
||||
if ( $post_type !== $this->post_type_name ) {
|
||||
return $post_options;
|
||||
}
|
||||
|
||||
$event_options = apply_filters( 'fw_ext_events_post_options',
|
||||
array(
|
||||
'events_tab' => array(
|
||||
'title' => __( 'Event Options', 'fw' ),
|
||||
'type' => 'tab',
|
||||
'options' => array(
|
||||
$this->event_option_id => array(
|
||||
'type' => 'event',
|
||||
'desc' => false,
|
||||
'label' => false,
|
||||
)
|
||||
)
|
||||
)
|
||||
) );
|
||||
|
||||
if (empty($event_options)) {
|
||||
return $post_options;
|
||||
}
|
||||
|
||||
if ( isset( $post_options['man'] ) && $post_options['main']['type'] === 'box' ) {
|
||||
$post_options['main']['options'][] = $event_options;
|
||||
} else {
|
||||
$post_options['main'] = array(
|
||||
'title' => esc_html__( 'Event Settings', 'fw' ),
|
||||
'desc' => false,
|
||||
'type' => 'box',
|
||||
'options' => $event_options
|
||||
);
|
||||
}
|
||||
|
||||
return $post_options;
|
||||
}
|
||||
|
||||
public function _filter_months_dropdown_results( $months ) {
|
||||
$current_screen = array(
|
||||
'only' => array(
|
||||
array( 'post_type' => $this->post_type_name )
|
||||
)
|
||||
);
|
||||
|
||||
return fw_current_screen_match( $current_screen ) ? array() : $months;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill custom column
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @param $column
|
||||
* @param $post_id
|
||||
*/
|
||||
public function _action_manage_custom_column( $column, $post_id ) {
|
||||
switch ( $column ) {
|
||||
case 'event_location' :
|
||||
echo $this->get_event_location( $post_id );
|
||||
break;
|
||||
case 'event_date' :
|
||||
echo $this->get_event_datetime_date( $post_id );
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get saved event location array from db
|
||||
*
|
||||
* @param $post_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_event_location( $post_id ) {
|
||||
$meta = fw_get_db_post_option( $post_id, $this->event_option_id );
|
||||
|
||||
return ( ( isset( $meta['event_location']['location'] ) and false === empty( $meta['event_location']['location'] ) ) ? $meta['event_location']['location'] : '—' );
|
||||
}
|
||||
|
||||
/**
|
||||
* A way to find out event start date
|
||||
*
|
||||
* @param $post_id int
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function get_event_datetime_date( $post_id ) {
|
||||
$meta = fw_get_db_post_option( $post_id, $this->event_option_id );
|
||||
$empty_msg = '—';
|
||||
|
||||
$result = $empty_msg;
|
||||
if ( isset( $meta['event_children'] ) && is_array( $meta['event_children'] ) ) {
|
||||
$meta_rows = fw_akg( 'event_children', $meta );
|
||||
if ( is_array( $meta_rows ) && count( $meta_rows ) > 0 ) {
|
||||
$min_date = null;
|
||||
$count = 0;
|
||||
//search event's minimal from_date (also check if exists)
|
||||
foreach ( $meta_rows as $meta_row ) {
|
||||
$from_date = fw_akg( 'event_date_range/from', $meta_row );
|
||||
|
||||
if ( empty( $from_date ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$from_date = new DateTime( $from_date, new DateTimeZone( 'GMT' ) );
|
||||
if ( $min_date === null or $from_date->format( 'U' ) < $min_date->format( 'U' ) ) {
|
||||
$min_date = $from_date;
|
||||
}
|
||||
$count ++;
|
||||
} catch ( Exception $e ) {
|
||||
//if was saved wrong format
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( $count > 1 ) {
|
||||
$result = __( 'Multi Interval Event', 'fw' );
|
||||
} else {
|
||||
$result = empty( $min_date ) ? $empty_msg : $min_date->format( 'Y/m/d' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enquee backend styles on events pages
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
public function _action_enqueue_scripts() {
|
||||
$current_screen = array(
|
||||
'only' => array(
|
||||
array( 'post_type' => $this->post_type_name )
|
||||
)
|
||||
);
|
||||
|
||||
if ( fw_current_screen_match( $current_screen ) ) {
|
||||
wp_enqueue_style( 'fw-ext-events-css',
|
||||
$this->get_declared_URI( '/static/css/backend-events-style.css' ),
|
||||
array(),
|
||||
fw()->manifest->get_version()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_initial_nav_menu_meta_boxes() {
|
||||
$screen = array(
|
||||
'only' => array(
|
||||
'base' => 'nav-menus'
|
||||
)
|
||||
);
|
||||
|
||||
if ( ! fw_current_screen_match( $screen ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$user_ID = get_current_user_id();
|
||||
$meta = fw_get_db_extension_user_data( $user_ID, $this->get_name() );
|
||||
|
||||
if ( isset( $meta['metaboxhidden_nav-menus'] ) && $meta['metaboxhidden_nav-menus'] == true ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$hidden_meta_boxes = get_user_meta( $user_ID, 'metaboxhidden_nav-menus' );
|
||||
if ( $key = array_search( 'add-' . $this->taxonomy_name, $hidden_meta_boxes[0] ) ) {
|
||||
unset( $hidden_meta_boxes[0][ $key ] );
|
||||
}
|
||||
|
||||
update_user_option( $user_ID, 'metaboxhidden_nav-menus', $hidden_meta_boxes[0], true );
|
||||
|
||||
if ( ! is_array( $meta ) ) {
|
||||
$meta = array();
|
||||
}
|
||||
|
||||
if ( ! isset( $meta['metaboxhidden_nav-menus'] ) ) {
|
||||
$meta['metaboxhidden_nav-menus'] = true;
|
||||
}
|
||||
|
||||
fw_set_db_extension_user_data( $user_ID, $this->get_name(), $meta );
|
||||
}
|
||||
|
||||
/**
|
||||
* @intenral
|
||||
*/
|
||||
public function _action_calendar_export() {
|
||||
global $post;
|
||||
if ( empty( $post ) or $post->post_type !== $this->post_type_name ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( FW_Request::GET( 'calendar' ) ) {
|
||||
$calendar = FW_Request::GET( 'calendar' );
|
||||
$row_id = FW_Request::GET( 'row_id' );
|
||||
$offset = FW_Request::GET( 'offset' );
|
||||
$options = fw_get_db_post_option( $post->ID, $this->get_event_option_id() );
|
||||
|
||||
if ( ! is_array( fw_akg( 'event_children/' . $row_id, $options ) ) or ! preg_match( '/^\d+$/', $row_id ) ) {
|
||||
wp_redirect( site_url() . '?error=404' );
|
||||
}
|
||||
|
||||
if ( ! preg_match( '/^(\-|\d)\d+$/', $offset ) ) {
|
||||
$offset = 0;
|
||||
}
|
||||
|
||||
switch ( $calendar ) {
|
||||
case 'google':
|
||||
wp_redirect( $this->get_google_uri( $post, $options, $row_id, $offset ) );
|
||||
break;
|
||||
default:
|
||||
$this->get_ics_headers( $post );
|
||||
echo $this->get_ics_content( $post, $options, $row_id, $offset );
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function get_google_uri( $post, $options, $row_id, $offset ) {
|
||||
$all_day = fw_akg( 'all_day', $options, 'yes' );
|
||||
|
||||
$date_template = 'Ymd';
|
||||
if ( $all_day === 'no' ) {
|
||||
$date_template = 'Ymd\THis\Z';
|
||||
}
|
||||
|
||||
$start = date( $date_template,
|
||||
$offset + strtotime( fw_akg( 'event_children/' . $row_id . '/event_date_range/from', $options, 'now' ) ) );
|
||||
$end = date( $date_template,
|
||||
$offset + strtotime( fw_akg( 'event_children/' . $row_id . '/event_date_range/to', $options, 'now' ) ) );
|
||||
$location = fw_akg( 'event_location/location', $options, '' );
|
||||
|
||||
return 'https://www.google.com/calendar/render?action=TEMPLATE&text=' . $post->post_title .
|
||||
'&dates=' . $start . '/' . $end .
|
||||
'&details=For+details,+link+here:+' . get_permalink( $post->ID ) .
|
||||
'&location=' . $location;
|
||||
}
|
||||
|
||||
private function get_ics_headers( $post ) {
|
||||
header( 'Content-type: text/calendar' );
|
||||
header( 'Content-Disposition: attachment; filename=' . urlencode( $post->post_title ) . '-' . time() . '.ics' );
|
||||
header( 'Pragma: no-cache' );
|
||||
header( 'Expires: 0' );
|
||||
}
|
||||
|
||||
private function get_ics_content( $post, $options, $row_id, $offset ) {
|
||||
$all_day = fw_akg( 'all_day', $options, 'yes' );
|
||||
|
||||
$date_template = 'Ymd\T000000';
|
||||
if ( $all_day === 'no' ) {
|
||||
$date_template = 'Ymd\THis\Z';
|
||||
}
|
||||
|
||||
$start = date( $date_template,
|
||||
$offset + strtotime( fw_akg( 'event_children/' . $row_id . '/event_date_range/from', $options, 'now' ) ) );
|
||||
$end = date( $date_template,
|
||||
$offset + strtotime( fw_akg( 'event_children/' . $row_id . '/event_date_range/to', $options, 'now' ) ) );
|
||||
$location = fw_akg( 'event_location/location', $options, '' );
|
||||
|
||||
return "BEGIN:VCALENDAR\n" .
|
||||
"VERSION:1.0\n" .
|
||||
"BEGIN:VEVENT\n" .
|
||||
"URL:" . get_permalink( $post->ID ) . "\n" .
|
||||
"DTSTART:" . $start . "\n" .
|
||||
"DTEND:" . $end . "\n" .
|
||||
"SUMMARY:" . $post->post_title . "\n" .
|
||||
"DESCRIPTION:For details, click here:" . get_permalink( $post->ID ) . "\n" .
|
||||
"LOCATION:" . $location . "\n" .
|
||||
"END:VEVENT\n" .
|
||||
"END:VCALENDAR";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,692 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
class FW_Extension_Events_Tags extends FW_Extension {
|
||||
|
||||
private $post_type_slug;
|
||||
private $post_type;
|
||||
private $data_provider_id = 'events';
|
||||
private $to_date = 'event-to-date';
|
||||
private $from_date = 'event-from-date';
|
||||
private $from_time = 'event-from-time';
|
||||
private $to_time = 'event-to-time';
|
||||
private $all_day = 'all_day_event';
|
||||
|
||||
/**
|
||||
* @var null|FW_Extension_Events
|
||||
*/
|
||||
private $parent = null;
|
||||
|
||||
|
||||
private function _fw_define_slugs() {
|
||||
$this->post_type = apply_filters( 'fw_ext_' . $this->get_name() . '_post_slug',
|
||||
$this->parent->get_post_type_name() . '-search' );
|
||||
$this->post_type_slug = apply_filters( 'fw_ext_' . $this->get_name() . '_post_slug',
|
||||
$this->parent->fw_get_post_type_slug() . '-search' );
|
||||
}
|
||||
|
||||
public function _init() {
|
||||
|
||||
$this->parent = $this->get_parent();
|
||||
|
||||
$this->_fw_define_slugs();
|
||||
|
||||
$this->wpml_compatibilitty();
|
||||
|
||||
add_action( 'init', array( $this, '_action_register_post_type_tags' ) );
|
||||
add_filter( 'fw_shortcode_calendar_provider', array( $this, '_filter_theme_shortcode_calendar_set_provider' ) );
|
||||
add_filter( 'fw_shortcode_map_provider', array( $this, '_filter_theme_shortcode_map_set_provider' ) );
|
||||
|
||||
if ( is_admin() ) {
|
||||
$this->admin_actions();
|
||||
} else {
|
||||
$this->theme_filters();
|
||||
}
|
||||
}
|
||||
|
||||
private function wpml_compatibilitty() {
|
||||
if ( ! class_exists( 'SitePress' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $sitepress_settings;
|
||||
$sitepress_settings['custom_posts_sync_option'][ $this->post_type ] = 1;
|
||||
|
||||
add_filter( 'get_translatable_documents', array( $this, '_filter_wpml_make_post_type_translatable' ) );
|
||||
|
||||
if ( is_admin() ) {
|
||||
add_action( 'icl_make_duplicate', array( $this, '_action_admin_on_save_event' ) );
|
||||
}
|
||||
}
|
||||
|
||||
private function theme_filters() {
|
||||
add_filter( 'fw_shortcode_calendar_ajax_params', array( $this, '_filter_theme_shortcode_calendar_ajax_params' ),
|
||||
10, 3 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Register extension events in shortcode "Map", with initial data
|
||||
*
|
||||
* @param array $value
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function _filter_theme_shortcode_map_set_provider( $value ) {
|
||||
$value[ $this->data_provider_id ] = array(
|
||||
'label' => __( 'Events', 'fw' ),
|
||||
'callback' => array( $this, 'fw_get_events_locations' ),
|
||||
'options' => array(
|
||||
'events_category' => array(
|
||||
'label' => __( 'Event Categories', 'fw' ),
|
||||
'desc' => __( 'Select an event category', 'fw' ),
|
||||
'type' => 'select',
|
||||
'choices' => array( '' => __( 'All Events', 'fw' ) ) + $this->_fw_get_event_terms_choices()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all/by_category event's locations from db
|
||||
*
|
||||
* @param array $atts
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fw_get_events_locations( $atts ) {
|
||||
|
||||
$category = fw_akg( 'data_provider/' . $this->data_provider_id . '/events_category', $atts );
|
||||
|
||||
$args = array(
|
||||
'post_type' => $this->parent->get_post_type_name(),
|
||||
'posts_per_page' => - 1,
|
||||
'post_status' => 'publish'
|
||||
);
|
||||
|
||||
// add taxonomy term query args
|
||||
{
|
||||
$terms_ids = array();
|
||||
$with_category = false;
|
||||
if ( preg_match( '/^\d+$/', $category ) ) {
|
||||
$terms_ids = get_term_children( $category, $this->parent->get_taxonomy_name() );
|
||||
if ( is_array( $terms_ids ) and false === empty( $terms_ids ) and false === is_wp_error( $terms_ids ) ) {
|
||||
$terms_ids[] = (int) $category;
|
||||
} else {
|
||||
$terms_ids = array( $category );
|
||||
}
|
||||
$with_category = true;
|
||||
}
|
||||
|
||||
if ( $with_category ) {
|
||||
$args['tax_query'] = array(
|
||||
array(
|
||||
'taxonomy' => $this->parent->get_taxonomy_name(),
|
||||
'field' => 'id',
|
||||
'terms' => $terms_ids,
|
||||
'operator' => 'IN'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$query = new WP_Query( $args );
|
||||
$posts = $query->get_posts();
|
||||
wp_reset_query();
|
||||
|
||||
$result = array();
|
||||
if ( is_array( $posts ) && count( $posts ) > 0 ) {
|
||||
foreach ( $posts as $key => $post ) {
|
||||
$meta = fw_get_db_post_option( $post->ID, $this->parent->get_event_option_id() );
|
||||
$location = trim( fw_akg( 'event_location/location', $meta, '' ) );
|
||||
if ( false === empty( $location ) ) {
|
||||
$result[ $key ]['title'] = htmlspecialchars_decode( $post->post_title );
|
||||
$result[ $key ]['coordinates'] = fw_akg( 'event_location/coordinates', $meta, array() );
|
||||
$result[ $key ]['url'] = get_permalink( $post->ID );
|
||||
$result[ $key ]['thumb'] = fw_resize( wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ),
|
||||
100, 60, true );
|
||||
$result[ $key ]['description'] = $location;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param array $post_types
|
||||
*
|
||||
* @return array
|
||||
**/
|
||||
public function _filter_wpml_make_post_type_translatable( $post_types ) {
|
||||
|
||||
if ( ! isset( $post_types[ $this->post_type ] ) ) {
|
||||
$post_types[ $this->post_type ] = get_post_type_object( $this->post_type );
|
||||
}
|
||||
|
||||
return $post_types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill shortcode Calendar with initial data
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @param $value - list of data providers
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function _filter_theme_shortcode_calendar_set_provider( $value ) {
|
||||
$value[ $this->data_provider_id ] = array(
|
||||
'label' => __( 'Events', 'fw' ),
|
||||
'callback' => array( $this, 'fw_get_events_by_range' ),
|
||||
'options' => array(
|
||||
'events_category' => array(
|
||||
'label' => __( 'Event Categories', 'fw' ),
|
||||
'desc' => __( 'Select an event category', 'fw' ),
|
||||
'type' => 'select',
|
||||
'choices' => array( '' => __( 'All Events', 'fw' ) ) + $this->_fw_get_event_terms_choices()
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saved option 'events_category' sets as ajax parameter
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @param array $value - presetted ajax parameters (e.g. array('ajax_post_param' => 'string value') )
|
||||
* @param string $provider - choosen data provider
|
||||
* @param array $option_values - user saved option values
|
||||
*
|
||||
* @return array - ajax parameters (e.g. array('ajax_post_param' => 'string value') )
|
||||
*/
|
||||
public function _filter_theme_shortcode_calendar_ajax_params( $value, $provider, $option_values ) {
|
||||
if ( $provider === $this->data_provider_id ) {
|
||||
if ( is_array( $value ) ) {
|
||||
return array_merge( $value, $option_values );
|
||||
}
|
||||
|
||||
return $option_values;
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate array of terms for option choices
|
||||
*/
|
||||
private function _fw_get_event_terms_choices() {
|
||||
$terms = get_terms( $this->parent->get_taxonomy_name(), array(
|
||||
'hide_empty' => 0
|
||||
) );
|
||||
|
||||
if ( is_wp_error( $terms ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$result = array();
|
||||
if ( is_array( $terms ) && ! empty( $terms ) ) {
|
||||
foreach ( $terms as $term ) {
|
||||
$name = trim( $term->name );
|
||||
$result[ $term->term_id ] = empty( $name ) ? $term->slug : $name;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function admin_actions() {
|
||||
add_action( 'fw_save_post_options', array( $this, '_action_admin_on_save_event' ) );
|
||||
add_action( 'before_delete_post', array( $this, '_action_admin_on_delete_event' ) );
|
||||
add_action( 'transition_post_status', array( $this, 'set_childs_status' ), 10, 3 );
|
||||
|
||||
$time = (int) $this->get_db_data( 'last_updated', 0 );
|
||||
|
||||
if ( ( time() - $time ) > ( 86400 + 5 ) ) {
|
||||
$this->update_events();
|
||||
$this->set_db_data( 'last_updated', time() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param $post_id
|
||||
*/
|
||||
public function _action_admin_on_save_event( $post_id ) {
|
||||
if ( get_post_type( $post_id ) !== $this->parent->get_post_type_name() or ! fw_is_real_post_save( $post_id ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_fw_remove_all_event_children_data( $post_id );
|
||||
$this->_fw_insert_all_event_children_data( $post_id );
|
||||
$this->set_childs_status( get_post_status( $post_id ), '', $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param $post_id
|
||||
*/
|
||||
public function _action_admin_on_delete_event( $post_id ) {
|
||||
if ( get_post_type( $post_id ) !== $this->parent->get_post_type_name() ) {
|
||||
return;
|
||||
}
|
||||
$this->_fw_remove_all_event_children_data( $post_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param $post_id
|
||||
*/
|
||||
public function set_childs_status( $new_status, $old_status, $post ) {
|
||||
|
||||
$post_id = is_object( $post ) ? $post->ID : $post;
|
||||
|
||||
if ( get_post_type( $post_id ) !== $this->parent->get_post_type_name() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $wpdb;
|
||||
|
||||
$childs = $wpdb->get_results( $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_parent='%d' AND post_type='{$this->post_type}'", $post_id ), ARRAY_A );
|
||||
|
||||
if ( ! $childs ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $childs as $child ) {
|
||||
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->posts} SET post_status = %s WHERE ID = %d AND post_type = %s", $new_status, $child['ID'], $this->post_type ) );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _action_register_post_type_tags() {
|
||||
|
||||
register_post_type( $this->post_type, array(
|
||||
'labels' => false,
|
||||
'description' => false,
|
||||
'public' => false,
|
||||
'show_ui' => false,
|
||||
'show_in_menu' => false,
|
||||
'publicly_queryable' => false,
|
||||
'exclude_from_search' => true,
|
||||
'show_in_admin_bar' => false,
|
||||
'has_archive' => false,
|
||||
'rewrite' => array(
|
||||
'slug' => $this->post_type_slug
|
||||
),
|
||||
'show_in_nav_menus' => false,
|
||||
'hierarchical' => true,
|
||||
'query_var' => false,
|
||||
'supports' => array(
|
||||
'author'
|
||||
)
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove fw-event-tags posts from db related with fw-event post.
|
||||
*
|
||||
* @param int $post_id
|
||||
*/
|
||||
private function _fw_remove_all_event_children_data( $post_id ) {
|
||||
|
||||
$args = array(
|
||||
'post_parent' => $post_id,
|
||||
'post_type' => $this->post_type,
|
||||
'post_status' => 'any',
|
||||
'numberposts' => -1
|
||||
);
|
||||
|
||||
$posts = get_posts( $args );
|
||||
|
||||
if ( is_array( $posts ) && count( $posts ) > 0 ) {
|
||||
|
||||
foreach ( $posts as $post ) {
|
||||
wp_delete_post( $post->ID, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For even datetime range row create custom 'fw-events-tags' post. Also save search query tags as meta values.
|
||||
*
|
||||
* @param int $post_id
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function _fw_insert_all_event_children_data( $post_id ) {
|
||||
$options_values = fw_get_db_post_option( $post_id );
|
||||
if ( is_array( $options_values ) === false ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$container_id = $this->parent->get_event_option_id();
|
||||
$meta_rows_data = fw_akg( $container_id . '/event_children', $options_values );
|
||||
$all_day_event = fw_akg( $container_id . '/all_day', $options_values );
|
||||
|
||||
if ( is_array( $meta_rows_data ) && count( $meta_rows_data ) > 0 ) {
|
||||
foreach ( $meta_rows_data as $meta_row ) {
|
||||
|
||||
$start_date = fw_akg( 'event_date_range/from', $meta_row );
|
||||
$end_date = fw_akg( 'event_date_range/to', $meta_row );
|
||||
|
||||
$from_timestamp = strtotime( $start_date );
|
||||
$to_timestamp = strtotime( $end_date );
|
||||
|
||||
if ( ! $from_timestamp || ! $to_timestamp || - 1 === $from_timestamp || - 1 === $to_timestamp ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$terms = wp_get_post_terms( $post_id, $this->parent->get_taxonomy_name(), array( 'fields' => 'ids' ) );
|
||||
|
||||
$event_post_tag_id = wp_insert_post(
|
||||
array(
|
||||
'post_parent' => $post_id,
|
||||
'post_type' => $this->post_type,
|
||||
'post_status' => 'publish',
|
||||
'tax_input' => array(
|
||||
$this->parent->get_taxonomy_name() => $terms
|
||||
)
|
||||
), true );
|
||||
|
||||
if ( $event_post_tag_id == 0 || $event_post_tag_id instanceof WP_Error ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
add_post_meta( $event_post_tag_id, $this->from_date,
|
||||
$from_timestamp - ( date( 'H', $from_timestamp ) * 3600 + date( 'i', $from_timestamp ) * 60 ) );
|
||||
add_post_meta( $event_post_tag_id, $this->to_date,
|
||||
$to_timestamp - ( date( 'H', $to_timestamp ) * 3600 + date( 'i', $to_timestamp ) * 60 ) );
|
||||
add_post_meta( $event_post_tag_id, $this->from_time,
|
||||
date( 'H', $from_timestamp ) * 3600 + date( 'i', $from_timestamp ) * 60 );
|
||||
add_post_meta( $event_post_tag_id, $this->to_time,
|
||||
date( 'H', $to_timestamp ) * 3600 + date( 'i', $to_timestamp ) * 60 );
|
||||
add_post_meta( $event_post_tag_id, $this->all_day, $all_day_event );
|
||||
|
||||
if ( function_exists( 'wpml_get_language_information' ) && function_exists( 'wpml_add_translatable_content' ) ) {
|
||||
$lang = wpml_get_language_information( $post_id );
|
||||
$language = substr( fw_akg( 'locale', $lang ), 0, 2 );
|
||||
|
||||
if ( ! empty( $language ) ) {
|
||||
wpml_add_translatable_content( 'post_' . $this->post_type, $event_post_tag_id, $language );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$users = fw_akg( 'event-user', $meta_row );
|
||||
if ( is_array( $users ) && count( $users ) > 0 ) {
|
||||
foreach ( $users as $user ) {
|
||||
add_post_meta( $event_post_tag_id, 'event-user', $user );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $params array(
|
||||
* 'from' => 123234455 - (int) start (unixtime) range query
|
||||
* 'to' => 435455645 - (int) end (unixtime) range query
|
||||
* 'template' => 'day' - (string) group dates for template (day grouped sensitivity equal minutes, else )
|
||||
* 'events_category' - (int) parent Events term id
|
||||
* )
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function fw_get_events_by_range( $params ) {
|
||||
$from = fw_akg( 'from', $params );
|
||||
$to = fw_akg( 'to', $params );
|
||||
|
||||
if ( empty( $from ) or empty( $to ) or ! preg_match( '/^\d+$/', $from ) or ! preg_match( '/^\d+$/',
|
||||
$to ) or ( $to < $from )
|
||||
) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$group_for = fw_akg( 'template', $params );
|
||||
$category = fw_akg( 'events_category', $params );
|
||||
|
||||
$terms_ids = array();
|
||||
$with_category = false;
|
||||
if ( preg_match( '/^\d+$/', $category ) ) {
|
||||
$terms_ids = get_term_children( $category, $this->parent->get_taxonomy_name() );
|
||||
if ( is_array( $terms_ids ) and false === empty( $terms_ids ) and false === is_wp_error( $terms_ids ) ) {
|
||||
$terms_ids[] = (int) $category;
|
||||
} else {
|
||||
$terms_ids = array( $category );
|
||||
}
|
||||
$with_category = true;
|
||||
}
|
||||
|
||||
$args = array(
|
||||
'post_type' => $this->post_type,
|
||||
'post_status' => 'publish',
|
||||
'posts_per_page' => -1,
|
||||
'meta_query' => array(
|
||||
'relation' => 'OR',
|
||||
array(
|
||||
'key' => $this->from_date,
|
||||
'value' => array( $from, $to ),
|
||||
'compare' => 'BETWEEN'
|
||||
),
|
||||
array(
|
||||
'key' => $this->to_date,
|
||||
'value' => array( $from, $to ),
|
||||
'compare' => 'BETWEEN'
|
||||
),
|
||||
array(
|
||||
'relation' => 'AND',
|
||||
array(
|
||||
'key' => $this->from_date,
|
||||
'value' => $from,
|
||||
'compare' => '<='
|
||||
),
|
||||
array(
|
||||
'key' => $this->to_date,
|
||||
'value' => $to,
|
||||
'compare' => '>='
|
||||
)
|
||||
)
|
||||
),
|
||||
);
|
||||
|
||||
if ( $with_category ) {
|
||||
$args['tax_query'] = array(
|
||||
array(
|
||||
'taxonomy' => $this->parent->get_taxonomy_name(),
|
||||
'field' => 'id',
|
||||
'terms' => $terms_ids,
|
||||
'operator' => 'IN'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
$posts = new WP_Query( $args );
|
||||
|
||||
$items = $posts->get_posts();
|
||||
|
||||
$result = array();
|
||||
if ( is_array( $items ) and count( $items ) > 0 ) {
|
||||
|
||||
if ( $group_for === 'day' ) {
|
||||
$result = $this->_fw_prepare_data( $items, 'YmdHi' );
|
||||
} else {
|
||||
$result = $this->_fw_prepare_data( $items, 'Ymd' );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* @param int $offset
|
||||
**/
|
||||
private function update_events( $offset = 0 ) {
|
||||
$posts = get_posts( array(
|
||||
'post_type' => $this->parent->get_post_type_name(),
|
||||
'posts_per_page' => 100,
|
||||
'offset' => $offset
|
||||
) );
|
||||
|
||||
$offset += 100;
|
||||
|
||||
if ( empty( $posts ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ( $posts as $post ) {
|
||||
$this->_action_admin_on_save_event( $post->ID );
|
||||
}
|
||||
|
||||
$this->update_events( $offset );
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare data structure compatible with shortcode Calendar
|
||||
*
|
||||
* @param WP_Post $items
|
||||
*
|
||||
* @param string $format
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _fw_prepare_data( $items, $format = null ) {
|
||||
|
||||
$result = array();
|
||||
|
||||
foreach ( $items as $key => $item ) {
|
||||
|
||||
//start datetime
|
||||
{
|
||||
$timestamp_start_date = get_post_meta( $item->ID, $this->from_date, true );
|
||||
$timestamp_start_time = get_post_meta( $item->ID, $this->from_time, true );
|
||||
$result[ $item->post_parent ][ $key ]['start'] = ( $timestamp_start_date + $timestamp_start_time );
|
||||
}
|
||||
|
||||
//end datetime
|
||||
{
|
||||
$timestamp_end_date = get_post_meta( $item->ID, $this->to_date, true );
|
||||
$timestamp_end_time = ( strtolower( get_post_meta( $item->ID, $this->all_day,
|
||||
true ) ) === 'yes' ? 86399 : get_post_meta( $item->ID,
|
||||
$this->to_time, true ) ); // 23:59:59 86399 //86400 24:00:00
|
||||
|
||||
$result[ $item->post_parent ][ $key ]['end'] = ( $timestamp_end_date + $timestamp_end_time );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$result = $this->_fw_grouped_calendar_dates( $result, $format );
|
||||
|
||||
$return_value = array();
|
||||
$i = 0;
|
||||
//fill return value with shrortcode Calendar supported data structure
|
||||
foreach ( $result as $event_id => $intervals ) {
|
||||
|
||||
if ( is_null( get_post( $event_id ) ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$title = get_the_title( $event_id );
|
||||
$url = get_permalink( $event_id );
|
||||
foreach ( $intervals as $interval ) {
|
||||
$return_value[ $i ]['start'] = $interval['start'];
|
||||
$return_value[ $i ]['end'] = $interval['end'];
|
||||
$return_value[ $i ]['id'] = $event_id;
|
||||
$return_value[ $i ]['title'] = htmlspecialchars_decode( $title );
|
||||
$return_value[ $i ]['url'] = $url;
|
||||
$i ++;
|
||||
}
|
||||
}
|
||||
|
||||
return $return_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge event dates by datetime format
|
||||
*
|
||||
* @param $format string - group accuracy (e.g. 'YmdHis' compatible with datetime formats)
|
||||
* @param $main_event array(
|
||||
* '123' => array( - (int) post_parent sub event
|
||||
* '333' => array( - (int) any unique id
|
||||
* 'start' => '1355270400' - (int) unixtimestamp
|
||||
* 'end' => '1355270700' - (int) unixtimestamp
|
||||
* )
|
||||
* ***
|
||||
* )
|
||||
* ***
|
||||
* )
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function _fw_grouped_calendar_dates( $main_event, $format = 'Ymd' ) {
|
||||
foreach ( $main_event as &$sub_events_array ) {
|
||||
//sort sub events date ranges by 'start' ascending
|
||||
uasort( $sub_events_array, array( $this, 'fw_compare_event_dates' ) );
|
||||
|
||||
$i = 0;
|
||||
$remove_items_keys = array();
|
||||
foreach ( $sub_events_array as &$sub_event ) {
|
||||
$i ++;
|
||||
|
||||
//get next sub event date ranges
|
||||
$events_sliced = array_slice( $sub_events_array, $i, null, true );
|
||||
|
||||
if ( empty( $events_sliced ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//merge date ranges by date format
|
||||
foreach ( $events_sliced as $key_sliced => $sub_event_sliced ) {
|
||||
if ( date( $format, $sub_event_sliced['start'] ) <= date( $format, $sub_event['end'] ) ) {
|
||||
if ( date( $format, $sub_event_sliced['end'] ) >= date( $format, $sub_event['end'] ) ) {
|
||||
$sub_event['end'] = $sub_event_sliced['end'];
|
||||
}
|
||||
//save elements keys which will be removed
|
||||
$remove_items_keys[] = $key_sliced;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//clean not actual sub event date ranges
|
||||
if ( ! empty( $remove_items_keys ) ) {
|
||||
foreach ( $remove_items_keys as $key ) {
|
||||
unset( $sub_events_array[ $key ] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $main_event;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function fw_compare_event_dates( $a, $b ) {
|
||||
if ( $a['start'] == $b['start'] ) {
|
||||
return 0;
|
||||
} elseif ( $a['start'] > $b['start'] ) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return - 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
if ( class_exists( 'SitePress' ) ) {
|
||||
if ( ! defined( 'WPML_LOAD_API_SUPPORT' ) && defined( 'ICL_PLUGIN_PATH' ) ) {
|
||||
define( 'WPML_LOAD_API_SUPPORT', 1 );
|
||||
require ICL_PLUGIN_PATH . '/inc/wpml-api.php';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
$manifest = array();
|
||||
|
||||
$manifest['name'] = __( 'Event-search-tags', 'fw' );
|
||||
$manifest['description'] = __( 'Connect extension event with shortcodes map & calendar', 'fw' );
|
||||
$manifest['version'] = '1.0.0';
|
||||
$manifest['display'] = 'event';
|
||||
$manifest['standalone'] = true;
|
||||
$manifest['requirements'] = array(
|
||||
'extensions' => array(
|
||||
'shortcodes' => array(),
|
||||
)
|
||||
);
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get shortcode [map] html string
|
||||
* @param int $post_id
|
||||
* @return null | string
|
||||
*/
|
||||
if ( ! function_exists( 'fw_ext_events_render_map' ) ) {
|
||||
function fw_ext_events_render_map( $post_id = 0 ) {
|
||||
if ( 0 === $post_id && null === ( $post_id = get_the_ID() ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$fw_ext_events = fw()->extensions->get( 'events' );
|
||||
if (empty($fw_ext_events)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$post = get_post($post_id);
|
||||
if ($post->post_type !== $fw_ext_events->get_post_type_name() ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$shortcode_ext = fw()->extensions->get('shortcodes');
|
||||
if (empty($shortcode_ext)){
|
||||
return null;
|
||||
}
|
||||
|
||||
$shortcode_map = $shortcode_ext->get_shortcode('map');
|
||||
if (empty($shortcode_map)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$options = fw_get_db_post_option($post->ID, $fw_ext_events->get_event_option_id());
|
||||
|
||||
if (empty($options['event_location']['location']) or empty($options['event_location']['coordinates']['lat']) or empty($options['event_location']['coordinates']['lng']) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $shortcode_map->render_custom(
|
||||
array(
|
||||
array(
|
||||
'title' => $post->post_title,
|
||||
'url' => get_permalink($post->ID),
|
||||
'description' => $options['event_location']['location'],
|
||||
'thumb' => array('attachment_id' => get_post_thumbnail_id( $post->ID ) ),
|
||||
'location' => array(
|
||||
'coordinates' => array(
|
||||
'lat' => $options['event_location']['coordinates']['lat'],
|
||||
'lng' => $options['event_location']['coordinates']['lng']
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'map_height' => false,
|
||||
'map_type' => false
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the content of the current template with the content of event view
|
||||
*
|
||||
* @param string $the_content
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function _filter_fw_ext_events_the_content( $the_content ) {
|
||||
|
||||
/**
|
||||
* @var FW_Extension_Events $events
|
||||
*/
|
||||
$events = fw()->extensions->get( 'events' );
|
||||
|
||||
return fw_render_view( $events->locate_view_path( 'content' ), array( 'the_content' => $the_content ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Select custom page template on frontend
|
||||
*
|
||||
* @internal
|
||||
*
|
||||
* @param string $template
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function _filter_fw_ext_events_template_include( $template ) {
|
||||
|
||||
/**
|
||||
* @var FW_Extension_Events $events
|
||||
*/
|
||||
$events = fw()->extensions->get( 'events' );
|
||||
|
||||
if ( is_singular( $events->get_post_type_name() ) ) {
|
||||
|
||||
if ( preg_match( '/single-' . '.*\.php/i', basename( $template ) ) === 1 ) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
if ( $events->locate_view_path( 'single' ) ) {
|
||||
return $events->locate_view_path( 'single' );
|
||||
} else {
|
||||
add_filter( 'the_content', '_filter_fw_ext_portfolio_the_content' );
|
||||
}
|
||||
} else if ( is_tax( $events->get_taxonomy_name() ) && $events->locate_view_path( 'taxonomy' ) ) {
|
||||
|
||||
if ( preg_match( '/taxonomy-' . '.*\.php/i', basename( $template ) ) === 1 ) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
return $events->locate_view_path( 'taxonomy' );
|
||||
} else if ( is_post_type_archive( $events->get_post_type_name() ) && $events->locate_view_path( 'archive' ) ) {
|
||||
if ( preg_match( '/archive-' . '.*\.php/i', basename( $template ) ) === 1 ) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
return $events->locate_view_path( 'archive' );
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
|
||||
add_filter( 'template_include', '_filter_fw_ext_events_template_include' );
|
||||
|
||||
function _action_fw_ext_events_option_types_init() {
|
||||
require_once dirname( __FILE__ ) . '/includes/option-types/event/class-fw-option-type-event.php';
|
||||
}
|
||||
add_action( 'fw_option_types_init', '_action_fw_ext_events_option_types_init' );
|
||||
@@ -0,0 +1,233 @@
|
||||
<?php if ( ! defined( 'FW' ) ) die( 'Forbidden' );
|
||||
|
||||
/**
|
||||
* Class FW_Option_Type_Event
|
||||
*
|
||||
* The option FW_Option_Type_Event is for internal use only.
|
||||
* Do not use it for posts/terms options as it will not affect events functionality.
|
||||
* It works only in the events page.
|
||||
*
|
||||
*/
|
||||
|
||||
class FW_Option_Type_Event extends FW_Option_Type {
|
||||
private $internal_options = array();
|
||||
|
||||
private static $extension;
|
||||
private $only_date_format = 'Y/m/d';
|
||||
private $min_date = '1970/01/01';
|
||||
private $max_date = '2038/01/19';
|
||||
|
||||
public function get_type()
|
||||
{
|
||||
return 'event';
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public function _init() {
|
||||
$ext = fw()->extensions->get( 'events' );
|
||||
|
||||
self::$extension = array(
|
||||
'path' => $ext->get_declared_path(),
|
||||
'URI' => $ext->get_declared_URI()
|
||||
);
|
||||
|
||||
$this->internal_options = array(
|
||||
'_gmaps_api_key' => array(
|
||||
'type' => 'gmap-key',
|
||||
'label' => __('Maps API Key'),
|
||||
'desc' => sprintf(
|
||||
__( 'Create an application in %sGoogle Console%s and add the Key here.', 'fw' ),
|
||||
'<a target="_blank" href="https://console.developers.google.com/flows/enableapi?apiid=places_backend,maps_backend,geocoding_backend,directions_backend,distance_matrix_backend,elevation_backend&keyType=CLIENT_SIDE&reusekey=true">',
|
||||
'</a>'
|
||||
),
|
||||
),
|
||||
|
||||
'event_location' => array(
|
||||
'label' => __('Event Location', 'fw'),
|
||||
'type' => 'map',
|
||||
'desc' => __('Where does the event take place?', 'fw'),
|
||||
),
|
||||
|
||||
'all_day' => array(
|
||||
'label' => __('All Day Event?', 'fw'),
|
||||
'desc' => __('Is your event an all day event?', 'fw'),
|
||||
'type' => 'switch',
|
||||
'right-choice' => array(
|
||||
'value' => 'yes',
|
||||
'label' => __('Yes', 'fw')
|
||||
),
|
||||
'left-choice' => array(
|
||||
'value' => 'no',
|
||||
'label' => __('No', 'fw')
|
||||
),
|
||||
'value' => 'no',
|
||||
),
|
||||
|
||||
'event_children' => array(
|
||||
'label' => __('Date & Time', 'fw'),
|
||||
'popup-title' => __('Add/Edit Date & Time', 'fw'),
|
||||
'type' => 'addable-popup',
|
||||
'desc' => false,
|
||||
'attr' => array('class' => 'fw-event-datetime'),
|
||||
'template' => '{{ if (event_date_range.from !== "" || event_date_range.to !== "") { print(event_date_range.from + " - " + event_date_range.to)} else { print("' . __('Note: Please set start & end event datetime', 'fw') . '")} }}',
|
||||
'popup-options' => array(
|
||||
apply_filters('fw_option_type_event_popup_options:before', array()),
|
||||
|
||||
'event_date_range' => array(
|
||||
'type' => 'datetime-range',
|
||||
'label' => __( 'Start & End of Event', 'fw' ),
|
||||
'desc' => __( 'Set start and end events datetime', 'fw' ),
|
||||
'datetime-pickers' => apply_filters( 'fw_option_type_event_datetime_pickers', array(
|
||||
'from' => array(
|
||||
'maxDate' => $this->max_date,
|
||||
'minDate' => $this->min_date,
|
||||
'extra-formats' => array( $this->only_date_format ),
|
||||
'fixed' => true,
|
||||
'timepicker' => true,
|
||||
'datepicker' => true,
|
||||
'defaultTime' => '08:00'
|
||||
),
|
||||
'to' => array(
|
||||
'maxDate' => $this->max_date,
|
||||
'minDate' => $this->min_date,
|
||||
'extra-formats' => array( $this->only_date_format ),
|
||||
'fixed' => true,
|
||||
'timepicker' => true,
|
||||
'datepicker' => true,
|
||||
'defaultTime' => '18:00'
|
||||
)
|
||||
) ),
|
||||
'value' => array(
|
||||
'from' => '',
|
||||
'to' => ''
|
||||
)
|
||||
),
|
||||
|
||||
'event-user' => array(
|
||||
'type' => 'multi-select',
|
||||
'label' =>__('Associated User','fw'),
|
||||
'population' => 'users',
|
||||
'desc' => __('Link this event to a specific user', 'fw'),
|
||||
'value' => array()
|
||||
),
|
||||
|
||||
apply_filters('fw_option_type_event_popup_options:after', array()),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function _enqueue_static($id, $option, $data)
|
||||
{
|
||||
wp_enqueue_script('fw-option-' . $this->get_type(),
|
||||
self::$extension['URI'] . '/includes/option-types/' . $this->get_type() . '/static/js/scripts.js',
|
||||
array('jquery', 'fw-events', 'editor', 'fw'),
|
||||
fw()->manifest->get_version()
|
||||
);
|
||||
wp_enqueue_style('fw-option-' . $this->get_type(),
|
||||
self::$extension['URI'] . '/includes/option-types/' . $this->get_type() . '/static/css/styles.css',
|
||||
array(),
|
||||
fw()->manifest->get_version()
|
||||
);
|
||||
|
||||
fw()->backend->enqueue_options_static($this->internal_options);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected function _render($id, $option, $data)
|
||||
{
|
||||
return fw_render_view( dirname(__FILE__) . '/view.php', array(
|
||||
'id' => $id,
|
||||
'option' => $option,
|
||||
'data' => $data,
|
||||
'internal_options' => $this->internal_options,
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected function _get_value_from_input($option, $input_value)
|
||||
{
|
||||
if (is_null($input_value)) {
|
||||
return $option['value'];
|
||||
} else {
|
||||
$value = fw_get_options_values_from_input(
|
||||
$this->internal_options,
|
||||
$input_value
|
||||
);
|
||||
|
||||
//remove time, if all_day selected
|
||||
$all_day = fw_akg('event_durability', $value);
|
||||
if ($all_day === 'yes') {
|
||||
foreach($value['event_datetime'] as $key => &$row) {
|
||||
if (isset($row['event_date_range']['from'])) {
|
||||
$row['event_date_range']['from'] = date($this->only_date_format, strtotime($row['event_date_range']['from']));
|
||||
}
|
||||
if (isset($row['event_date_range']['to'])) {
|
||||
$row['event_date_range']['to'] = date($this->only_date_format, strtotime($row['event_date_range']['to']));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public function _get_backend_width_type()
|
||||
{
|
||||
return 'full';
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
protected function _get_defaults()
|
||||
{
|
||||
return array(
|
||||
'value' => array()
|
||||
);
|
||||
}
|
||||
|
||||
protected function _storage_save($id, array $option, $value, array $params)
|
||||
{
|
||||
$value[$gmaps_option_id] = fw_db_option_storage_save(
|
||||
$gmaps_option_id = '_gmaps_api_key',
|
||||
array_merge( // use 'fw-storage' default param
|
||||
fw()->backend->option_type($this->internal_options[$gmaps_option_id]['type'])->get_defaults(),
|
||||
$this->internal_options[$gmaps_option_id]
|
||||
),
|
||||
isset($value[$gmaps_option_id]) ? $value[$gmaps_option_id] : null,
|
||||
$params
|
||||
);
|
||||
|
||||
return parent::_storage_save($id, $option, $value, $params);
|
||||
}
|
||||
|
||||
protected function _storage_load($id, array $option, $value, array $params)
|
||||
{
|
||||
$value[$gmaps_option_id] = fw_db_option_storage_load(
|
||||
$gmaps_option_id = '_gmaps_api_key',
|
||||
array_merge( // use 'fw-storage' default param
|
||||
fw()->backend->option_type($this->internal_options[$gmaps_option_id]['type'])->get_defaults(),
|
||||
$this->internal_options[$gmaps_option_id]
|
||||
),
|
||||
isset($value[$gmaps_option_id]) ? $value[$gmaps_option_id] : null,
|
||||
$params
|
||||
);
|
||||
|
||||
return parent::_storage_load($id, $option, $value, $params);
|
||||
}
|
||||
|
||||
}
|
||||
FW_Option_Type::register('FW_Option_Type_Event');
|
||||
@@ -0,0 +1,9 @@
|
||||
.fw-backend-option-type-event {
|
||||
padding-left: 0;
|
||||
padding-top: 0;
|
||||
padding-right: 0;
|
||||
}
|
||||
|
||||
.fw-option-type-event .fw-backend-option-design-default:last-child {
|
||||
border: none;
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
(function($, fwe) {
|
||||
|
||||
|
||||
var init = function() {
|
||||
var $eventOptionEl = $(this),
|
||||
$allDaySwitch = $eventOptionEl.find('[id="fw-option-general-event-all_day"] input'),
|
||||
$eventsPopup = $eventOptionEl.find('.fw-backend-option-input-type-addable-popup');
|
||||
|
||||
|
||||
/**
|
||||
* Update date_time format consider checkbox value
|
||||
*/
|
||||
fwe.on('fw:options:datetime-range:before-init', function(data){
|
||||
|
||||
if ( ! data.el.is( '#fw-edit-options-modal-event_date_range' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var $dateTimeFirstWrapper = data.el.find('.fw-option-type-datetime-picker:first'),
|
||||
$dateTimeLastWrapper = data.el.find('.fw-option-type-datetime-picker:last'),
|
||||
$dateTimeFirstInput = data.el.find('input'),
|
||||
$dateTimeLastInput = data.el.find('input'),
|
||||
dateTimeFirstAttrs = $dateTimeFirstWrapper.data('datetime-attr'),
|
||||
dateTimeLastAttrs = $dateTimeLastWrapper.data('datetime-attr'),
|
||||
format = 'Y/m/d H:i',
|
||||
newMomentFormat = 'YYYY/MM/DD HH:mm',
|
||||
timepicker = true;
|
||||
|
||||
if ($allDaySwitch.is(':checked')) {
|
||||
format = 'Y/m/d';
|
||||
newMomentFormat = 'YYYY/MM/DD';
|
||||
timepicker = false;
|
||||
|
||||
}
|
||||
|
||||
dateTimeFirstAttrs.format = format;
|
||||
dateTimeLastAttrs.format = format;
|
||||
dateTimeFirstAttrs.timepicker = timepicker;
|
||||
dateTimeLastAttrs.timepicker = timepicker;
|
||||
|
||||
$dateTimeLastWrapper.data('datetime-attr',dateTimeLastAttrs);
|
||||
$dateTimeFirstWrapper.data('datetime-attr',dateTimeFirstAttrs);
|
||||
|
||||
$dateTimeFirstInput.data('moment-format', newMomentFormat);
|
||||
$dateTimeLastInput.data('moment-format', newMomentFormat);
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Update values with new format
|
||||
*/
|
||||
fwe.on('fw:options:datetime-picker:before-init', function(data){
|
||||
|
||||
if (data.el.parents('.fw-option-type-datetime-range').length){
|
||||
var newMomentFormat = 'YYYY/MM/DD HH:mm';
|
||||
|
||||
if ($allDaySwitch.is(':checked')) {
|
||||
newMomentFormat = 'YYYY/MM/DD';
|
||||
}
|
||||
|
||||
if (data.el.val()) {
|
||||
var value = moment(data.el.val(), data.el.data('moment-format')).format(newMomentFormat);
|
||||
data.el.val(value);
|
||||
data.options.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$allDaySwitch.on('change', function(){
|
||||
var momentFormat = 'YYYY/MM/DD HH:mm',
|
||||
allDay = false;
|
||||
|
||||
if ($allDaySwitch.is(':checked')) {
|
||||
momentFormat = 'YYYY/MM/DD';
|
||||
allDay = true;
|
||||
}
|
||||
|
||||
$eventsPopup.find('.item:not(.disabled)').each(function(){
|
||||
var data = $.parseJSON($(this).find('input').val());
|
||||
if (data.event_date_range.from !== "" && data.event_date_range.to !== "" ) {
|
||||
var from = new Date(data.event_date_range.from),
|
||||
to = new Date(data.event_date_range.to);
|
||||
|
||||
if (allDay) {
|
||||
$(this).find('input').data('from-time', moment(from.toISOString()).format('HH:mm') );
|
||||
$(this).find('input').data('to-time', moment(to.toISOString()).format('HH:mm'));
|
||||
} else {
|
||||
var fromTime = moment($(this).find('input').data('from-time'), 'HH:mm').toDate(),
|
||||
toTime = moment($(this).find('input').data('to-time'), 'HH:mm').toDate();
|
||||
|
||||
from.setHours(fromTime.getHours());
|
||||
to.setHours(toTime.getHours());
|
||||
from.setMinutes(fromTime.getMinutes());
|
||||
to.setMinutes(toTime.getMinutes());
|
||||
|
||||
}
|
||||
|
||||
data.event_date_range.from = moment(from.toISOString()).format(momentFormat);
|
||||
data.event_date_range.to = moment(to.toISOString()).format(momentFormat);
|
||||
|
||||
$(this).find('input').val(JSON.stringify(data));
|
||||
$(this).find('.content').text(data.event_date_range.from + ' - ' + data.event_date_range.to);
|
||||
}
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
fwe.on('fw:options:init', function(data) {
|
||||
data.$elements
|
||||
.find('.fw-option-type-event:not(.fw-option-initialized)')
|
||||
.each(init)
|
||||
.addClass('fw-option-initialized');
|
||||
});
|
||||
|
||||
})(jQuery, fwEvents);
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php if (!defined('FW')) die('Forbidden');
|
||||
/**
|
||||
* @var array $option
|
||||
* @var array $data
|
||||
* @var string $id
|
||||
* @var array $internal_options
|
||||
|
||||
*/
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
$wrapper_attr = $option['attr'];
|
||||
unset($wrapper_attr['name'], $wrapper_attr['value']);
|
||||
|
||||
echo '<div ' . fw_attr_to_html($wrapper_attr) . '>';
|
||||
echo fw()->backend->render_options($internal_options, $data['value'], array(
|
||||
'id_prefix' => $data['id_prefix'] . $id . '-',
|
||||
'name_prefix' => $data['name_prefix'] . '[' . $id . ']'
|
||||
));
|
||||
echo '</div>';
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
$manifest = array();
|
||||
|
||||
$manifest['name'] = __( 'Events', 'fw' );
|
||||
$manifest['description'] = __( 'This extension adds a fully fledged Events module to your theme. It comes with built in pages that contain a calendar where events can be added.', 'fw' );
|
||||
$manifest['version'] = '1.0.15';
|
||||
$manifest['display'] = true;
|
||||
$manifest['standalone'] = true;
|
||||
$manifest['github_repo'] = 'https://github.com/ThemeFuse/Unyson-Events-Extension';
|
||||
$manifest['uri'] = 'http://manual.unyson.io/en/latest/extension/events/index.html#content';
|
||||
$manifest['author'] = 'ThemeFuse';
|
||||
$manifest['author_uri'] = 'http://themefuse.com/';
|
||||
|
||||
$manifest['github_update'] = 'ThemeFuse/Unyson-Events-Extension';
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
$options = apply_filters('fw_ext_events_settings_options', array());
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php if ( ! defined( 'FW' ) ) {
|
||||
die( 'Forbidden' );
|
||||
}
|
||||
|
||||
if ( !is_admin() ) {
|
||||
$ext_instance = fw()->extensions->get( 'events' );
|
||||
|
||||
if ( is_singular($ext_instance->get_post_type_name()) ) {
|
||||
wp_enqueue_style(
|
||||
'fw-extension-'. $ext_instance->get_name() .'-single-styles',
|
||||
$ext_instance->locate_css_URI( 'single-styles' ),
|
||||
array(),
|
||||
$ext_instance->manifest->get_version()
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'fw-extension-'. $ext_instance->get_name() .'-single-scripts',
|
||||
$ext_instance->locate_js_URI( 'single-scripts' ),
|
||||
array( 'jquery'),
|
||||
$ext_instance->manifest->get_version(),
|
||||
true
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
/* hide filter button*/
|
||||
.tablenav.top #post-query-submit {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media only screen and (min-width: 1350px) {
|
||||
#fw-option-general-event .fw-backend-option-input-type-map .fw-option-maps-tab .fw-col-sm-6{
|
||||
max-width: 214px;
|
||||
}
|
||||
|
||||
#fw-option-general-event .fw-backend-option-input-type-map .fw-option-maps-tab .fw-col-sm-6.map-googlemap {
|
||||
min-width: 430px;
|
||||
}
|
||||
|
||||
#fw-option-general-event .fw-backend-option-input-type-map .fw-inner.fw-pull-left{
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
.details-event{
|
||||
margin-left: 7px;
|
||||
padding-left: 0;
|
||||
}
|
||||
.details-event li {
|
||||
line-height: 2em;
|
||||
list-style: none;
|
||||
}
|
||||
.details-event li a{
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.details-event li a:hover{
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.details-event-button{
|
||||
display: inline-block;
|
||||
float: right;
|
||||
margin-top: 27px;
|
||||
margin-right: 7px;
|
||||
}
|
||||
|
||||
.details-event-button button{
|
||||
text-transform: uppercase;
|
||||
font-weight: normal;
|
||||
}
|
||||
.details-event-button button:last-child{
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
.before-hr{
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
/* Responsive */
|
||||
|
||||
/*Screen 768px*/
|
||||
@media(max-width:991px){
|
||||
|
||||
.details-event-button{
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.details-event-button button{
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*Screen 568px*/
|
||||
@media(max-width:767px){
|
||||
.details-event-button{
|
||||
margin-top: 7px;
|
||||
}
|
||||
.details-event-button button{
|
||||
display: inline-block;
|
||||
margin-right: 3px;
|
||||
}
|
||||
.details-event-button button:last-child{
|
||||
margin-right: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*Screen 480px*/
|
||||
@media(max-width:500px){
|
||||
.details-event-button button{
|
||||
display: block;
|
||||
margin-bottom: 5px;
|
||||
margin-right: 0;
|
||||
}
|
||||
.details-event-button button:last-child{
|
||||
float: right;
|
||||
}
|
||||
}
|
||||
|
||||
/*Screen 320px*/
|
||||
@media(max-width:479px){
|
||||
.details-event-button{
|
||||
margin-bottom: 14px;
|
||||
margin-top: 0;
|
||||
margin-right: 0;
|
||||
float: none;
|
||||
}
|
||||
.details-event-button button{
|
||||
margin-bottom: 0;
|
||||
margin-right: 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
.details-event-button button:last-child{
|
||||
float: none;
|
||||
}
|
||||
}
|
||||
|
||||
.fw-shortcode-map-wrapper.unyson-initialized{
|
||||
margin-bottom: 34px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
( function ( $ ) {
|
||||
|
||||
var insertParam2 = function ( key, value, uri ) {
|
||||
|
||||
key = encodeURI( key );
|
||||
|
||||
var kvp = key + "=" + encodeURI( value ),
|
||||
r = new RegExp( "(&|\\?)" + key + "=[^\&]*" );
|
||||
|
||||
uri = uri.replace( r, "$1" + kvp );
|
||||
|
||||
if ( ! uri.match( r ) ) {
|
||||
uri += ( uri.length > 0 ? '&' : '?' ) + kvp;
|
||||
}
|
||||
|
||||
return uri
|
||||
};
|
||||
|
||||
var initButton = function () {
|
||||
var $button = $( this ),
|
||||
uri = $button.data( 'uri' ),
|
||||
gmtOffset = new Date().getTimezoneOffset() * 60,
|
||||
options = "toolbar=yes,menubar=yes,location=yes,status=yes,scrollbars=yes,resizable=yes,width=800,height=600,left=0,top=0";
|
||||
|
||||
uri = insertParam2( 'offset', gmtOffset, uri );
|
||||
|
||||
window.open( uri, "calendar", options );
|
||||
};
|
||||
|
||||
$( document ).ready( function () {
|
||||
$( '.details-event-button button' ).on( 'click', initButton );
|
||||
} );
|
||||
|
||||
} )( jQuery );
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php if ( ! defined( 'FW' ) ) die( 'Forbidden' );
|
||||
/**
|
||||
* @var string $the_content
|
||||
*/
|
||||
|
||||
global $post;
|
||||
$options = fw_get_db_post_option($post->ID, fw()->extensions->get( 'events' )->get_event_option_id());
|
||||
?>
|
||||
<hr class="before-hr"/>
|
||||
<?php foreach($options['event_children'] as $key => $row) : ?>
|
||||
<?php if (empty($row['event_date_range']['from']) or empty($row['event_date_range']['to'])) : ?>
|
||||
<?php continue; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="details-event-button">
|
||||
<button data-uri="<?php echo esc_attr(add_query_arg( array( 'row_id' => $key, 'calendar' => 'google' ), fw_current_url() )); ?>" type="button"><?php _e('Google Calendar', 'fw') ?></button>
|
||||
<button data-uri="<?php echo esc_attr(add_query_arg( array( 'row_id' => $key, 'calendar' => 'ical' ), fw_current_url() )); ?>" type="button"><?php _e('Ical Export', 'fw') ?></button>
|
||||
</div>
|
||||
<ul class="details-event">
|
||||
<li><b><?php _e('Start', 'fw') ?>:</b> <?php echo $row['event_date_range']['from']; ?></li>
|
||||
<li><b><?php _e('End', 'fw') ?>:</b> <?php echo $row['event_date_range']['to']; ?></li>
|
||||
|
||||
<?php if (empty($row['event-user']) === false) : ?>
|
||||
<li>
|
||||
<b><?php _e('Speakers', 'fw') ?>:</b>
|
||||
<?php foreach($row['event-user'] as $user_id ) : ?>
|
||||
<?php $user_info = get_userdata($user_id); ?>
|
||||
<?php echo esc_html( $user_info->display_name ); ?>
|
||||
<?php echo ($user_id !== end($row['event-user']) ? ', ' : '' ); ?>
|
||||
<?php endforeach; ?>
|
||||
</li>
|
||||
<?php endif;?>
|
||||
|
||||
</ul>
|
||||
<hr class="after-hr"/>
|
||||
<?php endforeach; ?>
|
||||
<!-- .additional information about event -->
|
||||
|
||||
<!-- call map shortcode -->
|
||||
<?php echo fw_ext_events_render_map() ?>
|
||||
<!-- .call map shortcode -->
|
||||
|
||||
<?php echo $the_content; ?>
|
||||
|
||||
<?php do_action('fw_ext_events_single_after_content'); ?>
|
||||
Reference in New Issue
Block a user