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');
38 function CallHook ($hookname, &$params) {
41 $this->getHeaderLink();
45 $this->getOuterLink($params);
48 case 'site_admin_option_hook': {
49 echo '<li>'.$this->getAdminOptionLink().'</li>';
57 function getAdminOptionLink() {
58 return util_make_link('/plugins/'.$this->name.'/?type=globaladmin', _('Global HeaderMenu admin'), array('class' => 'tabtitle', 'title' => _('Direct link to global configuration of this plugin')));
62 * getHeaderLink - generate the links following the template
64 * @return bool true...
66 function getHeaderLink() {
67 $availableLinks = $this->getAvailableLinks('headermenu');
68 foreach ($availableLinks as $link) {
69 if ($link['is_enable']) {
70 $ahref = '<a href="'.$link['url'].'">'.htmlspecialchars($link['name']).'</a>';
71 $template = isset($params['template']) ? $params['template'] : ' | {menu}';
72 echo str_replace('{menu}', $ahref, $template);
79 * getOuterLink - update the links before generate the tab.
81 * @return bool true...
83 function getOuterLink($params) {
84 $availableLinks = $this->getAvailableLinks('outermenu');
85 foreach ($availableLinks as $link) {
86 if ($link['is_enable']) {
87 switch ($link['linktype']) {
89 $params['DIRS'][] = $link['url'];
90 $params['TITLES'][] = $link['name'];
91 $params['TOOLTIPS'][] = $link['description'];
95 $params['DIRS'][] = '/plugins/'.$this->name.'/?type=pageview&pageid='.$link['id_headermenu'];
96 $params['TITLES'][] = $link['name'];
97 $params['TOOLTIPS'][] = $link['description'];
106 * getAvailableLinks - get all the links from the db of certain kind
108 * @param string the type of menu links search in db
109 * @return array the available links
111 function getAvailableLinks($linkmenu) {
112 $links = db_query_params('select * FROM plugin_headermenu where linkmenu = $1', array($linkmenu));
113 $availableLinks = array();
114 while ($arr = db_fetch_array($links)) {
115 $availableLinks[] = $arr;
117 return $availableLinks;
121 * getAllAvailableLinks - get all the links from the db
123 * @return array the available links
125 function getAllAvailableLinks() {
126 $availableOuterLinks = $this->getAvailableLinks('outermenu');
127 $availableHeaderLinks = $this->getAvailableLinks('headermenu');
128 return array_merge($availableOuterLinks, $availableHeaderLinks);
132 * addLink - add a new valid link
134 * @param string the url
135 * @param string the displayed name
136 * @param string a short description (to help administration)
137 * @param string linkmenu entry : headermenu or outermenu
138 * @return bool success or not
140 function addLink($url, $name, $description, $linkmenu, $linktype = 'url', $htmlcode = '') {
141 $res = db_query_params('insert into plugin_headermenu (url, name, description, is_enable, linkmenu, linktype, htmlcode)
142 values ($1, $2, $3, $4, $5, $6, $7)',
159 * deleteLink - delete a link
161 * @param int the link id
162 * @return bool success or not
164 function deleteLink($idLink) {
165 $res = db_query_params('delete from plugin_headermenu where id_headermenu = $1', array($idLink));
172 function updateLinkStatus($idLink, $linkStatus) {
173 $res = db_query_params('update plugin_headermenu set is_enable = $1 where id_headermenu = $2', array($linkStatus, $idLink));
180 function getLink($idLink) {
181 $res = db_query_params('select * from plugin_headermenu where id_headermenu = $1', array($idLink));
182 if (db_numrows($res) == 1) {
183 return db_fetch_array($res);
188 function updateLink($idLink, $url, $name, $description, $linkmenu, $linktype = 'url', $htmlcode ='') {
189 $res = db_query_params('update plugin_headermenu set url = $1, name = $2, description = $3, linkmenu = $4, linktype = $5, htmlcode = $6
190 where id_headermenu = $7',
191 array($url, $name, $description, $linkmenu, $linktype, $htmlcode, $idLink));
199 * pageView - display a static html code
201 * @param int the page id
202 * @return string the html code
204 function pageView($pageid) {
205 $link = $this->getLink($pageid);
206 return $link['htmlcode'];
210 * getHeader - initialize header and js
212 * @param string type : user, project, globaladmin (aka group)
213 * @return bool success or not
215 function getHeader($type) {
219 case 'globaladmin': {
220 session_require_global_perm('forge_admin');
222 require_once($gfwww.'admin/admin_utils.php');
223 use_javascript('/js/sortable.js');
224 site_admin_header(array('title'=>_('Site Global Menu Admin'), 'toptab' => ''));
229 $link = $this->getLink($this->pageid);
230 site_header(array('title'=> $link['name'], 'toptab' => '/plugins/headermenu/?pageview&pageid='.$this->pageid));
239 * getGlobalAdminView - display the Global Admin View
243 function getGlobalAdminView() {
245 $user = session_get_user();
246 include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
251 * getPluginDescription - display the description of this plugin in pluginman admin page
253 * @return string the description
255 function getPluginDescription() {
256 return _('Get the ability to set new links next to the login menu (headermenu) or in the main menu (outermenu).');