summaryrefslogtreecommitdiff
path: root/smartyplugins/BlockNavbar.php
blob: a10075bf55ab49e6fc4d4230e048e277cebd042a (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
<?php
namespace Bitweaver\Plugins;

use Smarty\BlockHandler\BlockHandlerInterface;
use Smarty\Template;

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

/**
 * Smarty {navbar} block plugin
 *
 * Type:	block
 * Name:	navbar
 * Input:	set of links that are used for navigation purposes
 */
class BlockNavbar implements BlockHandlerInterface {

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

		$links = $this->smarty_block_navbar_get_links( $content );
		$gBitSmarty->assign( 'links',$links );
		return $gBitSmarty->fetch( 'bitpackage:kernel/navbar.tpl' );
	}

	public function smarty_block_navbar_get_links( $content ) {
		$links = [];
		if( preg_match_all( "/<a.*?href=\".*?\">.*?<\/a>/i",$content,$res ) ) {
			$res = $res[0];
			$links = array_unique( $res );
		}
		return $links;
	}

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