4 * headermenuPlugin Class
6 * Copyright 2012 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 {
27 function __construct() {
29 $this->name = "headermenu" ;
30 $this->text = "headermenu" ;
31 $this->_addHook('headermenu');
32 $this->_addHook('site_admin_option_hook');
35 function CallHook ($hookname, &$params) {
38 $this->getHeaderLink();
41 case "site_admin_option_hook": {
42 echo '<li>'.$this->getAdminOptionLink().'</li>';
49 function getAdminOptionLink() {
50 return util_make_link('/plugins/'.$this->name.'/?type=globaladmin', _('Global HeaderMenu admin'), array('class' => 'tabtitle', 'title' => _('Direct link to global configuration of this plugin')));
54 * getHeaderLink - generate the links following the template
56 * @return bool true...
58 function getHeaderLink() {
59 $availableLinks = $this->getAvailableLinks();
60 foreach ($availableLinks as $link) {
61 if ($link['is_enable']) {
62 $ahref = '<a href="'.$link['url'].'">'.$link['name'].'</a>';
63 $template = isset($params['template']) ? $params['template'] : ' | {menu}';
64 echo str_replace('{menu}', $ahref, $template);
71 * getAvailableLinks - get all the links from the db
73 * @return array the available links
75 function getAvailableLinks() {
76 $links = db_query_params('select * FROM plugin_headermenu', array());
77 $availableLinks = array();
78 while ($arr = db_fetch_array($links)) {
79 $availableLinks[] = $arr;
81 return $availableLinks;
85 * addLink - add a new valid link
87 * @param string the url
88 * @param string the displayed name
89 * @param string a short description (to help administration)
90 * @return bool success or not
92 function addLink($url, $name, $description) {
94 $res = db_query_params('insert into plugin_headermenu (url, name, description, is_enable)
95 values ($1, $2, $3, $4)',
111 * deleteLink - delete a link
113 * @param int the link id
114 * @return bool success or not
116 function deleteLink($idLink) {
117 $res = db_query_params('delete from plugin_headermenu where id_headermenu = $1', array($idLink));
124 function updateLinkStatus($idLink, $linkStatus) {
125 $res = db_query_params('update plugin_headermenu set is_enable = $1 where id_headermenu = $2', array($linkStatus, $idLink));
133 * getHeader - initialize header and js
135 * @param string type : user, project, globaladmin (aka group)
136 * @return bool success or not
138 function getHeader($type) {
142 case 'globaladmin': {
143 session_require_global_perm('forge_admin');
145 require_once($gfwww.'admin/admin_utils.php');
146 use_javascript('/js/sortable.js');
147 site_admin_header(array('title'=>_('Site Global headerMenu Admin'), 'toptab' => ''));
156 * getGlobalAdminView - display the Global Admin View
160 function getGlobalAdminView() {
162 $user = session_get_user();
163 include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
168 * getPluginDescription - display the description of this plugin in pluginman admin page
170 * @return string the description
172 function getPluginDescription() {
173 return _('Get the ability to set new links next to the login menu.');