Completed
Push — development ( ef0625...f79737 )
by Torben
04:11
created

initializeArguments()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
namespace DERHANSEN\SfEventMgt\ViewHelpers\Format;
3
4
/*
5
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.txt file that was distributed with this source code.
9
 */
10
11
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
12
13
/**
14
 * ICalendar Description viewhelper
15
 *
16
 * @author Torben Hansen <[email protected]>
17
 */
18
class ICalendarDescriptionViewHelper extends AbstractViewHelper
19
{
20
    /**
21
     * Initialize arguments
22
     */
23
    public function initializeArguments()
24
    {
25
        parent::initializeArguments();
26
        $this->registerArgument('description', 'string', 'The description', false);
27
    }
28
29
    /**
30
     * Formats the given description according to RFC 2445
31
     *
32
     * @return string
33
     */
34 7
    public function render()
35
    {
36 7
        $description = $this->arguments['description'];
37 1
        if ($description === null) {
38 1
            $description = $this->renderChildren();
39 7
        }
40 7
        $tmpDescription = strip_tags($description);
41 7
        $tmpDescription = str_replace('&nbsp;', ' ', $tmpDescription);
42
        $tmpDescription = html_entity_decode($tmpDescription);
43 7
        // Replace carriage return
44
        $tmpDescription = str_replace(chr(13), '\n\n', $tmpDescription);
45 7
        // Strip new lines
46
        $tmpDescription = str_replace(chr(10), '', $tmpDescription);
47 7
        // Glue everything together, so every line is max 75 chars
48 2
        if (strlen($tmpDescription) > 75) {
49 2
            $newDescription = substr($tmpDescription, 0, 63) . chr(10);
50 2
            $tmpDescription = substr($tmpDescription, 63);
51 2
            $arrPieces = str_split($tmpDescription, 74);
52 2
            foreach ($arrPieces as &$value) {
53 2
                $value = ' ' . $value;
54 2
            }
55 2
            $newDescription .= implode(chr(10), $arrPieces);
56 5
        } else {
57
            $newDescription = $tmpDescription;
58 7
        }
59
60
        return $newDescription;
61
    }
62
}
63