XF 1.4 News Feed Max Snippet Length Being Ignored

You are correct. I was looking in wrong place. I did setup the feed. Is there a way to limit size of {content}

Quoting Mike... I figured that was next Q, so I searched it.

That option controls your outgoing feeds.

The feed posting system will simply post what is in the RSS feed that you're reading from. There's no option on the XF end to limit the length of the feed content.

That was a while back, but not sure it has changed or the option added.
 
Not that modifying core xf files is advisable, but if you want to implement this now yourself in the mean time, you can copy the original and save it for good measure and then go on to the following if you are comfortable tweaking php files yourself (which will get over written when an xf update rewrites that file)

Edit: /library/XenForo/Model/Feed.php

(@ around line 216)

Find:

PHP:
            $enclosure = $entry->getEnclosure();
            if ($enclosure)
            {
                $entryData['enclosure_url'] = $enclosure->url;
                $entryData['enclosure_length'] = $enclosure->length;
                $entryData['enclosure_type'] = $enclosure->type;
            }

directly following that add this: (change 140 to the character limit you desire)

PHP:
            if (utf8_strlen($entryData['content_html']) > 140) {
                $entryData['content_html'] = substr($entryData['content_html'], 0, 140)) . '...';
            }


so it looks like this:

PHP:
            $enclosure = $entry->getEnclosure();
            if ($enclosure)
            {
                $entryData['enclosure_url'] = $enclosure->url;
                $entryData['enclosure_length'] = $enclosure->length;
                $entryData['enclosure_type'] = $enclosure->type;
            }
            if (utf8_strlen($entryData['content_html']) > 140) {
                $entryData['content_html'] = substr($entryData['content_html'], 0, 140)) . '...';
            }


*as a note this wont effect threads already created by the feeder
 
Hey @EQnoble, you still around?

I tried to adapt your excellent hint after upgrading to XF 1.5.24.

Here's the code (original lines commented)

PHP:
foreach ($feed as $entry)
                {
                        /** @var $entry Zend_Feed_Reader_EntryInterface */

                        try
                        {
                                $content = $entry->getContent();
                        }
                        catch (Exception $e)
                        {
                                // there's a situation where getting the content can trigger an exception if malformed,
                                // so ensure this doesn't error
                                $content = $entry->getDescription();
                        }

                        $entryData = array(
                                'id' => $entry->getId(),
                                'title' => html_entity_decode($entry->getTitle(), ENT_COMPAT, 'utf-8'),
                                'description' => html_entity_decode($entry->getDescription(), ENT_COMPAT, 'utf-8'),
                                'date_modified' => null,
                                'authors' => $entry->getAuthors(),
                                'link' => $entry->getLink(),
                                'content_html' => $content
                        );

                        $enclosure = $entry->getEnclosure();
                        if ($enclosure)
                        {
                                $entryData['enclosure_url'] = $enclosure->url;
                                $entryData['enclosure_length'] = $enclosure->length;
                                $entryData['enclosure_type'] = $enclosure->type;
                        }

                        /** if (utf8_strlen($entryData['id']) > 250) change by Temexter 20190806**/
                        if (utf8_strlen($entryData['id']) > 500)
                        {
                                $entryData['id'] = md5(substr($entryData['id'], 0, 500));
                                /** $entryData['id'] = md5($entryData['id']); change by Temexter 20190806 **/
                        }

                        try
                        {
                                $entryData['date_modified'] = $entry->getDateModified();
                        }
                        catch (Zend_Exception $e) {} // triggered with invalid date format

                        if (!empty($entryData['date_modified']) && $entryData['date_modified'] instanceof Zend_Date)
                        {
                                $entryData['date_modified'] = $entryData['date_modified']->getTimeStamp();
                        }
                        else
                        {
                                $entryData['date_modified'] = XenForo_Application::$time;
                        }
It does not throw any errors, but doesn't do anything either :LOL:

Would really appreciate help with code, because the feeder still has bad difficulties in HTML to BBCODE conversion and thus too many extra 2-3 line breaks and because of missing functionality empty space where should be a embedded video so the post looks quite bad. Ii decided to just post a snippet on on our News forum so people will hit "Read more..." to read the whole story. Moreover, people running the source site will be happier for more people coming to their site and traffic and hits. And it's probably legality wise a better solution as well ;)

Edit: I tried just for fun without md5-function, just to see what it does for conversion and now published post is missing line breaks. It looks still better than 2-3 line breaks everywhere... And yes, i checked again, XenPorta cuts correctly news automatically posted to Home page, but on News forum the post by Feeder is still complete, it's not cut to 500 chars. I already thought i fixed the issue by looking the Home page :oops:
 
Last edited:
I got this to work, but not enough still. That try above is really ****ty :D I was really tired and trying to see something in code in early hours, pathetic ;)

I now can truncate the post, but still need to find a way to not truncate in between HTML tags (or truncate BBCODE after HTML -> BBCODE conversion (and same, not truncate in between BBCODE tags.

And just for record, we are upgrading to 1.5.24, so the code differs from OP.
 
Back
Top Bottom