Limiting the numer of items in eBay rss feed

Discussion in 'Commission Junction' started by dcristo, Sep 15, 2006.

  1. #1
    If someone knows how to do this, please let me know. Most feeds generated are too large to be practical to work with, so am trying to find a solution.
     
    dcristo, Sep 15, 2006 IP
  2. Blasingame

    Blasingame Peon

    Messages:
    761
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Ok lets clear this up amd maybe i can help you...

    Are you trying to limit the amout of feeds shown in your ebay affiliate feed?

    Are you displaying the feed on your own site?

    If so how are you displaying this feed? Are you using a javascript or php or what?
     
    Blasingame, Sep 16, 2006 IP
  3. dcristo

    dcristo Illustrious Member

    Messages:
    19,776
    Likes Received:
    1,200
    Best Answers:
    7
    Trophy Points:
    470
    Articles:
    7
    #3
    Hey Dude, What I am trying to achieve is limiting the number of eBay listings displayed in each eBay rss feed I generate. Most feeds I am generating are very long.
     
    dcristo, Sep 16, 2006 IP
  4. Blasingame

    Blasingame Peon

    Messages:
    761
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    The only thing you can control is if you were posting them to your site however if you trying to send them through a reader you can also limit them.

    If your posting them to your site for display they can be easy to control.

    So, let me know where your trying to limit them. On your site display on your reader?

    I guess I'm just not undersdanding were you would like to limit them.

    Also, you do know your RSS Ebay feed is no more them custom search.
     
    Blasingame, Sep 16, 2006 IP
  5. dcristo

    dcristo Illustrious Member

    Messages:
    19,776
    Likes Received:
    1,200
    Best Answers:
    7
    Trophy Points:
    470
    Articles:
    7
    #5
    Sorry I should have explained things better, I am displayng the feeds on my site using php code.
     
    dcristo, Sep 16, 2006 IP
  6. Blasingame

    Blasingame Peon

    Messages:
    761
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    So what code are you using?
     
    Blasingame, Sep 16, 2006 IP
  7. dcristo

    dcristo Illustrious Member

    Messages:
    19,776
    Likes Received:
    1,200
    Best Answers:
    7
    Trophy Points:
    470
    Articles:
    7
    #7
    
    <?php
    
    /*
    Created by Global Syndication's RSS Parser
    http://www.globalsyndication.com/rss-parser
    */
    
    set_time_limit(0);
    
    $file = "http://rss-feed-url.com";
    
    $rss_channel = array();
    $currently_writing = "";
    $main = "";
    $item_counter = 0;
    
    function startElement($parser, $name, $attrs) {
       	global $rss_channel, $currently_writing, $main;
       	switch($name) {
       		case "RSS":
       		case "RDF:RDF":
       		case "ITEMS":
       			$currently_writing = "";
       			break;
       		case "CHANNEL":
       			$main = "CHANNEL";
       			break;
       		case "IMAGE":
       			$main = "IMAGE";
       			$rss_channel["IMAGE"] = array();
       			break;
       		case "ITEM":
       			$main = "ITEMS";
       			break;
       		default:
       			$currently_writing = $name;
       			break;
       	}
    }
    
    function endElement($parser, $name) {
       	global $rss_channel, $currently_writing, $item_counter;
       	$currently_writing = "";
       	if ($name == "ITEM") {
       		$item_counter++;
       	}
    }
    
    function characterData($parser, $data) {
    	global $rss_channel, $currently_writing, $main, $item_counter;
    	if ($currently_writing != "") {
    		switch($main) {
    			case "CHANNEL":
    				if (isset($rss_channel[$currently_writing])) {
    					$rss_channel[$currently_writing] .= $data;
    				} else {
    					$rss_channel[$currently_writing] = $data;
    				}
    				break;
    			case "IMAGE":
    				if (isset($rss_channel[$main][$currently_writing])) {
    					$rss_channel[$main][$currently_writing] .= $data;
    				} else {
    					$rss_channel[$main][$currently_writing] = $data;
    				}
    				break;
    			case "ITEMS":
    				if (isset($rss_channel[$main][$item_counter][$currently_writing])) {
    					$rss_channel[$main][$item_counter][$currently_writing] .= $data;
    				} else {
    					$rss_channel[$main][$item_counter][$currently_writing] = $data;
    				}
    				break;
    		}
    	}
    }
    
    $xml_parser = xml_parser_create();
    xml_set_element_handler($xml_parser, "startElement", "endElement");
    xml_set_character_data_handler($xml_parser, "characterData");
    if (!($fp = fopen($file, "r"))) {
    	die("could not open XML input");
    }
    
    while ($data = fread($fp, 4096)) {
    	if (!xml_parse($xml_parser, $data, feof($fp))) {
    		die(sprintf("XML error: %s at line %d",
    					xml_error_string(xml_get_error_code($xml_parser)),
    					xml_get_current_line_number($xml_parser)));
    	}
    }
    xml_parser_free($xml_parser);
    
    // output HTML
    // print ("<div class=\"channelname\">" . $rss_channel["TITLE"] . "</div>"); 
    
    if (isset($rss_channel["ITEMS"])) {
    	if (count($rss_channel["ITEMS"]) > 0) {
    		for($i = 0;$i < count($rss_channel["ITEMS"]);$i++) {
    			if (isset($rss_channel["ITEMS"][$i]["LINK"])) {
    			print ("\n<div class=\"itemtitle\"><a target='new' rel='nofollow' href=\"" . "" . $rss_channel["ITEMS"][$i]["LINK"] . "\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</a></div>");
    			} else {
    			print ("\n<div class=\"itemtitle\">" . $rss_channel["ITEMS"][$i]["TITLE"] . "</div>");
    			}
    			 print ("<div class=\"itemdescription\">" . $rss_channel["ITEMS"][$i]["DESCRIPTION"] . "</div><br />"); 		}
    	} else {
    		print ("<b>There are no articles in this feed.</b>");
    	}
    }
    
    ?>
    
    Code (markup):
     
    dcristo, Sep 16, 2006 IP
  8. Blasingame

    Blasingame Peon

    Messages:
    761
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Ok lets try this... change all of the red areas to fit your needsand you should be fine. Let me know if it works... Also when you finish I have a question for you about your existing feeds. Do you have your own feeds for your site?

    <?php
    // ( Generates HTML from a RSS feeds )
    //
    // Licensed Under the Gnu Public License
    //

    // Here are the feeds - you can add to them or change them
    $RSSFEEDS = array(
    0 => "http://yourdomain.com/myrss.xml",

    );


    //
    // Makes a pretty HTML page bit from the title,
    // description and link
    //
    function FormatRow($title, $description, $link) {
    return <<<HTML

    <!-- RSS FEED ENTRY -->
    <p class="feed_title"></p>
    <p class="feed_description">$description</p>
    <a class="feed_link" href="$link" rel="nofollow" target="_blank">Read more...</a>
    <hr size=1>
    <!-- END OF RSS FEED ENTRY -->

    HTML;
    }

    // we'll buffer the output
    ob_start();

    // Now we make sure that we have a feed selected to work with
    if (!isset($feedid)) $feedid = 0;
    $rss_url = $RSSFEEDS[$feedid];

    // Server friendly page cache set every 10 min
    $ttl = 60*10;// 60 secs/min for 60 minutes = 1 hour(360 secs) $cachefilename = md5($rss_url);
    if (file_exists($cachefilename) && (time() - $ttl < filemtime($cachefilename))) {
    // We recently did the work, so we'll save bandwidth by not doing it again
    include($cachefilename);
    exit();
    }

    // Now we read the feed
    $rss_feed = file_get_contents($rss_url);

    // Now we replace a few things that may cause problems later
    $rss_feed = str_replace("<![CDATA[", "", $rss_feed);
    $rss_feed = str_replace("]]>", "", $rss_feed);
    $rss_feed = str_replace("\n", "", $rss_feed);

    // If there is an image node remove it, we aren't going to use
    // it anyway and it often contains a <title> and <link>
    // that we don't want to match on later.
    $rss_feed = preg_replace('#<image>(.*?)</image>#', '', $rss_feed, 1 );

    // Now we get the nodes that we're interested in
    preg_match_all('#<title>(.*?)</title>#', $rss_feed, $title, PREG_SET_ORDER);
    preg_match_all('#<link>(.*?)</link>#', $rss_feed, $link, PREG_SET_ORDER);
    preg_match_all('#<description>(.*?)</description>#', $rss_feed, $description, PREG_SET_ORDER);

    //
    // Now that the RSS/XML is parsed.. Lets Make HTML !
    //

    // If there is not at least one title, then the feed was empty
    // it happens sometimes, so lets be prepared and do something
    // reasonable
    if(count($title) <= 1)
    {
    echo "No news at present, please check back later.<br><br>";
    }
    else
    {
    // OK Here we go, this is the fun part

    // Well do up the top 50 entries from the feed
    for ($counter = 1; $counter <= 50; $counter++ )
    {
    // We do a reality check to make sure there is something we can show
    if(!empty($title[$counter][1]))
    {
    // Then we'll make a good faith effort to make the title
    // valid HTML
    $title[$counter][1] = str_replace("&", "&", $title[$counter][1]);
    $title[$counter][1] = str_replace("&apos;", "'", $title[$counter][1]);

    // The description often has encoded HTML entities in it, and
    // we probably don't want these, so we'll decode them
    $description[$counter][1] = html_entity_decode( $description[$counter][1]);

    // Now we make a pretty page bit from the data we retrieved from
    // the RSS feed. Remember the function FormatRow from the
    // beginning of the program ? Here we put it to use.
    $row = FormatRow($title[$counter][1],$description[$counter][1],$link[$counter][1]);

    // And now we'll output the new page bit!
    echo $row;
    }
    }
    }

    // Finally we'll save a copy of the pretty HTML we just created
    // so that we can skip most of the work next time
    $fp = fopen($cachefilename, 'w');
    fwrite($fp, ob_get_contents());
    fclose($fp);

    // All Finished!
    ob_end_flush(); // Send the output to the browser

    ?>
     
    Blasingame, Sep 16, 2006 IP
  9. dcristo

    dcristo Illustrious Member

    Messages:
    19,776
    Likes Received:
    1,200
    Best Answers:
    7
    Trophy Points:
    470
    Articles:
    7
    #9
    I appreciate the help dude. That code seemed to limit the eBay listings in the feed, but I get this at the end of it:

    
    Warning: fwrite(): supplied argument is not a valid stream resource in /home/account/public_html/modules/content.module(14) : eval()'d code on line 109
    
    Warning: fclose(): supplied argument is not a valid stream resource in /home/account/public_html/modules/content.module(14) : eval()'d code on line 110
    
    Code (markup):
     
    dcristo, Sep 16, 2006 IP
  10. Blasingame

    Blasingame Peon

    Messages:
    761
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Your url is not completely valid... Try on you know that works. You knnow not one that you have generated. Find a news feed from another page and try to phase it and see if its ok.

    Or wait ... are you using aJoomla or a CMS ? It looks like you va e pointed this script to a mod?
     
    Blasingame, Sep 16, 2006 IP
  11. dcristo

    dcristo Illustrious Member

    Messages:
    19,776
    Likes Received:
    1,200
    Best Answers:
    7
    Trophy Points:
    470
    Articles:
    7
    #11
    The same feed works fine with the other RSS parser code I was using (just doesn't limit it)

    Yeah the feed is being parsed on a CMS page.
     
    dcristo, Sep 16, 2006 IP