示例#1
0
 /**
  * Constructor.
  *
  * @since 3.0.0
  */
 public function __construct()
 {
     $this->id = 'feeds';
     $this->option_group = 'settings';
     $this->label = __('Event Sources', 'google-calendar-events');
     //$this->description  = __( 'Manage calendar event sources settings.', 'google-calendar-events' );
     $feeds_settings = array();
     $feeds = simcal_get_feed_types();
     if (!empty($feeds) && is_array($feeds)) {
         foreach ($feeds as $feed) {
             $feed_type = simcal_get_feed($feed);
             if ($feed_type instanceof Feed) {
                 $settings = $feed_type->settings_fields();
                 if (!empty($settings)) {
                     $feeds_settings[$feed] = $settings;
                 }
             }
         }
     }
     $this->feed_types = $feeds_settings;
     $this->sections = $this->add_sections();
     $this->fields = $this->add_fields();
 }
/**
 * 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');
}
示例#3
0
    /**
     * Print the meta box settings handle.
     *
     * @since  3.0.0
     * @access  private
     *
     * @param \WP_Post $post
     */
    private static function settings_handle($post)
    {
        $feed_options = $calendar_options = $calendar_views = array();
        $feed_types = simcal_get_feed_types();
        foreach ($feed_types as $feed_type) {
            $feed = simcal_get_feed($feed_type);
            if ($feed instanceof Feed) {
                $feed_options[$feed_type] = $feed->name;
            }
        }
        $calendar_types = simcal_get_calendar_types();
        foreach ($calendar_types as $calendar_type => $views) {
            $calendar = simcal_get_calendar($calendar_type);
            if ($calendar instanceof Calendar) {
                $calendar_options[$calendar_type] = $calendar->name;
                $calendar_views[$calendar_type] = $calendar->views;
            }
        }
        if ($feed_options) {
            if ($feed_types = wp_get_object_terms($post->ID, 'calendar_feed')) {
                $feed_type = sanitize_title(current($feed_types)->name);
            } else {
                $feed_type = apply_filters('simcal_default_feed_type', 'google');
            }
            ?>
			<label for="_feed_type"><span><?php 
            _e('Event Source', 'google-calendar-events');
            ?>
</span>
				<select name="_feed_type" id="_feed_type">
					<optgroup label="<?php 
            _ex('Get events from', 'From which calendar source to load events from', 'google-calendar-events');
            ?>
">
						<?php 
            foreach ($feed_options as $feed => $name) {
                ?>
							<option value="<?php 
                echo $feed;
                ?>
" <?php 
                selected($feed, $feed_type, true);
                ?>
><?php 
                echo $name;
                ?>
</option>
						<?php 
            }
            ?>
					</optgroup>
				</select>
			</label>
			<?php 
        }
        if ($calendar_options) {
            if ($calendar_types = wp_get_object_terms($post->ID, 'calendar_type')) {
                $calendar_type = sanitize_title(current($calendar_types)->name);
            } else {
                $calendar_type = apply_filters('simcal_default_calendar_type', 'default-calendar');
            }
            ?>
			<label for="_calendar_type"><span><?php 
            _e('Calendar', 'google-calendar-events');
            ?>
</span>
				<select name="_calendar_type" id="_calendar_type">
					<optgroup label="<?php 
            _e('Calendar to use', 'google-calendar-events');
            ?>
">
						<?php 
            foreach ($calendar_options as $calendar => $name) {
                ?>
							<option value="<?php 
                echo $calendar;
                ?>
" <?php 
                selected($calendar, $calendar_type, true);
                ?>
><?php 
                echo $name;
                ?>
</option>
						<?php 
            }
            ?>
					</optgroup>
				</select>
			</label>
			<?php 
            if ($calendar_views) {
                $calendar_view = get_post_meta($post->ID, '_calendar_view', true);
                foreach ($calendar_views as $calendar => $views) {
                    $calendar_type_view = isset($calendar_view[$calendar]) ? $calendar_view[$calendar] : '';
                    ?>
					<label for="_calendar_view_<?php 
                    echo $calendar;
                    ?>
"><span><?php 
                    _e('View', 'google-calendar-events');
                    ?>
</span>
						<select name="_calendar_view[<?php 
                    echo $calendar;
                    ?>
]" id="_calendar_view_<?php 
                    echo $calendar;
                    ?>
">
							<optgroup label="<?php 
                    _e('View to display', 'google-calendar-events');
                    ?>
">
								<?php 
                    foreach ($views as $view => $name) {
                        ?>
									<option value="<?php 
                        echo $view;
                        ?>
" <?php 
                        selected($view, $calendar_type_view, true);
                        ?>
><?php 
                        echo $name;
                        ?>
</option>
								<?php 
                    }
                    ?>
							</optgroup>
						</select>
					</label>
					<?php 
                }
            }
        }
    }
/**
 * 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');
}