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 HeaderMenu 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&pageid='.$link['id_headermenu'];
142 $params['TITLES'][] = $link['name'];
143 $params['TOOLTIPS'][] = $link['description'];
147 $params['DIRS'][] = '/plugins/'.$this->name.'/?type=iframe&pageid='.$link['id_headermenu'];
148 $params['TITLES'][] = $link['name'];
149 $params['TOOLTIPS'][] = $link['description'];
159 * getAvailableLinks - get all the links from the db of certain kind
161 * @param string the type of menu links search in db
162 * @return array the available links
164 function getAvailableLinks($linkmenu) {
165 $links = db_query_params('select * FROM plugin_headermenu where linkmenu = $1', array($linkmenu));
166 $availableLinks = array();
167 while ($arr = db_fetch_array($links)) {
168 $availableLinks[] = $arr;
170 return $availableLinks;
174 * getAllAvailableLinks - get all the links from the db
176 * @return array the available links
178 function getAllAvailableLinks() {
179 $availableOuterLinks = $this->getAvailableLinks('outermenu');
180 $availableHeaderLinks = $this->getAvailableLinks('headermenu');
181 return array_merge($availableOuterLinks, $availableHeaderLinks);
185 * addLink - add a new valid link
187 * @param string $url the url
188 * @param string $name the displayed name
189 * @param string $description a short description (to help administration)
190 * @param string $linkmenu linkmenu entry : headermenu or outermenu
191 * @param string $linktype
192 * @param string $htmlcode
193 * @return bool success or not
195 function addLink($url, $name, $description, $linkmenu, $linktype = 'url', $htmlcode = '') {
196 $res = db_query_params('insert into plugin_headermenu (url, name, description, is_enable, linkmenu, linktype, htmlcode)
197 values ($1, $2, $3, $4, $5, $6, $7)',
214 * deleteLink - delete a link
216 * @param int $idLink the link id
217 * @return bool success or not
219 function deleteLink($idLink) {
220 $res = db_query_params('delete from plugin_headermenu where id_headermenu = $1', array($idLink));
227 function updateLinkStatus($idLink, $linkStatus) {
228 $res = db_query_params('update plugin_headermenu set is_enable = $1 where id_headermenu = $2', array($linkStatus, $idLink));
235 function getLink($idLink) {
236 $res = db_query_params('select * from plugin_headermenu where id_headermenu = $1', array($idLink));
237 if (db_numrows($res) == 1) {
238 return db_fetch_array($res);
244 * updateLink - update a valid link
246 * @param int $idLink the link id to be updated
247 * @param string $url the url
248 * @param string $name the displayed name
249 * @param string $description a short description (to help administration)
250 * @param string $linkmenu linkmenu entry : headermenu or outermenu
251 * @param string $linktype : url or htmlcode, default is url
252 * @param string $htmlcode
253 * @return bool success or not
255 function updateLink($idLink, $url, $name, $description, $linkmenu, $linktype = 'url', $htmlcode ='') {
256 $res = db_query_params('update plugin_headermenu set url = $1, name = $2, description = $3, linkmenu = $4, linktype = $5, htmlcode = $6
257 where id_headermenu = $7',
258 array($url, $name, $description, $linkmenu, $linktype, $htmlcode, $idLink));
266 * pageView - display a static html code
268 * @param int the page id
269 * @return string the html code
271 function pageView($pageid) {
272 $link = $this->getLink($pageid);
273 return $link['htmlcode'];
277 * iframeView - display the iframe
279 * @param int the iframe id
280 * @return string the html code
282 function iframeView($pageid) {
287 * getHeader - initialize header and js
289 * @param string type : user, project, globaladmin (aka group)
290 * @return bool success or not
292 function getHeader($type) {
295 case 'globaladmin': {
296 session_require_global_perm('forge_admin');
298 require_once($gfwww.'admin/admin_utils.php');
300 use_javascript('scripts/HeaderMenuController.js');
301 use_javascript('/js/sortable.js');
302 site_admin_header(array('title'=>_('Site Global Menu Admin'), 'toptab' => ''));
307 $link = $this->getLink($this->pageid);
308 site_header(array('title'=> $link['name'], 'toptab' => '/plugins/headermenu/?pageview&pageid='.$this->pageid));
312 case 'projectadmin': {
314 site_header(array('title'=>_('Project Menu Admin'), 'toptab' => ''));
323 * getGlobalAdminView - display the Global Admin View
327 function getGlobalAdminView() {
329 $user = session_get_user();
330 include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
335 * getProjectAdminView - display the Project Admin View
339 function getProjectAdminView() {
341 $user = session_get_user();
342 include $gfplugins.$this->name.'/view/admin/viewProjectConfiguration.php';
347 * getPluginDescription - display the description of this plugin in pluginman admin page
349 * @return string the description
351 function getPluginDescription() {
352 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).');