Exemple #1
0
/**
 * 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 ctc_sermon_data($post_id = null)
{
    // Get meta values
    $data = ctc_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'] = ctc_embed_code($data['video']);
    $data['audio_player'] = ctc_embed_code($data['audio']);
    // Get download URL's
    // Only local files can have "Save As" forced
    // Only local files can are always actual files, not pages (ie. YouTube, SoundCloud, etc.)
    // Video and Audio URL's may be pages on other site (YouTube, SoundCloud, etc.), so provide download URL only for local files
    // PDF is likely always to be actual file, so provide download URL no matter what (although cannot force "Save As" on external sites)
    $data['video_download_url'] = ctc_is_local_url($data['video']) ? ctc_force_download_url($data['video']) : '';
    // provide URL only if local so know it is actual file (not page) and can force "Save As"
    $data['audio_download_url'] = ctc_is_local_url($data['audio']) ? ctc_force_download_url($data['audio']) : '';
    // provide URL only if local so know it is actual file (not page) and can force "Save As"
    $data['pdf_download_url'] = ctc_force_download_url($data['pdf']);
    // provide URL only if local so know it is actual file (not page) and can force "Save As"
    // Return filtered
    return apply_filters('ctc_sermon_data', $data);
}
Exemple #2
0
/**
 * Convert regular URL to one that forces download ("Save As")
 *
 * This keeps the browser from doing what it wants with the file (such as play MP3 or show PDF).
 * Note that file must be in uploads folder and extension must be allowed by WordPress.
 *
 * Makes this:	http://yourname.com/?download=%2F2009%2F10%2Ffile.pdf
 * Out of:		http://yourname.com/wp-content/uploads/2013/05/file.pdf
 * 				http://yourname.com/wp-content/uploads/sites/6/2013/05/file.pdf (multisite)
 *
 * @since 0.9
 * @param string $url URL for file
 * @return string URL forcing "Save As" on file if local
 */
function ctc_force_download_url($url)
{
    // In case URL is not local or feature not supported by theme
    $download_url = $url;
    // Theme supports this?
    if (current_theme_supports('ctc-force-downloads')) {
        // Is URL local?
        if (ctc_is_local_url($url)) {
            // Get URL to upload directory
            $upload_dir = wp_upload_dir();
            $upload_dir_url = $upload_dir['baseurl'];
            // Get relative URL for file
            $relative_url = str_replace($upload_dir_url, '', $url);
            // remove base URL
            $relative_url = ltrim($relative_url);
            // remove preceding slash
            // Add ?download=file to site URL
            $download_url = home_url('/') . '?download=' . urlencode($relative_url);
        }
    }
    return apply_filters('ctc_force_download_url', $download_url, $url);
}