Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
categoryfeed.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Legacy
4  * @subpackage View
5  *
6  * @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
7  * @license GNU General Public License version 2 or later; see LICENSE.txt
8  */
9 
10 defined('_JEXEC') or die;
11 
12 /**
13  * Base feed View class for a category
14  *
15  * @package Joomla.Legacy
16  * @subpackage View
17  * @since 3.2
18  */
20 {
21  /**
22  * Execute and display a template script.
23  *
24  * @param string $tpl The name of the template file to parse; automatically searches through the template paths.
25  *
26  * @return mixed A string if successful, otherwise a Error object.
27  *
28  * @since 3.2
29  */
30  public function display($tpl = null)
31  {
32  $app = JFactory::getApplication();
33  $document = JFactory::getDocument();
34 
35  $extension = $app->input->getString('option');
36  $document->link = JRoute::_(JHelperRoute::getCategoryRoute($app->input->getInt('id'), $language = 0, $extension));
37 
38  $app->input->set('limit', $app->get('feed_limit'));
39  $siteEmail = $app->get('mailfrom');
40  $fromName = $app->get('fromname');
41  $feedEmail = $app->get('feed_email', 'author');
42  $document->editor = $fromName;
43 
44  if ($feedEmail != 'none')
45  {
46  $document->editorEmail = $siteEmail;
47  }
48 
49  // Get some data from the model
50  $items = $this->get('Items');
51  $category = $this->get('Category');
52 
53  foreach ($items as $item)
54  {
55  $this->reconcileNames($item);
56 
57  // Strip html from feed item title
58  $title = $this->escape($item->title);
59  $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
60 
61  // URL link to article
62  $router = new JHelperRoute;
63  $link = JRoute::_($router->getRoute($item->id, $item->catid));
64 
65  // Strip HTML from feed item description text.
66  $description = $item->description;
67  $author = $item->created_by_alias ? $item->created_by_alias : $item->author;
68  $date = isset($item->date) ? date('r', strtotime($item->date)) : '';
69 
70  // Load individual item creator class.
71  $feeditem = new JFeedItem;
72  $feeditem->title = $title;
73  $feeditem->link = $link;
74  $feeditem->description = $description;
75  $feeditem->date = $date;
76  $feeditem->category = $category->title;
77  $feeditem->author = $author;
78 
79  // We don't have the author email so we have to use site in both cases.
80  if ($feedEmail == 'site')
81  {
82  $feeditem->authorEmail = $siteEmail;
83  }
84  elseif ($feedEmail === 'author')
85  {
86  $feeditem->authorEmail = $item->author_email;
87  }
88 
89  // Loads item information into RSS array
90  $document->addItem($feeditem);
91  }
92  }
93 
94  /**
95  * Method to reconcile non standard names from components to usage in this class.
96  * Typically overriden in the component feed view class.
97  *
98  * @param object $item The item for a feed, an element of the $items array.
99  *
100  * @return void
101  *
102  * @since 3.2
103  */
104  protected function reconcileNames($item)
105  {
106  if (!property_exists($item, 'title') && property_exists($item, 'name'))
107  {
108  $item->title = $item->name;
109  }
110  }
111 }