/** * Automatically resample and save the downsized versions of each graphic. * * @param array $meta * * @return array */ function filter_images($meta) { $n = function ($function) { return __NAMESPACE__ . "\\{$function}"; }; add_filter('image_resize_dimensions', $n('upscale_dimensions'), 1, 6); $uploads = wp_upload_dir(); // Generate a placeholder for the full image $file = basename($meta['file']); $file_base_path = trailingslashit($uploads['basedir']) . str_replace($file, '', $meta['file']); $new_parent = create_placeholder($file, $file_base_path); // Generate placeholders for each image size foreach ($meta['sizes'] as $name => $data) { if (false !== strpos($name, '-ph')) { $new_file = create_placeholder($data['file'], $file_base_path); $meta['sizes'][$name]['file'] = $new_file; } } $file_ext = pathinfo($file, PATHINFO_EXTENSION); $mime_type = 'application/octet-stream'; $mime_types = wp_get_mime_types(); foreach ($mime_types as $extension => $type) { if (preg_match("/{$file_ext}/i", $extension)) { $mime_type = $type; break; } } $meta['sizes']['full-ph'] = array('file' => $new_parent, 'width' => $meta['width'], 'height' => $meta['height'], 'mime-type' => $mime_type); remove_filter('image_resize_dimensions', $n('upscale_dimensions'), 1); return $meta; }
function __construct() { add_action('init', array($this, 'action_init')); $this->allowed_mime_types = function_exists('wp_get_mime_types') ? wp_get_mime_types() : get_allowed_mime_types(); $this->has_correct_role = BYT_Theme_Utils::check_user_role(BOOKYOURTRAVEL_FRONTEND_SUBMIT_ROLE, $this->get_current_user_id()); $this->_html_helper = new Html_Helper(); }
function __construct() { global $sc_theme_globals; $this->sc_theme_globals = $sc_theme_globals; add_action('init', array($this, 'action_init')); $this->allowed_mime_types = function_exists('wp_get_mime_types') ? wp_get_mime_types() : get_allowed_mime_types(); $this->_html_helper = new Html_Helper(); }
protected function get_mime_type($extension) { $mime_types = wp_get_mime_types(); $extensions = array_keys($mime_types); foreach ($extensions as $_extension) { if (preg_match("/{$extension}/i", $_extension)) { return $mime_types[$_extension]; } } return; }
function tm_player($player = '', $args = array()) { if (empty($player) || empty($args['files'])) { return; } $defaults = array('files' => array(), 'poster' => '', 'autoplay' => false); $args = wp_parse_args($args, $defaults); extract($args); /* JWPlayer */ if ($player == 'jwplayer') { $options = array('file' => trim($files[0]), 'image' => $poster); $atts = arr2atts($options); $jwplayer_shortcode = '[jwplayer' . $atts . ']'; echo apply_filters('tm_video_filter', $jwplayer_shortcode); } elseif ($player == 'flowplayer' && function_exists('flowplayer_content_handle')) { $atts = array('splash' => $poster); foreach ($files as $key => $file) { $att = $key == 0 ? 'src' : 'src' . $key; $atts[$att] = $file; } echo flowplayer_content_handle($atts, '', ''); tm_flowplayer_script(); } elseif ($player == 'videojs' && function_exists('video_shortcode')) { $atts = array('poster' => $poster); foreach ($files as $key => $file) { $att = $key == 0 ? 'src' : 'src' . $key; if (strpos($file, '.mp4') !== false) { $atts['mp4'] = $file; } if (strpos($file, '.webm') !== false) { $atts['webm'] = $file; } if (strpos($file, '.ogg') !== false) { $atts['ogg'] = $file; } } echo video_shortcode($atts, '', ''); tm_add_videojs_swf(); } else { $atts = array(); foreach ($files as $file) { $file = trim($file); if (strpos($file, 'youtube.com') !== false) { $atts['youtube'] = $file; } else { $type = wp_check_filetype($file, wp_get_mime_types()); $atts[$type['ext']] = $file; } } echo wp_video_shortcode($atts); } }
/** * Function to sanitize upload * * @access public * @since 1.1 * * @param $coder_upload * @return string * */ function coder_sanitize_upload($coder_upload, $coder_setting) { /* * Array of valid upload file types. * * The array includes upload mime types that are included in wp_get_mime_types() */ $coder_mimes = wp_get_mime_types(); // Return an array with file extension and mime_type. $coder_file = wp_check_filetype($coder_upload, $coder_mimes); // If $coder_upload has a valid mime_type, return it; otherwise, return the default. return $coder_file['ext'] ? $coder_upload : $coder_setting->default; }
static function get_mime_extensions() { $mime_types = wp_get_mime_types(); $extensions = array(); foreach ($mime_types as $ext => $mime) { $ext = explode('|', $ext); $extensions[$mime] = $ext; $mime_parts = explode('/', $mime); if (empty($extensions[$mime_parts[0]])) { $extensions[$mime_parts[0]] = array(); } $extensions[$mime_parts[0]] = $extensions[$mime_parts[0] . '/*'] = array_merge($extensions[$mime_parts[0]], $ext); } return $extensions; }
/** * Get extension * * @param string $path * @return string */ public function get_extension($path) { $type = $this->get_mime($path); $match = []; $ext = ''; if ($type) { foreach (wp_get_mime_types() as $extensions => $content_type) { if ($content_type == $type) { $ext = explode('|', $extensions)[0]; break; } } } return $ext; }
/** * @see CACIE_Editable_Model::get_column_options() * @since 1.0 */ public function get_column_options($column) { $options = parent::get_column_options($column); switch ($column['type']) { // WP Default // Custom columns case 'column-taxonomy': $options = $this->get_term_options($column['taxonomy']); break; case 'column-mime_type': $mime_types = wp_get_mime_types(); $options = array_combine($mime_types, $mime_types); break; } return $options; }
function x_shortcode_audio_player($atts) { extract(shortcode_atts(array('id' => '', 'class' => '', 'style' => '', 'src' => '', 'advanced_controls' => '', 'preload' => '', 'autoplay' => '', 'loop' => '', 'mp3' => '', 'oga' => ''), $atts, 'x_audio_player')); $id = $id != '' ? 'id="' . esc_attr($id) . '"' : ''; $class = $class != '' ? 'x-audio player ' . esc_attr($class) : 'x-audio player'; $style = $style != '' ? 'style="' . $style . '"' : ''; $src = $src != '' ? explode('|', $src) : array(); $advanced_controls = $advanced_controls == 'true' ? ' advanced-controls' : ''; $preload = $preload != '' ? ' preload="' . $preload . '"' : ' preload="metadata"'; $autoplay = $autoplay == 'true' ? ' autoplay' : ''; $loop = $loop == 'true' ? ' loop' : ''; // // Deprecated parameters. // $mp3 = $mp3 != '' ? '<source src="' . $mp3 . '" type="audio/mpeg">' : ''; $oga = $oga != '' ? '<source src="' . $oga . '" type="audio/ogg">' : ''; // // Variable markup. // $data = cs_generate_data_attributes('x_mejs'); // // Enqueue scripts. // wp_enqueue_script('mediaelement'); // // Build sources. // $sources = array(); foreach ($src as $file) { $mime = wp_check_filetype($file, wp_get_mime_types()); $sources[] = '<source src="' . esc_url($file) . '" type="' . $mime['type'] . '">'; } if ($mp3 != '') { $sources[] = $mp3; } if ($oga != '') { $sources[] = $oga; } // // Markup. // $output = "<div {$id} class=\"{$class}{$autoplay}{$loop}\" {$data} {$style}>" . "<audio class=\"x-mejs{$advanced_controls}\"{$preload}{$autoplay}{$loop}>" . implode('', $sources) . '</audio>' . '</div>'; return $output; }
private function sideload_attachment($attachment, $_to_post_id, $date) { if ('image' === $attachment->type) { $response = wp_remote_head($attachment->url); if (200 == wp_remote_retrieve_response_code($response)) { $_mimes = array_flip(wp_get_mime_types()); $_content_type = wp_remote_retrieve_header($response, 'content-type'); if (isset($_mimes[$_content_type])) { $_ext = strtok($_mimes[$_content_type], '|'); $_temp_file = download_url($attachment->url); // TODO check for WP_Error $_new_file = str_replace('.tmp', '.' . $_ext, $_temp_file); rename($_temp_file, $_new_file); $file_array = array(); $file_array['name'] = basename($_new_file); $file_array['tmp_name'] = $_new_file; $attachment_id = media_handle_sideload($file_array, $_to_post_id, '', array('post_date' => $date, 'post_date_gmt' => $date)); } } } }
/** * Matt & Mike J requested that we allow video uploads from the API for mobile apps, even without the VideoPress upgrade.. * https://videop2.wordpress.com/2014/08/21/videopress-iteration/#comment-3377 */ function allow_video_uploads($mimes) { // if we are on Jetpack, bail - Videos are already allowed if (!defined('IS_WPCOM') || !IS_WPCOM) { return $mimes; } // extra check that this filter is only ever applied during REST API requests if (!defined('REST_API_REQUEST') || !REST_API_REQUEST) { return $mimes; } // bail early if they already have the upgrade.. if (get_option('video_upgrade') == '1') { return $mimes; } // lets whitelist to only specific clients right now $clients_allowed_video_uploads = array(); $clients_allowed_video_uploads = apply_filters('rest_api_clients_allowed_video_uploads', $clients_allowed_video_uploads); if (!in_array($this->api->token_details['client_id'], $clients_allowed_video_uploads)) { return $mimes; } $mime_list = wp_get_mime_types(); $site_exts = explode(' ', get_site_option('upload_filetypes')); $video_exts = explode(' ', get_site_option('video_upload_filetypes', false, false)); $video_exts = apply_filters('video_upload_filetypes', $video_exts); $video_mimes = array(); if (!empty($video_exts)) { foreach ($video_exts as $ext) { foreach ($mime_list as $ext_pattern => $mime) { if ($ext != '' && strpos($ext_pattern, $ext) !== false) { $video_mimes[$ext_pattern] = $mime; } } } $mimes = array_merge($mimes, $video_mimes); } return $mimes; }
function dynimg_404_handler() { if (!is_404()) { return; } // Has the file name the proper format for this handler? if (!preg_match('/(.*)-([0-9]+)x([0-9]+)(c)?\\.(\\w+)($|\\?|#)/i', $_SERVER['REQUEST_URI'], $matches)) { return; } $mime_types = wp_get_mime_types(); $img_ext = $matches[5]; $ext_known = false; // The extensions for some MIME types are set as regular expression (PCRE). foreach ($mime_types as $rgx_ext => $mime_type) { if (preg_match("/{$rgx_ext}/i", $img_ext)) { if (wp_image_editor_supports(array('mime_type' => $mime_type))) { $ext_known = true; break; } } } if (!$ext_known) { return; } $filename = urldecode($matches[1] . '.' . $img_ext); $width = $matches[2]; $height = $matches[3]; $crop = !empty($matches[4]); $uploads_dir = wp_upload_dir(); $temp = parse_url($uploads_dir['baseurl']); $upload_path = $temp['path']; $findfile = str_replace($upload_path, '', $filename); $basefile = $uploads_dir['basedir'] . $findfile; // Serve the image this one time (next time the webserver will do it for us) dynimg_create_save_stream($basefile, $width, $height, $crop); }
/** * @ticket 21594 */ function test_wp_get_mime_types() { $mimes = wp_get_mime_types(); $this->assertInternalType('array', $mimes); $this->assertNotEmpty($mimes); add_filter('mime_types', '__return_empty_array'); $mimes = wp_get_mime_types(); $this->assertInternalType('array', $mimes); $this->assertEmpty($mimes); remove_filter('mime_types', '__return_empty_array'); $mimes = wp_get_mime_types(); $this->assertInternalType('array', $mimes); $this->assertNotEmpty($mimes); // upload_mimes shouldn't affect wp_get_mime_types() add_filter('upload_mimes', '__return_empty_array'); $mimes = wp_get_mime_types(); $this->assertInternalType('array', $mimes); $this->assertNotEmpty($mimes); remove_filter('upload_mimes', '__return_empty_array'); $mimes2 = wp_get_mime_types(); $this->assertInternalType('array', $mimes2); $this->assertNotEmpty($mimes2); $this->assertEquals($mimes2, $mimes); }
/** * Builds the Video shortcode output. * * This implements the functionality of the Video Shortcode for displaying * WordPress mp4s in a post. * * @since 3.6.0 * * @global int $content_width * @staticvar int $instance * * @param array $attr { * Attributes of the shortcode. * * @type string $src URL to the source of the video file. Default empty. * @type int $height Height of the video embed in pixels. Default 360. * @type int $width Width of the video embed in pixels. Default $content_width or 640. * @type string $poster The 'poster' attribute for the `<video>` element. Default empty. * @type string $loop The 'loop' attribute for the `<video>` element. Default empty. * @type string $autoplay The 'autoplay' attribute for the `<video>` element. Default empty. * @type string $preload The 'preload' attribute for the `<video>` element. * Default 'metadata'. * @type string $class The 'class' attribute for the `<video>` element. * Default 'wp-video-shortcode'. * } * @param string $content Shortcode content. * @return string|void HTML content to display video. */ function wp_video_shortcode($attr, $content = '') { global $content_width; $post_id = get_post() ? get_the_ID() : 0; static $instance = 0; $instance++; /** * Filter the default video shortcode output. * * If the filtered output isn't empty, it will be used instead of generating * the default video template. * * @since 3.6.0 * * @see wp_video_shortcode() * * @param string $html Empty variable to be replaced with shortcode markup. * @param array $attr Attributes of the video shortcode. * @param string $content Video shortcode content. * @param int $instance Unique numeric ID of this video shortcode instance. */ $override = apply_filters('wp_video_shortcode_override', '', $attr, $content, $instance); if ('' !== $override) { return $override; } $video = null; $default_types = wp_get_video_extensions(); $defaults_atts = array('src' => '', 'poster' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata', 'width' => 640, 'height' => 360); foreach ($default_types as $type) { $defaults_atts[$type] = ''; } $atts = shortcode_atts($defaults_atts, $attr, 'video'); if (is_admin()) { // shrink the video so it isn't huge in the admin if ($atts['width'] > $defaults_atts['width']) { $atts['height'] = round($atts['height'] * $defaults_atts['width'] / $atts['width']); $atts['width'] = $defaults_atts['width']; } } else { // if the video is bigger than the theme if (!empty($content_width) && $atts['width'] > $content_width) { $atts['height'] = round($atts['height'] * $content_width / $atts['width']); $atts['width'] = $content_width; } } $is_vimeo = $is_youtube = false; $yt_pattern = '#^https?://(?:www\\.)?(?:youtube\\.com/watch|youtu\\.be/)#'; $vimeo_pattern = '#^https?://(.+\\.)?vimeo\\.com/.*#'; $primary = false; if (!empty($atts['src'])) { $is_vimeo = preg_match($vimeo_pattern, $atts['src']); $is_youtube = preg_match($yt_pattern, $atts['src']); if (!$is_youtube && !$is_vimeo) { $type = wp_check_filetype($atts['src'], wp_get_mime_types()); if (!in_array(strtolower($type['ext']), $default_types)) { return sprintf('<a class="wp-embedded-video" href="%s">%s</a>', esc_url($atts['src']), esc_html($atts['src'])); } } if ($is_vimeo) { wp_enqueue_script('froogaloop'); } $primary = true; array_unshift($default_types, 'src'); } else { foreach ($default_types as $ext) { if (!empty($atts[$ext])) { $type = wp_check_filetype($atts[$ext], wp_get_mime_types()); if (strtolower($type['ext']) === $ext) { $primary = true; } } } } if (!$primary) { $videos = get_attached_media('video', $post_id); if (empty($videos)) { return; } $video = reset($videos); $atts['src'] = wp_get_attachment_url($video->ID); if (empty($atts['src'])) { return; } array_unshift($default_types, 'src'); } /** * Filter the media library used for the video shortcode. * * @since 3.6.0 * * @param string $library Media library used for the video shortcode. */ $library = apply_filters('wp_video_shortcode_library', 'mediaelement'); if ('mediaelement' === $library && did_action('init')) { wp_enqueue_style('wp-mediaelement'); wp_enqueue_script('wp-mediaelement'); } /** * Filter the class attribute for the video shortcode output container. * * @since 3.6.0 * * @param string $class CSS class or list of space-separated classes. */ $html_atts = array('class' => apply_filters('wp_video_shortcode_class', 'wp-video-shortcode'), 'id' => sprintf('video-%d-%d', $post_id, $instance), 'width' => absint($atts['width']), 'height' => absint($atts['height']), 'poster' => esc_url($atts['poster']), 'loop' => wp_validate_boolean($atts['loop']), 'autoplay' => wp_validate_boolean($atts['autoplay']), 'preload' => $atts['preload']); // These ones should just be omitted altogether if they are blank foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) { if (empty($html_atts[$a])) { unset($html_atts[$a]); } } $attr_strings = array(); foreach ($html_atts as $k => $v) { $attr_strings[] = $k . '="' . esc_attr($v) . '"'; } $html = ''; if ('mediaelement' === $library && 1 === $instance) { $html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n"; } $html .= sprintf('<video %s controls="controls">', join(' ', $attr_strings)); $fileurl = ''; $source = '<source type="%s" src="%s" />'; foreach ($default_types as $fallback) { if (!empty($atts[$fallback])) { if (empty($fileurl)) { $fileurl = $atts[$fallback]; } if ('src' === $fallback && $is_youtube) { $type = array('type' => 'video/youtube'); } elseif ('src' === $fallback && $is_vimeo) { $type = array('type' => 'video/vimeo'); } else { $type = wp_check_filetype($atts[$fallback], wp_get_mime_types()); } $url = add_query_arg('_', $instance, $atts[$fallback]); $html .= sprintf($source, $type['type'], esc_url($url)); } } if (!empty($content)) { if (false !== strpos($content, "\n")) { $content = str_replace(array("\r\n", "\n", "\t"), '', $content); } $html .= trim($content); } if ('mediaelement' === $library) { $html .= wp_mediaelement_fallback($fileurl); } $html .= '</video>'; $width_rule = ''; if (!empty($atts['width'])) { $width_rule = sprintf('width: %dpx; ', $atts['width']); } $output = sprintf('<div style="%s" class="wp-video">%s</div>', $width_rule, $html); /** * Filter the output of the video shortcode. * * @since 3.6.0 * * @param string $output Video shortcode HTML output. * @param array $atts Array of video shortcode attributes. * @param string $video Video file. * @param int $post_id Post ID. * @param string $library Media library used for the video shortcode. */ return apply_filters('wp_video_shortcode', $output, $atts, $video, $post_id, $library); }
/** * Sanitizes a filename, replacing whitespace with dashes. * * Removes special characters that are illegal in filenames on certain * operating systems and special characters requiring special escaping * to manipulate at the command line. Replaces spaces and consecutive * dashes with a single dash. Trims period, dash and underscore from beginning * and end of filename. It is not guaranteed that this function will return a * filename that is allowed to be uploaded. * * @since 2.1.0 * * @param string $filename The filename to be sanitized * @return string The sanitized filename */ function sanitize_file_name( $filename ) { $filename_raw = $filename; $special_chars = array("?", "[", "]", "/", "\\", "=", "<", ">", ":", ";", ",", "'", "\"", "&", "$", "#", "*", "(", ")", "|", "~", "`", "!", "{", "}", "%", "+", chr(0)); /** * Filter the list of characters to remove from a filename. * * @since 2.8.0 * * @param array $special_chars Characters to remove. * @param string $filename_raw Filename as it was passed into sanitize_file_name(). */ $special_chars = apply_filters( 'sanitize_file_name_chars', $special_chars, $filename_raw ); $filename = preg_replace( "#\x{00a0}#siu", ' ', $filename ); $filename = str_replace( $special_chars, '', $filename ); $filename = str_replace( array( '%20', '+' ), '-', $filename ); $filename = preg_replace( '/[\r\n\t -]+/', '-', $filename ); $filename = trim( $filename, '.-_' ); if ( false === strpos( $filename, '.' ) ) { $mime_types = wp_get_mime_types(); $filetype = wp_check_filetype( 'test.' . $filename, $mime_types ); if ( $filetype['ext'] === $filename ) { $filename = 'unnamed-file.' . $filetype['ext']; } } // Split the filename into a base and extension[s] $parts = explode('.', $filename); // Return if only one extension if ( count( $parts ) <= 2 ) { /** * Filter a sanitized filename string. * * @since 2.8.0 * * @param string $filename Sanitized filename. * @param string $filename_raw The filename prior to sanitization. */ return apply_filters( 'sanitize_file_name', $filename, $filename_raw ); } // Process multiple extensions $filename = array_shift($parts); $extension = array_pop($parts); $mimes = get_allowed_mime_types(); /* * Loop over any intermediate extensions. Postfix them with a trailing underscore * if they are a 2 - 5 character long alpha string not in the extension whitelist. */ foreach ( (array) $parts as $part) { $filename .= '.' . $part; if ( preg_match("/^[a-zA-Z]{2,5}\d?$/", $part) ) { $allowed = false; foreach ( $mimes as $ext_preg => $mime_match ) { $ext_preg = '!^(' . $ext_preg . ')$!i'; if ( preg_match( $ext_preg, $part ) ) { $allowed = true; break; } } if ( !$allowed ) $filename .= '_'; } } $filename .= '.' . $extension; /** This filter is documented in wp-includes/formatting.php */ return apply_filters('sanitize_file_name', $filename, $filename_raw); }
if (!empty($bg_video_args)) { $attr_strings = array('loop', 'preload="1"', 'autoplay=""', 'muted="muted"'); if ($video_mute) { //$attr_strings[] = 'muted="muted"'; } if ($video_autoplay) { //$attr_strings[] = 'autoplay=""'; } if ($bg_video_cover && !in_array($bg_video_cover, array('none'))) { $bg_video_path = wp_get_attachment_image_src($bg_video_cover, 'kleo-full-width'); $attr_strings[] = 'poster="' . esc_url($bg_video_path[0]) . '"'; } $bg_video .= sprintf('<div class="video-wrap"><video %s class="full-video" webkit-playsinline>', join(' ', $attr_strings)); $source = '<source type="%s" src="%s" />'; foreach ($bg_video_args as $video_type => $video_src) { $video_type = wp_check_filetype($video_src, wp_get_mime_types()); $bg_video .= sprintf($source, $video_type['type'], esc_url($video_src)); } $bg_video .= '</video></div>'; $section_classes[] = 'bg-full-video no-video-controls'; } break; default: break; } if ($column_gap == 'no') { $section_classes[] = 'no-col-gap'; } if ($vertical_align == 'yes') { $section_classes[] = 'vertical-col'; }
function wp_playlist_shortcode($output, $attr) { global $content_width; $post = get_post(); static $instance = 0; $instance++; if (isset($attr['orderby'])) { $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); if (!$attr['orderby']) { unset($attr['orderby']); } } extract(shortcode_atts(array('type' => 'audio', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post ? $post->ID : 0, 'include' => '', 'exclude' => '', 'style' => 'light', 'tracklist' => true, 'tracknumbers' => true, 'images' => true, 'artists' => true), $attr, 'playlist')); $id = intval($id); if ('RAND' == $order) { $orderby = 'none'; } $args = array('post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => $type, 'order' => $order, 'orderby' => $orderby); if (!empty($include)) { $args['include'] = $include; $_attachments = get_posts($args); $attachments = array(); foreach ($_attachments as $key => $val) { $attachments[$val->ID] = $_attachments[$key]; } } elseif (!empty($exclude)) { $args['post_parent'] = $id; $args['exclude'] = $exclude; $attachments = get_children($args); } else { $args['post_parent'] = $id; $attachments = get_children($args); } if (empty($attachments)) { return ''; } if (is_feed()) { $output = "\n"; foreach ($attachments as $att_id => $attachment) { $output .= wp_get_attachment_link($att_id) . "\n"; } return $output; } $outer = 22; $default_width = 640; $default_height = 360; $theme_width = empty($content_width) ? $default_width : $content_width - $outer; $theme_height = empty($content_width) ? $default_height : round($default_height * $theme_width / $default_width); $data = compact('type'); foreach (array('tracklist', 'tracknumbers', 'images', 'artists') as $key) { $data[$key] = filter_var(${$key}, FILTER_VALIDATE_BOOLEAN); } $tracks = array(); foreach ($attachments as $attachment) { $url = wp_get_attachment_url($attachment->ID); $ftype = wp_check_filetype($url, wp_get_mime_types()); $track = array('src' => $url, 'type' => $ftype['type'], 'title' => $attachment->post_title, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content); $track['meta'] = array(); $meta = wp_get_attachment_metadata($attachment->ID); if (!empty($meta)) { foreach (wp_get_attachment_id3_keys($attachment) as $key => $label) { if (!empty($meta[$key])) { $track['meta'][$key] = $meta[$key]; } } if ('video' === $type) { if (!empty($meta['width']) && !empty($meta['height'])) { $width = $meta['width']; $height = $meta['height']; $theme_height = round($height * $theme_width / $width); } else { $width = $default_width; $height = $default_height; } $track['dimensions'] = array('original' => compact('width', 'height'), 'resized' => array('width' => $theme_width, 'height' => $theme_height)); } } if ($images) { $id = get_post_thumbnail_id($attachment->ID); if (!empty($id)) { list($src, $width, $height) = wp_get_attachment_image_src($id, 'full'); $track['image'] = compact('src', 'width', 'height'); list($src, $width, $height) = wp_get_attachment_image_src($id, 'thumbnail'); $track['thumb'] = compact('src', 'width', 'height'); } else { $src = wp_mime_type_icon($attachment->ID); $width = 48; $height = 64; $track['image'] = compact('src', 'width', 'height'); $track['thumb'] = compact('src', 'width', 'height'); } } $tracks[] = $track; } $data['tracks'] = $tracks; $safe_type = esc_attr($type); $safe_style = esc_attr($style); $playlist_meta = 'true' == $this->options('playlist_meta') ? "" : " hide-playlist-meta-pro "; ob_start(); if (1 === $instance) { do_action('wp_playlist_scripts', $type, $style); } ?> <div class="wp-playlist wp-<?php echo $safe_type; ?> -playlist wp-playlist-<?php echo $safe_style; ?> <?php echo $playlist_meta; ?> "> <?php if ('audio' === $type) { ?> <div class="wp-playlist-current-item"></div> <?php } ?> <<?php echo $safe_type; ?> controls="controls" preload="none" width="<?php echo (int) $theme_width; ?> "<?php if ('video' === $safe_type) { echo ' height="', (int) $theme_height, '"'; } else { echo ' style="visibility: hidden"'; } ?> ></<?php echo $safe_type; ?> > <div class="wp-playlist-next"></div> <div class="wp-playlist-prev"></div> <noscript> <ol><?php foreach ($attachments as $att_id => $attachment) { printf('<li>%s</li>', wp_get_attachment_link($att_id)); } ?> </ol> </noscript> <script type="application/json"><?php echo json_encode($data); ?> </script> </div> <?php return apply_filters('wp_playlist_shortcode', ob_get_clean()); }
/** * Retrieve list of allowed mime types and file extensions. * * @since 2.8.6 * * @uses apply_filters() Calls 'upload_mimes' on returned array * @uses wp_get_upload_mime_types() to fetch the list of mime types * * @return array Array of mime types keyed by the file extension regex corresponding to those types. */ function get_allowed_mime_types() { return apply_filters('upload_mimes', wp_get_mime_types()); }
if ('images' == $limit_file_type) { $limit_types = 'jpg,jpeg,png,gif'; } elseif ('video' == $limit_file_type) { $limit_types = 'mpg,mov,flv,mp4'; } elseif ('audio' == $limit_file_type) { $limit_types = 'mp3,m4a,wav,wma'; } elseif ('text' == $limit_file_type) { $limit_types = 'txt,rtx,csv,tsv'; } elseif ('any' == $limit_file_type) { $limit_types = ''; } else { $limit_types = pods_var($form_field_type . '_allowed_extensions', $options, '', null, true); } $limit_types = trim(str_replace(array(' ', '.', "\n", "\t", ';'), array('', ',', ',', ','), $limit_types), ','); if (pods_version_check('wp', '3.5')) { $mime_types = wp_get_mime_types(); if (in_array($limit_file_type, array('images', 'audio', 'video'))) { $new_limit_types = array(); foreach ($mime_types as $type => $mime) { if (0 === strpos($mime, $limit_file_type)) { $type = explode('|', $type); $new_limit_types = array_merge($new_limit_types, $type); } } if (!empty($new_limit_types)) { $limit_types = implode(',', $new_limit_types); } } elseif ('any' != $limit_file_type) { $new_limit_types = array(); $limit_types = explode(',', $limit_types); foreach ($limit_types as $k => $limit_type) {
/** * Get allowed attachment mime types. * * @since 2.4.0 * * @param string $type The extension types to get (Optional). * @param array $allowed_types List of allowed extensions * @return array List of allowed mime types */ function bp_attachments_get_allowed_mimes($type = '', $allowed_types = array()) { if (empty($allowed_types)) { $allowed_types = bp_attachments_get_allowed_types($type); } $validate_mimes = wp_match_mime_types(join(',', $allowed_types), wp_get_mime_types()); $allowed_mimes = array_map('implode', $validate_mimes); /** * Include jpg type if jpeg is set */ if (isset($allowed_mimes['jpeg']) && !isset($allowed_mimes['jpg'])) { $allowed_mimes['jpg'] = $allowed_mimes['jpeg']; } return $allowed_mimes; }
/** * Output deposits single item review page html. */ function humcore_deposit_item_review_content() { $metadata = (array) humcore_get_current_deposit(); if (!empty($metadata['group'])) { $groups = array_filter($metadata['group']); } if (!empty($groups)) { $group_list = implode(', ', array_map('esc_html', $groups)); } if (!empty($metadata['subject'])) { $subjects = array_filter($metadata['subject']); } if (!empty($subjects)) { $subject_list = implode(', ', array_map('esc_html', $subjects)); } if (!empty($metadata['keyword'])) { $keywords = array_filter($metadata['keyword']); } if (!empty($keywords)) { $keyword_list = implode(', ', array_map('esc_html', $keywords)); } $authors = array_filter($metadata['authors']); $author_uni = humcore_deposit_parse_author_info($metadata['author_info'][0], 1); $author_type = humcore_deposit_parse_author_info($metadata['author_info'][0], 3); $authors_list = implode(', ', array_map('esc_html', $authors)); $deposit_post_id = $metadata['record_identifier']; $post_data = get_post($deposit_post_id); $post_metadata = json_decode(get_post_meta($deposit_post_id, '_deposit_metadata', true), true); $file_metadata = json_decode(get_post_meta($deposit_post_id, '_deposit_file_metadata', true), true); $downloads_meta_key = sprintf('_total_downloads_%s_%s', $file_metadata['files'][0]['datastream_id'], $file_metadata['files'][0]['pid']); $total_downloads = get_post_meta($deposit_post_id, $downloads_meta_key, true); $views_meta_key = sprintf('_total_views_%s', $metadata['pid']); $total_views = get_post_meta($deposit_post_id, $views_meta_key, true) + 1; // Views counted at item page level. if ($post_data->post_author != bp_loggedin_user_id()) { $post_meta_ID = update_post_meta($deposit_post_id, $views_meta_key, $total_views); } $download_url = sprintf('/deposits/download/%s/%s/%s/', $file_metadata['files'][0]['pid'], $file_metadata['files'][0]['datastream_id'], $file_metadata['files'][0]['filename']); $view_url = sprintf('/deposits/view/%s/%s/%s/', $file_metadata['files'][0]['pid'], $file_metadata['files'][0]['datastream_id'], $file_metadata['files'][0]['filename']); $metadata_url = sprintf('/deposits/download/%s/%s/%s/', $metadata['pid'], 'descMetadata', 'xml'); $file_type_data = wp_check_filetype($file_metadata['files'][0]['filename'], wp_get_mime_types()); $file_type_icon = sprintf('<img class="deposit-icon" src="%s" alt="%s" />', plugins_url('assets/' . esc_attr($file_type_data['ext']) . '-icon-48x48.png', __FILE__), esc_attr($file_type_data['ext'])); if (!empty($file_metadata['files'][0]['thumb_filename'])) { $thumb_url = sprintf('<img class="deposit-thumb" src="/deposits/view/%s/%s/%s/" alt="%s" />', $file_metadata['files'][0]['pid'], $file_metadata['files'][0]['thumb_datastream_id'], $file_metadata['files'][0]['thumb_filename'], 'thumbnail'); } else { $thumb_url = ''; } ?> <div class="bp-group-documents-meta"> <dl class='defList'> <dt><?php _e('Title:', 'humcore_domain'); ?> </dt> <dd><span><?php echo $metadata['title_unchanged']; // XSS OK. ?> </span></dd> <dt><?php _e('Item Type:', 'humcore_domain'); ?> </dt> <dd><?php echo esc_html($metadata['genre']); ?> </dd> <!-- //new stuff --> <?php if ('Conference paper' == $metadata['genre'] || 'Conference proceeding' == $metadata['genre']) { ?> <dt><?php _e('Conf. Title:', 'humcore_domain'); ?> </dt> <?php if (!empty($post_metadata['conference_title'])) { ?> <dd><span><?php echo $post_metadata['conference_title']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Conf. Org.:', 'humcore_domain'); ?> </dt> <?php if (!empty($post_metadata['conference_organization'])) { ?> <dd><span><?php echo $post_metadata['conference_organization']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } } elseif ('Dissertation' == $metadata['genre'] || 'Thesis' == $metadata['genre'] || 'Technical Report' == $metadata['genre']) { ?> <dt><?php _e('Institution:', 'humcore_domain'); ?> </dt> <?php if (!empty($post_metadata['institution'])) { ?> <dd><span><?php echo $post_metadata['institution']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } } ?> <dt><?php _e('Abstract:', 'humcore_domain'); // Google Scholar wants Abstract. ?> </dt> <dd><?php echo $metadata['abstract_unchanged']; ?> </dd> <?php if ('yes' === $metadata['committee_deposit']) { // Do not show unless this is a committee deposit. ?> <dt><?php _e('Deposit Type:', 'humcore_domain'); ?> </dt> <dd><span><?php echo 'Committee'; ?> </span></dd> <?php } ?> <dt><?php _e('Author(s):', 'humcore_domain'); ?> </dt> <dd><?php echo $authors_list; // XSS OK. ?> </dd> <dt><?php _e('Subject(s):', 'humcore_domain'); ?> </dt> <?php if (!empty($subjects)) { ?> <dd><?php echo $subject_list; // XSS OK. ?> </dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Forum(s):', 'humcore_domain'); ?> </dt> <?php if (!empty($groups)) { ?> <dd><?php echo $group_list; // XSS OK. ?> </dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Tag(s):', 'humcore_domain'); ?> </dt> <?php if (!empty($keywords)) { ?> <dd><?php echo $keyword_list; // XSS OK. ?> </dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('File Type:', 'humcore_domain'); ?> </dt> <dd><?php echo esc_html($metadata['type_of_resource']); ?> </dd> <dt><?php _e('Notes:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['notes_unchanged'])) { ?> <dd><?php echo $metadata['notes_unchanged']; ?> </dd> <?php } else { ?> <dd>( None )</dd> <?php } if (!empty($post_metadata['type_of_license'])) { ?> <dt><?php _e('License:', 'humcore_domain'); ?> </dt> <dd><?php echo humcore_linkify_license($post_metadata['type_of_license']); ?> </dd> <?php } if ('journal-article' == $post_metadata['publication-type']) { ?> <dt><?php _e('Pub. Type:', 'humcore_domain'); ?> </dt> <dd><span><?php echo 'Journal Article'; // XSS OK. ?> </span></dd> <dt><?php _e('Pub. DOI:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['doi'])) { ?> <dd><span><?php echo $metadata['doi']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Publisher:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['publisher'])) { ?> <dd><span><?php echo $metadata['publisher']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Pub. Date:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['date'])) { ?> <dd><span><?php echo $metadata['date']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Journal:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['book_journal_title'])) { ?> <dd><span><?php echo $metadata['book_journal_title']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Volume:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['volume'])) { ?> <dd><span><?php echo $metadata['volume']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Issue:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['issue'])) { ?> <dd><span><?php echo $metadata['issue']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Start Page:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['start_page'])) { ?> <dd><span><?php echo $metadata['start_page']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('End Page:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['end_page'])) { ?> <dd><span><?php echo $metadata['end_page']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('ISSN:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['issn'])) { ?> <dd><span><?php echo $metadata['issn']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } } elseif ('book' == $post_metadata['publication-type']) { ?> <dt><?php _e('Pub. Type:', 'humcore_domain'); ?> </dt> <dd><span><?php echo 'Book'; // XSS OK. ?> </span></dd> <dt><?php _e('Pub. DOI:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['doi'])) { ?> <dd><span><?php echo $metadata['doi']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Publisher:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['publisher'])) { ?> <dd><span><?php echo $metadata['publisher']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Pub. Date:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['date'])) { ?> <dd><span><?php echo $metadata['date']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Author/Editor:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['book_author'])) { ?> <dd><span><?php echo $metadata['book_author']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Book Title:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['book_journal_title'])) { ?> <dd><span><?php echo $metadata['book_journal_title']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Chapter:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['chapter'])) { ?> <dd><span><?php echo $metadata['chapter']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Start Page:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['start_page'])) { ?> <dd><span><?php echo $metadata['start_page']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('End Page:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['end_page'])) { ?> <dd><span><?php echo $metadata['end_page']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('ISBN:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['isbn'])) { ?> <dd><span><?php echo $metadata['isbn']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } } elseif ('conference-proceeding' == $post_metadata['publication-type']) { ?> <dt><?php _e('Pub. Type:', 'humcore_domain'); ?> </dt> <dd><span><?php echo 'Conference Proceeding'; // XSS OK. ?> </span></dd> <dt><?php _e('Pub. DOI:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['doi'])) { ?> <dd><span><?php echo $metadata['doi']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Publisher:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['publisher'])) { ?> <dd><span><?php echo $metadata['publisher']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Pub. Date:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['date'])) { ?> <dd><span><?php echo $metadata['date']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Proceeding:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['book_journal_title'])) { ?> <dd><span><?php echo $metadata['book_journal_title']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('Start Page:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['start_page'])) { ?> <dd><span><?php echo $metadata['start_page']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } ?> <dt><?php _e('End Page:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['end_page'])) { ?> <dd><span><?php echo $metadata['end_page']; // XSS OK. ?> </span></dd> <?php } else { ?> <dd> </dd> <?php } } elseif (empty($post_metadata['publication-type']) || 'none' == $post_metadata['publication-type']) { ?> <dt><?php _e('Pub. Type:', 'humcore_domain'); ?> </dt> <dd><span><?php echo 'None'; // XSS OK. ?> </span></dd> <dt><?php _e('Creation Date:', 'humcore_domain'); ?> </dt> <?php if (!empty($metadata['date'])) { ?> <dd><?php echo esc_html($metadata['date']); ?> </dd> <?php } else { ?> <dd>( None entered )</dd> <?php } } ?> <dt><?php _e('File Name:', 'humcore_domain'); ?> </dt> <dd><?php echo esc_html($file_metadata['files'][0]['filename']); ?> </dd> <dt><?php _e('File Size:', 'humcore_domain'); ?> </dt> <dd><?php echo number_format($file_metadata['files'][0]['filesize']), " bytes"; ?> </dd> </dl> </div> <br style='clear:both'> <a onclick="target='_blank'" class="bp-deposits-view button white" title="View" href="<?php echo esc_url($view_url); ?> "><?php _e('View your Deposit', 'humcore_domain'); ?> </a> <?php }
/** * Slightly convoluted workaround to allow modifying of allowed MIME types for WP < 3.5, * Workaround for IE sometimes setting image/pjepg and image/x-png for JPEGs and PNGs respectively */ function _get_mime_types() { // Use wp_get_mime_types if available, fallback to get_allowed_mime_types() $mime_types = function_exists('wp_get_mime_types') ? wp_get_mime_types() : get_allowed_mime_types(); $fu_mime_types = fu_get_mime_types(); // Workaround for IE $mime_types['jpg|jpe|jpeg|pjpg'] = 'image/pjpeg'; $mime_types['png|xpng'] = 'image/x-png'; // Iterate through default extensions foreach ($fu_mime_types as $extension => $details) { // Skip if it's not in the settings if (!in_array($extension, $this->settings['enabled_files'])) { continue; } // Iterate through mime-types for this extension foreach ($details['mimes'] as $ext_mime) { $mime_types[$extension . '|' . $extension . sanitize_title_with_dashes($ext_mime)] = $ext_mime; } } // Configuration filter: fu_allowed_mime_types should return array of allowed mime types (see readme) $mime_types = apply_filters('fu_allowed_mime_types', $mime_types); foreach ($mime_types as $ext_key => $mime) { // Check for php just in case if (false !== strpos($mime, 'php')) { unset($mime_types[$ext_key]); } } return $mime_types; }
/** * Returns first matched extension from Mime-type, * as mapped from wp_get_mime_types() * * @since 3.5.0 * @access protected * * @param string $mime_type * @return string|boolean */ protected static function get_extension($mime_type = null) { $extensions = explode('|', array_search($mime_type, wp_get_mime_types())); if (empty($extensions[0])) { return false; } return $extensions[0]; }
function dh_post_featured($post_id = '', $post_format = '', $is_shortcode = false, $is_related = false, $entry_featured_class = '', $layout = '') { $post_id = empty($post_id) ? get_the_ID() : $post_id; $post_format = empty($post_format) ? get_post_format() : $post_format; $thumb_size = !is_singular() || $is_shortcode || $is_related ? 'dh-thumbnail' : 'dh-full'; if ($layout == 'masonry') { $thumb_size = 'dh-full'; } $thumb_size = apply_filters('dh_post_featured_thumbnail_size', $thumb_size, $post_id); $featured_class = !empty($post_format) ? ' ' . $post_format . '-featured' : ''; if ($is_related) { if (has_post_thumbnail()) { $thumb = get_the_post_thumbnail($post_id, $thumb_size, array('itemprop' => 'image')); echo '<div class="entry-featured' . $featured_class . '">'; echo '<a href="' . get_the_permalink() . '" title="' . esc_attr(get_the_title(get_post_thumbnail_id($post_id))) . '">' . $thumb . '</a>'; echo '</div>'; } } else { if ($post_format == 'gallery') { /** * script * {{ */ wp_enqueue_script('vendor-carouFredSel'); $gallery_ids = explode(',', dh_get_post_meta('gallery')); $gallery_ids = array_filter($gallery_ids); if (!empty($gallery_ids) && is_array($gallery_ids)) { ?> <div class="entry-featured<?php echo esc_attr($featured_class); echo ' ' . $entry_featured_class; ?> "> <div class="caroufredsel" data-visible="1" data-responsive="1" data-infinite="1" data-autoplay="1" data-height="variable"> <div class="caroufredsel-wrap"> <ul class="caroufredsel-items"> <?php foreach ($gallery_ids as $id) { ?> <?php if ($id) { ?> <?php $image = wp_get_attachment_image_src($id, 'dh-full'); ?> <li class="caroufredsel-item"> <a href="<?php echo @$image[0]; ?> " title="<?php echo get_the_title($id); ?> " data-rel="magnific-popup"> <?php echo wp_get_attachment_image($id, $thumb_size); ?> </a> </li> <?php } ?> <?php } ?> </ul> <a href="#" class="caroufredsel-prev"></a> <a href="#" class="caroufredsel-next"></a> </div> </div> </div> <?php } } elseif ($post_format == 'video') { /** * script * {{ */ wp_enqueue_style('mediaelement'); wp_enqueue_script('mediaelement'); if (is_single()) { $video_args = array(); if ($mp4 = dh_get_post_meta('video_mp4')) { $video_args['mp4'] = $mp4; } if ($ogv = dh_get_post_meta('video_ogv')) { $video_args['ogv'] = $ogv; } if ($webm = dh_get_post_meta('video_webm')) { $video_args['webm'] = $webm; } $poster = dh_get_post_meta('video_poster'); $poster_attr = ''; if (has_post_thumbnail()) { $post_thumb = wp_get_attachment_image_src(get_post_thumbnail_id($post_id), $thumb_size); $poster_attr = ' poster="' . esc_url(@$post_thumb[0]) . '"'; } if (!empty($poster)) { $poster_image = wp_get_attachment_image_src($poster, $thumb_size); $poster_attr = ' poster="' . esc_url(@$poster_image[0]) . '"'; } if (!empty($video_args)) { $video = '<div id="video-featured-' . $post_id . '" class="video-embed-wrap"><video controls="controls" ' . $poster_attr . ' preload="0" class="video-embed">'; $source = '<source type="%s" src="%s" />'; foreach ($video_args as $video_type => $video_src) { $video_type = wp_check_filetype($video_src, wp_get_mime_types()); $video .= sprintf($source, $video_type['type'], esc_url($video_src)); } $video .= '</video></div>'; echo '<div class="entry-featured' . $featured_class . '">'; echo dhecho($video); echo '</div>'; } elseif ($embed = dh_get_post_meta('video_embed')) { if (!empty($embed)) { echo '<div class="entry-featured ' . $post_format . '-featured ' . $entry_featured_class . '">'; echo '<div id="video-featured-' . $post_id . '" class="embed-wrap">'; echo apply_filters('dh_embed_video', $embed); echo '</div>'; echo '</div>'; } } } else { if (has_post_thumbnail()) { $thumb = get_the_post_thumbnail($post_id, $thumb_size, array('data-itemprop' => 'image')); } else { $thumb = '<img src="' . get_template_directory_uri() . '/assets/images/noo-thumb_700x350.png" alt="' . get_the_title() . '">'; } echo '<div class="entry-featured' . $featured_class . ' ' . $entry_featured_class . '">'; echo '<a href="' . get_the_permalink() . '" title="' . esc_attr(get_the_title(get_post_thumbnail_id($post_id))) . '">' . $thumb . '<i class="featured-play"></i></a>'; echo '</div>'; } } elseif ($post_format == 'audio') { /** * script * {{ */ wp_enqueue_style('mediaelement'); wp_enqueue_script('mediaelement'); $audio_args = array(); if ($mp3 = dh_get_post_meta('audio_mp3')) { $audio_args['mp3'] = $mp3; } if ($ogg = dh_get_post_meta('audio_ogg')) { $audio_args['ogg'] = $ogg; } if (!empty($audio_args)) { $audio = '<div id="audio-featured-' . $post_id . '" class="audio-embed-wrap"><audio class="audio-embed">'; $source = '<source type="%s" src="%s" />'; foreach ($audio_args as $type => $audio_src) { $audio_type = wp_check_filetype($audio_src, wp_get_mime_types()); $audio .= sprintf($source, $audio_type['type'], esc_url($audio_src)); } $audio .= '</audio></div>'; echo '<div class="entry-featured' . $featured_class . ' ' . $entry_featured_class . '">'; echo dhecho($audio); echo '</div>'; } } elseif (has_post_thumbnail()) { $thumb = get_the_post_thumbnail($post_id, $thumb_size, array('data-itemprop' => 'image')); echo '<div class="entry-featured' . $featured_class . ' ' . $entry_featured_class . '">'; if (!is_singular() || $is_shortcode) { echo '<a href="' . get_the_permalink() . '" title="' . esc_attr(get_the_title(get_post_thumbnail_id($post_id))) . '">' . $thumb . '</a>'; } else { echo dhecho($thumb); } echo '</div>'; } } return; }
/** * Add filtering dropdown * * @since 3.5 * @todo: Add support for customfield values longer then 30 characters. */ public function add_filtering_dropdown() { global $pagenow; if ($this->storage_model->page . '.php' !== $pagenow) { return; } foreach ($this->storage_model->columns as $column) { if (!$column->properties->is_filterable || 'on' != $column->options->filter) { continue; } $options = array(); $empty_option = false; // Use cache $cache = $this->storage_model->get_cache('filtering', $column->properties->name); $order = 'ASC'; $top_label = ''; // default if ($cache && $this->storage_model->is_cache_enabled()) { $options = $cache['options']; $empty_option = $cache['empty_option']; } else { switch ($column->properties->type) { // WP Default case 'author': if ($values = $this->get_values_by_post_field('post_author')) { foreach ($values as $value) { $user = get_user_by('id', $value); $options[$value] = $user->display_name; } } break; case 'comments': $top_label = __('All comments', 'cpac'); $options = array(0 => __('No comments', 'capc'), 1 => __('Has comments', 'capc')); break; case 'date': $order = ''; foreach ($this->get_post_fields('post_date') as $_value) { $date = substr($_value, 0, 7); // only year and month $options[$date] = date_i18n('F Y', strtotime($_value)); } krsort($options); break; case 'parent': foreach ($this->get_post_fields('post_parent') as $_value) { $options[$_value] = get_the_title($_value); } break; // Custom // Custom case 'column-description': foreach ($this->get_post_fields('post_content') as $_value) { $options[$_value] = strip_tags($_value); } break; case 'column-mime_type': $mime_types = array_flip(wp_get_mime_types()); foreach ($this->get_post_fields('post_mime_type') as $_value) { $options[$_value] = $mime_types[$_value]; } break; case 'column-taxonomy': if (taxonomy_exists($column->options->taxonomy)) { $empty_option = true; $order = false; // do not sort, messes up the indenting $terms_args = apply_filters('cac/addon/filtering/taxonomy/terms_args', array()); $options = $this->apply_indenting_markup($this->indent(get_terms($column->options->taxonomy, $terms_args), 0, 'parent', 'term_id')); } break; case 'column-meta': if ($_options = $this->get_meta_options($column)) { $empty_option = $_options['empty_option']; $options = $_options['options']; } break; case 'column-acf_field': if ($_options = $this->get_acf_options($column)) { $empty_option = $_options['empty_option']; $options = $_options['options']; } break; } // sort the options if ('ASC' == $order) { asort($options); } if ('DESC' == $order) { arsort($options); } // update cache $this->storage_model->set_cache('filtering', $column->properties->name, array('options' => $options, 'empty_option' => $empty_option)); } if (!$options && !$empty_option) { continue; } $this->dropdown($column, $options, $empty_option, $top_label); } }
/** * Retrieve list of allowed mime types and file extensions. * * @since 2.8.6 * * @param int|WP_User $user Optional. User to check. Defaults to current user. * @return array Array of mime types keyed by the file extension regex corresponding * to those types. */ function get_allowed_mime_types($user = null) { $t = wp_get_mime_types(); unset($t['swf'], $t['exe']); if (function_exists('current_user_can')) { $unfiltered = $user ? user_can($user, 'unfiltered_html') : current_user_can('unfiltered_html'); } if (empty($unfiltered)) { unset($t['htm|html']); } /** * Filter list of allowed mime types and file extensions. * * @since 2.0.0 * * @param array $t Mime types keyed by the file extension regex corresponding to * those types. 'swf' and 'exe' removed from full list. 'htm|html' also * removed depending on '$user' capabilities. * @param int|WP_User|null $user User ID, User object or null if not provided (indicates current user). */ return apply_filters('upload_mimes', $t, $user); }
function custom_video_shortcode($attr, $content = '') { global $content_width; $post_id = get_post() ? get_the_ID() : 0; static $instances = 0; $instances++; /** * Override the default video shortcode. * * @since 3.7.0 * * @param null Empty variable to be replaced with shortcode markup. * @param array $attr Attributes of the shortcode. * @param string $content Shortcode content. * @param int $instances Unique numeric ID of this video shortcode instance. */ $html = apply_filters('wp_video_shortcode_override', '', $attr, $content, $instances); if ('' !== $html) { return $html; } $video = null; $default_types = wp_get_video_extensions(); $defaults_atts = array('src' => '', 'poster' => '', 'loop' => '', 'autoplay' => '', 'preload' => 'metadata', 'height' => 1080, 'width' => empty($content_width) ? 1920 : $content_width, 'size' => ''); foreach ($default_types as $type) { $defaults_atts[$type] = ''; } $atts = shortcode_atts($defaults_atts, $attr, 'video'); extract($atts); $w = $width; $h = $height; if (is_admin() && $width > 600) { $w = 1920; } elseif (!is_admin() && $w > $defaults_atts['width']) { $w = $defaults_atts['width']; } if ($w < $width) { $height = round($h * $w / $width); } $width = $w; $primary = false; if (!empty($src)) { $type = wp_check_filetype($src, wp_get_mime_types()); if (!in_array(strtolower($type['ext']), $default_types)) { return sprintf('<a class="wp-embedded-video" href="%s">%s</a>', esc_url($src), esc_html($src)); } $primary = true; array_unshift($default_types, 'src'); } else { foreach ($default_types as $ext) { if (!empty(${$ext})) { $type = wp_check_filetype(${$ext}, wp_get_mime_types()); if (strtolower($type['ext']) === $ext) { $primary = true; } } } } if (!$primary) { $videos = get_attached_media('video', $post_id); if (empty($videos)) { return; } $video = reset($videos); $src = wp_get_attachment_url($video->ID); if (empty($src)) { return; } array_unshift($default_types, 'src'); } $library = apply_filters('wp_video_shortcode_library', 'mediaelement'); /*if ( 'mediaelement' === $library && did_action( 'init' ) ) { wp_enqueue_style( 'wp-mediaelement' ); wp_enqueue_script( 'wp-mediaelement' ); } /*$atts = array( 'class' => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ), 'id' => sprintf( 'video-%d-%d', $post_id, $instances ), 'width' => absint( $width ), 'height' => absint( $height ), 'poster' => esc_url( $poster ), 'loop' => $loop, 'autoplay' => $autoplay, 'preload' => $preload, );*/ // These ones should just be omitted altogether if they are blank foreach (array('poster', 'loop', 'autoplay', 'preload') as $a) { if (empty($atts[$a])) { unset($atts[$a]); } } $attr_strings = array(); foreach ($atts as $k => $v) { $attr_strings[] = $k . '="' . esc_attr($v) . '"'; } $html .= '<video id="videoplayer" class="video-js vjs-mnml ' . $size . '" controls="controls" data-setup>'; $fileurl = ''; $source = '<source type="%s" src="%s" />'; foreach ($default_types as $fallback) { if (!empty(${$fallback})) { if (empty($fileurl)) { $fileurl = ${$fallback}; } $type = wp_check_filetype(${$fallback}, wp_get_mime_types()); // m4v sometimes shows up as video/mpeg which collides with mp4 if ('m4v' === $type['ext']) { $type['type'] = 'video/m4v'; } $html .= sprintf($source, $type['type'], esc_url(${$fallback})); } } if ('mediaelement' === $library) { $html .= wp_mediaelement_fallback($fileurl); } $html .= '</video>'; $html = sprintf('<div class="wp-video">%s</div>', $html); return apply_filters('wp_video_shortcode', $html, $atts, $video, $post_id, $library); }
/** * Return post media by format * * @param $post_format * @param $options * @return string * * @since 3.0 */ function kleo_get_post_media($post_format = 'standard', $options = array()) { global $kleo_config; if (isset($options['icons']) && $options['icons']) { $icons = true; } else { $icons = false; } if (isset($options['media_width']) && isset($options['media_height'])) { $media_width = $options['media_width']; $media_height = $options['media_height']; } else { $media_width = $kleo_config['post_gallery_img_width']; $media_height = $kleo_config['post_gallery_img_height']; } $output = ''; switch ($post_format) { case 'video': //oEmbed video $video = get_cfield('embed'); // video bg self hosted $bg_video_args = array(); $k_video = ''; if (get_cfield('video_mp4')) { $bg_video_args['mp4'] = get_cfield('video_mp4'); } if (get_cfield('video_ogv')) { $bg_video_args['ogv'] = get_cfield('video_ogv'); } if (get_cfield('video_webm')) { $bg_video_args['webm'] = get_cfield('video_webm'); } if (!empty($bg_video_args)) { $attr_strings = array('preload="none"'); if (get_cfield('video_poster')) { $attr_strings[] = 'poster="' . get_cfield('video_poster') . '"'; } $k_video .= '<div class="kleo-video-wrap"><video ' . join(' ', $attr_strings) . ' controls="controls" class="kleo-video" style="width: 100%; height: 100%;">'; $source = '<source type="%s" src="%s" />'; foreach ($bg_video_args as $video_type => $video_src) { $video_type = wp_check_filetype($video_src, wp_get_mime_types()); $k_video .= sprintf($source, $video_type['type'], esc_url($video_src)); } $k_video .= '</video></div>'; $output .= $k_video; } elseif (!empty($video)) { global $wp_embed; $output .= apply_filters('kleo_oembed_video', $video); } break; case 'audio': $audio = get_cfield('audio'); if (!empty($audio)) { $output .= '<div class="post-audio">' . '<audio preload="none" class="kleo-audio" id="audio_' . get_the_ID() . '" style="width:100%;" src="' . $audio . '"></audio>' . '</div>'; } break; case 'gallery': $slides = get_cfield('slider'); $output .= '<div class="kleo-banner-slider">' . '<div class="kleo-banner-items" >'; if ($slides) { foreach ($slides as $slide) { if ($slide) { $image = aq_resize($slide, $media_width, $media_height, true, true, true); //small hack for non-hosted images if (!$image) { $image = $slide; } $output .= '<article> <a href="' . $slide . '" data-rel="modalPhoto[inner-gallery]"> <img src="' . $image . '" alt="' . get_the_title() . '">' . kleo_get_img_overlay() . '</a> </article>'; } } } $output .= '</div>' . '<a href="#" class="kleo-banner-prev"><i class="icon-angle-left"></i></a>' . '<a href="#" class="kleo-banner-next"><i class="icon-angle-right"></i></a>' . '<div class="kleo-banner-features-pager carousel-pager"></div>' . '</div>'; break; case 'aside': if ($icons) { $output .= '<div class="post-format-icon"><i class="icon icon-doc"></i></div>'; } break; case 'link': if ($icons) { $output .= '<div class="post-format-icon"><i class="icon icon-link"></i></div>'; } break; case 'quote': if ($icons) { $output .= '<div class="post-format-icon"><i class="icon icon-quote-right"></i></div>'; } break; case 'image': default: if (kleo_get_post_thumbnail_url() != '') { $output .= '<div class="post-image">'; $img_url = kleo_get_post_thumbnail_url(); $image = aq_resize($img_url, $media_width, $media_height, true, true, true); if (!$image) { $image = $img_url; } $output .= '<a href="' . get_permalink() . '" class="element-wrap">' . '<img src="' . $image . '" alt="' . get_the_title() . '">' . kleo_get_img_overlay() . '</a>'; $output .= '</div><!--end post-image-->'; } elseif ($icons) { $post_icon = $post_format == 'image' ? 'picture' : 'doc'; $output .= '<div class="post-format-icon"><i class="icon icon-' . $post_icon . '"></i></div>'; } break; } return $output; }
/** * wpuxss_eml_on_activation * * @since 1.0 * @created 28/09/13 */ function wpuxss_eml_on_activation() { global $wpuxss_eml_version, $wpuxss_eml_old_version; if (version_compare($wpuxss_eml_version, $wpuxss_eml_old_version, '<>')) { update_option('wpuxss_eml_version', $wpuxss_eml_version); } if (empty($wpuxss_eml_old_version) || version_compare($wpuxss_eml_old_version, '0.0.3', '==')) { $wpuxss_eml_taxonomies['media_category'] = array('assigned' => 1, 'eml_media' => 1, 'admin_filter' => 1, 'media_uploader_filter' => 1, 'labels' => array('name' => 'Media Categories', 'singular_name' => 'Media Category', 'menu_name' => 'Media Categories', 'all_items' => 'All Media Categories', 'edit_item' => 'Edit Media Category', 'view_item' => 'View Media Category', 'update_item' => 'Update Media Category', 'add_new_item' => 'Add New Media Category', 'new_item_name' => 'New Media Category Name', 'parent_item' => 'Parent Media Category', 'parent_item_colon' => 'Parent Media Category:', 'search_items' => 'Search Media Categories'), 'public' => true, 'show_admin_column' => true, 'show_in_nav_menus' => true, 'hierarchical' => true, 'rewrite' => array('slug' => 'media_category'), 'sort' => 0); $allowed_mimes = get_allowed_mime_types(); foreach (wp_get_mime_types() as $type => $mime) { $wpuxss_eml_mimes[$type] = array('mime' => $mime, 'singular' => $mime, 'plural' => $mime, 'filter' => 0, 'upload' => isset($allowed_mimes[$type]) ? 1 : 0); } $wpuxss_eml_mimes['pdf']['singular'] = 'PDF'; $wpuxss_eml_mimes['pdf']['plural'] = 'PDFs'; $wpuxss_eml_mimes['pdf']['filter'] = 1; update_option('wpuxss_eml_taxonomies', $wpuxss_eml_taxonomies); update_option('wpuxss_eml_mimes', $wpuxss_eml_mimes); update_option('wpuxss_eml_mimes_backup', $wpuxss_eml_mimes); } }