Tronquer les descriptions du flux rss de Freeglobes

WRInaute discret
Salut,

Qui pourrait me dire comment tronquer les descriptions du flux rss proposé par défaut dans Freeglobes ?
En effet, les longues descriptions y sont reprises intégralement et ça me pose des problèmes...

J'imagine que ça se passe soit dans rss.php :

Code:
<?php

/*
*	Displays RSS feed of the website
*/

include (dirname(__FILE__).'/init.php');
// RSS generator PHP class
include (SCRIPT_ROOT_PATH.'/class/class.rss_generator.php');

$lm =& get_manager('link');

$criteria = new Criteria("state",4,'=');
$criteria->setOrder('DESC');
$criteria->setSort('id');
$criteria->setLimit(1000);

$cols = array('id','name','url','description','image','date');
$sites = $lm->getObjects($criteria,$cols);

$rss = new rssGenerator_channel();
$rss_channel->docs = 'http://blogs.law.harvard.edu/tech/rss' ;
$rss_channel->pubDate = date('r') ;
$rss_channel->lastBuildDate = date('r') ;
$rss_channel->ttl = 120 ;
$rss_channel->title = utf8_encode($CONFIG['site_name']);
$rss_channel->link = $CONFIG['site_url'];
$rss_channel->description = utf8_encode($CONFIG['site_name']);
$rss_channel->language = 'fr-fr';
$rss_channel->generator = 'FreeGlobes';
$rss_channel->managingEditor = $CONFIG['site_mail'];
$rss_channel->webMaster = $CONFIG['site_mail'];

if (count($sites) != 0)
{
	$re =& MyRewriteEngine::getInstance();
	foreach($sites as $site)
	{
		$item = new rssGenerator_item();
		$item->pubDate = date('r',strtotime($site->getVar('date'))) ;
		$item->title = '<![CDATA[ '.utf8_encode($site->getVar('name')).' ]]>';
		$item->description = '<![CDATA[ '.utf8_encode($site->getVar('description')).' ]]>';
		$item->link = $CONFIG['site_url'].'/'.$re->buildUrl('single',array('id' => $site->getVar('id'), 'name' => $site->getVar('name')));
		
		$image = $site->getVar('image');
		if(!empty($image) && $image != 'http://')
		{
			$filesize = 0;
			$item->enclosure_url = $image;
			$item->enclosure_length = $filesize;
		}
	
		$rss_channel->items[] = $item;
		unset($item);
	}
}

$rss_feed = new rssGenerator_rss();
$rss_feed->encoding = 'UTF-8';
$rss_feed->version = '2.0';

header('Content-Type: text/xml');
echo $rss_feed->createFeed($rss_channel);

include(dirname(__FILE__).'/disconnect.php');
?>

Soit dans class.rss_generator.php :

Code:
<?php



/*

  RSS Feed Generator for PHP 4 or higher version

  Written by Vagharshak Tozalakyan <vagh@armdex.com>

  License: GNU Public License



  Classes in package:

    class rssGenerator_rss

    class rssGenerator_channel

    class rssGenerator_image

    class rssGenerator_textInput

    class rssGenerator_item



  For additional information please reffer the documentation

*/



class rssGenerator_rss

{



  var $rss_version = '2.0';

  var $encoding = '';



  function createFeed($channel)

