1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 13 14 15 16
17 class JViewCategoryfeed extends JViewLegacy
18 {
19 20 21 22 23 24 25 26 27
28 public function display($tpl = null)
29 {
30 $app = JFactory::getApplication();
31 $document = JFactory::getDocument();
32
33 $extension = $app->input->getString('option');
34 $contentType = $extension . '.' . $this->viewName;
35
36 $ucmType = new JUcmType;
37 $ucmRow = $ucmType->getTypeByAlias($contentType);
38 $ucmMapCommon = json_decode($ucmRow->field_mappings)->common;
39 $createdField = null;
40 $titleField = null;
41
42 if (is_object($ucmMapCommon))
43 {
44 $createdField = $ucmMapCommon->core_created_time;
45 $titleField = $ucmMapCommon->core_title;
46 }
47 elseif (is_array($ucmMapCommon))
48 {
49 $createdField = $ucmMapCommon[0]->core_created_time;
50 $titleField = $ucmMapCommon[0]->core_title;
51 }
52
53 $document->link = JRoute::_(JHelperRoute::getCategoryRoute($app->input->getInt('id'), $language = 0, $extension));
54
55 $app->input->set('limit', $app->get('feed_limit'));
56 $siteEmail = $app->get('mailfrom');
57 $fromName = $app->get('fromname');
58 $feedEmail = $app->get('feed_email', 'none');
59 $document->editor = $fromName;
60
61 if ($feedEmail != 'none')
62 {
63 $document->editorEmail = $siteEmail;
64 }
65
66
67 $items = $this->get('Items');
68 $category = $this->get('Category');
69
70
71 if ($category == false || $category->alias == "root")
72 {
73 return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
74 }
75
76 foreach ($items as $item)
77 {
78 $this->reconcileNames($item);
79
80
81 if ($titleField)
82 {
83 $title = $this->escape($item->$titleField);
84 $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
85 }
86 else
87 {
88 $title = '';
89 }
90
91
92 $router = new JHelperRoute;
93 $link = JRoute::_($router->getRoute($item->id, $contentType, null, null, $item->catid));
94
95
96 $description = $item->description;
97 $author = $item->created_by_alias ?: $item->author;
98
99 if ($createdField)
100 {
101 $date = isset($item->$createdField) ? date('r', strtotime($item->$createdField)) : '';
102 }
103 else
104 {
105 $date = '';
106 }
107
108
109 $feeditem = new JFeedItem;
110 $feeditem->title = $title;
111 $feeditem->link = $link;
112 $feeditem->description = $description;
113 $feeditem->date = $date;
114 $feeditem->category = $category->title;
115 $feeditem->author = $author;
116
117
118 if ($feedEmail == 'site')
119 {
120 $feeditem->authorEmail = $siteEmail;
121 }
122 elseif ($feedEmail === 'author')
123 {
124 $feeditem->authorEmail = $item->author_email;
125 }
126
127
128 $document->addItem($feeditem);
129 }
130 }
131
132 133 134 135 136 137 138 139 140 141
142 protected function reconcileNames($item)
143 {
144 if (!property_exists($item, 'title') && property_exists($item, 'name'))
145 {
146 $item->title = $item->name;
147 }
148 }
149 }
150