Photo Sidebar widget

The Photo Sidebar widget takes advantage of the Sidebar Widget plugin from Automattic, Inc. to display a user-selectable number of random photos from one (or several) RSS photo feeds (specifically SmugMug or Flickr feeds although it may conceivably work for others) in the sidebar of a Word Press blog.

This plugin requires the installation of the Widgets plugin (available here or included in WordPress version 2.2). For optimal performance, you may need to tweak your theme to work with the Widgets plugin.

Installation:
Installation is simple: Just place photo_sb.php in the widgets subdirectory, then activate it from the Plugins tab of your blog’s administrative panel. (Make sure that the Sidebar widget is activated as well.)

Setup:
Setup is easy, too. Go to the Sidebar Widgets page from the Presentation tab. Widgets can be dragged-and-dropped onto the sidebar and arranged to your liking. Use the blue ’settings’ box (on the widget’s “rectangle”) to point to RSS feeds, adjust any of the visual settings to fit your theme and preferences and save the sidebar settings. You should be able to see the sidebar on your front page.

Background:
After some good-natured prodding toward messing with the SmugMug API, I decided I needed to start small. My first foray into the world of SmugMug RSS was with Adam Tow’s WP-SmugMug plugin (to which this plugin owes much of its heritage.) After a little time, I decided I wanted to display the photos a little more prominently, along the lines of the Flickr “badge” that graces some blogs.

Comments and ideas for improvement are welcome and I’d love to see other sites that run this plugin. Don’t hesitate to contact me with problems, either.

Download:

