1<?php
2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
3//
4// All Rights Reserved. See copyright.txt for details and a complete list of authors.
5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
6// $Id$
7
8//this script may only be included - so its better to die if called directly.
9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) {
10	header("location: index.php");
11	exit;
12}
13
14/**
15 * @return array
16 */
17function module_breadcrumbs_info()
18{
19	return [
20		'name' => tra('Breadcrumbs'),
21		'description' => tra('A hierarchy of where you are. Ex.: Home > Section1 > Subsection C.'),
22		'prefs' => ['feature_breadcrumbs'],
23		'params' => [
24			'label' => [
25				'name' => tra('Label'),
26				'description' => tra('Label preceding the crumbs.'),
27				'filter' => 'text',
28				'default' => 'Location : ',
29			],
30			'menuId' => [
31				'name' => tra('Menu Id'),
32				'description' => tra('Menu to take the crumb trail from.'),
33				'filter' => 'int',
34				'default' => 0,
35				'profile_reference' => 'menu',
36			],
37			'menuStartLevel' => [
38				'name' => tra('Menu Start Level'),
39				'description' => tra('Lowest level of the menu to display.'),
40				'filter' => 'int',
41				'default' => null,
42			],
43			'menuStopLevel' => [
44				'name' => tra('Menu Stop Level'),
45				'description' => tra('Highest level of the menu to display.'),
46				'filter' => 'int',
47				'default' => null,
48			],
49			'showFirst' => [
50				'name' => tra('Show Site Crumb'),
51				'description' => tra('Display the first crumb, usually the site, when using menu crumbs.'),
52				'filter' => 'alpha',
53				'default' => 'y',
54			],
55			'showLast' => [
56				'name' => tra('Show Page Crumb'),
57				'description' => tra('Display the last crumb, usually the page, when using menu crumbs.'),
58				'filter' => 'alpha',
59				'default' => 'y',
60			],
61			'showLinks' => [
62				'name' => tra('Show Crumb Links'),
63				'description' => tra('Display links on the crumbs.'),
64				'filter' => 'alpha',
65				'default' => 'y',
66			],
67		],
68	];
69}
70
71/**
72 * @param $mod_reference
73 * @param $module_params
74 */
75function module_breadcrumbs($mod_reference, $module_params)
76{
77	global $prefs, $crumbs;
78	$smarty = TikiLib::lib('smarty');
79	if (! isset($module_params['label'])) {
80		if ($prefs['feature_siteloclabel'] === 'y') {
81			$module_params['label'] = 'Location : ';
82		}
83	}
84	$binfo = module_breadcrumbs_info();
85	$defaults = [];
86	foreach ($binfo['params'] as $k => $v) {
87		$defaults[$k] = $v['default'];
88	}
89	$module_params = array_merge($defaults, $module_params);
90
91	if (! empty($module_params['menuId'])) {
92		include_once('lib/breadcrumblib.php');
93
94		$newCrumbs = breadcrumb_buildMenuCrumbs($crumbs, $module_params['menuId'], $module_params['menuStartLevel'], $module_params['menuStopLevel']);
95		if ($newCrumbs !== $crumbs) {
96			$crumbs = $newCrumbs;
97		}
98	}
99
100	if ($module_params['showFirst'] === 'n') {
101		$crumbs[0]->hidden = true;
102	}
103	if ($module_params['showLast'] === 'n' && ($module_params['showFirst'] === 'n' || count($crumbs) > 1)) {
104		$crumbs[count($crumbs) - 1]->hidden = true;
105	}
106
107	$hide = true;
108	foreach ($crumbs as $crumb) {
109		if (! $crumb->hidden) {
110			$hide = false;
111		}
112	}
113	$smarty->assign('crumbs_all_hidden', $hide);
114
115	$smarty->assign_by_ref('trail', $crumbs);
116
117	$smarty->assign('module_params', $module_params);
118}
119