/** * Output the meta box markup. * * @since 3.0.0 * * @param \WP_Post $post */ public static function html($post) { // @see Meta_Boxes::save_meta_boxes() wp_nonce_field('simcal_save_data', 'simcal_meta_nonce'); $calendars = simcal_get_calendars(); simcal_print_field(array('type' => 'select', 'id' => '_simcal_attach_calendar_id', 'name' => '_simcal_attach_calendar_id', 'enhanced' => count($calendars) > 15 ? 'enhanced' : '', 'allow_void' => 'allow_void', 'value' => absint(get_post_meta($post->ID, '_simcal_attach_calendar_id', true)), 'options' => $calendars, 'attributes' => array('data-allowclear' => 'true'))); $position = get_post_meta($post->ID, '_simcal_attach_calendar_position', true); simcal_print_field(array('type' => 'radio', 'id' => '_simcal_attach_calendar_position', 'name' => '_simcal_attach_calendar_position', 'value' => $position ? $position : 'after', 'options' => array('after' => __('After Content', 'google-calendar-events'), 'before' => __('Before Content', 'google-calendar-events')))); }
/** * Constructor. * * @since 3.0.0 */ public function __construct() { $id_base = 'gce_widget'; // old id kept for legacy reasons $name = __('Simple Calendar', 'google-calendar-events'); $widget_options = array('description' => __('Display a calendar of events from one of your calendar feeds.', 'google-calendar-events')); parent::__construct($id_base, $name, $widget_options); if (is_admin()) { if (!defined('DOING_AJAX')) { $this->calendars = simcal_get_calendars(); } else { $this->calendars = get_transient('_simple-calendar_feed_ids'); } } }
/** * Add meta boxes. * * @since 3.0.0 */ public function add_meta_boxes() { add_meta_box('simcal-calendar-settings', __('Calendar Settings', 'google-calendar-events'), '\\SimpleCalendar\\Admin\\Metaboxes\\Settings::html', 'calendar', 'normal', 'core'); $addons = apply_filters('simcal_installed_addons', array()); if (empty($addons)) { add_meta_box('simcal-newsletter', __('Get 20% off Google Calendar Pro!', 'google-calendar-events'), '\\SimpleCalendar\\Admin\\Metaboxes\\Newsletter::html', 'calendar', 'side', 'default'); } add_meta_box('simcal-get-shortcode', __('Calendar Shortcode', 'google-calendar-events'), '\\SimpleCalendar\\Admin\\Metaboxes\\Get_Shortcode::html', 'calendar', 'side', 'default'); // Add meta box if there are calendars. if (true == simcal_get_calendars() && !empty($this->post_types)) { foreach ($this->post_types as $post_type) { add_meta_box('simcal-attach-calendar', __('Attach Calendar', 'google-calendar-events'), '\\SimpleCalendar\\Admin\\Metaboxes\\Attach_Calendar::html', $post_type, 'side', 'low'); } } do_action('simcal_add_meta_boxes'); }
/** * Clear feed transients cache. * * @since 3.0.0 * * @param string|int|array|\WP_Post $id * * @return bool */ function simcal_delete_feed_transients($id = '') { $grouped_ids = get_post_meta($id, '_grouped_calendars_ids', true); // If there are group IDs we need to construct an array to pass along with the grouped IDs + the original $post_id if (is_array($grouped_ids)) { $temp_id = $id; $id = $grouped_ids; $id[] = $temp_id; } if (is_numeric($id)) { $id = intval($id) > 0 ? absint($id) : simcal_get_calendars(); } elseif ($id instanceof WP_Post) { $id = $id->ID; } elseif (is_array($id)) { $id = array_map('absint', $id); } else { $id = simcal_get_calendars('', true); } $feed_types = simcal_get_feed_types(); if (is_array($id)) { $posts = get_posts(array('post_type' => 'calendar', 'fields' => 'ids', 'post__in' => $id, 'nopaging' => true)); foreach ($posts as $post) { $calendar = simcal_get_calendar($post); if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) { foreach ($feed_types as $feed_type) { delete_transient('_simple-calendar_feed_id_' . strval($calendar->id) . '_' . $feed_type); } } } } else { $post = get_post($id); $calendar = simcal_get_calendar($post); if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) { foreach ($feed_types as $feed_type) { delete_transient('_simple-calendar_feed_id_' . strval($calendar->id) . '_' . $feed_type); } } } return delete_transient('_simple-calendar_feed_ids'); }
/** * Add a panel to the settings meta box. * * @since 3.0.0 * * @param int $post_id */ public function add_settings_meta_panel($post_id) { ?> <div id="grouped-calendars-settings-panel" class="simcal-panel"> <table> <thead> <tr><th colspan="2"><?php _e('Grouped Calendar Settings', 'google-calendar-events'); ?> </th></tr> </thead> <tbody class="simcal-panel-section"> <tr class="simcal-panel-field"> <th><label for="_grouped_calendars_source"><?php _e('Get Calendars From', 'google-calendar-events'); ?> </label></th> <td> <?php $source = esc_attr(get_post_meta($post_id, '_grouped_calendars_source', true)); $source = empty($source) ? 'ids' : $source; ?> <select name="_grouped_calendars_source" id="_grouped_calendars_source" class="simcal-field simcal-field-select simcal-field-inline simcal-field-show-other" data-show-field-on-choice="true"> <option value="ids" data-show-field="_grouped_calendars_ids" <?php selected('ids', $source, true); ?> ><?php _e('Manual selection', 'google-calendar-events'); ?> </option> <option value="category" data-show-field="_grouped_calendars_category" <?php selected('category', $source, true); ?> ><?php _e('Category', 'google-calendar-events'); ?> </option> </select> <i class="simcal-icon-help simcal-help-tip" data-tip="<?php _e('Choose from which calendar feeds you want to get events from. Choose them individually or select all those belonging to calendar feed categories.', 'google-calendar-events'); ?> "></i> <br><br> <?php $cals = simcal_get_calendars($post_id); $meta = get_post_meta($post_id, '_grouped_calendars_ids', true); $ids = $meta && is_array($meta) ? implode(',', array_map('absint', $meta)) : absint($meta); simcal_print_field(array('type' => 'select', 'multiselect' => 'multiselect', 'name' => '_grouped_calendars_ids', 'id' => '_grouped_calendars_ids', 'value' => $ids !== 0 ? $ids : '', 'options' => $cals, 'enhanced' => 'enhanced', 'style' => 'ids' == $source ? '' : array('display' => 'none'), 'attributes' => array('data-noresults' => __('No results found.', 'google-calendar-events')))); $meta = get_post_meta($post_id, '_grouped_calendars_category', true); $category = $meta && is_array($meta) ? implode(',', array_map('absint', $meta)) : ''; $terms = get_terms('calendar_category'); if (!empty($terms)) { $categories = array(); foreach ($terms as $term) { $categories[$term->term_id] = $term->name; } simcal_print_field(array('type' => 'select', 'multiselect' => 'multiselect', 'name' => '_grouped_calendars_category', 'id' => '_grouped_calendars_category', 'value' => $category, 'options' => $categories, 'enhanced' => 'enhanced', 'style' => 'category' == $source ? '' : array('display' => 'none'), 'attributes' => array('data-noresults' => __('No results found.', 'google-calendar-events')))); } else { $style = 'category' == $source ? '' : 'display: none;'; $style .= ' width: 100%; max-width: 500px'; echo '<input type="text" disabled="disabled" name="_grouped_calendars_category" id="_grouped_calendars_category" style="' . $style . '" placeholder="' . __('There are no calendar categories yet.', 'google-calendar-events') . '" />'; } ?> </td> </tr> </tbody> </table> </div> <?php }
/** * Add meta boxes. * * @since 3.0.0 */ public function add_meta_boxes() { add_meta_box('simcal-calendar-settings', __('Calendar Settings', 'google-calendar-events'), '\\SimpleCalendar\\Admin\\Metaboxes\\Settings::html', 'calendar', 'normal', 'core'); $addons = apply_filters('simcal_installed_addons', array()); if (empty($addons)) { // Premium add-on feature list and upsell. add_meta_box('simcal-upgrade', __('Looking for more?', 'google-calendar-events'), '\\SimpleCalendar\\Admin\\Metaboxes\\Upgrade_To_Premium::html', 'calendar', 'side', 'default'); // Removing coupon code + mailing list sign-up for now. 9/26/16 /* add_meta_box( 'simcal-newsletter', __( 'Get 20% off all Pro Add-ons', 'google-calendar-events' ), '\SimpleCalendar\Admin\Metaboxes\Newsletter::html', 'calendar', 'side', 'default' ); */ } add_meta_box('simcal-get-shortcode', __('Calendar Shortcode', 'google-calendar-events'), '\\SimpleCalendar\\Admin\\Metaboxes\\Get_Shortcode::html', 'calendar', 'side', 'default'); // Add meta box if there are calendars. if (true == simcal_get_calendars() && !empty($this->post_types)) { foreach ($this->post_types as $post_type) { add_meta_box('simcal-attach-calendar', __('Attach Calendar', 'google-calendar-events'), '\\SimpleCalendar\\Admin\\Metaboxes\\Attach_Calendar::html', $post_type, 'side', 'low'); } } do_action('simcal_add_meta_boxes'); }
/** * Clear feed transients cache. * * @since 3.0.0 * * @param string|int|array|\WP_Post $id * * @return bool */ function simcal_delete_feed_transients($id = '') { if (is_numeric($id)) { $id = intval($id) > 0 ? absint($id) : simcal_get_calendars(); } elseif ($id instanceof WP_Post) { $id = $id->ID; } elseif (is_array($id)) { $id = array_map('absint', $id); } else { $id = simcal_get_calendars('', true); } $feed_types = simcal_get_feed_types(); if (is_array($id)) { $posts = get_posts(array('post_type' => 'calendar', 'fields' => 'ids', 'post__in' => $id, 'nopaging' => true)); foreach ($posts as $post) { $calendar = simcal_get_calendar($post); if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) { foreach ($feed_types as $feed_type) { delete_transient('_simple-calendar_feed_id_' . strval($calendar->id) . '_' . $feed_type); } } } } else { $post = get_post($id); $calendar = simcal_get_calendar($post); if ($calendar instanceof \SimpleCalendar\Abstracts\Calendar) { foreach ($feed_types as $feed_type) { delete_transient('_simple-calendar_feed_id_' . strval($calendar->id) . '_' . $feed_type); } } } return delete_transient('_simple-calendar_feed_ids'); }
/** * Panel for the add shortcode media button. * * Prints the panel for choosing a calendar to insert as a shortcode in a page or post. * * @since 3.0.0 */ public function add_shortcode_panel() { $calendars = simcal_get_calendars(); ?> <div id="simcal-insert-shortcode-panel" style="display:none;"> <div class="simcal-insert-shortcode-panel"> <h1><?php _e('Add Calendar', 'google-calendar-events'); ?> </h1> <?php _e('Add a calendar to your post.', 'google-calendar-events'); ?> <?php if (!empty($calendars) && is_array($calendars)) { ?> <p> <label for="simcal-choose-calendar"> <?php $multiselect = count($calendars) > 15 ? ' simcal-field-select-enhanced' : ''; ?> <select id="simcal-choose-calendar" class="simcal-field simcal-field-select<?php echo $multiselect; ?> " name=""> <?php foreach ($calendars as $id => $title) { ?> <option value="<?php echo $id; ?> "><?php echo $title; ?> </option> <?php } ?> </select> </label> </p> <p><input type="button" value="<?php _e('Insert Calendar', 'google-calendar-events'); ?> " id="simcal-insert-shortcode" class="button button-primary button-large" name="" /></p> <?php } else { ?> <p><em><?php _e('Could not find any calendars to add to this post.', 'google-calendar-events'); ?> </em></p> <strong><a href="post-new.php?post_type=calendar"><?php _e('Please add and configure new calendar first.', 'google-calendar-events'); ?> </a></strong> <?php } ?> </div> </div> <?php }