4 * headermenuPlugin Class
6 * Copyright 2012-2013, 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 = 'Menu Tabs Manager';
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');
40 $this->_addHook('clone_project_from_template');
41 $this->_addHook('group_delete');
44 function CallHook($hookname, &$params) {
47 $this->getOuterLink($params);
50 case 'site_admin_option_hook': {
51 echo '<li>'.$this->getAdminOptionLink().'</li>';
55 $group_id = $params['group'];
56 $project = group_get_object($group_id);
57 if ($project->usesPlugin($this->name)) {
58 $this->getGroupLink($params);
62 case 'project_admin_plugins': {
63 $group_id = $params['group_id'];
64 $project = group_get_object($group_id);
65 if ($project->usesPlugin($this->name)) {
66 echo '<p>'.util_make_link('/plugins/'.$this->name.'/?type=projectadmin&group_id='.$group_id,
67 _('Menu Tabs Manager Admin'), array('class' => 'tabtitle', 'title' => _('Add/Remove/Activate/Desactivate tabs'))) . '</p>';
71 case 'clone_project_from_template': {
73 $res = db_query_params('SELECT url, name, description, is_enable, linkmenu, linktype, htmlcode, ordering FROM plugin_headermenu WHERE project = $1',
74 array($params['template']->getID()));
75 while ($row = db_fetch_array($res)) {
77 $linksData['url'] = $row['url'];
78 $linksData['name'] = $row['name'];
79 $linksData['description'] = $row['description'];
80 $linksData['is_enable'] = $row['is_enable'];
81 $linksData['linkmenu'] = $row['linkmenu'];
82 $linksData['linktype'] = $row['linktype'];
83 $linksData['htmlcode'] = $row['htmlcode'];
84 $linksData['ordering'] = $row['ordering'];
85 $links[] = $linksData;
88 foreach ($links as $link) {
89 db_query_params('INSERT INTO plugin_headermenu (url, name, description, is_enable, linkmenu, linktype, htmlcode, ordering, project) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)',
98 $params['project']->getID()));
102 case 'group_delete': {
103 $links = $this->getAvailableLinks('groupmenu', $params['group_id']);
104 foreach ($links as $link) {
105 $this->deleteLink($link['id_headermenu']);
112 function getAdminOptionLink() {
113 return util_make_link('/plugins/'.$this->name.'/?type=globaladmin', _('Global HeaderMenu admin'), array('class' => 'tabtitle', 'title' => _('Direct link to global configuration of this plugin')));
117 * headermenu - Display the links following the template
120 * @return bool true...
122 function headermenu($params) {
123 $availableLinks = $this->getAvailableLinks('headermenu');
124 foreach ($availableLinks as $link) {
125 if ($link['is_enable']) {
126 $ahref = '<a href="'.$link['url'].'">'.htmlspecialchars($link['name']).'</a>';
127 $template = isset($params['template']) ? $params['template'] : ' | {menu}';
128 echo str_replace('{menu}', $ahref, $template);
135 * getOuterLink - update the links before generate the tab.
137 * @param array hook params array
138 * @return bool true...
140 function getOuterLink($params) {
141 $availableLinks = $this->getAvailableLinks('outermenu');
142 foreach ($availableLinks as $link) {
143 if ($link['is_enable']) {
144 switch ($link['linktype']) {
146 $params['DIRS'][] = $link['url'];
147 $params['TITLES'][] = $link['name'];
148 $params['TOOLTIPS'][] = $link['description'];
152 $params['DIRS'][] = '/plugins/'.$this->name.'/?type=pageview&pageid='.$link['id_headermenu'];
153 $params['TITLES'][] = $link['name'];
154 $params['TOOLTIPS'][] = $link['description'];
164 * getGroupLink - update the links before generate the tab.
166 * @param array hook params array
167 * @return bool true...
169 function getGroupLink($params) {
170 $availableLinks = $this->getAvailableLinks('groupmenu', $params['group']);
171 foreach ($availableLinks as $link) {
172 if ($link['is_enable']) {
173 switch ($link['linktype']) {
175 $params['DIRS'][] = $link['url'];
176 $params['TITLES'][] = $link['name'];
177 $params['TOOLTIPS'][] = $link['description'];
181 $params['DIRS'][] = '/plugins/'.$this->name.'/?type=pageview&group_id='.$params['group'].'&pageid='.$link['id_headermenu'];
182 $params['TITLES'][] = $link['name'];
183 $params['TOOLTIPS'][] = $link['description'];
184 if (isset($params['toptab']) && ($params['toptab'] == '/plugins/'.$this->name.'/?type=pageview&group_id='.$params['group'].'&pageid='.$link['id_headermenu'])) {
185 $params['selected'] = (count($params['DIRS'])-1);
190 $params['DIRS'][] = '/plugins/'.$this->name.'/?type=iframeview&group_id='.$params['group'].'&pageid='.$link['id_headermenu'];
191 $params['TITLES'][] = $link['name'];
192 $params['TOOLTIPS'][] = $link['description'];
193 if (isset($params['toptab']) && ($params['toptab'] == '/plugins/'.$this->name.'/?type=iframeview&group_id='.$params['group'].'&pageid='.$link['id_headermenu'])) {
194 $params['selected'] = (count($params['DIRS'])-1);
205 * getAvailableLinks - get all the links from the db of certain kind
207 * @param string the type of menu links search in db
208 * @param int the group_id. Default is 0 meaning : forge level
209 * @return array the available links
211 function getAvailableLinks($linkmenu, $project = 0) {
212 $links = db_query_params('select * FROM plugin_headermenu where linkmenu = $1 and project = $2 order by ordering asc', array($linkmenu, $project));
213 $availableLinks = array();
214 while ($arr = db_fetch_array($links)) {
215 $availableLinks[] = $arr;
217 return $availableLinks;
221 * getAllAvailableLinks - get all the links from the db
223 * @return array the available links
225 function getAllAvailableLinks() {
226 $availableOuterLinks = $this->getAvailableLinks('outermenu');
227 $availableHeaderLinks = $this->getAvailableLinks('headermenu');
228 return array_merge($availableOuterLinks, $availableHeaderLinks);
232 * setLinksOrder - set the linkOrder for a set of links id
234 * @param array $linksOrder array of ordered links id
235 * @return bool success or not
237 function setLinksOrder($linksOrder) {
238 for ($i =0; $i < count($linksOrder); $i++) {
239 $res = db_query_params('update plugin_headermenu set ordering = $1 where id_headermenu = $2', array($i, $linksOrder[$i]));
247 * addLink - add a new valid link
249 * @param string $url the url
250 * @param string $name the displayed name
251 * @param string $description a short description (to help administration)
252 * @param string $linkmenu linkmenu entry : headermenu or outermenu
253 * @param string $linktype
254 * @param int $project the group_id or 0 meaning forge level
255 * @param string $htmlcode
256 * @param integer $ordering
257 * @return bool success or not
259 function addLink($url, $name, $description, $linkmenu, $linktype = 'url', $project = 0, $htmlcode = '', $ordering = NULL) {
260 if ($ordering == NULL) {
261 $res = db_query_params('SELECT MAX(ordering) as ordering FROM plugin_headermenu WHERE project=$1 AND linkmenu=$2',
262 array($project, $linkmenu));
264 $ordering = db_result($res, 0, 'ordering')+1;
270 $res = db_query_params('insert into plugin_headermenu (url, name, description, is_enable, linkmenu, linktype, project, htmlcode, ordering)
271 values ($1, $2, $3, $4, $5, $6, $7, $8, $9)',
290 * deleteLink - delete a link
292 * @param int $idLink the link id
293 * @return bool success or not
295 function deleteLink($idLink) {
296 $res = db_query_params('delete from plugin_headermenu where id_headermenu = $1', array($idLink));
304 * updateLinkStatus - update the link status
306 * @param int $idLink the link id
307 * @param int $linkStatus the new status of the link id
308 * @return bool success or not
310 function updateLinkStatus($idLink, $linkStatus) {
311 $res = db_query_params('update plugin_headermenu set is_enable = $1 where id_headermenu = $2', array($linkStatus, $idLink));
319 * getLink - get all informations about a link
321 * @param int $idLink the link id
322 * @return array the link informations
324 function getLink($idLink) {
325 $res = db_query_params('select * from plugin_headermenu where id_headermenu = $1', array($idLink));
326 if (db_numrows($res) == 1) {
327 return db_fetch_array($res);
333 * updateLink - update a valid link
335 * @param int $idLink the link id to be updated
336 * @param string $url the url
337 * @param string $name the displayed name
338 * @param string $description a short description (to help administration)
339 * @param string $linkmenu linkmenu entry : headermenu or outermenu
340 * @param string $linktype : url or htmlcode, default is url
341 * @param string $htmlcode
342 * @return bool success or not
344 function updateLink($idLink, $url, $name, $description, $linkmenu, $linktype = 'url', $htmlcode ='') {
345 $res = db_query_params('update plugin_headermenu set url = $1, name = $2, description = $3, linkmenu = $4, linktype = $5, htmlcode = $6
346 where id_headermenu = $7',
347 array($url, $name, $description, $linkmenu, $linktype, $htmlcode, $idLink));
355 * pageView - display an HTML Page
357 * @param int the page id
358 * @return string the html code
360 function pageView($pageid) {
361 $link = $this->getLink($pageid);
363 return $link['htmlcode'];
365 return '<p class="error" >'._('Cannot retrieve the page').'</p>';
370 * iframeView - display the iframe
372 * @param int the iframe id
373 * @return string the html code
375 function iframeView($pageid) {
376 $link = $this->getLink($pageid);
378 return '<iframe src="'.rtrim($link['url'],'/').'" frameborder="0" height="600px" width="100%"></iframe>';
380 return '<p class="error" >'._('Cannot retrieve the page').'</p>';
385 * getHeader - initialize header and js
387 * @param string type : user, project, globaladmin (aka group)
388 * @return bool success or not
390 function getHeader($type) {
393 case 'globaladmin': {
394 session_require_global_perm('forge_admin');
396 require_once($gfwww.'admin/admin_utils.php');
399 use_javascript('scripts/HeaderMenuController.js');
400 use_javascript('/js/sortable.js');
401 site_admin_header(array('title'=>_('Site Global Menu Admin'), 'toptab' => ''));
407 $link = $this->getLink($this->pageid);
408 $group_id = getIntFromRequest('group_id');
410 $params['toptab'] = '/plugins/'.$this->name.'/?type='.$type.'&group_id='.$group_id.'&pageid='.$this->pageid;
411 $params['group'] = $group_id;
412 $params['title'] = $link['name'];
413 site_project_header($params);
415 site_header(array('title'=> $link['name'], 'toptab' => '/plugins/'.$this->name.'/?type='.$type.'&pageid='.$this->pageid));
420 case 'projectadmin': {
423 use_javascript('scripts/HeaderMenuController.js');
424 use_javascript('/js/sortable.js');
425 $group_id = getIntFromRequest('group_id');
426 $params['toptab'] = 'admin';
427 $params['group'] = $group_id;
428 $params['title'] = _('Menu Tabs Manager Admin');
429 site_project_header($params);
438 * getGlobalAdminView - display the Global Admin View
442 function getGlobalAdminView() {
444 $user = session_get_user();
445 include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
450 * getProjectAdminView - display the Project Admin View
454 function getProjectAdminView() {
456 $user = session_get_user();
457 include $gfplugins.$this->name.'/view/admin/viewProjectConfiguration.php';
462 * getPluginDescription - display the description of this plugin in pluginman admin page
464 * @return string the description
466 function getPluginDescription() {
467 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).');