function rtmedia_image($size = 'rt_media_thumbnail', $id = false, $recho = true) { global $rtmedia_backbone; if ($rtmedia_backbone['backbone']) { echo '<%= guid %>'; return; } if ($id) { $model = new RTMediaModel(); $media = $model->get_media(array('id' => $id), false, false); if (isset($media[0])) { $media_object = $media[0]; } else { return false; } } else { global $rtmedia_media; $media_object = $rtmedia_media; } $thumbnail_id = 0; if (isset($media_object->media_type)) { if ($media_object->media_type == 'album' || $media_object->media_type != 'photo' || $media_object->media_type == 'video') { if ($media_object->media_type == 'video') { $thumbnail_id = isset($media_object->cover_art) && $media_object->cover_art != "0" ? $media_object->cover_art : false; } $thumbnail_id = apply_filters('show_custom_album_cover', $thumbnail_id, $media_object->media_type, $media_object->id); // for rtMedia pro users } elseif ($media_object->media_type == 'photo') { $thumbnail_id = $media_object->media_id; } else { $thumbnail_id = false; } if ($media_object->media_type == 'music' && $thumbnail_id == "") { $thumbnail_id = get_music_cover_art(get_attached_file($media_object->media_id), $media_object->id); } if ($media_object->media_type == 'music' && $thumbnail_id == "-1") { $thumbnail_id = false; } } else { $src = false; } if (!$thumbnail_id) { global $rtmedia; // Getting the extension of the uploaded file $extension = rtmedia_get_extension(); // Checking if custom thumbnail for this file extension is set or not if (isset($rtmedia->allowed_types[$media_object->media_type]) && isset($rtmedia->allowed_types[$media_object->media_type]['ext_thumb']) && isset($rtmedia->allowed_types[$media_object->media_type]['ext_thumb'][$extension])) { $src = $rtmedia->allowed_types[$media_object->media_type]['ext_thumb'][$extension]; } else { if (isset($rtmedia->allowed_types[$media_object->media_type]) && isset($rtmedia->allowed_types[$media_object->media_type]['thumbnail'])) { $src = $rtmedia->allowed_types[$media_object->media_type]['thumbnail']; } elseif ($media_object->media_type == 'album') { $src = rtmedia_album_image($size, $id); } else { $src = false; } } } else { if (is_numeric($thumbnail_id) && $thumbnail_id != "0") { list($src, $width, $height) = wp_get_attachment_image_src($thumbnail_id, $size); } else { $src = $thumbnail_id; } } $src = apply_filters('rtmedia_media_thumb', $src, $media_object->id, $media_object->media_type); if ($recho == true) { echo $src; } else { return $src; } }
/** * Get media src * * @global array $rtmedia_backbone * @global object $rtmedia_media * @global RTMedia $rtmedia * * @param string $size * @param bool|int $id * @param bool $recho * * @return bool|int|string|void */ function rtmedia_image($size = 'rt_media_thumbnail', $id = false, $recho = true) { global $rtmedia_backbone; if ($rtmedia_backbone['backbone']) { echo '<%= guid %>'; return; } if ($id) { $model = new RTMediaModel(); $media = $model->get_media(array('id' => $id), false, false); if (isset($media[0])) { $media_object = $media[0]; } else { return false; } } else { global $rtmedia_media; $media_object = $rtmedia_media; } $thumbnail_id = 0; if (isset($media_object->media_type)) { if ('album' === $media_object->media_type || 'photo' !== $media_object->media_type || 'video' === $media_object->media_type) { $thumbnail_id = isset($media_object->cover_art) && (false !== filter_var($media_object->cover_art, FILTER_VALIDATE_URL) || 0 !== intval($media_object->cover_art)) ? $media_object->cover_art : false; $thumbnail_id = apply_filters('show_custom_album_cover', $thumbnail_id, $media_object->media_type, $media_object->id); // for rtMedia pro users } elseif ('photo' === $media_object->media_type) { $thumbnail_id = $media_object->media_id; } else { $thumbnail_id = false; } if ('music' === $media_object->media_type && empty($thumbnail_id)) { $thumbnail_id = rtm_get_music_cover_art($media_object); } if ('music' === $media_object->media_type && -1 === intval($thumbnail_id)) { $thumbnail_id = false; } } if (!$thumbnail_id) { global $rtmedia; // Getting the extension of the uploaded file $extension = rtmedia_get_extension(); // Checking if custom thumbnail for this file extension is set or not if (isset($rtmedia->allowed_types[$media_object->media_type]) && isset($rtmedia->allowed_types[$media_object->media_type]['ext_thumb']) && isset($rtmedia->allowed_types[$media_object->media_type]['ext_thumb'][$extension])) { $src = $rtmedia->allowed_types[$media_object->media_type]['ext_thumb'][$extension]; } else { if (isset($rtmedia->allowed_types[$media_object->media_type]) && isset($rtmedia->allowed_types[$media_object->media_type]['thumbnail'])) { $src = $rtmedia->allowed_types[$media_object->media_type]['thumbnail']; } elseif ('album' === $media_object->media_type) { $src = rtmedia_album_image($size, $id); } else { $src = false; } } } else { if (is_numeric($thumbnail_id) && 0 !== intval($thumbnail_id)) { list($src, $width, $height) = wp_get_attachment_image_src($thumbnail_id, $size); } else { $src = $thumbnail_id; } } $src = apply_filters('rtmedia_media_thumb', $src, $media_object->id, $media_object->media_type); if (true === $recho) { echo esc_url($src); } else { return $src; } }