/** * Get person data * * @since 0.9 * @param int $post_id Post ID to get data for; null for current post * @return array Person data */ function ctfw_person_data($post_id = null) { // Get meta values $data = ctfw_get_meta_data(array('position', 'phone', 'email', 'urls'), $post_id); // Return filtered return apply_filters('ctfw_person_data', $data); }
/** * Get sermon data * * @since 0.9 * @param int $post_id Post ID to get data for; null for current post * @return array Sermon data */ function ctfw_sermon_data($post_id = null) { // Get URL to upload directory $upload_dir = wp_upload_dir(); $upload_dir_url = $upload_dir['baseurl']; // Get meta values $data = ctfw_get_meta_data(array('video', 'audio', 'pdf', 'has_full_text'), $post_id); // Get media player code // Embed code generated from uploaded file, URL for file on other site, page on oEmbed-supported site, or manual embed code (HTML or shortcode) $data['video_player'] = ctfw_embed_code($data['video']); $data['audio_player'] = ctfw_embed_code($data['audio']); // Get file data for media // Path and size will be populated for local files only $media_types = array('audio', 'video', 'pdf'); foreach ($media_types as $media_type) { $data[$media_type . '_extension'] = ''; $data[$media_type . '_path'] = ''; $data[$media_type . '_size_bytes'] = ''; $data[$media_type . '_size'] = ''; // Get extension // This can be determined for local and external files // Empty for YouTube, SoundCloud, etc. $filetype = wp_check_filetype($data[$media_type]); $data[$media_type . '_extension'] = $filetype['ext']; // File is local, so can get path and size if ($data[$media_type] && ctfw_is_local_url($data[$media_type])) { // Local path $data[$media_type . '_path'] = $upload_dir['basedir'] . str_replace($upload_dir_url, '', $data[$media_type]); // Exists? if (!file_exists($data[$media_type . '_path'])) { $data[$media_type . '_path'] = ''; // clear it } else { // File type $filetype = wp_check_filetype($data[$media_type]); $data[$media_type . '_extension'] = $filetype['ext']; // File size $data[$media_type . '_size_bytes'] = filesize($data[$media_type . '_path']); $data[$media_type . '_size'] = size_format($data[$media_type . '_size_bytes']); // 30 MB, 2 GB, 220 kB, etc. } } } // Get download URL's // URL is returned if is local or external and has an extension. // Those without an extension (YouTube, SoundCloud, etc. page URL) return empty (nothing to download). // If locally hosted, URL is changed to force "Save As" via headers. // Use <a href="" download="download"> to attempt Save As via limited browser support for externally hosted files. $data['video_download_url'] = ctfw_download_url($data['video']); $data['audio_download_url'] = ctfw_download_url($data['audio']); $data['pdf_download_url'] = ctfw_download_url($data['pdf']); // Has at least one downloadable file URL? $data['has_download'] = false; if ($data['video_download_url'] || $data['audio_download_url'] || $data['pdf_download_url']) { // path empty if doesn't exist $data['has_download'] = true; } // Return filtered return apply_filters('ctfw_sermon_data', $data); }
/** * 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); }
/** * 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 – %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 – %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); }