#1  
Old 27th May 2008, 20:47
melat0nin melat0nin is offline
Junior Member
 
Join Date: May 2008
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default Facebook RSS truncate item?

Hi all

I've successfully implemented the Facebook RSS application, and limited the number of feed items to 8. However, I'd like to limit the amount of each item that shows, as per the Magpie tutorial here: http://www.howtoforge.com/rss_syndication_magpieRSS

This is the code they suggest:

Code:
if (strlen($desc) >= 100)
{
        $desc = substr($desc,0,99)."...";
}
I don't see where this can go in the rss.php code from the HOWTO.

Any thoughts?
Reply With Quote
Sponsored Links
  #2  
Old 28th May 2008, 16:43
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,722 Times in 2,563 Posts
Default

Try this:

Code:
<?php
define('MAGPIE_CACHE_DIR', './magpie_cache');
define('MAGPIE_CACHE_ON', 1);
define('MAGPIE_CACHE_AGE', 600);

require_once('appinclude.php');

require_once('rss/rss_fetch.inc');
$rss = @fetch_rss('http://www.howtoforge.com/node/feed');

$fbml = '<div style="margin:0 10px 0 10px;">';
$fbml .= '<table border="0" width="100%" style="margin: 5px 5px 5px 5px;"><tr><td valign="top" width="80%"><a href="'.$rss->channel['link'].'" style="font-weight: bold;">'.$rss->channel['title'].'</a></td><td valign="top" width="80%"><fb:share-button class="meta">
  <meta name="medium" content="blog"/>
  <meta name="title" content="'.htmlspecialchars(strip_tags($rss->channel['title'])).'"/>
  <meta name="description" content="'.htmlspecialchars(strip_tags($rss->channel['description'])).'"/>
  <link rel="target_url" href="'.$rss->channel['link'].'"/>
</fb:share-button></td></tr></table>';


foreach ($rss->items as $item) {
        $fbml .= '<div style="border-bottom: 2px solid #CCCCCC; padding-bottom:5px;"><br><div style="border-bottom: 1px dotted #CCCCCC; border-top: 1px dotted #CCCCCC;"><table border="0" width="100%" style="margin: 5px 5px 5px 5px;"><tr><td valign="top" width="80%"><a href="'.$item['link'].'" style="font-weight: bold;">'.$item['title'].'</a></td><td valign="top" width="80%"><fb:share-button class="meta">
  <meta name="medium" content="blog" />
  <meta name="title" content="'.htmlspecialchars(strip_tags($item['title'])).'" />
  <meta name="description" content="'.htmlspecialchars(strip_tags(substr($item['description'],0,99))).'" />
  <link rel="target_url" href="'.$item['link'].'" />
</fb:share-button></td></tr></table></div>';
        if($item['description']) $fbml .= $item['description'];
        $fbml .= '</div>';
}
$fbml .= '</div>';

$facebook->api_client->profile_setFBML($fbml, $user);
echo $fbml;
?>
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
The Following User Says Thank You to falko For This Useful Post:
melat0nin (28th May 2008)
  #3  
Old 28th May 2008, 17:04
melat0nin melat0nin is offline
Junior Member
 
Join Date: May 2008
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by falko View Post
Try this:

Code:
<?php
define('MAGPIE_CACHE_DIR', './magpie_cache');
define('MAGPIE_CACHE_ON', 1);
define('MAGPIE_CACHE_AGE', 600);

require_once('appinclude.php');

require_once('rss/rss_fetch.inc');
$rss = @fetch_rss('http://www.howtoforge.com/node/feed');

$fbml = '<div style="margin:0 10px 0 10px;">';
$fbml .= '<table border="0" width="100%" style="margin: 5px 5px 5px 5px;"><tr><td valign="top" width="80%"><a href="'.$rss->channel['link'].'" style="font-weight: bold;">'.$rss->channel['title'].'</a></td><td valign="top" width="80%"><fb:share-button class="meta">
  <meta name="medium" content="blog"/>
  <meta name="title" content="'.htmlspecialchars(strip_tags($rss->channel['title'])).'"/>
  <meta name="description" content="'.htmlspecialchars(strip_tags($rss->channel['description'])).'"/>
  <link rel="target_url" href="'.$rss->channel['link'].'"/>
</fb:share-button></td></tr></table>';


foreach ($rss->items as $item) {
        $fbml .= '<div style="border-bottom: 2px solid #CCCCCC; padding-bottom:5px;"><br><div style="border-bottom: 1px dotted #CCCCCC; border-top: 1px dotted #CCCCCC;"><table border="0" width="100%" style="margin: 5px 5px 5px 5px;"><tr><td valign="top" width="80%"><a href="'.$item['link'].'" style="font-weight: bold;">'.$item['title'].'</a></td><td valign="top" width="80%"><fb:share-button class="meta">
  <meta name="medium" content="blog" />
  <meta name="title" content="'.htmlspecialchars(strip_tags($item['title'])).'" />
  <meta name="description" content="'.htmlspecialchars(strip_tags(substr($item['description'],0,99))).'" />
  <link rel="target_url" href="'.$item['link'].'" />
</fb:share-button></td></tr></table></div>';
        if($item['description']) $fbml .= $item['description'];
        $fbml .= '</div>';
}
$fbml .= '</div>';

