4 * headermenuPlugin Class
6 * Copyright 2012-2013, Franck Villaume - TrivialDev
7 * http://fusionforge.org
9 * This file is part of FusionForge. FusionForge is free software;
10 * you can redistribute it and/or modify it under the terms of the
11 * GNU General Public License as published by the Free Software
12 * Foundation; either version 2 of the Licence, or (at your option)
15 * FusionForge is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 class headermenuPlugin extends Plugin {
29 function __construct() {
31 $this->name = 'headermenu';
32 $this->text = 'headermenu';
33 $this->_addHook('headermenu');
34 $this->_addHook('site_admin_option_hook');
35 $this->_addHook('outermenu');
36 $this->_addHook('groupisactivecheckbox'); // The "use ..." checkbox in editgroupinfo
37 $this->_addHook('groupisactivecheckboxpost');
38 $this->_addHook('groupmenu');
39 $this->_addHook('project_admin_plugins');
40 $this->_addHook('clone_project_from_template');
41 $this->_addHook('group_delete');
44 function CallHook($hookname, &$params) {
47 $this->getHeaderLink();
51 $this->getOuterLink($params);
54 case 'site_admin_option_hook': {
55 echo '<li>'.$this->getAdminOptionLink().'</li>';
59 $group_id = $params['group'];
60 $project = group_get_object($group_id);
61 if ($project->usesPlugin($this->name)) {
62 $this->getGroupLink($params);
66 case 'project_admin_plugins': {
67 $group_id = $params['group_id'];
68 $project = group_get_object($group_id);
69 if ($project->usesPlugin($this->name)) {
70 echo '<p>'.util_make_link('/plugins/'.$this->name.'/?type=projectadmin&group_id='.$group_id,
71 _('Project GroupMenu Admin'), array('class' => 'tabtitle', 'title' => _('Add/Remove/Activate/Desactivate tabs'))) . '</p>';
75 case 'clone_project_from_template': {
77 $res = db_query_params('SELECT url, name, description, is_enable, linkmenu, linktype, htmlcode, ordering FROM plugin_headermenu WHERE project = $1',
78 array($params['template']->getID()));
79 while ($row = db_fetch_array($res)) {
81 $linksData['url'] = $row['url'];
82 $linksData['name'] = $row['name'];
83 $linksData['description'] = $row['description'];
84 $linksData['is_enable'] = $row['is_enable'];
85 $linksData['linkmenu'] = $row['linkmenu'];
86 $linksData['linktype'] = $row['linktype'];
87 $linksData['htmlcode'] = $row['htmlcode'];
88 $linksData['ordering'] = $row['ordering'];
89 $links[] = $linksData;
92 foreach ($links as $link) {
93 db_query_params('INSERT INTO plugin_headermenu (url, name, description, is_enable, linkmenu, linktype, htmlcode, ordering, project) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)',
102 $params['project']->getID()));
106 case 'group_delete': {
107 $links = $this->getAvailableLinks('groupmenu', $params['group_id']);
108 foreach ($links as $link) {
109 $this->deleteLink($link['id_headermenu']);
116 function getAdminOptionLink() {
117 return util_make_link('/plugins/'.$this->name.'/?type=globaladmin', _('Global HeaderMenu admin'), array('class' => 'tabtitle', 'title' => _('Direct link to global configuration of this plugin')));
121 * getHeaderLink - generate the links following the template
123 * @return bool true...
125 function getHeaderLink() {
126 $availableLinks = $this->getAvailableLinks('headermenu');
127 foreach ($availableLinks as $link) {
128 if ($link['is_enable']) {
129 $ahref = '<a href="'.$link['url'].'">'.htmlspecialchars($link['name']).'</a>';
130 $template = isset($params['template']) ? $params['template'] : ' | {menu}';
131 echo str_replace('{menu}', $ahref, $template);
138 * getOuterLink - update the links before generate the tab.
140 * @param array hook params array
141 * @return bool true...
143 function getOuterLink($params) {
144 $availableLinks = $this->getAvailableLinks('outermenu');
145 foreach ($availableLinks as $link) {
146 if ($link['is_enable']) {
147 switch ($link['linktype']) {
149 $params['DIRS'][] = $link['url'];
150 $params['TITLES'][] = $link['name'];
151 $params['TOOLTIPS'][] = $link['description'];
155 $params['DIRS'][] = '/plugins/'.$this->name.'/?type=pageview&pageid='.$link['id_headermenu'];
156 $params['TITLES'][] = $link['name'];
157 $params['TOOLTIPS'][] = $link['description'];
167 * getGroupLink - update the links before generate the tab.
169 * @param array hook params array
170 * @return bool true...
172 function getGroupLink($params) {
173 $availableLinks = $this->getAvailableLinks('groupmenu', $params['group']);
174 foreach ($availableLinks as $link) {
175 if ($link['is_enable']) {
176 switch ($link['linktype']) {
178 $params['DIRS'][] = $link['url'];
179 $params['TITLES'][] = $link['name'];
180 $params['TOOLTIPS'][] = $link['description'];
184 $params['DIRS'][] = '/plugins/'.$this->name.'/?type=pageview&group_id='.$params['group'].'&pageid='.$link['id_headermenu'];
185 $params['TITLES'][] = $link['name'];
186 $params['TOOLTIPS'][] = $link['description'];
187 if ($params['toptab'] == '/plugins/'.$this->name.'/?type=pageview&group_id='.$params['group'].'&pageid='.$link['id_headermenu']) {
188 $params['selected'] = (count($params['DIRS'])-1);
193 $params['DIRS'][] = '/plugins/'.$this->name.'/?type=iframeview&group_id='.$params['group'].'&pageid='.$link['id_headermenu'];
194 $params['TITLES'][] = $link['name'];
195 $params['TOOLTIPS'][] = $link['description'];
196 if ($params['toptab'] == '/plugins/'.$this->name.'/?type=iframeview&group_id='.$params['group'].'&pageid='.$link['id_headermenu']) {
197 $params['selected'] = (count($params['DIRS'])-1);
208 * getAvailableLinks - get all the links from the db of certain kind
210 * @param string the type of menu links search in db
211 * @param int the group_id. Default is 0 meaning : forge level
212 * @return array the available links
214 function getAvailableLinks($linkmenu, $project = 0) {
215 $links = db_query_params('select * FROM plugin_headermenu where linkmenu = $1 and project = $2 order by ordering asc', array($linkmenu, $project));
216 $availableLinks = array();
217 while ($arr = db_fetch_array($links)) {
218 $availableLinks[] = $arr;
220 return $availableLinks;
224 * getAllAvailableLinks - get all the links from the db
226 * @return array the available links
228 function getAllAvailableLinks() {
229 $availableOuterLinks = $this->getAvailableLinks('outermenu');
230 $availableHeaderLinks = $this->getAvailableLinks('headermenu');
231 return array_merge($availableOuterLinks, $availableHeaderLinks);
235 * setLinksOrder - set the linkOrder for a set of links id
237 * @param array $linksOrder array of ordered links id
238 * @return bool success or not
240 function setLinksOrder($linksOrder) {
241 for ($i =0; $i < count($linksOrder); $i++) {
242 $res = db_query_params('update plugin_headermenu set ordering = $1 where id_headermenu = $2', array($i, $linksOrder[$i]));
250 * addLink - add a new valid link
252 * @param string $url the url
253 * @param string $name the displayed name
254 * @param string $description a short description (to help administration)
255 * @param string $linkmenu linkmenu entry : headermenu or outermenu
256 * @param string $linktype
257 * @param int $project the group_id or 0 meaning forge level
258 * @param string $htmlcode
259 * @return bool success or not
261 function addLink($url, $name, $description, $linkmenu, $linktype = 'url', $project = 0, $htmlcode = '', $ordering = 0) {
262 $res = db_query_params('insert into plugin_headermenu (url, name, description, is_enable, linkmenu, linktype, project, htmlcode, ordering)
263 values ($1, $2, $3, $4, $5, $6, $7, $8, $9)',
282 * deleteLink - delete a link
284 * @param int $idLink the link id
285 * @return bool success or not
287 function deleteLink($idLink) {
288 $res = db_query_params('delete from plugin_headermenu where id_headermenu = $1', array($idLink));
296 * updateLinkStatus - update the link status
298 * @param int $idLink the link id
299 * @param int $linkStatus the new status of the link id
300 * @return bool success or not
302 function updateLinkStatus($idLink, $linkStatus) {
303 $res = db_query_params('update plugin_headermenu set is_enable = $1 where id_headermenu = $2', array($linkStatus, $idLink));
311 * getLink - get all informations about a link
313 * @param int $idLink the link id
314 * @return array the link informations
316 function getLink($idLink) {
317 $res = db_query_params('select * from plugin_headermenu where id_headermenu = $1', array($idLink));
318 if (db_numrows($res) == 1) {
319 return db_fetch_array($res);
325 * updateLink - update a valid link
327 * @param int $idLink the link id to be updated
328 * @param string $url the url
329 * @param string $name the displayed name
330 * @param string $description a short description (to help administration)
331 * @param string $linkmenu linkmenu entry : headermenu or outermenu
332 * @param string $linktype : url or htmlcode, default is url
333 * @param string $htmlcode
334 * @return bool success or not
336 function updateLink($idLink, $url, $name, $description, $linkmenu, $linktype = 'url', $htmlcode ='') {
337 $res = db_query_params('update plugin_headermenu set url = $1, name = $2, description = $3, linkmenu = $4, linktype = $5, htmlcode = $6
338 where id_headermenu = $7',
339 array($url, $name, $description, $linkmenu, $linktype, $htmlcode, $idLink));
347 * pageView - display a static html code
349 * @param int the page id
350 * @return string the html code
352 function pageView($pageid) {
353 $link = $this->getLink($pageid);
355 return $link['htmlcode'];
357 return '<p class="error" >'._('Cannot retrieve the page').'</p>';
362 * iframeView - display the iframe
364 * @param int the iframe id
365 * @return string the html code
367 function iframeView($pageid) {
368 $link = $this->getLink($pageid);
370 return '<iframe src="'.rtrim($link['url'],'/').'" frameborder="0" height="600px" width="100%"></iframe>';
372 return '<p class="error" >'._('Cannot retrieve the page').'</p>';
377 * getHeader - initialize header and js
379 * @param string type : user, project, globaladmin (aka group)
380 * @return bool success or not
382 function getHeader($type) {
385 case 'globaladmin': {
386 session_require_global_perm('forge_admin');
388 require_once($gfwww.'admin/admin_utils.php');
391 use_javascript('scripts/HeaderMenuController.js');
392 use_javascript('/js/sortable.js');
393 site_admin_header(array('title'=>_('Site Global Menu Admin'), 'toptab' => ''));
399 $link = $this->getLink($this->pageid);
400 $group_id = getIntFromRequest('group_id');
402 $params['toptab'] = '/plugins/'.$this->name.'/?type='.$type.'&group_id='.$group_id.'&pageid='.$this->pageid;
403 $params['group'] = $group_id;
404 $params['title'] = $link['name'];
405 site_project_header($params);
407 site_header(array('title'=> $link['name'], 'toptab' => '/plugins/'.$this->name.'/?type='.$type.'&pageid='.$this->pageid));
412 case 'projectadmin': {
415 use_javascript('scripts/HeaderMenuController.js');
416 use_javascript('/js/sortable.js');
417 $group_id = getIntFromRequest('group_id');
418 $params['toptab'] = 'admin';
419 $params['group'] = $group_id;
420 $params['title'] = _('Project groupmenu Admin');
421 site_project_header($params);
430 * getGlobalAdminView - display the Global Admin View
434 function getGlobalAdminView() {
436 $user = session_get_user();
437 include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
442 * getProjectAdminView - display the Project Admin View
446 function getProjectAdminView() {
448 $user = session_get_user();
449 include $gfplugins.$this->name.'/view/admin/viewProjectConfiguration.php';
454 * getPluginDescription - display the description of this plugin in pluginman admin page
456 * @return string the description
458 function getPluginDescription() {
459 return _('Get the ability to set new links next to the login menu (headermenu), in the main menu (outermenu) or in the project menu (groupmenu).');