-
Notifications
You must be signed in to change notification settings - Fork 39
/
Component.php
228 lines (207 loc) · 8.02 KB
/
Component.php
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<?php
class Kwc_Basic_Text_Component extends Kwc_Abstract
{
public static function getSettings($param = null)
{
$ret = array_merge(parent::getSettings($param), array(
'ownModel' => 'Kwc_Basic_Text_Model',
'componentName' => trlKwfStatic('Text'),
'componentIcon' => 'paragraph_page',
'width' => 550,
'height' => 400,
'enableAlignments' => false,
'enableColors' => false,
'enableFont' => false,
'enableFormat' => true,
'enableLists' => true,
'enableSourceEdit' => true,
'enableBlock' => false,
'enableUndoRedo' => true,
'enableLinks' => false, //nur wenn link komponente nicht vorhanden
'enableInsertChar' => true,
'enablePastePlain' => true,
'enableTidy' => true,
'stylesIdPattern' => false, //zB: '^company_[0-9]+',
'enableStyles' => true,
'enableStylesEditor'=> true,
'enableTagsWhitelist'=> true,
'defaultText' => Kwc_Abstract::LOREM_IPSUM
));
$ret['stylesModel'] = 'Kwc_Basic_Text_StylesModel';
$ret['generators']['child'] = array(
'class' => 'Kwc_Basic_Text_Generator',
'component' => array(
//auf false setzen um buttons zu deaktivieren
'image' => false,
'link' => 'Kwc_Basic_LinkTag_Component',
'download' => 'Kwc_Basic_DownloadTag_Component'
)
);
$ret['assetsAdmin']['files'][] = 'kwf/Kwc/Basic/Text/StylesEditor.js';
$ret['assetsAdmin']['files'][] = 'kwf/Kwc/Basic/Text/StylesEditorTab.js';
$ret['assetsAdmin']['dep'][] = 'ExtHtmlEdit';
$ret['assetsAdmin']['dep'][] = 'ExtWindow';
$ret['assetsAdmin']['dep'][] = 'KwfAutoForm';
$ret['assetsAdmin']['dep'][] = 'KwfAutoGrid';
$ret['assetsAdmin']['dep'][] = 'ExtSimpleStore';
$ret['assetsAdmin']['dep'][] = 'KwfColorField';
$ret['rootElementClass'] = 'kwfUp-webStandard kwcText';
$ret['flags']['searchContent'] = true;
$ret['flags']['hasFulltext'] = true;
$ret['extConfig'] = 'Kwf_Component_Abstract_ExtConfig_Form';
$ret['throwHasContentChangedOnRowColumnsUpdate'] = 'content';
$ret['apiContent'] = 'Kwc_Basic_Text_ApiContent';
$ret['apiContentType'] = 'formattedText';
return $ret;
}
public static function validateSettings($settings, $component)
{
//nicht parent aufrufen weil da würde das model erstellt werden ohne componentClass zu übergeben
}
public function getOwnModel()
{
return self::createOwnModel($this->getData()->componentClass);
}
public function getChildModel()
{
return self::createChildModel($this->getData()->componentClass);
}
public static function createOwnModel($class)
{
return Kwc_Basic_Text_ModelFactory::getModelInstance(array(
'componentClass' => $class
));
}
public static function createChildModel($class)
{
return Kwc_Basic_Text_ChildComponentsModelFactory::getModelInstance(array(
'componentClass' => $class
));
}
protected function _getContentParts()
{
$content = $this->_getRow()->content;
$content = Kwf_Trl::getInstance()->trlStaticExecute($content, $this->getData()->getLanguage());
return $this->_getRow()->getContentParts($content);
}
public function getTemplateVars(Kwf_Component_Renderer_Abstract $renderer)
{
$ret = parent::getTemplateVars($renderer);
$ret['contentParts'] = array();
$childs = $this->getData()->getChildComponents();
foreach ($this->_getContentParts() as $part) {
if (is_array($part)) {
if ($part['type'] == 'image') {
$part['nr'] = 'i'.$part['nr'];
} else if ($part['type'] == 'link') {
$part['nr'] = 'l'.$part['nr'];
} else if ($part['type'] == 'download') {
$part['nr'] = 'd'.$part['nr'];
} else {
continue;
}
foreach ($childs as $row) {
if ($row->dbId == $this->getData()->dbId.'-'.$part['nr']) {
$ret['contentParts'][] = array(
'type' => $part['type'],
'component'=>$row
);
break;
}
}
} else {
if (preg_match_all('#(<[a-z]+\s[^>]*)class\s*=\s*"style(\d+)"([^>]*>)#', $part, $m)) {
foreach (array_keys($m[0]) as $i) {
$matched = $m[0][$i];
$prefix = $m[1][$i];
$styleId = $m[2][$i];
$postfix = $m[3][$i];
$style = '';
$row = Kwf_Model_Abstract::getInstance($this->_getSetting('stylesModel'))
->getRow($styleId);
if ($row) {
foreach ($row->getStyles() as $k=>$v) {
$style .= "$k: $v; ";
}
}
$styleAttr = 'style="'.Kwf_Util_HtmlSpecialChars::filter($style).'"';
$part = str_replace($matched, $prefix.$styleAttr.$postfix, $part);
}
}
$part = str_replace('[-]', '­', $part);
$ret['contentParts'][] = $part;
}
}
return $ret;
}
public function hasContent()
{
$content = $this->_getRow()->content;
$content = strip_tags($content);
// replace every non-word-character, to see if there is real content,
// or just a bunch of white-spaces
$content = preg_replace('/\s*/u', '', $content);
if (!empty($content)) return true;
return false;
}
public function getSearchContent()
{
$ret = '';
foreach ($this->_getRow()->getContentParts() as $part) {
if (is_string($part)) {
$part = strip_tags($part);
$part = str_replace('[-]', '­', $part);
$ret .= ' '.$part;
}
}
return $ret;
}
public function getFulltextContent()
{
$html = '';
foreach ($this->_getRow()->getContentParts() as $part) {
if (is_string($part)) $html .= ' '.$part;
}
$ret = array();
$ret['content'] = $this->_stripTags($html);
$tags = array(
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'strong',
);
foreach ($tags as $tag) {
if (preg_match_all("#<$tag.*?>(.*?)</$tag>#", $html, $m)) {
$html = preg_replace("#<$tag.*?>.*?</$tag>#", '', $html);
foreach ($m[1] as $text) {
$text = $this->_stripTags($text);
if ($text) {
if (!isset($ret['content'.$tag])) {
$ret['content'.$tag] = $text;
} else {
$ret['content'.$tag] .= ' '.$text;
}
}
}
}
}
$html = $this->_stripTags($html);
if ($html) {
$ret['normalContent'] = $html;
}
return $ret;
}
private static function _stripTags($html)
{
$html = preg_replace("#<[^>]*>#", ' ', $html);
$html = str_replace("\r", ' ', $html);
$html = str_replace("\n", ' ', $html);
$html = preg_replace('# +#', ' ', $html);
$html = str_replace('[-]', '­', $html);
$html = trim($html);
return $html;
}
}