summaryrefslogtreecommitdiffstats
path: root/library/Icinga/Web/View/helpers/string.php
blob: b3f667b161c5a19ca64fd90143e6e2eb03f6fb8c (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
<?php
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */

namespace Icinga\Web\View;

use Icinga\Util\StringHelper;
use Icinga\Web\Helper\Markdown;

$this->addHelperFunction('ellipsis', function ($string, $maxLength, $ellipsis = '...') {
    return StringHelper::ellipsis($string, $maxLength, $ellipsis);
});

$this->addHelperFunction('nl2br', function ($string) {
    return nl2br(str_replace(array('\r\n', '\r', '\n'), '<br>', $string), false);
});

$this->addHelperFunction('markdown', function ($content, $containerAttribs = null) {
    if (! isset($containerAttribs['class'])) {
        $containerAttribs['class'] = 'markdown';
    } else {
        $containerAttribs['class'] .= ' markdown';
    }

    return '<section' . $this->propertiesToString($containerAttribs) . '>' . Markdown::text($content) . '</section>';
});

$this->addHelperFunction('markdownLine', function ($content, $containerAttribs = null) {
    if (! isset($containerAttribs['class'])) {
        $containerAttribs['class'] = 'markdown inline';
    } else {
        $containerAttribs['class'] .= ' markdown inline';
    }

    return '<section' . $this->propertiesToString($containerAttribs) . '>' .
        Markdown::line($content) . '</section>';
});