$facebook->api_client->profile_setFBML($fbml, $user);
echo $fbml;
?>
Thanks falko, that works, although the extra code has to be put here as well:

Code:
<?php
define('MAGPIE_CACHE_DIR', './magpie_cache');
define('MAGPIE_CACHE_ON', 1);
define('MAGPIE_CACHE_AGE', 600);

require_once('appinclude.php');

require_once('rss/rss_fetch.inc');
$rss = @fetch_rss('http://www.howtoforge.com/node/feed');

$fbml = '<div style="margin:0 10px 0 10px;">';
$fbml .= '<table border="0" width="100%" style="margin: 5px 5px 5px 5px;"><tr><td valign="top" width="80%"><a href="'.$rss->channel['link'].'" style="font-weight: bold;">'.$rss->channel['title'].'</a></td><td valign="top" width="80%"><fb:share-button class="meta">
  <meta name="medium" content="blog"/>
  <meta name="title" content="'.htmlspecialchars(strip_tags($rss->channel['title'])).'"/>
  <meta name="description" content="'.htmlspecialchars(strip_tags($rss->channel['description'])).'"/>
  <link rel="target_url" href="'.$rss->channel['link'].'"/>
</fb:share-button></td></tr></table>';


foreach ($rss->items as $item) {
        $fbml .= '<div style="border-bottom: 2px solid #CCCCCC; padding-bottom:5px;"><br><div style="border-bottom: 1px dotted #CCCCCC; border-top: 1px dotted #CCCCCC;"><table border="0" width="100%" style="margin: 5px 5px 5px 5px;"><tr><td valign="top" width="80%"><a href="'.$item['link'].'" style="font-weight: bold;">'.$item['title'].'</a></td><td valign="top" width="80%"><fb:share-button class="meta">
  <meta name="medium" content="blog" />
  <meta name="title" content="'.htmlspecialchars(strip_tags($item['title'])).'" />
  <meta name="description" content="'.htmlspecialchars(strip_tags(substr($item['description'],0,99))).'" />
  <link rel="target_url" href="'.$item['link'].'" />
</fb:share-button></td></tr></table></div>';
        if($item['description']) $fbml .= substr($item['description'],0,99);
        $fbml .= '</div>';
}
$fbml .= '</div>';

$facebook->api_client->profile_setFBML($fbml, $user);
echo $fbml;
?>
Thanks again
Reply With Quote
  #4  
Old 29th May 2008, 09:53
melat0nin melat0nin is offline
Junior Member
 
Join Date: May 2008
Posts: 9
Thanks: 2
Thanked 0 Times in 0 Posts
Default

I've got a problem with the script. When there are no items in my RSS feed I see the following error on my facebook application page/profile:

Code:
Warning: array_slice() [function.array-slice]: The first argument should be an array in /data/www/domain.co.uk/www/fb/rss.php on line 20

Warning: Invalid argument supplied for foreach() in /data/www/domain.co.uk/www/fb/rss.php on line 22
Presumably it's because the array is empty. My php skills don't stretch to working out what to do though
Reply With Quote
  #5  
Old 29th May 2008, 18:28
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,722 Times in 2,563 Posts
 
Default

Try this:
Code:
if(is_array($rss->items) && !empty($rss->items)){
foreach ($rss->items as $item) {
        $fbml .= '<div style="border-bottom: 2px solid #CCCCCC; padding-bottom:5px;"><br><div style="border-bottom: 1px dotted #CCCCCC; border-top: 1px dotted #CCCCCC;"><table border="0" width="100%" style="margin: 5px 5px 5px 5px;"><tr><td valign="top" width="80%"><a href="'.$item['link'].'" style="font-weight: bold;">'.$item['title'].'</a></td><td valign="top" width="80%"><fb:share-button class="meta">
  <meta name="medium" content="blog" />
  <meta name="title" content="'.htmlspecialchars(strip_tags($item['title'])).'" />
  <meta name="description" content="'.htmlspecialchars(strip_tags(substr($item['description'],0,99))).'" />
  <link rel="target_url" href="'.$item['link'].'" />
</fb:share-button></td></tr></table></div>';
        if($item['description']) $fbml .= substr($item['description'],0,99);
        $fbml .= '</div>';
}
}
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Facebook RSS feed app invite page deprecated godrox HOWTO-Related Questions 16 29th January 2010 07:37
RSS = Profile Update xrum HOWTO-Related Questions 3 12th January 2008 17:30
Facebook RSS reader app - error!? parakeet HOWTO-Related Questions 1 12th December 2007 12:05
Facebook Rss dwilight HOWTO-Related Questions 1 9th November 2007 18:27
Facebook RSS PubDate raw HOWTO-Related Questions 1 30th October 2007 17:53


All times are GMT +2. The time now is 04:10.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.