  {

    $rss = '<?xml version="1.0"';

    if (!empty($this->encoding))

    {

      $rss .= ' encoding="' . $this->encoding . '"';

    }

    $rss .= '?>' . "\n";

    $rss .= '<!-- Generated on ' . date('r') . ' -->' . "\n";

    $rss .= '<rss version="' . $this->rss_version . '">' . "\n";

    $rss .= '  <channel>' . "\n";

    $rss .= '    <title>' . $channel->title . '</title>' . "\n";

    $rss .= '    <link>' . $channel->link . '</link>' . "\n";

    $rss .= '    <description>' . $channel->description . '</description>' . "\n";

    if (!empty($channel->language))

    {

      $rss .= '    <language>' . $channel->language . '</language>' . "\n";

    }

    if (!empty($channel->copyright))

    {

      $rss .= '    <copyright>' . $channel->copyright . '</copyright>' . "\n";

    }

    if (!empty($channel->managingEditor))

    {

      $rss .= '    <managingEditor>' . $channel->managingEditor . '</managingEditor>' . "\n";

    }

    if (!empty($channel->webMaster))

    {

      $rss .= '    <webMaster>' . $channel->webMaster . '</webMaster>' . "\n";

    }

    if (!empty($channel->pubDate))

    {

      $rss .= '    <pubDate>' . $channel->pubDate . '</pubDate>' . "\n";

    }

    if (!empty($channel->lastBuildDate))

    {

      $rss .= '    <lastBuildDate>' . $channel->lastBuildDate . '</lastBuildDate>' . "\n";

    }

	if (!empty($channel->categories))

	{

	    foreach ($channel->categories as $category)

	    {

	      $rss .= '    <category';

	      if (!empty($category['domain']))

	      {

	        $rss .= ' domain="' . $category['domain'] . '"';

	      }

	      $rss .= '>' . $category['name'] . '</category>' . "\n";

	    }

	}

    if (!empty($channel->generator))

    {

      $rss .= '    <generator>' . $channel->generator . '</generator>' . "\n";

    }

    if (!empty($channel->docs))

    {

      $rss .= '    <docs>' . $channel->docs . '</docs>' . "\n";

    }

    if (!empty($channel->ttl))

    {

      $rss .= '    <ttl>' . $channel->ttl . '</ttl>' . "\n";

    }

    if (!empty($channel->skipHours))

    {

      $rss .= '    <skipHours>' . "\n";

      foreach ($channel->skipHours as $hour)

      {

        $rss .= '      <hour>' . $hour . '</hour>' . "\n";

      }

      $rss .= '    </skipHours>' . "\n";

    }

    if (!empty($channel->skipDays))

    {

      $rss .= '    <skipDays>' . "\n";

      foreach ($channel->skipDays as $day)

      {

        $rss .= '      <day>' . $day . '</day>' . "\n";

      }

      $rss .= '    </skipDays>' . "\n";

    }

    if (!empty($channel->image))

    {

      $image = $channel->image;

      $rss .= '    <image>' . "\n";

      $rss .= '      <url>' . $image->url . '</url>' . "\n";

      $rss .= '      <title>' . $image->title . '</title>' . "\n";

      $rss .= '      <link>' . $image->link . '</link>' . "\n";

      if (image.width)

      {

        $rss .= '      <width>' . $image->width . '</width>' . "\n";

      }

      if ($image.height)

      {

        $rss .= '      <height>' . $image->height . '</height>' . "\n";

      }

      if (!empty($image->description))

      {

        $rss .= '      <description>' . $image->description . '</description>' . "\n";

      }

      $rss .= '    </image>' . "\n";

    }

    if (!empty($channel->textInput))

    {

      $textInput = $channel->textInput;

      $rss .= '    <textInput>' . "\n";

      $rss .= '      <title>' . $textInput->title . '</title>' . "\n";

      $rss .= '      <description>' .  $textInput->description . '</description>' . "\n";

      $rss .= '      <name>' . $textInput->name . '</name>' . "\n";

      $rss .= '      <link>' . $textInput->link . '</link>' . "\n";

      $rss .= '    </textInput>' . "\n";

    }

    if (!empty($channel->cloud_domain) || !empty($channel->cloud_path) ||

      !empty($channel->cloud_registerProcedure) || !empty($channel->cloud_protocol))

    {

      $rss .= '    <cloud domain="' . $channel->cloud_domain . '" ';

      $rss .= 'port="' . $channel->cloud_port . '" path="' . $channel->cloud_path . '" ';

      $rss .= 'registerProcedure="' . $channel->cloud_registerProcedure . '" ';

      $rss .= 'protocol="' . $channel->cloud_protocol . '" />' . "\n";

    }

    if (!empty($channel->extraXML))

    {

      $rss .= $channel->extraXML . "\n";

    }

    foreach ($channel->items as $item)

    {

      $rss .= '    <item>' . "\n";

      if (!empty($item->title))

      {

        $rss .= '      <title>' . $item->title . '</title>' . "\n";

      }

      if (!empty($item->description))

      {

        $rss .= '      <description>' . $item->description . '</description>' . "\n";

      }

      if (!empty($item->link))

      {

        $rss .= '      <link>' . $item->link . '</link>' . "\n";

      }

      if (!empty($item->pubDate))

      {

        $rss .= '      <pubDate>' . $item->pubDate . '</pubDate>' . "\n";

      }

      if (!empty($item->author))

      {

        $rss .= '      <author>' . $item->author . '</author>' . "\n";

      }

      if (!empty($item->comments))

      {

        $rss .= '      <comments>' . $item->comments . '</comments>' . "\n";

      }

      if (!empty($item->guid))

      {

        $rss .= '      <guid isPermaLink="';

        $rss .= ($item->guid_isPermaLink ? 'true' : 'false') . '">';

        $rss .= $item->guid . '</guid>' . "\n";

      }

      if (!empty($item->source))

      {

        $rss .= '      <source url="' . $item->source_url . '">';

        $rss .= $item->source . '</source>' . "\n";

      }

      if (!empty($item->enclosure_url) || !empty($item->enclosure_type))

      {

        $rss .= '      <enclosure url="' . $item->enclosure_url . '" ';

        $rss .= 'length="' . $item->enclosure_length . '" ';

        $rss .= 'type="' . $item->enclosure_type . '" />' . "\n";

      }

      foreach ($item->categories as $category)

      {

        $rss .= '      <category';

        if (!empty($category['domain']))

        {

          $rss .= ' domain="' . $category['domain'] . '"';

        }

        $rss .= '>' . $category['name'] . '</category>' . "\n";

      }

      $rss .= '    </item>' . "\n";

    }

    $rss .= '  </channel>' . "\n";

    return $rss .= '</rss>';

  }



}



