summaryrefslogtreecommitdiff
path: root/smartyplugins/BlockJstab.php
blob: 758dfd3be1355951302970ea0611c4efdb4f90ff (plain)
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
<?php
namespace Bitweaver\Plugins;

use Bitweaver\BitBase;
use Smarty\BlockHandler\BlockHandlerInterface;
use Smarty\Template;
use Bitweaver\KernelTools;

/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */

/**
 * Smarty {jstab} block plugin
  *
 * Type:		block
 * Name:		jstab
 * Input:
 * Abstract:	Used to enclose a set of tabs
 */

 class BlockJstab implements BlockHandlerInterface {

	public function handle( $params, $content, Template $template, &$repeat): string {
		if( empty( $repeat ) ){
			global $jsTabLinks;

			$tClass = isset( $params['class'] ) ? ' class="'.$params['class'].'"' : '';
			$tStyle	= isset( $params['style'] ) ? ' style="'.$params['style'].'"' : '';
			$tClick	= isset( $params['onclick'] ) ? ' onclick="'.$params['onclick'].'"' : '';
			$tTitle	= KernelTools::tra( $params['title'] ?? 'No Title' );

			$tabId = strtolower( $params['id'] ?? 'tab'.preg_replace("/[^A-Za-z0-9]/", '', $tTitle) );

			$tabString = '<li '.$tClick.' '.$tClass.' '.$tStyle.'><a href="#'.$tabId.'">' . $tTitle . '</a></li>';
			if( isset( $params['position'] ) ) {
				array_splice( $jsTabLinks, $params['position'], 0, $tabString );
			} else {
				$jsTabLinks[] = $tabString;
			}

			$tabType = BitBase::getParameter( $params, 'tabtype', 'tab' );

			$ret = '<div class="'.$tabType.'-pane" id="'.$tabId.'">';
			$ret .= $content;
			$ret .= '</div>';

			return $ret;
		}
		return '';
	}

	public function isCacheable(): bool {
		return true;
	}
}