Greetings!

I have put a nice little button, in a drupal block, on my site that allows iTunes users to click and subscribe as a podcast in iTunes. It looks something like:

(open bracket)a href="itpc://ctl.nsuok.edu/drupal/?q=blog/4/feed"(closebracket )
(open bracket)img alt="Use iTunes to Subscribe to CTL Podcast" src="http://ctl.nsuok.edu/drupal/badgeitunes61x15dark.gif"(close bracket) /a

This works great for that single user's blog. Does anyone have a clue on how I could add this to all my users blogs automatically?

Comments

yelvington’s picture

Your best bet is probably to override theme_feed_icon by constructing a corresponding function in your theme's template.tpl file. There you can replace the http url with the itpc url by doing a string replace. If you want to retain the functionality of the normal syndicate block, you could simply emit both sets of links.

JymBrittain’s picture

I wouldnt even know how to begin to implement what you said. I can barely code HTML let alone fine and replace in the code that makes drupal. We're using the bluemarine theme, for what it's worth.

technology4teachers.com

yelvington’s picture

It's not simple, but it's not as hard as it seems, and you don't have to be a bona fide PHP wizard. You do have to understand some basics of coding.

http://drupal.org/node/55126 explains how to start. By convention, any time Drupal emits HTML, it runs that HTML through a function. With phptemplate it's not hard to override that function with one of your own. You do that by copying the standard function into template.php, changing its name, and then tinkering with how it works.

In this case the standard function is theme_feed_icon, so you would begin by looking it up at api.drupal.org. View the source. Copy the code. Paste it into your theme's template.php file (create one if it doesn't exist). Change the function name from theme_feed icon to sometheme_feed_icon, where "sometheme" is replaced by the actual name of your theme (which will be the same as the directory it is in).

Now you have the starting point. In the code, you have

 function theme_feed_icon($url) {
  if ($image = theme('image', 'misc/feed.png', t('Syndicate content'), t('Syndicate content'))) {
    return '<a href="'. check_url($url) .'" class="feed-icon">'. $image. '</a>';
  }
} 

That may look like gobbledegook, but the important part is the line that says "return" followed by a statement that builds the string.

What you need is something like

 function sometheme_feed_icon($url) {
  if ($image = theme('image', 'misc/feed.png', t('Syndicate content'), t('Syndicate content'))) {
    /* instead of returning the value, stuff it into a variable */
    $retval =  '<a href="'. check_url($url) .'" class="feed-icon">'. $image. '</a>';
   /* now replace the a href string */
   $retval = str_replace('a href="/','a href="itpc://ctl.nsuok.edu/',$retval);
  /* and replace the icon */
  $retval = str_replace('img src="/misc/feed.png" alt="Syndicate content" title="Syndicate content" height="16" width="16"', 'img alt="Use iTunes to Subscribe to CTL Podcast" src="http://ctl.nsuok.edu/drupal/badgeitunes61x15dark.gif" height="15" width="61"',$retval);
  /* and return the mashed-up results */
  return $retval;
  }
} 

(Note that this is all untested code and is just an example. Instead of taking the obvious approach of fixing the existing code, I'm using brute force to replace strings before returning a result. Rewriting the entire function would be a better way of doing it.)

If you are using the current phptemplate version of bluemarine, and not the outdated xtemplate version, this technique can be used to replace pretty much any Drupal output with an alternative of your own choice. It doesn't require that you touch any core Drupal code, but it does require that you write some of your own and you do have to understand how to figure out function names and look them up in the documentation system.

JymBrittain’s picture

But, as luck would have it we're using the old xtemplate version.

technology4teachers.com

JymBrittain’s picture

What I would like to do is add a button or somesuch at the bottom of all my user blogs automatically that will allow folks to click and have that blog subscribed in iTunes using the itpc:// protocol

technology4teachers.com