Temexter
Member
Hello folks,
I already asked in the relevant thread: https://xenforo.com/community/threads/news-feed-max-snippet-length-being-ignored.103439/
I tried to adapt @EQnoble's excellent hint in said thread after upgrading to XF 1.5.24 (the version used by the OP in that thread is 1.4).
Here's the code (changed lines commented):
It does not throw any errors, but doesn't cut the post either
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. So decided to just post a snippet on on our News forum so our members would hit "Read more..." to read the whole story. Moreover, people running the source site would be happier for more people coming to their site and traffic and hits. And it's probably legality wise a better solution as well in general
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
I already asked in the relevant thread: https://xenforo.com/community/threads/news-feed-max-snippet-length-being-ignored.103439/
I tried to adapt @EQnoble's excellent hint in said thread after upgrading to XF 1.5.24 (the version used by the OP in that thread is 1.4).
Here's the code (changed 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 cut the post either
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. So decided to just post a snippet on on our News forum so our members would hit "Read more..." to read the whole story. Moreover, people running the source site would be happier for more people coming to their site and traffic and hits. And it's probably legality wise a better solution as well in general
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