class rssGenerator_channel

{



  var $title = '';

  var $link = '';

  var $description = '';

  var $language = '';

  var $copyright = '';

  var $managingEditor = '';

  var $webMaster = '';

  var $pubDate = '';

  var $lastBuildDate = '';

  var $categories = array();

  var $generator = '';

  var $docs = '';

  var $ttl = '';

  var $image = '';

  var $textInput = '';

  var $skipHours = array();

  var $skipDays = array();

  var $cloud_domain = '';

  var $cloud_port = '80';

  var $cloud_path = '';

  var $cloud_registerProcedure = '';

  var $cloud_protocol = '';

  var $items = array();

  var $extraXML = '';



}



class rssGenerator_image

{



  var $url = '';

  var $title = '';

  var $link = '';

  var $width = '88';

  var $height = '31';

  var $description = '';



}



class rssGenerator_textInput

{



  var $title = '';

  var $description = '';

  var $name = '';

  var $link = '';



}



class rssGenerator_item

{



  var $title = '';

  var $description = '';

  var $link = '';

  var $author = '';

  var $pubDate = '';

  var $comments = '';

  var $guid = '';

  var $guid_isPermaLink = true;

  var $source = '';

  var $source_url = '';

  var $enclosure_url = '';

  var $enclosure_length = '0';

  var $enclosure_type = '';

  var $categories = array();



}



?>

J'ai beau bidouiller, j'y connais rien du tout en php...

Est-ce que quelqu'un connait la solution ?
Merci.
 
WRInaute passionné
Dans rss.php tu as :
Code:
$item->description = '<![CDATA[ '.utf8_encode($site->getVar('description')).' ]]>';
A remplacer par
Code:
$nombre_de_caractere_que_tu_veux = 100;
$item->description = '<![CDATA[ '.utf8_encode(substr($site->getVar('description'), 0, $nombre_de_caractere_que_tu_veux)).' ]]>';
 
WRInaute accro
Je suis pas sûr que ça suffise avec substr parce que dans le cas où la description contient du html, ça va avoir des effet un peu aléatoires non ?
 
WRInaute discret
Bonjour,

Merci, ça fonctionne.
Je n'aurais pas de html dans mon cas mais si il était possible d'éviter de couper au milieu d'un mot et de terminer par "...", ce serait le top !
Encore merci.
 
WRInaute accro
Essaie comme ceci pour terminer avec ...
Ectorio a dit:
Je n'aurais pas de html dans mon cas mais si il était possible d'éviter de couper au milieu d'un mot et de terminer par "...", ce serait le top !
Code:
$item->description = '<![CDATA[ '.utf8_encode(substr($site->getVar('description'), 0, $nombre_de_caractere_que_tu_veux." ...")).' ]]>';
 
WRInaute accro
Code:
function truncate($string, $max, $rep = '...') {
	$stringlength = strlen($string);
	$string = $string." ";
	$string = substr($string,0,$max);
	$string = substr($string,0,strrpos($string,' '));
	if($stringlength > $max)
		$string = $string.$rep;
	return $string;
}
 
WRInaute accro
attention, la recherche du dernier espace précédent la longueur de texte à récupérer peut très bien couper au milieu d'une balise image, <a href>, <div class="">,etc... :cry:
Et après, tu reviendras sur wri demander pourquoi google invente des url :wink:
 
WRInaute discret
Salut à tous,

Etant donné que je comprends rien au php et que je n'aurais pas de html, je vais quand même couper à l'arrache avec les "...".
Merci à tous de l'aide proposée, ça m'arrange bien...
 
Discussions similaires
Haut