blob: fdcc5967cd50533d0a70d454a8b7bbdac6a71d9a (
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
|
<?php
namespace Bitweaver\Plugins;
use Smarty\BlockHandler\BlockHandlerInterface;
use Smarty\Template;
/**
* Smarty plugin
* @package Smarty
* @subpackage plugins
*/
/**
* Smarty plugin
* -------------------------------------------------------------
* File: block.sortlinks.php
* Type: block
* Name: sortlinks
* -------------------------------------------------------------
*/
class BlockSortLinks implements BlockHandlerInterface {
public function handle( $params, $content, Template $template, &$repeat): string {
if ($content) {
$links = mb_split("\n",mb_strtolower($content) );
$links2 = [];
foreach ($links as $value) {
$splitted=preg_split("/[<>]/",$value,-1,PREG_SPLIT_NO_EMPTY);
$links2[$splitted[2]]=$value;
}
if( isset( $params['order'] ) && $params['order']=='reverse' ) {
krsort( $links2 );
} else {
ksort($links2);
}
foreach($links2 as $value) {
echo $value;
}
}
return '';
}
public function isCacheable(): bool {
return true;
}
}
|