Exemplo n.º 1
0
/**
 * Get location data
 *
 * @since 0.9
 * @param int $post_id Post ID to get data for; null for current post
 * @return array Location data
 */
function ctfw_location_data($post_id = null)
{
    // Get meta values
    $data = ctfw_get_meta_data(array('address', 'show_directions_link', 'phone', 'email', 'times', 'map_lat', 'map_lng', 'map_type', 'map_zoom'), $post_id);
    // Add directions URL (empty if show_directions_link not set)
    $data['directions_url'] = $data['show_directions_link'] ? ctfw_directions_url($data['address']) : '';
    // Map has coordinates?
    $data['map_has_coordinates'] = $data['map_lat'] && $data['map_lng'] ? true : false;
    // Return filtered
    return apply_filters('ctfw_location_data', $data, $post_id);
}
Exemplo n.º 2
0
/**
 * Get event data
 *
 * @since 0.9
 * @param array|int $args post_id or array of arguments; If no post ID, current post used
 * @return array Event data
 */
function ctfw_event_data($args = array())
{
    // Post ID given instead of args array?
    if (is_numeric($args)) {
        $args = array('post_id' => $args);
    }
    // Default arguments
    $args = wp_parse_args($args, array('post_id' => null, 'time_and_desc_format' => __('%1$s <span>(%2$s)</span>', 'church-theme-framework')));
    // Extract arguments to variables
    extract($args);
    // Get meta values
    $meta = ctfw_get_meta_data(array('start_date', 'end_date', 'time', 'start_time', 'end_time', 'hide_time_range', 'recurrence', 'recurrence_end_date', 'recurrence_weekly_interval', 'recurrence_monthly_interval', 'recurrence_monthly_type', 'recurrence_monthly_week', 'venue', 'address', 'show_directions_link', 'map_lat', 'map_lng', 'map_type', 'map_zoom'), $post_id);
    // Empty Custom Recurring Events add-on values if plugin not active
    // This keeps theme from displaying recurrence data that may be stored but is not effective
    if (!defined('CTC_CRE_VERSION')) {
        $meta['recurrence_weekly_interval'] = 1;
        $meta['recurrence_monthly_interval'] = 1;
        $meta['recurrence_monthly_type'] = 'day';
        $meta['recurrence_monthly_week'] = '';
    }
    // Timestamps
    $start_date_timestamp = strtotime($meta['start_date']);
    $end_date_timestamp = strtotime($meta['end_date']);
    // Add friendly date
    $date_format = get_option('date_format');
    if ($meta['end_date'] != $meta['start_date']) {
        // date range
        // Date formats
        // Make compact range of "June 1 - 5, 2015 if using "F j, Y" format (month and year removed from start date as not to be redundant)
        // If year is same but month different, becomes "June 30 - July 1, 2015"
        $start_date_format = $date_format;
        $end_date_format = $date_format;
        if ('F j, Y' == $date_format && date_i18n('Y', $start_date_timestamp) == date_i18n('Y', $end_date_timestamp)) {
            // Year on both dates must be same
            // Remove year from start date
            $start_date_format = 'F j';
            // Months and year is same
            // Remove month from end date
            if (date_i18n('F', $start_date_timestamp) == date_i18n('F', $end_date_timestamp)) {
                $end_date_format = 'j, Y';
            }
        }
        // Format dates
        $start_date_formatted = date_i18n($start_date_format, $start_date_timestamp);
        $end_date_formatted = date_i18n($end_date_format, $end_date_timestamp);
        // Build range
        /* translators: date range */
        $meta['date'] = sprintf(_x('%1$s &ndash; %2$s', 'dates', 'church-theme-framework'), $start_date_formatted, $end_date_formatted);
    } else {
        // start date only
        $meta['date'] = date_i18n($date_format, $start_date_timestamp);
    }
    // Format Start and End Time
    $time_format = get_option('time_format');
    $meta['start_time_formatted'] = $meta['start_time'] ? date_i18n($time_format, strtotime($meta['start_time'])) : '';
    $meta['end_time_formatted'] = $meta['end_time'] ? date_i18n($time_format, strtotime($meta['end_time'])) : '';
    // Time Range
    // Show Start/End Time range (or only Start Time)
    $meta['time_range'] = '';
    if ($meta['start_time_formatted']) {
        // Start Time Only
        $meta['time_range'] = $meta['start_time_formatted'];
        // Start and End Time (Range)
        if ($meta['end_time_formatted']) {
            // Time Range
            /* translators: time range */
            $meta['time_range'] = sprintf(_x('%1$s &ndash; %2$s', 'times', 'church-theme-framework'), $meta['start_time_formatted'], $meta['end_time_formatted']);
        }
    }
    // Time and/or Description
    // Show Start/End Time (if given) and maybe Time Description (if given) in parenthesis
    // If no Start/End Time (or it is set to hide), show Time Description by itself
    // This is useful for event post header
    $meta['time_range_and_description'] = '';
    $meta['time_range_or_description'] = '';
    if ($meta['time_range'] && !$meta['hide_time_range']) {
        // Show Time Range and maybe Description after it
        // Definitely show time range
        $meta['time_range_and_description'] = $meta['time_range'];
        $meta['time_range_or_description'] = $meta['time_range'];
        // Maybe show description after time range
        if ($meta['time']) {
            // Time and Description
            $meta['time_range_and_description'] = sprintf($time_and_desc_format, $meta['time_range'], $meta['time']);
        }
    } else {
        // Show description only
        $meta['time_range_and_description'] = $meta['time'];
        $meta['time_range_or_description'] = $meta['time'];
    }
    // Add directions URL (empty if show_directions_link not set)
    $meta['directions_url'] = $meta['show_directions_link'] ? ctfw_directions_url($meta['address']) : '';
    // Recurrence note
    $recurrence_note = ctfw_event_recurrence_note(false, $meta);
    $meta['recurrence_note'] = isset($recurrence_note['full']) ? $recurrence_note['full'] : '';
    // sentence such as "Every 3 months on the second Wednesday until January 24, 2018"
    $meta['recurrence_note_short'] = isset($recurrence_note['short']) ? $recurrence_note['short'] : '';
    // short version such as "Every 3 Months" (can show this with full on tooltip)
    // Map has coordinates?
    $meta['map_has_coordinates'] = $meta['map_lat'] && $meta['map_lng'] ? true : false;
    // Return filtered
    return apply_filters('ctfw_event_data', $meta, $post_id);
}