1 <?php
2 3 4 5 6 7
8
9 defined('FOF_INCLUDED') or die;
10
11 12 13 14 15 16 17
18 class FOFViewHtml extends FOFViewRaw
19 {
20
21 public $setFrontendPageTitle = false;
22
23
24 public $defaultPageTitle = null;
25
26 27 28 29 30
31 public function __construct($config = array())
32 {
33
34 if (is_object($config))
35 {
36 $config = (array)$config;
37 }
38 elseif (!is_array($config))
39 {
40 $config = array();
41 }
42
43 if (isset($config['setFrontendPageTitle']))
44 {
45 $this->setFrontendPageTitle = (bool)$config['setFrontendPageTitle'];
46 }
47
48 if (isset($config['defaultPageTitle']))
49 {
50 $this->defaultPageTitle = $config['defaultPageTitle'];
51 }
52
53 parent::__construct($config);
54 }
55
56 57 58 59 60 61
62 protected function preRender()
63 {
64 $view = $this->input->getCmd('view', 'cpanel');
65 $task = $this->getModel()->getState('task', 'browse');
66
67
68
69 if (!FOFPlatform::getInstance()->isCli())
70 {
71 $toolbar = FOFToolbar::getAnInstance($this->input->getCmd('option', 'com_foobar'), $this->config);
72 $toolbar->perms = $this->perms;
73 $toolbar->renderToolbar($view, $task, $this->input);
74 }
75
76 if (FOFPlatform::getInstance()->isFrontend())
77 {
78 if ($this->setFrontendPageTitle)
79 {
80 $this->setPageTitle();
81 }
82 }
83
84 $renderer = $this->getRenderer();
85 $renderer->preRender($view, $task, $this->input, $this->config);
86 }
87
88 89 90 91 92 93
94 protected function postRender()
95 {
96 $view = $this->input->getCmd('view', 'cpanel');
97 $task = $this->getModel()->getState('task', 'browse');
98
99 $renderer = $this->getRenderer();
100
101 if ($renderer instanceof FOFRenderAbstract)
102 {
103 $renderer->postRender($view, $task, $this->input, $this->config);
104 }
105 }
106
107 public function setPageTitle()
108 {
109 $document = JFactory::getDocument();
110 $app = JFactory::getApplication();
111 $menus = $app->getMenu();
112 $menu = $menus->getActive();
113 $title = null;
114
115
116 $option = empty($this->option) ? $this->input->getCmd('option', 'com_foobar') : $this->option;
117 $view = empty($this->view) ? $this->input->getCmd('view', $this->getName()) : $this->view;
118
119
120 $default = empty($this->defaultPageTitle) ? $option . '_TITLE_' . $view : $this->defaultPageTitle;
121
122 $params = $app->getPageParameters($option);
123
124
125 if ($menu)
126 {
127 $params->def('page_heading', $params->get('page_title', $menu->title));
128 }
129 else
130 {
131 $params->def('page_heading', JText::_($default));
132 }
133
134
135 $title = $params->get('page_title', '');
136 $sitename = $app->getCfg('sitename');
137
138 if ($title == $sitename)
139 {
140 $title = JText::_($default);
141 }
142
143 if (empty($title))
144 {
145 $title = $sitename;
146 }
147 elseif ($app->getCfg('sitename_pagetitles', 0) == 1)
148 {
149 $title = JText::sprintf('JPAGETITLE', $app->getCfg('sitename'), $title);
150 }
151 elseif ($app->getCfg('sitename_pagetitles', 0) == 2)
152 {
153 $title = JText::sprintf('JPAGETITLE', $title, $app->getCfg('sitename'));
154 }
155
156 $document->setTitle($title);
157
158
159 if ($params->get('menu-meta_description'))
160 {
161 $document->setDescription($params->get('menu-meta_description'));
162 }
163
164 if ($params->get('menu-meta_keywords'))
165 {
166 $document->setMetadata('keywords', $params->get('menu-meta_keywords'));
167 }
168
169 if ($params->get('robots'))
170 {
171 $document->setMetadata('robots', $params->get('robots'));
172 }
173
174 return $title;
175 }
176 }
177