This file is indexed.

/usr/share/gforge/plugins/headermenu/common/headermenuPlugin.class.php is in fusionforge-plugin-headermenu 5.3.2+20141104-3+deb8u3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
<?php

/**
 * headermenuPlugin Class
 *
 * Copyright 2012-2013, Franck Villaume - TrivialDev
 * http://fusionforge.org
 *
 * This file is part of FusionForge. FusionForge is free software;
 * you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the Licence, or (at your option)
 * any later version.
 *
 * FusionForge is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

class headermenuPlugin extends Plugin {

	var $pageid;

	function __construct() {
		$this->Plugin();
		$this->name = 'headermenu';
		$this->text = _('Menu Tabs Manager');
		$this->_addHook('headermenu');
		$this->_addHook('site_admin_option_hook');
		$this->_addHook('outermenu');
		$this->_addHook('groupisactivecheckbox'); // The "use ..." checkbox in editgroupinfo
		$this->_addHook('groupisactivecheckboxpost');
		$this->_addHook('groupmenu');
		$this->_addHook('project_admin_plugins');
		$this->_addHook('clone_project_from_template');
		$this->_addHook('group_delete');
	}

	function CallHook($hookname, &$params) {
		switch ($hookname) {
			case 'outermenu': {
				$this->getOuterLink($params);
				break;
			}
			case 'site_admin_option_hook': {
				echo '<li>'.$this->getAdminOptionLink().'</li>';
				break;
			}
			case 'groupmenu': {
				$group_id = $params['group'];
				$project = group_get_object($group_id);
				if ($project->usesPlugin($this->name)) {
					$this->getGroupLink($params);
				}
				break;
			}
			case 'project_admin_plugins': {
				$group_id = $params['group_id'];
				$project = group_get_object($group_id);
				if ($project->usesPlugin($this->name)) {
					echo '<p>'.util_make_link('/plugins/'.$this->name.'/?type=projectadmin&amp;group_id='.$group_id,
					     _('Menu Tabs Manager Admin'), array('class' => 'tabtitle', 'title' => _('Add/Remove/Activate/Desactivate tabs'))) . '</p>';
				}
				break;
			}
			case 'clone_project_from_template': {
				$links = array();
				$res = db_query_params('SELECT url, name, description, is_enable, linkmenu, linktype, htmlcode, ordering FROM plugin_headermenu WHERE project = $1',
							array($params['template']->getID()));
				while ($row = db_fetch_array($res)) {
					$linksData = array();
					$linksData['url'] = $row['url'];
					$linksData['name'] = $row['name'];
					$linksData['description'] = $row['description'];
					$linksData['is_enable'] = $row['is_enable'];
					$linksData['linkmenu'] = $row['linkmenu'];
					$linksData['linktype'] = $row['linktype'];
					$linksData['htmlcode'] = $row['htmlcode'];
					$linksData['ordering'] = $row['ordering'];
					$links[] = $linksData;
				}

				foreach ($links as $link) {
					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)',
							array($link['url'],
								$link['name'],
								$link['description'],
								$link['is_enable'],
								$link['linkmenu'],
								$link['linktype'],
								$link['htmlcode'],
								$link['ordering'],
								$params['project']->getID()));
				}
				break;
			}
			case 'group_delete': {
				$links = $this->getAvailableLinks('groupmenu', $params['group_id']);
				foreach ($links as $link) {
					$this->deleteLink($link['id_headermenu']);
				}
			}
		}
	}

	function getAdminOptionLink() {
		return util_make_link('/plugins/'.$this->name.'/?type=globaladmin', _('Global HeaderMenu admin'), array('class' => 'tabtitle', 'title' => _('Direct link to global configuration of this plugin')));
	}

	/**
	 * headermenu - Display the links following the template
	 *
	 * @param	array	$params
	 * @return	bool	true...
	 */
	function headermenu($params) {
		$availableLinks = $this->getAvailableLinks('headermenu');
		foreach ($availableLinks as $link) {
			if ($link['is_enable']) {
				$ahref = '<a href="'.$link['url'].'">'.htmlspecialchars($link['name']).'</a>';
				$template = isset($params['template']) ?  $params['template'] : ' | {menu}';
				echo str_replace('{menu}', $ahref, $template);
			}
		}
		return true;
	}

	/**
	 * getOuterLink - update the links before generate the tab.
	 *
	 * @param 	array	$params	hook params array
	 * @return	bool	true...
	 */
	function getOuterLink($params) {
		$availableLinks = $this->getAvailableLinks('outermenu');
		foreach ($availableLinks as $link) {
			if ($link['is_enable']) {
				switch ($link['linktype']) {
					case 'url': {
						$params['DIRS'][] = $link['url'];
						$params['TITLES'][] = $link['name'];
						$params['TOOLTIPS'][] = $link['description'];
						break;
					}
					case 'htmlcode': {
						$params['DIRS'][] = '/plugins/'.$this->name.'/?type=pageview&amp;pageid='.$link['id_headermenu'];
						$params['TITLES'][] = $link['name'];
						$params['TOOLTIPS'][] = $link['description'];
						break;
					}
				}
			}
		}
		return true;
	}

	/**
	 * getGroupLink - update the links before generate the tab.
	 *
	 * @param	array	$params	hook params array
	 * @return	bool	true...
	 */
	function getGroupLink($params) {
		$availableLinks = $this->getAvailableLinks('groupmenu', $params['group']);
		foreach ($availableLinks as $link) {
			if ($link['is_enable']) {
				switch ($link['linktype']) {
					case 'url': {
						$params['DIRS'][] = $link['url'];
						$params['TITLES'][] = $link['name'];
						$params['TOOLTIPS'][] = $link['description'];
						break;
					}
					case 'htmlcode': {
						$params['DIRS'][] = '/plugins/'.$this->name.'/?type=pageview&amp;group_id='.$params['group'].'&amp;pageid='.$link['id_headermenu'];
						$params['TITLES'][] = $link['name'];
						$params['TOOLTIPS'][] = $link['description'];
						if (isset($params['toptab']) && ($params['toptab'] == '/plugins/'.$this->name.'/?type=pageview&amp;group_id='.$params['group'].'&amp;pageid='.$link['id_headermenu'])) {
							$params['selected'] = (count($params['DIRS'])-1);
						}
						break;
					}
					case 'iframe': {
						$params['DIRS'][] = '/plugins/'.$this->name.'/?type=iframeview&amp;group_id='.$params['group'].'&amp;pageid='.$link['id_headermenu'];
						$params['TITLES'][] = $link['name'];
						$params['TOOLTIPS'][] = $link['description'];
						if (isset($params['toptab']) && ($params['toptab'] == '/plugins/'.$this->name.'/?type=iframeview&amp;group_id='.$params['group'].'&amp;pageid='.$link['id_headermenu'])) {
							$params['selected'] = (count($params['DIRS'])-1);
						}
						break;
					}
				}
			}
		}
		return true;
	}

	/**
	 * getAvailableLinks - get all the links from the db of certain kind
	 *
	 * @param	string	$linkmenu	the type of menu links search in db
	 * @param	int		$project	the group_id. Default is 0 meaning : forge level
	 * @return	array	the available links
	 */
	function getAvailableLinks($linkmenu, $project = 0) {
		$links = db_query_params('select * FROM plugin_headermenu where linkmenu = $1 and project = $2 order by ordering asc', array($linkmenu, $project));
		$availableLinks = array();
		while ($arr = db_fetch_array($links)) {
			$availableLinks[] = $arr;
		}
		return $availableLinks;
	}

	/**
	 * getAllAvailableLinks - get all the links from the db
	 *
	 * @return	array	the available links
	 */
	function getAllAvailableLinks() {
		$availableOuterLinks = $this->getAvailableLinks('outermenu');
		$availableHeaderLinks = $this->getAvailableLinks('headermenu');
		return array_merge($availableOuterLinks, $availableHeaderLinks);
	}

	/**
	 * setLinksOrder - set the linkOrder for a set of links id
	 *
	 * @param	array	$linksOrder array of ordered links id
	 * @return	bool	success or not
	 */
	function setLinksOrder($linksOrder) {
		for ($i =0; $i < count($linksOrder); $i++) {
			$res = db_query_params('update plugin_headermenu set ordering = $1 where id_headermenu = $2', array($i, $linksOrder[$i]));
			if (!$res)
				return false;
		}
		return true;
	}

	/**
	 * addLink - add a new valid link
	 *
	 * @param	string	$url the url
	 * @param	string	$name the displayed name
	 * @param	string	$description a short description (to help administration)
	 * @param	string	$linkmenu linkmenu entry : headermenu or outermenu
	 * @param	string	$linktype
	 * @param	int	$project the group_id or 0 meaning forge level
	 * @param	string	$htmlcode
	 * @param	integer	$ordering
	 * @return	bool	success or not
	 */
	function addLink($url, $name, $description, $linkmenu, $linktype = 'url', $project = 0, $htmlcode = '', $ordering = NULL) {
		if ($ordering == NULL) {
			$res = db_query_params('SELECT MAX(ordering) as ordering FROM plugin_headermenu WHERE project=$1 AND linkmenu=$2',
				array($project, $linkmenu));
			if ($res) {
				$ordering = db_result($res, 0, 'ordering')+1;
			} else {
				$ordering = 0;
			}
		}

		$res = db_query_params('insert into plugin_headermenu (url, name, description, is_enable, linkmenu, linktype, project, htmlcode, ordering)
					values ($1, $2, $3, $4, $5, $6, $7, $8, $9)',
					array(
						$url,
						$name,
						$description,
						1,
						$linkmenu,
						$linktype,
						$project,
						$htmlcode,
						$ordering
					));
		if (!$res)
			return false;

		return true;
	}

	/**
	 * deleteLink - delete a link
	 *
	 * @param	int		$idLink the link id
	 * @return	bool	success or not
	 */
	function deleteLink($idLink) {
		$res = db_query_params('delete from plugin_headermenu where id_headermenu = $1', array($idLink));
		if ($res) {
			return true;
		}
		return false;
	}

	/**
	 * updateLinkStatus - update the link status
	 *
	 * @param	int		$idLink the link id
	 * @param	int		$linkStatus the new status of the link id
	 * @return	bool	success or not
	 */
	function updateLinkStatus($idLink, $linkStatus) {
		$res = db_query_params('update plugin_headermenu set is_enable = $1 where id_headermenu = $2', array($linkStatus, $idLink));
		if ($res) {
			return true;
		}
		return false;
	}

	/**
	 * getLink - get all informations about a link
	 *
	 * @param	int	$idLink the link id
	 * @return	array	the link informations
	 */
	function getLink($idLink) {
		$res = db_query_params('select * from plugin_headermenu where id_headermenu = $1', array($idLink));
		if (db_numrows($res) == 1) {
			return db_fetch_array($res);
		}
		return false;
	}

	/**
	 * updateLink - update a valid link
	 *
	 * @param	int		$idLink the link id to be updated
	 * @param	string	$url the url
	 * @param	string	$name the displayed name
	 * @param	string	$description a short description (to help administration)
	 * @param	string	$linkmenu linkmenu entry : headermenu or outermenu
	 * @param	string	$linktype : url or htmlcode, default is url
	 * @param	string	$htmlcode
	 * @return	bool	success or not
	 */
	function updateLink($idLink, $url, $name, $description, $linkmenu, $linktype = 'url', $htmlcode ='') {
		$res = db_query_params('update plugin_headermenu set url = $1, name = $2, description = $3, linkmenu = $4, linktype = $5, htmlcode = $6
					where id_headermenu = $7',
				array($url, $name, $description, $linkmenu, $linktype, $htmlcode, $idLink));
		if ($res) {
			return true;
		}
		return false;
	}

	/**
	 * pageView - display an HTML Page
	 *
	 * @param	int		$pageid	the page id
	 * @return	string	the html code
	 */
	function pageView($pageid) {
		$link = $this->getLink($pageid);
		if ($link) {
			return $link['htmlcode'];
		} else {
			return '<p class="error" >'._('Cannot retrieve the page').'</p>';
		}
	}

	/**
	 * iframeView - display the iframe
	 *
	 * @param	int		$pageid	the iframe id
	 * @return	string	the html code
	 */
	 function iframeView($pageid) {
		$link = $this->getLink($pageid);
		if ($link) {
			return '<iframe src="'.rtrim($link['url'],'/').'" frameborder="0" height="600px" width="100%"></iframe>';
		} else {
			return '<p class="error" >'._('Cannot retrieve the page').'</p>';
		}
	 }

	/**
	 * getHeader - initialize header and js
	 *
	 * @param	string	$type : user, project, globaladmin (aka group)
	 * @return	bool	success or not
	 */
	function getHeader($type) {
		$returned = false;
		switch ($type) {
			case 'globaladmin': {
				session_require_global_perm('forge_admin');
				global $gfwww;
				require_once($gfwww.'admin/admin_utils.php');
				html_use_jquery();
				html_use_jqueryui();
				use_javascript('/plugins/'.$this->name.'/scripts/HeaderMenuController.js');
				use_javascript('/js/sortable.js');
				site_admin_header(array('title'=>_('Site Global Menu Admin'), 'toptab' => ''));
				$returned = true;
				break;
			}
			case 'pageview':
			case 'iframeview': {
				$link = $this->getLink($this->pageid);
				$group_id = getIntFromRequest('group_id');
				if ($group_id) {
					$params['toptab'] = '/plugins/'.$this->name.'/?type='.$type.'&amp;group_id='.$group_id.'&amp;pageid='.$this->pageid;
					$params['group'] = $group_id;
					$params['title'] = $link['name'];
					site_project_header($params);
				} else {
					site_header(array('title'=> $link['name'], 'toptab' => '/plugins/'.$this->name.'/?type='.$type.'&amp;pageid='.$this->pageid));
				}
				$returned = true;
				break;
			}
			case 'projectadmin': {
				html_use_jquery();
				html_use_jqueryui();
				use_javascript('/plugins/'.$this->name.'/scripts/HeaderMenuController.js');
				use_javascript('/js/sortable.js');
				$group_id = getIntFromRequest('group_id');
				$params['toptab'] = 'admin';
				$params['group'] = $group_id;
				$params['title'] = _('Menu Tabs Manager Admin');
				site_project_header($params);
				$returned = true;
				break;
			}
		}
		return $returned;
	}

	/**
	 * getGlobalAdminView - display the Global Admin View
	 *
	 * @return	bool	true
	 */
	function getGlobalAdminView() {
		global $gfplugins;
		$user = session_get_user();
		include $gfplugins.$this->name.'/view/admin/viewGlobalConfiguration.php';
		return true;
	}

	/**
	 * getProjectAdminView - display the Project Admin View
	 *
	 * @return	bool	true
	 */
	function getProjectAdminView() {
		global $gfplugins;
		$user = session_get_user();
		include $gfplugins.$this->name.'/view/admin/viewProjectConfiguration.php';
		return true;
	}

	/**
	 * getPluginDescription - display the description of this plugin in pluginman admin page
	 *
	 * @return	string	the description
	 */
	function getPluginDescription() {
		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).');
	}
}