Your IP : 216.73.216.240
<?php
/*
* @package Tech Fry Library
* @license https://www.gnu.org/licenses/gpl-3.0.en.html
*/
namespace TechFry\Library\View\Front;
defined('_JEXEC') or die;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Document\Feed\FeedItem;
use Joomla\CMS\MVC\View\AbstractView;
class TfViewFeed extends AbstractView
{
public $items;
public $doc;
public $base_item_link; // Feed item link without id
public $current_link; // List of records link
public function display($tpl = null)
{
$app = Factory::getApplication();
$params = $app->getParams();
$feedEmail = $app->get('feed_email', 'none');
$siteEmail = $app->get('mailfrom');
$input = $app->input;
$option = $input->get('option');
$cparams = ComponentHelper::getParams($option);
$this->getDocument()->link = Route::_($this->current_link);
$app->getInput()->set('limit', $app->get('feed_limit'));
// Get data from the model
$rows = $this->get('Items');
foreach ($rows as $row)
{
// For each item, title, link, description are required
// A. Strip html from feed item title
$title = htmlspecialchars($row->title, ENT_QUOTES, 'UTF-8');
$title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
// B. Link of Feed Item
$link = $this->base_item_link . '&id=' . $row->id;
// C. Description of Feed Item
$description = '';
// C1. Image in description
if (isset($row->image) && !empty($row->image))
{
$image = preg_match('/http/', $row->image) ? $row->image : Uri::root() . $row->image;
$description .= '<p><img src="' . $image . '" /></p>';
}
// C2. Text in description
$desc = htmlspecialchars(trim(strip_tags($row->description)));
$feed_summary_limit = $cparams->get('feed_summary_limit', 150);
if (strlen($desc) > $feed_summary_limit)
{
$position = strpos($desc, ' ', $feed_summary_limit);
$desc = substr($desc, 0, $position);
}
$description .= $desc;
// C3. Read more in description
if ($cparams->get('feed_show_readmore', 1))
{
$description .= '<p><a target="_blank" href="' . $link . '">' . Text::_('COM_TF_FEED_READMORE') . '</a></p>';
}
// Load individual item
$item = new FeedItem();
$item->title = $title;
$item->link = Route::_($link);
if (isset($row->modified) && !empty($row->modified))
{
$item->date = $row->modified;
}
elseif (isset($row->created) && !empty($row->created))
{
$item->date = $row->created;
}
$item->authorEmail = $siteEmail;
$item->description = '<div>' . $description . '</div>';
$this->getDocument()->addItem($item);
}
}
}