[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

Help with CFLOOP and Random RSS Feeds ColdFusion

Asked by ghmurphy in Web Servers, ColdFusion Application Server

I have a small ColdFusion widget which I am able to use to collect RSS feeds and display them randomly. Everything is working okay except for the discription.  I am getting the same desdription for each item with the same array key.  I am only getting the first one in the array.  It is not looping properly to give me the correct discription.  The title is correct but not the description.  I have attached the Application.cfm page and the widget utility.cfm.
You can see what is coming back by looking at http://newsite.websbygeorge.com/utility.cfm
You can see a dump of the ARRAY APPLICATION.RSSFeed by looking at
http://newsite.websbygeorge.com/test.cfm
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
<!---This sits in my Application.cfm file --->
<cfparam name="APPLICATION.TimeStamp" default="">
 <CFIF (APPLICATION.TimeStamp EQ "") OR (DateDiff("n", APPLICATION.TimeStamp, TimeFormat(NOW(), "hh:mm:s")) GT 10) AND NOT IsDefined('URL.INIT')> 
       <CFSET APPLICATION.TimeStamp = CreateTime(TimeFormat(NOW(), "hh"), TimeFormat(NOW(), "mm"), TimeFormat(NOW(), "s"))> 
       <CFSET APPLICATION.RSSFeed = ArrayNew(1)>
       <CFHTTP METHOD="GET" URL="http://pipes.yahoo.com/pipes/pipe.run?_id=tHshp1Ed3RGr3uC9JphxuA&_render=rss" />
       <CFSET APPLICATION.RSSFeed[1] = CFHTTP.FileContent>
       <CFHTTP METHOD="GET" URL="http://pipes.yahoo.com/pipes/pipe.run?_id=itFf9VId3RGmcBsNzKky6g&_render=rss" />
       <CFSET APPLICATION.RSSFeed[2] = CFHTTP.FileContent>
	   <CFHTTP METHOD="GET" URL="http://pipes.yahoo.com/pipes/pipe.run?_id=lD1mhGAd3RGLYXkgMlrX_Q&_render=rss" />
       <CFSET APPLICATION.RSSFeed[3] = CFHTTP.FileContent>
	   <CFSET APPLICATION.ParsedRSS = ArrayNew(1)>
       <CFSET Temp = APPLICATION.RSSFeed[1]>
       <CFSET APPLICATION.ParsedRSS[1] = "#XMLParse(Temp)#">
       <CFSET Temp = APPLICATION.RSSFeed[2]>
       <CFSET APPLICATION.ParsedRSS[2] = "#XMLParse(Temp)#">
	   <CFSET Temp = APPLICATION.RSSFeed[3]>
       <CFSET APPLICATION.ParsedRSS[3] = "#XMLParse(Temp)#">
    </CFIF> 
<!--- This is my Utility.cfm widget --->
<cfsetting enablecfoutputonly="yes">
<cfscript>
/**
 * Displays n number of characters from a string without cutting off in the middle of a word
 * Code used from FullLeft
 * 
 * @param string 	 String to be modified. (Required)
 * @param number 	 Number of characters to include in teaser. (Required)
 * @param urlArgument 	 URL to use for 'more' link. (Optional)
 * @return Returns a string. 
 * @author Bryan LaPlante (blaplante@netwebapps.com) 
 * @version 3, July 31, 2003 
 */
function FormatTeaser(string,number){
	var urlArgument = "";
	var shortString = "";
	
	//return quickly if string is short or no spaces at all
	if(len(string) lte number or not refind("[[:space:]]",string)) return string;
	
	if(arrayLen(arguments) gt 2) urlArgument = "... <a target=""_blank"" href=""" & arguments[3] & """>[more]</a>";
 
	//Full Left code (http://www.cflib.org/udf.cfm?ID=329)
	if(reFind("[[:space:]]",mid(string,number+1,1))) {
	  	shortString = left(string,number);
	} else { 
		if(number-refind("[[:space:]]", reverse(mid(string,1,number)))) shortString = Left(string, (number-refind("[[:space:]]", reverse(mid(string,1,number))))); 
		else shortString = left(str,1);
	}
	
	return shortString & urlArgument;
 
}
</cfscript>
<!--- I loop over the Application Array and populate the local Array --->
<cfloop index="i" from="1" to="#ArrayLen(APPLICATION.RSSFeed)#">
<cfset VARIABLES.LocalRSS[i] = XMLParse(APPLICATION.RSSFeed[i])>
</cfloop>
<cfset RandomList = "">
<cfoutput>
<cfloop from="1" to="10" index="r">
<cfset VARIABLES.LoopControl = 0>
<cfloop condition="VARIABLES.LoopControl EQ 0">
  <cfset RandomFeed = RandRange(1,3)>
  <cfset RandomPick = RandRange(1, Arraylen(VARIABLES.LocalRSS[RandomFeed].rss.channel.item))>
  <cfif NOT ListFind(VARIABLES.RandomList, RandomPick)>
    <cfset VARIABLES.RandomList = ListAppend(VARIABLES.RandomList, RandomPick)>
    <cfset VARIABLES.LoopControl = 1>
  </cfif>
<!--- Moved CF Loop to line 55 --->
<dl><br />
<dt class="rsstitle"><A HREF="#APPLICATION.ParsedRSS[RandomFeed].rss.channel.item[RandomPick].link.xmltext#" TARGET="_BLANK"> #APPLICATION.ParsedRSS[RandomFeed].rss.channel.item[RandomPick].title.xmltext#</A></dt>
    <dd class="rsssubtitle">#FormatTeaser(APPLICATION.ParsedRSS[RandomFeed].rss.channel.item.description.xmltext,75,APPLICATION.ParsedRSS[RandomFeed].rss.channel.item[RandomPick].link.xmltext)#</dd>
 </dl>
 </cfloop>
</cfloop>
</cfoutput>
<cfsetting enablecfoutputonly="no" />
[+][-]07/16/08 05:29 PM, ID: 22021432Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/12/09 07:11 AM, ID: 23353782Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81 / EE_QW_2_20070628