CoreFiles by mySites.guru
FeedView.php127 lines, 3,867 bytes, from Joomla_4.0.0-alpha5-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha3
md5
641f3d13fc093a8ecc81abc36aa6b353
sha1
3cf39cda54eb6dc5b2533766683fc6817cdce25b
sha256
529ddcf2f1240e9031dd84faf3ae7b9f7f8c0c4b6ba0e4881eb4f2e1007602a5
<?php
/**
 * @package     Joomla.Site
 * @subpackage  com_content
 *
 * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\Component\Content\Site\View\Featured;

defined('_JEXEC') or die;

use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Document\Feed\FeedItem;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\AbstractView;
use Joomla\CMS\Router\Route;

/**
 * Frontpage View class
 *
 * @since  1.5
 */
class FeedView extends AbstractView
{
	/**
	 * Execute and display a template script.
	 *
	 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
	 *
	 * @return  mixed  A string if successful, otherwise an Error object.
	 */
	public function display($tpl = null)
	{
		// Parameters
		$app       = Factory::getApplication();
		$doc       = Factory::getDocument();
		$params    = $app->getParams();
		$feedEmail = $app->get('feed_email', 'none');
		$siteEmail = $app->get('mailfrom');
		$doc->link = Route::_('index.php?option=com_content&view=featured');

		// Get some data from the model
		$app->input->set('limit', $app->get('feed_limit'));
		$categories = Categories::getInstance('Content');
		$rows       = $this->get('Items');

		foreach ($rows as $row)
		{
			// Strip html from feed item title
			$title = $this->escape($row->title);
			$title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');

			// Compute the article slug
			$row->slug = $row->alias ? ($row->id . ':' . $row->alias) : $row->id;

			// URL link to article
			$link = Route::_(\ContentHelperRoute::getArticleRoute($row->slug, $row->catid, $row->language));

			// Get row fulltext
			$db = Factory::getDbo();
			$query = $db->getQuery(true)
				->select($db->quoteName('fulltext'))
				->from($db->quoteName('#__content'))
				->where($db->quoteName('id') . ' = ' . $row->id);
			$db->setQuery($query);
			$row->fulltext = $db->loadResult();

			$description = '';
			$obj = json_decode($row->images);
			$introImage = $obj->{'image_intro'} ?? '';

			if (isset($introImage) && ($introImage != ''))
			{
				$image = preg_match('/http/', $introImage) ? $introImage : JURI::root() . $introImage;
				$description = '<p><img src="' . $image . '"></p>';
			}

			$description .= ($params->get('feed_summary', 0) ? $row->introtext . $row->fulltext : $row->introtext);
			$author      = $row->created_by_alias ?: $row->author;

			// Load individual item creator class
			$item           = new FeedItem;
			$item->title    = $title;
			$item->link     = $link;
			$item->date     = $row->publish_up;
			$item->category = array();

			// All featured articles are categorized as "Featured"
			$item->category[] = Text::_('JFEATURED');

			for ($item_category = $categories->get($row->catid); $item_category !== null; $item_category = $item_category->getParent())
			{
				// Only add non-root categories
				if ($item_category->id > 1)
				{
					$item->category[] = $item_category->title;
				}
			}

			$item->author = $author;

			if ($feedEmail === 'site')
			{
				$item->authorEmail = $siteEmail;
			}
			elseif ($feedEmail === 'author')
			{
				$item->authorEmail = $row->author_email;
			}

			// Add readmore link to description if introtext is shown, show_readmore is true and fulltext exists
			if (!$params->get('feed_summary', 0) && $params->get('feed_show_readmore', 0) && $row->fulltext)
			{
				$description .= '<p class="feed-readmore"><a target="_blank" href ="' . $item->link . '">' . Text::_('COM_CONTENT_FEED_READMORE') . '</a></p>';
			}

			// Load item description and add div
			$item->description = '<div class="feed-description">' . $description . '</div>';

			// Loads item info into rss array
			$doc->addItem($item);
		}
	}
}

The same content is in 2 releases, Joomla 4.0.0-alpha5 to 4.0.0-alpha6. See them all, or every version of this file.