AbstractRendering   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 111
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 9
Bugs 1 Features 1
Metric Value
wmc 9
c 9
b 1
f 1
lcom 1
cbo 3
dl 0
loc 111
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 6 1
A breakContent() 0 9 2
A getLink() 0 4 1
A breakLines() 0 5 2
B parseBody() 0 24 3
1
<?php
2
/**
3
 * Abstract rendering helper
4
 *
5
 * @author  Tim Lochmüller
6
 */
7
8
namespace FRUIT\Ink\Rendering;
9
10
use FRUIT\Ink\Configuration;
11
use TYPO3\CMS\Core\Utility\MailUtility;
12
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
13
14
/**
15
 * Abstract rendering helper
16
 */
17
abstract class AbstractRendering implements RenderingInterface
18
{
19
20
    /**
21
     * Content object
22
     *
23
     * @var ContentObjectRenderer
24
     */
25
    protected $contentObject;
26
27
    /**
28
     * Configuration
29
     *
30
     * @var array
31
     */
32
    protected $configuration;
33
34
    /**
35
     * Set the content object and configuration
36
     * Call the renderInternal after preparation
37
     *
38
     * @param ContentObjectRenderer $contentObject
39
     * @param array                 $configuration
40
     *
41
     * @return array
42
     */
43
    public function render($contentObject, $configuration)
44
    {
45
        $this->contentObject = $contentObject;
46
        $this->configuration = $configuration;
47
        return $this->renderInternal();
48
    }
49
50
    /**
51
     * Parsing the bodytext field content, removing typical entities and <br /> tags.
52
     *
53
     * @param    string $str     : Field content from "bodytext" or other text field
54
     * @param    string $altConf : Altername conf name (especially when bodyext field in other table then tt_content)
55
     *
56
     * @return    string        Processed content
57
     */
58
    public function parseBody($str, $altConf = 'bodytext')
59
    {
60
        if ($this->configuration[$altConf . '.']['doubleLF']) {
61
            $str = preg_replace("/\n/", "\n\n", $str);
62
        }
63
        // Regular parsing:
64
        $str = preg_replace('/<br\s*\/?>/i', chr(10), $str);
65
        $str = $this->contentObject->stdWrap($str, $this->configuration[$altConf . '.']['stdWrap.']);
66
67
        // Then all a-tags:
68
        $aConf = array();
69
        $aConf['parseFunc.']['tags.']['a'] = 'USER';
70
        // check direct mail usage @todo
71
        $aConf['parseFunc.']['tags.']['a.']['userFunc'] = 'FRUIT\\Ink\\PlainRenderer->atagToHttp';
72
        $aConf['parseFunc.']['tags.']['a.']['siteUrl'] = 'http://www.google.de';
73
        $str = $this->contentObject->stdWrap($str, $aConf);
74
        $str = str_replace('&nbsp;', ' ', htmlspecialchars_decode($str));
75
76
        if ($this->configuration[$altConf . '.']['header']) {
77
            $str = $this->configuration[$altConf . '.']['header'] . LF . $str;
78
        }
79
80
        return chr(10) . $str;
81
    }
82
83
    /**
84
     * Function used to wrap the bodytext field content (or image caption) into lines of a max length of
85
     *
86
     * @param        string $str : The content to break
87
     *
88
     * @return        string                Processed value.
89
     * @see main_plaintext(), breakLines()
90
     */
91
    public function breakContent($str)
92
    {
93
        $cParts = explode(chr(10), $str);
94
        $lines = array();
95
        foreach ($cParts as $substrs) {
96
            $lines[] = $this->breakLines($substrs, LF);
97
        }
98
        return implode(chr(10), $lines);
99
    }
100
101
    /**
102
     * Returns a typolink URL based on input.
103
     *
104
     * @param    string $ll : Parameter to typolink
105
     *
106
     * @return    string        The URL returned from $this->cObj->getTypoLink_URL(); - possibly it prefixed with the URL of the site if not present already
107
     */
108
    public function getLink($ll)
109
    {
110
        return $this->contentObject->getTypoLink_URL($ll);
111
    }
112
113
    /**
114
     * Breaking lines into fixed length lines, using GeneralUtility::breakLinesForEmail()
115
     *
116
     * @param        string  $str       : The string to break
117
     * @param        string  $implChar  : Line break character
118
     * @param        integer $charWidth : Length of lines, default is $this->charWidth
119
     *
120
     * @return        string                Processed string
121
     */
122
    public function breakLines($str, $implChar = LF, $charWidth = false)
123
    {
124
        $charWidth = $charWidth === false ? Configuration::getPlainTextWith() : (int)$charWidth;
125
        return MailUtility::breakLinesForEmail($str, $implChar, $charWidth);
126
    }
127
}
128