91 Comments »

  1. cellus said,

    April 13, 2007 at 7:34 pm

    I thought I’d fixed an IE 5/6 problem with the CSS that throws the entire sidebar to the bottom of the page. It’s still popping up intermittently and I’ll be working on a better fix.

  2. cellus said,

    April 22, 2007 at 11:29 am

    As of this morning, I’ve changed the style to address the IE 5/6 problem. Instead of
    display=block; margins = 0 auto;
    I have
    align="center"
    in the div section. This appears to solve the problem reliably on my IE 6 browser.

  3. Curtis said,

    April 24, 2007 at 11:40 pm

    I enabled this plugin and the widget only displays text with no pictures. I have the following URL as the RSS feed.

    http://mykidzshotz.smugmug.com/hack/feed.mg?type=gallery&Data=2757946&format=rss200

    Any tips on why images are not showing up on the left column?

  4. cellus said,

    April 25, 2007 at 7:11 am

    Curtis, I’m guessing the text you’re seeing are the photo descriptions? If so, the only thing I can think of offhand is that the image urls are blocked or for some other reason the images can’t be downloaded.

    I took a look at your site and see the photo sidebar on the right, which seems to be working–is this a different theme? Let me know what theme and what browser and I’ll see if I can replicate it. Thanks!

  5. Bradjward said,

    April 26, 2007 at 9:40 pm

    I’m having the same issue as Curtis. I’m using a custom theme, and Firefox on a Mac.

    Where did you pull the RSS from in Smugmug?

  6. cellus said,

    April 26, 2007 at 11:48 pm

    Brad, I’m getting my feeds from the “available feeds” buttons on individual galleries, and specifically from the RSS-formatted feed rather than the atom-formatted feed.

    In fact, this may be a clue–I was able to replicate your problem by using an atom feed. It displayed the link but not the photo; the parsed html had the image source blank.

    Let me know if this is indeed the issue and if so, I’ll update the FAQ!

    Incidentally, when I used the “recent photos” atom feed rather than the one for the individual gallery, I didn’t get anything–as if the WP RSS code had rejected the feed as invalid (as it’s supposed to do.) The Smugmug RSS feed links are enclosed in guid tags while the atom feed links are enclosed in id tags but the title tags are the same for both feeds which is consistent with this problem.

  7. Bradjward said,

    April 27, 2007 at 9:41 am

    Got it! Used the Rss2 feed and it works fine. Thanks!

    Bradjward

  8. TC said,

    May 7, 2007 at 5:21 pm

    I can’t get this to work. No matter which RSS 2.0 Smugmug feed I use, i only get the names of the photos (text descriptions) and not the actual photos themselves.

  9. cellus said,

    May 7, 2007 at 8:10 pm

    TC, would you mind sending me your web page? If you’re not comfortable posting it, you can email me the code (what you would get if you went to “view source” in IE or “page source” in Firefox. You can crop everything except what is between the two sidebar tags. My address is wallace6_80210 AT yahoo.com

  10. John said,

    May 9, 2007 at 12:26 pm

    The plug-in works great. Two questions: 1. Can I have two of these running in the sidebar, pulling two different feeds and number of images? 2. Can I have a title/caption under the photo?

    Thanks, John

  11. cellus said,

    May 9, 2007 at 11:32 pm

    John, thanks for the comments…I think “creating” a second widget may be relatively easy but I’ll have to play around with it.

    I’ll look at adding an option to display a caption in the next version, probably in a week or two. I suspect there may be more demand for this than the current “border” option.

  12. cellus said,

    May 15, 2007 at 12:25 am

    I’ve posted the newest version (1.20). This adds support for Flckr feeds. (Why, you ask? Well, now you can merge Flickr and Smugmug feeds. Really, more an exercise for me than an in-demand feature, but it could be fun.) I also scrapped the “border” for now (IMHO, the widget looks better in most themes without it) and added an option to display an image caption (if one exists).

  13. David said,

    May 18, 2007 at 5:30 pm

    Thanks for creating this. Is it possible to make this work with Gallery2 feeds? When I attempted to do this myself, the links showed up with no url in the src=”" attribute of the img tags is blank. Here is a sample feed if it is helpful. (http://www.heapoverflow.org/gallery/main.php?g2_view=rss.Render&g2_name=Milo)

    After looking at the plugin code, I decided to see if I could fix it myself (I am not a programmer). After a couple of attempts, I got an error that I couldn’t resolve. I inserted the following code at line 153:


    elseif ($item["generator"]==”Gallery 2 RSS Module, version 1.1.0″) {
    //Image URL’s in Flickr feeds are buried; the feed is controlling how these are displayed
    //We just want the URL and not the formatting
    $item_url = $item["image"]["description"];
    $start_pos = strpos($item_url , ”

    The error I get is:
    Warning: strpos() [function.strpos]: Offset not contained in string. in photo-sidebar-widget/photo_sb.php on line 159

    If you could point me in the right direction, I would be EXTREMELY gratefully!

    Thanks

    David

  14. David said,

    May 18, 2007 at 5:35 pm

    wordpress messed up my modified code. You can find it here:

    http://www.heapoverflow.org/code.txt

  15. cellus said,

    May 19, 2007 at 12:05 am

    David, I was thinking about tackling Gallery2 next–this is a great opportunity to take a look at it.

    After installing the RSS module, I took a look at the feed and it looks like your ["generator"]= line is perfect.

    As you were able to determine, the image source is formatted similar to the Flickr feed. However, rather than storing the link in a second-level tag (i.e., ["image"]["text"], it is it’s own first level tag, so we just have ["description"].

    I think if you just remove ["image"] you should be set:
    $item_url = $item["description"];

    Let me know how it looks.

    Nice work–thanks!

  16. David said,

    May 19, 2007 at 2:38 pm

    It looks great. You are the man! Thank you so much! I’ve not been pleased with the way the WPG2 plugin works by wrapping your wordpress theme around gallery. The plugins that adds random photos that came with it uses that format and there wasn’t an easy way to make it link directly to the image instead of it wrapping WP around gallery. This plug makes me a very happy man.

    Thanks again!

    David

  17. cellus said,

    May 20, 2007 at 8:05 pm

    Glad it worked! Thanks for the comments, and thanks also for letting me know about your issues with posting comments.

  18. Mark said,

    June 1, 2007 at 12:42 pm

    Love the plugin! One question, though — what’s the chance this could be configured to only pick horizontal or vertical photos? I’m just thinking it’s a bit ugly when when it picks both… thoughts??

  19. cellus said,

    June 3, 2007 at 6:19 pm

    Mark, glad you like it.

    I agree that the different photo orientations is a difficulty…here is a quick and simple way to change the code to force the plugin to choose one or the other.

    At the line just before //generate the appropriate code to show the photo), add these two lines:

    $image_info = getimagesize($item_url);
    if ($image_info[0] < $image_info[1]) {

    Then, scroll down about twenty lines or so, to just before
    }
    else break;

    And insert a line there that is simply:

    }

    This code will always show only images in a “portrait” orientation. $image_info[0] is the image width and $image_info[1] is the image height, so if you would prefer to show landscape photos, just change the “< " to a ">“. You could also have the code decide on the fly which photos to show (using a random function or based on the first image) with some more involved code modifications.

    I worry a bit about creeping featurism but does anyone think this is worth adding to the next version of the plugin?

  20. linda blackwell said,

    June 8, 2007 at 10:47 am

    im just in the process of setting up my new blogpage and your photo widget was one of the first I wanted to try but it keeps giving me this error:
    Warning: Invalid argument supplied for foreach() in /home/renegade/public_html/jamamamas-shadylawn/blog/wp-content/plugins/widgets/photo_sb.php on line 106

    instead of the photos. as you can see it is available to activate in my sidebar so i have installed it ok, and i cannot program things, forget that.
    i read what you said abd IE and i run slimbrowser which is solely based on IE just has a nicer theme and addon i like and have used it for years, but i does run IE.

    can you help me. i get so frustrated when things don’t work and they say go to line whtever, all that means to my non technical brain is, crp i’m not going to have this one and I usually delete it, but if there is a fix for it that i or you could do that would be great.
    thanks,
    jamamama (i love how it looks here on your page)

  21. cellus said,

    June 8, 2007 at 4:04 pm

    Hi Jamamama,

    Thanks for the comment–I think I can help you.

    I get this error occasionally when there is something wrong with the feed url I’m using. Usually, I’ve left off a character somewhere, but it can be something less obvious, such as a misplaced comma (for instance, if you put a comma in without adding a new feed after it, you will see this error.)

    I suggest going into the settings and clearing out the RSS Feed URL’s box. Once it’s clear, make sure you’re “in” the entry box and hit the delete key several times to clear any extra hard returns. Then re-enter your feed URL. I suggest copying the link by selecting it from the address bar or right-clicking on the link (in Windows) and selecting “Copy Link Location,” then pasting it into the entry box.

    I hope this works–let me know if you’re still having problems!

    Incidentally, I plan to clean things up in the next version so that you won’t see this error (which is ugly and intimidating). Instead, you just won’t see any photos, at least from the feed that’s causing the error.

  22. linda blackwell said,

    June 9, 2007 at 12:01 am

    can you fix it?——-
    ‘;
    else
    ***************************************************/

    echo ”;

    //Use WordPress’ built-in RSS functionality
    if (!function_exists(’MagpieRSS’)) { // Check if another plugin is using RSS, may not work
    include_once (ABSPATH . WPINC . ‘/rss-functions.php’);
    //error_reporting(E_ERROR);
    }

    foreach ($feed_url as $url) {
    //load the structured rss feed(s)
    $url = trim($url); //this will remove any extra “whitespace” (spaces, tabs, CR, LF, etc.) that may exist in the user-entered feed list
    $rss = fetch_rss($url);
    $channel = $rss->channel;
    $generator = $channel["generator"];
    $new_fetch = $rss->items;

    foreach($new_fetch as $key=>$value) {
    $new_fetch[$key]["generator"] = $generator; //since our feeds may be mixed, each item needs to keep its generator info
    }

    //the first time through the loop, the array is set up automatically. For all
    //subsequent trips through the loop (i.e. for additional feeds,) we have to
    //add to the array manually. array_push($fetch,$old_fetch) just puts the whole
    //$old_fetch object as the last element of the array instead of adding all of the
    //individual elements, which is what we want.

    if (count($fetch) != 0) {
    foreach($new_fetch as $items) {
    array_push($fetch,$items);
    }
    }
    else $fetch=$new_fetch;
    }

    if($fetch) {

    //sort the items (photos) randomly
    usort($fetch, rand_compare);

    $count = 0;

    foreach($fetch as $item) {
    //format the title correctly in case the photo title includes text that needs to be escaped
    $item["title"]=htmlspecialchars($item["title"]);

    //use the maximum number of photos to control the foreach loop
    //if we haven’t displayed the maximum number of photos, build the HTML to
    //display an image including built-in (i.e inline) style elements to center the photo

    if ($count “; //include some whitespace for items for which the feed type isn’t determined

    //generate the appropriate code to show the photo
    echo ‘‘;
    echo “\n”;

    if ($show_title)
    echo ” . $item[title] . ”; //show the caption if requested

    if ($item_url == “”)
    echo “”; //include some whitespace for items for which the feed type isn’t determined
    }
    else break;

    $count = $count + 1;
    }
    }

    //finish sidebar code
    echo ”; //an if statement isn’t necessary since we opened a div regardless of whether a border was selected
    echo $after_widget;
    }

    //This registers the widget with the Sidebar plugin
    register_sidebar_widget(’Photos’,'disp_sm_feed’);

    //This lets the Sidebar plugin know that a built-in control is available
    //225 pixels is a larger height than necessary but IE puts extra spaces between lines so this is the fix for now.
    //increase the second number to 365 if the border code has been included
    register_widget_control(array(’Photos’, ‘widgets’), ‘widget_photo_sb_control’, 600, 225);

    }

    /* Function: rand_compare
    ** To be used with an array sort function (i.e. usort), this function
    ** will randomly sort an array
    **
    ** args: $x=string; $y=string (handled by the function call)
    ** returns: a random integer between -1 and 1
    */

    function rand_compare($xt, $yt) {
    // We don’t care about the array elements passed on so we’ll
    // create a random value for the return value
    return mt_rand(-1,1);
    }

    /* Function: widget_photo_sb_control()
    ** This is the function that outputs the form to let the users edit
    ** the widget’s title, the RSS feed and the number of photos to
    ** display; mainly minor adjustments from the Google Search widget control
    ** args: none
    ** returns: nothing
    */

    function widget_photo_sb_control() {

    // Get our options and see if we’re handling a form submission.
    $options = get_option(’widget_photo_sb’);
    if ( !is_array($options) )
    $options = array(’title’=>’Photos’, ‘feed_url’=>”, ‘photo_count’=>’5′, ’show_title’=>FALSE, ‘draw_border’=>FALSE, ‘background_color’=>’white’, ‘padding_top’=>’0′, ‘padding_right’=>’0′, ‘padding_bottom’=>’0′, ‘padding_left’=>’0′);
    if ( $_POST['photo_sb-submit'] ) {

    // Remember to sanitize and format use input appropriately.
    $options['title'] = strip_tags(stripslashes($_POST['photo_sb-title']));
    $options['feed_url'] = strip_tags(stripslashes($_POST['photo_sb-feed_url']));
    $options['photo_count'] = strip_tags(stripslashes($_POST['photo_sb-photo_count']));
    $options['show_title'] = strip_tags(stripslashes($_POST['photo_sb-show_title']));

    /***************************************************
    Uncomment these lines to add the option for a border
    $options['draw_border'] = strip_tags(stripslashes($_POST['photo_sb-draw_border']));
    $options['background_color'] = strip_tags(stripslashes($_POST['photo_sb-background_color']));
    $options['padding_top'] = strip_tags(stripslashes($_POST['photo_sb-padding_top']));
    $options['padding_right'] = strip_tags(stripslashes($_POST['photo_sb-padding_right']));
    $options['padding_bottom'] = strip_tags(stripslashes($_POST['photo_sb-padding_bottom']));
    $options['padding_left'] = strip_tags(stripslashes($_POST['photo_sb-padding_left']));
    ******************************************************/

    update_option(’widget_photo_sb’, $options);
    }

    // Be sure you format your options to be valid HTML attributes.
    $title = htmlspecialchars($options['title'], ENT_QUOTES);
    $feed_url = htmlspecialchars($options['feed_url'], ENT_QUOTES);
    $photo_count = htmlspecialchars($options['photo_count'], ENT_QUOTES);
    $show_title = htmlspecialchars($options['show_title'], ENT_QUOTES);

    /***************************************************
    Uncomment these lines to add the option for a border
    $draw_border = $options['draw_border'];
    $background_color = htmlspecialchars($options['background_color'], ENT_QUOTES);
    $padding_top = htmlspecialchars($options['padding_top'], ENT_QUOTES);
    $padding_right = htmlspecialchars($options['padding_right'], ENT_QUOTES);
    $padding_bottom = htmlspecialchars($options['padding_bottom'], ENT_QUOTES);
    $padding_left = htmlspecialchars($options['padding_left'], ENT_QUOTES);
    ******************************************************/

    // Here is our little form segment. Notice that we don’t need a
    // complete form. This will be embedded into the existing form.

    echo ” . ‘Title: ‘ . ‘ ‘;
    echo ” . ‘RSS Feed URL\’s (seperate URL\’s with “, “): ‘ . ”.$feed_url.”;

    //create an option box with a set number of values generated by a for loop
    echo ” . ‘Number of photos to show: ‘ . ”;
    for($list_val=1; $list_val ‘ . $list_val . ”;

    else
    echo ” . $list_val . ”;
    }
    echo ”;
    echo ” . ‘Show caption beneath photo? ‘ . ”;

    /***************************************************
    Uncomment these lines to add the option for a border
    echo ”;
    echo ” . ‘Include a border for this widget? ‘ . ”;
    echo ” . ‘Background color (names or hex codes; e.g. \’white\’ or \’#FFFFFF\’):’ . ‘ ‘;
    echo ” . ‘Padding:’ . ”;
    echo ” . ‘Top: ‘ . ”
    . ” . ‘ Right: ‘ . ”
    . ” . ‘ Bottom: ‘ . ”
    . ” . ‘ Left: ‘ . ”;
    ******************************************************/

    echo ”;
    }

    add_action(’widgets_init’,'widget_photo_sb_init’);

    ?>
    thanks

  23. cellus said,

    June 9, 2007 at 5:54 am

    Jamamama, could you send me the link you are using as your photo feed? You could email it to me at wallace6_80210@yahoo.com if you like.

  24. Laurent Cavalie said,

    June 11, 2007 at 5:12 pm

    i have exactly the same problem with smugmug and my installation of WordPress. Same error at line 106 (in a loop).
    I copied and pasted the link directly from the rss feed on the smugmug page. Quite sure there was no bad caracters in the field.
    Really ddon’tknow what is wrong.
    I’m sad because it’s a real good widget.
    Any chance you found out what that error is ?

  25. cellus said,

    June 11, 2007 at 9:33 pm

    Laurent, Jamamama:

    I’m seeing the same issue you are when I try to use my “recent photos” feed from Smugmug but no problems using my gallery feeds (as I’m doing on this site.) I’ve noticed that loading the feeds in a browser window is slow as well, so I *think* that the wordpress RSS code is timing out because the feed is taking too long to load. I’m working on verifying this as well as looking into other reasons some feeds are working fine while others are not, but it may take some time for me to work through this.

    Out of curiosity, are you using the “recent photos” feed or a gallery feed (or perhaps not a smugmug feed at all?) If you’re using the Smugmug recent photos feed, does using a gallery feed instead help?

    I apologize for the problems!

  26. Laurent Cavalie said,

    June 12, 2007 at 10:11 am

    Hi,

    Yes I tried with the recent feeds of smugmug (recent photos or galleries).
    I did not tried with a gallery feed but I will as soona s i have a minute.

    Thanks for working on it.

  27. Brian Robertson said,

    June 13, 2007 at 11:15 am

    Tried the plug in, read the above suggestions, but still no luck. I did find the actual rss feed of the site I wanted to feature, but I still get only the titles, no pictures. If you have a moment, can you take a look and see what might be the problem?

    Thanks!

    Brian

  28. cellus said,

    June 13, 2007 at 9:53 pm

    Brian, I think I may know what the problem was because I ran into it while trying to solve the issues Laurent and Jamamama have been having. Are you using the “Recent Gallery” feed?

    If so, I think I can help although I’ll need to make some changes in my code–hopefully I can have an update by this weekend. In the meantime, you could see if you can use a gallery feed instead.

  29. Brian Robertson said,

    June 14, 2007 at 12:35 am

    Thanks, Cellus. I don’t tknow if this will help, but here’s the process I went through to get my sad dead end!

    My newsreader shows the feed as:

    http://scrapiteria.blogspot.com/feeds/posts/default

    I don’t think photos would take that at all, it came up blank - so I dug up their rss feed and used it instead. http://scrapiteria.blogspot.com/rss.xml

    Is there an example of a feed of photos that does work with the feature? I’ve tried a few and had no luck.

    Thanks for helping, by the way, and I’ll look forward to what happens. I don’t really know what a “galley feed” is and how it differs from the .rss or how you even begin to find it.

    Brian

  30. cellus said,

    June 14, 2007 at 10:35 pm

    Hey Brian, here is an example of a feed that current works (Incidentally, it’s the feed of the user who had the featured photo on Flickr when I visited that site a few minutes ago.)

    The feed you indicated isn’t one that is supported (and that’s probably why you didn’t know what I meant when I wrote about the “recent gallery” feed) but I can show you how to modify the code (as long as you’re not squeamish about these things) to get it to work. I’ll have to look at it a little more closely–again, something I should be able to do in a couple of days.

  31. Brian Robertson said,

    June 15, 2007 at 9:26 am

    Absolutely NO hurry. Just thought a bit more information might help you figure what was going on. I’m happy to wait with this page bookmarked :)

    Thank you so much for your kind efforts.

    Brian

  32. cellus said,

    June 19, 2007 at 11:12 pm

    Hi Brian,
    You should be able to use your feed by adding the following lines to the photo_sb.php file before the line that says
    elseif($item["id"])

    lines that say
    else
    $item_url=”";

    elseif($item["generator"]==”Blogger”) {
    $item_url = $item["description"];
    $start_pos = strpos($item_url , “src=”)+4;
    $end_pos = strpos($item_url , “\”", $start_pos);
    $item_url = substr($item_url, $start_pos, $end_pos-$start_pos);
    }

    Let me know if it works!

  33. Brian said,

    June 20, 2007 at 10:25 am

    Tried it, cellus –problem :(

    I put the above right before the line, as suggested, and got this when I tried to upload:

    Parse error: parse error, unexpected ‘=’ in /home/content/v/i/s/visualblip/html/wp-content/plugins/photo_sb.php on line 156

    I’m so ignorant on php that I can’t figure what’s wrong. :(

  34. cellus said,

    June 20, 2007 at 9:39 pm

    My fault! My face is a little red because there are actually two things wrong that I didn’t catch. Most importantly, I told you to paste it in the wrong place. I corrected in the text of my original instructions–this should result in you moving the text up about three lines. The second error is that the double-quote character ‘”‘ isn’t appearing consistently (although this may well correct itself when you paste into a text editor.) You will want to double check this when you paste the text in and if there are two different double-quotes, type over each one manually.

    Better yet, I’ve uploaded a version of the php file that works for me; it’s in the Download section of this page.

    I apologize!

  35. Brian said,

    June 20, 2007 at 11:20 pm

    Well, it worked! :)

    I downloaded the 2nd of the 2 downloads, the one for blogger, and finally got it to appear on my page.

    In case anyone else is following this, it will NOT work with the normal “default” feed from blogger, but will work with the change of the feed to: http://BLOGNAME.blogspot.com/rss.xml

    The first time I loaded it, I got an error:

    Warning: strpos(): Offset not contained in string. in /home/content/v/i/s/visualblip/html/wp-content/plugins/photo_sb.php on line 160

    which ties back to the php file, but then when I refreshed, the error which was written across my page where the 3rd picture should be vanished.

    You’ze a genius!

    Brian

  36. Brian said,

    June 20, 2007 at 11:28 pm

    eeks, it came back, big time, and won’t go away. think it’s something to do with an error in their rss feed? or is there something missing in the php? I

    you’ze STILL a genius ;)

    Brian

  37. Brian said,

    June 20, 2007 at 11:46 pm

    Last time I clutter up your poor comments page, I swear. I did figure out what’s wrong. In the mix of photographs is an occasional blog entry saying “THEME OF THE WEEK IS” etc. The plugin is picking up that text entry and having a spaz attack.

    I don’t know if it’s possible in the code to say, basically, if there’s no png or jpg or gif, ignore posting and do not show and move to the next one.

    But when there’s text, it kicks line 160, apparently!

    Brian

  38. cellus said,

    June 21, 2007 at 10:58 pm

    Thanks Brian…I guess you now know what it’s like to beta test something the programmer was too lazy to fully test himself! :-)

    I did see those same errors occasionally and per your suggestion, I’ve limited the plugin to pick up on images only so as to avoid any issues on that line 160. I also found a few more weaknesses in the code which this type of feed exposed and which I’ll be able to fully improve upon in the next release.

    In the meantime, I’ve re-posted the improved code in the download section of this page.

    As far as the multiple comments, no worries! You’ve helped me quite a bit.

  39. Brian said,

    June 22, 2007 at 3:33 pm

    Thanks for the kind words and the good work.

    Another question popped up as I was playing around. If I tried to put two versions on my one site, even if I rename everything in the code to, let’s say, Photo_sbb, there’s a traffic jam everything shuts down.

    No way to add the same photo function two times on a web, one for one type feed one for another?

    Just had to ask,

    Brian

  40. cellus said,

    June 23, 2007 at 11:00 am

    There is a plugin that allows you to duplicate widgets if you’re using a version earlier than WordPress 2.2; it is available here.

    I played around a little with this concept before but didn’t get very far but since it seems to be a popular idea, I’ll take another look at it.

  41. Brian said,

    June 23, 2007 at 11:47 am

    Appreciate it. Downloaded and set it up. It does duplicate and make another widget called Photos Copy 1. Problem is, there is no way to access it to put in the information about what one would like the feed to be. So, it just lies there. I read and reread whatever I could find on it, was able to produce the dup in the pile of items to choose at the bottom of the page but, alas, it’s useless.

    Not a big thing. Appreciate the pointer, though, and I’m quite happy with just one if need be. Thanks again for all your work.

    Brian

  42. Laurent Cavalie said,

    June 23, 2007 at 2:34 pm

    Hi cellus,
    any news on the solution to the problem we mentioned earlier ?

    Thanks.

  43. cellus said,

    June 23, 2007 at 8:44 pm

    Laurent, I have just released a new version of the code that should allow you to use the Recent Galleries feed.

    This code actually cleans up some problems with earlier versions and also adds coverage for Gallery2 and Blogger feeds as well.

    Let me know if you’re still having problems.

  44. Laurent Cavalie said,

    June 24, 2007 at 1:35 pm

    I would say - we are almost there.
    It’s better but there are stil some problems.
    Based on my testing this is the result with the new version.
    With the recent photos and the popular photos feeds I get nothing (weird but I can leave with that), with the recent galleries feed I get 2 error messages (see below) and then I get the photo but not sized correctly.
    The messages are :
    Warning: getimagesize() [function.getimagesize]: URL file-access is disabled in the server configuration in /home/.red/lcavalie/laurentcavalie.com/wordpress/wp-content/plugins/photo_sb.php on line 225

    Warning: getimagesize(http://photo.mindworkscreation.com/photos/143306413-S.jpg) [function.getimagesize]: failed to open stream: no suitable wrapper could be found in /home/.red/lcavalie/laurentcavalie.com/wordpress/wp-content/plugins/photo_sb.php on line 225

    (laurentcavalie.com is the address of my blog, you can check it if you want)

    The pictures are there under the error messages but when it’s a vertical picture it’s displayed correctly, when it’s an horizontal one it’s not sized correctly only the left part of it is visible.
    So I think it’s better because the feed acquisition sounds ok now it’s just a matter of manipulating the picture correctly.
    if you want to test the feed I try to import is :
    http://photo.mindworkscreation.com/hack/feed.mg?Type=nickname&Data=lcavalie&format=rss200

    Thanks for your efforts to get this to work.
    Hope the testing will help.

    L

  45. cellus said,

    June 24, 2007 at 10:44 pm

    Hmm, it looks like my method for resizing isn’t going to work in your case. I’ll find another way to do it.

    I’m not really happy with using getimagesize() anyway (it is a slow function when using a URL). But because each of the feeds is using a different image size, the function needs a way to determine whether the image is horizontal or vertical. Any php programmers out there have any suggestions?

  46. cellus said,

    June 24, 2007 at 11:34 pm

    I’ve uploaded a new version which should handle not being able to access getimagesize() a little better…I don’t think it’s a perfect solution but it will show the entire image when you have landscape or portrait image files from a SmugMug Recent Gallery feed.

    I’m still lost as to why other feeds aren’t displaying anything–I’m seeing the same thing on my test blog but my “live” blog (as you can see) is working as expected. Unfortunately it’s probably going to be some time before I can get to the bottom of that issue.

  47. Laurent Cavalie said,

    June 26, 2007 at 11:11 am

    I tested it.
    it works, sort of :-)
    I no longer get an error message, I do get the pictures even if they are not sized as they should, the vertical ones are ok, but only half of the horizontal ones is visible.

    Thanks anyway

  48. Lovely D said,

    June 28, 2007 at 1:31 am

    Ok, I’m a little lost on configuring this for gallery 2.

    As far as I’ve gotten I add this code in the photo_sb file which is in the widgets folder

    elseif ($item["generator"]==”Gallery 2 RSS Module, version 1.1.0″) {
    //Image URL’s in Flickr feeds are buried; the feed is controlling how these are displayed
    //We just want the URL and not the formatting
    $item_url = $item["description"];
    $start_pos = strpos($item_url , ”

    But After What line exactly . . .???
    I have no idea where line 153 is or should be.

    thanks

  49. cellus said,

    June 28, 2007 at 6:15 pm

    Lovely D, I have actually included code for Gallery2 in the most recent version. If you have the latest version (which was last updated a few days ago) you don’t need to touch the code. Let me know if you’re having problems!

  50. cellus said,

    June 28, 2007 at 11:19 pm

    Laurent, I have a couple more suggestions to try to get your horizontal photos to display correctly.

    First, find the line that begins:
    $img_info = array(150,150);
    and change 150 to 151 in both locations.

    If that doesn’t work, go to line 7 lines below that which should say:
    $img_scale = '';
    and change the ''; to 'width = 150';

    I took a look at your site and it actually looked…not bad. I’m sure you’d prefer to see every photo completely. The above suggestions *should* accomplish that but they’ll still be scaled differently.

    I’m going to see if I can accomplish the scaling in a way that won’t generate the error message you saw…if it’s causing problems for you, it’s probably causing problems for other people as well. If another way exists, I’ll work that into the next release.

    Thanks for your feedback.

  51. Laurent Cavalie said,

    July 1, 2007 at 11:27 am

    Hi again,

    Back after some testing and I can say that it works this time.
    Tried the two modifications that you indicated and since I have a correct display of my photos.
    Thanks a lot for the troubleshooting.
    I have permanently installed the widget now and thanks to the fix my blog looks like what I wanted.
    Thanks again.

    L

  52. cellus said,

    July 1, 2007 at 9:24 pm

    Excellent! Glad things are working. I took a look and things look better! Thanks for the kind mention on your site!

  53. Michael said,

    July 18, 2007 at 11:05 am

    Hi Cellus,
    Wondering if I could ask for some advice. At my site, I have the plugin installed, but nothing appears, text or photos. I’ve put in new photos to test the feed (Smugmug, both recent photos and recent galleries), but I’ve never seen anything appear.

    http://www.ispithotfire.com/ (right hand side under “new photos”. I have WP 2.2.1 installed (pretty new to WP in general, over the last 3-4 weeks))

    This is the feed that is currently in now: http://ispithotsoleyman.smugmug.com/hack/feed.mg?Type=nickname&Data=ISpitHotSoleyman&format=rss200

    (I didn’t enter a comma after the feed and I hit delete to eliminate all empty space and return lines)

    What else can I try for troubleshooting (I am not a code warrior, unfortunately)

  54. Michael said,

    July 18, 2007 at 11:06 am

    I forgot to mention, I tried another theme with this earlier today, a 1 column, more basic theme, and images still did not show. I’m not sure if some themes don’t work with certain plugins…

  55. cellus said,

    July 18, 2007 at 10:43 pm

    Hi Michael,

    I was having the same problem you were with this feed, but it has since started working–perhaps a hiccup on smugmug’s side? I took another look at your site and it looks good. Depending on your host’s configuration, you may still need to implement some of the tweaks I suggested to Laurent (above). Let me know if you are still having problems!

  56. Michael said,

    July 19, 2007 at 8:07 am

    Hmm, could be. Yeah, I just looked at the site, and it looks fine now. Odd! But good. My friend said she would look at the plugin code, but I don’t think she did anything. I’ll check it out. : )

    Thanks!

  57. Michael said,

    July 19, 2007 at 11:59 am

    The Recent Galleries feed works (didn’t seem to work yesterday, but maybe I didn’t give it enough time), but the recent photos feed doesn’t. I know the actual feed is working though (see it in my RSS browser)

  58. cellus said,

    July 19, 2007 at 10:42 pm

    I’ve seen this before and it really mystifies me. For some reason, it seems that there are problems coming from (though perhaps not due to) WP’s rss code. I’ll try again to isolate the problem and see if there’s anything I can do.

    Thanks for your patience!

  59. Michael said,

    July 20, 2007 at 7:29 am

    Hey, no problem. I greatly appreciate any thing you can do to help me, I already appreciate it even if you can’t! :)

  60. kendrick said,

    July 25, 2007 at 11:56 am

    I’m wanting to tweak the RSS feeder so that it will accept PixelPost RSS feeds. How do i put your (great) plugin into giving me any feedback. All attempts to output var_dump() so far been unsucessful… any hints/idea? Thx

  61. cellus said,

    July 25, 2007 at 10:49 pm

    kendrick,

    It looks like your feed is very similar to some of the others, so I think you should be able to accomplish the same thing by copying (or cannibalizing) the code from Gallery2 or Flickr and changing the appropriate places (the “generator” name and the code to extract $item_url); the only worry is that the thumbnails will be scaled up to 150 pixels (although I imagine things would look fine if you disabled that in the code.)

    var_dump() is working fine for me but perhaps you can get what you need from print_r().

    Let me know if this puts you in the right direction…

  62. cellus said,

    August 9, 2007 at 8:27 am

    I’m homing in on the Smugmug Recent Photos issue (I think). It seems as if either Smugmug is sending incomplete header information or the WordPress code doesn’t parse it correctly. More to follow…

  63. Michael said,

    August 11, 2007 at 2:23 pm

    Ah, great!

  64. Michael said,

    September 12, 2007 at 2:33 pm

    Hi Cellus,
    How’s progress?

    Thanks!

  65. cellus said,

    September 13, 2007 at 11:19 pm

    Hey Michael,

    I was hoping to hear from a Smugmug guru and had kind of pinned my hope on that. But I haven’t heard anything, so it seems I need to look at some other knowledge-bases. I will keep you posted-thanks for making sure I don’t lose sight of this!

  66. cellus said,

    September 18, 2007 at 11:25 pm

    Alright, I’ve played around with this a little more.

    It looks like the feeds are working correctly now, so you should be able to use them without doing anything else but adding them to the list of feeds in the plugin controls.

    If things aren’t working, though, I’d like to try changing the line of code (around line 621) in rss.php

    return $sc >= 200 && $sc < 300;

    to

    return $sc >= 200 && $sc < 300 || $sc == 0;

    But again, it looks like the Recent Photos feed is working fine now.

  67. Michael said,

    September 26, 2007 at 10:31 am

    Thanks! I’m checking it out. Getting some odd results (rendering more than 1 photo per line), but will have to look into it more over the weekend.

  68. austin said,

    October 7, 2007 at 1:13 pm

    Hi There, Sort of Nubie to this plugin. Reading your article it sounds like the plugin I should use. I currently have Word Press 2.3 installed and I have added your plugin successfully. I have activated it within plugin area of wordpress and assigned it within the sidebar widget. I am able to place the RSS feeds in the settings but no photos will post. The link title appears, but no pics…. I no the rss feeds are valid, in addition I had the RSS validated in the syndications area to ensure there was not a problem with RSS url. Do you have any ideas on what maybe causing this trouble?? Would it be a simple change of code? Or is not compatible at all with 2.3. BTW… I looked in both compatible and non-compatble plugins for wordpress 2.3 and your plugin is not listed in either. However, I downloaded your plugin from the Word Press site. Just an FYI… Thanks for your time.

  69. cellus said,

    October 11, 2007 at 1:33 am

    Hey Austin,

    Your problem sounds like an intermittent problem that several other people have had with certain RSS feeds from Smugmug. Unfortunately, since it is intermittent, it is hard to pinpoint. Which feed are you using?

    I would guess it’s not a compatibility issue with 2.3 although (based on your tip) it appears I need to do something to make sure the compatibility is checked and noted.

    Apologies for the lag in response I should be able to delve into this a little more deeply early in the week next week; thanks for the tip!

  70. Dmitry said,

    October 26, 2007 at 2:14 pm

    Hi everyone. May be it is not relevant to this particular plug-in but it is in the scope: can anyone tell me why there is no simple plug-in for WP, that will simply display a random (or whatever) image in a sidebar from my local folder on the server. WHY??? This is probably the easiest of all, without any RSS/Flickers/smugmugs you name it - just an image from my folder in a sidebar. What is so difficult about it? Thank you!

  71. Dmitry said,

    October 26, 2007 at 2:17 pm

    Sorry clarification - of course there are plug-ins like that for different “Galleries”, but they are too heavy, and they only good for photo blogs really and most of them have a lot of bugs. I am talking about just an image from my folder without any need or dependency on other image plug-ins. frustrated :(

  72. cellus said,

    October 26, 2007 at 9:59 pm

    Dmitry,

    Have you come across George Howell’s “Random Banner” plugin? I used it for some time with an earlier theme to display a random “banner” image–it was very “light”–essentially just a piece of code that you could insert into your theme wherever you wanted. I still have it and it’s worked for me with WP 2.2.

    I agree, sometimes the simplest things get overlooked…

  73. RK Bentley said,

    October 28, 2007 at 9:36 pm

    Hiyas, first off, thank you for the plug in, I recently upgraded from 2.1 to 2.3.1 and found my pixel post plugin in got tossed to the curb so I’ve been looking for a widget to cover this and so far yours seems to be the one.

    Except, like everyone else, I’m getting the titles of the Pictures but no pictures. It may be because I haven’t upgrade to latest pixel post or the intermittent problem you mentioned everyone else is having.

    The odd thing is, I replaced the coding with two other photo blogs using Pixel Post and nothing came up.

    If it helps, my photo blog and my blog.

  74. cellus said,

    October 29, 2007 at 12:40 am

    Hi RK,

    I think you should be ok if you make the following simple change in the plugin code (the photo_sb.php file.)

    Find the line that looks like elseif ($item["generator"]==”Blogger”) {

    (it should be at line 199) and modify it to add pixelpost support (it should all be on one line, i.e., don’t add a hard return):

    $item["generator"]==”Blogger” or $item["generator"]==”pixelpost”) {

    Incidentally, since pixelpost’s RSS feed uses thumbnails that are smaller than 150 px, they are scaled up by the plugin. You can disable this in a similar fashion by editing line 229 to say:

    if ($item["generator"]==”http://www.smugmug.com/” && $img_width < = 150 or $item["generator"]=="pixelpost")

    Let me know how it works! I’ll try to get pixelpost support in the next version. I haven’t made image scaling for small images an option for simplicity’s sake, but I could if there is enough interest.

  75. RK Bentley said,

    October 30, 2007 at 1:07 pm

    Thaaaaaaank you Cellus! The first fix worked. I edited line 228 and it gave me errors:

    Parse error: syntax error, unexpected ‘=’ in /home/u5/robentley/html/blog/wp-content/plugins/photo_sb.php on line 229

    As for the thumbnails being fuzzy in pixel post you can change the size of the thumbnail size so that’s easily fixable on my end.

    Great to hear about the Pixel Post support in the future. More than a few us will be happy to hear this. :)

  76. cellus said,

    October 30, 2007 at 11:34 pm

    Great, glad it’s working!

    I like that Pixel Post gives you the ability to change thumbnail size, too–that makes things nice.

    If anyone needs to implement the code to turn resizing off from comment 74, remove the extra space (between the “<” and “=” ) that WP adds to the comment.

  77. Newbie said,

    November 2, 2007 at 4:36 am

    Hello all, Im new at this. I just wanted to know can I install this widget and just insert picture from my harddrive or web host. I just want to be able to have a widget that allows me to put .jpg or .gifs into my sidebar. Do I have to have smugmug to do that?

  78. cellus said,

    November 2, 2007 at 10:29 pm

    You don’t need Smugmug to do that. You might be able to use Flickr (which has a free version.) Flickr will also work with this plugin.

    But I don’t think you should have to use any of these if you’re really just looking at showing one particular image (or even one or several random images from a static collection). Since there seems to be some interest, I’ll see if I can’t come up with a simple widget to do that…

  79. Mark said,

    December 27, 2007 at 11:49 pm

    I thought I could do this on my own, but I’m not having much luck… is there a way to ensure the captions are truncated if they are longer than ‘x’ characters? I imagine it is really simple code, but….? :) Thank you again for a great plugin!

  80. cellus said,

    December 28, 2007 at 9:23 pm

    Hi Mark,

    I like this idea. Here is what I came up with: I would add the following lines after the if ($show_title) (on line 251). For clarity in this post, I added blank lines between code lines; you’ll have to correct the indentation as well.

    if (strlen($item[title]) > 50) {

    $truncate_pos = strpos($item[title],’ ‘,49); //find the first space after 50 characters

    if ($truncate_pos !== FALSE) //only truncate and add ellipsis if there is a space after 50 chars

    $item[title] = substr($item[title],0,$truncate_pos) . “…”; //cut off the end and add “…”

    }

    This implementation checks the caption length and cuts it off at the end of the next word. It also adds an ellipsis. I think you should be able to tweak it to suit your needs.
    Hope this helps!

  81. Mark said,

    December 29, 2007 at 9:30 am

    Perfect! (Well, almost.) I’m now getting the URL text of my two feeds at the top of the widget… (but the truncating works beautifully). Thoughts? (See the URL saved in the comment for my website.) Thanks, again!

    Code is as follows:
    ….
    //generate the appropriate code to show the photo
    echo ‘‘;
    echo “\n”;
    if ($show_title) {
    // begin code add (other than { in previous line)
    if (strlen($item[title]) > 50) {
    $truncate_pos = strpos($item[title],’ ‘,49);
    if ($truncate_pos !== FALSE)
    $item[title] = substr($item[title],0,$truncate_pos) . “…”;
    }
    echo ” . $item[title] . ”; //show the caption if requested
    }

  82. cellus said,

    December 29, 2007 at 3:46 pm

    Mark,

    It looks like the feed url’s have been copied into the widget title. Check your settings page to see if the Title field has been overwritten–with luck, it has and changing it back will solve your problem.

    I’m fairly confident that should work but If it doesn’t help, I would grab a fresh copy of the plugin, make sure it’s working as expected and then make the changes above again.

    By the way, your site is fantastic–I’m honored that this plugin is working well for you!

  83. Mark said,

    December 30, 2007 at 7:45 am

    Hah! That was it… it didn’t even occur to me it was something other than the new code. :) Thanks, again (as well as for the compliment). I do have two last questions, as long as I have your ear! [1] Do you know how easy it would be to allow more than one widget instance of the plugin? (e.g., with the text widget, you can choose to have ‘x’ number — and while I know I can add multiple feeds, I’d love to separate a few of them out with different titles). [2] Is it possible to only display the first ‘x’ images in a feed? (e.g., for the popular gallery feed, instead of choosing ‘x’ images at random, maybe just display the ‘x’ *most* popular). Thank you again!!

  84. cellus said,

    December 31, 2007 at 2:15 am

    Good, I’m glad it was a simple solution…you had me worried! :-)

    As for you other two questions…I have worked on the multiple-instance problem before and so far a clean solution (i.e., one that hasn’t required dealing with the database manually) has eluded me. Hopefully I can come up with something user-friendly in a future version.

    You can easily disable the random function by commenting out the usort command on line 130; then the widget will show the first x images. Or with a little more tweaking, that line could be used to sort based on other data from the feed, such as the date the photo was taken.

  85. Mark said,

    December 31, 2007 at 2:36 am

    Perfect! — I’ll work on setting the random piece to just display the ten most popular photos; as for multiple instances… if I just manually copied the widget two more times with different names, and enabled all three under WP Plugins, would that serve as a viable workaround?

  86. cellus said,

    December 31, 2007 at 4:13 pm

    It’s a little more difficult than that–the software will complain because even though the file has a different name, it’s still looking in the same place for settings. My temporary workaround is to rename the functions and variables in the new file to make them unique. It’s a little tedious but I found a version where I had done just that. I have uploaded it: photo_sb2.zip.

    To get, say, a third instance, you could make another copy of this file and replace the 2 with 3 on any function/variable names. For example widget_photo_sb2_init(), widget_photo_sb2, rand_compare2. Using the “find” command in my editor, I found 68 places where the 2 would be replaced with 3 (etc.).

    Naturally, any other changes you would make (disabling the random sort, etc.) would need to be done in each file.

  87. Mark said,

    January 1, 2008 at 6:20 am

    I can’t tell you how appreciative I am for all your help. I’ve got three feeds going, now, exactly as I’d hoped to do — one that displays the Top10 most popular, and then two separate feeds that display random color and black/white images from my professional galleries. Thank you!!

  88. cellus said,

    January 1, 2008 at 10:36 pm

    Great–it’s exciting to see the “multiple instances” in action, even if it’s not a pretty workaround. If nothing else, it’s good motivation to come up with a more eloquent solution. Thanks for the suggestions!

  89. cellus said,

    January 1, 2008 at 10:40 pm

    I have released version 1.22 of the plugin via the WordPress plugin repository. This version adds pixelpost support and truncated captions. This should be the last release of version 1.0; I’m now working in earnest on some of the more glamorous potential features that may justify a “major” version number such as caching and multiple instances.

  90. roary said,

    April 7, 2008 at 2:46 am

    I can’t get it to work it tells me theres an error on line 140

  91. cellus said,

    April 7, 2008 at 8:37 pm

    Roary,

    Could you post the error message you see?

RSS feed for comments on this post

Post a Comment