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>';
56 function getAdminOptionLink() {
57 return util_make_link('/plugins/'.$this->name.'/?type=globaladmin', _('Global HeaderMenu admin'), array('class' => 'tabtitle', 'title' => _('Direct link to global configuration of this plugin')));
61 * getHeaderLink - generate the links following the template
63 * @return bool true...
65 function getHeaderLink() {
66 $availableLinks = $this->getAvailableLinks('headermenu');
67 foreach ($availableLinks as $link) {
68 if ($link['is_enable']) {
69 $ahref = '<a href="'.$link['url'].'">'.htmlspecialchars($link['name']).'</a>';
70 $template = isset($params['template']) ? $params['template'] : ' | {menu}';
71 echo str_replace('{menu}', $ahref, $template);
78 * getOuterLink - update the links before generate the tab.
80 * @param array hook params array
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'];
107 * getAvailableLinks - get all the links from the db of certain kind
109 * @param string the type of menu links search in db
110 * @return array the available links
112 function getAvailableLinks($linkmenu) {
113 $links = db_query_params('select * FROM plugin_headermenu where linkmenu = $1', array($linkmenu));
114 $availableLinks = array();
115 while ($arr = db_fetch_array($links)) {
116 $availableLinks[] = $arr;
118 return $availableLinks;
122 * getAllAvailableLinks - get all the links from the db
124 * @return array the available links
126 function getAllAvailableLinks() {
127 $availableOuterLinks = $this->getAvailableLinks('outermenu');
128 $availableHeaderLinks = $this->getAvailableLinks('headermenu');
129 return array_merge($availableOuterLinks, $availableHeaderLinks);
133 * addLink - add a new valid link
135 * @param string $url the url
136 * @param string $name the displayed name
137 * @param string $description a short description (to help administration)
138 * @param string $linkmenu linkmenu entry : headermenu or outermenu
139 * @param string $linktype
140 * @param string $htmlcode
141 * @return bool success or not
143 function addLink($url, $name, $description, $linkmenu, $linktype = 'url', $htmlcode = '') {
144 $res = db_query_params('insert into plugin_headermenu (url, name, description, is_enable, linkmenu, linktype, htmlcode)
145 values ($1, $2, $3, $4, $5, $6, $7)',
162 * deleteLink - delete a link
164 * @param int $idLink the link id
165 * @return bool success or not
167 function deleteLink($idLink) {
168 $res = db_query_params('delete from plugin_headermenu where id_headermenu = $1', array($idLink));
175 function updateLinkStatus($idLink, $linkStatus) {
176 $res = db_query_params('update plugin_headermenu set is_enable = $1 where id_headermenu = $2', array($linkStatus, $idLink));
183 function getLink($idLink) {
184 $res = db_query_params('select * from plugin_headermenu where id_headermenu = $1', array($idLink));
185 if (db_numrows($res) == 1) {
186 return db_fetch_array($res);
192 * updateLink - update a valid link
194 * @param int $idLink the link id to be updated
195 * @param string $url the url
196 * @param string $name the displayed name
197 * @param string $description a short description (to help administration)
198 * @param string $linkmenu linkmenu entry : headermenu or outermenu
199 * @param string $linktype : url or htmlcode, default is url
200 * @param string $htmlcode
201 * @return bool success or not
203 function updateLink($idLink, $url, $name, $description, $linkmenu, $linktype = 'url', $htmlcode ='') {
204 $res = db_query_params('update plugin_headermenu set url = $1, name = $2, description = $3, linkmenu = $4, linktype = $5, htmlcode = $6
205 where id_headermenu = $7',
206 array($url, $name, $description, $linkmenu, $linktype, $htmlcode, $idLink));
214 * pageView - display a static html code
216 * @param int the page id
217 * @return string the html code
219 function pageView($pageid) {
220 $link = $this->getLink($pageid);
221 return $link['htmlcode'];
225 * getHeader - initialize header and js
227 * @param string type : user, project, globaladmin (aka group)
228 * @return bool success or not
230 function getHeader($type) {
233 case 'globaladmin': {
234 session_require_global_perm('forge_admin');
236 require_once($gfwww.'admin/admin_utils.php');
238 use_javascript('scripts/HeaderMenuController.js');
239 use_javascript('/js/sortable.js');
240 site_admin_header(array('title'=>_('Site Global Menu Admin'), 'toptab' => ''));
245 $link = $this->getLink($this->pageid);
246 site_header(array('title'=> $link['name'], 'toptab' => '/plugins/headermenu/?pageview&pageid='.$this->pageid));
255 * getGlobalAdminView - display the Global Admin View
259 function getGlobalAdminView() {
261 $user = session_get_user();
262 include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
267 * getPluginDescription - display the description of this plugin in pluginman admin page
269 * @return string the description
271 function getPluginDescription() {
272 return _('Get the ability to set new links next to the login menu (headermenu) or in the main menu (outermenu).');