1 <?php
  2   3   4   5   6   7   8 
  9 
 10 defined('JPATH_PLATFORM') or die;
 11 
 12  13  14  15  16 
 17 class JViewCategory extends JViewLegacy
 18 {
 19      20  21  22  23  24 
 25     protected $state;
 26 
 27      28  29  30  31  32 
 33     protected $items;
 34 
 35      36  37  38  39  40 
 41     protected $category;
 42 
 43      44  45  46  47  48 
 49     protected $categories;
 50 
 51      52  53  54  55  56 
 57     protected ;
 58 
 59      60  61  62  63  64 
 65     protected $children;
 66 
 67      68  69  70  71  72 
 73     protected $extension;
 74 
 75      76  77  78  79  80 
 81     protected $viewName;
 82 
 83      84  85  86  87  88 
 89     protected $defaultPageTitle;
 90 
 91      92  93  94  95  96  97 
 98     protected $runPlugins = false;
 99 
100     101 102 103 104 105 106 
107     public function commonCategoryDisplay()
108     {
109         $app    = JFactory::getApplication();
110         $user   = JFactory::getUser();
111         $params = $app->getParams();
112 
113         
114         $model       = $this->getModel();
115         $paramsModel = $model->getState('params');
116         
117         $paramsModel->set('check_access_rights', 0);
118         $model->setState('params', $paramsModel);
119 
120         $state       = $this->get('State');
121         $category    = $this->get('Category');
122         $children    = $this->get('Children');
123         $parent      = $this->get('Parent');
124 
125         if ($category == false)
126         {
127             return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
128         }
129 
130         if ($parent == false)
131         {
132             return JError::raiseError(404, JText::_('JGLOBAL_CATEGORY_NOT_FOUND'));
133         }
134         
135         
136         $groups = $user->getAuthorisedViewLevels();
137         
138         if (!in_array($category->access, $groups))
139         {
140             return JError::raiseError(403, JText::_('JERROR_ALERTNOAUTHOR'));
141         }
142 
143         $items      = $this->get('Items');
144         $pagination = $this->get('Pagination');
145 
146         
147         if (count($errors = $this->get('Errors')))
148         {
149             JError::raiseError(500, implode("\n", $errors));
150 
151             return false;
152         }
153 
154         
155         $cparams          = $category->getParams();
156         $category->params = clone $params;
157         $category->params->merge($cparams);
158 
159         $children = array($category->id => $children);
160 
161         
162         $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
163 
164         if ($this->runPlugins)
165         {
166             JPluginHelper::importPlugin('content');
167 
168             foreach ($items as $itemElement)
169             {
170                 $itemElement = (object) $itemElement;
171                 $itemElement->event = new stdClass;
172 
173                 
174                 !empty($itemElement->description)? $itemElement->text = $itemElement->description : $itemElement->text = null;
175 
176                 $dispatcher = JEventDispatcher::getInstance();
177 
178                 $dispatcher->trigger('onContentPrepare', array($this->extension . '.category', &$itemElement, &$itemElement->params, 0));
179 
180                 $results = $dispatcher->trigger('onContentAfterTitle', array($this->extension . '.category', &$itemElement, &$itemElement->core_params, 0));
181                 $itemElement->event->afterDisplayTitle = trim(implode("\n", $results));
182 
183                 $results = $dispatcher->trigger('onContentBeforeDisplay', array($this->extension . '.category', &$itemElement, &$itemElement->core_params, 0));
184                 $itemElement->event->beforeDisplayContent = trim(implode("\n", $results));
185 
186                 $results = $dispatcher->trigger('onContentAfterDisplay', array($this->extension . '.category', &$itemElement, &$itemElement->core_params, 0));
187                 $itemElement->event->afterDisplayContent = trim(implode("\n", $results));
188 
189                 if ($itemElement->text)
190                 {
191                     $itemElement->description = $itemElement->text;
192                 }
193             }
194         }
195 
196         $maxLevel         = $params->get('maxLevel', -1) < 0 ? PHP_INT_MAX : $params->get('maxLevel', PHP_INT_MAX);
197         $this->maxLevel   = &$maxLevel;
198         $this->state      = &$state;
199         $this->items      = &$items;
200         $this->category   = &$category;
201         $this->children   = &$children;
202         $this->params     = &$params;
203         $this->parent     = &$parent;
204         $this->pagination = &$pagination;
205         $this->user       = &$user;
206 
207         
208         
209         $active = $app->getMenu()->getActive();
210 
211         if ((!$active) || ((strpos($active->link, 'view=category') === false) || (strpos($active->link, '&id=' . (string) $this->category->id) === false)))
212         {
213             if ($layout = $category->params->get('category_layout'))
214             {
215                 $this->setLayout($layout);
216             }
217         }
218         elseif (isset($active->query['layout']))
219         {
220             
221             $this->setLayout($active->query['layout']);
222         }
223 
224         $this->category->tags = new JHelperTags;
225         $this->category->tags->getItemTags($this->extension . '.category', $this->category->id);
226     }
227 
228     229 230 231 232 233 234 235 236 
237     public function display($tpl = null)
238     {
239         $this->prepareDocument();
240 
241         return parent::display($tpl);
242     }
243 
244     245 246 247 248 249 250 
251     protected function prepareDocument()
252     {
253         $app           = JFactory::getApplication();
254         $menus         = $app->getMenu();
255         $this->pathway = $app->getPathway();
256         $title         = null;
257 
258         
259         $this->menu = $menus->getActive();
260 
261         if ($this->menu)
262         {
263             $this->params->def('page_heading', $this->params->get('page_title', $this->menu->title));
264         }
265         else
266         {
267             $this->params->def('page_heading', JText::_($this->defaultPageTitle));
268         }
269 
270         $title = $this->params->get('page_title', '');
271 
272         if (empty($title))
273         {
274             $title = $app->get('sitename');
275         }
276         elseif ($app->get('sitename_pagetitles', 0) == 1)
277         {
278             $title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title);
279         }
280         elseif ($app->get('sitename_pagetitles', 0) == 2)
281         {
282             $title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename'));
283         }
284 
285         $this->document->setTitle($title);
286 
287         if ($this->params->get('menu-meta_description'))
288         {
289             $this->document->setDescription($this->params->get('menu-meta_description'));
290         }
291 
292         if ($this->params->get('menu-meta_keywords'))
293         {
294             $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
295         }
296 
297         if ($this->params->get('robots'))
298         {
299             $this->document->setMetadata('robots', $this->params->get('robots'));
300         }
301     }
302 
303     304 305 306 307 308 309 
310     protected function addFeed()
311     {
312         if ($this->params->get('show_feed_link', 1) == 1)
313         {
314             $link    = '&format=feed&limitstart=';
315             $attribs = array('type' => 'application/rss+xml', 'title' => 'RSS 2.0');
316             $this->document->addHeadLink(JRoute::_($link . '&type=rss'), 'alternate', 'rel', $attribs);
317             $attribs = array('type' => 'application/atom+xml', 'title' => 'Atom 1.0');
318             $this->document->addHeadLink(JRoute::_($link . '&type=atom'), 'alternate', 'rel', $attribs);
319         }
320     }
321 }
322