<?xml version="1.0" encoding="UTF-8"?>
<Module>
  <ModulePrefs
	title="Flickr.com: __UP_title__"
	title_url="http://www.flickr.com"
	directory_title="Flickr.com Photo RSS 2.0 feeds"
	description="Show image miniatures from Flickr.com RSS 2.0 streams"
	author="Simone Avogadro"
	author_location="Como, Italy"
	author_affiliation="Wise-Lab s.r.l."
	author_email="simone.avogadro+flickrfeed@gmail.com"
        author_link="http://www.flickr.com/photos/honeyjar/"
	screenshot="http://farm3.static.flickr.com/2398/1937683532_110d0ac9b0.jpg?v=0"
        thumbnail="http://simone.avogadro.googlepages.com/FlickrFeedRSS2.0_thumb.png"
        height="230"
        width="400"
	 ><!-- default h=230 -->
   <Require feature="dynamic-height"/>
 </ModulePrefs>
    <!-- width will only be used for embedding -->
	<!-- unfortunately this will not work: height="__UP_vsize__" -->
	<!--
		old screenshot="http://base.google.com/base_image?q=hand3494390411526874306&amp;size=1"
	-->
  <UserPref name="feed" display_name="Flickr RSS 2.0 feed (copy here the link of the small 'latest' link at the end of the group/person photos)" required="true" default_value="http://api.flickr.com/services/feeds/photos_public.gne?id=85034886@N00&amp;lang=en-us&amp;format=rss_200"/>
  <UserPref name="title" display_name="Module Title" default_value="Simone's Pictures"/>
  <UserPref name="columns" display_name="Columns" default_value="5" datatype="enum" >
	<EnumValue value="2" />
	<EnumValue value="3" />
	<EnumValue value="4" />
	<EnumValue value="5" />
  </UserPref>
  <UserPref name="rows" display_name="Rows" default_value="2" datatype="enum" >
	<EnumValue value="1" />
	<EnumValue value="2" />
	<EnumValue value="3" />
	<EnumValue value="4" />
	<EnumValue value="5" />
  </UserPref>
	<!-- UserPref name="vsize" display_name="Module size" default_value="250" datatype="enum" required="true" >
		 <EnumValue value="250" />
		 <EnumValue value="350" />
		 <EnumValue value="450" />
	</UserPref -->
	<!--
		Problems and Improvements:
		- allow the user to select the vertical size: currently Google API doesn't seem to like: height="__UP_vsize__"
		- support the more conventional RSS 2.0 stream: there is an interaction problem between
				Google API Content Proxy and Flickr.com web services, as a result the following URL:
					http://www.flickr.com/services/feeds/photos_public.gne?tags=beach&format=rss_200
				when called from inside the content proxy will produce an ATOM feed instead of a RSS2.0 feed!
				P.S.: on the contrary the following will work:
					http://www.flickr.com/groups/fave20times/pool/feed/?format=rss_200
				I suspect the problem is due to the ampersend in the URL!
		- add some kind of help to guide beginner users in copy&paste of URLs
	-->

  
<Content type="html">
<![CDATA[ 
<style type="text/css">
 body {margin: 0px;}		
 .ima {
    max-width: 100%;
    max-height: 100%;
 }
</style>
<div id="outputd__MODULE_ID__">Loading...</div>
<script><!--
function loadRSS__MODULE_ID__ (prefs) {
  _IG_FetchContent(
    prefs.getString("feed"),
    function (responseText) {
	var output = _gel("outputd" + __MODULE_ID__);
	output.innerHTML = "Loading...()";
        var prefix = '<item>';
	var suffix = '</item>';
	var colSize = 100 / prefs.getString("columns");
	// var colSize = 20;
	var innerPrefix = '<link>';
	var innerSuffix = '</link>';
	var innerPrefix2 = '<media:thumbnail url="';
	var innerSuffix2 = '"';
								 
	var starting = responseText.indexOf('<rss version="2.0"');
	if (starting<0) {
	    output.innerHTML = "Sorry, this feed doesn't seem to be a Flickr.com RSS 2.0";
	    return;
	}
	var loading = true;

	output.innerHTML = "Loading....";
	text = responseText.substring(starting);	// skip header

	var start = text.indexOf(innerPrefix2);
        var maxcount = prefs.getString("columns")* prefs.getString("rows");
        var count = 1;
	while (start>0 && count<=maxcount) {
	    var urlWithTail = text.substring(start+innerPrefix2.length,text.length);
            var end2 = urlWithTail.indexOf(innerSuffix2);
	    var link = urlWithTail.substring(0,end2);
				   
	    start = text.indexOf(prefix);
	    if (start>0) {
		urlWithTail = text.substring(start+prefix.length,text.length);
		var end = urlWithTail.indexOf(suffix);
   		var urlOnly = urlWithTail.substr(0,end);
		var innerStart = urlOnly.indexOf(innerPrefix);
		if (innerStart > 0) {
		    urlOnly = urlOnly.substring(innerStart + innerPrefix.length);
		    var innerEnd = urlOnly.indexOf(innerSuffix);
		    urlOnly = urlOnly.substring(0,innerEnd);
		    if (loading) {
			loading = false;
			output.innerHTML =
	"<style type='text/css'>"+
	".block { "+
	"	width: "+colSize+"%; "+
	//"	height: 50%; "+
	"	float: left; "+
	"	vertical-align: middle; "+
	"	horizontal-align: middle; "+
	"	margin-left: auto; "+
	"	margin-right: auto; "+
	"	margin-bottom: 4px; "+
	"	text-align: center; "+
	"} </style>";
		    }
                    else{
		      output.innerHTML = 
                          output.innerHTML+
                            '<div class="block"><a target="_blank" href="'+urlOnly+'"><img class="ima" border="0" src="'+link+'"></a></div>';
                      count++;
                    }
		}
	    }
  	    text = urlWithTail;
	    start = text.indexOf(innerPrefix2);
	}
        _IG_AdjustIFrameHeight();
     });
}
loadRSS__MODULE_ID__ (new _IG_Prefs(__MODULE_ID__));
//--></script>
     ]]> 
</Content>
</Module>
