WordPress.org

Ready to get started?Download WordPress

Forums

podPress
Trying to find/create a function to call mp3 url [podpress] (5 posts)

  1. tempestjonny
    Member
    Posted 3 years ago #

    Hey, If Mr Podpress is reading this. damn sir, you have created a slick plugin. In fact the more I jump into your code to try and break it, the more I realize how good it is :P

    I am currently updating the website of one of my podcasts. We already have a style and a theme that our fan are used to seeing. This basically means that instead of using the default media streamer and the download links, I would like to use my own styled button as the download button. but I'm having troubles getting the URL for an episode that i add to a post.

    Put simply, is there a method/function that i can use to call the URL of the media file added to the post?

    I get the feeling I'm missing something obvious, but I'm willing to look a fool to get this sorted. Thanks in advance and keep up the awesome work.

  2. ntm
    Member
    Plugin Author

    Posted 3 years ago #

    podPress is a very complex plugin and it is not easy to find the right line of code if you are not familiar with it and getting familiar with it takes takes time.

    is there a method/function that i can use to call the URL of the media file added to the post?

    No, podPress has no API function. But there are several filter hooks you could use to modify URLs and other elements of the podPress output.
    All hooks are listed on the Other Notes page in the section Filter Hooks of podPress.

    For instance:
    You could use the hook podpress_downloadlinks and write you a little filter plugin. This filter hook is to filter the podPress row below the player (all what is between <!-- Begin: podPress download link line --> and <!-- End: podPress download link line --> these comments included).

    A filter which may replace certain download buttons could look like this:

    add_filter('podpress_downloadlinks', 'filter_podpress_download_button_img_urls');
    function filter_podpress_download_button_img_urls($podpressdownloadlinks) {
    	// retrieve the URL of the download button out of the code of this line
    	$result = preg_match('/\<img src=\"(.+)\" class=\"podPress_imgicon\" alt=\"\" \/\>/i', $podpressdownloadlinks, $matches);
    	if ( 1 === $result ) { //  img URL found
    		// if there is a download image then compare the URL (matches[1]) to discover which image it is and replace the URL with a different one
    		//  (matches[0] contains the complete <img> tag)
    		Switch ($matches[1]) {
    			case PODPRESS_URL . '/images/audio_mp3_button.png' :
    				$new_url = PODPRESS_URL . '/images/audio_mp3_icon.png'; // in this example the button URL of the download button of mp3 files gets exchanged with the icon URL
    			break;
    			default :
    				$new_url ='';
    			break;
    		}
    		// if the URL should be replaced then replace it. otherwise return code unchanged
    		if ( '' !== $new_url ) {
    			return str_replace($matches[1], $new_url, $podpressdownloadlinks);
    		} else {
    			return $podpressdownloadlinks;
    		}
    	} else {
    		return $podpressdownloadlinks;
    	}
    }

    You can put this code in the functions.php of your theme or in a php file e.g. podpress_filters.php along with:

    /*
    Plugin Name: podPress filters
    Plugin URI:
    Description: some filters for the output of podPress
    Author: ntm
    Version: 1.0
    Author URI:
    */

    (This should be placed at the beginning of the php file before the other code.)
    podpress_filters.php should be placed in the plugin folder or in a separate sub folder like /wp-content/plugins/podpress_filters/podpress_filters.php. If you do that, it will among the other plugins on the plugins page of your blog and you can easily switch it on and off.

    If you really like to know how podPress assembles the output then take a look in the podpress_class.php file (line 1000-1325) which retrieves the data from the wp_postmeta table and in the podpress_theme.php file which assembles the output.

    But I recommend to use the filter hooks and a filter plugin.

    Regards,
    Tim

  3. tempestjonny
    Member
    Posted 3 years ago #

    Hi Tim, Thanks for getting back so quickly and sorry for getting back to you so slowly.

    I've had a try at the filter and managed to get the image i want. Thank you very much for getting me this far. There are a few extra things I need to sort out to get it working with my theme, don't know if you could point me in the right direction or not.

    1 - I only really managed to get the Image I wanted by giving the full URL of it. I originally tried changing the line
    $new_url = PODPRESS_URL . '/images/audio_mp3_icon.png';
    to
    $new_url = bloginfo('template_url') . '/images/audio_mp3_icon.png';
    but I don't think it liked the bloginfo being used inside a plugin....not too sure

    2 - I've got it displaying the button, but still can't remove the words "Standard podcast" or what ever the file type is. I know i can do it by altering your plugin, but then i won't be able to enjoy your updates.

    3 - I'm sure there was a way to simply place the output anywhere on the page via the theme, but i can't find the line of code anywhere, am i being blind and missing the point.

    Thank you again for getting me this far, and if you manage to get me the rest of the way, then you officially will be owed a drink :P

  4. ntm
    Member
    Plugin Author

    Posted 3 years ago #

    to 1.: bloginfo() is almost the right function. But bloginfo echos the path or any other value you could retrieve with this function. Better use get_bloginfo() instead. It returns the value and you can echo it when ever you want to. (see http://phpxref.com/xref/wordpress/wp-includes/general-template.php.source.html#l363 for the keywords you can use with this function and to see which functions this function calls to retrieve the URL)

    to 2.: the phrase "Standard Podcast" is a default value which will be displayed if you do not define a title for the episode. It is not always this phrase. The phrase depends on the file type of the podcast episode (see the last 50 lines in the podpress_theme.php file).
    Unfortunately that seems to be the only part of that line which one can not disable/hide via a option on the settings page. I'm going to change that in the next version of podPress.
    So far the only possibility is to use the same filter hook and function. If you have only mp3 files you could use str_replace to delete the phrase.

    to 3.: You can define the position of the podPress elements within the content of a post or page by using the place-holder [display_podcast]. podPress will replace that place-holder on page load. But other than that will probably be difficult. Because all the functions which insert the podPress elements are design to as filters for the content and excerpts. It uses for instance the filter hook the_content. There is no function which delivers you the code of the podPress elements if you call it with a certain ID of a post.
    If you want to have the podPress elements outside of the usual posts then you probably would need to create a custom Loop which may request only certain posts and use the_content() or get_the_content(). If you don't want to display the content again, you could use a further filter with the hook the_content to delete the post content before podPress adds the player code and the links.
    That are only spontaneous ideas. I have not written such function or snippet for one of the theme files myself. But I would help you if have questions.

    ps:

    sorry for getting back to you so slowly.

    No problem!

  5. tempestjonny
    Member
    Posted 3 years ago #

    Thank you so much for getting back to me and with such detail.

    1 - Your right. Adding the Get_ sorted that out instantly.
    2 - In the end I was a bit checky. I added...
    .podpress_mediafile_title{display:none;}
    ...to my CSS and removed from being displayed.
    3 - To be honest, i had never come across filters until i found your plugin. Can't believe how powerful they are. I tried a few things to try and get the content with out the content being displayed...all to little avail.
    In the end, I cheated. I got the "podPress_downloadlinks" class and added absolute positioning to it. not the perfect solution, but for me at least it worked.

    Thank you again for all your help, i could not have done it without you. Thanks.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags