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 {
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');
42 function CallHook($hookname, &$params) {
45 $this->getHeaderLink();
49 $this->getOuterLink($params);
52 case 'site_admin_option_hook': {
53 echo '<li>'.$this->getAdminOptionLink().'</li>';
57 $this->getGroupLink($params);
60 case 'project_admin_plugins': {
61 $group_id = $params['group_id'];
62 $project = group_get_object($group_id);
63 if ($project->usesPlugin($this->name)) {
64 echo '<p>'.util_make_link('/plugins/headermenu/?type=projectadmin&group_id='.$group_id,
65 _('Project GroupMenu Admin'), array('class' => 'tabtitle', 'title' => _('Add/Remove/Activate/Desactivate tabs'))) . '</p>';
73 function getAdminOptionLink() {
74 return util_make_link('/plugins/'.$this->name.'/?type=globaladmin', _('Global HeaderMenu admin'), array('class' => 'tabtitle', 'title' => _('Direct link to global configuration of this plugin')));
78 * getHeaderLink - generate the links following the template
80 * @return bool true...
82 function getHeaderLink() {
83 $availableLinks = $this->getAvailableLinks('headermenu');
84 foreach ($availableLinks as $link) {
85 if ($link['is_enable']) {
86 $ahref = '<a href="'.$link['url'].'">'.htmlspecialchars($link['name']).'</a>';
87 $template = isset($params['template']) ? $params['template'] : ' | {menu}';
88 echo str_replace('{menu}', $ahref, $template);
95 * getOuterLink - update the links before generate the tab.
97 * @param array hook params array
98 * @return bool true...
100 function getOuterLink($params) {
101 $availableLinks = $this->getAvailableLinks('outermenu');
102 foreach ($availableLinks as $link) {
103 if ($link['is_enable']) {
104 switch ($link['linktype']) {
106 $params['DIRS'][] = $link['url'];
107 $params['TITLES'][] = $link['name'];
108 $params['TOOLTIPS'][] = $link['description'];
112 $params['DIRS'][] = '/plugins/'.$this->name.'/?type=pageview&pageid='.$link['id_headermenu'];
113 $params['TITLES'][] = $link['name'];
114 $params['TOOLTIPS'][] = $link['description'];
124 * getGroupLink - update the links before generate the tab.
126 * @param array hook params array
127 * @return bool true...
129 function getGroupLink($params) {
130 $availableLinks = $this->getAvailableLinks('groupmenu');
131 foreach ($availableLinks as $link) {
132 if ($link['is_enable']) {
133 switch ($link['linktype']) {
135 $params['DIRS'][] = $link['url'];
136 $params['TITLES'][] = $link['name'];
137 $params['TOOLTIPS'][] = $link['description'];
141 $params['DIRS'][] = '/plugins/'.$this->name.'/?type=pageview&group_id='.$params['group'].'&pageid='.$link['id_headermenu'];
142 $params['TITLES'][] = $link['name'];
143 $params['TOOLTIPS'][] = $link['description'];
144 if ($params['toptab'] == '/plugins/'.$this->name.'/?type=pageview&group_id='.$params['group'].'&pageid='.$link['id_headermenu']) {
145 $params['selected'] = (count($params['DIRS'])-1);
150 $params['DIRS'][] = '/plugins/'.$this->name.'/?type=iframe&group_id='.$params['group'].'&pageid='.$link['id_headermenu'];
151 $params['TITLES'][] = $link['name'];
152 $params['TOOLTIPS'][] = $link['description'];
153 if ($params['toptab'] == '/plugins/'.$this->name.'/?type=iframe&group_id='.$params['group'].'&pageid='.$link['id_headermenu']) {
154 $params['selected'] = (count($params['DIRS'])-1);
165 * getAvailableLinks - get all the links from the db of certain kind
167 * @param string the type of menu links search in db
168 * @return array the available links
170 function getAvailableLinks($linkmenu) {
171 $links = db_query_params('select * FROM plugin_headermenu where linkmenu = $1', array($linkmenu));
172 $availableLinks = array();
173 while ($arr = db_fetch_array($links)) {
174 $availableLinks[] = $arr;
176 return $availableLinks;
180 * getAllAvailableLinks - get all the links from the db
182 * @return array the available links
184 function getAllAvailableLinks() {
185 $availableOuterLinks = $this->getAvailableLinks('outermenu');
186 $availableHeaderLinks = $this->getAvailableLinks('headermenu');
187 return array_merge($availableOuterLinks, $availableHeaderLinks);
191 * addLink - add a new valid link
193 * @param string $url the url
194 * @param string $name the displayed name
195 * @param string $description a short description (to help administration)
196 * @param string $linkmenu linkmenu entry : headermenu or outermenu
197 * @param string $linktype
198 * @param string $htmlcode
199 * @return bool success or not
201 function addLink($url, $name, $description, $linkmenu, $linktype = 'url', $htmlcode = '') {
202 $res = db_query_params('insert into plugin_headermenu (url, name, description, is_enable, linkmenu, linktype, htmlcode)
203 values ($1, $2, $3, $4, $5, $6, $7)',
220 * deleteLink - delete a link
222 * @param int $idLink the link id
223 * @return bool success or not
225 function deleteLink($idLink) {
226 $res = db_query_params('delete from plugin_headermenu where id_headermenu = $1', array($idLink));
233 function updateLinkStatus($idLink, $linkStatus) {
234 $res = db_query_params('update plugin_headermenu set is_enable = $1 where id_headermenu = $2', array($linkStatus, $idLink));
241 function getLink($idLink) {
242 $res = db_query_params('select * from plugin_headermenu where id_headermenu = $1', array($idLink));
243 if (db_numrows($res) == 1) {
244 return db_fetch_array($res);
250 * updateLink - update a valid link
252 * @param int $idLink the link id to be updated
253 * @param string $url the url
254 * @param string $name the displayed name
255 * @param string $description a short description (to help administration)
256 * @param string $linkmenu linkmenu entry : headermenu or outermenu
257 * @param string $linktype : url or htmlcode, default is url
258 * @param string $htmlcode
259 * @return bool success or not
261 function updateLink($idLink, $url, $name, $description, $linkmenu, $linktype = 'url', $htmlcode ='') {
262 $res = db_query_params('update plugin_headermenu set url = $1, name = $2, description = $3, linkmenu = $4, linktype = $5, htmlcode = $6
263 where id_headermenu = $7',
264 array($url, $name, $description, $linkmenu, $linktype, $htmlcode, $idLink));
272 * pageView - display a static html code
274 * @param int the page id
275 * @return string the html code
277 function pageView($pageid) {
278 $link = $this->getLink($pageid);
279 return $link['htmlcode'];
283 * iframeView - display the iframe
285 * @param int the iframe id
286 * @return string the html code
288 function iframeView($pageid) {
293 * getHeader - initialize header and js
295 * @param string type : user, project, globaladmin (aka group)
296 * @return bool success or not
298 function getHeader($type) {
301 case 'globaladmin': {
302 session_require_global_perm('forge_admin');
304 require_once($gfwww.'admin/admin_utils.php');
306 use_javascript('scripts/HeaderMenuController.js');
307 use_javascript('/js/sortable.js');
308 site_admin_header(array('title'=>_('Site Global Menu Admin'), 'toptab' => ''));
313 $link = $this->getLink($this->pageid);
314 $group_id = getIntFromRequest('group_id');
316 $params['toptab'] = '/plugins/headermenu/?type=pageview&group_id='.$group_id.'&pageid='.$this->pageid;
317 $params['group'] = $group_id;
318 $params['title'] = $link['name'];
319 site_project_header($params);
321 site_header(array('title'=> $link['name'], 'toptab' => '/plugins/headermenu/?type=pageview&pageid='.$this->pageid));
326 case 'projectadmin': {
328 use_javascript('scripts/HeaderMenuController.js');
329 use_javascript('/js/sortable.js');
330 site_header(array('title'=>_('Project Menu Admin'), 'toptab' => ''));
339 * getGlobalAdminView - display the Global Admin View
343 function getGlobalAdminView() {
345 $user = session_get_user();
346 include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
351 * getProjectAdminView - display the Project Admin View
355 function getProjectAdminView() {
357 $user = session_get_user();
358 include $gfplugins.$this->name.'/view/admin/viewProjectConfiguration.php';
363 * getPluginDescription - display the description of this plugin in pluginman admin page
365 * @return string the description
367 function getPluginDescription() {
368 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).');