Back to CategoryFeedView class

Method display

public void
display
(mixed $tpl = null)
Execute and display a template script.
Parameters
  • string $tpl The name of the template file to parse; automatically searches through the template paths.
Returns
  • void
Since
  • 3.2
-
  • \Exception

Method display - Source code

/**
 * Execute and display a template script.
 *
 * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
 *
 * @return  void
 *
 * @since   3.2
 * @throws  \Exception
 */
public function display($tpl = null)
{
    $app = Factory::getApplication();
    $document = Factory::getDocument();
    $extension = $app->input->getString('option');
    $contentType = $extension . '.' . $this->viewName;
    $ucmType = new UCMType();
    $ucmRow = $ucmType->getTypeByAlias($contentType);
    $ucmMapCommon = json_decode($ucmRow->field_mappings)->common;
    $createdField = null;
    $titleField = null;
    if (\is_object($ucmMapCommon)) {
        $createdField = $ucmMapCommon->core_created_time;
        $titleField = $ucmMapCommon->core_title;
    } elseif (\is_array($ucmMapCommon)) {
        $createdField = $ucmMapCommon[0]->core_created_time;
        $titleField = $ucmMapCommon[0]->core_title;
    }
    $document->link = Route::_(RouteHelper::getCategoryRoute($app->input->getInt('id'), $language = 0, $extension));
    $app->input->set('limit', $app->get('feed_limit'));
    $siteEmail = $app->get('mailfrom');
    $fromName = $app->get('fromname');
    $feedEmail = $app->get('feed_email', 'none');
    $document->editor = $fromName;
    if ($feedEmail !== 'none') {
        $document->editorEmail = $siteEmail;
    }
    // Get some data from the model
    $items = $this->get('Items');
    $category = $this->get('Category');
    // Don't display feed if category id missing or non existent
    if ($category == false || $category->alias === 'root') {
        throw new \Exception(Text::_('JGLOBAL_CATEGORY_NOT_FOUND'), 404);
    }
    foreach ($items as $item) {
        $this->reconcileNames($item);
        // Strip html from feed item title
        if ($titleField) {
            $title = $this->escape($item->{$titleField});
            $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
        } else {
            $title = '';
        }
        // URL link to article
        $router = new RouteHelper();
        $link = Route::_($router->getRoute($item->id, $contentType, null, null, $item->catid));
        // Strip HTML from feed item description text.
        $description = $item->description;
        $author = $item->created_by_alias ?: $item->author;
        $categoryTitle = isset($item->category_title) ? $item->category_title : $category->title;
        if ($createdField) {
            $date = isset($item->{$createdField}) ? date('r', strtotime($item->{$createdField})) : '';
        } else {
            $date = '';
        }
        // Load individual item creator class.
        $feeditem = new FeedItem();
        $feeditem->title = $title;
        $feeditem->link = $link;
        $feeditem->description = $description;
        $feeditem->date = $date;
        $feeditem->category = $categoryTitle;
        $feeditem->author = $author;
        // We don't have the author email so we have to use site in both cases.
        if ($feedEmail === 'site') {
            $feeditem->authorEmail = $siteEmail;
        } elseif ($feedEmail === 'author') {
            $feeditem->authorEmail = $item->author_email;
        }
        // Loads item information into RSS array
        $document->addItem($feeditem);
    }
}