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
8function wikiplugin_footnotearea_info()
9{
10	return [
11		'name' => tra('Footnote Area'),
12		'documentation' => 'PluginFootnoteArea',
13		'description' => tra('Create automatically numbered footnotes (together with PluginFootnote)'),
14		'prefs' => ['wikiplugin_footnote'],
15		'iconname' => 'superscript',
16		'format' => 'html',
17		'introduced' => 3,
18		'params' => [
19			'class' => [
20				'required' => false,
21				'name' => tra('Class'),
22				'description' => tra('Filter footnotearea by footnote class'),
23				'since' => '17.0',
24				'default' => '',
25				'filter' => 'alnum',
26				'accepted' => tra('Valid CSS class'),
27			],
28			'sameasstyle' => [
29				'required' => false,
30				'name' => tra('SameAs Style'),
31				'description' => tra('Numbering style for sameas referencing.'),
32				'since' => '17.0',
33				'default' => 'disc',
34				'filter' => 'text',
35				'accepted' => tra('Valid Tiki ((Number Style))'),
36			],
37		],
38	];
39}
40
41/**
42 * @param $data
43 * @param $params
44 * @param $offset
45 * @param $context
46 * @return string
47 * @throws Exception
48 */
49function wikiplugin_footnotearea($data, $params, $offset, $context)
50{
51	$footnotes = $context->footnotes;
52	$smarty = TikiLib::lib('smarty');
53
54	if (isset($params['sameasstyle'])) {
55		$smarty->assign('sameType', $params['sameasstyle']);
56	} else {
57		$smarty->assign('sameType', 'disc');
58	}
59
60	$html = '';
61
62	if (isset($params['class'])) {                                       // if class was given
63		if (isset($footnotes['lists'][$params['class']])) {        // if the class exists
64			$html = genFootnoteArea($footnotes['lists'][$params['class']]);
65			unset($footnotes['lists'][$params['class']]['entry']);
66		}
67	} else {
68		$html = genFootnoteArea($footnotes['lists']['.def.']);
69	}
70
71	return $html;
72}
73
74/**
75 *
76 * Generate footnote area HTML
77 *
78 * @param $list array the array to turn into HTML
79 *
80 * @return string
81 */
82
83function genFootnoteArea($list)
84{
85	$smarty = TikiLib::lib('smarty');
86	$smarty->assign('footnotes', $list['entry']);
87	$smarty->assign('listType', $list['listType']);
88
89	return $smarty->fetch('templates/wiki-plugins/wikiplugin_footnotearea.tpl');
90}
91