Ask your Symfony questions! Pay money and get answers fast! (more info)

Make the RSS feeds look pretty in Netvibes Symfony

  • SOLVED

Hey, everyone, I am overwhelmed with work this weekend so I am going to outsource 2 small projects to the excellent programmers of Symfony Experts.

This project is going to use [[LINK href="http://www.netvibes.com/"]]NetVibes[[/LINK]] as the reference RSS reader, so you will need to get a NetVibes account, if you do not already have one. It is free and takes about 30 seconds to sign up.

I would like to fix the RSS feeds. Check out the screen shot I have uploaded with this question. See how the content lacks line breaks? I need that fixed.

Also check out the RSS we output on [[LINK href="http://www.wpquestions.com/feed?sort=end_at"]]WP Questions[[/LINK]].

We are using the sfFeed2 plugin, though we could switch to another if someone suggests something good.

Here is the code I wrote when we created the site, I have not had the time to clean this up:

public function executeIndex(sfWebRequest $request)
{
$order = $request->getParameter('order');
$sort = $request->getParameter('sort');
if (!$sort) $sort = "end_at";
$c = new Criteria();
$sort = strtoupper($sort);
$c->add(QuestionsAndResponsesPeer::END_AT, date('Y-m-d H:i:s'), Criteria::GREATER_THAN);
$c->add(QuestionsAndResponsesPeer::STATUS, 'active');
if ($order == "desc") {
$c->addDescendingOrderByColumn("questions_and_responses.$sort");
} else {
$c->addAscendingOrderByColumn("questions_and_responses.$sort");
}
$c->setLimit(20);
$posts = QuestionsAndResponsesPeer::doSelect($c);

$title = "";
if (strtolower($sort) == 'end_at') $title = " Questions that end soon on ";
if (strtolower($sort) == 'responses') $title = " Questions with the most responses on ";
if (strtolower($sort) == 'created_at') $title = " Recent questions on ";
if (strtolower($sort) == 'prize_amount') $title = " Questions with the biggest prizes on ";

$siteUrl = "http://" . $request->getHost();
$sort = strtolower($sort);

$feed = new sfAtom1Feed();
$feed->setTitle($title . ' ' . sfConfig::get('app_subdomain_specific_info_nice_name_for_site'));
$feed->setLink($siteUrl.'/question/index?sort='.$sort.'&order='.$order);
$feed->setAuthorEmail(sfConfig::get('app_subdomain_specific_info_email'));
$feed->setAuthorName( sfConfig::get('app_subdomain_specific_info_nice_name_for_site') );

$feedImage = new sfFeedImage();
$feedImage->setFavicon($siteUrl . 'favicon.ico');

foreach ($posts as $post)
{
$item = new sfFeedItem();
$item->setTitle($post->getSubject());
$item->setLink($siteUrl.'/question/show/id/'.$post->getId());
$item->setAuthorName($post->getsfGuardUser()->getProfile()->getNiceName());
$item->setPubdate($post->getCreatedAt('U'));
$item->setUniqueId('/question/show/id/'.$post->getId());
$item->setCategories(array($post->getPrizeAmount()));
$description = $post->getDescription();
$description = str_replace(">", ">", $description);
$description = str_replace("&lt;", "<", $description);
$description = str_replace("<p>", "<br /> \n", $description);
$description = str_replace("[[LINK ", " ", $description);
$description = str_replace("[[/LINK]]", " ", $description);
$description = str_replace("&nbsp;", " ", $description);
$description = str_replace("&", " ", $description);
$item->setContent($description);
$item->setDescription($description);

$feed->addItem($item);
}

$this->feed = $feed;

}



Please note, if you can upload a screenshot of NetVibes, with the content looking good, I will be much more likely to give you money than if you do not upload such a screenshot.

Thanks to everyone.

Answers (1)

2010-05-17

Bill Hunt answers:

Hey lawrence, I think the main part will be cleaned up if you switch this order up:


$description = str_replace("&", " ", $description); // Rogue ampersands First
$description = str_replace("<p>", "<br /> \n", $description);
$description = str_replace(" // This line broke in your post - not sure what's supposed to go here?
$description = str_replace("", " ", $description);
$description = str_replace("&nbsp;", " ", $description);

// Tags *last*
$description = str_replace("&gt;", ">", $description);
$description = str_replace("&lt;", "<", $description);


Lawrence Krubner comments:

Do you have time to work on this Bill? I can give you access to our Subversion server.


Bill Hunt comments:

Sure thing. :)