Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
categories.php
Aller à la documentation de ce fichier.
1 <?php
2 /**
3  * @package Joomla.Libraries
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  * Categories view base class.
14  *
15  * @package Joomla.Libraries
16  * @subpackage View
17  * @since 3.2
18  */
20 {
21  /**
22  * State data
23  *
24  * @var JRegistry
25  * @since 3.2
26  */
27  protected $state;
28 
29  /**
30  * Category items data
31  *
32  * @var array
33  * @since 3.2
34  */
35  protected $items;
36 
37  /**
38  * Language key for default page heading
39  *
40  * @var string
41  * @since 3.2
42  */
43  protected $pageHeading;
44 
45  /**
46  * Execute and display a template script.
47  *
48  * @param string $tpl The name of the template file to parse; automatically searches through the template paths.
49  *
50  * @return mixed A string if successful, otherwise a Error object.
51  *
52  * @since 3.2
53  */
54  public function display($tpl = null)
55  {
56  $state = $this->get('State');
57  $items = $this->get('Items');
58  $parent = $this->get('Parent');
59 
60  $app = JFactory::getApplication();
61 
62  // Check for errors.
63  if (count($errors = $this->get('Errors')))
64  {
65  $app->enqueueMessage($errors, 'error');
66 
67  return false;
68  }
69 
70  if ($items === false)
71  {
72  $app->enqueueMessage(JText::_('JGLOBAL_CATEGORY_NOT_FOUND'), 'error');
73 
74  return false;
75  }
76 
77  if ($parent == false)
78  {
79  $app->enqueueMessage(JText::_('JGLOBAL_CATEGORY_NOT_FOUND'), 'error');
80 
81  return false;
82  }
83 
84  $params = &$state->params;
85 
86  $items = array($parent->id => $items);
87 
88  // Escape strings for HTML output
89  $this->pageclass_sfx = htmlspecialchars($params->get('pageclass_sfx'));
90 
91  $this->maxLevelcat = $params->get('maxLevelcat', -1);
92  $this->params = &$params;
93  $this->parent = &$parent;
94  $this->items = &$items;
95 
96  $this->prepareDocument();
97 
98  return parent::display($tpl);
99  }
100 
101  /**
102  * Prepares the document
103  *
104  * @return void
105  *
106  * @since 3.2
107  */
108  protected function prepareDocument()
109  {
110  $app = JFactory::getApplication();
111  $menus = $app->getMenu();
112 
113  // Because the application sets a default page title, we need to get it from the menu item itself
114  $menu = $menus->getActive();
115 
116  if ($menu)
117  {
118  $this->params->def('page_heading', $this->params->get('page_title', $menu->title));
119  }
120  else
121  {
122  $this->params->def('page_heading', JText::_($this->pageHeading));
123  }
124 
125  $title = $this->params->get('page_title', '');
126 
127  if (empty($title))
128  {
129  $title = $app->get('sitename');
130  }
131  elseif ($app->get('sitename_pagetitles', 0) == 1)
132  {
133  $title = JText::sprintf('JPAGETITLE', $app->get('sitename'), $title);
134  }
135  elseif ($app->get('sitename_pagetitles', 0) == 2)
136  {
137  $title = JText::sprintf('JPAGETITLE', $title, $app->get('sitename'));
138  }
139 
140  $this->document->setTitle($title);
141 
142  if ($this->params->get('menu-meta_description'))
143  {
144  $this->document->setDescription($this->params->get('menu-meta_description'));
145  }
146 
147  if ($this->params->get('menu-meta_keywords'))
148  {
149  $this->document->setMetadata('keywords', $this->params->get('menu-meta_keywords'));
150  }
151 
152  if ($this->params->get('robots'))
153  {
154  $this->document->setMetadata('robots', $this->params->get('robots'));
155  }
156  }
157 }